@payloadcms/storage-uploadthing 3.82.1 → 3.83.0-canary.1
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/dist/adapter.d.ts +11 -0
- package/dist/adapter.d.ts.map +1 -0
- package/dist/adapter.js +53 -0
- package/dist/adapter.js.map +1 -0
- package/dist/client/UploadthingClientUploadHandler.d.ts.map +1 -1
- package/dist/deleteFile.d.ts +11 -0
- package/dist/deleteFile.d.ts.map +1 -0
- package/dist/deleteFile.js +22 -0
- package/dist/deleteFile.js.map +1 -0
- package/dist/getFile.d.ts +14 -0
- package/dist/getFile.d.ts.map +1 -0
- package/dist/getFile.js +134 -0
- package/dist/getFile.js.map +1 -0
- package/dist/index.d.ts +2 -0
- package/dist/index.d.ts.map +1 -1
- package/dist/index.js +20 -56
- package/dist/index.js.map +1 -1
- package/dist/uploadFile.d.ts +14 -0
- package/dist/uploadFile.d.ts.map +1 -0
- package/dist/uploadFile.js +47 -0
- package/dist/uploadFile.js.map +1 -0
- package/package.json +4 -4
- package/dist/handleDelete.d.ts +0 -8
- package/dist/handleDelete.d.ts.map +0 -1
- package/dist/handleDelete.js +0 -26
- package/dist/handleDelete.js.map +0 -1
- package/dist/handleUpload.d.ts +0 -10
- package/dist/handleUpload.d.ts.map +0 -1
- package/dist/handleUpload.js +0 -49
- package/dist/handleUpload.js.map +0 -1
- package/dist/staticHandler.d.ts +0 -8
- package/dist/staticHandler.d.ts.map +0 -1
- package/dist/staticHandler.js +0 -140
- package/dist/staticHandler.js.map +0 -1
|
@@ -0,0 +1,11 @@
|
|
|
1
|
+
import type { Adapter, ClientUploadsConfig } from '@payloadcms/plugin-cloud-storage/types';
|
|
2
|
+
import type { UTApi } from 'uploadthing/server';
|
|
3
|
+
import type { ACL } from './index.js';
|
|
4
|
+
interface CreateUploadthingAdapterArgs {
|
|
5
|
+
acl: ACL;
|
|
6
|
+
clientUploads?: ClientUploadsConfig;
|
|
7
|
+
utApi: UTApi;
|
|
8
|
+
}
|
|
9
|
+
export declare function createUploadthingAdapter({ acl, clientUploads, utApi, }: CreateUploadthingAdapterArgs): Adapter;
|
|
10
|
+
export {};
|
|
11
|
+
//# sourceMappingURL=adapter.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"adapter.d.ts","sourceRoot":"","sources":["../src/adapter.ts"],"names":[],"mappings":"AAAA,OAAO,KAAK,EACV,OAAO,EACP,mBAAmB,EAEpB,MAAM,wCAAwC,CAAA;AAE/C,OAAO,KAAK,EAAE,KAAK,EAAE,MAAM,oBAAoB,CAAA;AAE/C,OAAO,KAAK,EAAE,GAAG,EAAE,MAAM,YAAY,CAAA;AAOrC,UAAU,4BAA4B;IACpC,GAAG,EAAE,GAAG,CAAA;IACR,aAAa,CAAC,EAAE,mBAAmB,CAAA;IACnC,KAAK,EAAE,KAAK,CAAA;CACb;AAED,wBAAgB,wBAAwB,CAAC,EACvC,GAAG,EACH,aAAa,EACb,KAAK,GACN,EAAE,4BAA4B,GAAG,OAAO,CAiDxC"}
|
package/dist/adapter.js
ADDED
|
@@ -0,0 +1,53 @@
|
|
|
1
|
+
import { deleteFile } from './deleteFile.js';
|
|
2
|
+
import { generateURL } from './generateURL.js';
|
|
3
|
+
import { getFile } from './getFile.js';
|
|
4
|
+
import { uploadFile } from './uploadFile.js';
|
|
5
|
+
export function createUploadthingAdapter({ acl, clientUploads, utApi }) {
|
|
6
|
+
const fields = [
|
|
7
|
+
{
|
|
8
|
+
name: '_key',
|
|
9
|
+
type: 'text',
|
|
10
|
+
admin: {
|
|
11
|
+
disableBulkEdit: true,
|
|
12
|
+
disableListColumn: true,
|
|
13
|
+
disableListFilter: true,
|
|
14
|
+
hidden: true
|
|
15
|
+
}
|
|
16
|
+
}
|
|
17
|
+
];
|
|
18
|
+
return ()=>({
|
|
19
|
+
name: 'uploadthing',
|
|
20
|
+
clientUploads,
|
|
21
|
+
fields,
|
|
22
|
+
generateURL,
|
|
23
|
+
handleDelete: ({ doc, filename, req })=>deleteFile({
|
|
24
|
+
doc: doc,
|
|
25
|
+
filename,
|
|
26
|
+
req,
|
|
27
|
+
utApi
|
|
28
|
+
}),
|
|
29
|
+
handleUpload: async ({ clientUploadContext, data, file })=>{
|
|
30
|
+
const result = await uploadFile({
|
|
31
|
+
acl,
|
|
32
|
+
buffer: file.buffer,
|
|
33
|
+
clientUploadContext,
|
|
34
|
+
data,
|
|
35
|
+
filename: file.filename,
|
|
36
|
+
mimeType: file.mimeType,
|
|
37
|
+
utApi
|
|
38
|
+
});
|
|
39
|
+
return result;
|
|
40
|
+
},
|
|
41
|
+
staticHandler: (req, { doc, headers, params: { clientUploadContext, collection, filename } })=>getFile({
|
|
42
|
+
clientUploadContext,
|
|
43
|
+
collection,
|
|
44
|
+
doc: doc,
|
|
45
|
+
filename,
|
|
46
|
+
incomingHeaders: headers || new Headers(),
|
|
47
|
+
req,
|
|
48
|
+
utApi
|
|
49
|
+
})
|
|
50
|
+
});
|
|
51
|
+
}
|
|
52
|
+
|
|
53
|
+
//# sourceMappingURL=adapter.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"sources":["../src/adapter.ts"],"sourcesContent":["import type {\n Adapter,\n ClientUploadsConfig,\n GeneratedAdapter,\n} from '@payloadcms/plugin-cloud-storage/types'\nimport type { Field } from 'payload'\nimport type { UTApi } from 'uploadthing/server'\n\nimport type { ACL } from './index.js'\n\nimport { deleteFile } from './deleteFile.js'\nimport { generateURL } from './generateURL.js'\nimport { getFile } from './getFile.js'\nimport { uploadFile } from './uploadFile.js'\n\ninterface CreateUploadthingAdapterArgs {\n acl: ACL\n clientUploads?: ClientUploadsConfig\n utApi: UTApi\n}\n\nexport function createUploadthingAdapter({\n acl,\n clientUploads,\n utApi,\n}: CreateUploadthingAdapterArgs): Adapter {\n const fields: Field[] = [\n {\n name: '_key',\n type: 'text',\n admin: {\n disableBulkEdit: true,\n disableListColumn: true,\n disableListFilter: true,\n hidden: true,\n },\n },\n ]\n\n return (): GeneratedAdapter => ({\n name: 'uploadthing',\n clientUploads,\n fields,\n\n generateURL,\n\n handleDelete: ({ doc, filename, req }) =>\n deleteFile({ doc: doc as unknown as Record<string, unknown>, filename, req, utApi }),\n\n handleUpload: async ({ clientUploadContext, data, file }) => {\n const result = await uploadFile({\n acl,\n buffer: file.buffer,\n clientUploadContext,\n data,\n filename: file.filename,\n mimeType: file.mimeType,\n utApi,\n })\n\n return result\n },\n\n staticHandler: (req, { doc, headers, params: { clientUploadContext, collection, filename } }) =>\n getFile({\n clientUploadContext,\n collection,\n doc: doc as unknown as Record<string, unknown> | undefined,\n filename,\n incomingHeaders: headers || new Headers(),\n req,\n utApi,\n }),\n })\n}\n"],"names":["deleteFile","generateURL","getFile","uploadFile","createUploadthingAdapter","acl","clientUploads","utApi","fields","name","type","admin","disableBulkEdit","disableListColumn","disableListFilter","hidden","handleDelete","doc","filename","req","handleUpload","clientUploadContext","data","file","result","buffer","mimeType","staticHandler","headers","params","collection","incomingHeaders","Headers"],"mappings":"AAUA,SAASA,UAAU,QAAQ,kBAAiB;AAC5C,SAASC,WAAW,QAAQ,mBAAkB;AAC9C,SAASC,OAAO,QAAQ,eAAc;AACtC,SAASC,UAAU,QAAQ,kBAAiB;AAQ5C,OAAO,SAASC,yBAAyB,EACvCC,GAAG,EACHC,aAAa,EACbC,KAAK,EACwB;IAC7B,MAAMC,SAAkB;QACtB;YACEC,MAAM;YACNC,MAAM;YACNC,OAAO;gBACLC,iBAAiB;gBACjBC,mBAAmB;gBACnBC,mBAAmB;gBACnBC,QAAQ;YACV;QACF;KACD;IAED,OAAO,IAAyB,CAAA;YAC9BN,MAAM;YACNH;YACAE;YAEAP;YAEAe,cAAc,CAAC,EAAEC,GAAG,EAAEC,QAAQ,EAAEC,GAAG,EAAE,GACnCnB,WAAW;oBAAEiB,KAAKA;oBAA2CC;oBAAUC;oBAAKZ;gBAAM;YAEpFa,cAAc,OAAO,EAAEC,mBAAmB,EAAEC,IAAI,EAAEC,IAAI,EAAE;gBACtD,MAAMC,SAAS,MAAMrB,WAAW;oBAC9BE;oBACAoB,QAAQF,KAAKE,MAAM;oBACnBJ;oBACAC;oBACAJ,UAAUK,KAAKL,QAAQ;oBACvBQ,UAAUH,KAAKG,QAAQ;oBACvBnB;gBACF;gBAEA,OAAOiB;YACT;YAEAG,eAAe,CAACR,KAAK,EAAEF,GAAG,EAAEW,OAAO,EAAEC,QAAQ,EAAER,mBAAmB,EAAES,UAAU,EAAEZ,QAAQ,EAAE,EAAE,GAC1FhB,QAAQ;oBACNmB;oBACAS;oBACAb,KAAKA;oBACLC;oBACAa,iBAAiBH,WAAW,IAAII;oBAChCb;oBACAZ;gBACF;QACJ,CAAA;AACF"}
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"UploadthingClientUploadHandler.d.ts","sourceRoot":"","sources":["../../src/client/UploadthingClientUploadHandler.ts"],"names":[],"mappings":"AAKA,eAAO,MAAM,8BAA8B;;;;;;;
|
|
1
|
+
{"version":3,"file":"UploadthingClientUploadHandler.d.ts","sourceRoot":"","sources":["../../src/client/UploadthingClientUploadHandler.ts"],"names":[],"mappings":"AAKA,eAAO,MAAM,8BAA8B;;;;;;;aAmB6F,OAAO,aAD7I,CAAA"}
|
|
@@ -0,0 +1,11 @@
|
|
|
1
|
+
import type { PayloadRequest } from 'payload';
|
|
2
|
+
import type { UTApi } from 'uploadthing/server';
|
|
3
|
+
interface DeleteFileArgs {
|
|
4
|
+
doc: Record<string, unknown>;
|
|
5
|
+
filename: string;
|
|
6
|
+
req: PayloadRequest;
|
|
7
|
+
utApi: UTApi;
|
|
8
|
+
}
|
|
9
|
+
export declare function deleteFile({ doc, filename, req, utApi }: DeleteFileArgs): Promise<void>;
|
|
10
|
+
export {};
|
|
11
|
+
//# sourceMappingURL=deleteFile.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"deleteFile.d.ts","sourceRoot":"","sources":["../src/deleteFile.ts"],"names":[],"mappings":"AAAA,OAAO,KAAK,EAAE,cAAc,EAAE,MAAM,SAAS,CAAA;AAC7C,OAAO,KAAK,EAAE,KAAK,EAAE,MAAM,oBAAoB,CAAA;AAM/C,UAAU,cAAc;IACtB,GAAG,EAAE,MAAM,CAAC,MAAM,EAAE,OAAO,CAAC,CAAA;IAC5B,QAAQ,EAAE,MAAM,CAAA;IAChB,GAAG,EAAE,cAAc,CAAA;IACnB,KAAK,EAAE,KAAK,CAAA;CACb;AAED,wBAAsB,UAAU,CAAC,EAAE,GAAG,EAAE,QAAQ,EAAE,GAAG,EAAE,KAAK,EAAE,EAAE,cAAc,GAAG,OAAO,CAAC,IAAI,CAAC,CAmB7F"}
|
|
@@ -0,0 +1,22 @@
|
|
|
1
|
+
import { APIError } from 'payload';
|
|
2
|
+
import { getKeyFromFilename } from './utilities.js';
|
|
3
|
+
export async function deleteFile({ doc, filename, req, utApi }) {
|
|
4
|
+
const key = getKeyFromFilename(doc, filename);
|
|
5
|
+
if (!key) {
|
|
6
|
+
req.payload.logger.error({
|
|
7
|
+
msg: `Error deleting file: ${filename} - unable to extract key from doc`
|
|
8
|
+
});
|
|
9
|
+
throw new APIError(`Error deleting file: ${filename}`);
|
|
10
|
+
}
|
|
11
|
+
try {
|
|
12
|
+
await utApi.deleteFiles(key);
|
|
13
|
+
} catch (err) {
|
|
14
|
+
req.payload.logger.error({
|
|
15
|
+
err,
|
|
16
|
+
msg: `Error deleting file with key: ${filename} - key: ${key}`
|
|
17
|
+
});
|
|
18
|
+
throw new APIError(`Error deleting file: ${filename}`);
|
|
19
|
+
}
|
|
20
|
+
}
|
|
21
|
+
|
|
22
|
+
//# sourceMappingURL=deleteFile.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"sources":["../src/deleteFile.ts"],"sourcesContent":["import type { PayloadRequest } from 'payload'\nimport type { UTApi } from 'uploadthing/server'\n\nimport { APIError } from 'payload'\n\nimport { getKeyFromFilename } from './utilities.js'\n\ninterface DeleteFileArgs {\n doc: Record<string, unknown>\n filename: string\n req: PayloadRequest\n utApi: UTApi\n}\n\nexport async function deleteFile({ doc, filename, req, utApi }: DeleteFileArgs): Promise<void> {\n const key = getKeyFromFilename(doc, filename)\n\n if (!key) {\n req.payload.logger.error({\n msg: `Error deleting file: ${filename} - unable to extract key from doc`,\n })\n throw new APIError(`Error deleting file: ${filename}`)\n }\n\n try {\n await utApi.deleteFiles(key)\n } catch (err) {\n req.payload.logger.error({\n err,\n msg: `Error deleting file with key: ${filename} - key: ${key}`,\n })\n throw new APIError(`Error deleting file: ${filename}`)\n }\n}\n"],"names":["APIError","getKeyFromFilename","deleteFile","doc","filename","req","utApi","key","payload","logger","error","msg","deleteFiles","err"],"mappings":"AAGA,SAASA,QAAQ,QAAQ,UAAS;AAElC,SAASC,kBAAkB,QAAQ,iBAAgB;AASnD,OAAO,eAAeC,WAAW,EAAEC,GAAG,EAAEC,QAAQ,EAAEC,GAAG,EAAEC,KAAK,EAAkB;IAC5E,MAAMC,MAAMN,mBAAmBE,KAAKC;IAEpC,IAAI,CAACG,KAAK;QACRF,IAAIG,OAAO,CAACC,MAAM,CAACC,KAAK,CAAC;YACvBC,KAAK,CAAC,qBAAqB,EAAEP,SAAS,iCAAiC,CAAC;QAC1E;QACA,MAAM,IAAIJ,SAAS,CAAC,qBAAqB,EAAEI,UAAU;IACvD;IAEA,IAAI;QACF,MAAME,MAAMM,WAAW,CAACL;IAC1B,EAAE,OAAOM,KAAK;QACZR,IAAIG,OAAO,CAACC,MAAM,CAACC,KAAK,CAAC;YACvBG;YACAF,KAAK,CAAC,8BAA8B,EAAEP,SAAS,QAAQ,EAAEG,KAAK;QAChE;QACA,MAAM,IAAIP,SAAS,CAAC,qBAAqB,EAAEI,UAAU;IACvD;AACF"}
|
|
@@ -0,0 +1,14 @@
|
|
|
1
|
+
import type { PayloadRequest } from 'payload';
|
|
2
|
+
import type { UTApi } from 'uploadthing/server';
|
|
3
|
+
interface GetFileArgs {
|
|
4
|
+
clientUploadContext?: unknown;
|
|
5
|
+
collection: string;
|
|
6
|
+
doc?: Record<string, unknown>;
|
|
7
|
+
filename: string;
|
|
8
|
+
incomingHeaders: Headers;
|
|
9
|
+
req: PayloadRequest;
|
|
10
|
+
utApi: UTApi;
|
|
11
|
+
}
|
|
12
|
+
export declare function getFile({ clientUploadContext, collection, doc, filename, incomingHeaders, req, utApi, }: GetFileArgs): Promise<Response>;
|
|
13
|
+
export {};
|
|
14
|
+
//# sourceMappingURL=getFile.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"getFile.d.ts","sourceRoot":"","sources":["../src/getFile.ts"],"names":[],"mappings":"AAAA,OAAO,KAAK,EAAE,cAAc,EAAS,MAAM,SAAS,CAAA;AACpD,OAAO,KAAK,EAAE,KAAK,EAAE,MAAM,oBAAoB,CAAA;AAM/C,UAAU,WAAW;IACnB,mBAAmB,CAAC,EAAE,OAAO,CAAA;IAC7B,UAAU,EAAE,MAAM,CAAA;IAClB,GAAG,CAAC,EAAE,MAAM,CAAC,MAAM,EAAE,OAAO,CAAC,CAAA;IAC7B,QAAQ,EAAE,MAAM,CAAA;IAChB,eAAe,EAAE,OAAO,CAAA;IACxB,GAAG,EAAE,cAAc,CAAA;IACnB,KAAK,EAAE,KAAK,CAAA;CACb;AAED,wBAAsB,OAAO,CAAC,EAC5B,mBAAmB,EACnB,UAAU,EACV,GAAG,EACH,QAAQ,EACR,eAAe,EACf,GAAG,EACH,KAAK,GACN,EAAE,WAAW,GAAG,OAAO,CAAC,QAAQ,CAAC,CAuIjC"}
|
package/dist/getFile.js
ADDED
|
@@ -0,0 +1,134 @@
|
|
|
1
|
+
import { getRangeRequestInfo } from 'payload/internal';
|
|
2
|
+
import { getKeyFromFilename } from './utilities.js';
|
|
3
|
+
export async function getFile({ clientUploadContext, collection, doc, filename, incomingHeaders, req, utApi }) {
|
|
4
|
+
try {
|
|
5
|
+
let key;
|
|
6
|
+
const collectionConfig = req.payload.collections[collection]?.config;
|
|
7
|
+
if (clientUploadContext && typeof clientUploadContext === 'object' && 'key' in clientUploadContext && typeof clientUploadContext.key === 'string') {
|
|
8
|
+
key = clientUploadContext.key;
|
|
9
|
+
} else {
|
|
10
|
+
let retrievedDoc = doc;
|
|
11
|
+
if (!retrievedDoc) {
|
|
12
|
+
const or = [
|
|
13
|
+
{
|
|
14
|
+
filename: {
|
|
15
|
+
equals: filename
|
|
16
|
+
}
|
|
17
|
+
}
|
|
18
|
+
];
|
|
19
|
+
if (collectionConfig?.upload.imageSizes) {
|
|
20
|
+
collectionConfig.upload.imageSizes.forEach(({ name })=>{
|
|
21
|
+
or.push({
|
|
22
|
+
[`sizes.${name}.filename`]: {
|
|
23
|
+
equals: filename
|
|
24
|
+
}
|
|
25
|
+
});
|
|
26
|
+
});
|
|
27
|
+
}
|
|
28
|
+
const result = await req.payload.db.findOne({
|
|
29
|
+
collection,
|
|
30
|
+
req,
|
|
31
|
+
where: {
|
|
32
|
+
or
|
|
33
|
+
}
|
|
34
|
+
});
|
|
35
|
+
if (result) {
|
|
36
|
+
retrievedDoc = result;
|
|
37
|
+
}
|
|
38
|
+
}
|
|
39
|
+
if (!retrievedDoc) {
|
|
40
|
+
return new Response(null, {
|
|
41
|
+
status: 404,
|
|
42
|
+
statusText: 'Not Found'
|
|
43
|
+
});
|
|
44
|
+
}
|
|
45
|
+
key = getKeyFromFilename(retrievedDoc, filename);
|
|
46
|
+
}
|
|
47
|
+
if (!key) {
|
|
48
|
+
return new Response(null, {
|
|
49
|
+
status: 404,
|
|
50
|
+
statusText: 'Not Found'
|
|
51
|
+
});
|
|
52
|
+
}
|
|
53
|
+
const { url: signedURL } = await utApi.getSignedURL(key);
|
|
54
|
+
if (!signedURL) {
|
|
55
|
+
return new Response(null, {
|
|
56
|
+
status: 404,
|
|
57
|
+
statusText: 'Not Found'
|
|
58
|
+
});
|
|
59
|
+
}
|
|
60
|
+
const headResponse = await fetch(signedURL, {
|
|
61
|
+
method: 'HEAD'
|
|
62
|
+
});
|
|
63
|
+
if (!headResponse.ok) {
|
|
64
|
+
return new Response(null, {
|
|
65
|
+
status: 404,
|
|
66
|
+
statusText: 'Not Found'
|
|
67
|
+
});
|
|
68
|
+
}
|
|
69
|
+
const fileSize = Number(headResponse.headers.get('content-length'));
|
|
70
|
+
const rangeHeader = req.headers.get('range');
|
|
71
|
+
const rangeResult = getRangeRequestInfo({
|
|
72
|
+
fileSize,
|
|
73
|
+
rangeHeader
|
|
74
|
+
});
|
|
75
|
+
if (rangeResult.type === 'invalid') {
|
|
76
|
+
return new Response(null, {
|
|
77
|
+
headers: new Headers(rangeResult.headers),
|
|
78
|
+
status: rangeResult.status
|
|
79
|
+
});
|
|
80
|
+
}
|
|
81
|
+
const response = await fetch(signedURL, {
|
|
82
|
+
headers: rangeResult.type === 'partial' ? {
|
|
83
|
+
Range: `bytes=${rangeResult.rangeStart}-${rangeResult.rangeEnd}`
|
|
84
|
+
} : undefined
|
|
85
|
+
});
|
|
86
|
+
if (!response.ok || !response.body) {
|
|
87
|
+
return new Response(null, {
|
|
88
|
+
status: 404,
|
|
89
|
+
statusText: 'Not Found'
|
|
90
|
+
});
|
|
91
|
+
}
|
|
92
|
+
const etagFromHeaders = req.headers.get('etag') || req.headers.get('if-none-match');
|
|
93
|
+
const objectEtag = response.headers.get('etag');
|
|
94
|
+
let headers = new Headers(incomingHeaders);
|
|
95
|
+
for (const [headerKey, value] of Object.entries(rangeResult.headers)){
|
|
96
|
+
headers.append(headerKey, value);
|
|
97
|
+
}
|
|
98
|
+
const contentType = response.headers.get('content-type');
|
|
99
|
+
if (contentType) {
|
|
100
|
+
headers.append('Content-Type', contentType);
|
|
101
|
+
}
|
|
102
|
+
if (objectEtag) {
|
|
103
|
+
headers.append('ETag', objectEtag);
|
|
104
|
+
}
|
|
105
|
+
if (contentType === 'image/svg+xml') {
|
|
106
|
+
headers.append('Content-Security-Policy', "script-src 'none'");
|
|
107
|
+
}
|
|
108
|
+
if (collectionConfig?.upload && typeof collectionConfig.upload === 'object' && typeof collectionConfig.upload.modifyResponseHeaders === 'function') {
|
|
109
|
+
headers = collectionConfig.upload.modifyResponseHeaders({
|
|
110
|
+
headers
|
|
111
|
+
}) || headers;
|
|
112
|
+
}
|
|
113
|
+
if (etagFromHeaders && etagFromHeaders === objectEtag) {
|
|
114
|
+
return new Response(null, {
|
|
115
|
+
headers,
|
|
116
|
+
status: 304
|
|
117
|
+
});
|
|
118
|
+
}
|
|
119
|
+
return new Response(response.body, {
|
|
120
|
+
headers,
|
|
121
|
+
status: rangeResult.status
|
|
122
|
+
});
|
|
123
|
+
} catch (err) {
|
|
124
|
+
req.payload.logger.error({
|
|
125
|
+
err,
|
|
126
|
+
msg: 'Unexpected error in staticHandler'
|
|
127
|
+
});
|
|
128
|
+
return new Response('Internal Server Error', {
|
|
129
|
+
status: 500
|
|
130
|
+
});
|
|
131
|
+
}
|
|
132
|
+
}
|
|
133
|
+
|
|
134
|
+
//# sourceMappingURL=getFile.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"sources":["../src/getFile.ts"],"sourcesContent":["import type { PayloadRequest, Where } from 'payload'\nimport type { UTApi } from 'uploadthing/server'\n\nimport { getRangeRequestInfo } from 'payload/internal'\n\nimport { getKeyFromFilename } from './utilities.js'\n\ninterface GetFileArgs {\n clientUploadContext?: unknown\n collection: string\n doc?: Record<string, unknown>\n filename: string\n incomingHeaders: Headers\n req: PayloadRequest\n utApi: UTApi\n}\n\nexport async function getFile({\n clientUploadContext,\n collection,\n doc,\n filename,\n incomingHeaders,\n req,\n utApi,\n}: GetFileArgs): Promise<Response> {\n try {\n let key: string\n const collectionConfig = req.payload.collections[collection]?.config\n\n if (\n clientUploadContext &&\n typeof clientUploadContext === 'object' &&\n 'key' in clientUploadContext &&\n typeof clientUploadContext.key === 'string'\n ) {\n key = clientUploadContext.key\n } else {\n let retrievedDoc = doc\n\n if (!retrievedDoc) {\n const or: Where[] = [\n {\n filename: {\n equals: filename,\n },\n },\n ]\n\n if (collectionConfig?.upload.imageSizes) {\n collectionConfig.upload.imageSizes.forEach(({ name }) => {\n or.push({\n [`sizes.${name}.filename`]: {\n equals: filename,\n },\n })\n })\n }\n\n const result = await req.payload.db.findOne({\n collection,\n req,\n where: { or },\n })\n\n if (result) {\n retrievedDoc = result as Record<string, unknown>\n }\n }\n\n if (!retrievedDoc) {\n return new Response(null, { status: 404, statusText: 'Not Found' })\n }\n\n key = getKeyFromFilename(retrievedDoc, filename)!\n }\n\n if (!key) {\n return new Response(null, { status: 404, statusText: 'Not Found' })\n }\n\n const { url: signedURL } = await utApi.getSignedURL(key)\n\n if (!signedURL) {\n return new Response(null, { status: 404, statusText: 'Not Found' })\n }\n\n const headResponse = await fetch(signedURL, { method: 'HEAD' })\n if (!headResponse.ok) {\n return new Response(null, { status: 404, statusText: 'Not Found' })\n }\n\n const fileSize = Number(headResponse.headers.get('content-length'))\n\n const rangeHeader = req.headers.get('range')\n const rangeResult = getRangeRequestInfo({ fileSize, rangeHeader })\n\n if (rangeResult.type === 'invalid') {\n return new Response(null, {\n headers: new Headers(rangeResult.headers),\n status: rangeResult.status,\n })\n }\n\n const response = await fetch(signedURL, {\n headers:\n rangeResult.type === 'partial'\n ? { Range: `bytes=${rangeResult.rangeStart}-${rangeResult.rangeEnd}` }\n : undefined,\n })\n\n if (!response.ok || !response.body) {\n return new Response(null, { status: 404, statusText: 'Not Found' })\n }\n\n const etagFromHeaders = req.headers.get('etag') || req.headers.get('if-none-match')\n const objectEtag = response.headers.get('etag')\n\n let headers = new Headers(incomingHeaders)\n\n for (const [headerKey, value] of Object.entries(rangeResult.headers)) {\n headers.append(headerKey, value)\n }\n\n const contentType = response.headers.get('content-type')\n if (contentType) {\n headers.append('Content-Type', contentType)\n }\n\n if (objectEtag) {\n headers.append('ETag', objectEtag)\n }\n\n if (contentType === 'image/svg+xml') {\n headers.append('Content-Security-Policy', \"script-src 'none'\")\n }\n\n if (\n collectionConfig?.upload &&\n typeof collectionConfig.upload === 'object' &&\n typeof collectionConfig.upload.modifyResponseHeaders === 'function'\n ) {\n headers = collectionConfig.upload.modifyResponseHeaders({ headers }) || headers\n }\n\n if (etagFromHeaders && etagFromHeaders === objectEtag) {\n return new Response(null, {\n headers,\n status: 304,\n })\n }\n\n return new Response(response.body, {\n headers,\n status: rangeResult.status,\n })\n } catch (err) {\n req.payload.logger.error({ err, msg: 'Unexpected error in staticHandler' })\n return new Response('Internal Server Error', { status: 500 })\n }\n}\n"],"names":["getRangeRequestInfo","getKeyFromFilename","getFile","clientUploadContext","collection","doc","filename","incomingHeaders","req","utApi","key","collectionConfig","payload","collections","config","retrievedDoc","or","equals","upload","imageSizes","forEach","name","push","result","db","findOne","where","Response","status","statusText","url","signedURL","getSignedURL","headResponse","fetch","method","ok","fileSize","Number","headers","get","rangeHeader","rangeResult","type","Headers","response","Range","rangeStart","rangeEnd","undefined","body","etagFromHeaders","objectEtag","headerKey","value","Object","entries","append","contentType","modifyResponseHeaders","err","logger","error","msg"],"mappings":"AAGA,SAASA,mBAAmB,QAAQ,mBAAkB;AAEtD,SAASC,kBAAkB,QAAQ,iBAAgB;AAYnD,OAAO,eAAeC,QAAQ,EAC5BC,mBAAmB,EACnBC,UAAU,EACVC,GAAG,EACHC,QAAQ,EACRC,eAAe,EACfC,GAAG,EACHC,KAAK,EACO;IACZ,IAAI;QACF,IAAIC;QACJ,MAAMC,mBAAmBH,IAAII,OAAO,CAACC,WAAW,CAACT,WAAW,EAAEU;QAE9D,IACEX,uBACA,OAAOA,wBAAwB,YAC/B,SAASA,uBACT,OAAOA,oBAAoBO,GAAG,KAAK,UACnC;YACAA,MAAMP,oBAAoBO,GAAG;QAC/B,OAAO;YACL,IAAIK,eAAeV;YAEnB,IAAI,CAACU,cAAc;gBACjB,MAAMC,KAAc;oBAClB;wBACEV,UAAU;4BACRW,QAAQX;wBACV;oBACF;iBACD;gBAED,IAAIK,kBAAkBO,OAAOC,YAAY;oBACvCR,iBAAiBO,MAAM,CAACC,UAAU,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K,IAAI,EAAE;YACjCX;YACAX,QAAQc,YAAYd,MAAM;QAC5B;IACF,EAAE,OAAOgC,KAAK;QACZpD,IAAII,OAAO,CAACiD,MAAM,CAACC,KAAK,CAAC;YAAEF;YAAKG,KAAK;QAAoC;QACzE,OAAO,IAAIpC,SAAS,yBAAyB;YAAEC,QAAQ;QAAI;IAC7D;AACF"}
|
package/dist/index.d.ts
CHANGED
|
@@ -23,6 +23,8 @@ export type UploadthingStorageOptions = {
|
|
|
23
23
|
} | boolean;
|
|
24
24
|
/**
|
|
25
25
|
* Collection options to apply the adapter to.
|
|
26
|
+
*
|
|
27
|
+
* TODO V4: OMIT 'prefix' from the collection options - uploadthing does not support prefixes
|
|
26
28
|
*/
|
|
27
29
|
collections: Partial<Record<UploadCollectionSlug, Omit<CollectionOptions, 'adapter'> | true>>;
|
|
28
30
|
/**
|
package/dist/index.d.ts.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../src/index.ts"],"names":[],"mappings":"AAAA,OAAO,KAAK,
|
|
1
|
+
{"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../src/index.ts"],"names":[],"mappings":"AAAA,OAAO,KAAK,EACV,mBAAmB,EAEnB,iBAAiB,EAClB,MAAM,wCAAwC,CAAA;AAC/C,OAAO,KAAK,EAAU,MAAM,EAAE,oBAAoB,EAAE,MAAM,SAAS,CAAA;AACnE,OAAO,KAAK,EAAE,iBAAiB,EAAE,MAAM,oBAAoB,CAAA;AAC3D,OAAO,KAAK,EAAE,YAAY,EAAE,MAAM,mBAAmB,CAAA;AASrD,MAAM,MAAM,qBAAqB,GAAG,UAAU,CAAC,UAAU,CAAC,OAAO,iBAAiB,CAAC,CAAC,CAAC,CAAC,CAAC,CAAA;AAEvF,MAAM,MAAM,yBAAyB,GAAG;IACtC;;;;;;;;OAQG;IACH,kBAAkB,CAAC,EAAE,OAAO,CAAA;IAE5B;;OAEG;IACH,aAAa,CAAC,EACV;QACE,MAAM,CAAC,EAAE,mBAAmB,CAAA;QAC5B,iBAAiB,CAAC,EAAE,qBAAqB,CAAA;KAC1C,GACD,OAAO,CAAA;IAEX;;;;OAIG;IACH,WAAW,EAAE,OAAO,CAAC,MAAM,CAAC,oBAAoB,EAAE,IAAI,CAAC,iBAAiB,EAAE,SAAS,CAAC,GAAG,IAAI,CAAC,CAAC,CAAA;IAE7F;;;;OAIG;IACH,OAAO,CAAC,EAAE,OAAO,CAAA;IAEjB;;OAEG;IACH,OAAO,EAAE;QACP;;WAEG;QACH,GAAG,CAAC,EAAE,GAAG,CAAA;KACV,GAAG,YAAY,CAAA;CACjB,CAAA;AAED,KAAK,iBAAiB,GAAG,CAAC,yBAAyB,EAAE,yBAAyB,KAAK,MAAM,CAAA;AAEzF,+FAA+F;AAC/F,MAAM,MAAM,GAAG,GAAG,SAAS,GAAG,aAAa,CAAA;AAE3C,eAAO,MAAM,kBAAkB,EAAE,iBA6E9B,CAAA"}
|
package/dist/index.js
CHANGED
|
@@ -1,11 +1,8 @@
|
|
|
1
1
|
import { cloudStoragePlugin } from '@payloadcms/plugin-cloud-storage';
|
|
2
2
|
import { initClientUploads } from '@payloadcms/plugin-cloud-storage/utilities';
|
|
3
3
|
import { UTApi } from 'uploadthing/server';
|
|
4
|
-
import {
|
|
4
|
+
import { createUploadthingAdapter } from './adapter.js';
|
|
5
5
|
import { getClientUploadRoute } from './getClientUploadRoute.js';
|
|
6
|
-
import { getHandleDelete } from './handleDelete.js';
|
|
7
|
-
import { getHandleUpload } from './handleUpload.js';
|
|
8
|
-
import { getHandler } from './staticHandler.js';
|
|
9
6
|
export const uploadthingStorage = (uploadthingStorageOptions)=>(incomingConfig)=>{
|
|
10
7
|
const isPluginDisabled = uploadthingStorageOptions.enabled === false;
|
|
11
8
|
initClientUploads({
|
|
@@ -24,24 +21,24 @@ export const uploadthingStorage = (uploadthingStorageOptions)=>(incomingConfig)=
|
|
|
24
21
|
if (isPluginDisabled) {
|
|
25
22
|
return incomingConfig;
|
|
26
23
|
}
|
|
27
|
-
|
|
28
|
-
|
|
29
|
-
|
|
30
|
-
|
|
31
|
-
|
|
32
|
-
|
|
33
|
-
|
|
24
|
+
const { acl = 'public-read', ...utOptions } = uploadthingStorageOptions.options;
|
|
25
|
+
const utApi = new UTApi(utOptions);
|
|
26
|
+
const adapter = createUploadthingAdapter({
|
|
27
|
+
acl,
|
|
28
|
+
clientUploads: uploadthingStorageOptions.clientUploads,
|
|
29
|
+
utApi
|
|
30
|
+
});
|
|
31
|
+
const collectionsWithAdapter = Object.entries(uploadthingStorageOptions.collections).reduce((acc, [slug, collOptions])=>{
|
|
32
|
+
const mergedOptions = {
|
|
33
|
+
...collOptions === true ? {} : collOptions,
|
|
34
|
+
adapter,
|
|
35
|
+
prefix: ''
|
|
36
|
+
};
|
|
37
|
+
return {
|
|
34
38
|
...acc,
|
|
35
|
-
[slug]:
|
|
36
|
-
|
|
37
|
-
|
|
38
|
-
// ...(uploadthingStorageOptions.options.acl === 'public-read'
|
|
39
|
-
// ? { disablePayloadAccessControl: true }
|
|
40
|
-
// : {}),
|
|
41
|
-
adapter
|
|
42
|
-
}
|
|
43
|
-
}), {});
|
|
44
|
-
// Set disableLocalStorage: true for collections specified in the plugin options
|
|
39
|
+
[slug]: mergedOptions
|
|
40
|
+
};
|
|
41
|
+
}, {});
|
|
45
42
|
const config = {
|
|
46
43
|
...incomingConfig,
|
|
47
44
|
collections: (incomingConfig.collections || []).map((collection)=>{
|
|
@@ -59,42 +56,9 @@ export const uploadthingStorage = (uploadthingStorageOptions)=>(incomingConfig)=
|
|
|
59
56
|
};
|
|
60
57
|
return cloudStoragePlugin({
|
|
61
58
|
alwaysInsertFields: uploadthingStorageOptions.alwaysInsertFields,
|
|
62
|
-
collections: collectionsWithAdapter
|
|
59
|
+
collections: collectionsWithAdapter,
|
|
60
|
+
useCompositePrefixes: false
|
|
63
61
|
})(config);
|
|
64
62
|
};
|
|
65
|
-
function uploadthingInternal(options) {
|
|
66
|
-
const fields = [
|
|
67
|
-
{
|
|
68
|
-
name: '_key',
|
|
69
|
-
type: 'text',
|
|
70
|
-
admin: {
|
|
71
|
-
disableBulkEdit: true,
|
|
72
|
-
disableListColumn: true,
|
|
73
|
-
disableListFilter: true,
|
|
74
|
-
hidden: true
|
|
75
|
-
}
|
|
76
|
-
}
|
|
77
|
-
];
|
|
78
|
-
return ()=>{
|
|
79
|
-
const { clientUploads, options: { acl = 'public-read', ...utOptions } } = options;
|
|
80
|
-
const utApi = new UTApi(utOptions);
|
|
81
|
-
return {
|
|
82
|
-
name: 'uploadthing',
|
|
83
|
-
clientUploads,
|
|
84
|
-
fields,
|
|
85
|
-
generateURL,
|
|
86
|
-
handleDelete: getHandleDelete({
|
|
87
|
-
utApi
|
|
88
|
-
}),
|
|
89
|
-
handleUpload: getHandleUpload({
|
|
90
|
-
acl,
|
|
91
|
-
utApi
|
|
92
|
-
}),
|
|
93
|
-
staticHandler: getHandler({
|
|
94
|
-
utApi
|
|
95
|
-
})
|
|
96
|
-
};
|
|
97
|
-
};
|
|
98
|
-
}
|
|
99
63
|
|
|
100
64
|
//# sourceMappingURL=index.js.map
|
package/dist/index.js.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"sources":["../src/index.ts"],"sourcesContent":["import type {\n
|
|
1
|
+
{"version":3,"sources":["../src/index.ts"],"sourcesContent":["import type {\n ClientUploadsAccess,\n PluginOptions as CloudStoragePluginOptions,\n CollectionOptions,\n} from '@payloadcms/plugin-cloud-storage/types'\nimport type { Config, Plugin, UploadCollectionSlug } from 'payload'\nimport type { createUploadthing } from 'uploadthing/server'\nimport type { UTApiOptions } from 'uploadthing/types'\n\nimport { cloudStoragePlugin } from '@payloadcms/plugin-cloud-storage'\nimport { initClientUploads } from '@payloadcms/plugin-cloud-storage/utilities'\nimport { UTApi } from 'uploadthing/server'\n\nimport { createUploadthingAdapter } from './adapter.js'\nimport { getClientUploadRoute } from './getClientUploadRoute.js'\n\nexport type FileRouterInputConfig = Parameters<ReturnType<typeof createUploadthing>>[0]\n\nexport type UploadthingStorageOptions = {\n /**\n * When enabled, fields (like the prefix field) will always be inserted into\n * the collection schema regardless of whether the plugin is enabled. This\n * ensures a consistent schema across all environments.\n *\n * This will be enabled by default in Payload v4.\n *\n * @default false\n */\n alwaysInsertFields?: boolean\n\n /**\n * Do uploads directly on the client, to bypass limits on Vercel.\n */\n clientUploads?:\n | {\n access?: ClientUploadsAccess\n routerInputConfig?: FileRouterInputConfig\n }\n | boolean\n\n /**\n * Collection options to apply the adapter to.\n *\n * TODO V4: OMIT 'prefix' from the collection options - uploadthing does not support prefixes\n */\n collections: Partial<Record<UploadCollectionSlug, Omit<CollectionOptions, 'adapter'> | true>>\n\n /**\n * Whether or not to enable the plugin\n *\n * Default: true\n */\n enabled?: boolean\n\n /**\n * Uploadthing Options\n */\n options: {\n /**\n * @default 'public-read'\n */\n acl?: ACL\n } & UTApiOptions\n}\n\ntype UploadthingPlugin = (uploadthingStorageOptions: UploadthingStorageOptions) => Plugin\n\n/** NOTE: not synced with uploadthing's internal types. Need to modify if more options added */\nexport type ACL = 'private' | 'public-read'\n\nexport const uploadthingStorage: UploadthingPlugin =\n (uploadthingStorageOptions: UploadthingStorageOptions) =>\n (incomingConfig: Config): Config => {\n const isPluginDisabled = uploadthingStorageOptions.enabled === false\n\n initClientUploads({\n clientHandler: '@payloadcms/storage-uploadthing/client#UploadthingClientUploadHandler',\n collections: uploadthingStorageOptions.collections,\n config: incomingConfig,\n enabled: !isPluginDisabled && Boolean(uploadthingStorageOptions.clientUploads),\n serverHandler: getClientUploadRoute({\n access:\n typeof uploadthingStorageOptions.clientUploads === 'object'\n ? uploadthingStorageOptions.clientUploads.access\n : undefined,\n acl: uploadthingStorageOptions.options.acl || 'public-read',\n routerInputConfig:\n typeof uploadthingStorageOptions.clientUploads === 'object'\n ? uploadthingStorageOptions.clientUploads.routerInputConfig\n : undefined,\n token: uploadthingStorageOptions.options.token,\n }),\n serverHandlerPath: '/storage-uploadthing-client-upload-route',\n })\n\n if (isPluginDisabled) {\n return incomingConfig\n }\n\n const { acl = 'public-read', ...utOptions } = uploadthingStorageOptions.options\n const utApi = new UTApi(utOptions)\n\n const adapter = createUploadthingAdapter({\n acl,\n clientUploads: uploadthingStorageOptions.clientUploads,\n utApi,\n })\n\n const collectionsWithAdapter: CloudStoragePluginOptions['collections'] = Object.entries(\n uploadthingStorageOptions.collections,\n ).reduce(\n (acc, [slug, collOptions]) => {\n const mergedOptions = {\n ...(collOptions === true ? {} : collOptions),\n adapter,\n prefix: '', // upload thing does not support prefixes\n }\n return {\n ...acc,\n [slug]: mergedOptions,\n }\n },\n {} as Record<string, CollectionOptions>,\n )\n\n const config = {\n ...incomingConfig,\n collections: (incomingConfig.collections || []).map((collection) => {\n if (!collectionsWithAdapter[collection.slug]) {\n return collection\n }\n\n return {\n ...collection,\n upload: {\n ...(typeof collection.upload === 'object' ? collection.upload : {}),\n disableLocalStorage: true,\n },\n }\n }),\n }\n\n return cloudStoragePlugin({\n alwaysInsertFields: uploadthingStorageOptions.alwaysInsertFields,\n collections: collectionsWithAdapter,\n useCompositePrefixes: false, // uploadthing does not support prefixes\n })(config)\n }\n"],"names":["cloudStoragePlugin","initClientUploads","UTApi","createUploadthingAdapter","getClientUploadRoute","uploadthingStorage","uploadthingStorageOptions","incomingConfig","isPluginDisabled","enabled","clientHandler","collections","config","Boolean","clientUploads","serverHandler","access","undefined","acl","options","routerInputConfig","token","serverHandlerPath","utOptions","utApi","adapter","collectionsWithAdapter","Object","entries","reduce","acc","slug","collOptions","mergedOptions","prefix","map","collection","upload","disableLocalStorage","alwaysInsertFields","useCompositePrefixes"],"mappings":"AASA,SAASA,kBAAkB,QAAQ,mCAAkC;AACrE,SAASC,iBAAiB,QAAQ,6CAA4C;AAC9E,SAASC,KAAK,QAAQ,qBAAoB;AAE1C,SAASC,wBAAwB,QAAQ,eAAc;AACvD,SAASC,oBAAoB,QAAQ,4BAA2B;AAwDhE,OAAO,M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AAOK;gBACT;gBAEA,OAAO;oBACL,GAAGA,UAAU;oBACbC,QAAQ;wBACN,GAAI,OAAOD,WAAWC,MAAM,KAAK,WAAWD,WAAWC,MAAM,GAAG,CAAC,CAAC;wBAClEC,qBAAqB;oBACvB;gBACF;YACF;QACF;QAEA,OAAOtC,mBAAmB;YACxBuC,oBAAoBjC,0BAA0BiC,kBAAkB;YAChE5B,aAAae;YACbc,sBAAsB;QACxB,GAAG5B;IACL,EAAC"}
|
|
@@ -0,0 +1,14 @@
|
|
|
1
|
+
import type { UTApi } from 'uploadthing/server';
|
|
2
|
+
import type { ACL } from './index.js';
|
|
3
|
+
interface UploadFileArgs {
|
|
4
|
+
acl: ACL;
|
|
5
|
+
buffer: Buffer;
|
|
6
|
+
clientUploadContext?: unknown;
|
|
7
|
+
data: Record<string, unknown>;
|
|
8
|
+
filename: string;
|
|
9
|
+
mimeType: string;
|
|
10
|
+
utApi: UTApi;
|
|
11
|
+
}
|
|
12
|
+
export declare function uploadFile({ acl, buffer, clientUploadContext, data, filename, mimeType, utApi, }: UploadFileArgs): Promise<Record<string, unknown>>;
|
|
13
|
+
export {};
|
|
14
|
+
//# sourceMappingURL=uploadFile.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"uploadFile.d.ts","sourceRoot":"","sources":["../src/uploadFile.ts"],"names":[],"mappings":"AAAA,OAAO,KAAK,EAAE,KAAK,EAAE,MAAM,oBAAoB,CAAA;AAK/C,OAAO,KAAK,EAAE,GAAG,EAAE,MAAM,YAAY,CAAA;AAErC,UAAU,cAAc;IACtB,GAAG,EAAE,GAAG,CAAA;IACR,MAAM,EAAE,MAAM,CAAA;IACd,mBAAmB,CAAC,EAAE,OAAO,CAAA;IAC7B,IAAI,EAAE,MAAM,CAAC,MAAM,EAAE,OAAO,CAAC,CAAA;IAC7B,QAAQ,EAAE,MAAM,CAAA;IAChB,QAAQ,EAAE,MAAM,CAAA;IAChB,KAAK,EAAE,KAAK,CAAA;CACb;AAED,wBAAsB,UAAU,CAAC,EAC/B,GAAG,EACH,MAAM,EACN,mBAAmB,EACnB,IAAI,EACJ,QAAQ,EACR,QAAQ,EACR,KAAK,GACN,EAAE,cAAc,GAAG,OAAO,CAAC,MAAM,CAAC,MAAM,EAAE,OAAO,CAAC,CAAC,CAkDnD"}
|
|
@@ -0,0 +1,47 @@
|
|
|
1
|
+
import { APIError } from 'payload';
|
|
2
|
+
import { UTFile } from 'uploadthing/server';
|
|
3
|
+
export async function uploadFile({ acl, buffer, clientUploadContext, data, filename, mimeType, utApi }) {
|
|
4
|
+
try {
|
|
5
|
+
if (clientUploadContext && typeof clientUploadContext === 'object' && 'key' in clientUploadContext && typeof clientUploadContext.key === 'string') {
|
|
6
|
+
await utApi.deleteFiles(clientUploadContext.key);
|
|
7
|
+
}
|
|
8
|
+
const blob = new Blob([
|
|
9
|
+
buffer
|
|
10
|
+
], {
|
|
11
|
+
type: mimeType
|
|
12
|
+
});
|
|
13
|
+
const res = await utApi.uploadFiles(new UTFile([
|
|
14
|
+
blob
|
|
15
|
+
], filename), {
|
|
16
|
+
acl
|
|
17
|
+
});
|
|
18
|
+
if (res.error) {
|
|
19
|
+
throw new APIError(`Error uploading file: ${res.error.code} - ${res.error.message}`);
|
|
20
|
+
}
|
|
21
|
+
const sizes = data.sizes;
|
|
22
|
+
const foundSize = Object.keys(sizes || {}).find((key)=>sizes?.[key]?.filename === filename);
|
|
23
|
+
if (foundSize && sizes && sizes[foundSize]) {
|
|
24
|
+
sizes[foundSize]._key = res.data?.key;
|
|
25
|
+
} else {
|
|
26
|
+
data._key = res.data?.key;
|
|
27
|
+
data.filename = res.data?.name;
|
|
28
|
+
}
|
|
29
|
+
return data;
|
|
30
|
+
} catch (error) {
|
|
31
|
+
if (error instanceof APIError) {
|
|
32
|
+
throw error;
|
|
33
|
+
}
|
|
34
|
+
if (error instanceof Error) {
|
|
35
|
+
if ('toJSON' in error && typeof error.toJSON === 'function') {
|
|
36
|
+
const json = error.toJSON();
|
|
37
|
+
if (json.cause?.defect?.error && json.cause.defect.data?.error) {
|
|
38
|
+
throw new APIError(`Error uploading file with uploadthing: ${json.cause.defect.error} - ${json.cause.defect.data.error}`);
|
|
39
|
+
}
|
|
40
|
+
}
|
|
41
|
+
throw new APIError(`Error uploading file with uploadthing: ${error.message}`);
|
|
42
|
+
}
|
|
43
|
+
throw new APIError('Error uploading file with uploadthing: Unknown error');
|
|
44
|
+
}
|
|
45
|
+
}
|
|
46
|
+
|
|
47
|
+
//# sourceMappingURL=uploadFile.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"sources":["../src/uploadFile.ts"],"sourcesContent":["import type { UTApi } from 'uploadthing/server'\n\nimport { APIError } from 'payload'\nimport { UTFile } from 'uploadthing/server'\n\nimport type { ACL } from './index.js'\n\ninterface UploadFileArgs {\n acl: ACL\n buffer: Buffer\n clientUploadContext?: unknown\n data: Record<string, unknown>\n filename: string\n mimeType: string\n utApi: UTApi\n}\n\nexport async function uploadFile({\n acl,\n buffer,\n clientUploadContext,\n data,\n filename,\n mimeType,\n utApi,\n}: UploadFileArgs): Promise<Record<string, unknown>> {\n try {\n if (\n clientUploadContext &&\n typeof clientUploadContext === 'object' &&\n 'key' in clientUploadContext &&\n typeof clientUploadContext.key === 'string'\n ) {\n await utApi.deleteFiles(clientUploadContext.key)\n }\n\n const blob = new Blob([buffer], { type: mimeType })\n const res = await utApi.uploadFiles(new UTFile([blob], filename), { acl })\n\n if (res.error) {\n throw new APIError(`Error uploading file: ${res.error.code} - ${res.error.message}`)\n }\n\n const sizes = data.sizes as Record<string, { _key?: string; filename?: string }> | undefined\n const foundSize = Object.keys(sizes || {}).find((key) => sizes?.[key]?.filename === filename)\n\n if (foundSize && sizes && sizes[foundSize]) {\n sizes[foundSize]._key = res.data?.key\n } else {\n data._key = res.data?.key\n data.filename = res.data?.name\n }\n\n return data\n } catch (error: unknown) {\n if (error instanceof APIError) {\n throw error\n }\n\n if (error instanceof Error) {\n if ('toJSON' in error && typeof error.toJSON === 'function') {\n const json = error.toJSON() as {\n cause?: { defect?: { _id?: string; data?: { error?: string }; error?: string } }\n }\n if (json.cause?.defect?.error && json.cause.defect.data?.error) {\n throw new APIError(\n `Error uploading file with uploadthing: ${json.cause.defect.error} - ${json.cause.defect.data.error}`,\n )\n }\n }\n throw new APIError(`Error uploading file with uploadthing: ${error.message}`)\n }\n\n throw new APIError('Error uploading file with uploadthing: Unknown error')\n }\n}\n"],"names":["APIError","UTFile","uploadFile","acl","buffer","clientUploadContext","data","filename","mimeType","utApi","key","deleteFiles","blob","Blob","type","res","uploadFiles","error","code","message","sizes","foundSize","Object","keys","find","_key","name","Error","toJSON","json","cause","defect"],"mappings":"AAEA,SAASA,QAAQ,QAAQ,UAAS;AAClC,SAASC,MAAM,QAAQ,qBAAoB;AAc3C,OAAO,eAAeC,WAAW,EAC/BC,GAAG,EACHC,MAAM,EACNC,mBAAmB,EACnBC,IAAI,EACJC,QAAQ,EACRC,QAAQ,EACRC,KAAK,EACU;IACf,IAAI;QACF,IACEJ,uBACA,OAAOA,wBAAwB,YAC/B,SAASA,uBACT,OAAOA,oBAAoBK,GAAG,KAAK,UACnC;YACA,MAAMD,MAAME,WAAW,CAACN,oBAAoBK,GAAG;QACjD;QAEA,MAAME,OAAO,IAAIC,KAAK;YAACT;SAAO,EAAE;YAAEU,MAAMN;QAAS;QACjD,MAAMO,MAAM,MAAMN,MAAMO,WAAW,CAAC,IAAIf,OAAO;YAACW;SAAK,EAAEL,WAAW;YAAEJ;QAAI;QAExE,IAAIY,IAAIE,KAAK,EAAE;YACb,MAAM,IAAIjB,SAAS,CAAC,sBAAsB,EAAEe,IAAIE,KAAK,CAACC,IAAI,CAAC,GAAG,EAAEH,IAAIE,KAAK,CAACE,OAAO,EAAE;QACrF;QAEA,MAAMC,QAAQd,KAAKc,KAAK;QACxB,MAAMC,YAAYC,OAAOC,IAAI,CAACH,SAAS,CAAC,GAAGI,IAAI,CAAC,CAACd,MAAQU,OAAO,CAACV,IAAI,EAAEH,aAAaA;QAEpF,IAAIc,aAAaD,SAASA,KAAK,CAACC,UAAU,EAAE;YAC1CD,KAAK,CAACC,UAAU,CAACI,IAAI,GAAGV,IAAIT,IAAI,EAAEI;QACpC,OAAO;YACLJ,KAAKmB,IAAI,GAAGV,IAAIT,IAAI,EAAEI;YACtBJ,KAAKC,QAAQ,GAAGQ,IAAIT,IAAI,EAAEoB;QAC5B;QAEA,OAAOpB;IACT,EAAE,OAAOW,OAAgB;QACvB,IAAIA,iBAAiBjB,UAAU;YAC7B,MAAMiB;QACR;QAEA,IAAIA,iBAAiBU,OAAO;YAC1B,IAAI,YAAYV,SAAS,OAAOA,MAAMW,MAAM,KAAK,YAAY;gBAC3D,MAAMC,OAAOZ,MAAMW,MAAM;gBAGzB,IAAIC,KAAKC,KAAK,EAAEC,QAAQd,SAASY,KAAKC,KAAK,CAACC,MAAM,CAACzB,IAAI,EAAEW,OAAO;oBAC9D,MAAM,IAAIjB,SACR,CAAC,uCAAuC,EAAE6B,KAAKC,KAAK,CAACC,MAAM,CAACd,KAAK,CAAC,GAAG,EAAEY,KAAKC,KAAK,CAACC,MAAM,CAACzB,IAAI,CAACW,KAAK,EAAE;gBAEzG;YACF;YACA,MAAM,IAAIjB,SAAS,CAAC,uCAAuC,EAAEiB,MAAME,OAAO,EAAE;QAC9E;QAEA,MAAM,IAAInB,SAAS;IACrB;AACF"}
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@payloadcms/storage-uploadthing",
|
|
3
|
-
"version": "3.
|
|
3
|
+
"version": "3.83.0-canary.1",
|
|
4
4
|
"description": "Payload storage adapter for uploadthing",
|
|
5
5
|
"homepage": "https://payloadcms.com",
|
|
6
6
|
"repository": {
|
|
@@ -38,13 +38,13 @@
|
|
|
38
38
|
],
|
|
39
39
|
"dependencies": {
|
|
40
40
|
"uploadthing": "7.3.0",
|
|
41
|
-
"@payloadcms/plugin-cloud-storage": "3.
|
|
41
|
+
"@payloadcms/plugin-cloud-storage": "3.83.0-canary.1"
|
|
42
42
|
},
|
|
43
43
|
"devDependencies": {
|
|
44
|
-
"payload": "3.
|
|
44
|
+
"payload": "3.83.0-canary.1"
|
|
45
45
|
},
|
|
46
46
|
"peerDependencies": {
|
|
47
|
-
"payload": "3.
|
|
47
|
+
"payload": "3.83.0-canary.1"
|
|
48
48
|
},
|
|
49
49
|
"engines": {
|
|
50
50
|
"node": "^18.20.2 || >=20.9.0"
|
package/dist/handleDelete.d.ts
DELETED
|
@@ -1,8 +0,0 @@
|
|
|
1
|
-
import type { HandleDelete } from '@payloadcms/plugin-cloud-storage/types';
|
|
2
|
-
import type { UTApi } from 'uploadthing/server';
|
|
3
|
-
type Args = {
|
|
4
|
-
utApi: UTApi;
|
|
5
|
-
};
|
|
6
|
-
export declare const getHandleDelete: ({ utApi }: Args) => HandleDelete;
|
|
7
|
-
export {};
|
|
8
|
-
//# sourceMappingURL=handleDelete.d.ts.map
|
|
@@ -1 +0,0 @@
|
|
|
1
|
-
{"version":3,"file":"handleDelete.d.ts","sourceRoot":"","sources":["../src/handleDelete.ts"],"names":[],"mappings":"AAAA,OAAO,KAAK,EAAE,YAAY,EAAE,MAAM,wCAAwC,CAAA;AAC1E,OAAO,KAAK,EAAE,KAAK,EAAE,MAAM,oBAAoB,CAAA;AAM/C,KAAK,IAAI,GAAG;IACV,KAAK,EAAE,KAAK,CAAA;CACb,CAAA;AAED,eAAO,MAAM,eAAe,cAAe,IAAI,KAAG,YAuBjD,CAAA"}
|
package/dist/handleDelete.js
DELETED
|
@@ -1,26 +0,0 @@
|
|
|
1
|
-
import { APIError } from 'payload';
|
|
2
|
-
import { getKeyFromFilename } from './utilities.js';
|
|
3
|
-
export const getHandleDelete = ({ utApi })=>{
|
|
4
|
-
return async ({ doc, filename, req })=>{
|
|
5
|
-
const key = getKeyFromFilename(doc, filename);
|
|
6
|
-
if (!key) {
|
|
7
|
-
req.payload.logger.error({
|
|
8
|
-
msg: `Error deleting file: ${filename} - unable to extract key from doc`
|
|
9
|
-
});
|
|
10
|
-
throw new APIError(`Error deleting file: ${filename}`);
|
|
11
|
-
}
|
|
12
|
-
try {
|
|
13
|
-
if (key) {
|
|
14
|
-
await utApi.deleteFiles(key);
|
|
15
|
-
}
|
|
16
|
-
} catch (err) {
|
|
17
|
-
req.payload.logger.error({
|
|
18
|
-
err,
|
|
19
|
-
msg: `Error deleting file with key: ${filename} - key: ${key}`
|
|
20
|
-
});
|
|
21
|
-
throw new APIError(`Error deleting file: ${filename}`);
|
|
22
|
-
}
|
|
23
|
-
};
|
|
24
|
-
};
|
|
25
|
-
|
|
26
|
-
//# sourceMappingURL=handleDelete.js.map
|
package/dist/handleDelete.js.map
DELETED
|
@@ -1 +0,0 @@
|
|
|
1
|
-
{"version":3,"sources":["../src/handleDelete.ts"],"sourcesContent":["import type { HandleDelete } from '@payloadcms/plugin-cloud-storage/types'\nimport type { UTApi } from 'uploadthing/server'\n\nimport { APIError } from 'payload'\n\nimport { getKeyFromFilename } from './utilities.js'\n\ntype Args = {\n utApi: UTApi\n}\n\nexport const getHandleDelete = ({ utApi }: Args): HandleDelete => {\n return async ({ doc, filename, req }) => {\n const key = getKeyFromFilename(doc, filename)\n\n if (!key) {\n req.payload.logger.error({\n msg: `Error deleting file: ${filename} - unable to extract key from doc`,\n })\n throw new APIError(`Error deleting file: ${filename}`)\n }\n\n try {\n if (key) {\n await utApi.deleteFiles(key)\n }\n } catch (err) {\n req.payload.logger.error({\n err,\n msg: `Error deleting file with key: ${filename} - key: ${key}`,\n })\n throw new APIError(`Error deleting file: ${filename}`)\n }\n }\n}\n"],"names":["APIError","getKeyFromFilename","getHandleDelete","utApi","doc","filename","req","key","payload","logger","error","msg","deleteFiles","err"],"mappings":"AAGA,SAASA,QAAQ,QAAQ,UAAS;AAElC,SAASC,kBAAkB,QAAQ,iBAAgB;AAMnD,OAAO,MAAMC,kBAAkB,CAAC,EAAEC,KAAK,EAAQ;IAC7C,OAAO,OAAO,EAAEC,GAAG,EAAEC,QAAQ,EAAEC,GAAG,EAAE;QAClC,MAAMC,MAAMN,mBAAmBG,KAAKC;QAEpC,IAAI,CAACE,KAAK;YACRD,IAAIE,OAAO,CAACC,MAAM,CAACC,KAAK,CAAC;gBACvBC,KAAK,CAAC,qBAAqB,EAAEN,SAAS,iCAAiC,CAAC;YAC1E;YACA,MAAM,IAAIL,SAAS,CAAC,qBAAqB,EAAEK,UAAU;QACvD;QAEA,IAAI;YACF,IAAIE,KAAK;gBACP,MAAMJ,MAAMS,WAAW,CAACL;YAC1B;QACF,EAAE,OAAOM,KAAK;YACZP,IAAIE,OAAO,CAACC,MAAM,CAACC,KAAK,CAAC;gBACvBG;gBACAF,KAAK,CAAC,8BAA8B,EAAEN,SAAS,QAAQ,EAAEE,KAAK;YAChE;YACA,MAAM,IAAIP,SAAS,CAAC,qBAAqB,EAAEK,UAAU;QACvD;IACF;AACF,EAAC"}
|
package/dist/handleUpload.d.ts
DELETED
|
@@ -1,10 +0,0 @@
|
|
|
1
|
-
import type { HandleUpload } from '@payloadcms/plugin-cloud-storage/types';
|
|
2
|
-
import type { UTApi } from 'uploadthing/server';
|
|
3
|
-
import type { ACL } from './index.js';
|
|
4
|
-
type HandleUploadArgs = {
|
|
5
|
-
acl: ACL;
|
|
6
|
-
utApi: UTApi;
|
|
7
|
-
};
|
|
8
|
-
export declare const getHandleUpload: ({ acl, utApi }: HandleUploadArgs) => HandleUpload;
|
|
9
|
-
export {};
|
|
10
|
-
//# sourceMappingURL=handleUpload.d.ts.map
|
|
@@ -1 +0,0 @@
|
|
|
1
|
-
{"version":3,"file":"handleUpload.d.ts","sourceRoot":"","sources":["../src/handleUpload.ts"],"names":[],"mappings":"AAAA,OAAO,KAAK,EAAE,YAAY,EAAE,MAAM,wCAAwC,CAAA;AAC1E,OAAO,KAAK,EAAE,KAAK,EAAE,MAAM,oBAAoB,CAAA;AAK/C,OAAO,KAAK,EAAE,GAAG,EAAE,MAAM,YAAY,CAAA;AAErC,KAAK,gBAAgB,GAAG;IACtB,GAAG,EAAE,GAAG,CAAA;IACR,KAAK,EAAE,KAAK,CAAA;CACb,CAAA;AAED,eAAO,MAAM,eAAe,mBAAoB,gBAAgB,KAAG,YAqDlE,CAAA"}
|
package/dist/handleUpload.js
DELETED
|
@@ -1,49 +0,0 @@
|
|
|
1
|
-
import { APIError } from 'payload';
|
|
2
|
-
import { UTFile } from 'uploadthing/server';
|
|
3
|
-
export const getHandleUpload = ({ acl, utApi })=>{
|
|
4
|
-
return async ({ clientUploadContext, data, file })=>{
|
|
5
|
-
try {
|
|
6
|
-
if (clientUploadContext && typeof clientUploadContext === 'object' && 'key' in clientUploadContext && typeof clientUploadContext.key === 'string') {
|
|
7
|
-
// Clear the old file
|
|
8
|
-
await utApi.deleteFiles(clientUploadContext.key);
|
|
9
|
-
}
|
|
10
|
-
const { buffer, filename, mimeType } = file;
|
|
11
|
-
const blob = new Blob([
|
|
12
|
-
buffer
|
|
13
|
-
], {
|
|
14
|
-
type: mimeType
|
|
15
|
-
});
|
|
16
|
-
const res = await utApi.uploadFiles(new UTFile([
|
|
17
|
-
blob
|
|
18
|
-
], filename), {
|
|
19
|
-
acl
|
|
20
|
-
});
|
|
21
|
-
if (res.error) {
|
|
22
|
-
throw new APIError(`Error uploading file: ${res.error.code} - ${res.error.message}`);
|
|
23
|
-
}
|
|
24
|
-
// Find matching data.sizes entry
|
|
25
|
-
const foundSize = Object.keys(data.sizes || {}).find((key)=>data.sizes?.[key]?.filename === filename);
|
|
26
|
-
if (foundSize) {
|
|
27
|
-
data.sizes[foundSize]._key = res.data?.key;
|
|
28
|
-
} else {
|
|
29
|
-
data._key = res.data?.key;
|
|
30
|
-
data.filename = res.data?.name;
|
|
31
|
-
}
|
|
32
|
-
return data;
|
|
33
|
-
} catch (error) {
|
|
34
|
-
if (error instanceof Error) {
|
|
35
|
-
// Interrogate uploadthing error which returns FiberFailure
|
|
36
|
-
if ('toJSON' in error && typeof error.toJSON === 'function') {
|
|
37
|
-
const json = error.toJSON();
|
|
38
|
-
if (json.cause?.defect?.error && json.cause.defect.data?.error) {
|
|
39
|
-
throw new APIError(`Error uploading file with uploadthing: ${json.cause.defect.error} - ${json.cause.defect.data.error}`);
|
|
40
|
-
}
|
|
41
|
-
} else {
|
|
42
|
-
throw new APIError(`Error uploading file with uploadthing: ${error.message}`);
|
|
43
|
-
}
|
|
44
|
-
}
|
|
45
|
-
}
|
|
46
|
-
};
|
|
47
|
-
};
|
|
48
|
-
|
|
49
|
-
//# sourceMappingURL=handleUpload.js.map
|
package/dist/handleUpload.js.map
DELETED
|
@@ -1 +0,0 @@
|
|
|
1
|
-
{"version":3,"sources":["../src/handleUpload.ts"],"sourcesContent":["import type { HandleUpload } from '@payloadcms/plugin-cloud-storage/types'\nimport type { UTApi } from 'uploadthing/server'\n\nimport { APIError } from 'payload'\nimport { UTFile } from 'uploadthing/server'\n\nimport type { ACL } from './index.js'\n\ntype HandleUploadArgs = {\n acl: ACL\n utApi: UTApi\n}\n\nexport const getHandleUpload = ({ acl, utApi }: HandleUploadArgs): HandleUpload => {\n return async ({ clientUploadContext, data, file }) => {\n try {\n if (\n clientUploadContext &&\n typeof clientUploadContext === 'object' &&\n 'key' in clientUploadContext &&\n typeof clientUploadContext.key === 'string'\n ) {\n // Clear the old file\n await utApi.deleteFiles(clientUploadContext.key)\n }\n\n const { buffer, filename, mimeType } = file\n\n const blob = new Blob([buffer], { type: mimeType })\n const res = await utApi.uploadFiles(new UTFile([blob], filename), { acl })\n\n if (res.error) {\n throw new APIError(`Error uploading file: ${res.error.code} - ${res.error.message}`)\n }\n\n // Find matching data.sizes entry\n const foundSize = Object.keys(data.sizes || {}).find(\n (key) => data.sizes?.[key]?.filename === filename,\n )\n\n if (foundSize) {\n data.sizes[foundSize]._key = res.data?.key\n } else {\n data._key = res.data?.key\n data.filename = res.data?.name\n }\n\n return data\n } catch (error: unknown) {\n if (error instanceof Error) {\n // Interrogate uploadthing error which returns FiberFailure\n if ('toJSON' in error && typeof error.toJSON === 'function') {\n const json = error.toJSON() as {\n cause?: { defect?: { _id?: string; data?: { error?: string }; error?: string } }\n }\n if (json.cause?.defect?.error && json.cause.defect.data?.error) {\n throw new APIError(\n `Error uploading file with uploadthing: ${json.cause.defect.error} - ${json.cause.defect.data.error}`,\n )\n }\n } else {\n throw new APIError(`Error uploading file with uploadthing: ${error.message}`)\n }\n }\n }\n }\n}\n"],"names":["APIError","UTFile","getHandleUpload","acl","utApi","clientUploadContext","data","file","key","deleteFiles","buffer","filename","mimeType","blob","Blob","type","res","uploadFiles","error","code","message","foundSize","Object","keys","sizes","find","_key","name","Error","toJSON","json","cause","defect"],"mappings":"AAGA,SAASA,QAAQ,QAAQ,UAAS;AAClC,SAASC,MAAM,QAAQ,qBAAoB;AAS3C,OAAO,MAAMC,kBAAkB,CAAC,EAAEC,GAAG,EAAEC,KAAK,EAAoB;IAC9D,OAAO,OAAO,EAAEC,mBAAmB,EAAEC,IAAI,EAAEC,IAAI,EAAE;QAC/C,IAAI;YACF,IACEF,uBACA,OAAOA,wBAAwB,YAC/B,SAASA,uBACT,OAAOA,oBAAoBG,GAAG,KAAK,UACnC;gBACA,qBAAqB;gBACrB,MAAMJ,MAAMK,WAAW,CAACJ,oBAAoBG,GAAG;YACjD;YAEA,MAAM,EAAEE,MAAM,EAAEC,QAAQ,EAAEC,QAAQ,EAAE,GAAGL;YAEvC,MAAMM,OAAO,IAAIC,KAAK;gBAACJ;aAAO,EAAE;gBAAEK,MAAMH;YAAS;YACjD,MAAMI,MAAM,MAAMZ,MAAMa,WAAW,CAAC,IAAIhB,OAAO;gBAACY;aAAK,EAAEF,WAAW;gBAAER;YAAI;YAExE,IAAIa,IAAIE,KAAK,EAAE;gBACb,MAAM,IAAIlB,SAAS,CAAC,sBAAsB,EAAEgB,IAAIE,KAAK,CAACC,IAAI,CAAC,GAAG,EAAEH,IAAIE,KAAK,CAACE,OAAO,EAAE;YACrF;YAEA,iCAAiC;YACjC,MAAMC,YAAYC,OAAOC,IAAI,CAACjB,KAAKkB,KAAK,IAAI,CAAC,GAAGC,IAAI,CAClD,CAACjB,MAAQF,KAAKkB,KAAK,EAAE,CAAChB,IAAI,EAAEG,aAAaA;YAG3C,IAAIU,WAAW;gBACbf,KAAKkB,KAAK,CAACH,UAAU,CAACK,IAAI,GAAGV,IAAIV,IAAI,EAAEE;YACzC,OAAO;gBACLF,KAAKoB,IAAI,GAAGV,IAAIV,IAAI,EAAEE;gBACtBF,KAAKK,QAAQ,GAAGK,IAAIV,IAAI,EAAEqB;YAC5B;YAEA,OAAOrB;QACT,EAAE,OAAOY,OAAgB;YACvB,IAAIA,iBAAiBU,OAAO;gBAC1B,2DAA2D;gBAC3D,IAAI,YAAYV,SAAS,OAAOA,MAAMW,MAAM,KAAK,YAAY;oBAC3D,MAAMC,OAAOZ,MAAMW,MAAM;oBAGzB,IAAIC,KAAKC,KAAK,EAAEC,QAAQd,SAASY,KAAKC,KAAK,CAACC,MAAM,CAAC1B,IAAI,EAAEY,OAAO;wBAC9D,MAAM,IAAIlB,SACR,CAAC,uCAAuC,EAAE8B,KAAKC,KAAK,CAACC,MAAM,CAACd,KAAK,CAAC,GAAG,EAAEY,KAAKC,KAAK,CAACC,MAAM,CAAC1B,IAAI,CAACY,KAAK,EAAE;oBAEzG;gBACF,OAAO;oBACL,MAAM,IAAIlB,SAAS,CAAC,uCAAuC,EAAEkB,MAAME,OAAO,EAAE;gBAC9E;YACF;QACF;IACF;AACF,EAAC"}
|
package/dist/staticHandler.d.ts
DELETED
|
@@ -1,8 +0,0 @@
|
|
|
1
|
-
import type { StaticHandler } from '@payloadcms/plugin-cloud-storage/types';
|
|
2
|
-
import type { UTApi } from 'uploadthing/server';
|
|
3
|
-
type Args = {
|
|
4
|
-
utApi: UTApi;
|
|
5
|
-
};
|
|
6
|
-
export declare const getHandler: ({ utApi }: Args) => StaticHandler;
|
|
7
|
-
export {};
|
|
8
|
-
//# sourceMappingURL=staticHandler.d.ts.map
|
|
@@ -1 +0,0 @@
|
|
|
1
|
-
{"version":3,"file":"staticHandler.d.ts","sourceRoot":"","sources":["../src/staticHandler.ts"],"names":[],"mappings":"AAAA,OAAO,KAAK,EAAE,aAAa,EAAE,MAAM,wCAAwC,CAAA;AAE3E,OAAO,KAAK,EAAE,KAAK,EAAE,MAAM,oBAAoB,CAAA;AAM/C,KAAK,IAAI,GAAG;IACV,KAAK,EAAE,KAAK,CAAA;CACb,CAAA;AAED,eAAO,MAAM,UAAU,cAAe,IAAI,KAAG,aAgJ5C,CAAA"}
|
package/dist/staticHandler.js
DELETED
|
@@ -1,140 +0,0 @@
|
|
|
1
|
-
import { getRangeRequestInfo } from 'payload/internal';
|
|
2
|
-
import { getKeyFromFilename } from './utilities.js';
|
|
3
|
-
export const getHandler = ({ utApi })=>{
|
|
4
|
-
return async (req, { doc, headers: incomingHeaders, params: { clientUploadContext, collection, filename } })=>{
|
|
5
|
-
try {
|
|
6
|
-
let key;
|
|
7
|
-
const collectionConfig = req.payload.collections[collection]?.config;
|
|
8
|
-
if (clientUploadContext && typeof clientUploadContext === 'object' && 'key' in clientUploadContext && typeof clientUploadContext.key === 'string') {
|
|
9
|
-
key = clientUploadContext.key;
|
|
10
|
-
} else {
|
|
11
|
-
let retrievedDoc = doc;
|
|
12
|
-
if (!retrievedDoc) {
|
|
13
|
-
const or = [
|
|
14
|
-
{
|
|
15
|
-
filename: {
|
|
16
|
-
equals: filename
|
|
17
|
-
}
|
|
18
|
-
}
|
|
19
|
-
];
|
|
20
|
-
if (collectionConfig?.upload.imageSizes) {
|
|
21
|
-
collectionConfig.upload.imageSizes.forEach(({ name })=>{
|
|
22
|
-
or.push({
|
|
23
|
-
[`sizes.${name}.filename`]: {
|
|
24
|
-
equals: filename
|
|
25
|
-
}
|
|
26
|
-
});
|
|
27
|
-
});
|
|
28
|
-
}
|
|
29
|
-
const result = await req.payload.db.findOne({
|
|
30
|
-
collection,
|
|
31
|
-
req,
|
|
32
|
-
where: {
|
|
33
|
-
or
|
|
34
|
-
}
|
|
35
|
-
});
|
|
36
|
-
if (result) {
|
|
37
|
-
retrievedDoc = result;
|
|
38
|
-
}
|
|
39
|
-
}
|
|
40
|
-
if (!retrievedDoc) {
|
|
41
|
-
return new Response(null, {
|
|
42
|
-
status: 404,
|
|
43
|
-
statusText: 'Not Found'
|
|
44
|
-
});
|
|
45
|
-
}
|
|
46
|
-
key = getKeyFromFilename(retrievedDoc, filename);
|
|
47
|
-
}
|
|
48
|
-
if (!key) {
|
|
49
|
-
return new Response(null, {
|
|
50
|
-
status: 404,
|
|
51
|
-
statusText: 'Not Found'
|
|
52
|
-
});
|
|
53
|
-
}
|
|
54
|
-
const { url: signedURL } = await utApi.getSignedURL(key);
|
|
55
|
-
if (!signedURL) {
|
|
56
|
-
return new Response(null, {
|
|
57
|
-
status: 404,
|
|
58
|
-
statusText: 'Not Found'
|
|
59
|
-
});
|
|
60
|
-
}
|
|
61
|
-
// Get file metadata first for range validation
|
|
62
|
-
const headResponse = await fetch(signedURL, {
|
|
63
|
-
method: 'HEAD'
|
|
64
|
-
});
|
|
65
|
-
if (!headResponse.ok) {
|
|
66
|
-
return new Response(null, {
|
|
67
|
-
status: 404,
|
|
68
|
-
statusText: 'Not Found'
|
|
69
|
-
});
|
|
70
|
-
}
|
|
71
|
-
const fileSize = Number(headResponse.headers.get('content-length'));
|
|
72
|
-
// Handle range request
|
|
73
|
-
const rangeHeader = req.headers.get('range');
|
|
74
|
-
const rangeResult = getRangeRequestInfo({
|
|
75
|
-
fileSize,
|
|
76
|
-
rangeHeader
|
|
77
|
-
});
|
|
78
|
-
if (rangeResult.type === 'invalid') {
|
|
79
|
-
return new Response(null, {
|
|
80
|
-
headers: new Headers(rangeResult.headers),
|
|
81
|
-
status: rangeResult.status
|
|
82
|
-
});
|
|
83
|
-
}
|
|
84
|
-
const response = await fetch(signedURL, {
|
|
85
|
-
headers: rangeResult.type === 'partial' ? {
|
|
86
|
-
Range: `bytes=${rangeResult.rangeStart}-${rangeResult.rangeEnd}`
|
|
87
|
-
} : undefined
|
|
88
|
-
});
|
|
89
|
-
if (!response.ok || !response.body) {
|
|
90
|
-
return new Response(null, {
|
|
91
|
-
status: 404,
|
|
92
|
-
statusText: 'Not Found'
|
|
93
|
-
});
|
|
94
|
-
}
|
|
95
|
-
const etagFromHeaders = req.headers.get('etag') || req.headers.get('if-none-match');
|
|
96
|
-
const objectEtag = response.headers.get('etag');
|
|
97
|
-
let headers = new Headers(incomingHeaders);
|
|
98
|
-
// Add range-related headers from the result
|
|
99
|
-
for (const [key, value] of Object.entries(rangeResult.headers)){
|
|
100
|
-
headers.append(key, value);
|
|
101
|
-
}
|
|
102
|
-
const contentType = response.headers.get('content-type');
|
|
103
|
-
if (contentType) {
|
|
104
|
-
headers.append('Content-Type', contentType);
|
|
105
|
-
}
|
|
106
|
-
if (objectEtag) {
|
|
107
|
-
headers.append('ETag', objectEtag);
|
|
108
|
-
}
|
|
109
|
-
// Add Content-Security-Policy header for SVG files to prevent executable code
|
|
110
|
-
if (contentType === 'image/svg+xml') {
|
|
111
|
-
headers.append('Content-Security-Policy', "script-src 'none'");
|
|
112
|
-
}
|
|
113
|
-
if (collectionConfig?.upload && typeof collectionConfig.upload === 'object' && typeof collectionConfig.upload.modifyResponseHeaders === 'function') {
|
|
114
|
-
headers = collectionConfig.upload.modifyResponseHeaders({
|
|
115
|
-
headers
|
|
116
|
-
}) || headers;
|
|
117
|
-
}
|
|
118
|
-
if (etagFromHeaders && etagFromHeaders === objectEtag) {
|
|
119
|
-
return new Response(null, {
|
|
120
|
-
headers,
|
|
121
|
-
status: 304
|
|
122
|
-
});
|
|
123
|
-
}
|
|
124
|
-
return new Response(response.body, {
|
|
125
|
-
headers,
|
|
126
|
-
status: rangeResult.status
|
|
127
|
-
});
|
|
128
|
-
} catch (err) {
|
|
129
|
-
req.payload.logger.error({
|
|
130
|
-
err,
|
|
131
|
-
msg: 'Unexpected error in staticHandler'
|
|
132
|
-
});
|
|
133
|
-
return new Response('Internal Server Error', {
|
|
134
|
-
status: 500
|
|
135
|
-
});
|
|
136
|
-
}
|
|
137
|
-
};
|
|
138
|
-
};
|
|
139
|
-
|
|
140
|
-
//# sourceMappingURL=staticHandler.js.map
|
|
@@ -1 +0,0 @@
|
|
|
1
|
-
{"version":3,"sources":["../src/staticHandler.ts"],"sourcesContent":["import type { StaticHandler } from '@payloadcms/plugin-cloud-storage/types'\nimport type { Where } from 'payload'\nimport type { UTApi } from 'uploadthing/server'\n\nimport { getRangeRequestInfo } from 'payload/internal'\n\nimport { getKeyFromFilename } from './utilities.js'\n\ntype Args = {\n utApi: UTApi\n}\n\nexport const getHandler = ({ utApi }: Args): StaticHandler => {\n return async (\n req,\n { doc, headers: incomingHeaders, params: { clientUploadContext, collection, filename } },\n ) => {\n try {\n let key: string\n const collectionConfig = req.payload.collections[collection]?.config\n\n if (\n clientUploadContext &&\n typeof clientUploadContext === 'object' &&\n 'key' in clientUploadContext &&\n typeof clientUploadContext.key === 'string'\n ) {\n key = clientUploadContext.key\n } else {\n let retrievedDoc = doc\n\n if (!retrievedDoc) {\n const or: Where[] = [\n {\n filename: {\n equals: filename,\n },\n },\n ]\n\n if (collectionConfig?.upload.imageSizes) {\n collectionConfig.upload.imageSizes.forEach(({ name }) => {\n or.push({\n [`sizes.${name}.filename`]: {\n equals: filename,\n },\n })\n })\n }\n\n const result = await req.payload.db.findOne({\n collection,\n req,\n where: { or },\n })\n\n if (result) {\n retrievedDoc = result\n }\n }\n\n if (!retrievedDoc) {\n return new Response(null, { status: 404, statusText: 'Not Found' })\n }\n\n key = getKeyFromFilename(retrievedDoc, filename)!\n }\n\n if (!key) {\n return new Response(null, { status: 404, statusText: 'Not Found' })\n }\n\n const { url: signedURL } = await utApi.getSignedURL(key)\n\n if (!signedURL) {\n return new Response(null, { status: 404, statusText: 'Not Found' })\n }\n\n // Get file metadata first for range validation\n const headResponse = await fetch(signedURL, { method: 'HEAD' })\n if (!headResponse.ok) {\n return new Response(null, { status: 404, statusText: 'Not Found' })\n }\n\n const fileSize = Number(headResponse.headers.get('content-length'))\n\n // Handle range request\n const rangeHeader = req.headers.get('range')\n const rangeResult = getRangeRequestInfo({ fileSize, rangeHeader })\n\n if (rangeResult.type === 'invalid') {\n return new Response(null, {\n headers: new Headers(rangeResult.headers),\n status: rangeResult.status,\n })\n }\n\n const response = await fetch(signedURL, {\n headers:\n rangeResult.type === 'partial'\n ? { Range: `bytes=${rangeResult.rangeStart}-${rangeResult.rangeEnd}` }\n : undefined,\n })\n\n if (!response.ok || !response.body) {\n return new Response(null, { status: 404, statusText: 'Not Found' })\n }\n\n const etagFromHeaders = req.headers.get('etag') || req.headers.get('if-none-match')\n const objectEtag = response.headers.get('etag')\n\n let headers = new Headers(incomingHeaders)\n\n // Add range-related headers from the result\n for (const [key, value] of Object.entries(rangeResult.headers)) {\n headers.append(key, value)\n }\n\n const contentType = response.headers.get('content-type')\n if (contentType) {\n headers.append('Content-Type', contentType)\n }\n\n if (objectEtag) {\n headers.append('ETag', objectEtag)\n }\n\n // Add Content-Security-Policy header for SVG files to prevent executable code\n if (contentType === 'image/svg+xml') {\n headers.append('Content-Security-Policy', \"script-src 'none'\")\n }\n\n if (\n collectionConfig?.upload &&\n typeof collectionConfig.upload === 'object' &&\n typeof collectionConfig.upload.modifyResponseHeaders === 'function'\n ) {\n headers = collectionConfig.upload.modifyResponseHeaders({ headers }) || headers\n }\n\n if (etagFromHeaders && etagFromHeaders === objectEtag) {\n return new Response(null, {\n headers,\n status: 304,\n })\n }\n\n return new Response(response.body, {\n headers,\n status: rangeResult.status,\n })\n } catch (err) {\n req.payload.logger.error({ err, msg: 'Unexpected error in staticHandler' })\n return new Response('Internal Server Error', { status: 500 })\n }\n }\n}\n"],"names":["getRangeRequestInfo","getKeyFromFilename","getHandler","utApi","req","doc","headers","incomingHeaders","params","clientUploadContext","collection","filename","key","collectionConfig","payload","collections","config","retrievedDoc","or","equals","upload","imageSizes","forEach","name","push","result","db","findOne","where","Response","status","statusText","url","signedURL","getSignedURL","headResponse","fetch","method","ok","fileSize","Number","get","rangeHeader","rangeResult","type","Headers","response","Range","rangeStart","rangeEnd","undefined","body","etagFromHeaders","objectEtag","value","Object","entries","append","contentType","modifyResponseHeaders","err","logger","error","msg"],"mappings":"AAIA,SAASA,mBAAmB,QAAQ,mBAAkB;AAEtD,SAASC,kBAAkB,QAAQ,iBAAgB;AAMnD,OAAO,MAAMC,aAAa,CAAC,EAAEC,KAAK,EAAQ;IACxC,OAAO,OACLC,KACA,EAAEC,GAAG,EAAEC,SAASC,eAAe,EAAEC,QAAQ,EAAEC,mBAAmB,EAAEC,UAAU,EAAEC,QAAQ,EAAE,EAAE;QAExF,IAAI;YACF,IAAIC;YACJ,MAAMC,mBAAmBT,IAAIU,OAAO,CAACC,WAAW,CAACL,WAAW,EAAEM;YAE9D,IACEP,uBACA,OAAOA,wBAAwB,YAC/B,SAASA,uBACT,OAAOA,oBAAoBG,GAAG,KAAK,UACnC;gBACAA,MAAMH,oBAAoBG,GAAG;YAC/B,OAAO;gBACL,IAAIK,eAAeZ;gBAEnB,IAAI,CAACY,cAAc;oBACjB,MAAMC,KAAc;wBAClB;4BACEP,UAAU;gCACRQ,QAAQR;4BACV;wBACF;qBACD;oBAED,IAAIE,kBAAkBO,OAAOC,YAAY;wBACvCR,iBAAiBO,MAAM,CAACC,UAAU,CAACC,OAAO,CAAC,CAAC,EAAEC,IAAI,EAAE;4BAClDL,GAAGM,IAAI,CAAC;gCACN,CAAC,CAAC,MAAM,EAAED,KAAK,SAAS,CAAC,CAAC,EAAE;oCAC1BJ,QAAQR;gCACV;4BACF;wBACF;oBACF;oBAEA,MAAMc,SAAS,MAAMrB,IAAIU,OAAO,CAACY,EAAE,CAACC,OAAO,CAAC;wBAC1CjB;wBACAN;wBACAwB,OAAO;4BAAEV;wBAAG;oBACd;oBAEA,IAAIO,QAAQ;wBACVR,eAAeQ;oBACjB;gBACF;gBAEA,IAAI,CAACR,cAAc;oBACjB,OAAO,IAAIY,SAAS,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