@lumeweb/pinner 0.1.7 → 0.1.8
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.
|
@@ -1,13 +1,11 @@
|
|
|
1
1
|
import { UploadResultSymbol } from "../types/upload.js";
|
|
2
2
|
import { UPLOAD_SOURCE_TUS } from "./constants.js";
|
|
3
3
|
import { BaseUploadHandler } from "./base-upload.js";
|
|
4
|
-
import { patchTusNodeHttpStack } from "../utils/tus-patch.js";
|
|
5
4
|
import TusPlugin from "@uppy/tus";
|
|
6
5
|
|
|
7
6
|
//#region src/upload/tus-upload.ts
|
|
8
7
|
var TUSUploadHandler = class extends BaseUploadHandler {
|
|
9
8
|
constructor(config) {
|
|
10
|
-
patchTusNodeHttpStack();
|
|
11
9
|
super(config);
|
|
12
10
|
}
|
|
13
11
|
configurePlugin(uppy) {
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"tus-upload.js","names":[],"sources":["../../../src/upload/tus-upload.ts"],"sourcesContent":["import Uppy from \"@uppy/core\";\nimport TusPlugin from \"@uppy/tus\";\nimport type { UploadResult } from \"@/types/upload\";\nimport { UploadResultSymbol } from \"@/types/upload\";\nimport { BaseUploadHandler } from \"./base-upload\";\nimport
|
|
1
|
+
{"version":3,"file":"tus-upload.js","names":[],"sources":["../../../src/upload/tus-upload.ts"],"sourcesContent":["import Uppy from \"@uppy/core\";\nimport TusPlugin from \"@uppy/tus\";\nimport type { UploadResult } from \"@/types/upload\";\nimport { UploadResultSymbol } from \"@/types/upload\";\nimport { BaseUploadHandler } from \"./base-upload\";\nimport type { PinnerConfig } from \"@/config\";\nimport { UPLOAD_SOURCE_TUS } from \"./constants\";\n\nexport class TUSUploadHandler extends BaseUploadHandler {\n constructor(config: PinnerConfig) {\n super(config);\n }\n protected configurePlugin(uppy: Uppy): void {\n uppy.use(TusPlugin, {\n endpoint: `${this.config.endpoint}/api/upload/tus`,\n headers: {\n Authorization: `Bearer ${this.config.jwt}`,\n },\n chunkSize: 10 * 1024 * 1024, // 10MB chunks\n retryDelays: [0, 1000, 3000, 5000],\n });\n }\n\n protected parseResult(result: unknown): UploadResult {\n const uppyResponse = result as\n | {\n uploadURL: string;\n body?: UploadResult;\n }\n | undefined;\n\n if (!uppyResponse) {\n return {\n id: \"\",\n cid: \"\",\n name: \"\",\n size: 0,\n mimeType: \"\",\n createdAt: new Date(),\n numberOfFiles: 1,\n isDirectory: false,\n [UploadResultSymbol]: true,\n };\n }\n\n const response = uppyResponse.body;\n\n if (response && response.cid) {\n return {\n id: response.id,\n cid: response.cid,\n name: response.name,\n size: response.size,\n mimeType: response.mimeType,\n createdAt: new Date(response.createdAt),\n numberOfFiles: response.numberOfFiles,\n isDirectory: response.isDirectory ?? false,\n keyvalues: response.keyvalues,\n operationId: response.operationId,\n [UploadResultSymbol]: true,\n };\n }\n\n const uploadId = uppyResponse.uploadURL?.split(\"/\").pop() || \"\";\n\n return {\n id: uploadId,\n cid: \"\",\n name: \"\",\n size: 0,\n mimeType: \"\",\n createdAt: new Date(),\n numberOfFiles: 1,\n isDirectory: false,\n [UploadResultSymbol]: true,\n };\n }\n\n protected getUploadSource(): string {\n return UPLOAD_SOURCE_TUS;\n }\n}\n"],"mappings":";;;;;;AAQA,IAAa,mBAAb,cAAsC,kBAAkB;CACtD,YAAY,QAAsB;AAChC,QAAM,OAAO;;CAEf,AAAU,gBAAgB,MAAkB;AAC1C,OAAK,IAAI,WAAW;GAClB,UAAU,GAAG,KAAK,OAAO,SAAS;GAClC,SAAS,EACP,eAAe,UAAU,KAAK,OAAO,OACtC;GACD,WAAW,KAAK,OAAO;GACvB,aAAa;IAAC;IAAG;IAAM;IAAM;IAAK;GACnC,CAAC;;CAGJ,AAAU,YAAY,QAA+B;EACnD,MAAM,eAAe;AAOrB,MAAI,CAAC,aACH,QAAO;GACL,IAAI;GACJ,KAAK;GACL,MAAM;GACN,MAAM;GACN,UAAU;GACV,2BAAW,IAAI,MAAM;GACrB,eAAe;GACf,aAAa;IACZ,qBAAqB;GACvB;EAGH,MAAM,WAAW,aAAa;AAE9B,MAAI,YAAY,SAAS,IACvB,QAAO;GACL,IAAI,SAAS;GACb,KAAK,SAAS;GACd,MAAM,SAAS;GACf,MAAM,SAAS;GACf,UAAU,SAAS;GACnB,WAAW,IAAI,KAAK,SAAS,UAAU;GACvC,eAAe,SAAS;GACxB,aAAa,SAAS,eAAe;GACrC,WAAW,SAAS;GACpB,aAAa,SAAS;IACrB,qBAAqB;GACvB;AAKH,SAAO;GACL,IAHe,aAAa,WAAW,MAAM,IAAI,CAAC,KAAK,IAAI;GAI3D,KAAK;GACL,MAAM;GACN,MAAM;GACN,UAAU;GACV,2BAAW,IAAI,MAAM;GACrB,eAAe;GACf,aAAa;IACZ,qBAAqB;GACvB;;CAGH,AAAU,kBAA0B;AAClC,SAAO"}
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@lumeweb/pinner",
|
|
3
|
-
"version": "0.1.
|
|
3
|
+
"version": "0.1.8",
|
|
4
4
|
"type": "module",
|
|
5
5
|
"files": [
|
|
6
6
|
"dist",
|
|
@@ -63,8 +63,8 @@
|
|
|
63
63
|
"progress-events": "^1.1.0",
|
|
64
64
|
"tus-js-client": "4.3.1",
|
|
65
65
|
"unstorage": "^1.17.5",
|
|
66
|
-
"@lumeweb/portal-sdk": "0.1.2",
|
|
67
66
|
"@lumeweb/query-builder": "0.1.1",
|
|
67
|
+
"@lumeweb/portal-sdk": "0.1.3",
|
|
68
68
|
"@lumeweb/uppy-post-upload": "0.1.1"
|
|
69
69
|
},
|
|
70
70
|
"devDependencies": {
|
|
@@ -1,8 +0,0 @@
|
|
|
1
|
-
//#region \0rolldown/runtime.js
|
|
2
|
-
var __require = /* @__PURE__ */ ((x) => typeof require !== "undefined" ? require : typeof Proxy !== "undefined" ? new Proxy(x, { get: (a, b) => (typeof require !== "undefined" ? require : a)[b] }) : x)(function(x) {
|
|
3
|
-
if (typeof require !== "undefined") return require.apply(this, arguments);
|
|
4
|
-
throw Error("Calling `require` for \"" + x + "\" in an environment that doesn't expose the `require` function. See https://rolldown.rs/in-depth/bundling-cjs#require-external-modules for more details.");
|
|
5
|
-
});
|
|
6
|
-
|
|
7
|
-
//#endregion
|
|
8
|
-
export { __require };
|
|
@@ -1,51 +0,0 @@
|
|
|
1
|
-
import { __require } from "../_virtual/_rolldown/runtime.js";
|
|
2
|
-
import { isNodeEnvironment } from "./env.js";
|
|
3
|
-
|
|
4
|
-
//#region src/utils/tus-patch.ts
|
|
5
|
-
/**
|
|
6
|
-
* Runtime patch for tus-js-client's NodeHttpStack Request class.
|
|
7
|
-
*
|
|
8
|
-
* PROBLEM:
|
|
9
|
-
* Code using onBeforeRequest hook may need to call abort() on the request
|
|
10
|
-
* before send() is called. However, the Request class only sets this._request
|
|
11
|
-
* inside the send() method, so getUnderlyingObject() returns null before send().
|
|
12
|
-
*
|
|
13
|
-
* SOLUTION:
|
|
14
|
-
* Patch the Request class to initialize a dummy _request object with an abort()
|
|
15
|
-
* method immediately when the request is created.
|
|
16
|
-
*
|
|
17
|
-
* NOTE:
|
|
18
|
-
* This patch is only needed in Node.js environments. In browser environments,
|
|
19
|
-
* the tus-js-client uses a different HTTP stack that doesn't have this issue.
|
|
20
|
-
*/
|
|
21
|
-
function patchTusNodeHttpStack() {
|
|
22
|
-
if (!isNodeEnvironment()) return;
|
|
23
|
-
try {
|
|
24
|
-
const tusHttpStackModule = __require("tus-js-client/lib.es5/node/httpStack.js");
|
|
25
|
-
if (!tusHttpStackModule || !tusHttpStackModule.default) {
|
|
26
|
-
console.warn("[tus-patch] tus-js-client NodeHttpStack not found, patch skipped");
|
|
27
|
-
return;
|
|
28
|
-
}
|
|
29
|
-
const NodeHttpStack = tusHttpStackModule.default;
|
|
30
|
-
const originalCreateRequest = NodeHttpStack.prototype.createRequest;
|
|
31
|
-
if (typeof originalCreateRequest !== "function") {
|
|
32
|
-
console.warn("[tus-patch] createRequest method not found, patch skipped");
|
|
33
|
-
return;
|
|
34
|
-
}
|
|
35
|
-
NodeHttpStack.prototype.createRequest = function(method, url) {
|
|
36
|
-
const request = originalCreateRequest.call(this, method, url);
|
|
37
|
-
request._request = {
|
|
38
|
-
abort: () => {},
|
|
39
|
-
destroyed: false
|
|
40
|
-
};
|
|
41
|
-
return request;
|
|
42
|
-
};
|
|
43
|
-
console.debug("[tus-patch] Successfully patched tus-js-client NodeHttpStack");
|
|
44
|
-
} catch (error) {
|
|
45
|
-
console.warn("[tus-patch] Failed to patch tus-js-client:", error);
|
|
46
|
-
}
|
|
47
|
-
}
|
|
48
|
-
|
|
49
|
-
//#endregion
|
|
50
|
-
export { patchTusNodeHttpStack };
|
|
51
|
-
//# sourceMappingURL=tus-patch.js.map
|
|
@@ -1 +0,0 @@
|
|
|
1
|
-
{"version":3,"file":"tus-patch.js","names":[],"sources":["../../../src/utils/tus-patch.ts"],"sourcesContent":["/**\n * Runtime patch for tus-js-client's NodeHttpStack Request class.\n *\n * PROBLEM:\n * Code using onBeforeRequest hook may need to call abort() on the request\n * before send() is called. However, the Request class only sets this._request\n * inside the send() method, so getUnderlyingObject() returns null before send().\n *\n * SOLUTION:\n * Patch the Request class to initialize a dummy _request object with an abort()\n * method immediately when the request is created.\n *\n * NOTE:\n * This patch is only needed in Node.js environments. In browser environments,\n * the tus-js-client uses a different HTTP stack that doesn't have this issue.\n */\n\nimport { isNodeEnvironment } from \"./env\";\n\n// Track whether the patch has been applied to prevent multiple patches\nlet isPatched = false;\n\nexport function patchTusNodeHttpStack(): void {\n // Prevent multiple patches\n if (isPatched) {\n return;\n }\n\n // Only apply patch in Node.js environments\n if (!isNodeEnvironment()) {\n return;\n }\n\n // Find the tus-js-client NodeHttpStack module\n // It exports the default as NodeHttpStack with a nested Request class\n try {\n // Use dynamic require() to avoid bundling issues\n // eslint-disable-next-line @typescript-eslint/no-var-requires\n const tusHttpStackModule = require(\"tus-js-client/lib.es5/node/httpStack\");\n\n if (!tusHttpStackModule || !tusHttpStackModule.default) {\n console.warn(\n \"[tus-patch] tus-js-client NodeHttpStack not found, patch skipped\",\n );\n return;\n }\n\n const NodeHttpStack = tusHttpStackModule.default;\n\n // Get the original createRequest method\n const originalCreateRequest = NodeHttpStack.prototype.createRequest;\n\n if (typeof originalCreateRequest !== \"function\") {\n console.warn(\"[tus-patch] createRequest method not found, patch skipped\");\n return;\n }\n\n // Patch createRequest to set up a dummy _request on the Request instance\n NodeHttpStack.prototype.createRequest = function (\n method: string,\n url: string,\n ) {\n // Call the original createRequest to get the Request instance\n const request = originalCreateRequest.call(this, method, url);\n\n // Set a dummy _request object with an abort() method\n // This allows getUnderlyingObject().abort() to work before send() is called\n request._request = {\n abort: () => {\n // No-op abort before actual request is created\n // The real request will be created in send() and this will be replaced\n },\n // Preserve any existing properties that might be checked\n destroyed: false,\n };\n\n return request;\n };\n\n console.debug(\n \"[tus-patch] Successfully patched tus-js-client NodeHttpStack\",\n );\n } catch (error) {\n console.warn(\"[tus-patch] Failed to patch tus-js-client:\", error);\n }\n}\n"],"mappings":";;;;;;;;;;;;;;;;;;;;AAsBA,SAAgB,wBAA8B;AAO5C,KAAI,CAAC,mBAAmB,CACtB;AAKF,KAAI;EAGF,MAAM,+BAA6B,0CAAuC;AAE1E,MAAI,CAAC,sBAAsB,CAAC,mBAAmB,SAAS;AACtD,WAAQ,KACN,mEACD;AACD;;EAGF,MAAM,gBAAgB,mBAAmB;EAGzC,MAAM,wBAAwB,cAAc,UAAU;AAEtD,MAAI,OAAO,0BAA0B,YAAY;AAC/C,WAAQ,KAAK,4DAA4D;AACzE;;AAIF,gBAAc,UAAU,gBAAgB,SACtC,QACA,KACA;GAEA,MAAM,UAAU,sBAAsB,KAAK,MAAM,QAAQ,IAAI;AAI7D,WAAQ,WAAW;IACjB,aAAa;IAKb,WAAW;IACZ;AAED,UAAO;;AAGT,UAAQ,MACN,+DACD;UACM,OAAO;AACd,UAAQ,KAAK,8CAA8C,MAAM"}
|