naystack 1.8.10 → 1.8.12
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/file/index.cjs.js +10 -6
- package/dist/file/index.d.mts +1 -1
- package/dist/file/index.d.ts +1 -1
- package/dist/file/index.esm.js +10 -6
- package/dist/file/put.cjs.js +7 -4
- package/dist/file/put.d.mts +3 -1
- package/dist/file/put.d.ts +3 -1
- package/dist/file/put.esm.js +7 -4
- package/dist/file/setup.cjs.js +7 -4
- package/dist/file/setup.d.mts +19 -0
- package/dist/file/setup.d.ts +19 -0
- package/dist/file/setup.esm.js +7 -4
- package/dist/file/utils.cjs.js +6 -4
- package/dist/file/utils.d.mts +19 -3
- package/dist/file/utils.d.ts +19 -3
- package/dist/file/utils.esm.js +6 -4
- package/package.json +1 -1
package/dist/file/index.cjs.js
CHANGED
|
@@ -165,14 +165,15 @@ var getDownloadURL = (keys) => {
|
|
|
165
165
|
};
|
|
166
166
|
var uploadFile = async (keys, {
|
|
167
167
|
url,
|
|
168
|
-
blob
|
|
168
|
+
blob,
|
|
169
|
+
put
|
|
169
170
|
}) => {
|
|
170
171
|
if (!checkClient(client)) return;
|
|
171
172
|
if (!blob && !url) return null;
|
|
172
173
|
const fileBlob = blob || await fetch(url).then((file) => file.blob());
|
|
173
174
|
if (fileBlob) {
|
|
174
175
|
const key = getKey(keys);
|
|
175
|
-
await uploadBlob(fileBlob, key);
|
|
176
|
+
await uploadBlob(fileBlob, key, put);
|
|
176
177
|
return getDownloadURL(key);
|
|
177
178
|
}
|
|
178
179
|
return null;
|
|
@@ -199,7 +200,7 @@ function checkClient(client2) {
|
|
|
199
200
|
if (!client2) throw new Error("Client does not exist");
|
|
200
201
|
return true;
|
|
201
202
|
}
|
|
202
|
-
var uploadBlob = async (file, key) => {
|
|
203
|
+
var uploadBlob = async (file, key, overrides) => {
|
|
203
204
|
if (!checkClient(client)) return;
|
|
204
205
|
const fileBuffer = await file.arrayBuffer();
|
|
205
206
|
return client.send(
|
|
@@ -209,7 +210,8 @@ var uploadBlob = async (file, key) => {
|
|
|
209
210
|
ACL: "public-read",
|
|
210
211
|
Body: Buffer.from(fileBuffer),
|
|
211
212
|
ContentType: file.type,
|
|
212
|
-
ContentLength: file.size
|
|
213
|
+
ContentLength: file.size,
|
|
214
|
+
...overrides
|
|
213
215
|
})
|
|
214
216
|
);
|
|
215
217
|
};
|
|
@@ -231,8 +233,10 @@ var getFileUploadPutRoute = (options) => async (req) => {
|
|
|
231
233
|
};
|
|
232
234
|
const fileKey = options.getKey ? await options.getKey(inputData) : (0, import_uuid.v4)();
|
|
233
235
|
const url = getDownloadURL(fileKey);
|
|
234
|
-
|
|
235
|
-
|
|
236
|
+
const blob = options.processFile ? await options.processFile(file, inputData) : file;
|
|
237
|
+
const put = options.putOptions?.(inputData);
|
|
238
|
+
if (async) (0, import_functions.waitUntil)(uploadBlob(blob, fileKey, put));
|
|
239
|
+
else await uploadBlob(blob, fileKey, put);
|
|
236
240
|
const onUploadResponse = await options.onUpload({
|
|
237
241
|
...inputData,
|
|
238
242
|
url
|
package/dist/file/index.d.mts
CHANGED
|
@@ -1,4 +1,4 @@
|
|
|
1
1
|
export { setupFileUpload } from './setup.mjs';
|
|
2
|
-
export { deleteFile, getDownloadURL, getUploadURL, uploadFile } from './utils.mjs';
|
|
2
|
+
export { PutOverrides, deleteFile, getDownloadURL, getUploadURL, uploadFile } from './utils.mjs';
|
|
3
3
|
import 'next/server';
|
|
4
4
|
import '@aws-sdk/client-s3';
|
package/dist/file/index.d.ts
CHANGED
|
@@ -1,4 +1,4 @@
|
|
|
1
1
|
export { setupFileUpload } from './setup.js';
|
|
2
|
-
export { deleteFile, getDownloadURL, getUploadURL, uploadFile } from './utils.js';
|
|
2
|
+
export { PutOverrides, deleteFile, getDownloadURL, getUploadURL, uploadFile } from './utils.js';
|
|
3
3
|
import 'next/server';
|
|
4
4
|
import '@aws-sdk/client-s3';
|
package/dist/file/index.esm.js
CHANGED
|
@@ -139,14 +139,15 @@ var getDownloadURL = (keys) => {
|
|
|
139
139
|
};
|
|
140
140
|
var uploadFile = async (keys, {
|
|
141
141
|
url,
|
|
142
|
-
blob
|
|
142
|
+
blob,
|
|
143
|
+
put
|
|
143
144
|
}) => {
|
|
144
145
|
if (!checkClient(client)) return;
|
|
145
146
|
if (!blob && !url) return null;
|
|
146
147
|
const fileBlob = blob || await fetch(url).then((file) => file.blob());
|
|
147
148
|
if (fileBlob) {
|
|
148
149
|
const key = getKey(keys);
|
|
149
|
-
await uploadBlob(fileBlob, key);
|
|
150
|
+
await uploadBlob(fileBlob, key, put);
|
|
150
151
|
return getDownloadURL(key);
|
|
151
152
|
}
|
|
152
153
|
return null;
|
|
@@ -173,7 +174,7 @@ function checkClient(client2) {
|
|
|
173
174
|
if (!client2) throw new Error("Client does not exist");
|
|
174
175
|
return true;
|
|
175
176
|
}
|
|
176
|
-
var uploadBlob = async (file, key) => {
|
|
177
|
+
var uploadBlob = async (file, key, overrides) => {
|
|
177
178
|
if (!checkClient(client)) return;
|
|
178
179
|
const fileBuffer = await file.arrayBuffer();
|
|
179
180
|
return client.send(
|
|
@@ -183,7 +184,8 @@ var uploadBlob = async (file, key) => {
|
|
|
183
184
|
ACL: "public-read",
|
|
184
185
|
Body: Buffer.from(fileBuffer),
|
|
185
186
|
ContentType: file.type,
|
|
186
|
-
ContentLength: file.size
|
|
187
|
+
ContentLength: file.size,
|
|
188
|
+
...overrides
|
|
187
189
|
})
|
|
188
190
|
);
|
|
189
191
|
};
|
|
@@ -205,8 +207,10 @@ var getFileUploadPutRoute = (options) => async (req) => {
|
|
|
205
207
|
};
|
|
206
208
|
const fileKey = options.getKey ? await options.getKey(inputData) : v4();
|
|
207
209
|
const url = getDownloadURL(fileKey);
|
|
208
|
-
|
|
209
|
-
|
|
210
|
+
const blob = options.processFile ? await options.processFile(file, inputData) : file;
|
|
211
|
+
const put = options.putOptions?.(inputData);
|
|
212
|
+
if (async) waitUntil(uploadBlob(blob, fileKey, put));
|
|
213
|
+
else await uploadBlob(blob, fileKey, put);
|
|
210
214
|
const onUploadResponse = await options.onUpload({
|
|
211
215
|
...inputData,
|
|
212
216
|
url
|
package/dist/file/put.cjs.js
CHANGED
|
@@ -152,7 +152,7 @@ function checkClient(client2) {
|
|
|
152
152
|
if (!client2) throw new Error("Client does not exist");
|
|
153
153
|
return true;
|
|
154
154
|
}
|
|
155
|
-
var uploadBlob = async (file, key) => {
|
|
155
|
+
var uploadBlob = async (file, key, overrides) => {
|
|
156
156
|
if (!checkClient(client)) return;
|
|
157
157
|
const fileBuffer = await file.arrayBuffer();
|
|
158
158
|
return client.send(
|
|
@@ -162,7 +162,8 @@ var uploadBlob = async (file, key) => {
|
|
|
162
162
|
ACL: "public-read",
|
|
163
163
|
Body: Buffer.from(fileBuffer),
|
|
164
164
|
ContentType: file.type,
|
|
165
|
-
ContentLength: file.size
|
|
165
|
+
ContentLength: file.size,
|
|
166
|
+
...overrides
|
|
166
167
|
})
|
|
167
168
|
);
|
|
168
169
|
};
|
|
@@ -184,8 +185,10 @@ var getFileUploadPutRoute = (options) => async (req) => {
|
|
|
184
185
|
};
|
|
185
186
|
const fileKey = options.getKey ? await options.getKey(inputData) : (0, import_uuid.v4)();
|
|
186
187
|
const url = getDownloadURL(fileKey);
|
|
187
|
-
|
|
188
|
-
|
|
188
|
+
const blob = options.processFile ? await options.processFile(file, inputData) : file;
|
|
189
|
+
const put = options.putOptions?.(inputData);
|
|
190
|
+
if (async) (0, import_functions.waitUntil)(uploadBlob(blob, fileKey, put));
|
|
191
|
+
else await uploadBlob(blob, fileKey, put);
|
|
189
192
|
const onUploadResponse = await options.onUpload({
|
|
190
193
|
...inputData,
|
|
191
194
|
url
|
package/dist/file/put.d.mts
CHANGED
|
@@ -1,5 +1,7 @@
|
|
|
1
1
|
import { NextRequest, NextResponse } from 'next/server';
|
|
2
2
|
import { SetupFileUploadOptions } from './setup.mjs';
|
|
3
|
+
import './utils.mjs';
|
|
4
|
+
import '@aws-sdk/client-s3';
|
|
3
5
|
|
|
4
6
|
/**
|
|
5
7
|
* Returns the PUT route handler for file upload.
|
|
@@ -7,7 +9,7 @@ import { SetupFileUploadOptions } from './setup.mjs';
|
|
|
7
9
|
* Requires authentication (Bearer token, not refresh cookie).
|
|
8
10
|
* Expects multipart form data with fields: `file` (File), `type` (string), and optional `data` (JSON string).
|
|
9
11
|
*
|
|
10
|
-
* @param options - `SetupFileUploadOptions` (getKey, onUpload).
|
|
12
|
+
* @param options - `SetupFileUploadOptions` (getKey, processFile, onUpload).
|
|
11
13
|
* @returns Async Next.js route handler for PUT requests.
|
|
12
14
|
* @category File
|
|
13
15
|
*/
|
package/dist/file/put.d.ts
CHANGED
|
@@ -1,5 +1,7 @@
|
|
|
1
1
|
import { NextRequest, NextResponse } from 'next/server';
|
|
2
2
|
import { SetupFileUploadOptions } from './setup.js';
|
|
3
|
+
import './utils.js';
|
|
4
|
+
import '@aws-sdk/client-s3';
|
|
3
5
|
|
|
4
6
|
/**
|
|
5
7
|
* Returns the PUT route handler for file upload.
|
|
@@ -7,7 +9,7 @@ import { SetupFileUploadOptions } from './setup.js';
|
|
|
7
9
|
* Requires authentication (Bearer token, not refresh cookie).
|
|
8
10
|
* Expects multipart form data with fields: `file` (File), `type` (string), and optional `data` (JSON string).
|
|
9
11
|
*
|
|
10
|
-
* @param options - `SetupFileUploadOptions` (getKey, onUpload).
|
|
12
|
+
* @param options - `SetupFileUploadOptions` (getKey, processFile, onUpload).
|
|
11
13
|
* @returns Async Next.js route handler for PUT requests.
|
|
12
14
|
* @category File
|
|
13
15
|
*/
|
package/dist/file/put.esm.js
CHANGED
|
@@ -132,7 +132,7 @@ function checkClient(client2) {
|
|
|
132
132
|
if (!client2) throw new Error("Client does not exist");
|
|
133
133
|
return true;
|
|
134
134
|
}
|
|
135
|
-
var uploadBlob = async (file, key) => {
|
|
135
|
+
var uploadBlob = async (file, key, overrides) => {
|
|
136
136
|
if (!checkClient(client)) return;
|
|
137
137
|
const fileBuffer = await file.arrayBuffer();
|
|
138
138
|
return client.send(
|
|
@@ -142,7 +142,8 @@ var uploadBlob = async (file, key) => {
|
|
|
142
142
|
ACL: "public-read",
|
|
143
143
|
Body: Buffer.from(fileBuffer),
|
|
144
144
|
ContentType: file.type,
|
|
145
|
-
ContentLength: file.size
|
|
145
|
+
ContentLength: file.size,
|
|
146
|
+
...overrides
|
|
146
147
|
})
|
|
147
148
|
);
|
|
148
149
|
};
|
|
@@ -164,8 +165,10 @@ var getFileUploadPutRoute = (options) => async (req) => {
|
|
|
164
165
|
};
|
|
165
166
|
const fileKey = options.getKey ? await options.getKey(inputData) : v4();
|
|
166
167
|
const url = getDownloadURL(fileKey);
|
|
167
|
-
|
|
168
|
-
|
|
168
|
+
const blob = options.processFile ? await options.processFile(file, inputData) : file;
|
|
169
|
+
const put = options.putOptions?.(inputData);
|
|
170
|
+
if (async) waitUntil(uploadBlob(blob, fileKey, put));
|
|
171
|
+
else await uploadBlob(blob, fileKey, put);
|
|
169
172
|
const onUploadResponse = await options.onUpload({
|
|
170
173
|
...inputData,
|
|
171
174
|
url
|
package/dist/file/setup.cjs.js
CHANGED
|
@@ -154,7 +154,7 @@ function checkClient(client2) {
|
|
|
154
154
|
if (!client2) throw new Error("Client does not exist");
|
|
155
155
|
return true;
|
|
156
156
|
}
|
|
157
|
-
var uploadBlob = async (file, key) => {
|
|
157
|
+
var uploadBlob = async (file, key, overrides) => {
|
|
158
158
|
if (!checkClient(client)) return;
|
|
159
159
|
const fileBuffer = await file.arrayBuffer();
|
|
160
160
|
return client.send(
|
|
@@ -164,7 +164,8 @@ var uploadBlob = async (file, key) => {
|
|
|
164
164
|
ACL: "public-read",
|
|
165
165
|
Body: Buffer.from(fileBuffer),
|
|
166
166
|
ContentType: file.type,
|
|
167
|
-
ContentLength: file.size
|
|
167
|
+
ContentLength: file.size,
|
|
168
|
+
...overrides
|
|
168
169
|
})
|
|
169
170
|
);
|
|
170
171
|
};
|
|
@@ -186,8 +187,10 @@ var getFileUploadPutRoute = (options) => async (req) => {
|
|
|
186
187
|
};
|
|
187
188
|
const fileKey = options.getKey ? await options.getKey(inputData) : (0, import_uuid.v4)();
|
|
188
189
|
const url = getDownloadURL(fileKey);
|
|
189
|
-
|
|
190
|
-
|
|
190
|
+
const blob = options.processFile ? await options.processFile(file, inputData) : file;
|
|
191
|
+
const put = options.putOptions?.(inputData);
|
|
192
|
+
if (async) (0, import_functions.waitUntil)(uploadBlob(blob, fileKey, put));
|
|
193
|
+
else await uploadBlob(blob, fileKey, put);
|
|
191
194
|
const onUploadResponse = await options.onUpload({
|
|
192
195
|
...inputData,
|
|
193
196
|
url
|
package/dist/file/setup.d.mts
CHANGED
|
@@ -1,9 +1,18 @@
|
|
|
1
1
|
import * as next_server from 'next/server';
|
|
2
|
+
import { PutOverrides } from './utils.mjs';
|
|
3
|
+
import '@aws-sdk/client-s3';
|
|
2
4
|
|
|
3
5
|
/**
|
|
4
6
|
* Options for setting up file upload via {@link setupFileUpload}.
|
|
5
7
|
*
|
|
6
8
|
* @property getKey - Optional. Given `{ type, userId, data }`, returns the S3 object key for the upload. If omitted, a UUID is generated.
|
|
9
|
+
* @property processFile - Optional. Given the uploaded `file` and `{ type, userId, data }`, returns the blob to
|
|
10
|
+
* store in its place — e.g. re-encoding an image, or stripping metadata. Runs after authentication and before the
|
|
11
|
+
* S3 write, so only the returned bytes are ever stored. The blob's `type` becomes the object's `Content-Type`,
|
|
12
|
+
* so change it when the format changes. Return the file unchanged to leave it alone. Throwing fails the upload.
|
|
13
|
+
* @property putOptions - Optional. Given `{ type, userId, data }`, returns fields to set on the S3 put —
|
|
14
|
+
* `CacheControl`, `ContentDisposition`, `Metadata` and so on. A function rather than a static object so
|
|
15
|
+
* headers can differ per upload kind. See {@link PutOverrides}.
|
|
7
16
|
* @property onUpload - **Required.** Called after each successful upload with `{ url, type, userId, data }`.
|
|
8
17
|
* The return value is included in the API response as `onUploadResponse` (e.g. save metadata to your database and return it).
|
|
9
18
|
*
|
|
@@ -15,6 +24,16 @@ interface SetupFileUploadOptions {
|
|
|
15
24
|
userId: number;
|
|
16
25
|
data: object;
|
|
17
26
|
}) => Promise<string>;
|
|
27
|
+
processFile?: (file: File, data: {
|
|
28
|
+
type: string;
|
|
29
|
+
userId: number;
|
|
30
|
+
data: object;
|
|
31
|
+
}) => Promise<Blob>;
|
|
32
|
+
putOptions?: (data: {
|
|
33
|
+
type: string;
|
|
34
|
+
userId: number;
|
|
35
|
+
data: object;
|
|
36
|
+
}) => PutOverrides;
|
|
18
37
|
onUpload: (data: {
|
|
19
38
|
url: string | null;
|
|
20
39
|
type: string;
|
package/dist/file/setup.d.ts
CHANGED
|
@@ -1,9 +1,18 @@
|
|
|
1
1
|
import * as next_server from 'next/server';
|
|
2
|
+
import { PutOverrides } from './utils.js';
|
|
3
|
+
import '@aws-sdk/client-s3';
|
|
2
4
|
|
|
3
5
|
/**
|
|
4
6
|
* Options for setting up file upload via {@link setupFileUpload}.
|
|
5
7
|
*
|
|
6
8
|
* @property getKey - Optional. Given `{ type, userId, data }`, returns the S3 object key for the upload. If omitted, a UUID is generated.
|
|
9
|
+
* @property processFile - Optional. Given the uploaded `file` and `{ type, userId, data }`, returns the blob to
|
|
10
|
+
* store in its place — e.g. re-encoding an image, or stripping metadata. Runs after authentication and before the
|
|
11
|
+
* S3 write, so only the returned bytes are ever stored. The blob's `type` becomes the object's `Content-Type`,
|
|
12
|
+
* so change it when the format changes. Return the file unchanged to leave it alone. Throwing fails the upload.
|
|
13
|
+
* @property putOptions - Optional. Given `{ type, userId, data }`, returns fields to set on the S3 put —
|
|
14
|
+
* `CacheControl`, `ContentDisposition`, `Metadata` and so on. A function rather than a static object so
|
|
15
|
+
* headers can differ per upload kind. See {@link PutOverrides}.
|
|
7
16
|
* @property onUpload - **Required.** Called after each successful upload with `{ url, type, userId, data }`.
|
|
8
17
|
* The return value is included in the API response as `onUploadResponse` (e.g. save metadata to your database and return it).
|
|
9
18
|
*
|
|
@@ -15,6 +24,16 @@ interface SetupFileUploadOptions {
|
|
|
15
24
|
userId: number;
|
|
16
25
|
data: object;
|
|
17
26
|
}) => Promise<string>;
|
|
27
|
+
processFile?: (file: File, data: {
|
|
28
|
+
type: string;
|
|
29
|
+
userId: number;
|
|
30
|
+
data: object;
|
|
31
|
+
}) => Promise<Blob>;
|
|
32
|
+
putOptions?: (data: {
|
|
33
|
+
type: string;
|
|
34
|
+
userId: number;
|
|
35
|
+
data: object;
|
|
36
|
+
}) => PutOverrides;
|
|
18
37
|
onUpload: (data: {
|
|
19
38
|
url: string | null;
|
|
20
39
|
type: string;
|
package/dist/file/setup.esm.js
CHANGED
|
@@ -132,7 +132,7 @@ function checkClient(client2) {
|
|
|
132
132
|
if (!client2) throw new Error("Client does not exist");
|
|
133
133
|
return true;
|
|
134
134
|
}
|
|
135
|
-
var uploadBlob = async (file, key) => {
|
|
135
|
+
var uploadBlob = async (file, key, overrides) => {
|
|
136
136
|
if (!checkClient(client)) return;
|
|
137
137
|
const fileBuffer = await file.arrayBuffer();
|
|
138
138
|
return client.send(
|
|
@@ -142,7 +142,8 @@ var uploadBlob = async (file, key) => {
|
|
|
142
142
|
ACL: "public-read",
|
|
143
143
|
Body: Buffer.from(fileBuffer),
|
|
144
144
|
ContentType: file.type,
|
|
145
|
-
ContentLength: file.size
|
|
145
|
+
ContentLength: file.size,
|
|
146
|
+
...overrides
|
|
146
147
|
})
|
|
147
148
|
);
|
|
148
149
|
};
|
|
@@ -164,8 +165,10 @@ var getFileUploadPutRoute = (options) => async (req) => {
|
|
|
164
165
|
};
|
|
165
166
|
const fileKey = options.getKey ? await options.getKey(inputData) : v4();
|
|
166
167
|
const url = getDownloadURL(fileKey);
|
|
167
|
-
|
|
168
|
-
|
|
168
|
+
const blob = options.processFile ? await options.processFile(file, inputData) : file;
|
|
169
|
+
const put = options.putOptions?.(inputData);
|
|
170
|
+
if (async) waitUntil(uploadBlob(blob, fileKey, put));
|
|
171
|
+
else await uploadBlob(blob, fileKey, put);
|
|
169
172
|
const onUploadResponse = await options.onUpload({
|
|
170
173
|
...inputData,
|
|
171
174
|
url
|
package/dist/file/utils.cjs.js
CHANGED
|
@@ -107,14 +107,15 @@ var getDownloadURL = (keys) => {
|
|
|
107
107
|
};
|
|
108
108
|
var uploadFile = async (keys, {
|
|
109
109
|
url,
|
|
110
|
-
blob
|
|
110
|
+
blob,
|
|
111
|
+
put
|
|
111
112
|
}) => {
|
|
112
113
|
if (!checkClient(client)) return;
|
|
113
114
|
if (!blob && !url) return null;
|
|
114
115
|
const fileBlob = blob || await fetch(url).then((file) => file.blob());
|
|
115
116
|
if (fileBlob) {
|
|
116
117
|
const key = getKey(keys);
|
|
117
|
-
await uploadBlob(fileBlob, key);
|
|
118
|
+
await uploadBlob(fileBlob, key, put);
|
|
118
119
|
return getDownloadURL(key);
|
|
119
120
|
}
|
|
120
121
|
return null;
|
|
@@ -141,7 +142,7 @@ function checkClient(client2) {
|
|
|
141
142
|
if (!client2) throw new Error("Client does not exist");
|
|
142
143
|
return true;
|
|
143
144
|
}
|
|
144
|
-
var uploadBlob = async (file, key) => {
|
|
145
|
+
var uploadBlob = async (file, key, overrides) => {
|
|
145
146
|
if (!checkClient(client)) return;
|
|
146
147
|
const fileBuffer = await file.arrayBuffer();
|
|
147
148
|
return client.send(
|
|
@@ -151,7 +152,8 @@ var uploadBlob = async (file, key) => {
|
|
|
151
152
|
ACL: "public-read",
|
|
152
153
|
Body: Buffer.from(fileBuffer),
|
|
153
154
|
ContentType: file.type,
|
|
154
|
-
ContentLength: file.size
|
|
155
|
+
ContentLength: file.size,
|
|
156
|
+
...overrides
|
|
155
157
|
})
|
|
156
158
|
);
|
|
157
159
|
};
|
package/dist/file/utils.d.mts
CHANGED
|
@@ -1,5 +1,18 @@
|
|
|
1
1
|
import * as _aws_sdk_client_s3 from '@aws-sdk/client-s3';
|
|
2
|
+
import { PutObjectCommandInput } from '@aws-sdk/client-s3';
|
|
2
3
|
|
|
4
|
+
/**
|
|
5
|
+
* Fields a caller may set on the underlying S3 put — `CacheControl`,
|
|
6
|
+
* `ContentDisposition`, `Metadata`, `StorageClass`, and so on. Spread over the
|
|
7
|
+
* defaults, so anything given here wins.
|
|
8
|
+
*
|
|
9
|
+
* What identifies the upload — `Bucket`, `Key`, `Body` — is deliberately not
|
|
10
|
+
* overridable: those are naystack's to set, and replacing them would silently
|
|
11
|
+
* write the wrong bytes or the wrong object rather than fail.
|
|
12
|
+
*
|
|
13
|
+
* @category File
|
|
14
|
+
*/
|
|
15
|
+
type PutOverrides = Omit<PutObjectCommandInput, "Bucket" | "Key" | "Body">;
|
|
3
16
|
/**
|
|
4
17
|
* Generates a presigned PUT URL for uploading a file to the given S3 key(s).
|
|
5
18
|
* The URL expires after 5 minutes.
|
|
@@ -23,12 +36,14 @@ declare const getDownloadURL: (keys: string | string[]) => string;
|
|
|
23
36
|
* @param keys - S3 key or key path segments (array joined by `/`).
|
|
24
37
|
* @param options.blob - A Blob/File to upload directly.
|
|
25
38
|
* @param options.url - A remote URL to fetch and upload. Ignored if `blob` is provided.
|
|
39
|
+
* @param options.put - Fields to set on the S3 put. See {@link PutOverrides}.
|
|
26
40
|
* @returns The public download URL of the uploaded file, or `null` if neither `blob` nor `url` was provided.
|
|
27
41
|
* @category File
|
|
28
42
|
*/
|
|
29
|
-
declare const uploadFile: (keys: string | string[], { url, blob, }: {
|
|
43
|
+
declare const uploadFile: (keys: string | string[], { url, blob, put, }: {
|
|
30
44
|
blob?: Blob;
|
|
31
45
|
url?: string;
|
|
46
|
+
put?: PutOverrides;
|
|
32
47
|
}) => Promise<string | null | undefined>;
|
|
33
48
|
/**
|
|
34
49
|
* Deletes an S3 object identified by its full public URL.
|
|
@@ -43,9 +58,10 @@ declare const deleteFile: (url: string) => Promise<boolean | undefined>;
|
|
|
43
58
|
*
|
|
44
59
|
* @param file - The Blob or File to upload.
|
|
45
60
|
* @param key - The S3 object key.
|
|
61
|
+
* @param overrides - Fields to set on the put, spread over the defaults below. See {@link PutOverrides}.
|
|
46
62
|
* @returns The `PutObjectCommandOutput` from S3.
|
|
47
63
|
* @category File
|
|
48
64
|
*/
|
|
49
|
-
declare const uploadBlob: (file: File | Blob, key: string) => Promise<_aws_sdk_client_s3.PutObjectCommandOutput | undefined>;
|
|
65
|
+
declare const uploadBlob: (file: File | Blob, key: string, overrides?: PutOverrides) => Promise<_aws_sdk_client_s3.PutObjectCommandOutput | undefined>;
|
|
50
66
|
|
|
51
|
-
export { deleteFile, getDownloadURL, getUploadURL, uploadBlob, uploadFile };
|
|
67
|
+
export { type PutOverrides, deleteFile, getDownloadURL, getUploadURL, uploadBlob, uploadFile };
|
package/dist/file/utils.d.ts
CHANGED
|
@@ -1,5 +1,18 @@
|
|
|
1
1
|
import * as _aws_sdk_client_s3 from '@aws-sdk/client-s3';
|
|
2
|
+
import { PutObjectCommandInput } from '@aws-sdk/client-s3';
|
|
2
3
|
|
|
4
|
+
/**
|
|
5
|
+
* Fields a caller may set on the underlying S3 put — `CacheControl`,
|
|
6
|
+
* `ContentDisposition`, `Metadata`, `StorageClass`, and so on. Spread over the
|
|
7
|
+
* defaults, so anything given here wins.
|
|
8
|
+
*
|
|
9
|
+
* What identifies the upload — `Bucket`, `Key`, `Body` — is deliberately not
|
|
10
|
+
* overridable: those are naystack's to set, and replacing them would silently
|
|
11
|
+
* write the wrong bytes or the wrong object rather than fail.
|
|
12
|
+
*
|
|
13
|
+
* @category File
|
|
14
|
+
*/
|
|
15
|
+
type PutOverrides = Omit<PutObjectCommandInput, "Bucket" | "Key" | "Body">;
|
|
3
16
|
/**
|
|
4
17
|
* Generates a presigned PUT URL for uploading a file to the given S3 key(s).
|
|
5
18
|
* The URL expires after 5 minutes.
|
|
@@ -23,12 +36,14 @@ declare const getDownloadURL: (keys: string | string[]) => string;
|
|
|
23
36
|
* @param keys - S3 key or key path segments (array joined by `/`).
|
|
24
37
|
* @param options.blob - A Blob/File to upload directly.
|
|
25
38
|
* @param options.url - A remote URL to fetch and upload. Ignored if `blob` is provided.
|
|
39
|
+
* @param options.put - Fields to set on the S3 put. See {@link PutOverrides}.
|
|
26
40
|
* @returns The public download URL of the uploaded file, or `null` if neither `blob` nor `url` was provided.
|
|
27
41
|
* @category File
|
|
28
42
|
*/
|
|
29
|
-
declare const uploadFile: (keys: string | string[], { url, blob, }: {
|
|
43
|
+
declare const uploadFile: (keys: string | string[], { url, blob, put, }: {
|
|
30
44
|
blob?: Blob;
|
|
31
45
|
url?: string;
|
|
46
|
+
put?: PutOverrides;
|
|
32
47
|
}) => Promise<string | null | undefined>;
|
|
33
48
|
/**
|
|
34
49
|
* Deletes an S3 object identified by its full public URL.
|
|
@@ -43,9 +58,10 @@ declare const deleteFile: (url: string) => Promise<boolean | undefined>;
|
|
|
43
58
|
*
|
|
44
59
|
* @param file - The Blob or File to upload.
|
|
45
60
|
* @param key - The S3 object key.
|
|
61
|
+
* @param overrides - Fields to set on the put, spread over the defaults below. See {@link PutOverrides}.
|
|
46
62
|
* @returns The `PutObjectCommandOutput` from S3.
|
|
47
63
|
* @category File
|
|
48
64
|
*/
|
|
49
|
-
declare const uploadBlob: (file: File | Blob, key: string) => Promise<_aws_sdk_client_s3.PutObjectCommandOutput | undefined>;
|
|
65
|
+
declare const uploadBlob: (file: File | Blob, key: string, overrides?: PutOverrides) => Promise<_aws_sdk_client_s3.PutObjectCommandOutput | undefined>;
|
|
50
66
|
|
|
51
|
-
export { deleteFile, getDownloadURL, getUploadURL, uploadBlob, uploadFile };
|
|
67
|
+
export { type PutOverrides, deleteFile, getDownloadURL, getUploadURL, uploadBlob, uploadFile };
|
package/dist/file/utils.esm.js
CHANGED
|
@@ -83,14 +83,15 @@ var getDownloadURL = (keys) => {
|
|
|
83
83
|
};
|
|
84
84
|
var uploadFile = async (keys, {
|
|
85
85
|
url,
|
|
86
|
-
blob
|
|
86
|
+
blob,
|
|
87
|
+
put
|
|
87
88
|
}) => {
|
|
88
89
|
if (!checkClient(client)) return;
|
|
89
90
|
if (!blob && !url) return null;
|
|
90
91
|
const fileBlob = blob || await fetch(url).then((file) => file.blob());
|
|
91
92
|
if (fileBlob) {
|
|
92
93
|
const key = getKey(keys);
|
|
93
|
-
await uploadBlob(fileBlob, key);
|
|
94
|
+
await uploadBlob(fileBlob, key, put);
|
|
94
95
|
return getDownloadURL(key);
|
|
95
96
|
}
|
|
96
97
|
return null;
|
|
@@ -117,7 +118,7 @@ function checkClient(client2) {
|
|
|
117
118
|
if (!client2) throw new Error("Client does not exist");
|
|
118
119
|
return true;
|
|
119
120
|
}
|
|
120
|
-
var uploadBlob = async (file, key) => {
|
|
121
|
+
var uploadBlob = async (file, key, overrides) => {
|
|
121
122
|
if (!checkClient(client)) return;
|
|
122
123
|
const fileBuffer = await file.arrayBuffer();
|
|
123
124
|
return client.send(
|
|
@@ -127,7 +128,8 @@ var uploadBlob = async (file, key) => {
|
|
|
127
128
|
ACL: "public-read",
|
|
128
129
|
Body: Buffer.from(fileBuffer),
|
|
129
130
|
ContentType: file.type,
|
|
130
|
-
ContentLength: file.size
|
|
131
|
+
ContentLength: file.size,
|
|
132
|
+
...overrides
|
|
131
133
|
})
|
|
132
134
|
);
|
|
133
135
|
};
|