@payloadcms/storage-vercel-blob 3.91.0 → 3.92.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.map +1 -1
- package/dist/adapter.js +11 -3
- package/dist/adapter.js.map +1 -1
- package/dist/adapter.spec.js +156 -0
- package/dist/adapter.spec.js.map +1 -0
- package/dist/uploadFile.d.ts +2 -1
- package/dist/uploadFile.d.ts.map +1 -1
- package/dist/uploadFile.js +4 -2
- package/dist/uploadFile.js.map +1 -1
- package/package.json +6 -6
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,EACV,OAAO,EACP,mBAAmB,EAEpB,MAAM,wCAAwC,CAAA;
|
|
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;AAS/C,UAAU,2BAA2B;IACnC,MAAM,EAAE,QAAQ,CAAA;IAChB,eAAe,CAAC,EAAE,OAAO,CAAA;IACzB,OAAO,EAAE,MAAM,CAAA;IACf,kBAAkB,EAAE,MAAM,CAAA;IAC1B,aAAa,CAAC,EAAE,mBAAmB,CAAA;IACnC,KAAK,EAAE,MAAM,CAAA;IACb,oBAAoB,CAAC,EAAE,OAAO,CAAA;CAC/B;AAED,wBAAgB,uBAAuB,CAAC,EACtC,MAAM,EACN,eAAe,EACf,OAAO,EACP,kBAAkB,EAClB,aAAa,EACb,KAAK,EACL,oBAA4B,GAC7B,EAAE,2BAA2B,GAAG,OAAO,CAqEvC"}
|
package/dist/adapter.js
CHANGED
|
@@ -1,3 +1,4 @@
|
|
|
1
|
+
import { CLIENT_UPLOAD_TEMP_FILE_PATH_CONTEXT_KEY } from 'payload';
|
|
1
2
|
import { deleteFile } from './deleteFile.js';
|
|
2
3
|
import { generateURL } from './generateURL.js';
|
|
3
4
|
import { getFile } from './getFile.js';
|
|
@@ -19,18 +20,25 @@ export function createVercelBlobAdapter({ access, addRandomSuffix, baseUrl, cach
|
|
|
19
20
|
storageFilePath,
|
|
20
21
|
token
|
|
21
22
|
}),
|
|
22
|
-
handleUpload: async ({ data, file: { buffer, mimeType }, storageFilePath })=>{
|
|
23
|
+
handleUpload: async ({ data, file: { buffer, imageSizeName, mimeType, tempFilePath }, req, storageFilePath })=>{
|
|
24
|
+
// A processed client upload keeps the storage key from its receipt.
|
|
25
|
+
const isClientUpload = Boolean(tempFilePath) && tempFilePath === req.context?.[CLIENT_UPLOAD_TEMP_FILE_PATH_CONTEXT_KEY];
|
|
23
26
|
const result = await uploadFile({
|
|
24
27
|
access,
|
|
25
|
-
addRandomSuffix,
|
|
28
|
+
addRandomSuffix: addRandomSuffix && !isClientUpload,
|
|
26
29
|
buffer,
|
|
27
30
|
cacheControlMaxAge,
|
|
28
31
|
mimeType,
|
|
29
32
|
storageFilePath,
|
|
33
|
+
tempFilePath,
|
|
30
34
|
token
|
|
31
35
|
});
|
|
32
36
|
if (result.filename) {
|
|
33
|
-
|
|
37
|
+
if (imageSizeName !== undefined) {
|
|
38
|
+
data.sizes[imageSizeName].filename = result.filename;
|
|
39
|
+
} else {
|
|
40
|
+
data.filename = result.filename;
|
|
41
|
+
}
|
|
34
42
|
}
|
|
35
43
|
return data;
|
|
36
44
|
},
|
package/dist/adapter.js.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"sources":["../src/adapter.ts"],"sourcesContent":["import 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 CreateVercelBlobAdapterArgs {\n access: 'public'\n addRandomSuffix?: boolean\n baseUrl: string\n cacheControlMaxAge: number\n clientUploads?: ClientUploadsConfig\n token: string\n useCompositePrefixes?: boolean\n}\n\nexport function createVercelBlobAdapter({\n access,\n addRandomSuffix,\n baseUrl,\n cacheControlMaxAge,\n clientUploads,\n token,\n useCompositePrefixes = false,\n}: CreateVercelBlobAdapterArgs): Adapter {\n return ({ collection, prefix = '' }): GeneratedAdapter => ({\n name: 'vercel-blob',\n clientUploads,\n requiresClientUploadReceipt: true,\n\n generateURL: ({ filename, prefix: urlPrefix = '' }) =>\n generateURL({\n baseUrl,\n collectionPrefix: prefix,\n filename,\n prefix: urlPrefix,\n useCompositePrefixes,\n }),\n\n handleDelete: ({ storageFilePath }) =>\n deleteFile({\n baseUrl,\n storageFilePath,\n token,\n }),\n\n handleUpload: async ({
|
|
1
|
+
{"version":3,"sources":["../src/adapter.ts"],"sourcesContent":["import type {\n Adapter,\n ClientUploadsConfig,\n GeneratedAdapter,\n} from '@payloadcms/plugin-cloud-storage/types'\n\nimport { CLIENT_UPLOAD_TEMP_FILE_PATH_CONTEXT_KEY } from 'payload'\n\nimport { deleteFile } from './deleteFile.js'\nimport { generateURL } from './generateURL.js'\nimport { getFile } from './getFile.js'\nimport { uploadFile } from './uploadFile.js'\n\ninterface CreateVercelBlobAdapterArgs {\n access: 'public'\n addRandomSuffix?: boolean\n baseUrl: string\n cacheControlMaxAge: number\n clientUploads?: ClientUploadsConfig\n token: string\n useCompositePrefixes?: boolean\n}\n\nexport function createVercelBlobAdapter({\n access,\n addRandomSuffix,\n baseUrl,\n cacheControlMaxAge,\n clientUploads,\n token,\n useCompositePrefixes = false,\n}: CreateVercelBlobAdapterArgs): Adapter {\n return ({ collection, prefix = '' }): GeneratedAdapter => ({\n name: 'vercel-blob',\n clientUploads,\n requiresClientUploadReceipt: true,\n\n generateURL: ({ filename, prefix: urlPrefix = '' }) =>\n generateURL({\n baseUrl,\n collectionPrefix: prefix,\n filename,\n prefix: urlPrefix,\n useCompositePrefixes,\n }),\n\n handleDelete: ({ storageFilePath }) =>\n deleteFile({\n baseUrl,\n storageFilePath,\n token,\n }),\n\n handleUpload: async ({\n data,\n file: { buffer, imageSizeName, mimeType, tempFilePath },\n req,\n storageFilePath,\n }) => {\n // A processed client upload keeps the storage key from its receipt.\n const isClientUpload =\n Boolean(tempFilePath) &&\n tempFilePath === req.context?.[CLIENT_UPLOAD_TEMP_FILE_PATH_CONTEXT_KEY]\n const result = await uploadFile({\n access,\n addRandomSuffix: addRandomSuffix && !isClientUpload,\n buffer,\n cacheControlMaxAge,\n mimeType,\n storageFilePath,\n tempFilePath,\n token,\n })\n\n if (result.filename) {\n if (imageSizeName !== undefined) {\n data.sizes[imageSizeName].filename = result.filename\n } else {\n data.filename = result.filename\n }\n }\n\n return data\n },\n\n staticHandler: (req, { doc, headers, params: { clientUploadContext, filename } }) =>\n getFile({\n baseUrl,\n cacheControlMaxAge,\n clientUploadContext,\n collection,\n collectionPrefix: prefix,\n doc,\n filename,\n incomingHeaders: headers,\n req,\n token,\n useCompositePrefixes,\n }),\n })\n}\n"],"names":["CLIENT_UPLOAD_TEMP_FILE_PATH_CONTEXT_KEY","deleteFile","generateURL","getFile","uploadFile","createVercelBlobAdapter","access","addRandomSuffix","baseUrl","cacheControlMaxAge","clientUploads","token","useCompositePrefixes","collection","prefix","name","requiresClientUploadReceipt","filename","urlPrefix","collectionPrefix","handleDelete","storageFilePath","handleUpload","data","file","buffer","imageSizeName","mimeType","tempFilePath","req","isClientUpload","Boolean","context","result","undefined","sizes","staticHandler","doc","headers","params","clientUploadContext","incomingHeaders"],"mappings":"AAMA,SAASA,wCAAwC,QAAQ,UAAS;AAElE,SAASC,UAAU,QAAQ,kBAAiB;AAC5C,SAASC,WAAW,QAAQ,mBAAkB;AAC9C,SAASC,OAAO,QAAQ,eAAc;AACtC,SAASC,UAAU,QAAQ,kBAAiB;AAY5C,OAAO,SAASC,wBAAwB,EACtCC,MAAM,EACNC,eAAe,EACfC,OAAO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;QACJ,CAAA;AACF"}
|
|
@@ -0,0 +1,156 @@
|
|
|
1
|
+
import { put } from '@vercel/blob';
|
|
2
|
+
import { describe, expect, it, vi } from 'vitest';
|
|
3
|
+
vi.mock('@vercel/blob', async (importOriginal)=>({
|
|
4
|
+
...await importOriginal(),
|
|
5
|
+
put: vi.fn(async (pathname)=>({
|
|
6
|
+
pathname: pathname.replace('.png', '-suffix.png')
|
|
7
|
+
}))
|
|
8
|
+
}));
|
|
9
|
+
vi.mock('fs', async (importOriginal)=>({
|
|
10
|
+
...await importOriginal(),
|
|
11
|
+
openAsBlob: vi.fn(async ()=>new Blob([
|
|
12
|
+
'file'
|
|
13
|
+
]))
|
|
14
|
+
}));
|
|
15
|
+
import { createVercelBlobAdapter } from './adapter.js';
|
|
16
|
+
const adapter = createVercelBlobAdapter({
|
|
17
|
+
access: 'public',
|
|
18
|
+
addRandomSuffix: true,
|
|
19
|
+
baseUrl: 'https://example.com',
|
|
20
|
+
cacheControlMaxAge: 60,
|
|
21
|
+
token: 'token'
|
|
22
|
+
})({
|
|
23
|
+
collection: {
|
|
24
|
+
fields: [],
|
|
25
|
+
slug: 'media',
|
|
26
|
+
upload: {}
|
|
27
|
+
},
|
|
28
|
+
prefix: ''
|
|
29
|
+
});
|
|
30
|
+
describe('handleUpload with addRandomSuffix', ()=>{
|
|
31
|
+
it.each([
|
|
32
|
+
[
|
|
33
|
+
'main file',
|
|
34
|
+
'image.png',
|
|
35
|
+
{
|
|
36
|
+
filename: 'image-suffix.png',
|
|
37
|
+
square: 'image-400x400.png'
|
|
38
|
+
}
|
|
39
|
+
],
|
|
40
|
+
[
|
|
41
|
+
'image size',
|
|
42
|
+
'image-400x400.png',
|
|
43
|
+
{
|
|
44
|
+
filename: 'image.png',
|
|
45
|
+
square: 'image-400x400-suffix.png'
|
|
46
|
+
}
|
|
47
|
+
]
|
|
48
|
+
])('should set the suffixed filename only on the %s', async (_, filename, expected)=>{
|
|
49
|
+
const data = {
|
|
50
|
+
filename: 'image.png',
|
|
51
|
+
sizes: {
|
|
52
|
+
square: {
|
|
53
|
+
filename: 'image-400x400.png'
|
|
54
|
+
}
|
|
55
|
+
}
|
|
56
|
+
};
|
|
57
|
+
await adapter.handleUpload({
|
|
58
|
+
data,
|
|
59
|
+
file: {
|
|
60
|
+
buffer: Buffer.from('file'),
|
|
61
|
+
filename,
|
|
62
|
+
filesize: 4,
|
|
63
|
+
imageSizeName: filename === 'image.png' ? undefined : 'square',
|
|
64
|
+
mimeType: 'image/png'
|
|
65
|
+
},
|
|
66
|
+
req: {
|
|
67
|
+
context: {}
|
|
68
|
+
},
|
|
69
|
+
storageFilePath: filename
|
|
70
|
+
});
|
|
71
|
+
expect({
|
|
72
|
+
filename: data.filename,
|
|
73
|
+
square: data.sizes.square.filename
|
|
74
|
+
}).toEqual(expected);
|
|
75
|
+
});
|
|
76
|
+
it('should give image sizes with the same dimensions their own suffixed filenames', async ()=>{
|
|
77
|
+
vi.mocked(put).mockResolvedValueOnce({
|
|
78
|
+
pathname: 'image-400x400-a.png'
|
|
79
|
+
}).mockResolvedValueOnce({
|
|
80
|
+
pathname: 'image-400x400-b.png'
|
|
81
|
+
});
|
|
82
|
+
const data = {
|
|
83
|
+
filename: 'image.png',
|
|
84
|
+
sizes: {
|
|
85
|
+
card: {
|
|
86
|
+
filename: 'image-400x400.png'
|
|
87
|
+
},
|
|
88
|
+
square: {
|
|
89
|
+
filename: 'image-400x400.png'
|
|
90
|
+
}
|
|
91
|
+
}
|
|
92
|
+
};
|
|
93
|
+
const uploadImageSize = (imageSizeName)=>adapter.handleUpload({
|
|
94
|
+
data,
|
|
95
|
+
file: {
|
|
96
|
+
buffer: Buffer.from('file'),
|
|
97
|
+
filename: 'image-400x400.png',
|
|
98
|
+
filesize: 4,
|
|
99
|
+
imageSizeName,
|
|
100
|
+
mimeType: 'image/png'
|
|
101
|
+
},
|
|
102
|
+
req: {
|
|
103
|
+
context: {}
|
|
104
|
+
},
|
|
105
|
+
storageFilePath: 'image-400x400.png'
|
|
106
|
+
});
|
|
107
|
+
await Promise.all([
|
|
108
|
+
uploadImageSize('card'),
|
|
109
|
+
uploadImageSize('square')
|
|
110
|
+
]);
|
|
111
|
+
expect(data.sizes).toEqual({
|
|
112
|
+
card: {
|
|
113
|
+
filename: 'image-400x400-a.png'
|
|
114
|
+
},
|
|
115
|
+
square: {
|
|
116
|
+
filename: 'image-400x400-b.png'
|
|
117
|
+
}
|
|
118
|
+
});
|
|
119
|
+
});
|
|
120
|
+
it.each([
|
|
121
|
+
[
|
|
122
|
+
'a processed client upload',
|
|
123
|
+
'/tmp/client-upload',
|
|
124
|
+
false
|
|
125
|
+
],
|
|
126
|
+
[
|
|
127
|
+
'another temp file',
|
|
128
|
+
'/tmp/other-upload',
|
|
129
|
+
true
|
|
130
|
+
]
|
|
131
|
+
])('should set addRandomSuffix for %s', async (_, tempFilePath, expected)=>{
|
|
132
|
+
await adapter.handleUpload({
|
|
133
|
+
data: {
|
|
134
|
+
filename: 'image.png'
|
|
135
|
+
},
|
|
136
|
+
file: {
|
|
137
|
+
buffer: Buffer.alloc(0),
|
|
138
|
+
filename: 'image.png',
|
|
139
|
+
filesize: 4,
|
|
140
|
+
mimeType: 'image/png',
|
|
141
|
+
tempFilePath
|
|
142
|
+
},
|
|
143
|
+
req: {
|
|
144
|
+
context: {
|
|
145
|
+
payloadClientUploadTempFilePath: '/tmp/client-upload'
|
|
146
|
+
}
|
|
147
|
+
},
|
|
148
|
+
storageFilePath: 'issued/image.png'
|
|
149
|
+
});
|
|
150
|
+
expect(vi.mocked(put)).toHaveBeenLastCalledWith('issued/image.png', expect.anything(), expect.objectContaining({
|
|
151
|
+
addRandomSuffix: expected
|
|
152
|
+
}));
|
|
153
|
+
});
|
|
154
|
+
});
|
|
155
|
+
|
|
156
|
+
//# sourceMappingURL=adapter.spec.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"sources":["../src/adapter.spec.ts"],"sourcesContent":["import { put } from '@vercel/blob'\nimport { describe, expect, it, vi } from 'vitest'\n\nvi.mock('@vercel/blob', async (importOriginal) => ({\n ...(await importOriginal<typeof import('@vercel/blob')>()),\n put: vi.fn(async (pathname: string) => ({ pathname: pathname.replace('.png', '-suffix.png') })),\n}))\n\nvi.mock('fs', async (importOriginal) => ({\n ...(await importOriginal<typeof import('fs')>()),\n openAsBlob: vi.fn(async () => new Blob(['file'])),\n}))\n\nimport { createVercelBlobAdapter } from './adapter.js'\n\nconst adapter = createVercelBlobAdapter({\n access: 'public',\n addRandomSuffix: true,\n baseUrl: 'https://example.com',\n cacheControlMaxAge: 60,\n token: 'token',\n})({ collection: { fields: [], slug: 'media', upload: {} }, prefix: '' })\n\ndescribe('handleUpload with addRandomSuffix', () => {\n it.each([\n ['main file', 'image.png', { filename: 'image-suffix.png', square: 'image-400x400.png' }],\n [\n 'image size',\n 'image-400x400.png',\n { filename: 'image.png', square: 'image-400x400-suffix.png' },\n ],\n ])('should set the suffixed filename only on the %s', async (_, filename, expected) => {\n const data = { filename: 'image.png', sizes: { square: { filename: 'image-400x400.png' } } }\n\n await adapter.handleUpload({\n data,\n file: {\n buffer: Buffer.from('file'),\n filename,\n filesize: 4,\n imageSizeName: filename === 'image.png' ? undefined : 'square',\n mimeType: 'image/png',\n },\n req: { context: {} },\n storageFilePath: filename,\n } as never)\n\n expect({ filename: data.filename, square: data.sizes.square.filename }).toEqual(expected)\n })\n\n it('should give image sizes with the same dimensions their own suffixed filenames', async () => {\n vi.mocked(put)\n .mockResolvedValueOnce({ pathname: 'image-400x400-a.png' } as never)\n .mockResolvedValueOnce({ pathname: 'image-400x400-b.png' } as never)\n\n const data = {\n filename: 'image.png',\n sizes: { card: { filename: 'image-400x400.png' }, square: { filename: 'image-400x400.png' } },\n }\n const uploadImageSize = (imageSizeName: string) =>\n adapter.handleUpload({\n data,\n file: {\n buffer: Buffer.from('file'),\n filename: 'image-400x400.png',\n filesize: 4,\n imageSizeName,\n mimeType: 'image/png',\n },\n req: { context: {} },\n storageFilePath: 'image-400x400.png',\n } as never)\n\n await Promise.all([uploadImageSize('card'), uploadImageSize('square')])\n\n expect(data.sizes).toEqual({\n card: { filename: 'image-400x400-a.png' },\n square: { filename: 'image-400x400-b.png' },\n })\n })\n\n it.each([\n ['a processed client upload', '/tmp/client-upload', false],\n ['another temp file', '/tmp/other-upload', true],\n ])('should set addRandomSuffix for %s', async (_, tempFilePath, expected) => {\n await adapter.handleUpload({\n data: { filename: 'image.png' },\n file: {\n buffer: Buffer.alloc(0),\n filename: 'image.png',\n filesize: 4,\n mimeType: 'image/png',\n tempFilePath,\n },\n req: { context: { payloadClientUploadTempFilePath: '/tmp/client-upload' } },\n storageFilePath: 'issued/image.png',\n } as never)\n\n expect(vi.mocked(put)).toHaveBeenLastCalledWith(\n 'issued/image.png',\n expect.anything(),\n expect.objectContaining({ addRandomSuffix: expected }),\n )\n })\n})\n"],"names":["put","describe","expect","it","vi","mock","importOriginal","fn","pathname","replace","openAsBlob","Blob","createVercelBlobAdapter","adapter","access","addRandomSuffix","baseUrl","cacheControlMaxAge","token","collection","fields","slug","upload","prefix","each","filename","square","_","expected","data","sizes","handleUpload","file","buffer","Buffer","from","filesize","imageSizeName","undefined","mimeType","req","context","storageFilePath","toEqual","mocked","mockResolvedValueOnce","card","uploadImageSize","Promise","all","tempFilePath","alloc","payloadClientUploadTempFilePath","toHaveBeenLastCalledWith","anything","objectContaining"],"mappings":"AAAA,SAASA,GAAG,QAAQ,eAAc;AAClC,SAASC,QAAQ,EAAEC,MAAM,EAAEC,EAAE,EAAEC,EAAE,QAAQ,SAAQ;AAEjDA,GAAGC,IAAI,CAAC,gBAAgB,OAAOC,iBAAoB,CAAA;QACjD,GAAI,MAAMA,gBAA+C;QACzDN,KAAKI,GAAGG,EAAE,CAAC,OAAOC,WAAsB,CAAA;gBAAEA,UAAUA,SAASC,OAAO,CAAC,QAAQ;YAAe,CAAA;IAC9F,CAAA;AAEAL,GAAGC,IAAI,CAAC,MAAM,OAAOC,iBAAoB,CA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AAErB,UAAU;gBAAoB;gBAAGC,QAAQ;oBAAED,UAAU;gBAAoB;YAAE;QAC9F;QACA,MAAMsB,kBAAkB,CAACV,gBACvBxB,QAAQkB,YAAY,CAAC;gBACnBF;gBACAG,MAAM;oBACJC,QAAQC,OAAOC,IAAI,CAAC;oBACpBV,UAAU;oBACVW,UAAU;oBACVC;oBACAE,UAAU;gBACZ;gBACAC,KAAK;oBAAEC,SAAS,CAAC;gBAAE;gBACnBC,iBAAiB;YACnB;QAEF,MAAMM,QAAQC,GAAG,CAAC;YAACF,gBAAgB;YAASA,gBAAgB;SAAU;QAEtE7C,OAAO2B,KAAKC,KAAK,EAAEa,OAAO,CAAC;YACzBG,MAAM;gBAAErB,UAAU;YAAsB;YACxCC,QAAQ;gBAAED,UAAU;YAAsB;QAC5C;IACF;IAEAtB,GAAGqB,IAAI,CAAC;QACN;YAAC;YAA6B;YAAsB;SAAM;QAC1D;YAAC;YAAqB;YAAqB;SAAK;KACjD,EAAE,qCAAqC,OAAOG,GAAGuB,cAActB;QAC9D,MAAMf,QAAQkB,YAAY,CAAC;YACzBF,MAAM;gBAAEJ,UAAU;YAAY;YAC9BO,MAAM;gBACJC,QAAQC,OAAOiB,KAAK,CAAC;gBACrB1B,UAAU;gBACVW,UAAU;gBACVG,UAAU;gBACVW;YACF;YACAV,KAAK;gBAAEC,SAAS;oBAAEW,iCAAiC;gBAAqB;YAAE;YAC1EV,iBAAiB;QACnB;QAEAxC,OAAOE,GAAGwC,MAAM,CAAC5C,MAAMqD,wBAAwB,CAC7C,oBACAnD,OAAOoD,QAAQ,IACfpD,OAAOqD,gBAAgB,CAAC;YAAExC,iBAAiBa;QAAS;IAExD;AACF"}
|
package/dist/uploadFile.d.ts
CHANGED
|
@@ -5,11 +5,12 @@ interface UploadFileArgs {
|
|
|
5
5
|
cacheControlMaxAge?: number;
|
|
6
6
|
mimeType: string;
|
|
7
7
|
storageFilePath: string;
|
|
8
|
+
tempFilePath?: string;
|
|
8
9
|
token: string;
|
|
9
10
|
}
|
|
10
11
|
interface UploadFileResult {
|
|
11
12
|
filename?: string;
|
|
12
13
|
}
|
|
13
|
-
export declare function uploadFile({ access, addRandomSuffix, buffer, cacheControlMaxAge, mimeType, storageFilePath, token, }: UploadFileArgs): Promise<UploadFileResult>;
|
|
14
|
+
export declare function uploadFile({ access, addRandomSuffix, buffer, cacheControlMaxAge, mimeType, storageFilePath, tempFilePath, token, }: UploadFileArgs): Promise<UploadFileResult>;
|
|
14
15
|
export {};
|
|
15
16
|
//# sourceMappingURL=uploadFile.d.ts.map
|
package/dist/uploadFile.d.ts.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"uploadFile.d.ts","sourceRoot":"","sources":["../src/uploadFile.ts"],"names":[],"mappings":"
|
|
1
|
+
{"version":3,"file":"uploadFile.d.ts","sourceRoot":"","sources":["../src/uploadFile.ts"],"names":[],"mappings":"AAIA,UAAU,cAAc;IACtB,MAAM,EAAE,QAAQ,CAAA;IAChB,eAAe,CAAC,EAAE,OAAO,CAAA;IACzB,MAAM,EAAE,MAAM,CAAA;IACd,kBAAkB,CAAC,EAAE,MAAM,CAAA;IAC3B,QAAQ,EAAE,MAAM,CAAA;IAChB,eAAe,EAAE,MAAM,CAAA;IACvB,YAAY,CAAC,EAAE,MAAM,CAAA;IACrB,KAAK,EAAE,MAAM,CAAA;CACd;AAED,UAAU,gBAAgB;IACxB,QAAQ,CAAC,EAAE,MAAM,CAAA;CAClB;AAED,wBAAsB,UAAU,CAAC,EAC/B,MAAM,EACN,eAAe,EACf,MAAM,EACN,kBAAkB,EAClB,QAAQ,EACR,eAAe,EACf,YAAY,EACZ,KAAK,GACN,EAAE,cAAc,GAAG,OAAO,CAAC,gBAAgB,CAAC,CAkB5C"}
|
package/dist/uploadFile.js
CHANGED
|
@@ -1,7 +1,9 @@
|
|
|
1
1
|
import { put } from '@vercel/blob';
|
|
2
|
+
import { openAsBlob } from 'fs';
|
|
2
3
|
import path from 'path';
|
|
3
|
-
export async function uploadFile({ access, addRandomSuffix, buffer, cacheControlMaxAge, mimeType, storageFilePath, token }) {
|
|
4
|
-
const
|
|
4
|
+
export async function uploadFile({ access, addRandomSuffix, buffer, cacheControlMaxAge, mimeType, storageFilePath, tempFilePath, token }) {
|
|
5
|
+
const body = tempFilePath ? await openAsBlob(tempFilePath) : buffer;
|
|
6
|
+
const result = await put(storageFilePath, body, {
|
|
5
7
|
access,
|
|
6
8
|
addRandomSuffix,
|
|
7
9
|
allowOverwrite: true,
|
package/dist/uploadFile.js.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"sources":["../src/uploadFile.ts"],"sourcesContent":["import { put } from '@vercel/blob'\nimport path from 'path'\n\ninterface UploadFileArgs {\n access: 'public'\n addRandomSuffix?: boolean\n buffer: Buffer\n cacheControlMaxAge?: number\n mimeType: string\n storageFilePath: string\n token: string\n}\n\ninterface UploadFileResult {\n filename?: string\n}\n\nexport async function uploadFile({\n access,\n addRandomSuffix,\n buffer,\n cacheControlMaxAge,\n mimeType,\n storageFilePath,\n token,\n}: UploadFileArgs): Promise<UploadFileResult> {\n const result = await put(storageFilePath,
|
|
1
|
+
{"version":3,"sources":["../src/uploadFile.ts"],"sourcesContent":["import { put } from '@vercel/blob'\nimport { openAsBlob } from 'fs'\nimport path from 'path'\n\ninterface UploadFileArgs {\n access: 'public'\n addRandomSuffix?: boolean\n buffer: Buffer\n cacheControlMaxAge?: number\n mimeType: string\n storageFilePath: string\n tempFilePath?: string\n token: string\n}\n\ninterface UploadFileResult {\n filename?: string\n}\n\nexport async function uploadFile({\n access,\n addRandomSuffix,\n buffer,\n cacheControlMaxAge,\n mimeType,\n storageFilePath,\n tempFilePath,\n token,\n}: UploadFileArgs): Promise<UploadFileResult> {\n const body = tempFilePath ? await openAsBlob(tempFilePath) : buffer\n const result = await put(storageFilePath, body, {\n access,\n addRandomSuffix,\n allowOverwrite: true,\n cacheControlMaxAge,\n contentType: mimeType,\n token,\n })\n\n if (addRandomSuffix) {\n const pathname = result.pathname.replace(/^\\/+/, '')\n const basename = path.posix.basename(pathname)\n return { filename: decodeURIComponent(basename) }\n }\n\n return {}\n}\n"],"names":["put","openAsBlob","path","uploadFile","access","addRandomSuffix","buffer","cacheControlMaxAge","mimeType","storageFilePath","tempFilePath","token","body","result","allowOverwrite","contentType","pathname","replace","basename","posix","filename","decodeURIComponent"],"mappings":"AAAA,SAASA,GAAG,QAAQ,eAAc;AAClC,SAASC,UAAU,QAAQ,KAAI;AAC/B,OAAOC,UAAU,OAAM;AAiBvB,OAAO,eAAeC,WAAW,EAC/BC,MAAM,EACNC,eAAe,EACfC,MAAM,EACNC,kBAAkB,EAClBC,QAAQ,EACRC,eAAe,EACfC,YAAY,EACZC,KAAK,EACU;IACf,MAAMC,OAAOF,eAAe,MAAMT,WAAWS,gBAAgBJ;IAC7D,MAAMO,SAAS,MAAMb,IAAIS,iBAAiBG,MAAM;QAC9CR;QACAC;QACAS,gBAAgB;QAChBP;QACAQ,aAAaP;QACbG;IACF;IAEA,IAAIN,iBAAiB;QACnB,MAAMW,WAAWH,OAAOG,QAAQ,CAACC,OAAO,CAAC,QAAQ;QACjD,MAAMC,WAAWhB,KAAKiB,KAAK,CAACD,QAAQ,CAACF;QACrC,OAAO;YAAEI,UAAUC,mBAAmBH;QAAU;IAClD;IAEA,OAAO,CAAC;AACV"}
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@payloadcms/storage-vercel-blob",
|
|
3
|
-
"version": "3.
|
|
3
|
+
"version": "3.92.1",
|
|
4
4
|
"description": "Payload storage adapter for Vercel Blob Storage",
|
|
5
5
|
"homepage": "https://payloadcms.com",
|
|
6
6
|
"repository": {
|
|
@@ -37,17 +37,17 @@
|
|
|
37
37
|
"dist"
|
|
38
38
|
],
|
|
39
39
|
"dependencies": {
|
|
40
|
-
"@
|
|
41
|
-
"@
|
|
40
|
+
"@payloadcms/plugin-cloud-storage": "3.92.1",
|
|
41
|
+
"@vercel/blob": "2.3.1"
|
|
42
42
|
},
|
|
43
43
|
"devDependencies": {
|
|
44
|
-
"payload": "3.
|
|
44
|
+
"payload": "3.92.1"
|
|
45
45
|
},
|
|
46
46
|
"peerDependencies": {
|
|
47
|
-
"payload": "3.
|
|
47
|
+
"payload": "3.92.1"
|
|
48
48
|
},
|
|
49
49
|
"engines": {
|
|
50
|
-
"node": ">=
|
|
50
|
+
"node": "^22.23.4 || >=24.22.1"
|
|
51
51
|
},
|
|
52
52
|
"scripts": {
|
|
53
53
|
"build": "pnpm build:types && pnpm build:swc",
|