@payloadcms/storage-azure 3.71.0-internal.e36f916 → 3.71.0
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"staticHandler.d.ts","sourceRoot":"","sources":["../src/staticHandler.ts"],"names":[],"mappings":"AAAA,OAAO,KAAK,EAAE,eAAe,EAAE,MAAM,qBAAqB,CAAA;AAC1D,OAAO,KAAK,EAAE,aAAa,EAAE,MAAM,wCAAwC,CAAA;AAC3E,OAAO,KAAK,EAAE,gBAAgB,EAAE,MAAM,SAAS,CAAA;
|
|
1
|
+
{"version":3,"file":"staticHandler.d.ts","sourceRoot":"","sources":["../src/staticHandler.ts"],"names":[],"mappings":"AAAA,OAAO,KAAK,EAAE,eAAe,EAAE,MAAM,qBAAqB,CAAA;AAC1D,OAAO,KAAK,EAAE,aAAa,EAAE,MAAM,wCAAwC,CAAA;AAC3E,OAAO,KAAK,EAAE,gBAAgB,EAAE,MAAM,SAAS,CAAA;AAO/C,UAAU,IAAI;IACZ,UAAU,EAAE,gBAAgB,CAAA;IAC5B,gBAAgB,EAAE,MAAM,eAAe,CAAA;CACxC;AAED,eAAO,MAAM,UAAU,qCAAsC,IAAI,KAAG,aAkGnE,CAAA"}
|
package/dist/staticHandler.js
CHANGED
|
@@ -1,7 +1,7 @@
|
|
|
1
1
|
import { RestError } from '@azure/storage-blob';
|
|
2
2
|
import { getFilePrefix } from '@payloadcms/plugin-cloud-storage/utilities';
|
|
3
3
|
import path from 'path';
|
|
4
|
-
import {
|
|
4
|
+
import { getRangeRequestInfo } from 'payload/internal';
|
|
5
5
|
export const getHandler = ({ collection, getStorageClient })=>{
|
|
6
6
|
return async (req, { headers: incomingHeaders, params: { clientUploadContext, filename } })=>{
|
|
7
7
|
try {
|
|
@@ -12,28 +12,45 @@ export const getHandler = ({ collection, getStorageClient })=>{
|
|
|
12
12
|
req
|
|
13
13
|
});
|
|
14
14
|
const blockBlobClient = getStorageClient().getBlockBlobClient(path.posix.join(prefix, filename));
|
|
15
|
-
|
|
16
|
-
const
|
|
17
|
-
const
|
|
18
|
-
|
|
19
|
-
|
|
20
|
-
|
|
21
|
-
|
|
22
|
-
|
|
23
|
-
|
|
24
|
-
|
|
25
|
-
|
|
26
|
-
|
|
15
|
+
// Get file size for range validation
|
|
16
|
+
const properties = await blockBlobClient.getProperties();
|
|
17
|
+
const fileSize = properties.contentLength;
|
|
18
|
+
if (!fileSize) {
|
|
19
|
+
return new Response('Internal Server Error', {
|
|
20
|
+
status: 500
|
|
21
|
+
});
|
|
22
|
+
}
|
|
23
|
+
// Handle range request
|
|
24
|
+
const rangeHeader = req.headers.get('range');
|
|
25
|
+
const rangeResult = getRangeRequestInfo({
|
|
26
|
+
fileSize,
|
|
27
|
+
rangeHeader
|
|
28
|
+
});
|
|
29
|
+
if (rangeResult.type === 'invalid') {
|
|
30
|
+
return new Response(null, {
|
|
31
|
+
headers: new Headers(rangeResult.headers),
|
|
32
|
+
status: rangeResult.status
|
|
33
|
+
});
|
|
34
|
+
}
|
|
35
|
+
// Download with range if partial
|
|
36
|
+
const blob = rangeResult.type === 'partial' ? await blockBlobClient.download(rangeResult.rangeStart, rangeResult.rangeEnd - rangeResult.rangeStart + 1) : await blockBlobClient.download();
|
|
37
|
+
let headers = new Headers(incomingHeaders);
|
|
38
|
+
// Add range-related headers from the result
|
|
39
|
+
for (const [key, value] of Object.entries(rangeResult.headers)){
|
|
40
|
+
headers.append(key, value);
|
|
41
|
+
}
|
|
42
|
+
// Add Azure-specific headers
|
|
43
|
+
headers.append('Content-Type', String(properties.contentType));
|
|
44
|
+
if (properties.etag) {
|
|
45
|
+
headers.append('ETag', String(properties.etag));
|
|
27
46
|
}
|
|
28
|
-
let headers = new Headers(initHeaders);
|
|
29
47
|
const etagFromHeaders = req.headers.get('etag') || req.headers.get('if-none-match');
|
|
30
|
-
const objectEtag = response.headers.get('etag');
|
|
31
48
|
if (collection.upload && typeof collection.upload === 'object' && typeof collection.upload.modifyResponseHeaders === 'function') {
|
|
32
49
|
headers = collection.upload.modifyResponseHeaders({
|
|
33
50
|
headers
|
|
34
51
|
}) || headers;
|
|
35
52
|
}
|
|
36
|
-
if (etagFromHeaders && etagFromHeaders ===
|
|
53
|
+
if (etagFromHeaders && etagFromHeaders === properties.etag) {
|
|
37
54
|
return new Response(null, {
|
|
38
55
|
headers,
|
|
39
56
|
status: 304
|
|
@@ -59,7 +76,7 @@ export const getHandler = ({ collection, getStorageClient })=>{
|
|
|
59
76
|
});
|
|
60
77
|
return new Response(readableStream, {
|
|
61
78
|
headers,
|
|
62
|
-
status:
|
|
79
|
+
status: rangeResult.status
|
|
63
80
|
});
|
|
64
81
|
} catch (err) {
|
|
65
82
|
if (err instanceof RestError && err.statusCode === 404) {
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"sources":["../src/staticHandler.ts"],"sourcesContent":["import type { ContainerClient } from '@azure/storage-blob'\nimport type { StaticHandler } from '@payloadcms/plugin-cloud-storage/types'\nimport type { CollectionConfig } from 'payload'\n\nimport { RestError } from '@azure/storage-blob'\nimport { getFilePrefix } from '@payloadcms/plugin-cloud-storage/utilities'\nimport path from 'path'\
|
|
1
|
+
{"version":3,"sources":["../src/staticHandler.ts"],"sourcesContent":["import type { ContainerClient } from '@azure/storage-blob'\nimport type { StaticHandler } from '@payloadcms/plugin-cloud-storage/types'\nimport type { CollectionConfig } from 'payload'\n\nimport { RestError } from '@azure/storage-blob'\nimport { getFilePrefix } from '@payloadcms/plugin-cloud-storage/utilities'\nimport path from 'path'\nimport { getRangeRequestInfo } from 'payload/internal'\n\ninterface Args {\n collection: CollectionConfig\n getStorageClient: () => ContainerClient\n}\n\nexport const getHandler = ({ collection, getStorageClient }: Args): StaticHandler => {\n return async (req, { headers: incomingHeaders, params: { clientUploadContext, filename } }) => {\n try {\n const prefix = await getFilePrefix({ clientUploadContext, collection, filename, req })\n const blockBlobClient = getStorageClient().getBlockBlobClient(\n path.posix.join(prefix, filename),\n )\n\n // Get file size for range validation\n const properties = await blockBlobClient.getProperties()\n const fileSize = properties.contentLength\n\n if (!fileSize) {\n return new Response('Internal Server Error', { status: 500 })\n }\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 // Download with range if partial\n const blob =\n rangeResult.type === 'partial'\n ? await blockBlobClient.download(\n rangeResult.rangeStart,\n rangeResult.rangeEnd - rangeResult.rangeStart + 1,\n )\n : await blockBlobClient.download()\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 // Add Azure-specific headers\n headers.append('Content-Type', String(properties.contentType))\n if (properties.etag) {\n headers.append('ETag', String(properties.etag))\n }\n\n const etagFromHeaders = req.headers.get('etag') || req.headers.get('if-none-match')\n\n if (\n collection.upload &&\n typeof collection.upload === 'object' &&\n typeof collection.upload.modifyResponseHeaders === 'function'\n ) {\n headers = collection.upload.modifyResponseHeaders({ headers }) || headers\n }\n\n if (etagFromHeaders && etagFromHeaders === properties.etag) {\n return new Response(null, {\n headers,\n status: 304,\n })\n }\n\n // Manually create a ReadableStream for the web from a Node.js stream.\n const readableStream = new ReadableStream({\n start(controller) {\n const nodeStream = blob.readableStreamBody\n if (!nodeStream) {\n throw new Error('No readable stream body')\n }\n\n nodeStream.on('data', (chunk) => {\n controller.enqueue(new Uint8Array(chunk))\n })\n nodeStream.on('end', () => {\n controller.close()\n })\n nodeStream.on('error', (err) => {\n controller.error(err)\n })\n },\n })\n\n return new Response(readableStream, {\n headers,\n status: rangeResult.status,\n })\n } catch (err: unknown) {\n if (err instanceof RestError && err.statusCode === 404) {\n return new Response(null, { status: 404, statusText: 'Not Found' })\n }\n req.payload.logger.error(err)\n return new Response('Internal Server Error', { status: 500 })\n }\n }\n}\n"],"names":["RestError","getFilePrefix","path","getRangeRequestInfo","getHandler","collection","getStorageClient","req","headers","incomingHeaders","params","clientUploadContext","filename","prefix","blockBlobClient","getBlockBlobClient","posix","join","properties","getProperties","fileSize","contentLength","Response","status","rangeHeader","get","rangeResult","type","Headers","blob","download","rangeStart","rangeEnd","key","value","Object","entries","append","String","contentType","etag","etagFromHeaders","upload","modifyResponseHeaders","readableStream","ReadableStream","start","controller","nodeStream","readableStreamBody","Error","on","chunk","enqueue","Uint8Array","close","err","error","statusCode","statusText","payload","logger"],"mappings":"AAIA,SAASA,SAAS,QAAQ,sBAAqB;AAC/C,SAASC,aAAa,QAAQ,6CAA4C;AAC1E,OAAOC,UAAU,OAAM;AACvB,SAASC,mBAAmB,QAAQ,mBAAkB;AAOtD,OAAO,MAAMC,aAAa,CAAC,EAAEC,UAAU,EAAEC,gBAAgB,EAAQ;IAC/D,OAAO,OAAOC,KAAK,EAAEC,SAASC,eAAe,EAAEC,QAAQ,EAAEC,mBAAmB,EAAEC,QAAQ,EAAE,EAAE;QACxF,IAAI;YACF,MAAMC,SAAS,MAAMZ,cAAc;gBAAEU;gBAAqBN;gBAAYO;gBAAUL;YAAI;YACpF,MAAMO,kBAAkBR,mBAAmBS,kBAAkB,CAC3Db,KAAKc,KAAK,CAACC,IAAI,CAACJ,QAAQD;YAG1B,qCAAqC;YACrC,MAAMM,aAAa,MAAMJ,gBAAgBK,aAAa;YACtD,MAAMC,WAAWF,WAAWG,aAAa;YAEzC,IAAI,CAACD,UAAU;gBACb,OAAO,IAAIE,SAAS,yBAAyB;oBAAEC,QAAQ;gBAAI;YAC7D;YAEA,uBAAuB;YACvB,MAAMC,cAAcjB,IAAIC,OAAO,CAACiB,GAAG,CAAC;YACpC,MAAMC,cAAcvB,oBAAoB;gBAAEiB;gBAAUI;YAAY;YAEhE,IAAIE,YAAYC,IAAI,KAAK,WAAW;gBAClC,OAAO,IAAIL,SAAS,MAAM;oBACxBd,SAAS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AWG,EAAE,CAAC,QAAQ,CAACC;wBACrBL,WAAWM,OAAO,CAAC,IAAIC,WAAWF;oBACpC;oBACAJ,WAAWG,EAAE,CAAC,OAAO;wBACnBJ,WAAWQ,KAAK;oBAClB;oBACAP,WAAWG,EAAE,CAAC,SAAS,CAACK;wBACtBT,WAAWU,KAAK,CAACD;oBACnB;gBACF;YACF;YAEA,OAAO,IAAIlC,SAASsB,gBAAgB;gBAClCpC;gBACAe,QAAQG,YAAYH,MAAM;YAC5B;QACF,EAAE,OAAOiC,KAAc;YACrB,IAAIA,eAAexD,aAAawD,IAAIE,UAAU,KAAK,KAAK;gBACtD,OAAO,IAAIpC,SAAS,MAAM;oBAAEC,QAAQ;oBAAKoC,YAAY;gBAAY;YACnE;YACApD,IAAIqD,OAAO,CAACC,MAAM,CAACJ,KAAK,CAACD;YACzB,OAAO,IAAIlC,SAAS,yBAAyB;gBAAEC,QAAQ;YAAI;QAC7D;IACF;AACF,EAAC"}
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@payloadcms/storage-azure",
|
|
3
|
-
"version": "3.71.0
|
|
3
|
+
"version": "3.71.0",
|
|
4
4
|
"description": "Payload storage adapter for Azure Blob Storage",
|
|
5
5
|
"homepage": "https://payloadcms.com",
|
|
6
6
|
"repository": {
|
|
@@ -39,15 +39,13 @@
|
|
|
39
39
|
"dependencies": {
|
|
40
40
|
"@azure/abort-controller": "^1.1.0",
|
|
41
41
|
"@azure/storage-blob": "^12.11.0",
|
|
42
|
-
"
|
|
43
|
-
"@payloadcms/plugin-cloud-storage": "3.71.0-internal.e36f916"
|
|
42
|
+
"@payloadcms/plugin-cloud-storage": "3.71.0"
|
|
44
43
|
},
|
|
45
44
|
"devDependencies": {
|
|
46
|
-
"
|
|
47
|
-
"payload": "3.71.0-internal.e36f916"
|
|
45
|
+
"payload": "3.71.0"
|
|
48
46
|
},
|
|
49
47
|
"peerDependencies": {
|
|
50
|
-
"payload": "3.71.0
|
|
48
|
+
"payload": "3.71.0"
|
|
51
49
|
},
|
|
52
50
|
"engines": {
|
|
53
51
|
"node": "^18.20.2 || >=20.9.0"
|