hypercore-fetch 9.5.0 → 9.6.0
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/index.js +28 -6
- package/package.json +1 -1
- package/test.js +16 -0
package/index.js
CHANGED
|
@@ -367,6 +367,8 @@ export default async function makeHyperFetch ({
|
|
|
367
367
|
return { status: 403, body: `Cannot PUT file to read-only drive: ${drive.url}`, headers: { Location: request.url } }
|
|
368
368
|
}
|
|
369
369
|
|
|
370
|
+
const mtime = Date.now()
|
|
371
|
+
|
|
370
372
|
if (isFormData) {
|
|
371
373
|
// It's a form! Get the files out and process them
|
|
372
374
|
const formData = await request.formData()
|
|
@@ -377,7 +379,7 @@ export default async function makeHyperFetch ({
|
|
|
377
379
|
Readable.from(data.stream()),
|
|
378
380
|
drive.createWriteStream(filePath, {
|
|
379
381
|
metadata: {
|
|
380
|
-
mtime
|
|
382
|
+
mtime
|
|
381
383
|
}
|
|
382
384
|
})
|
|
383
385
|
)
|
|
@@ -390,18 +392,31 @@ export default async function makeHyperFetch ({
|
|
|
390
392
|
Readable.from(request.body),
|
|
391
393
|
drive.createWriteStream(pathname, {
|
|
392
394
|
metadata: {
|
|
393
|
-
mtime
|
|
395
|
+
mtime
|
|
394
396
|
}
|
|
395
397
|
})
|
|
396
398
|
)
|
|
397
399
|
}
|
|
398
400
|
}
|
|
399
401
|
|
|
400
|
-
|
|
402
|
+
const fullURL = new URL(pathname, drive.url).href
|
|
403
|
+
|
|
404
|
+
const headers = {
|
|
405
|
+
Location: request.url,
|
|
406
|
+
ETag: `${drive.version}`,
|
|
407
|
+
Link: `<${fullURL}>; rel="canonical"`,
|
|
408
|
+
[HEADER_LAST_MODIFIED]: isFormData ? undefined : new Date(mtime).toUTCString()
|
|
409
|
+
}
|
|
410
|
+
|
|
411
|
+
return { status: 201, headers }
|
|
401
412
|
}
|
|
402
413
|
|
|
403
414
|
function putFilesVersioned (request) {
|
|
404
|
-
return {
|
|
415
|
+
return {
|
|
416
|
+
status: 405,
|
|
417
|
+
body: 'Cannot PUT file to old version',
|
|
418
|
+
headers: { Location: request.url }
|
|
419
|
+
}
|
|
405
420
|
}
|
|
406
421
|
|
|
407
422
|
async function deleteFiles (request) {
|
|
@@ -433,7 +448,14 @@ export default async function makeHyperFetch ({
|
|
|
433
448
|
}
|
|
434
449
|
await drive.del(pathname)
|
|
435
450
|
|
|
436
|
-
|
|
451
|
+
const fullURL = new URL(pathname, drive.url).href
|
|
452
|
+
|
|
453
|
+
const headers = {
|
|
454
|
+
ETag: `${drive.version}`,
|
|
455
|
+
Link: `<${fullURL}>; rel="canonical"`
|
|
456
|
+
}
|
|
457
|
+
|
|
458
|
+
return { status: 200, headers }
|
|
437
459
|
}
|
|
438
460
|
|
|
439
461
|
function deleteFilesVersioned (request) {
|
|
@@ -741,7 +763,7 @@ function makeToTry (pathname) {
|
|
|
741
763
|
|
|
742
764
|
async function resolvePath (drive, pathname, noResolve) {
|
|
743
765
|
if (noResolve) {
|
|
744
|
-
const entry = drive.entry(pathname)
|
|
766
|
+
const entry = await drive.entry(pathname)
|
|
745
767
|
|
|
746
768
|
return { entry, path: pathname }
|
|
747
769
|
}
|
package/package.json
CHANGED
package/test.js
CHANGED
|
@@ -333,6 +333,22 @@ test('Ignore index.html with noResolve', async (t) => {
|
|
|
333
333
|
const entries = await listDirRequest.json()
|
|
334
334
|
t.deepEqual(entries, ['index.html'], 'able to list index.html')
|
|
335
335
|
})
|
|
336
|
+
test('Ensure that noResolve works with file paths', async (t) => {
|
|
337
|
+
const created = await nextURL(t)
|
|
338
|
+
const uploadLocation = new URL('./example.txt', created)
|
|
339
|
+
const uploadResponse = await fetch(uploadLocation, {
|
|
340
|
+
method: 'put',
|
|
341
|
+
body: SAMPLE_CONTENT
|
|
342
|
+
})
|
|
343
|
+
await checkResponse(uploadResponse, t)
|
|
344
|
+
|
|
345
|
+
const noResolve = uploadLocation.href + '?noResolve'
|
|
346
|
+
const getRequest = await fetch(noResolve)
|
|
347
|
+
await checkResponse(getRequest, t)
|
|
348
|
+
|
|
349
|
+
const headRequest = await fetch(noResolve, { method: 'HEAD' })
|
|
350
|
+
await checkResponse(headRequest, t)
|
|
351
|
+
})
|
|
336
352
|
test('Render index.gmi', async (t) => {
|
|
337
353
|
const created = await nextURL(t)
|
|
338
354
|
const uploadLocation = new URL('./index.gmi', created)
|