@tus/server
Advanced tools
Comparing version 1.6.0 to 1.7.0
@@ -53,6 +53,7 @@ "use strict"; | ||
getFileIdFromRequest(req) { | ||
const match = reExtractFileID.exec(req.url); | ||
if (this.options.getFileIdFromRequest) { | ||
return this.options.getFileIdFromRequest(req); | ||
const lastPath = match ? decodeURIComponent(match[1]) : undefined; | ||
return this.options.getFileIdFromRequest(req, lastPath); | ||
} | ||
const match = reExtractFileID.exec(req.url); | ||
if (!match || this.options.path.includes(match[1])) { | ||
@@ -59,0 +60,0 @@ return; |
@@ -48,3 +48,3 @@ /// <reference types="node" /> | ||
*/ | ||
getFileIdFromRequest?: (req: http.IncomingMessage) => string | void; | ||
getFileIdFromRequest?: (req: http.IncomingMessage, lastPath?: string) => string | void; | ||
/** | ||
@@ -51,0 +51,0 @@ * Control how you want to name files. |
{ | ||
"$schema": "https://json.schemastore.org/package.json", | ||
"name": "@tus/server", | ||
"version": "1.6.0", | ||
"version": "1.7.0", | ||
"description": "Tus resumable upload protocol in Node.js", | ||
@@ -24,3 +24,3 @@ "main": "dist/index.js", | ||
"dependencies": { | ||
"@tus/utils": "^0.2.0", | ||
"@tus/utils": "^0.3.0", | ||
"debug": "^4.3.4", | ||
@@ -27,0 +27,0 @@ "lodash.throttle": "^4.1.1" |
@@ -109,5 +109,8 @@ # `@tus/server` | ||
Control how the Upload-ID is extracted from the request (`(req) => string | void`) By | ||
default, it expects everything in the path after the last `/` to be the upload id. | ||
Control how the Upload-ID is extracted from the request | ||
(`(req, lastPath) => string | void`) | ||
By default, it expects everything in the path after the last `/` to be the upload id. | ||
`lastPath` is everything after the last `/`. | ||
Checkout the example how to | ||
@@ -161,3 +164,4 @@ [store files in custom nested directories](#example-store-files-in-custom-nested-directories). | ||
`onUploadFinish` will be invoked after an upload is completed but before a response is | ||
returned to the client (`(req, res, upload) => Promise<{ res: http.ServerResponse, status_code?: number, headers?: Record<string, string | number>, body?: string }>`). | ||
returned to the client | ||
(`(req, res, upload) => Promise<{ res: http.ServerResponse, status_code?: number, headers?: Record<string, string | number>, body?: string }>`). | ||
@@ -259,4 +263,5 @@ - You can optionally return `status_code`, `headers` and `body` to modify the response. | ||
This means you are not guaranteed to get (all) events for an upload. For instance if | ||
`postReceiveInterval` is set to 1000ms and an PATCH request takes 500ms, no event is emitted. | ||
If the PATCH request takes 2500ms, you would get the offset at 2000ms, but not at 2500ms. | ||
`postReceiveInterval` is set to 1000ms and an PATCH request takes 500ms, no event is | ||
emitted. If the PATCH request takes 2500ms, you would get the offset at 2000ms, but not at | ||
2500ms. | ||
@@ -549,14 +554,9 @@ Use `POST_FINISH` if you need to know when an upload is done. | ||
}, | ||
getFileIdFromRequest(req) { | ||
const reExtractFileID = /([^/]+)\/?$/ | ||
const match = reExtractFileID.exec(req.url as string) | ||
if (!match || path.includes(match[1])) { | ||
return | ||
} | ||
return Buffer.from(match[1], 'base64url').toString('utf-8') | ||
getFileIdFromRequest(req, lastPath) { | ||
// lastPath is everything after the last `/` | ||
// If your custom URL is different, this might be undefined | ||
// and you need to extract the ID yourself | ||
return Buffer.from(lastPath, 'base64url').toString('utf-8') | ||
}, | ||
}) | ||
``` | ||
@@ -563,0 +563,0 @@ |
License Policy Violation
LicenseThis package is not allowed per your license policy. Review the package's license to ensure compliance.
Found 1 instance in 1 package
License Policy Violation
LicenseThis package is not allowed per your license policy. Review the package's license to ensure compliance.
Found 1 instance in 1 package
86230
29
1445
+ Added@tus/utils@0.3.0(transitive)
- Removed@tus/utils@0.2.0(transitive)
Updated@tus/utils@^0.3.0