MISC: Add file metadata (timestamps) (#2199)

This commit is contained in:
catloversg
2025-06-17 06:34:06 +07:00
committed by GitHub
parent e5bfa641e1
commit a794fddaf7
19 changed files with 297 additions and 30 deletions
+12
View File
@@ -1402,6 +1402,18 @@ export const ns: InternalAPI<NSFull> = {
const server = ctx.workerScript.getServer();
return server.getContentFile(path)?.content ?? "";
},
getFileMetadata: (ctx) => (_filename) => {
const path = helpers.filePath(ctx, "filename", _filename);
if (!hasScriptExtension(path) && !hasTextExtension(path)) {
throw new Error(`Invalid path: ${_filename}. It must be a text file or a script.`);
}
const server = ctx.workerScript.getServer();
const contentFile = server.getContentFile(path);
if (!contentFile) {
throw new Error(`Invalid path: ${_filename}. The file does not exist on ${server.hostname}.`);
}
return contentFile.metadata.plain();
},
peek: (ctx) => (_portNumber) => {
const portNumber = helpers.portNumber(ctx, _portNumber);
return peekPort(portNumber);