@payloadcms/storage-gcs 3.47.0-internal.b17506e → 3.47.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,aAAa,EAAE,MAAM,wCAAwC,CAAA;AAC3E,OAAO,KAAK,EAAE,gBAAgB,EAAE,MAAM,SAAS,CAAA;AAE/C,OAAO,EAAY,KAAK,OAAO,EAAE,MAAM,uBAAuB,CAAA;AAI9D,UAAU,IAAI;IACZ,MAAM,EAAE,MAAM,CAAA;IACd,UAAU,EAAE,gBAAgB,CAAA;IAC5B,gBAAgB,EAAE,MAAM,OAAO,CAAA;CAChC;AAED,eAAO,MAAM,UAAU,6CAA8C,IAAI,KAAG,
|
|
1
|
+
{"version":3,"file":"staticHandler.d.ts","sourceRoot":"","sources":["../src/staticHandler.ts"],"names":[],"mappings":"AAAA,OAAO,KAAK,EAAE,aAAa,EAAE,MAAM,wCAAwC,CAAA;AAC3E,OAAO,KAAK,EAAE,gBAAgB,EAAE,MAAM,SAAS,CAAA;AAE/C,OAAO,EAAY,KAAK,OAAO,EAAE,MAAM,uBAAuB,CAAA;AAI9D,UAAU,IAAI;IACZ,MAAM,EAAE,MAAM,CAAA;IACd,UAAU,EAAE,gBAAgB,CAAA;IAC5B,gBAAgB,EAAE,MAAM,OAAO,CAAA;CAChC;AAED,eAAO,MAAM,UAAU,6CAA8C,IAAI,KAAG,aA4D3E,CAAA"}
|
package/dist/staticHandler.js
CHANGED
|
@@ -2,7 +2,7 @@ import { ApiError } from '@google-cloud/storage';
|
|
|
2
2
|
import { getFilePrefix } from '@payloadcms/plugin-cloud-storage/utilities';
|
|
3
3
|
import path from 'path';
|
|
4
4
|
export const getHandler = ({ bucket, collection, getStorageClient })=>{
|
|
5
|
-
return async (req, { params: { clientUploadContext, filename } })=>{
|
|
5
|
+
return async (req, { headers: incomingHeaders, params: { clientUploadContext, filename } })=>{
|
|
6
6
|
try {
|
|
7
7
|
const prefix = await getFilePrefix({
|
|
8
8
|
clientUploadContext,
|
|
@@ -14,13 +14,18 @@ export const getHandler = ({ bucket, collection, getStorageClient })=>{
|
|
|
14
14
|
const [metadata] = await file.getMetadata();
|
|
15
15
|
const etagFromHeaders = req.headers.get('etag') || req.headers.get('if-none-match');
|
|
16
16
|
const objectEtag = metadata.etag;
|
|
17
|
+
let headers = new Headers(incomingHeaders);
|
|
18
|
+
headers.append('Content-Length', String(metadata.size));
|
|
19
|
+
headers.append('Content-Type', String(metadata.contentType));
|
|
20
|
+
headers.append('ETag', String(metadata.etag));
|
|
21
|
+
if (collection.upload && typeof collection.upload === 'object' && typeof collection.upload.modifyResponseHeaders === 'function') {
|
|
22
|
+
headers = collection.upload.modifyResponseHeaders({
|
|
23
|
+
headers
|
|
24
|
+
}) || headers;
|
|
25
|
+
}
|
|
17
26
|
if (etagFromHeaders && etagFromHeaders === objectEtag) {
|
|
18
27
|
return new Response(null, {
|
|
19
|
-
headers
|
|
20
|
-
'Content-Length': String(metadata.size),
|
|
21
|
-
'Content-Type': String(metadata.contentType),
|
|
22
|
-
ETag: String(metadata.etag)
|
|
23
|
-
}),
|
|
28
|
+
headers,
|
|
24
29
|
status: 304
|
|
25
30
|
});
|
|
26
31
|
}
|
|
@@ -40,11 +45,7 @@ export const getHandler = ({ bucket, collection, getStorageClient })=>{
|
|
|
40
45
|
}
|
|
41
46
|
});
|
|
42
47
|
return new Response(readableStream, {
|
|
43
|
-
headers
|
|
44
|
-
'Content-Length': String(metadata.size),
|
|
45
|
-
'Content-Type': String(metadata.contentType),
|
|
46
|
-
ETag: String(metadata.etag)
|
|
47
|
-
}),
|
|
48
|
+
headers,
|
|
48
49
|
status: 200
|
|
49
50
|
});
|
|
50
51
|
} catch (err) {
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"sources":["../src/staticHandler.ts"],"sourcesContent":["import type { StaticHandler } from '@payloadcms/plugin-cloud-storage/types'\nimport type { CollectionConfig } from 'payload'\n\nimport { ApiError, type Storage } from '@google-cloud/storage'\nimport { getFilePrefix } from '@payloadcms/plugin-cloud-storage/utilities'\nimport path from 'path'\n\ninterface Args {\n bucket: string\n collection: CollectionConfig\n getStorageClient: () => Storage\n}\n\nexport const getHandler = ({ bucket, collection, getStorageClient }: Args): StaticHandler => {\n return async (req, { params: { clientUploadContext, filename } }) => {\n try {\n const prefix = await getFilePrefix({ clientUploadContext, collection, filename, req })\n const file = getStorageClient().bucket(bucket).file(path.posix.join(prefix, filename))\n\n const [metadata] = await file.getMetadata()\n\n const etagFromHeaders = req.headers.get('etag') || req.headers.get('if-none-match')\n const objectEtag = metadata.etag\n\n
|
|
1
|
+
{"version":3,"sources":["../src/staticHandler.ts"],"sourcesContent":["import type { StaticHandler } from '@payloadcms/plugin-cloud-storage/types'\nimport type { CollectionConfig } from 'payload'\n\nimport { ApiError, type Storage } from '@google-cloud/storage'\nimport { getFilePrefix } from '@payloadcms/plugin-cloud-storage/utilities'\nimport path from 'path'\n\ninterface Args {\n bucket: string\n collection: CollectionConfig\n getStorageClient: () => Storage\n}\n\nexport const getHandler = ({ bucket, 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 file = getStorageClient().bucket(bucket).file(path.posix.join(prefix, filename))\n\n const [metadata] = await file.getMetadata()\n\n const etagFromHeaders = req.headers.get('etag') || req.headers.get('if-none-match')\n const objectEtag = metadata.etag\n\n let headers = new Headers(incomingHeaders)\n\n headers.append('Content-Length', String(metadata.size))\n headers.append('Content-Type', String(metadata.contentType))\n headers.append('ETag', String(metadata.etag))\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 === objectEtag) {\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 = file.createReadStream()\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: 200,\n })\n } catch (err: unknown) {\n if (err instanceof ApiError && err.code === 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":["ApiError","getFilePrefix","path","getHandler","bucket","collection","getStorageClient","req","headers","incomingHeaders","params","clientUploadContext","filename","prefix","file","posix","join","metadata","getMetadata","etagFromHeaders","get","objectEtag","etag","Headers","append","String","size","contentType","upload","modifyResponseHeaders","Response","status","readableStream","ReadableStream","start","controller","nodeStream","createReadStream","on","chunk","enqueue","Uint8Array","close","err","error","code","statusText","payload","logger"],"mappings":"AAGA,SAASA,QAAQ,QAAsB,wBAAuB;AAC9D,SAASC,aAAa,QAAQ,6CAA4C;AAC1E,OAAOC,UAAU,OAAM;AAQvB,OAAO,MAAMC,aAAa,CAAC,EAAEC,MAAM,EAAEC,UAAU,EAAEC,gBAAgB,EAAQ;IACvE,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,OAAOR,mBAAmBF,MAAM,CAACA,QAAQU,IAAI,CAACZ,KAAKa,KAAK,CAACC,IAAI,CAACH,QAAQD;YAE5E,MAAM,CAACK,SAAS,GAAG,MAAMH,KAAKI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AO,CAACC,MAAM,CAACJ,KAAK,CAACD;YACzB,OAAO,IAAIb,SAAS,yBAAyB;gBAAEC,QAAQ;YAAI;QAC7D;IACF;AACF,EAAC"}
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@payloadcms/storage-gcs",
|
|
3
|
-
"version": "3.47.0
|
|
3
|
+
"version": "3.47.0",
|
|
4
4
|
"description": "Payload storage adapter for Google Cloud Storage",
|
|
5
5
|
"homepage": "https://payloadcms.com",
|
|
6
6
|
"repository": {
|
|
@@ -38,13 +38,13 @@
|
|
|
38
38
|
],
|
|
39
39
|
"dependencies": {
|
|
40
40
|
"@google-cloud/storage": "^7.7.0",
|
|
41
|
-
"@payloadcms/plugin-cloud-storage": "3.47.0
|
|
41
|
+
"@payloadcms/plugin-cloud-storage": "3.47.0"
|
|
42
42
|
},
|
|
43
43
|
"devDependencies": {
|
|
44
|
-
"payload": "3.47.0
|
|
44
|
+
"payload": "3.47.0"
|
|
45
45
|
},
|
|
46
46
|
"peerDependencies": {
|
|
47
|
-
"payload": "3.47.0
|
|
47
|
+
"payload": "3.47.0"
|
|
48
48
|
},
|
|
49
49
|
"engines": {
|
|
50
50
|
"node": "^18.20.2 || >=20.9.0"
|