mirror of
https://github.com/HeyPuter/puter.git
synced 2025-01-23 22:40:20 +08:00
dev: DRY destination node handling
This commit is contained in:
parent
6b6c295a87
commit
e840544ee0
@ -85,7 +85,31 @@ module.exports = eggspress('/writeFile', {
|
||||
if(owner_user.suspended)
|
||||
return res.status(401).send({error: 'Account suspended'});
|
||||
|
||||
const db = req.services.get('database').get(DB_WRITE, 'filesystem');
|
||||
const writeFile_handler_api = {
|
||||
async get_dest_node () {
|
||||
if(!req.body.destination_write_url){
|
||||
res.status(400).send({
|
||||
error:{
|
||||
message: 'No destination specified.'
|
||||
}
|
||||
});
|
||||
return;
|
||||
}
|
||||
try{
|
||||
validate_signature_auth(req.body.destination_write_url, 'write');
|
||||
}catch(e){
|
||||
res.status(403).send(e);
|
||||
return;
|
||||
}
|
||||
try {
|
||||
return await (new FSNodeParam('dest_path')).consolidate({
|
||||
req, getParam: () => req.body.dest_path ?? req.body.destination_uid
|
||||
});
|
||||
} catch (e) {
|
||||
res.status(500).send('Internal Server Error');
|
||||
}
|
||||
}
|
||||
};
|
||||
|
||||
const writeFile_handlers = require('./writeFile/writeFile_handlers.js');
|
||||
if ( writeFile_handlers.hasOwnProperty(req.query.operation) ) {
|
||||
@ -98,6 +122,7 @@ module.exports = eggspress('/writeFile', {
|
||||
|
||||
return await Context.get().sub({ actor: Actor.adapt(user) }).arun(async () => {
|
||||
return await writeFile_handlers[req.query.operation]({
|
||||
api: writeFile_handler_api,
|
||||
req, res, actor,
|
||||
node,
|
||||
});
|
||||
|
@ -3,35 +3,19 @@ const { HLCopy } = require('../../filesystem/hl_operations/hl_copy');
|
||||
const { validate_signature_auth } = require('../../helpers');
|
||||
|
||||
module.exports = async function writeFile_handle_copy ({
|
||||
api,
|
||||
req, res, actor, node,
|
||||
}) {
|
||||
|
||||
// check if destination_write_url provided
|
||||
if(!req.body.destination_write_url){
|
||||
return res.status(400).send({
|
||||
error:{
|
||||
message: 'No destination specified.'
|
||||
}
|
||||
})
|
||||
}
|
||||
|
||||
// check if destination_write_url is valid
|
||||
try{
|
||||
validate_signature_auth(req.body.destination_write_url, 'write');
|
||||
}catch(e){
|
||||
console.log('REALLY THIS ONE')
|
||||
return res.status(403).send(e);
|
||||
}
|
||||
const dest_node = await api.get_dest_node();
|
||||
if ( ! dest_node ) return;
|
||||
|
||||
const overwrite = req.body.overwrite ?? false;
|
||||
const change_name = req.body.auto_rename ?? false;
|
||||
|
||||
// TODO: [fs:operation:param-coercion]
|
||||
const dest_node = await (new FSNodeParam('dest_path')).consolidate({
|
||||
req, getParam: () => req.body.dest_path ?? req.body.destination_uid
|
||||
});
|
||||
|
||||
// Get user
|
||||
const opts = {
|
||||
source: node,
|
||||
destination_or_parent: dest_node,
|
||||
|
@ -3,6 +3,7 @@ const { HLMove } = require("../../filesystem/hl_operations/hl_move");
|
||||
const { validate_signature_auth } = require("../../helpers");
|
||||
|
||||
module.exports = async function writeFile_handle_move ({
|
||||
api,
|
||||
req, res, actor, node,
|
||||
}) {
|
||||
// check if destination_write_url provided
|
||||
@ -14,20 +15,11 @@ module.exports = async function writeFile_handle_move ({
|
||||
})
|
||||
}
|
||||
|
||||
// check if destination_write_url is valid
|
||||
try{
|
||||
validate_signature_auth(req.body.destination_write_url, 'write');
|
||||
}catch(e){
|
||||
return res.status(403).send(e);
|
||||
}
|
||||
const dest_node = await api.get_dest_node();
|
||||
if ( ! dest_node ) return;
|
||||
|
||||
const hl_move = new HLMove();
|
||||
|
||||
// TODO: [fs:operation:param-coercion]
|
||||
const dest_node = await (new FSNodeParam('dest_path')).consolidate({
|
||||
req, getParam: () => req.body.dest_path ?? req.body.destination_uid
|
||||
});
|
||||
|
||||
const opts = {
|
||||
user: actor.type.user,
|
||||
source: node,
|
||||
|
Loading…
Reference in New Issue
Block a user