mirror of
https://github.com/sasjs/server.git
synced 2026-04-09 07:03:13 +00:00
chore: additional param for stp/execute + desktop user in req
This commit is contained in:
@@ -164,12 +164,12 @@ const getFile = async (filePath: string): Promise<GetFileResponse> => {
|
||||
const fileContent = await readFile(filePathFull)
|
||||
|
||||
return { status: 'success', fileContent: fileContent }
|
||||
} catch (err) {
|
||||
} catch (err: any) {
|
||||
throw {
|
||||
code: 400,
|
||||
status: 'failure',
|
||||
message: 'File request failed.',
|
||||
...(typeof err === 'object' ? err : { details: err })
|
||||
error: typeof err === 'object' ? err.toString() : err
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -185,12 +185,12 @@ const updateFile = async (body: FilePayload): Promise<GetFileResponse> => {
|
||||
await createFile(filePathFull, fileContent)
|
||||
|
||||
return { status: 'success' }
|
||||
} catch (err) {
|
||||
} catch (err: any) {
|
||||
throw {
|
||||
code: 400,
|
||||
status: 'failure',
|
||||
message: 'File request failed.',
|
||||
...(typeof err === 'object' ? err : { details: err })
|
||||
error: typeof err === 'object' ? err.toString() : err
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
@@ -1,4 +1,4 @@
|
||||
import express from 'express'
|
||||
import express, { response } from 'express'
|
||||
import path from 'path'
|
||||
import {
|
||||
Request,
|
||||
@@ -92,12 +92,12 @@ const executeReturnRaw = async (
|
||||
)
|
||||
|
||||
return result as string
|
||||
} catch (err) {
|
||||
} catch (err: any) {
|
||||
throw {
|
||||
code: 400,
|
||||
status: 'failure',
|
||||
message: 'Job execution failed.',
|
||||
...(typeof err === 'object' ? err : { details: err })
|
||||
error: typeof err === 'object' ? err.toString() : err
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -128,11 +128,11 @@ const executeReturnJson = async (
|
||||
result: jsonResult.result,
|
||||
log: jsonResult.log
|
||||
}
|
||||
} catch (err) {
|
||||
} catch (err: any) {
|
||||
throw {
|
||||
status: 'failure',
|
||||
message: 'Job execution failed.',
|
||||
...(typeof err === 'object' ? err : { details: err })
|
||||
error: typeof err === 'object' ? err.toString() : err
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
@@ -29,7 +29,18 @@ const authenticateToken = (
|
||||
tokenType: 'accessToken' | 'refreshToken' = 'accessToken'
|
||||
) => {
|
||||
const { MODE } = process.env
|
||||
if (MODE?.trim() !== 'server') return next()
|
||||
if (MODE?.trim() !== 'server') {
|
||||
req.user = {
|
||||
userId: '1234',
|
||||
clientId: 'desktopModeClientId',
|
||||
username: 'desktopModeUsername',
|
||||
displayName: 'desktopModeDisplayName',
|
||||
isAdmin: true,
|
||||
isActive: true
|
||||
}
|
||||
req.accessToken = 'desktopModeAccessToken'
|
||||
return next()
|
||||
}
|
||||
|
||||
const authHeader = req.headers['authorization']
|
||||
const token = authHeader?.split(' ')[1]
|
||||
|
||||
@@ -1,3 +1,4 @@
|
||||
import open from 'open'
|
||||
import appPromise from './app'
|
||||
import { configuration } from '../package.json'
|
||||
|
||||
@@ -6,5 +7,9 @@ appPromise.then((app) => {
|
||||
console.log(
|
||||
`⚡️[server]: Server is running at http://localhost:${configuration.sasJsPort}`
|
||||
)
|
||||
const { MODE } = process.env
|
||||
if (MODE?.trim() !== 'server') {
|
||||
open(`http://localhost:${configuration.sasJsPort}`)
|
||||
}
|
||||
})
|
||||
})
|
||||
|
||||
@@ -81,5 +81,5 @@ export const executeProgramRawValidation = (data: any): Joi.ValidationResult =>
|
||||
Joi.object({
|
||||
_program: Joi.string().required()
|
||||
})
|
||||
.pattern(/\w\d/, Joi.string())
|
||||
.pattern(/^/, Joi.string())
|
||||
.validate(data)
|
||||
|
||||
Reference in New Issue
Block a user