Skip to content

Commit

Permalink
fix(server): support array input param for adding deps (#577)
Browse files Browse the repository at this point in the history
  • Loading branch information
maslow authored Dec 24, 2022
1 parent 7911ba0 commit a7c0dc8
Show file tree
Hide file tree
Showing 4 changed files with 17 additions and 20 deletions.
3 changes: 0 additions & 3 deletions server/.env
Original file line number Diff line number Diff line change
Expand Up @@ -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
4 changes: 3 additions & 1 deletion server/src/dependency/dependency.controller.ts
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,7 @@ import {
} from '@nestjs/common'
import {
ApiBearerAuth,
ApiBody,
ApiOperation,
ApiResponse,
ApiTags,
Expand Down Expand Up @@ -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)
}
Expand Down
29 changes: 13 additions & 16 deletions server/src/dependency/dependency.service.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
1 change: 1 addition & 0 deletions server/src/runtime-builtin-deps.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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',
Expand Down

0 comments on commit a7c0dc8

Please sign in to comment.