Fix /file and /setItem

This commit is contained in:
KernelDeimos
2024-04-03 17:20:49 -04:00
parent 5fab338ba1
commit 274b69d017
3 changed files with 17 additions and 31 deletions

View File

@@ -40,6 +40,10 @@ router.get('/file', async (req, res, next)=>{
return res.status(403).send(e);
}
const log = req.services.get('log-service').create('/file');
const errors = req.services.get('error-service').create(log);
// modules
const db = req.services.get('database').get(DB_WRITE, 'filesystem');
const mime = require('mime-types')
@@ -113,13 +117,17 @@ router.get('/file', async (req, res, next)=>{
// stream data from S3
try{
let stream = await storage.create_read_stream({
key: fsentry[0].uuid,
let stream = await storage.create_read_stream(fsentry[0].uuid, {
bucket: fsentry[0].bucket,
bucket_region: fsentry[0].bucket_region,
});
return stream.pipe(res);
}catch(e){
errors.report('read from storage', {
source: e,
trace: true,
alarm: true,
});
return res.type('application/json').status(500).send({message: 'There was an internal problem reading the file.'});
}
}
@@ -175,14 +183,17 @@ router.get('/file', async (req, res, next)=>{
});
try{
let stream = await storage.create_read_stream({
key: fsentry[0].uuid,
let stream = await storage.create_read_stream(fsentry[0].uuid, {
bucket: fsentry[0].bucket,
bucket_region: fsentry[0].bucket_region,
});
return stream.pipe(res);
}catch(e){
console.log(e)
errors.report('read from storage', {
source: e,
trace: true,
alarm: true,
});
return res.type('application/json').status(500).send({message: 'There was an internal problem reading the file.'});
}
}

View File

@@ -101,6 +101,7 @@ router.get('/get-launch-apps', auth, express.json(), async (req, res, next)=>{
'plushie-connect',
'hex-frvr',
'spider-solitaire',
'test',
]
// Prepare each app for returning to user by only returning the necessary fields

View File

@@ -56,32 +56,6 @@ router.post('/setItem', auth, express.json(), async (req, res, next)=>{
else if(req.body.app && !await app_exists({uid: req.body.app}))
return res.status(400).send('`app` does not exist');
// hash key for faster search in DB
const murmurhash = require('murmurhash')
const key_hash = murmurhash.v3(req.body.key);
// database connection
const db = require('../../db/mysql.js');
// insert into DB (in case the row isn't migrated yet)
await db.promise().execute(
`INSERT INTO kv
(user_id, app, kkey_hash, kkey, value)
VALUES
(?, ?, ?, ?, ?)
ON DUPLICATE KEY UPDATE
value = ?`,
[
req.user.id,
// 0 is reserved for global system variables
req.body.app ?? 'global',
key_hash,
String(req.body.key),
String(req.body.value),
String(req.body.value),
]
)
// insert into KV 1
const actor = req.body.app
? await Actor.create(AppUnderUserActorType, {