diff --git a/src/backend/src/routers/filesystem_api/readdir.js b/src/backend/src/routers/filesystem_api/readdir.js index 34503eca2..bbfda4b87 100644 --- a/src/backend/src/routers/filesystem_api/readdir.js +++ b/src/backend/src/routers/filesystem_api/readdir.js @@ -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; diff --git a/src/puter-js/src/modules/FileSystem/index.js b/src/puter-js/src/modules/FileSystem/index.js index 300c2b7fb..ae3ea06ec 100644 --- a/src/puter-js/src/modules/FileSystem/index.js +++ b/src/puter-js/src/modules/FileSystem/index.js @@ -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); - } - }, } /** diff --git a/src/puter-js/src/modules/FileSystem/operations/readdir.js b/src/puter-js/src/modules/FileSystem/operations/readdir.js index 6f4f3b097..3e6051000 100644 --- a/src/puter-js/src/modules/FileSystem/operations/readdir.js +++ b/src/puter-js/src/modules/FileSystem/operations/readdir.js @@ -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)); }) }