diff --git a/server/.env b/server/.env index 20dc93c7b5..576559485d 100644 --- a/server/.env +++ b/server/.env @@ -22,6 +22,3 @@ CASDOOR_APP_NAME=laf CASDOOR_CLIENT_ID=a71f65e93723c436027e CASDOOR_CLIENT_SECRET=0d7e157be08055867b81456df3c222ea7c68a097 CASDOOR_REDIRECT_URI=http://localhost:3001/login_callback - - -NODE_RUNTIME_BUILTIN_DEPENDENCIES=@aws-sdk/client-s3@3.72.0,@aws-sdk/client-sts@3.72.0,@aws-sdk/s3-request-presigner@3.72.0,@kubernetes/client-node@0.17.1,alipay-sdk@3.1.7,axios@0.21.1,database-proxy@0.8.2,dayjs@1.10.7,dotenv@8.2.0,ejs@3.1.6,express@4.17.1,express-xml-bodyparser@0.3.0,fs-extra@9.1.0,jsonwebtoken@8.5.1,lodash@4.17.21,log4js@6.7.1,minio@7.0.28,mongodb@4.1.3,mongodb-uri@0.9.7,multer@1.4.5-lts.1,node-modules-utils@0.8.2,nodemailer@6.6.3,validator@13.7.0,ws@8.2.3 \ No newline at end of file diff --git a/server/src/dependency/dependency.controller.ts b/server/src/dependency/dependency.controller.ts index a98499e2f7..1c6b91c790 100644 --- a/server/src/dependency/dependency.controller.ts +++ b/server/src/dependency/dependency.controller.ts @@ -10,6 +10,7 @@ import { } from '@nestjs/common' import { ApiBearerAuth, + ApiBody, ApiOperation, ApiResponse, ApiTags, @@ -38,7 +39,8 @@ export class DependencyController { @ApiOperation({ summary: 'Add a dependency' }) @UseGuards(JwtAuthGuard, ApplicationAuthGuard) @Post() - async add(@Param('appid') appid: string, @Body() dto: CreateDependencyDto) { + @ApiBody({ type: [CreateDependencyDto] }) + async add(@Param('appid') appid: string, @Body() dto: CreateDependencyDto[]) { const res = await this.depsService.add(appid, dto) return ResponseUtil.ok(res) } diff --git a/server/src/dependency/dependency.service.ts b/server/src/dependency/dependency.service.ts index 4e95c8d4a2..a00fc986a8 100644 --- a/server/src/dependency/dependency.service.ts +++ b/server/src/dependency/dependency.service.ts @@ -40,30 +40,27 @@ export class DependencyService { return Object.values(deps) } - async add(appid: string, dto: CreateDependencyDto) { - if (!this.validate(dto)) { - return false - } + async add(appid: string, dto: CreateDependencyDto[]) { + // validate + const valid = dto.every((dep) => this.validate(dep)) + if (!valid) return false const extras = await this.getExtras(appid) const builtins = this.getBuiltins() const all = extras.concat(builtins) // check if the dependency name is already existed - const existed = all.find((dep) => { - const r = npa(dep) - return r.name === dto.name - }) - if (existed) return false - - const new_dep = `${dto.name}@${dto.spec}` + const names = all.map((dep) => npa(dep).name) + const new_names = dto.map((dep) => npa(dep.name).name) + const has_dup = new_names.some((name) => names.includes(name)) + if (has_dup) return false + + // add + const new_deps = dto.map((dep) => `${dep.name}@${dep.spec}`) + const deps = extras.concat(new_deps) await this.prisma.applicationConfiguration.update({ where: { appid }, - data: { - dependencies: { - push: new_dep, - }, - }, + data: { dependencies: deps }, }) return true diff --git a/server/src/runtime-builtin-deps.ts b/server/src/runtime-builtin-deps.ts index 437afd864a..2e1201c472 100644 --- a/server/src/runtime-builtin-deps.ts +++ b/server/src/runtime-builtin-deps.ts @@ -3,6 +3,7 @@ export const RUNTIME_BUILTIN_DEPENDENCIES = { '@aws-sdk/client-sts': '^3.231.0', '@aws-sdk/s3-request-presigner': '^3.231.0', '@kubernetes/client-node': '^0.18.0', + '@lafjs/cloud': '^0.0.2', 'alipay-sdk': '^3.2.0', axios: '^1.2.1', 'database-proxy': '^0.8.2',