Make readdir workd with uid in addition to path

This commit is contained in:
Nariman Jelveh
2025-09-15 20:12:45 -07:00
parent d482d7cdf5
commit e4c2581623
3 changed files with 23 additions and 17 deletions
@@ -33,9 +33,12 @@ module.exports = eggspress('/readdir', {
fs: true,
json: true,
allowedMethods: ['POST'],
alias: { uid: 'path' },
alias: {
path: 'subject',
uid: 'subject',
},
parameters: {
subject: new FSNodeParam('path'),
subject: new FSNodeParam('subject'),
recursive: new FlagParam('recursive', { optional: true }),
no_thumbs: new FlagParam('no_thumbs', { optional: true }),
no_assocs: new FlagParam('no_assocs', { optional: true }),
@@ -46,7 +49,7 @@ module.exports = eggspress('/readdir', {
log = x.get('services').get('log-service').create('readdir', {
concern: 'filesystem',
});
log.info(`readdir: ${req.body.path}`);
log.info(`readdir: ${req.body.subject || req.body.path || req.body.uid}`);
}
const subject = req.values.subject;
+2 -8
View File
@@ -11,6 +11,7 @@ import move from "./operations/move.js";
import write from "./operations/write.js";
import sign from "./operations/sign.js";
import symlink from './operations/symlink.js';
import readdir from './operations/readdir.js';
// Why is this called deleteFSEntry instead of just delete? because delete is
// a reserved keyword in javascript
import deleteFSEntry from "./operations/deleteFSEntry.js";
@@ -34,6 +35,7 @@ export class PuterJSFileSystemModule extends AdvancedBase {
sign = sign;
symlink = symlink;
getReadURL = getReadURL;
readdir = readdir;
FSItem = FSItem
@@ -46,14 +48,6 @@ export class PuterJSFileSystemModule extends AdvancedBase {
return svc_fs.filesystem.stat(parameters);
}
},
readdir: {
positional: ['path'],
firstarg_options: true,
async fn (parameters) {
const svc_fs = await this.context.services.aget('filesystem');
return svc_fs.filesystem.readdir(parameters);
}
},
}
/**
@@ -17,9 +17,9 @@ const readdir = async function (...args) {
}
return new Promise(async (resolve, reject) => {
// path is required
if(!options.path){
throw new Error({ code: 'NO_PATH', message: 'No path provided.' });
// Either path or uid is required
if(!options.path && !options.uid){
throw new Error({ code: 'NO_PATH_OR_UID', message: 'Either path or uid must be provided.' });
}
// If auth token is not provided and we are in the web environment,
@@ -39,11 +39,20 @@ const readdir = async function (...args) {
// set up event handlers for load and error events
utils.setupXhrEventHandlers(xhr, options.success, options.error, resolve, reject);
xhr.send(JSON.stringify({
path: getAbsolutePathForApp(options.path),
// Build request payload - support both path and uid parameters
const payload = {
no_thumbs: options.no_thumbs,
no_assocs: options.no_assocs,
}));
};
// Add either uid or path to the payload
if (options.uid) {
payload.uid = options.uid;
} else if (options.path) {
payload.path = getAbsolutePathForApp(options.path);
}
xhr.send(JSON.stringify(payload));
})
}