MCPcopy Index your code
hub / github.com/nodeSolidServer/node-solid-server / addFile

Function addFile

lib/ldp-container.mjs:33–113  ·  view source on GitHub ↗
(ldp, resourceGraph, containerUri, reqUri, container, file)

Source from the content-addressed store, hash-verified

31}
32
33async function addFile (ldp, resourceGraph, containerUri, reqUri, container, file) {
34 // Skip .meta and .acl
35 if (file.endsWith(ldp.suffixMeta) || file.endsWith(ldp.suffixAcl)) {
36 return null
37 }
38
39 const filePath = path.join(container, file)
40
41 // Get file stats
42 let stats
43 try {
44 stats = await ldp.stat(filePath)
45 } catch (e) {
46 return null
47 }
48 const memberUri = reqUri + (stats.isDirectory() ? '/' : '')
49
50 // Add fileStats to resource Graph
51 addStats(resourceGraph, memberUri, stats, file)
52
53 // Add to `contains` list
54 resourceGraph.add(
55 resourceGraph.sym(containerUri),
56 ns.ldp('contains'),
57 resourceGraph.sym(memberUri))
58
59 // Set up a metaFile path
60 // Earlier code used a .ttl file as its own meta file, which
61 // caused massive data files to parsed as part of deirectory listings just looking for type triples
62 const metaFile = containerUri + file + ldp.suffixMeta
63
64 let metadataGraph
65 try {
66 metadataGraph = await getMetadataGraph(ldp, metaFile, memberUri)
67 } catch (err) {
68 metadataGraph = $rdf.graph()
69 }
70
71 // Add Container or BasicContainer types
72 if (stats.isDirectory()) {
73 resourceGraph.add(
74 metadataGraph.sym(memberUri),
75 ns.rdf('type'),
76 ns.ldp('BasicContainer'))
77
78 resourceGraph.add(
79 metadataGraph.sym(memberUri),
80 ns.rdf('type'),
81 ns.ldp('Container'))
82 }
83 // Add generic LDP type
84 resourceGraph.add(
85 metadataGraph.sym(memberUri),
86 ns.rdf('type'),
87 ns.ldp('Resource'))
88
89 // Add type from metadataGraph
90 metadataGraph

Callers

nothing calls this directly

Calls 4

addStatsFunction · 0.85
getMetadataGraphFunction · 0.85
statMethod · 0.80
graphMethod · 0.80

Tested by

no test coverage detected