Skip to content

Commit

Permalink
Merge pull request #101 from solid-contrib/containerMetadata
Browse files Browse the repository at this point in the history
container representation metadata
  • Loading branch information
jeff-zucker authored Mar 3, 2024
2 parents 21e77e2 + d3c0a55 commit be5a7e0
Show file tree
Hide file tree
Showing 2 changed files with 20 additions and 15 deletions.
18 changes: 11 additions & 7 deletions core/src/utils/container.js
Original file line number Diff line number Diff line change
Expand Up @@ -19,11 +19,11 @@ export default async function containerAsTurtle(pathname, contentsArray, typeWan
@prefix dct: <http://purl.org/dc/terms/>.
@prefix stat: <http://www.w3.org/ns/posix/stat#>.
@prefix xsd: <http://www.w3.org/2001/XMLSchema#>.
<> a ldp:BasicContainer, ldp:Container
`;
<> a ldp:BasicContainer, ldp:Container`;

if (filenames.length) {
str = str + "; ldp:contains\n";
str = str + ";\n ldp:contains\n"; // alain

for (var i = 0; i < filenames.length; i++) {
let fn = filenames[i].path;
Expand All @@ -43,16 +43,20 @@ export default async function containerAsTurtle(pathname, contentsArray, typeWan
modified = i.modified;
}
catch(e){console.log(e)}
} else if (filenames[i].metadata) {
size = filenames[i].metadata.size
mtime = filenames[i].metadata.mtimeMs
modified = new Date(mtime).toISOString()
}
ctype = ctype || await self.getContentType(fn, ftype) || "";
// REMOVE CHARSET FROM CONTENT-TYPE
ctype = ctype.replace(/;.*/, '');
ftype = filenames[i].isContainer ? "ldp:Container; a ldp:BasicContainer; a ldp:Resource" : "ldp:Resource";
str2 = str2 + `<${fn}> a ${ftype}.\n`;
if(ctype)
str2 = str2 + `<${fn}> a <http://www.w3.org/ns/iana/media-types/${ctype}#Resource>.\n`; // str2 = str2 + `<${fn}> :type "${ctype}".\n`
str2 = str2 + `<${fn}> a ${ftype}`;
if(ctype && !filenames[i].isContainer) // no media-type for Container
str2 = str2 + `, <http://www.w3.org/ns/iana/media-types/${ctype}#Resource>`; // str2 = str2 + `<${fn}> :type "${ctype}".\n`
if(size){
str2 = str2 + `<${fn}> stat:size ${size}; stat:mtime ${mtime}; dct:"${modified}"^^xsd:dateTime.\n`
str2 = str2 + `;\n stat:size ${size};\n stat:mtime ${mtime};\n dct:modified "${modified}"^^xsd:dateTime.\n`
}
}

Expand Down
17 changes: 9 additions & 8 deletions file/src/index.js
Original file line number Diff line number Diff line change
Expand Up @@ -54,7 +54,7 @@ export class SolidRestFile {
/**
* check if thing is Container or Resource
* @param filePath
* @return "Container" | "Resource" | null
* @return { type: "Container"|"Resource", metadata: stat } | {}
*/


Expand All @@ -65,13 +65,13 @@ export class SolidRestFile {
stat = await fs.lstatSync(path);
} catch (err) {}

if (!stat) return null;
if (!stat) return {};
if (stat.isSymbolicLink()) {
return "Container";
return { type: "Container", metadata: stat };
};
if (stat.isDirectory()) return "Container";
if (stat.isFile()) return "Resource";
return null;
if (stat.isDirectory()) return { type: "Container", metadata: stat };
if (stat.isFile()) return { type: "Resource", metadata: stat };
return {};
}
/**
* read a folder
Expand Down Expand Up @@ -112,7 +112,7 @@ export class SolidRestFile {
fn = fn.replace(/^file:\/\//, '');
let mimetype = await mime.lookup(fn); // mimetype from ext

let type = await this.itemType(fn); // Container/Resource
const { type, metadata } = await this.itemType(fn); // Container/Resource and metadata

let exists = await this.itemExists(fn);
if (!type && fn.endsWith('/')) type = "Container";
Expand Down Expand Up @@ -145,7 +145,8 @@ export class SolidRestFile {
exists: exists,
isContainer: type === "Container" ? true : false,
mimetype: mimetype,
contentType: mimetype
contentType: mimetype,
metadata: metadata
};
return Promise.resolve(item);
}
Expand Down

0 comments on commit be5a7e0

Please sign in to comment.