@@ -469,7 +469,7 @@ export async function serverRoutes(app: any, prefix = '') {
469469 const where : any [ ] = [ { userId : user . id } ] ;
470470 if ( subuserUuids . length ) where . push ( { uuid : In ( subuserUuids ) } ) ;
471471 const found = await cfgRepo . find ( { where } ) ;
472- return found . filter ( ( c : any ) => ! c . isCodeInstance ) ;
472+ return found ;
473473 } ) ( ) ;
474474
475475 const cfgMap = new Map ( configs . map ( ( c : any ) => [ c . uuid , c ] ) ) ;
@@ -1188,64 +1188,10 @@ export async function serverRoutes(app: any, prefix = '') {
11881188 } ;
11891189 }
11901190
1191- let isCodeInstance = ! ! body . isCodeInstance || Number ( body . eggId ) === 264 ;
1192-
1193- if ( isCodeInstance && ! isAdmin ) {
1194- const settingRepo = AppDataSource . getRepository (
1195- require ( '../models/panelSetting.entity' ) . PanelSetting
1196- ) ;
1197- const setting = await settingRepo . findOneBy ( { key : 'codeInstancesEnabled' } ) ;
1198- if ( setting ?. value === 'false' ) {
1199- ctx . set . status = 403 ;
1200- return { error : 'Code instance creation is temporarily disabled by an administrator.' } ;
1201- }
1202- }
1203-
1204- const allUserServers = ! isAdmin
1191+ const existingRegularServers = ! isAdmin
12051192 ? await cfgRepo ( ) . find ( { where : { userId : ownerId } } )
12061193 : [ ] ;
12071194
1208- const existingCodeInstances = allUserServers . filter ( ( s : any ) => s . isCodeInstance ) ;
1209- const existingRegularServers = allUserServers . filter ( ( s : any ) => ! s . isCodeInstance ) ;
1210-
1211- if ( isCodeInstance && ! isAdmin ) {
1212- const allowedPortalTypes = [ 'educational' , 'paid' , 'enterprise' ] ;
1213- if ( ! allowedPortalTypes . includes ( effectivePortalType ) ) {
1214- ctx . set . status = 403 ;
1215- return { error : 'Code Instances are available only for educational or higher plans.' } ;
1216- }
1217-
1218- if ( existingCodeInstances . length >= 2 ) {
1219- ctx . set . status = 403 ;
1220- return { error : 'Maximum 2 Code Instances are allowed concurrently.' } ;
1221- }
1222-
1223- const existingCIMem = existingCodeInstances . reduce ( ( sum : number , i : any ) => sum + ( i . memory || 0 ) , 0 ) ;
1224- const existingCICpu = existingCodeInstances . reduce ( ( sum : number , i : any ) => sum + ( i . cpu || 0 ) , 0 ) ;
1225- const existingCIDisk = existingCodeInstances . reduce ( ( sum : number , i : any ) => sum + ( i . disk || 0 ) , 0 ) ;
1226-
1227- if ( existingCIMem + memory > 8192 ) {
1228- ctx . set . status = 403 ;
1229- return { error : 'Total Code Instance memory limit is 8192 MB.' } ;
1230- }
1231- if ( existingCICpu + cpu > 6 ) {
1232- ctx . set . status = 403 ;
1233- return { error : 'Total Code Instance CPU limit is 6 cores.' } ;
1234- }
1235- if ( existingCIDisk + disk > 102400 ) {
1236- ctx . set . status = 403 ;
1237- return { error : 'Total Code Instance disk limit is 100000 MB.' } ;
1238- }
1239-
1240- const usedMinutes = existingCodeInstances . reduce (
1241- ( sum : number , i : any ) => sum + ( i . codeInstanceMinutesUsed || 0 ) , 0
1242- ) ;
1243- if ( usedMinutes >= 150 * 60 ) {
1244- ctx . set . status = 403 ;
1245- return { error : 'Monthly Code Instance usage limit of 150 hours reached.' } ;
1246- }
1247- }
1248-
12491195 if ( ! isAdmin ) {
12501196 if ( limits . serverLimit != null && limits . serverLimit > 0 ) {
12511197 if ( existingRegularServers . length >= limits . serverLimit ) {
@@ -1272,10 +1218,6 @@ export async function serverRoutes(app: any, prefix = '') {
12721218 }
12731219 }
12741220
1275- if ( isCodeInstance ) {
1276- eggId = 264 ;
1277- }
1278-
12791221 if ( ! eggId ) {
12801222 ctx . set . status = 400 ;
12811223 return { error : 'eggId is required' } ;
@@ -1480,9 +1422,7 @@ export async function serverRoutes(app: any, prefix = '') {
14801422 disk,
14811423 cpu,
14821424 eggId : egg . id ,
1483- isCodeInstance,
14841425 kvmPassthroughEnabled,
1485- lastActivityAt : isCodeInstance ? new Date ( ) : undefined ,
14861426 ...( autoAllocation ? { allocations : autoAllocation } : { } ) ,
14871427 } ) ;
14881428
@@ -4320,88 +4260,4 @@ export async function serverRoutes(app: any, prefix = '') {
43204260 response : { 200 : t . Object ( { host : t . String ( ) , port : t . Number ( ) , username : t . String ( ) , proxied : t . Boolean ( ) } ) , 401 : t . Object ( { error : t . String ( ) } ) , 403 : t . Object ( { error : t . String ( ) } ) , 404 : t . Object ( { error : t . String ( ) } ) , 500 : t . Object ( { error : t . String ( ) } ) } ,
43214261 detail : { summary : 'Get SFTP connection info' , tags : [ 'Servers' ] }
43224262 } ) ;
4323-
4324- app . get ( prefix + '/infrastructure/code-instances' , async ( ctx : any ) => {
4325- const user = ctx . user as User ;
4326- if ( ! user ) {
4327- ctx . set . status = 401 ;
4328- return { error : 'Unauthorized' } ;
4329- }
4330-
4331- const instances = await cfgRepo ( ) . find ( { where : { userId : user . id , isCodeInstance : true } } ) ;
4332- return instances . map ( ( cfg ) => ( {
4333- uuid : cfg . uuid ,
4334- name : cfg . name ,
4335- nodeId : cfg . nodeId ,
4336- memory : cfg . memory ,
4337- disk : cfg . disk ,
4338- cpu : cfg . cpu ,
4339- status : cfg . hibernated ? 'hibernated' : 'active' ,
4340- lastActivityAt : cfg . lastActivityAt ,
4341- createdAt : cfg . createdAt ,
4342- codeInstanceMinutesUsed : cfg . codeInstanceMinutesUsed ,
4343- } ) ) ;
4344- } , {
4345- beforeHandle : [ authenticate ] ,
4346- response : { 200 : t . Array ( t . Any ( ) ) , 401 : t . Object ( { error : t . String ( ) } ) } ,
4347- detail : { summary : 'List code instances for the current user' , tags : [ 'Code Instances' ] }
4348- } ) ;
4349-
4350- app . post ( prefix + '/infrastructure/code-instances/:uuid/ping' , async ( ctx : any ) => {
4351- const { uuid } = ctx . params as any ;
4352- const user = ctx . user as User ;
4353- if ( ! user ) {
4354- ctx . set . status = 401 ;
4355- return { error : 'Unauthorized' } ;
4356- }
4357-
4358- const cfg = await cfgRepo ( ) . findOneBy ( { uuid, isCodeInstance : true } ) ;
4359- if ( ! cfg || cfg . userId !== user . id ) {
4360- ctx . set . status = 404 ;
4361- return { error : 'Code Instance not found' } ;
4362- }
4363-
4364- cfg . lastActivityAt = new Date ( ) ;
4365- await cfgRepo ( ) . save ( cfg ) ;
4366-
4367- await createActivityLog ( { userId : user . id , action : 'codeInstance:ping' , targetId : uuid , targetType : 'code-instance' , ipAddress : ctx . ip } ) ;
4368- return { success : true } ;
4369- } , {
4370- beforeHandle : [ authenticate ] ,
4371- response : { 200 : t . Object ( { success : t . Boolean ( ) } ) , 401 : t . Object ( { error : t . String ( ) } ) , 404 : t . Object ( { error : t . String ( ) } ) } ,
4372- detail : { summary : 'Ping code instance activity' , tags : [ 'Code Instances' ] }
4373- } ) ;
4374-
4375- app . post ( prefix + '/infrastructure/code-instances/:uuid/stop' , async ( ctx : any ) => {
4376- const { uuid } = ctx . params as any ;
4377- const user = ctx . user as User ;
4378- if ( ! user ) {
4379- ctx . set . status = 401 ;
4380- return { error : 'Unauthorized' } ;
4381- }
4382-
4383- const cfg = await cfgRepo ( ) . findOneBy ( { uuid, isCodeInstance : true } ) ;
4384- if ( ! cfg || cfg . userId !== user . id ) {
4385- ctx . set . status = 404 ;
4386- return { error : 'Code Instance not found' } ;
4387- }
4388-
4389- try {
4390- const svc = await serviceFor ( uuid ) ;
4391- await svc . powerServer ( uuid , 'stop' ) . catch ( ( ) => { } ) ;
4392- await svc . serverRequest ( uuid , '' , 'delete' ) . catch ( ( ) => { } ) ;
4393- } catch ( e : any ) {
4394- // skip
4395- }
4396-
4397- await removeServerConfig ( uuid ) . catch ( ( ) => { } ) ;
4398- await nodeSvc . unmapServer ( uuid ) . catch ( ( ) => { } ) ;
4399-
4400- await createActivityLog ( { userId : user . id , action : 'codeInstance:stop' , targetId : uuid , targetType : 'code-instance' , ipAddress : ctx . ip } ) ;
4401- return { success : true } ;
4402- } , {
4403- beforeHandle : [ authenticate ] ,
4404- response : { 200 : t . Object ( { success : t . Boolean ( ) } ) , 401 : t . Object ( { error : t . String ( ) } ) , 404 : t . Object ( { error : t . String ( ) } ) } ,
4405- detail : { summary : 'Stop and delete code instance' , tags : [ 'Code Instances' ] }
4406- } ) ;
4407- }
4263+ }
0 commit comments