@payloadcms/storage-azure 4.0.0-internal.e55ccef → 4.0.0-internal.ea6e8f8
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/README.md +13 -10
- package/dist/adapter.d.ts +1 -1
- package/dist/adapter.d.ts.map +1 -1
- package/dist/adapter.js +35 -14
- package/dist/adapter.js.map +1 -1
- package/dist/client/AzureClientUploadHandler.d.ts +3 -4
- package/dist/client/AzureClientUploadHandler.d.ts.map +1 -1
- package/dist/client/AzureClientUploadHandler.js +2 -11
- package/dist/client/AzureClientUploadHandler.js.map +1 -1
- package/dist/client/handleAzureUpload.d.ts +2 -9
- package/dist/client/handleAzureUpload.d.ts.map +1 -1
- package/dist/client/handleAzureUpload.js +2 -27
- package/dist/client/handleAzureUpload.js.map +1 -1
- package/dist/copyFile.d.ts +11 -0
- package/dist/copyFile.d.ts.map +1 -0
- package/dist/copyFile.js +52 -0
- package/dist/copyFile.js.map +1 -0
- package/dist/deleteFile.d.ts +2 -5
- package/dist/deleteFile.d.ts.map +1 -1
- package/dist/deleteFile.js +2 -9
- package/dist/deleteFile.js.map +1 -1
- package/dist/generateURL.js +3 -3
- package/dist/generateURL.js.map +1 -1
- package/dist/generateUploadInstructions.d.ts +12 -0
- package/dist/generateUploadInstructions.d.ts.map +1 -0
- package/dist/generateUploadInstructions.js +57 -0
- package/dist/generateUploadInstructions.js.map +1 -0
- package/dist/getFile.d.ts +5 -4
- package/dist/getFile.d.ts.map +1 -1
- package/dist/getFile.js +17 -19
- package/dist/getFile.js.map +1 -1
- package/dist/index.d.ts +23 -17
- package/dist/index.d.ts.map +1 -1
- package/dist/index.js +25 -22
- package/dist/index.js.map +1 -1
- package/dist/isClientUploadAllowed.d.ts +6 -0
- package/dist/isClientUploadAllowed.d.ts.map +1 -0
- package/dist/isClientUploadAllowed.js +3 -0
- package/dist/isClientUploadAllowed.js.map +1 -0
- package/dist/uploadFile.d.ts +2 -5
- package/dist/uploadFile.d.ts.map +1 -1
- package/dist/uploadFile.js +2 -9
- package/dist/uploadFile.js.map +1 -1
- package/package.json +5 -5
- package/dist/client/handleAzureUpload.spec.d.ts +0 -2
- package/dist/client/handleAzureUpload.spec.d.ts.map +0 -1
- package/dist/client/handleAzureUpload.spec.js +0 -185
- package/dist/client/handleAzureUpload.spec.js.map +0 -1
- package/dist/generateSignedURL.d.ts +0 -14
- package/dist/generateSignedURL.d.ts.map +0 -1
- package/dist/generateSignedURL.js +0 -47
- package/dist/generateSignedURL.js.map +0 -1
package/README.md
CHANGED
|
@@ -14,7 +14,7 @@ pnpm add @payloadcms/storage-azure
|
|
|
14
14
|
|
|
15
15
|
- Configure the `collections` object to specify which collections should use the Azure Blob Storage adapter. The slug _must_ match one of your existing collection slugs.
|
|
16
16
|
- When enabled, this package will automatically set `disableLocalStorage` to `true` for each collection.
|
|
17
|
-
- When deploying to Vercel, server uploads are limited
|
|
17
|
+
- When deploying to Vercel, server uploads are limited to 4.5MB. Set `clientUploads` to `true` to use upload instructions and send files directly to Azure.
|
|
18
18
|
|
|
19
19
|
### Client uploads and CORS
|
|
20
20
|
|
|
@@ -58,12 +58,15 @@ export default buildConfig({
|
|
|
58
58
|
|
|
59
59
|
### Configuration Options
|
|
60
60
|
|
|
61
|
-
| Option | Description
|
|
62
|
-
| ---------------------- |
|
|
63
|
-
| `enabled` | Whether or not to enable the plugin
|
|
64
|
-
| `collections` | Collections to apply the Azure Blob adapter to
|
|
65
|
-
| `allowContainerCreate` | Whether or not to allow the container to be created if it does not exist
|
|
66
|
-
| `
|
|
67
|
-
| `
|
|
68
|
-
| `
|
|
69
|
-
| `
|
|
61
|
+
| Option | Description | Default |
|
|
62
|
+
| ---------------------- | ------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------- | ----------- |
|
|
63
|
+
| `enabled` | Whether or not to enable the plugin | `true` |
|
|
64
|
+
| `collections` | Collections to apply the Azure Blob adapter to | |
|
|
65
|
+
| `allowContainerCreate` | Whether or not to allow the container to be created if it does not exist | `false` |
|
|
66
|
+
| `containerAccess` | Public access level for a container the plugin creates. `'private'` (default) serves blobs only through Payload's access-controlled route; `'blob'` / `'container'` expose them to anonymous clients directly from Azure. Has no effect on containers that already exist. | `'private'` |
|
|
67
|
+
| `baseURL` | Base URL for the Azure Blob storage account | |
|
|
68
|
+
| `connectionString` | Azure Blob storage connection string | |
|
|
69
|
+
| `containerName` | Azure Blob storage container name | |
|
|
70
|
+
| `clientUploads` | Upload directly to Azure instead of through Payload. | |
|
|
71
|
+
|
|
72
|
+
> **Breaking change (private by default):** When `allowContainerCreate: true`, the plugin now creates containers with **private** access. Previously it created them with public `blob` access. If you relied on files being served directly from the anonymous Azure blob URL (typically alongside `disablePayloadAccessControl: true`), set `containerAccess: 'blob'` to restore the old behaviour. This only affects **newly created** containers — existing containers keep their current access level, so you must flip their ACL manually if needed.
|
package/dist/adapter.d.ts
CHANGED
|
@@ -5,7 +5,7 @@ interface CreateAzureAdapterArgs {
|
|
|
5
5
|
baseURL: string;
|
|
6
6
|
clientUploads?: ClientUploadsConfig;
|
|
7
7
|
containerName: string;
|
|
8
|
-
createContainerIfNotExists: () => void;
|
|
8
|
+
createContainerIfNotExists: () => Promise<void> | void;
|
|
9
9
|
getStorageClient: () => ContainerClient;
|
|
10
10
|
useCompositePrefixes?: boolean;
|
|
11
11
|
}
|
package/dist/adapter.d.ts.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"adapter.d.ts","sourceRoot":"","sources":["../src/adapter.ts"],"names":[],"mappings":"AAAA,OAAO,KAAK,EAAE,eAAe,EAAE,MAAM,qBAAqB,CAAA;AAC1D,OAAO,KAAK,EACV,OAAO,EACP,mBAAmB,
|
|
1
|
+
{"version":3,"file":"adapter.d.ts","sourceRoot":"","sources":["../src/adapter.ts"],"names":[],"mappings":"AAAA,OAAO,KAAK,EAAE,eAAe,EAAE,MAAM,qBAAqB,CAAA;AAC1D,OAAO,KAAK,EACV,OAAO,EACP,mBAAmB,EAGpB,MAAM,wCAAwC,CAAA;AAU/C,UAAU,sBAAsB;IAC9B,oBAAoB,EAAE,OAAO,CAAA;IAC7B,OAAO,EAAE,MAAM,CAAA;IACf,aAAa,CAAC,EAAE,mBAAmB,CAAA;IACnC,aAAa,EAAE,MAAM,CAAA;IACrB,0BAA0B,EAAE,MAAM,OAAO,CAAC,IAAI,CAAC,GAAG,IAAI,CAAA;IACtD,gBAAgB,EAAE,MAAM,eAAe,CAAA;IACvC,oBAAoB,CAAC,EAAE,OAAO,CAAA;CAC/B;AAED,wBAAgB,kBAAkB,CAAC,EACjC,oBAAoB,EACpB,OAAO,EACP,aAAa,EACb,aAAa,EACb,0BAA0B,EAC1B,gBAAgB,EAChB,oBAA4B,GAC7B,EAAE,sBAAsB,GAAG,OAAO,CAmElC"}
|
package/dist/adapter.js
CHANGED
|
@@ -1,11 +1,25 @@
|
|
|
1
|
+
import { copyAzureFile } from './copyFile.js';
|
|
1
2
|
import { deleteFile } from './deleteFile.js';
|
|
3
|
+
import { generateUploadInstructions } from './generateUploadInstructions.js';
|
|
2
4
|
import { generateURL } from './generateURL.js';
|
|
3
5
|
import { getFile } from './getFile.js';
|
|
6
|
+
import { isClientUploadAllowed } from './isClientUploadAllowed.js';
|
|
4
7
|
import { uploadFile } from './uploadFile.js';
|
|
5
8
|
export function createAzureAdapter({ allowContainerCreate, baseURL, clientUploads, containerName, createContainerIfNotExists, getStorageClient, useCompositePrefixes = false }) {
|
|
9
|
+
const deleteStoredFile = ({ storageFilePath })=>deleteFile({
|
|
10
|
+
client: getStorageClient(),
|
|
11
|
+
storageFilePath
|
|
12
|
+
});
|
|
6
13
|
return ({ collection, prefix = '' })=>({
|
|
7
14
|
name: 'azure',
|
|
8
|
-
|
|
15
|
+
supportsTempFiles: true,
|
|
16
|
+
copyFile: ({ from, req, to })=>copyAzureFile({
|
|
17
|
+
client: getStorageClient(),
|
|
18
|
+
from,
|
|
19
|
+
req,
|
|
20
|
+
to
|
|
21
|
+
}),
|
|
22
|
+
deleteFile: deleteStoredFile,
|
|
9
23
|
generateURL: ({ filename, prefix: urlPrefix = '' })=>generateURL({
|
|
10
24
|
baseURL,
|
|
11
25
|
collectionPrefix: prefix,
|
|
@@ -14,35 +28,42 @@ export function createAzureAdapter({ allowContainerCreate, baseURL, clientUpload
|
|
|
14
28
|
prefix: urlPrefix,
|
|
15
29
|
useCompositePrefixes
|
|
16
30
|
}),
|
|
17
|
-
|
|
18
|
-
|
|
31
|
+
uploadInstructions: {
|
|
32
|
+
adminHandler: {
|
|
33
|
+
path: '@payloadcms/storage-azure/client#AzureClientUploadHandler'
|
|
34
|
+
},
|
|
35
|
+
enabled: Boolean(clientUploads) && isClientUploadAllowed(collection),
|
|
36
|
+
generate: generateUploadInstructions({
|
|
37
|
+
access: typeof clientUploads === 'object' ? clientUploads.access : undefined,
|
|
19
38
|
collectionPrefix: prefix,
|
|
20
|
-
|
|
21
|
-
|
|
39
|
+
containerName,
|
|
40
|
+
getStorageClient,
|
|
22
41
|
useCompositePrefixes
|
|
23
42
|
}),
|
|
24
|
-
|
|
43
|
+
requiresUploadReceipt: true,
|
|
44
|
+
useInAdmin: true
|
|
45
|
+
},
|
|
46
|
+
handleDelete: deleteStoredFile,
|
|
47
|
+
handleUpload: async ({ data, file, storageFilePath })=>{
|
|
25
48
|
await uploadFile({
|
|
26
49
|
buffer: file.buffer,
|
|
27
50
|
client: getStorageClient(),
|
|
28
|
-
collectionPrefix: prefix,
|
|
29
|
-
docPrefix: data.prefix,
|
|
30
|
-
filename: file.filename,
|
|
31
51
|
mimeType: file.mimeType,
|
|
32
|
-
|
|
33
|
-
|
|
52
|
+
storageFilePath,
|
|
53
|
+
tempFilePath: file.tempFilePath
|
|
34
54
|
});
|
|
35
55
|
return data;
|
|
36
56
|
},
|
|
37
|
-
staticHandler: (req, { headers, params: {
|
|
57
|
+
staticHandler: (req, { doc, headers, params: { filename, operation, uploadReference } })=>getFile({
|
|
38
58
|
client: getStorageClient(),
|
|
39
|
-
clientUploadContext,
|
|
40
59
|
collection,
|
|
41
60
|
collectionPrefix: prefix,
|
|
61
|
+
doc,
|
|
42
62
|
filename,
|
|
43
63
|
incomingHeaders: headers,
|
|
44
|
-
|
|
64
|
+
operation,
|
|
45
65
|
req,
|
|
66
|
+
uploadReference,
|
|
46
67
|
useCompositePrefixes
|
|
47
68
|
}),
|
|
48
69
|
...allowContainerCreate && {
|
package/dist/adapter.js.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"sources":["../src/adapter.ts"],"sourcesContent":["import type { ContainerClient } from '@azure/storage-blob'\nimport type {\n Adapter,\n ClientUploadsConfig,\n GeneratedAdapter,\n} from '@payloadcms/plugin-cloud-storage/types'\n\nimport { deleteFile } from './deleteFile.js'\nimport { generateURL } from './generateURL.js'\nimport { getFile } from './getFile.js'\nimport { uploadFile } from './uploadFile.js'\n\ninterface CreateAzureAdapterArgs {\n allowContainerCreate: boolean\n baseURL: string\n clientUploads?: ClientUploadsConfig\n containerName: string\n createContainerIfNotExists: () => void\n getStorageClient: () => ContainerClient\n useCompositePrefixes?: boolean\n}\n\nexport function createAzureAdapter({\n allowContainerCreate,\n baseURL,\n clientUploads,\n containerName,\n createContainerIfNotExists,\n getStorageClient,\n useCompositePrefixes = false,\n}: CreateAzureAdapterArgs): Adapter {\n return ({ collection, prefix = '' }): GeneratedAdapter => ({\n name: 'azure',\n
|
|
1
|
+
{"version":3,"sources":["../src/adapter.ts"],"sourcesContent":["import type { ContainerClient } from '@azure/storage-blob'\nimport type {\n Adapter,\n ClientUploadsConfig,\n DeleteFile,\n GeneratedAdapter,\n} from '@payloadcms/plugin-cloud-storage/types'\n\nimport { copyAzureFile } from './copyFile.js'\nimport { deleteFile } from './deleteFile.js'\nimport { generateUploadInstructions } from './generateUploadInstructions.js'\nimport { generateURL } from './generateURL.js'\nimport { getFile } from './getFile.js'\nimport { isClientUploadAllowed } from './isClientUploadAllowed.js'\nimport { uploadFile } from './uploadFile.js'\n\ninterface CreateAzureAdapterArgs {\n allowContainerCreate: boolean\n baseURL: string\n clientUploads?: ClientUploadsConfig\n containerName: string\n createContainerIfNotExists: () => Promise<void> | void\n getStorageClient: () => ContainerClient\n useCompositePrefixes?: boolean\n}\n\nexport function createAzureAdapter({\n allowContainerCreate,\n baseURL,\n clientUploads,\n containerName,\n createContainerIfNotExists,\n getStorageClient,\n useCompositePrefixes = false,\n}: CreateAzureAdapterArgs): Adapter {\n const deleteStoredFile: DeleteFile = ({ storageFilePath }) =>\n deleteFile({ client: getStorageClient(), storageFilePath })\n\n return ({ collection, prefix = '' }): GeneratedAdapter => ({\n name: 'azure',\n supportsTempFiles: true,\n\n copyFile: ({ from, req, to }) => copyAzureFile({ client: getStorageClient(), from, req, to }),\n deleteFile: deleteStoredFile,\n\n generateURL: ({ filename, prefix: urlPrefix = '' }) =>\n generateURL({\n baseURL,\n collectionPrefix: prefix,\n containerName,\n filename,\n prefix: urlPrefix,\n useCompositePrefixes,\n }),\n\n uploadInstructions: {\n adminHandler: {\n path: '@payloadcms/storage-azure/client#AzureClientUploadHandler',\n },\n enabled: Boolean(clientUploads) && isClientUploadAllowed(collection),\n generate: generateUploadInstructions({\n access: typeof clientUploads === 'object' ? clientUploads.access : undefined,\n collectionPrefix: prefix,\n containerName,\n getStorageClient,\n useCompositePrefixes,\n }),\n requiresUploadReceipt: true,\n useInAdmin: true,\n },\n\n handleDelete: deleteStoredFile,\n\n handleUpload: async ({ data, file, storageFilePath }) => {\n await uploadFile({\n buffer: file.buffer,\n client: getStorageClient(),\n mimeType: file.mimeType,\n storageFilePath,\n tempFilePath: file.tempFilePath,\n })\n\n return data\n },\n\n staticHandler: (req, { doc, headers, params: { filename, operation, uploadReference } }) =>\n getFile({\n client: getStorageClient(),\n collection,\n collectionPrefix: prefix,\n doc,\n filename,\n incomingHeaders: headers,\n operation,\n req,\n uploadReference,\n useCompositePrefixes,\n }),\n\n ...(allowContainerCreate && { onInit: createContainerIfNotExists }),\n })\n}\n"],"names":["copyAzureFile","deleteFile","generateUploadInstructions","generateURL","getFile","isClientUploadAllowed","uploadFile","createAzureAdapter","allowContainerCreate","baseURL","clientUploads","containerName","createContainerIfNotExists","getStorageClient","useCompositePrefixes","deleteStoredFile","storageFilePath","client","collection","prefix","name","supportsTempFiles","copyFile","from","req","to","filename","urlPrefix","collectionPrefix","uploadInstructions","adminHandler","path","enabled","Boolean","generate","access","undefined","requiresUploadReceipt","useInAdmin","handleDelete","handleUpload","data","file","buffer","mimeType","tempFilePath","staticHandler","doc","headers","params","operation","uploadReference","incomingHeaders","onInit"],"mappings":"AAQA,SAASA,aAAa,QAAQ,gBAAe;AAC7C,SAASC,UAAU,QAAQ,kBAAiB;AAC5C,SAASC,0BAA0B,QAAQ,kCAAiC;AAC5E,SAASC,WAAW,QAAQ,mBAAkB;AAC9C,SAASC,OAAO,QAAQ,eAAc;AACtC,SAASC,qBAAqB,QAAQ,6BAA4B;AAClE,SAASC,UAAU,QAAQ,kBAAiB;AAY5C,OAAO,SAASC,mBAAmB,EACjCC,oBAAoB,EACpBC,OAAO,EACPC,aAAa,EACbC,aAAa,EACbC,0BAA0B,EAC1BC,gBAAgB,EAChBC,uBAAuB,KAAK,EACL;IACvB,MAAMC,mBAA+B,CAAC,EAAEC,eAAe,EAAE,GACvDf,WAAW;YAAEgB,QAAQJ;YAAoBG;QAAgB;IAE3D,OAAO,CAAC,EAAEE,UAAU,EAAEC,SAAS,EAAE,EAAE,GAAwB,CAAA;YACzDC,MAAM;YACNC,mBAAmB;YAEnBC,UAAU,CAAC,EAAEC,IAAI,EAAEC,GAAG,EAAEC,EAAE,EAAE,GAAKzB,cAAc;oBAAEiB,QAAQJ;oBAAoBU;oBAAMC;oBAAKC;gBAAG;YAC3FxB,YAAYc;YAEZZ,aAAa,CAAC,EAAEuB,QAAQ,EAAEP,QAAQQ,YAAY,EAAE,EAAE,GAChDxB,YAAY;oBACVM;oBACAmB,kBAAkBT;oBAClBR;oBACAe;oBACAP,QAAQQ;oBACRb;gBACF;YAEFe,oBAAoB;gBAClBC,cAAc;oBACZC,MAAM;gBACR;gBACAC,SAASC,QAAQvB,kBAAkBL,sBAAsBa;gBACzDgB,UAAUhC,2BAA2B;oBACnCiC,QAAQ,OAAOzB,kBAAkB,WAAWA,cAAcyB,MAAM,GAAGC;oBACnER,kBAAkBT;oBAClBR;oBACAE;oBACAC;gBACF;gBACAuB,uBAAuB;gBACvBC,YAAY;YACd;YAEAC,cAAcxB;YAEdyB,cAAc,OAAO,EAAEC,IAAI,EAAEC,IAAI,EAAE1B,eAAe,EAAE;gBAClD,MAAMV,WAAW;oBACfqC,QAAQD,KAAKC,MAAM;oBACnB1B,QAAQJ;oBACR+B,UAAUF,KAAKE,QAAQ;oBACvB5B;oBACA6B,cAAcH,KAAKG,YAAY;gBACjC;gBAEA,OAAOJ;YACT;YAEAK,eAAe,CAACtB,KAAK,EAAEuB,GAAG,EAAEC,OAAO,EAAEC,QAAQ,EAAEvB,QAAQ,EAAEwB,SAAS,EAAEC,eAAe,EAAE,EAAE,GACrF/C,QAAQ;oBACNa,QAAQJ;oBACRK;oBACAU,kBAAkBT;oBAClB4B;oBACArB;oBACA0B,iBAAiBJ;oBACjBE;oBACA1B;oBACA2B;oBACArC;gBACF;YAEF,GAAIN,wBAAwB;gBAAE6C,QAAQzC;YAA2B,CAAC;QACpE,CAAA;AACF"}
|
|
@@ -1,9 +1,8 @@
|
|
|
1
|
-
export declare const AzureClientUploadHandler: ({ children, collectionSlug,
|
|
1
|
+
export declare const AzureClientUploadHandler: ({ children, collectionSlug, endpointPath, prefix, props, }: {
|
|
2
2
|
children: import("react").ReactNode;
|
|
3
3
|
collectionSlug: import("payload").UploadCollectionSlug;
|
|
4
|
-
|
|
5
|
-
extra: Record<string, unknown>;
|
|
4
|
+
endpointPath?: `/${string}`;
|
|
6
5
|
prefix?: string;
|
|
7
|
-
|
|
6
|
+
props: Record<string, unknown>;
|
|
8
7
|
}) => import("react").JSX.Element;
|
|
9
8
|
//# sourceMappingURL=AzureClientUploadHandler.d.ts.map
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"AzureClientUploadHandler.d.ts","sourceRoot":"","sources":["../../src/client/AzureClientUploadHandler.ts"],"names":[],"mappings":"AAKA,eAAO,MAAM,wBAAwB
|
|
1
|
+
{"version":3,"file":"AzureClientUploadHandler.d.ts","sourceRoot":"","sources":["../../src/client/AzureClientUploadHandler.ts"],"names":[],"mappings":"AAKA,eAAO,MAAM,wBAAwB;;;;;;iCAGnC,CAAA"}
|
|
@@ -2,17 +2,8 @@
|
|
|
2
2
|
import { createClientUploadHandler } from '@payloadcms/plugin-cloud-storage/client';
|
|
3
3
|
import { handleAzureUpload } from './handleAzureUpload.js';
|
|
4
4
|
export const AzureClientUploadHandler = createClientUploadHandler({
|
|
5
|
-
|
|
6
|
-
|
|
7
|
-
apiRoute,
|
|
8
|
-
collectionSlug,
|
|
9
|
-
docPrefix,
|
|
10
|
-
file,
|
|
11
|
-
serverHandlerPath,
|
|
12
|
-
serverURL,
|
|
13
|
-
updateFilename
|
|
14
|
-
});
|
|
15
|
-
}
|
|
5
|
+
name: 'uploadToAzure',
|
|
6
|
+
handler: handleAzureUpload
|
|
16
7
|
});
|
|
17
8
|
|
|
18
9
|
//# sourceMappingURL=AzureClientUploadHandler.js.map
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"sources":["../../src/client/AzureClientUploadHandler.ts"],"sourcesContent":["'use client'\nimport { createClientUploadHandler } from '@payloadcms/plugin-cloud-storage/client'\n\nimport { handleAzureUpload } from './handleAzureUpload.js'\n\nexport const AzureClientUploadHandler = createClientUploadHandler({\n
|
|
1
|
+
{"version":3,"sources":["../../src/client/AzureClientUploadHandler.ts"],"sourcesContent":["'use client'\nimport { createClientUploadHandler } from '@payloadcms/plugin-cloud-storage/client'\n\nimport { handleAzureUpload } from './handleAzureUpload.js'\n\nexport const AzureClientUploadHandler = createClientUploadHandler({\n name: 'uploadToAzure',\n handler: handleAzureUpload,\n})\n"],"names":["createClientUploadHandler","handleAzureUpload","AzureClientUploadHandler","name","handler"],"mappings":"AAAA;AACA,SAASA,yBAAyB,QAAQ,0CAAyC;AAEnF,SAASC,iBAAiB,QAAQ,yBAAwB;AAE1D,OAAO,MAAMC,2BAA2BF,0BAA0B;IAChEG,MAAM;IACNC,SAASH;AACX,GAAE"}
|
|
@@ -1,14 +1,7 @@
|
|
|
1
1
|
type HandleAzureUploadArgs = {
|
|
2
|
-
|
|
3
|
-
collectionSlug: string;
|
|
4
|
-
docPrefix?: string;
|
|
2
|
+
data?: unknown;
|
|
5
3
|
file: File;
|
|
6
|
-
serverHandlerPath: `/${string}`;
|
|
7
|
-
serverURL: string;
|
|
8
|
-
updateFilename: (value: string) => void;
|
|
9
4
|
};
|
|
10
|
-
export declare const handleAzureUpload: ({
|
|
11
|
-
prefix: string;
|
|
12
|
-
}>;
|
|
5
|
+
export declare const handleAzureUpload: ({ data, file }: HandleAzureUploadArgs) => Promise<void>;
|
|
13
6
|
export {};
|
|
14
7
|
//# sourceMappingURL=handleAzureUpload.d.ts.map
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"handleAzureUpload.d.ts","sourceRoot":"","sources":["../../src/client/handleAzureUpload.ts"],"names":[],"mappings":"
|
|
1
|
+
{"version":3,"file":"handleAzureUpload.d.ts","sourceRoot":"","sources":["../../src/client/handleAzureUpload.ts"],"names":[],"mappings":"AASA,KAAK,qBAAqB,GAAG;IAC3B,IAAI,CAAC,EAAE,OAAO,CAAA;IACd,IAAI,EAAE,IAAI,CAAA;CACX,CAAA;AAED,eAAO,MAAM,iBAAiB,mBAA0B,qBAAqB,KAAG,OAAO,CAAC,IAAI,CAc3F,CAAA"}
|
|
@@ -1,34 +1,12 @@
|
|
|
1
1
|
'use client';
|
|
2
|
-
import { formatAdminURL } from 'payload/shared';
|
|
3
2
|
// Balances upload parallelism against browser memory: `blockSize * concurrency`
|
|
4
3
|
// bytes are buffered in flight. The SDK uses a single Put Blob for small files
|
|
5
4
|
// and switches to Put Block + Put Block List above its single-shot threshold,
|
|
6
5
|
// lifting the ~5 GB single-request ceiling to Azure's block-blob maximum.
|
|
7
6
|
const BLOCK_SIZE = 64 * 1024 * 1024;
|
|
8
7
|
const CONCURRENCY = 4;
|
|
9
|
-
export const handleAzureUpload = async ({
|
|
10
|
-
const
|
|
11
|
-
apiRoute,
|
|
12
|
-
path: serverHandlerPath,
|
|
13
|
-
serverURL
|
|
14
|
-
});
|
|
15
|
-
const response = await fetch(endpointRoute, {
|
|
16
|
-
body: JSON.stringify({
|
|
17
|
-
collectionSlug,
|
|
18
|
-
docPrefix,
|
|
19
|
-
filename: file.name,
|
|
20
|
-
mimeType: file.type
|
|
21
|
-
}),
|
|
22
|
-
credentials: 'include',
|
|
23
|
-
method: 'POST'
|
|
24
|
-
});
|
|
25
|
-
if (!response.ok) {
|
|
26
|
-
throw new Error('Failed to retrieve signed URL for Azure client upload');
|
|
27
|
-
}
|
|
28
|
-
const { docPrefix: sanitizedDocPrefix, filename: sanitizedFilename, url } = await response.json();
|
|
29
|
-
if (sanitizedFilename && sanitizedFilename !== file.name) {
|
|
30
|
-
updateFilename(sanitizedFilename);
|
|
31
|
-
}
|
|
8
|
+
export const handleAzureUpload = async ({ data, file })=>{
|
|
9
|
+
const { url } = data;
|
|
32
10
|
// Loaded on demand so @azure/storage-blob is only pulled into the client bundle
|
|
33
11
|
// when a client upload actually runs, rather than for every Azure adapter user.
|
|
34
12
|
const { BlockBlobClient } = await import('@azure/storage-blob');
|
|
@@ -40,9 +18,6 @@ export const handleAzureUpload = async ({ apiRoute, collectionSlug, docPrefix, f
|
|
|
40
18
|
blockSize: BLOCK_SIZE,
|
|
41
19
|
concurrency: CONCURRENCY
|
|
42
20
|
});
|
|
43
|
-
return {
|
|
44
|
-
prefix: sanitizedDocPrefix
|
|
45
|
-
};
|
|
46
21
|
};
|
|
47
22
|
|
|
48
23
|
//# sourceMappingURL=handleAzureUpload.js.map
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"sources":["../../src/client/handleAzureUpload.ts"],"sourcesContent":["'use client'\
|
|
1
|
+
{"version":3,"sources":["../../src/client/handleAzureUpload.ts"],"sourcesContent":["'use client'\n\n// Balances upload parallelism against browser memory: `blockSize * concurrency`\n// bytes are buffered in flight. The SDK uses a single Put Blob for small files\n// and switches to Put Block + Put Block List above its single-shot threshold,\n// lifting the ~5 GB single-request ceiling to Azure's block-blob maximum.\nconst BLOCK_SIZE = 64 * 1024 * 1024\nconst CONCURRENCY = 4\n\ntype HandleAzureUploadArgs = {\n data?: unknown\n file: File\n}\n\nexport const handleAzureUpload = async ({ data, file }: HandleAzureUploadArgs): Promise<void> => {\n const { url } = data as { url: string }\n\n // Loaded on demand so @azure/storage-blob is only pulled into the client bundle\n // when a client upload actually runs, rather than for every Azure adapter user.\n const { BlockBlobClient } = await import('@azure/storage-blob')\n\n const blockBlobClient = new BlockBlobClient(url)\n\n await blockBlobClient.uploadData(file, {\n blobHTTPHeaders: { blobContentType: file.type },\n blockSize: BLOCK_SIZE,\n concurrency: CONCURRENCY,\n })\n}\n"],"names":["BLOCK_SIZE","CONCURRENCY","handleAzureUpload","data","file","url","BlockBlobClient","blockBlobClient","uploadData","blobHTTPHeaders","blobContentType","type","blockSize","concurrency"],"mappings":"AAAA;AAEA,gFAAgF;AAChF,+EAA+E;AAC/E,8EAA8E;AAC9E,0EAA0E;AAC1E,MAAMA,aAAa,KAAK,OAAO;AAC/B,MAAMC,cAAc;AAOpB,OAAO,MAAMC,oBAAoB,OAAO,EAAEC,IAAI,EAAEC,IAAI,EAAyB;IAC3E,MAAM,EAAEC,GAAG,EAAE,GAAGF;IAEhB,gFAAgF;IAChF,gFAAgF;IAChF,MAAM,EAAEG,eAAe,EAAE,GAAG,MAAM,MAAM,CAAC;IAEzC,MAAMC,kBAAkB,IAAID,gBAAgBD;IAE5C,MAAME,gBAAgBC,UAAU,CAACJ,MAAM;QACrCK,iBAAiB;YAAEC,iBAAiBN,KAAKO,IAAI;QAAC;QAC9CC,WAAWZ;QACXa,aAAaZ;IACf;AACF,EAAC"}
|
|
@@ -0,0 +1,11 @@
|
|
|
1
|
+
import type { ContainerClient } from '@azure/storage-blob';
|
|
2
|
+
import type { PayloadRequest } from 'payload';
|
|
3
|
+
type Args = {
|
|
4
|
+
client: ContainerClient;
|
|
5
|
+
from: string;
|
|
6
|
+
req?: PayloadRequest;
|
|
7
|
+
to: string;
|
|
8
|
+
};
|
|
9
|
+
export declare const copyAzureFile: ({ client, from, req, to }: Args) => Promise<void>;
|
|
10
|
+
export {};
|
|
11
|
+
//# sourceMappingURL=copyFile.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"copyFile.d.ts","sourceRoot":"","sources":["../src/copyFile.ts"],"names":[],"mappings":"AAAA,OAAO,KAAK,EAAE,eAAe,EAAE,MAAM,qBAAqB,CAAA;AAE1D,OAAO,KAAK,EAAE,cAAc,EAAE,MAAM,SAAS,CAAA;AAE7C,KAAK,IAAI,GAAG;IAAE,MAAM,EAAE,eAAe,CAAC;IAAC,IAAI,EAAE,MAAM,CAAC;IAAC,GAAG,CAAC,EAAE,cAAc,CAAC;IAAC,EAAE,EAAE,MAAM,CAAA;CAAE,CAAA;AAEvF,eAAO,MAAM,aAAa,8BAAqC,IAAI,KAAG,OAAO,CAAC,IAAI,CAqDjF,CAAA"}
|
package/dist/copyFile.js
ADDED
|
@@ -0,0 +1,52 @@
|
|
|
1
|
+
export const copyAzureFile = async ({ client, from, req, to })=>{
|
|
2
|
+
if (from === to) {
|
|
3
|
+
throw new Error('Storage copy requires different source and destination keys');
|
|
4
|
+
}
|
|
5
|
+
const source = client.getBlockBlobClient(from);
|
|
6
|
+
const destination = client.getBlockBlobClient(to);
|
|
7
|
+
const properties = await source.getProperties();
|
|
8
|
+
const { tags } = await source.getTags();
|
|
9
|
+
const download = await source.download();
|
|
10
|
+
if (!download.readableStreamBody) {
|
|
11
|
+
throw new Error(`Azure storage source is not readable: ${from}`);
|
|
12
|
+
}
|
|
13
|
+
const uploaded = await destination.uploadStream(download.readableStreamBody, 4 * 1024 * 1024, 4, {
|
|
14
|
+
blobHTTPHeaders: {
|
|
15
|
+
blobCacheControl: properties.cacheControl,
|
|
16
|
+
blobContentDisposition: properties.contentDisposition,
|
|
17
|
+
blobContentEncoding: properties.contentEncoding,
|
|
18
|
+
blobContentLanguage: properties.contentLanguage,
|
|
19
|
+
blobContentType: properties.contentType
|
|
20
|
+
},
|
|
21
|
+
conditions: {
|
|
22
|
+
ifNoneMatch: '*'
|
|
23
|
+
},
|
|
24
|
+
metadata: properties.metadata,
|
|
25
|
+
tags
|
|
26
|
+
});
|
|
27
|
+
try {
|
|
28
|
+
const copied = await destination.getProperties();
|
|
29
|
+
if (copied.contentLength !== properties.contentLength) {
|
|
30
|
+
throw new Error(`Copied Azure object is not readable at its expected length: ${to}`);
|
|
31
|
+
}
|
|
32
|
+
} catch (err) {
|
|
33
|
+
try {
|
|
34
|
+
if (!uploaded.etag) {
|
|
35
|
+
throw new Error('Azure copy did not return an ETag for safe cleanup');
|
|
36
|
+
}
|
|
37
|
+
await destination.deleteIfExists({
|
|
38
|
+
conditions: {
|
|
39
|
+
ifMatch: uploaded.etag
|
|
40
|
+
}
|
|
41
|
+
});
|
|
42
|
+
} catch (cleanupError) {
|
|
43
|
+
req?.payload.logger.error({
|
|
44
|
+
err: cleanupError,
|
|
45
|
+
msg: `Failed to remove unsuccessful Azure copy at ${client.containerName}/${to}`
|
|
46
|
+
});
|
|
47
|
+
}
|
|
48
|
+
throw err;
|
|
49
|
+
}
|
|
50
|
+
};
|
|
51
|
+
|
|
52
|
+
//# sourceMappingURL=copyFile.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"sources":["../src/copyFile.ts"],"sourcesContent":["import type { ContainerClient } from '@azure/storage-blob'\nimport type { Readable } from 'node:stream'\nimport type { PayloadRequest } from 'payload'\n\ntype Args = { client: ContainerClient; from: string; req?: PayloadRequest; to: string }\n\nexport const copyAzureFile = async ({ client, from, req, to }: Args): Promise<void> => {\n if (from === to) {\n throw new Error('Storage copy requires different source and destination keys')\n }\n\n const source = client.getBlockBlobClient(from)\n const destination = client.getBlockBlobClient(to)\n const properties = await source.getProperties()\n const { tags } = await source.getTags()\n const download = await source.download()\n\n if (!download.readableStreamBody) {\n throw new Error(`Azure storage source is not readable: ${from}`)\n }\n\n const uploaded = await destination.uploadStream(\n download.readableStreamBody as Readable,\n 4 * 1024 * 1024,\n 4,\n {\n blobHTTPHeaders: {\n blobCacheControl: properties.cacheControl,\n blobContentDisposition: properties.contentDisposition,\n blobContentEncoding: properties.contentEncoding,\n blobContentLanguage: properties.contentLanguage,\n blobContentType: properties.contentType,\n },\n conditions: { ifNoneMatch: '*' },\n metadata: properties.metadata,\n tags,\n },\n )\n\n try {\n const copied = await destination.getProperties()\n\n if (copied.contentLength !== properties.contentLength) {\n throw new Error(`Copied Azure object is not readable at its expected length: ${to}`)\n }\n } catch (err) {\n try {\n if (!uploaded.etag) {\n throw new Error('Azure copy did not return an ETag for safe cleanup')\n }\n await destination.deleteIfExists({ conditions: { ifMatch: uploaded.etag } })\n } catch (cleanupError) {\n req?.payload.logger.error({\n err: cleanupError,\n msg: `Failed to remove unsuccessful Azure copy at ${client.containerName}/${to}`,\n })\n }\n throw err\n }\n}\n"],"names":["copyAzureFile","client","from","req","to","Error","source","getBlockBlobClient","destination","properties","getProperties","tags","getTags","download","readableStreamBody","uploaded","uploadStream","blobHTTPHeaders","blobCacheControl","cacheControl","blobContentDisposition","contentDisposition","blobContentEncoding","contentEncoding","blobContentLanguage","contentLanguage","blobContentType","contentType","conditions","ifNoneMatch","metadata","copied","contentLength","err","etag","deleteIfExists","ifMatch","cleanupError","payload","logger","error","msg","containerName"],"mappings":"AAMA,OAAO,MAAMA,gBAAgB,OAAO,EAAEC,MAAM,EAAEC,IAAI,EAAEC,GAAG,EAAEC,EAAE,EAAQ;IACjE,IAAIF,SAASE,IAAI;QACf,MAAM,IAAIC,MAAM;IAClB;IAEA,MAAMC,SAASL,OAAOM,kBAAkB,CAACL;IACzC,MAAMM,cAAcP,OAAOM,kBAAkB,CAACH;IAC9C,MAAMK,aAAa,MAAMH,OAAOI,aAAa;IAC7C,MAAM,EAAEC,IAAI,EAAE,GAAG,MAAML,OAAOM,OAAO;IACrC,MAAMC,WAAW,MAAMP,OAAOO,QAAQ;IAEtC,IAAI,CAACA,SAASC,kBAAkB,EAAE;QAChC,MAAM,IAAIT,MAAM,CAAC,sCAAsC,EAAEH,MAAM;IACjE;IAEA,MAAMa,WAAW,MAAMP,YAAYQ,YAAY,CAC7CH,SAASC,kBAAkB,EAC3B,IAAI,OAAO,MACX,GACA;QACEG,iBAAiB;YACfC,kBAAkBT,WAAWU,YAAY;YACzCC,wBAAwBX,WAAWY,kBAAkB;YACrDC,qBAAqBb,WAAWc,eAAe;YAC/CC,qBAAqBf,WAAWgB,eAAe;YAC/CC,iBAAiBjB,WAAWkB,WAAW;QACzC;QACAC,YAAY;YAAEC,aAAa;QAAI;QAC/BC,UAAUrB,WAAWqB,QAAQ;QAC7BnB;IACF;IAGF,IAAI;QACF,MAAMoB,SAAS,MAAMvB,YAAYE,aAAa;QAE9C,IAAIqB,OAAOC,aAAa,KAAKvB,WAAWuB,aAAa,EAAE;YACrD,MAAM,IAAI3B,MAAM,CAAC,4DAA4D,EAAED,IAAI;QACrF;IACF,EAAE,OAAO6B,KAAK;QACZ,IAAI;YACF,IAAI,CAAClB,SAASmB,IAAI,EAAE;gBAClB,MAAM,IAAI7B,MAAM;YAClB;YACA,MAAMG,YAAY2B,cAAc,CAAC;gBAAEP,YAAY;oBAAEQ,SAASrB,SAASmB,IAAI;gBAAC;YAAE;QAC5E,EAAE,OAAOG,cAAc;YACrBlC,KAAKmC,QAAQC,OAAOC,MAAM;gBACxBP,KAAKI;gBACLI,KAAK,CAAC,4CAA4C,EAAExC,OAAOyC,aAAa,CAAC,CAAC,EAAEtC,IAAI;YAClF;QACF;QACA,MAAM6B;IACR;AACF,EAAC"}
|
package/dist/deleteFile.d.ts
CHANGED
|
@@ -1,11 +1,8 @@
|
|
|
1
1
|
import type { ContainerClient } from '@azure/storage-blob';
|
|
2
2
|
interface DeleteArgs {
|
|
3
3
|
client: ContainerClient;
|
|
4
|
-
|
|
5
|
-
docPrefix: string;
|
|
6
|
-
filename: string;
|
|
7
|
-
useCompositePrefixes?: boolean;
|
|
4
|
+
storageFilePath: string;
|
|
8
5
|
}
|
|
9
|
-
export declare function deleteFile({ client,
|
|
6
|
+
export declare function deleteFile({ client, storageFilePath }: DeleteArgs): Promise<void>;
|
|
10
7
|
export {};
|
|
11
8
|
//# sourceMappingURL=deleteFile.d.ts.map
|
package/dist/deleteFile.d.ts.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"deleteFile.d.ts","sourceRoot":"","sources":["../src/deleteFile.ts"],"names":[],"mappings":"AAAA,OAAO,KAAK,EAAE,eAAe,EAAE,MAAM,qBAAqB,CAAA;
|
|
1
|
+
{"version":3,"file":"deleteFile.d.ts","sourceRoot":"","sources":["../src/deleteFile.ts"],"names":[],"mappings":"AAAA,OAAO,KAAK,EAAE,eAAe,EAAE,MAAM,qBAAqB,CAAA;AAE1D,UAAU,UAAU;IAClB,MAAM,EAAE,eAAe,CAAA;IACvB,eAAe,EAAE,MAAM,CAAA;CACxB;AAED,wBAAsB,UAAU,CAAC,EAAE,MAAM,EAAE,eAAe,EAAE,EAAE,UAAU,GAAG,OAAO,CAAC,IAAI,CAAC,CAIvF"}
|
package/dist/deleteFile.js
CHANGED
|
@@ -1,12 +1,5 @@
|
|
|
1
|
-
|
|
2
|
-
|
|
3
|
-
const { fileKey } = getFileKey({
|
|
4
|
-
collectionPrefix,
|
|
5
|
-
docPrefix,
|
|
6
|
-
filename,
|
|
7
|
-
useCompositePrefixes
|
|
8
|
-
});
|
|
9
|
-
const blockBlobClient = client.getBlockBlobClient(fileKey);
|
|
1
|
+
export async function deleteFile({ client, storageFilePath }) {
|
|
2
|
+
const blockBlobClient = client.getBlockBlobClient(storageFilePath);
|
|
10
3
|
await blockBlobClient.deleteIfExists();
|
|
11
4
|
}
|
|
12
5
|
|
package/dist/deleteFile.js.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"sources":["../src/deleteFile.ts"],"sourcesContent":["import type { ContainerClient } from '@azure/storage-blob'\n\
|
|
1
|
+
{"version":3,"sources":["../src/deleteFile.ts"],"sourcesContent":["import type { ContainerClient } from '@azure/storage-blob'\n\ninterface DeleteArgs {\n client: ContainerClient\n storageFilePath: string\n}\n\nexport async function deleteFile({ client, storageFilePath }: DeleteArgs): Promise<void> {\n const blockBlobClient = client.getBlockBlobClient(storageFilePath)\n\n await blockBlobClient.deleteIfExists()\n}\n"],"names":["deleteFile","client","storageFilePath","blockBlobClient","getBlockBlobClient","deleteIfExists"],"mappings":"AAOA,OAAO,eAAeA,WAAW,EAAEC,MAAM,EAAEC,eAAe,EAAc;IACtE,MAAMC,kBAAkBF,OAAOG,kBAAkB,CAACF;IAElD,MAAMC,gBAAgBE,cAAc;AACtC"}
|
package/dist/generateURL.js
CHANGED
|
@@ -1,12 +1,12 @@
|
|
|
1
|
-
import {
|
|
1
|
+
import { buildStoragePathData } from '@payloadcms/plugin-cloud-storage/utilities';
|
|
2
2
|
export function generateURL({ baseURL, collectionPrefix = '', containerName, filename, prefix, useCompositePrefixes = false }) {
|
|
3
|
-
const {
|
|
3
|
+
const { storageFilePath } = buildStoragePathData({
|
|
4
4
|
collectionPrefix,
|
|
5
5
|
docPrefix: prefix,
|
|
6
6
|
filename,
|
|
7
7
|
useCompositePrefixes
|
|
8
8
|
});
|
|
9
|
-
return `${baseURL}/${containerName}/${
|
|
9
|
+
return `${baseURL}/${containerName}/${storageFilePath}`;
|
|
10
10
|
}
|
|
11
11
|
|
|
12
12
|
//# sourceMappingURL=generateURL.js.map
|
package/dist/generateURL.js.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"sources":["../src/generateURL.ts"],"sourcesContent":["import {
|
|
1
|
+
{"version":3,"sources":["../src/generateURL.ts"],"sourcesContent":["import { buildStoragePathData } from '@payloadcms/plugin-cloud-storage/utilities'\n\ninterface GenerateURLArgs {\n baseURL: string\n collectionPrefix?: string\n containerName: string\n filename: string\n prefix: string\n useCompositePrefixes?: boolean\n}\n\nexport function generateURL({\n baseURL,\n collectionPrefix = '',\n containerName,\n filename,\n prefix,\n useCompositePrefixes = false,\n}: GenerateURLArgs): string {\n const { storageFilePath } = buildStoragePathData({\n collectionPrefix,\n docPrefix: prefix,\n filename,\n useCompositePrefixes,\n })\n\n return `${baseURL}/${containerName}/${storageFilePath}`\n}\n"],"names":["buildStoragePathData","generateURL","baseURL","collectionPrefix","containerName","filename","prefix","useCompositePrefixes","storageFilePath","docPrefix"],"mappings":"AAAA,SAASA,oBAAoB,QAAQ,6CAA4C;AAWjF,OAAO,SAASC,YAAY,EAC1BC,OAAO,EACPC,mBAAmB,EAAE,EACrBC,aAAa,EACbC,QAAQ,EACRC,MAAM,EACNC,uBAAuB,KAAK,EACZ;IAChB,MAAM,EAAEC,eAAe,EAAE,GAAGR,qBAAqB;QAC/CG;QACAM,WAAWH;QACXD;QACAE;IACF;IAEA,OAAO,GAAGL,QAAQ,CAAC,EAAEE,cAAc,CAAC,EAAEI,iBAAiB;AACzD"}
|
|
@@ -0,0 +1,12 @@
|
|
|
1
|
+
import type { ContainerClient } from '@azure/storage-blob';
|
|
2
|
+
import type { GenerateUploadInstructions, UploadInstructionsAccess } from 'payload';
|
|
3
|
+
interface Args {
|
|
4
|
+
access?: UploadInstructionsAccess;
|
|
5
|
+
collectionPrefix: string;
|
|
6
|
+
containerName: string;
|
|
7
|
+
getStorageClient: () => ContainerClient;
|
|
8
|
+
useCompositePrefixes?: boolean;
|
|
9
|
+
}
|
|
10
|
+
export declare const generateUploadInstructions: ({ access, collectionPrefix, containerName, getStorageClient, useCompositePrefixes, }: Args) => GenerateUploadInstructions;
|
|
11
|
+
export {};
|
|
12
|
+
//# sourceMappingURL=generateUploadInstructions.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"generateUploadInstructions.d.ts","sourceRoot":"","sources":["../src/generateUploadInstructions.ts"],"names":[],"mappings":"AAAA,OAAO,KAAK,EAAE,eAAe,EAA8B,MAAM,qBAAqB,CAAA;AACtF,OAAO,KAAK,EAAE,0BAA0B,EAAE,wBAAwB,EAAE,MAAM,SAAS,CAAA;AASnF,UAAU,IAAI;IACZ,MAAM,CAAC,EAAE,wBAAwB,CAAA;IACjC,gBAAgB,EAAE,MAAM,CAAA;IACxB,aAAa,EAAE,MAAM,CAAA;IACrB,gBAAgB,EAAE,MAAM,eAAe,CAAA;IACvC,oBAAoB,CAAC,EAAE,OAAO,CAAA;CAC/B;AAED,eAAO,MAAM,0BAA0B,yFAMpC,IAAI,KAAG,0BA8DT,CAAA"}
|
|
@@ -0,0 +1,57 @@
|
|
|
1
|
+
import { BlobSASPermissions, generateBlobSASQueryParameters } from '@azure/storage-blob';
|
|
2
|
+
import { resolveSignedURLKey } from '@payloadcms/plugin-cloud-storage/utilities';
|
|
3
|
+
import { APIError, Forbidden } from 'payload';
|
|
4
|
+
import { assertClientUploadAllowed } from 'payload/internal';
|
|
5
|
+
import { isClientUploadAllowed } from './isClientUploadAllowed.js';
|
|
6
|
+
export const generateUploadInstructions = ({ access, collectionPrefix, containerName, getStorageClient, useCompositePrefixes = false })=>{
|
|
7
|
+
return async ({ collectionSlug, docPrefix, filename, filesize, mimeType, overrideAccess, req })=>{
|
|
8
|
+
if (!overrideAccess && (access ? !await access({
|
|
9
|
+
collectionSlug,
|
|
10
|
+
req
|
|
11
|
+
}) : !req.user)) {
|
|
12
|
+
throw new Forbidden(req.t);
|
|
13
|
+
}
|
|
14
|
+
const collection = req.payload.collections[collectionSlug]?.config;
|
|
15
|
+
if (!isClientUploadAllowed(collection)) {
|
|
16
|
+
throw new APIError('Azure client uploads require allowRestrictedFileTypes to be enabled.', 400);
|
|
17
|
+
}
|
|
18
|
+
assertClientUploadAllowed({
|
|
19
|
+
collection,
|
|
20
|
+
filename,
|
|
21
|
+
mimeType
|
|
22
|
+
});
|
|
23
|
+
const { sanitizedFilename, storageFilePath, uploadReference } = await resolveSignedURLKey({
|
|
24
|
+
collectionPrefix,
|
|
25
|
+
collectionSlug,
|
|
26
|
+
docPrefix,
|
|
27
|
+
filename,
|
|
28
|
+
req,
|
|
29
|
+
useCompositePrefixes
|
|
30
|
+
});
|
|
31
|
+
const blobClient = getStorageClient().getBlobClient(storageFilePath);
|
|
32
|
+
const sasToken = generateBlobSASQueryParameters({
|
|
33
|
+
blobName: storageFilePath,
|
|
34
|
+
containerName,
|
|
35
|
+
contentType: mimeType,
|
|
36
|
+
expiresOn: new Date(Date.now() + 3 * 60 * 60 * 1000),
|
|
37
|
+
permissions: BlobSASPermissions.parse('c'),
|
|
38
|
+
startsOn: new Date(),
|
|
39
|
+
version: '2026-04-06'
|
|
40
|
+
}, getStorageClient().credential);
|
|
41
|
+
return {
|
|
42
|
+
name: 'uploadToAzure',
|
|
43
|
+
type: 'dispatch',
|
|
44
|
+
data: {
|
|
45
|
+
url: `${blobClient.url}?${sasToken.toString()}`
|
|
46
|
+
},
|
|
47
|
+
file: {
|
|
48
|
+
filename: sanitizedFilename,
|
|
49
|
+
mimeType,
|
|
50
|
+
size: filesize,
|
|
51
|
+
uploadReference
|
|
52
|
+
}
|
|
53
|
+
};
|
|
54
|
+
};
|
|
55
|
+
};
|
|
56
|
+
|
|
57
|
+
//# sourceMappingURL=generateUploadInstructions.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"sources":["../src/generateUploadInstructions.ts"],"sourcesContent":["import type { ContainerClient, StorageSharedKeyCredential } from '@azure/storage-blob'\nimport type { GenerateUploadInstructions, UploadInstructionsAccess } from 'payload'\n\nimport { BlobSASPermissions, generateBlobSASQueryParameters } from '@azure/storage-blob'\nimport { resolveSignedURLKey } from '@payloadcms/plugin-cloud-storage/utilities'\nimport { APIError, Forbidden } from 'payload'\nimport { assertClientUploadAllowed } from 'payload/internal'\n\nimport { isClientUploadAllowed } from './isClientUploadAllowed.js'\n\ninterface Args {\n access?: UploadInstructionsAccess\n collectionPrefix: string\n containerName: string\n getStorageClient: () => ContainerClient\n useCompositePrefixes?: boolean\n}\n\nexport const generateUploadInstructions = ({\n access,\n collectionPrefix,\n containerName,\n getStorageClient,\n useCompositePrefixes = false,\n}: Args): GenerateUploadInstructions => {\n return async ({\n collectionSlug,\n docPrefix,\n filename,\n filesize,\n mimeType,\n overrideAccess,\n req,\n }) => {\n if (!overrideAccess && (access ? !(await access({ collectionSlug, req })) : !req.user)) {\n throw new Forbidden(req.t)\n }\n\n const collection = req.payload.collections[collectionSlug]?.config\n if (!isClientUploadAllowed(collection)) {\n throw new APIError(\n 'Azure client uploads require allowRestrictedFileTypes to be enabled.',\n 400,\n )\n }\n\n assertClientUploadAllowed({ collection, filename, mimeType })\n\n const { sanitizedFilename, storageFilePath, uploadReference } = await resolveSignedURLKey({\n collectionPrefix,\n collectionSlug,\n docPrefix,\n filename,\n req,\n useCompositePrefixes,\n })\n\n const blobClient = getStorageClient().getBlobClient(storageFilePath)\n\n const sasToken = generateBlobSASQueryParameters(\n {\n blobName: storageFilePath,\n containerName,\n contentType: mimeType,\n expiresOn: new Date(Date.now() + 3 * 60 * 60 * 1000),\n permissions: BlobSASPermissions.parse('c'),\n startsOn: new Date(),\n version: '2026-04-06',\n },\n getStorageClient().credential as StorageSharedKeyCredential,\n )\n\n return {\n name: 'uploadToAzure',\n type: 'dispatch',\n data: {\n url: `${blobClient.url}?${sasToken.toString()}`,\n },\n file: {\n filename: sanitizedFilename,\n mimeType,\n size: filesize,\n uploadReference,\n },\n }\n }\n}\n"],"names":["BlobSASPermissions","generateBlobSASQueryParameters","resolveSignedURLKey","APIError","Forbidden","assertClientUploadAllowed","isClientUploadAllowed","generateUploadInstructions","access","collectionPrefix","containerName","getStorageClient","useCompositePrefixes","collectionSlug","docPrefix","filename","filesize","mimeType","overrideAccess","req","user","t","collection","payload","collections","config","sanitizedFilename","storageFilePath","uploadReference","blobClient","getBlobClient","sasToken","blobName","contentType","expiresOn","Date","now","permissions","parse","startsOn","version","credential","name","type","data","url","toString","file","size"],"mappings":"AAGA,SAASA,kBAAkB,EAAEC,8BAA8B,QAAQ,sBAAqB;AACxF,SAASC,mBAAmB,QAAQ,6CAA4C;AAChF,SAASC,QAAQ,EAAEC,SAAS,QAAQ,UAAS;AAC7C,SAASC,yBAAyB,QAAQ,mBAAkB;AAE5D,SAASC,qBAAqB,QAAQ,6BAA4B;AAUlE,OAAO,MAAMC,6BAA6B,CAAC,EACzCC,MAAM,EACNC,gBAAgB,EAChBC,aAAa,EACbC,gBAAgB,EAChBC,uBAAuB,KAAK,EACvB;IACL,OAAO,OAAO,EACZC,cAAc,EACdC,SAAS,EACTC,QAAQ,EACRC,QAAQ,EACRC,QAAQ,EACRC,cAAc,EACdC,GAAG,EACJ;QACC,IAAI,CAACD,kBAAmBV,CAAAA,SAAS,CAAE,MAAMA,OAAO;YAAEK;YAAgBM;QAAI,KAAM,CAACA,IAAIC,IAAI,AAAD,GAAI;YACtF,MAAM,IAAIhB,UAAUe,IAAIE,CAAC;QAC3B;QAEA,MAAMC,aAAaH,IAAII,OAAO,CAACC,WAAW,CAACX,eAAe,EAAEY;QAC5D,IAAI,CAACnB,sBAAsBgB,aAAa;YACtC,MAAM,IAAInB,SACR,wEACA;QAEJ;QAEAE,0BAA0B;YAAEiB;YAAYP;YAAUE;QAAS;QAE3D,MAAM,EAAES,iBAAiB,EAAEC,eAAe,EAAEC,eAAe,EAAE,GAAG,MAAM1B,oBAAoB;YACxFO;YACAI;YACAC;YACAC;YACAI;YACAP;QACF;QAEA,MAAMiB,aAAalB,mBAAmBmB,aAAa,CAACH;QAEpD,MAAMI,WAAW9B,+BACf;YACE+B,UAAUL;YACVjB;YACAuB,aAAahB;YACbiB,WAAW,IAAIC,KAAKA,KAAKC,GAAG,KAAK,IAAI,KAAK,KAAK;YAC/CC,aAAarC,mBAAmBsC,KAAK,CAAC;YACtCC,UAAU,IAAIJ;YACdK,SAAS;QACX,GACA7B,mBAAmB8B,UAAU;QAG/B,OAAO;YACLC,MAAM;YACNC,MAAM;YACNC,MAAM;gBACJC,KAAK,GAAGhB,WAAWgB,GAAG,CAAC,CAAC,EAAEd,SAASe,QAAQ,IAAI;YACjD;YACAC,MAAM;gBACJhC,UAAUW;gBACVT;gBACA+B,MAAMhC;gBACNY;YACF;QACF;IACF;AACF,EAAC"}
|
package/dist/getFile.d.ts
CHANGED
|
@@ -1,16 +1,17 @@
|
|
|
1
1
|
import type { ContainerClient } from '@azure/storage-blob';
|
|
2
|
-
import type { CollectionConfig, PayloadRequest } from 'payload';
|
|
2
|
+
import type { CollectionConfig, FileHandlerOperation, PayloadRequest, TypeWithID } from 'payload';
|
|
3
3
|
interface GetFileArgs {
|
|
4
4
|
client: ContainerClient;
|
|
5
|
-
clientUploadContext?: unknown;
|
|
6
5
|
collection: CollectionConfig;
|
|
7
6
|
collectionPrefix?: string;
|
|
7
|
+
doc?: TypeWithID;
|
|
8
8
|
filename: string;
|
|
9
9
|
incomingHeaders?: Headers;
|
|
10
|
-
|
|
10
|
+
operation?: FileHandlerOperation;
|
|
11
11
|
req: PayloadRequest;
|
|
12
|
+
uploadReference?: unknown;
|
|
12
13
|
useCompositePrefixes?: boolean;
|
|
13
14
|
}
|
|
14
|
-
export declare function getFile({ client,
|
|
15
|
+
export declare function getFile({ client, collection, collectionPrefix, doc, filename, incomingHeaders, operation, req, uploadReference, useCompositePrefixes, }: GetFileArgs): Promise<Response>;
|
|
15
16
|
export {};
|
|
16
17
|
//# sourceMappingURL=getFile.d.ts.map
|
package/dist/getFile.d.ts.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"getFile.d.ts","sourceRoot":"","sources":["../src/getFile.ts"],"names":[],"mappings":"AAAA,OAAO,KAAK,EAA8B,eAAe,EAAE,MAAM,qBAAqB,CAAA;AACtF,OAAO,KAAK,EAAE,gBAAgB,EAAE,cAAc,EAAE,MAAM,SAAS,CAAA;
|
|
1
|
+
{"version":3,"file":"getFile.d.ts","sourceRoot":"","sources":["../src/getFile.ts"],"names":[],"mappings":"AAAA,OAAO,KAAK,EAA8B,eAAe,EAAE,MAAM,qBAAqB,CAAA;AACtF,OAAO,KAAK,EAAE,gBAAgB,EAAE,oBAAoB,EAAE,cAAc,EAAE,UAAU,EAAE,MAAM,SAAS,CAAA;AAUjG,UAAU,WAAW;IACnB,MAAM,EAAE,eAAe,CAAA;IACvB,UAAU,EAAE,gBAAgB,CAAA;IAC5B,gBAAgB,CAAC,EAAE,MAAM,CAAA;IACzB,GAAG,CAAC,EAAE,UAAU,CAAA;IAChB,QAAQ,EAAE,MAAM,CAAA;IAChB,eAAe,CAAC,EAAE,OAAO,CAAA;IACzB,SAAS,CAAC,EAAE,oBAAoB,CAAA;IAChC,GAAG,EAAE,cAAc,CAAA;IACnB,eAAe,CAAC,EAAE,OAAO,CAAA;IACzB,oBAAoB,CAAC,EAAE,OAAO,CAAA;CAC/B;AAgCD,wBAAsB,OAAO,CAAC,EAC5B,MAAM,EACN,UAAU,EACV,gBAAqB,EACrB,GAAG,EACH,QAAQ,EACR,eAAe,EACf,SAAkB,EAClB,GAAG,EACH,eAAe,EACf,oBAA4B,GAC7B,EAAE,WAAW,GAAG,OAAO,CAAC,QAAQ,CAAC,CAsHjC"}
|