naystack 1.8.10 → 1.8.11
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 +3 -2
- package/dist/file/index.esm.js +3 -2
- package/dist/file/put.cjs.js +3 -2
- package/dist/file/put.d.mts +1 -1
- package/dist/file/put.d.ts +1 -1
- package/dist/file/put.esm.js +3 -2
- package/dist/file/setup.cjs.js +3 -2
- package/dist/file/setup.d.mts +9 -0
- package/dist/file/setup.d.ts +9 -0
- package/dist/file/setup.esm.js +3 -2
- package/package.json +1 -1
package/dist/file/index.cjs.js
CHANGED
|
@@ -231,8 +231,9 @@ var getFileUploadPutRoute = (options) => async (req) => {
|
|
|
231
231
|
};
|
|
232
232
|
const fileKey = options.getKey ? await options.getKey(inputData) : (0, import_uuid.v4)();
|
|
233
233
|
const url = getDownloadURL(fileKey);
|
|
234
|
-
|
|
235
|
-
|
|
234
|
+
const blob = options.processFile ? await options.processFile(file, inputData) : file;
|
|
235
|
+
if (async) (0, import_functions.waitUntil)(uploadBlob(blob, fileKey));
|
|
236
|
+
else await uploadBlob(blob, fileKey);
|
|
236
237
|
const onUploadResponse = await options.onUpload({
|
|
237
238
|
...inputData,
|
|
238
239
|
url
|
package/dist/file/index.esm.js
CHANGED
|
@@ -205,8 +205,9 @@ var getFileUploadPutRoute = (options) => async (req) => {
|
|
|
205
205
|
};
|
|
206
206
|
const fileKey = options.getKey ? await options.getKey(inputData) : v4();
|
|
207
207
|
const url = getDownloadURL(fileKey);
|
|
208
|
-
|
|
209
|
-
|
|
208
|
+
const blob = options.processFile ? await options.processFile(file, inputData) : file;
|
|
209
|
+
if (async) waitUntil(uploadBlob(blob, fileKey));
|
|
210
|
+
else await uploadBlob(blob, fileKey);
|
|
210
211
|
const onUploadResponse = await options.onUpload({
|
|
211
212
|
...inputData,
|
|
212
213
|
url
|
package/dist/file/put.cjs.js
CHANGED
|
@@ -184,8 +184,9 @@ var getFileUploadPutRoute = (options) => async (req) => {
|
|
|
184
184
|
};
|
|
185
185
|
const fileKey = options.getKey ? await options.getKey(inputData) : (0, import_uuid.v4)();
|
|
186
186
|
const url = getDownloadURL(fileKey);
|
|
187
|
-
|
|
188
|
-
|
|
187
|
+
const blob = options.processFile ? await options.processFile(file, inputData) : file;
|
|
188
|
+
if (async) (0, import_functions.waitUntil)(uploadBlob(blob, fileKey));
|
|
189
|
+
else await uploadBlob(blob, fileKey);
|
|
189
190
|
const onUploadResponse = await options.onUpload({
|
|
190
191
|
...inputData,
|
|
191
192
|
url
|
package/dist/file/put.d.mts
CHANGED
|
@@ -7,7 +7,7 @@ import { SetupFileUploadOptions } from './setup.mjs';
|
|
|
7
7
|
* Requires authentication (Bearer token, not refresh cookie).
|
|
8
8
|
* Expects multipart form data with fields: `file` (File), `type` (string), and optional `data` (JSON string).
|
|
9
9
|
*
|
|
10
|
-
* @param options - `SetupFileUploadOptions` (getKey, onUpload).
|
|
10
|
+
* @param options - `SetupFileUploadOptions` (getKey, processFile, onUpload).
|
|
11
11
|
* @returns Async Next.js route handler for PUT requests.
|
|
12
12
|
* @category File
|
|
13
13
|
*/
|
package/dist/file/put.d.ts
CHANGED
|
@@ -7,7 +7,7 @@ import { SetupFileUploadOptions } from './setup.js';
|
|
|
7
7
|
* Requires authentication (Bearer token, not refresh cookie).
|
|
8
8
|
* Expects multipart form data with fields: `file` (File), `type` (string), and optional `data` (JSON string).
|
|
9
9
|
*
|
|
10
|
-
* @param options - `SetupFileUploadOptions` (getKey, onUpload).
|
|
10
|
+
* @param options - `SetupFileUploadOptions` (getKey, processFile, onUpload).
|
|
11
11
|
* @returns Async Next.js route handler for PUT requests.
|
|
12
12
|
* @category File
|
|
13
13
|
*/
|
package/dist/file/put.esm.js
CHANGED
|
@@ -164,8 +164,9 @@ var getFileUploadPutRoute = (options) => async (req) => {
|
|
|
164
164
|
};
|
|
165
165
|
const fileKey = options.getKey ? await options.getKey(inputData) : v4();
|
|
166
166
|
const url = getDownloadURL(fileKey);
|
|
167
|
-
|
|
168
|
-
|
|
167
|
+
const blob = options.processFile ? await options.processFile(file, inputData) : file;
|
|
168
|
+
if (async) waitUntil(uploadBlob(blob, fileKey));
|
|
169
|
+
else await uploadBlob(blob, fileKey);
|
|
169
170
|
const onUploadResponse = await options.onUpload({
|
|
170
171
|
...inputData,
|
|
171
172
|
url
|
package/dist/file/setup.cjs.js
CHANGED
|
@@ -186,8 +186,9 @@ var getFileUploadPutRoute = (options) => async (req) => {
|
|
|
186
186
|
};
|
|
187
187
|
const fileKey = options.getKey ? await options.getKey(inputData) : (0, import_uuid.v4)();
|
|
188
188
|
const url = getDownloadURL(fileKey);
|
|
189
|
-
|
|
190
|
-
|
|
189
|
+
const blob = options.processFile ? await options.processFile(file, inputData) : file;
|
|
190
|
+
if (async) (0, import_functions.waitUntil)(uploadBlob(blob, fileKey));
|
|
191
|
+
else await uploadBlob(blob, fileKey);
|
|
191
192
|
const onUploadResponse = await options.onUpload({
|
|
192
193
|
...inputData,
|
|
193
194
|
url
|
package/dist/file/setup.d.mts
CHANGED
|
@@ -4,6 +4,10 @@ import * as next_server from 'next/server';
|
|
|
4
4
|
* Options for setting up file upload via {@link setupFileUpload}.
|
|
5
5
|
*
|
|
6
6
|
* @property getKey - Optional. Given `{ type, userId, data }`, returns the S3 object key for the upload. If omitted, a UUID is generated.
|
|
7
|
+
* @property processFile - Optional. Given the uploaded `file` and `{ type, userId, data }`, returns the blob to
|
|
8
|
+
* store in its place — e.g. re-encoding an image, or stripping metadata. Runs after authentication and before the
|
|
9
|
+
* S3 write, so only the returned bytes are ever stored. The blob's `type` becomes the object's `Content-Type`,
|
|
10
|
+
* so change it when the format changes. Return the file unchanged to leave it alone. Throwing fails the upload.
|
|
7
11
|
* @property onUpload - **Required.** Called after each successful upload with `{ url, type, userId, data }`.
|
|
8
12
|
* The return value is included in the API response as `onUploadResponse` (e.g. save metadata to your database and return it).
|
|
9
13
|
*
|
|
@@ -15,6 +19,11 @@ interface SetupFileUploadOptions {
|
|
|
15
19
|
userId: number;
|
|
16
20
|
data: object;
|
|
17
21
|
}) => Promise<string>;
|
|
22
|
+
processFile?: (file: File, data: {
|
|
23
|
+
type: string;
|
|
24
|
+
userId: number;
|
|
25
|
+
data: object;
|
|
26
|
+
}) => Promise<Blob>;
|
|
18
27
|
onUpload: (data: {
|
|
19
28
|
url: string | null;
|
|
20
29
|
type: string;
|
package/dist/file/setup.d.ts
CHANGED
|
@@ -4,6 +4,10 @@ import * as next_server from 'next/server';
|
|
|
4
4
|
* Options for setting up file upload via {@link setupFileUpload}.
|
|
5
5
|
*
|
|
6
6
|
* @property getKey - Optional. Given `{ type, userId, data }`, returns the S3 object key for the upload. If omitted, a UUID is generated.
|
|
7
|
+
* @property processFile - Optional. Given the uploaded `file` and `{ type, userId, data }`, returns the blob to
|
|
8
|
+
* store in its place — e.g. re-encoding an image, or stripping metadata. Runs after authentication and before the
|
|
9
|
+
* S3 write, so only the returned bytes are ever stored. The blob's `type` becomes the object's `Content-Type`,
|
|
10
|
+
* so change it when the format changes. Return the file unchanged to leave it alone. Throwing fails the upload.
|
|
7
11
|
* @property onUpload - **Required.** Called after each successful upload with `{ url, type, userId, data }`.
|
|
8
12
|
* The return value is included in the API response as `onUploadResponse` (e.g. save metadata to your database and return it).
|
|
9
13
|
*
|
|
@@ -15,6 +19,11 @@ interface SetupFileUploadOptions {
|
|
|
15
19
|
userId: number;
|
|
16
20
|
data: object;
|
|
17
21
|
}) => Promise<string>;
|
|
22
|
+
processFile?: (file: File, data: {
|
|
23
|
+
type: string;
|
|
24
|
+
userId: number;
|
|
25
|
+
data: object;
|
|
26
|
+
}) => Promise<Blob>;
|
|
18
27
|
onUpload: (data: {
|
|
19
28
|
url: string | null;
|
|
20
29
|
type: string;
|
package/dist/file/setup.esm.js
CHANGED
|
@@ -164,8 +164,9 @@ var getFileUploadPutRoute = (options) => async (req) => {
|
|
|
164
164
|
};
|
|
165
165
|
const fileKey = options.getKey ? await options.getKey(inputData) : v4();
|
|
166
166
|
const url = getDownloadURL(fileKey);
|
|
167
|
-
|
|
168
|
-
|
|
167
|
+
const blob = options.processFile ? await options.processFile(file, inputData) : file;
|
|
168
|
+
if (async) waitUntil(uploadBlob(blob, fileKey));
|
|
169
|
+
else await uploadBlob(blob, fileKey);
|
|
169
170
|
const onUploadResponse = await options.onUpload({
|
|
170
171
|
...inputData,
|
|
171
172
|
url
|