list keyframes
This commit is contained in:
+48
-2
@@ -3,12 +3,54 @@ import { uuidv7obj, UUID } from "uuidv7"
|
|||||||
|
|
||||||
|
|
||||||
export const mappings = [
|
export const mappings = [
|
||||||
|
{ method: 'post', url:'/keyframes', handler: 'listKeyframes', middlewares: [authGuard]},
|
||||||
{ method: 'put', url:'/keyframes', handler: 'createKeyframe', middlewares: [authGuard]},
|
{ method: 'put', url:'/keyframes', handler: 'createKeyframe', middlewares: [authGuard]},
|
||||||
{ method: 'put', url:'/keyframes/:kfid', handler: 'renameKeyframe', middlewares: [authGuard]},
|
{ method: 'put', url:'/keyframes/:kfid', handler: 'renameKeyframe', middlewares: [authGuard]},
|
||||||
{ method: 'put', url:'/keyframes/:kfid/agents', handler: 'saveKeyframeAgents', middlewares: [authGuard]},
|
{ method: 'put', url:'/keyframes/:kfid/agents', handler: 'saveKeyframeAgents', middlewares: [authGuard]},
|
||||||
]
|
]
|
||||||
|
|
||||||
export const methods = {
|
export const methods = {
|
||||||
|
|
||||||
|
async listKeyframes(req, res) {
|
||||||
|
const[isOk, payload, errors] = this.utils.validateMapObject(req.body,
|
||||||
|
{
|
||||||
|
'kfId': ((val, obj) => ( (typeof(val)=='undefined') || (this.utils.isValidUUIDV7(val)) ) ),
|
||||||
|
'prevKfId': ((val, obj) => ( (val===null) || (typeof(val)=='undefined') || (this.utils.isValidUUIDV7(val)) ) ),
|
||||||
|
},
|
||||||
|
{
|
||||||
|
'kfId': 'kfId',
|
||||||
|
'prevKfId': 'prevKfId',
|
||||||
|
})
|
||||||
|
if(!isOk){
|
||||||
|
this.err(req, res,`Cannot filter on these criteria ! `, `Validations errors for listing KF : ${errors.join(', ')}`, 400)
|
||||||
|
return
|
||||||
|
}
|
||||||
|
|
||||||
|
const conditions = []
|
||||||
|
const params = []
|
||||||
|
|
||||||
|
if (payload.kfid !== undefined) {
|
||||||
|
conditions.push('ekf_uuid = UUID_TO_BIN(?)')
|
||||||
|
params.push(kfid)
|
||||||
|
}
|
||||||
|
|
||||||
|
if(payload.prevKfId !== undefined) {
|
||||||
|
if(payload.prevKfId === null) {
|
||||||
|
conditions.push('ekf_prev_uuid IS NULL')
|
||||||
|
} else {
|
||||||
|
conditions.push('ekf_prev_uuid = UUID_TO_BIN(?)')
|
||||||
|
params.push(payload.prevKfId)
|
||||||
|
}
|
||||||
|
}
|
||||||
|
const whereClause = conditions.length ? 'WHERE ' + conditions.join(' AND ') : ''
|
||||||
|
|
||||||
|
const results = await this.db.execute(`
|
||||||
|
SELECT BIN_TO_UUID(ekf_uuid) AS ekf_uuid, ekf_name, BIN_TO_UUID(ekf_prev_uuid) AS ekf_prev_uuid
|
||||||
|
FROM p42SIM.edited_keyframes ${whereClause}`, params)
|
||||||
|
|
||||||
|
this.ok(req, res, results)
|
||||||
|
},
|
||||||
|
|
||||||
async createKeyframe(req, res) {
|
async createKeyframe(req, res) {
|
||||||
const[isOk, payload, errors] = this.utils.validateMapObject(req.body,
|
const[isOk, payload, errors] = this.utils.validateMapObject(req.body,
|
||||||
{
|
{
|
||||||
@@ -55,13 +97,17 @@ export const methods = {
|
|||||||
return
|
return
|
||||||
}
|
}
|
||||||
|
|
||||||
await this.db.execute(`
|
const [result] = await this.db.execute(`
|
||||||
UPDATE p42SIM.edited_keyframes
|
UPDATE p42SIM.edited_keyframes
|
||||||
SET ekf_name = ?
|
SET ekf_name = ?
|
||||||
WHERE (ekf_uuid = ?)`,
|
WHERE (ekf_uuid = ?)`,
|
||||||
[payload.kfName, UUID.parse(kfid).bytes])
|
[payload.kfName, UUID.parse(kfid).bytes])
|
||||||
|
|
||||||
this.ok(req, res, { kfId: kfid })
|
if (result.affectedRows === 0) {
|
||||||
|
this.err(req, res,`Cannot rename this keyframe ! `, `Non-existin kfId: (${UUID.parse(kfid).toString()})`, 400)
|
||||||
|
} else {
|
||||||
|
this.ok(req, res, { kfId: kfid })
|
||||||
|
}
|
||||||
},
|
},
|
||||||
|
|
||||||
async saveKeyframeAgents(req, res) {
|
async saveKeyframeAgents(req, res) {
|
||||||
|
|||||||
@@ -29,16 +29,7 @@ const mysqlCreds = {
|
|||||||
queueLimit: 0
|
queueLimit: 0
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
const db = await mysql.createConnection(mysqlCreds)
|
const db = await mysql.createConnection(mysqlCreds)
|
||||||
// {
|
|
||||||
// host: mysqlCreds.host,
|
|
||||||
// port: mysqlCreds.port,
|
|
||||||
// socketPath: mysqlCreds.socketPath,
|
|
||||||
// database: mysqlCreds.database,
|
|
||||||
// user: mysqlCreds.user,
|
|
||||||
// password: mysqlCreds.password
|
|
||||||
// });
|
|
||||||
|
|
||||||
const sessionStore = new MySQLStore({
|
const sessionStore = new MySQLStore({
|
||||||
createDatabaseTable: false,
|
createDatabaseTable: false,
|
||||||
|
|||||||
Reference in New Issue
Block a user