mirror of
https://github.com/sasjs/server.git
synced 2026-01-15 09:50:06 +00:00
fix: adde validation + code improvement
This commit is contained in:
290
api/package-lock.json
generated
290
api/package-lock.json
generated
File diff suppressed because it is too large
Load Diff
@@ -57,8 +57,7 @@
|
|||||||
"mongoose-sequence": "^5.3.1",
|
"mongoose-sequence": "^5.3.1",
|
||||||
"morgan": "^1.10.0",
|
"morgan": "^1.10.0",
|
||||||
"multer": "^1.4.3",
|
"multer": "^1.4.3",
|
||||||
"swagger-ui-express": "^4.1.6",
|
"swagger-ui-express": "^4.1.6"
|
||||||
"tsoa": "3.14.1"
|
|
||||||
},
|
},
|
||||||
"devDependencies": {
|
"devDependencies": {
|
||||||
"@types/bcryptjs": "^2.4.2",
|
"@types/bcryptjs": "^2.4.2",
|
||||||
@@ -84,6 +83,7 @@
|
|||||||
"supertest": "^6.1.3",
|
"supertest": "^6.1.3",
|
||||||
"ts-jest": "^27.0.3",
|
"ts-jest": "^27.0.3",
|
||||||
"ts-node": "^10.0.0",
|
"ts-node": "^10.0.0",
|
||||||
|
"tsoa": "3.14.1",
|
||||||
"typescript": "^4.3.2"
|
"typescript": "^4.3.2"
|
||||||
},
|
},
|
||||||
"configuration": {
|
"configuration": {
|
||||||
|
|||||||
@@ -172,12 +172,20 @@ components:
|
|||||||
enum:
|
enum:
|
||||||
- service
|
- service
|
||||||
type: string
|
type: string
|
||||||
|
MemberType.file:
|
||||||
|
enum:
|
||||||
|
- file
|
||||||
|
type: string
|
||||||
ServiceMember:
|
ServiceMember:
|
||||||
properties:
|
properties:
|
||||||
name:
|
name:
|
||||||
type: string
|
type: string
|
||||||
type:
|
type:
|
||||||
$ref: '#/components/schemas/MemberType.service'
|
anyOf:
|
||||||
|
-
|
||||||
|
$ref: '#/components/schemas/MemberType.service'
|
||||||
|
-
|
||||||
|
$ref: '#/components/schemas/MemberType.file'
|
||||||
code:
|
code:
|
||||||
type: string
|
type: string
|
||||||
required:
|
required:
|
||||||
@@ -220,6 +228,7 @@ components:
|
|||||||
fileTree:
|
fileTree:
|
||||||
$ref: '#/components/schemas/FileTree'
|
$ref: '#/components/schemas/FileTree'
|
||||||
required:
|
required:
|
||||||
|
- appLoc
|
||||||
- fileTree
|
- fileTree
|
||||||
type: object
|
type: object
|
||||||
additionalProperties: false
|
additionalProperties: false
|
||||||
|
|||||||
@@ -28,7 +28,7 @@ import { FileTree, isFileTree, TreeNode } from '../types'
|
|||||||
import { getTmpFilesFolderPath } from '../utils'
|
import { getTmpFilesFolderPath } from '../utils'
|
||||||
|
|
||||||
interface DeployPayload {
|
interface DeployPayload {
|
||||||
appLoc?: string
|
appLoc: string
|
||||||
fileTree: FileTree
|
fileTree: FileTree
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -196,7 +196,7 @@ const deploy = async (data: DeployPayload) => {
|
|||||||
|
|
||||||
await createFileTree(
|
await createFileTree(
|
||||||
data.fileTree.members,
|
data.fileTree.members,
|
||||||
data.appLoc ? data.appLoc.replace(/^\//, '').split('/') : []
|
data.appLoc.replace(/^\//, '').split('/')
|
||||||
).catch((err) => {
|
).catch((err) => {
|
||||||
throw { code: 500, ...execDeployErrorResponse, ...err }
|
throw { code: 500, ...execDeployErrorResponse, ...err }
|
||||||
})
|
})
|
||||||
|
|||||||
@@ -5,18 +5,24 @@ import { publishAppStream } from '../appStream'
|
|||||||
|
|
||||||
import { multerSingle } from '../../middlewares/multer'
|
import { multerSingle } from '../../middlewares/multer'
|
||||||
import { DriveController } from '../../controllers/'
|
import { DriveController } from '../../controllers/'
|
||||||
import { fileBodyValidation, fileParamValidation } from '../../utils'
|
import {
|
||||||
|
deployValidation,
|
||||||
|
fileBodyValidation,
|
||||||
|
fileParamValidation
|
||||||
|
} from '../../utils'
|
||||||
|
|
||||||
const controller = new DriveController()
|
const controller = new DriveController()
|
||||||
|
|
||||||
const driveRouter = express.Router()
|
const driveRouter = express.Router()
|
||||||
|
|
||||||
driveRouter.post('/deploy', async (req, res) => {
|
driveRouter.post('/deploy', async (req, res) => {
|
||||||
try {
|
const { error, value: body } = deployValidation(req.body)
|
||||||
const response = await controller.deploy(req.body)
|
if (error) return res.status(400).send(error.details[0].message)
|
||||||
|
|
||||||
const data = req.body
|
try {
|
||||||
const appLoc = data.appLoc ? data.appLoc.replace(/^\//, '').split('/') : []
|
const response = await controller.deploy(body)
|
||||||
|
|
||||||
|
const appLoc = body.appLoc.replace(/^\//, '')?.split('/')
|
||||||
|
|
||||||
publishAppStream(appLoc)
|
publishAppStream(appLoc)
|
||||||
|
|
||||||
|
|||||||
@@ -1,11 +1,12 @@
|
|||||||
import path from 'path'
|
import path from 'path'
|
||||||
import express from 'express'
|
import express from 'express'
|
||||||
|
import { folderExists } from '@sasjs/utils'
|
||||||
|
|
||||||
import { getTmpFilesFolderPath } from '../../utils'
|
import { getTmpFilesFolderPath } from '../../utils'
|
||||||
|
|
||||||
const router = express.Router()
|
const router = express.Router()
|
||||||
|
|
||||||
export const publishAppStream = (appLoc: string[]) => {
|
export const publishAppStream = async (appLoc: string[]) => {
|
||||||
const appLocUrl = encodeURI(appLoc.join('/'))
|
const appLocUrl = encodeURI(appLoc.join('/'))
|
||||||
const appLocPath = appLoc.join(path.sep)
|
const appLocPath = appLoc.join(path.sep)
|
||||||
|
|
||||||
@@ -16,7 +17,10 @@ export const publishAppStream = (appLoc: string[]) => {
|
|||||||
'webv'
|
'webv'
|
||||||
)
|
)
|
||||||
|
|
||||||
router.use(`/${appLocUrl}`, express.static(pathToDeployment))
|
if (await folderExists(pathToDeployment)) {
|
||||||
|
router.use(`/${appLocUrl}`, express.static(pathToDeployment))
|
||||||
|
console.log('Serving Stream App: ', appLocUrl)
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
export default router
|
export default router
|
||||||
|
|||||||
@@ -66,6 +66,12 @@ export const registerClientValidation = (data: any): Joi.ValidationResult =>
|
|||||||
clientSecret: Joi.string().required()
|
clientSecret: Joi.string().required()
|
||||||
}).validate(data)
|
}).validate(data)
|
||||||
|
|
||||||
|
export const deployValidation = (data: any): Joi.ValidationResult =>
|
||||||
|
Joi.object({
|
||||||
|
appLoc: Joi.string().pattern(/^\//).required().min(2),
|
||||||
|
fileTree: Joi.any().required()
|
||||||
|
}).validate(data)
|
||||||
|
|
||||||
export const fileBodyValidation = (data: any): Joi.ValidationResult =>
|
export const fileBodyValidation = (data: any): Joi.ValidationResult =>
|
||||||
Joi.object({
|
Joi.object({
|
||||||
filePath: Joi.string().pattern(/.sas$/).required().messages({
|
filePath: Joi.string().pattern(/.sas$/).required().messages({
|
||||||
|
|||||||
Reference in New Issue
Block a user