FazBrowse GitHub Viewer | Trending |
URL:
| Home
Tools: [Download Repo ZIP]   [Original HTTPS Page]

feat: include stat metadata in container listings by melvincarvalho · Pull Request #225 · JavaScriptSolidServer/JavaScriptSolidServer · GitHub

Repository navigation

Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension .js  (2) All 1 file type selected
Viewed files
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Unified
Split
Hide whitespace
Diff view
Unified
Split
Hide whitespace
7 changes: 6 additions & 1 deletion src/ldp/container.js
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters. Learn more about bidirectional Unicode characters
Original file line number Diff line number Diff line change
Expand Up @@ -16,15 +16,20 @@ export function generateContainerJsonLd(containerUrl, entries) {

const contains = entries.map(entry => {
const childUrl = baseUrl + entry.name + (entry.isDirectory ? '/' : '');
return {
const item = {
'@id': childUrl,
'@type': entry.isDirectory ? [`${LDP}Container`, `${LDP}BasicContainer`, `${LDP}Resource`] : [`${LDP}Resource`]
};
if (entry.size != null) item['stat:size'] = entry.size;
if (entry.modified) item['dcterms:modified'] = entry.modified;
return item;
Comment on lines 21 to +25

Copilot AI Mar 22, 2026

Copy link

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Choose a reason Spam Abuse Off Topic Outdated Duplicate Resolved Low Quality

Including per-entry stat:size / dcterms:modified changes the container listing body when a child file changes, but the GET handler’s conditional responses use an ETag derived from the directory’s stat (mtime/size). On many filesystems the directory mtime does not change when a contained file is modified, so clients can incorrectly receive 304 Not Modified for a changed listing. Consider computing the container listing ETag from the listing content (e.g., hash of sorted {name,isDirectory,size,modified}) instead of the directory stat.

Copilot uses AI. Check for mistakes.
});

return {
'@context': {
'ldp': LDP,
'stat': 'http://www.w3.org/ns/posix/stat#',
'dcterms': 'http://purl.org/dc/terms/',
'contains': { '@id': 'ldp:contains', '@type': '@id' }
},
'@id': baseUrl,
Expand Down
19 changes: 14 additions & 5 deletions src/storage/filesystem.js
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters. Learn more about bidirectional Unicode characters
Original file line number Diff line number Diff line change
Expand Up @@ -126,19 +126,28 @@ export async function createContainer(urlPath) {
}

/**
* List container contents
* List container contents with stat metadata
* @param {string} urlPath
* @returns {Promise<Array<{name: string, isDirectory: boolean}> | null>}
* @returns {Promise<Array<{name: string, isDirectory: boolean, size?: number, modified?: string}> | null>}
*/
export async function listContainer(urlPath) {
const filePath = urlToPath(urlPath);

try {
const entries = await fs.readdir(filePath, { withFileTypes: true });
return entries.map(entry => ({
name: entry.name,
isDirectory: entry.isDirectory()
const results = await Promise.all(entries.map(async (entry) => {
const result = {
name: entry.name,
isDirectory: entry.isDirectory()
};
try {
const stat = await fs.stat(path.join(filePath, entry.name));
result.size = stat.size;
result.modified = stat.mtime.toISOString();
} catch { /* stat failed, skip metadata */ }
return result;
}));
return results;
} catch {
return null;
}
Expand Down

Back | FazBrowse Home | New Git URL