diff --git a/src/classes/PermanentFileSystem.ts b/src/classes/PermanentFileSystem.ts index d92e63c3..10663a1a 100644 --- a/src/classes/PermanentFileSystem.ts +++ b/src/classes/PermanentFileSystem.ts @@ -10,6 +10,7 @@ import { } from '@permanentorg/sdk'; import { deduplicateFileEntries, + generateAttributesForArchive, generateAttributesForFile, generateAttributesForFolder, generateDefaultAttributes, @@ -110,10 +111,15 @@ export class PermanentFileSystem { public async getItemAttributes(itemPath: string): Promise { if (isRootPath(itemPath) - || isArchiveCataloguePath(itemPath) - || isArchivePath(itemPath)) { + || isArchiveCataloguePath(itemPath)) { return generateDefaultAttributes(fs.constants.S_IFDIR); } + + if (isArchivePath(itemPath)) { + const archive = await this.loadArchive(itemPath); + return generateAttributesForArchive(archive); + } + const fileType = await this.getItemType(itemPath); switch (fileType) { case fs.constants.S_IFREG: { @@ -302,6 +308,14 @@ export class PermanentFileSystem { return archiveFolders; } + private async loadArchive(requestedPath: string): Promise { + if (!isArchivePath(requestedPath)) { + throw new Error('The requested path is not an archive'); + } + const archiveSlug = getArchiveSlugFromPath(requestedPath); + return this.loadArchiveByArchiveSlug(archiveSlug); + } + private async loadFolder(requestedPath: string, overrideCache = false): Promise { const cachedFolder = this.folderCache.get(requestedPath); if (cachedFolder && !overrideCache) { @@ -337,7 +351,7 @@ export class PermanentFileSystem { const archives = await this.loadArchives(); return archives.map((archive: Archive) => generateFileEntry( `${archive.name} (${archive.slug})`, - generateDefaultAttributes(fs.constants.S_IFDIR), + generateAttributesForArchive(archive), )); } @@ -346,7 +360,7 @@ export class PermanentFileSystem { const folders = await this.loadArchiveFolders(archiveId); return folders.map((archiveFolder) => generateFileEntry( `${archiveFolder.fileSystemCompatibleName}`, - generateDefaultAttributes(fs.constants.S_IFDIR), + generateAttributesForFolder(archiveFolder), )); } diff --git a/src/utils/generateAttributesForArchive.ts b/src/utils/generateAttributesForArchive.ts new file mode 100644 index 00000000..796874db --- /dev/null +++ b/src/utils/generateAttributesForArchive.ts @@ -0,0 +1,13 @@ +import fs from 'fs'; +import { generateDefaultMode } from './generateDefaultMode'; +import type { Attributes } from 'ssh2'; +import type { Archive } from '@permanentorg/sdk'; + +export const generateAttributesForArchive = (archive: Archive): Attributes => ({ + mode: generateDefaultMode(fs.constants.S_IFDIR), + uid: 0, + gid: 0, + size: 0, + atime: 0, + mtime: archive.updatedAt.getTime() / 1000, +}); diff --git a/src/utils/generateAttributesForFile.ts b/src/utils/generateAttributesForFile.ts index 37304891..65a64f59 100644 --- a/src/utils/generateAttributesForFile.ts +++ b/src/utils/generateAttributesForFile.ts @@ -12,7 +12,7 @@ export const generateAttributesForFile = (file?: File): Attributes => ( gid: 0, size: file.size, atime: 0, - mtime: file.updatedAt.getTime(), + mtime: file.updatedAt.getTime() / 1000, } : generateDefaultAttributes(fs.constants.S_IFREG) ); diff --git a/src/utils/generateAttributesForFolder.ts b/src/utils/generateAttributesForFolder.ts index 02827e90..65346a8b 100644 --- a/src/utils/generateAttributesForFolder.ts +++ b/src/utils/generateAttributesForFolder.ts @@ -9,5 +9,5 @@ export const generateAttributesForFolder = (folder: Folder): Attributes => ({ gid: 0, size: folder.size, atime: 0, - mtime: folder.updatedAt.getTime(), + mtime: folder.updatedAt.getTime() / 1000, }); diff --git a/src/utils/index.ts b/src/utils/index.ts index b9e66e4d..5db76ec3 100644 --- a/src/utils/index.ts +++ b/src/utils/index.ts @@ -1,4 +1,5 @@ export * from './deduplicateFileEntries'; +export * from './generateAttributesForArchive'; export * from './generateAttributesForFile'; export * from './generateAttributesForFolder'; export * from './generateDefaultAttributes';