mirror of
https://github.com/HeyPuter/puter.git
synced 2026-03-08 18:50:47 -05:00
Fix /file and /setItem
This commit is contained in:
@@ -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.'});
|
||||
}
|
||||
}
|
||||
|
||||
@@ -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
|
||||
|
||||
@@ -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, {
|
||||
|
||||
Reference in New Issue
Block a user