Skip to content

Commit 1859144

Browse files
committed
serialize to jsonld
1 parent 6aa3ae0 commit 1859144

File tree

5 files changed

+3728
-12737
lines changed

5 files changed

+3728
-12737
lines changed

lib/handlers/patch.js

Lines changed: 25 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -177,23 +177,34 @@ function writeGraph (graph, resource, root, serverUri) {
177177
debug('PATCH -- Writing patched file')
178178
return new Promise((resolve, reject) => {
179179
const resourceSym = graph.sym(resource.url)
180-
const serialized = $rdf.serialize(resourceSym, graph, resource.url, resource.contentType)
181180

182-
// First check if we are above quota
183-
overQuota(root, serverUri).then((isOverQuota) => {
184-
if (isOverQuota) {
185-
return reject(error(413,
186-
'User has exceeded their storage quota'))
187-
}
188-
189-
fs.writeFile(resource.path, serialized, { encoding: 'utf8' }, function (err) {
190-
if (err) {
191-
return reject(error(500, `Failed to write file after patch: ${err}`))
181+
function doWrite (serialized) {
182+
// First check if we are above quota
183+
overQuota(root, serverUri).then((isOverQuota) => {
184+
if (isOverQuota) {
185+
return reject(error(413,
186+
'User has exceeded their storage quota'))
192187
}
193-
debug('PATCH -- applied successfully')
194-
resolve('Patch applied successfully.\n')
188+
189+
fs.writeFile(resource.path, serialized, { encoding: 'utf8' }, function (err) {
190+
if (err) {
191+
return reject(error(500, `Failed to write file after patch: ${err}`))
192+
}
193+
debug('PATCH -- applied successfully')
194+
resolve('Patch applied successfully.\n')
195+
})
196+
}).catch(() => reject(error(500, 'Error finding user quota')))
197+
}
198+
199+
if (resource.contentType === 'application/ld+json') {
200+
$rdf.serialize(resourceSym, graph, resource.url, resource.contentType, function (err, result) {
201+
if (err) return reject(error(500, `Failed to serialize after patch: ${err}`))
202+
doWrite(result)
195203
})
196-
}).catch(() => reject(error(500, 'Error finding user quota')))
204+
} else {
205+
const serialized = $rdf.serialize(resourceSym, graph, resource.url, resource.contentType)
206+
doWrite(serialized)
207+
}
197208
})
198209
}
199210

lib/resource-mapper.js

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -149,7 +149,7 @@ class ResourceMapper {
149149

150150
// encode/decode path except slash (/) / %encodedSlash (%2F|%2f) /ntimes%encodedSlash (%2525...2F|%2525...2f)
151151
// see https://github.com/solid/node-solid-server/issues/1666
152-
_exceptSlash () { return /(\/|%(?:25)*(?:2[Ff]))/g }
152+
_exceptSlash () { return /(\/|%(?:25)*(?:2f))/gi }
153153

154154
_encodePath (pathname) {
155155
return pathname.split(this._exceptSlash())

0 commit comments

Comments
 (0)