@payloadcms/next 3.0.0-beta.7 → 3.0.0-canary.6041f49
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/cjs/withPayload.cjs +2 -1
- package/dist/cjs/withPayload.cjs.map +1 -1
- package/dist/exports/routes.d.ts +1 -1
- package/dist/exports/routes.d.ts.map +1 -1
- package/dist/exports/routes.js +1 -1
- package/dist/exports/routes.js.map +1 -1
- package/dist/exports/utilities.d.ts +7 -1
- package/dist/exports/utilities.d.ts.map +1 -1
- package/dist/exports/utilities.js +7 -1
- package/dist/exports/utilities.js.map +1 -1
- package/dist/{next-fileupload → fetchAPI-multipart}/fileFactory.d.ts +2 -2
- package/dist/fetchAPI-multipart/fileFactory.d.ts.map +1 -0
- package/dist/fetchAPI-multipart/fileFactory.js.map +1 -0
- package/dist/{next-fileupload → fetchAPI-multipart}/handlers.d.ts +2 -2
- package/dist/fetchAPI-multipart/handlers.d.ts.map +1 -0
- package/dist/fetchAPI-multipart/handlers.js.map +1 -0
- package/dist/{next-fileupload → fetchAPI-multipart}/index.d.ts +8 -8
- package/dist/fetchAPI-multipart/index.d.ts.map +1 -0
- package/dist/{next-fileupload → fetchAPI-multipart}/index.js +1 -1
- package/dist/fetchAPI-multipart/index.js.map +1 -0
- package/dist/fetchAPI-multipart/isEligibleRequest.d.ts.map +1 -0
- package/dist/{next-fileupload → fetchAPI-multipart}/isEligibleRequest.js +1 -1
- package/dist/fetchAPI-multipart/isEligibleRequest.js.map +1 -0
- package/dist/fetchAPI-multipart/processMultipart.d.ts +8 -0
- package/dist/fetchAPI-multipart/processMultipart.d.ts.map +1 -0
- package/dist/{next-fileupload → fetchAPI-multipart}/processMultipart.js +29 -6
- package/dist/fetchAPI-multipart/processMultipart.js.map +1 -0
- package/dist/fetchAPI-multipart/processNested.d.ts.map +1 -0
- package/dist/{next-fileupload → fetchAPI-multipart}/processNested.js +2 -1
- package/dist/fetchAPI-multipart/processNested.js.map +1 -0
- package/dist/fetchAPI-multipart/uploadTimer.d.ts.map +1 -0
- package/dist/fetchAPI-multipart/uploadTimer.js.map +1 -0
- package/dist/{next-fileupload → fetchAPI-multipart}/utilities.d.ts +4 -4
- package/dist/fetchAPI-multipart/utilities.d.ts.map +1 -0
- package/dist/{next-fileupload → fetchAPI-multipart}/utilities.js +4 -4
- package/dist/fetchAPI-multipart/utilities.js.map +1 -0
- package/dist/fetchAPI-stream-file/index.d.ts.map +1 -0
- package/dist/fetchAPI-stream-file/index.js.map +1 -0
- package/dist/prod/styles.css +1 -1
- package/dist/routes/graphql/handler.d.ts.map +1 -1
- package/dist/routes/graphql/handler.js +22 -10
- package/dist/routes/graphql/handler.js.map +1 -1
- package/dist/routes/index.d.ts +1 -1
- package/dist/routes/index.d.ts.map +1 -1
- package/dist/routes/index.js +1 -1
- package/dist/routes/index.js.map +1 -1
- package/dist/routes/rest/auth/access.d.ts.map +1 -1
- package/dist/routes/rest/auth/access.js +5 -0
- package/dist/routes/rest/auth/access.js.map +1 -1
- package/dist/routes/rest/auth/forgotPassword.d.ts.map +1 -1
- package/dist/routes/rest/auth/forgotPassword.js +7 -2
- package/dist/routes/rest/auth/forgotPassword.js.map +1 -1
- package/dist/routes/rest/auth/init.d.ts.map +1 -1
- package/dist/routes/rest/auth/init.js +6 -0
- package/dist/routes/rest/auth/init.js.map +1 -1
- package/dist/routes/rest/auth/login.d.ts.map +1 -1
- package/dist/routes/rest/auth/login.js +8 -5
- package/dist/routes/rest/auth/login.js.map +1 -1
- package/dist/routes/rest/auth/logout.d.ts.map +1 -1
- package/dist/routes/rest/auth/logout.js +11 -6
- package/dist/routes/rest/auth/logout.js.map +1 -1
- package/dist/routes/rest/auth/me.d.ts.map +1 -1
- package/dist/routes/rest/auth/me.js +5 -0
- package/dist/routes/rest/auth/me.js.map +1 -1
- package/dist/routes/rest/auth/refresh.d.ts.map +1 -1
- package/dist/routes/rest/auth/refresh.js +11 -7
- package/dist/routes/rest/auth/refresh.js.map +1 -1
- package/dist/routes/rest/auth/registerFirstUser.d.ts.map +1 -1
- package/dist/routes/rest/auth/registerFirstUser.js +8 -5
- package/dist/routes/rest/auth/registerFirstUser.js.map +1 -1
- package/dist/routes/rest/auth/resetPassword.d.ts.map +1 -1
- package/dist/routes/rest/auth/resetPassword.js +8 -5
- package/dist/routes/rest/auth/resetPassword.js.map +1 -1
- package/dist/routes/rest/auth/unlock.d.ts.map +1 -1
- package/dist/routes/rest/auth/unlock.js +7 -2
- package/dist/routes/rest/auth/unlock.js.map +1 -1
- package/dist/routes/rest/auth/verifyEmail.d.ts.map +1 -1
- package/dist/routes/rest/auth/verifyEmail.js +7 -2
- package/dist/routes/rest/auth/verifyEmail.js.map +1 -1
- package/dist/routes/rest/buildFormState.d.ts +3 -3
- package/dist/routes/rest/buildFormState.d.ts.map +1 -1
- package/dist/routes/rest/buildFormState.js +41 -6
- package/dist/routes/rest/buildFormState.js.map +1 -1
- package/dist/routes/rest/collections/count.d.ts +3 -0
- package/dist/routes/rest/collections/count.d.ts.map +1 -0
- package/dist/routes/rest/collections/count.js +15 -0
- package/dist/routes/rest/collections/count.js.map +1 -0
- package/dist/routes/rest/collections/create.d.ts.map +1 -1
- package/dist/routes/rest/collections/create.js +5 -0
- package/dist/routes/rest/collections/create.js.map +1 -1
- package/dist/routes/rest/collections/delete.d.ts.map +1 -1
- package/dist/routes/rest/collections/delete.js +7 -0
- package/dist/routes/rest/collections/delete.js.map +1 -1
- package/dist/routes/rest/collections/deleteByID.d.ts.map +1 -1
- package/dist/routes/rest/collections/deleteByID.js +7 -0
- package/dist/routes/rest/collections/deleteByID.js.map +1 -1
- package/dist/routes/rest/collections/docAccess.d.ts.map +1 -1
- package/dist/routes/rest/collections/docAccess.js +5 -0
- package/dist/routes/rest/collections/docAccess.js.map +1 -1
- package/dist/routes/rest/collections/duplicate.d.ts.map +1 -1
- package/dist/routes/rest/collections/duplicate.js +5 -0
- package/dist/routes/rest/collections/duplicate.js.map +1 -1
- package/dist/routes/rest/collections/find.d.ts.map +1 -1
- package/dist/routes/rest/collections/find.js +5 -0
- package/dist/routes/rest/collections/find.js.map +1 -1
- package/dist/routes/rest/collections/findByID.d.ts.map +1 -1
- package/dist/routes/rest/collections/findByID.js +5 -0
- package/dist/routes/rest/collections/findByID.js.map +1 -1
- package/dist/routes/rest/collections/findVersionByID.d.ts.map +1 -1
- package/dist/routes/rest/collections/findVersionByID.js +5 -0
- package/dist/routes/rest/collections/findVersionByID.js.map +1 -1
- package/dist/routes/rest/collections/findVersions.d.ts.map +1 -1
- package/dist/routes/rest/collections/findVersions.js +5 -0
- package/dist/routes/rest/collections/findVersions.js.map +1 -1
- package/dist/routes/rest/collections/preview.d.ts.map +1 -1
- package/dist/routes/rest/collections/preview.js +7 -1
- package/dist/routes/rest/collections/preview.js.map +1 -1
- package/dist/routes/rest/collections/restoreVersion.d.ts.map +1 -1
- package/dist/routes/rest/collections/restoreVersion.js +5 -0
- package/dist/routes/rest/collections/restoreVersion.js.map +1 -1
- package/dist/routes/rest/collections/update.d.ts.map +1 -1
- package/dist/routes/rest/collections/update.js +7 -0
- package/dist/routes/rest/collections/update.js.map +1 -1
- package/dist/routes/rest/collections/updateByID.d.ts.map +1 -1
- package/dist/routes/rest/collections/updateByID.js +5 -0
- package/dist/routes/rest/collections/updateByID.js.map +1 -1
- package/dist/routes/rest/files/checkFileAccess.d.ts +3 -3
- package/dist/routes/rest/files/checkFileAccess.d.ts.map +1 -1
- package/dist/routes/rest/files/checkFileAccess.js +1 -0
- package/dist/routes/rest/files/checkFileAccess.js.map +1 -1
- package/dist/routes/rest/files/getFile.d.ts +2 -2
- package/dist/routes/rest/files/getFile.d.ts.map +1 -1
- package/dist/routes/rest/files/getFile.js +19 -10
- package/dist/routes/rest/files/getFile.js.map +1 -1
- package/dist/routes/rest/files/getFileTypeFallback.d.ts +7 -0
- package/dist/routes/rest/files/getFileTypeFallback.d.ts.map +1 -0
- package/dist/routes/rest/files/getFileTypeFallback.js +21 -0
- package/dist/routes/rest/files/getFileTypeFallback.js.map +1 -0
- package/dist/routes/rest/globals/docAccess.d.ts.map +1 -1
- package/dist/routes/rest/globals/docAccess.js +5 -0
- package/dist/routes/rest/globals/docAccess.js.map +1 -1
- package/dist/routes/rest/globals/findOne.d.ts.map +1 -1
- package/dist/routes/rest/globals/findOne.js +5 -0
- package/dist/routes/rest/globals/findOne.js.map +1 -1
- package/dist/routes/rest/globals/findVersionByID.d.ts.map +1 -1
- package/dist/routes/rest/globals/findVersionByID.js +5 -0
- package/dist/routes/rest/globals/findVersionByID.js.map +1 -1
- package/dist/routes/rest/globals/findVersions.d.ts.map +1 -1
- package/dist/routes/rest/globals/findVersions.js +5 -0
- package/dist/routes/rest/globals/findVersions.js.map +1 -1
- package/dist/routes/rest/globals/preview.d.ts.map +1 -1
- package/dist/routes/rest/globals/preview.js +7 -1
- package/dist/routes/rest/globals/preview.js.map +1 -1
- package/dist/routes/rest/globals/restoreVersion.d.ts.map +1 -1
- package/dist/routes/rest/globals/restoreVersion.js +5 -0
- package/dist/routes/rest/globals/restoreVersion.js.map +1 -1
- package/dist/routes/rest/globals/update.d.ts.map +1 -1
- package/dist/routes/rest/globals/update.js +5 -0
- package/dist/routes/rest/globals/update.js.map +1 -1
- package/dist/routes/rest/index.d.ts +1 -0
- package/dist/routes/rest/index.d.ts.map +1 -1
- package/dist/routes/rest/index.js +324 -213
- package/dist/routes/rest/index.js.map +1 -1
- package/dist/routes/rest/routeError.d.ts +5 -4
- package/dist/routes/rest/routeError.d.ts.map +1 -1
- package/dist/routes/rest/routeError.js +25 -11
- package/dist/routes/rest/routeError.js.map +1 -1
- package/dist/routes/rest/types.d.ts +7 -7
- package/dist/routes/rest/types.d.ts.map +1 -1
- package/dist/routes/rest/types.js.map +1 -1
- package/dist/utilities/addDataAndFileToRequest.d.ts +11 -0
- package/dist/utilities/addDataAndFileToRequest.d.ts.map +1 -0
- package/dist/utilities/addDataAndFileToRequest.js +74 -0
- package/dist/utilities/addDataAndFileToRequest.js.map +1 -0
- package/dist/utilities/addLocalesToRequest.d.ts +20 -0
- package/dist/utilities/addLocalesToRequest.d.ts.map +1 -0
- package/dist/utilities/addLocalesToRequest.js +44 -0
- package/dist/utilities/addLocalesToRequest.js.map +1 -0
- package/dist/utilities/buildFieldSchemaMap/index.d.ts +2 -2
- package/dist/utilities/buildFieldSchemaMap/index.d.ts.map +1 -1
- package/dist/utilities/buildFieldSchemaMap/index.js.map +1 -1
- package/dist/utilities/buildFieldSchemaMap/traverseFields.d.ts.map +1 -1
- package/dist/utilities/buildFieldSchemaMap/traverseFields.js +3 -0
- package/dist/utilities/buildFieldSchemaMap/traverseFields.js.map +1 -1
- package/dist/utilities/createPayloadRequest.d.ts.map +1 -1
- package/dist/utilities/createPayloadRequest.js +15 -28
- package/dist/utilities/createPayloadRequest.js.map +1 -1
- package/dist/utilities/getDataAndFile.d.ts +2 -2
- package/dist/utilities/getDataAndFile.d.ts.map +1 -1
- package/dist/utilities/getDataAndFile.js +27 -47
- package/dist/utilities/getDataAndFile.js.map +1 -1
- package/dist/utilities/getPayloadHMR.d.ts +2 -1
- package/dist/utilities/getPayloadHMR.d.ts.map +1 -1
- package/dist/utilities/getPayloadHMR.js +22 -19
- package/dist/utilities/getPayloadHMR.js.map +1 -1
- package/dist/utilities/getRequestLanguage.d.ts +1 -1
- package/dist/utilities/getRequestLanguage.d.ts.map +1 -1
- package/dist/utilities/getRequestLanguage.js +3 -4
- package/dist/utilities/getRequestLanguage.js.map +1 -1
- package/dist/utilities/headersWithCors.d.ts +8 -0
- package/dist/utilities/headersWithCors.d.ts.map +1 -0
- package/dist/utilities/headersWithCors.js +17 -0
- package/dist/utilities/headersWithCors.js.map +1 -0
- package/dist/utilities/initPage/handleAdminPage.d.ts +13 -0
- package/dist/utilities/initPage/handleAdminPage.d.ts.map +1 -0
- package/dist/utilities/initPage/handleAdminPage.js +35 -0
- package/dist/utilities/initPage/handleAdminPage.js.map +1 -0
- package/dist/utilities/initPage/handleAuthRedirect.d.ts +9 -0
- package/dist/utilities/initPage/handleAuthRedirect.d.ts.map +1 -0
- package/dist/utilities/initPage/handleAuthRedirect.js +26 -0
- package/dist/utilities/initPage/handleAuthRedirect.js.map +1 -0
- package/dist/utilities/initPage/index.d.ts +4 -0
- package/dist/utilities/initPage/index.d.ts.map +1 -0
- package/dist/utilities/{initPage.js → initPage/index.js} +22 -31
- package/dist/utilities/initPage/index.js.map +1 -0
- package/dist/utilities/initPage/shared.d.ts +4 -0
- package/dist/utilities/initPage/shared.d.ts.map +1 -0
- package/dist/utilities/initPage/shared.js +17 -0
- package/dist/utilities/initPage/shared.js.map +1 -0
- package/dist/utilities/initPage/types.d.ts +24 -0
- package/dist/utilities/initPage/types.d.ts.map +1 -0
- package/dist/utilities/initPage/types.js +3 -0
- package/dist/utilities/initPage/types.js.map +1 -0
- package/dist/views/API/index.client.js +7 -7
- package/dist/views/API/index.client.js.map +1 -1
- package/dist/views/Account/index.d.ts.map +1 -1
- package/dist/views/Account/index.js +2 -1
- package/dist/views/Account/index.js.map +1 -1
- package/dist/views/CreateFirstUser/index.client.d.ts +3 -3
- package/dist/views/CreateFirstUser/index.client.d.ts.map +1 -1
- package/dist/views/CreateFirstUser/index.client.js +48 -6
- package/dist/views/CreateFirstUser/index.client.js.map +1 -1
- package/dist/views/CreateFirstUser/index.d.ts.map +1 -1
- package/dist/views/CreateFirstUser/index.js +9 -29
- package/dist/views/CreateFirstUser/index.js.map +1 -1
- package/dist/views/CreateFirstUser/index.scss +2 -12
- package/dist/views/Document/index.d.ts.map +1 -1
- package/dist/views/Document/index.js +2 -1
- package/dist/views/Document/index.js.map +1 -1
- package/dist/views/Edit/Default/Auth/APIKey.d.ts +1 -0
- package/dist/views/Edit/Default/Auth/APIKey.d.ts.map +1 -1
- package/dist/views/Edit/Default/Auth/APIKey.js +13 -6
- package/dist/views/Edit/Default/Auth/APIKey.js.map +1 -1
- package/dist/views/Edit/Default/Auth/index.js +2 -1
- package/dist/views/Edit/Default/Auth/index.js.map +1 -1
- package/dist/views/Edit/Default/{SetStepNav → SetDocumentStepNav}/index.d.ts +1 -1
- package/dist/views/Edit/Default/SetDocumentStepNav/index.d.ts.map +1 -0
- package/dist/views/Edit/Default/{SetStepNav → SetDocumentStepNav}/index.js +12 -5
- package/dist/views/Edit/Default/SetDocumentStepNav/index.js.map +1 -0
- package/dist/views/Edit/Default/index.d.ts.map +1 -1
- package/dist/views/Edit/Default/index.js +6 -5
- package/dist/views/Edit/Default/index.js.map +1 -1
- package/dist/views/ForgotPassword/ForgotPasswordForm/index.d.ts +3 -0
- package/dist/views/ForgotPassword/ForgotPasswordForm/index.d.ts.map +1 -0
- package/dist/views/ForgotPassword/ForgotPasswordForm/index.js +58 -0
- package/dist/views/ForgotPassword/ForgotPasswordForm/index.js.map +1 -0
- package/dist/views/ForgotPassword/index.d.ts.map +1 -1
- package/dist/views/ForgotPassword/index.js +3 -39
- package/dist/views/ForgotPassword/index.js.map +1 -1
- package/dist/views/List/index.js +2 -2
- package/dist/views/List/index.js.map +1 -1
- package/dist/views/LivePreview/Preview/index.d.ts.map +1 -1
- package/dist/views/LivePreview/Preview/index.js +23 -0
- package/dist/views/LivePreview/Preview/index.js.map +1 -1
- package/dist/views/LivePreview/Toolbar/Controls/index.d.ts.map +1 -1
- package/dist/views/LivePreview/Toolbar/Controls/index.js +6 -4
- package/dist/views/LivePreview/Toolbar/Controls/index.js.map +1 -1
- package/dist/views/LivePreview/index.client.js +2 -2
- package/dist/views/LivePreview/index.client.js.map +1 -1
- package/dist/views/Login/LoginForm/index.d.ts.map +1 -1
- package/dist/views/Login/LoginForm/index.js +32 -2
- package/dist/views/Login/LoginForm/index.js.map +1 -1
- package/dist/views/Login/index.d.ts.map +1 -1
- package/dist/views/Login/index.js +14 -7
- package/dist/views/Login/index.js.map +1 -1
- package/dist/views/Logout/LogoutClient.d.ts.map +1 -1
- package/dist/views/Logout/LogoutClient.js +1 -2
- package/dist/views/Logout/LogoutClient.js.map +1 -1
- package/dist/views/NotFound/index.d.ts.map +1 -1
- package/dist/views/NotFound/index.js +5 -3
- package/dist/views/NotFound/index.js.map +1 -1
- package/dist/views/ResetPassword/index.client.d.ts +7 -0
- package/dist/views/ResetPassword/index.client.d.ts.map +1 -0
- package/dist/views/ResetPassword/index.client.js +83 -0
- package/dist/views/ResetPassword/index.client.js.map +1 -0
- package/dist/views/ResetPassword/index.d.ts.map +1 -1
- package/dist/views/ResetPassword/index.js +6 -31
- package/dist/views/ResetPassword/index.js.map +1 -1
- package/dist/views/ResetPassword/index.scss +2 -12
- package/dist/views/Root/getViewFromConfig.d.ts +1 -1
- package/dist/views/Root/getViewFromConfig.d.ts.map +1 -1
- package/dist/views/Root/getViewFromConfig.js.map +1 -1
- package/dist/views/Root/index.js +1 -1
- package/dist/views/Root/index.js.map +1 -1
- package/dist/views/Version/RenderFieldsToDiff/fields/index.d.ts +0 -2
- package/dist/views/Version/RenderFieldsToDiff/fields/index.d.ts.map +1 -1
- package/dist/views/Version/Restore/index.d.ts.map +1 -1
- package/dist/views/Version/Restore/index.js +11 -8
- package/dist/views/Version/Restore/index.js.map +1 -1
- package/dist/views/Version/Restore/index.scss +4 -2
- package/dist/views/Versions/index.js +2 -2
- package/dist/views/Versions/index.js.map +1 -1
- package/dist/withPayload.d.ts.map +1 -1
- package/dist/withPayload.js +2 -1
- package/dist/withPayload.js.map +1 -1
- package/package.json +35 -34
- package/dist/next-fileupload/fileFactory.d.ts.map +0 -1
- package/dist/next-fileupload/fileFactory.js.map +0 -1
- package/dist/next-fileupload/handlers.d.ts.map +0 -1
- package/dist/next-fileupload/handlers.js.map +0 -1
- package/dist/next-fileupload/index.d.ts.map +0 -1
- package/dist/next-fileupload/index.js.map +0 -1
- package/dist/next-fileupload/isEligibleRequest.d.ts.map +0 -1
- package/dist/next-fileupload/isEligibleRequest.js.map +0 -1
- package/dist/next-fileupload/processMultipart.d.ts +0 -8
- package/dist/next-fileupload/processMultipart.d.ts.map +0 -1
- package/dist/next-fileupload/processMultipart.js.map +0 -1
- package/dist/next-fileupload/processNested.d.ts.map +0 -1
- package/dist/next-fileupload/processNested.js.map +0 -1
- package/dist/next-fileupload/uploadTimer.d.ts.map +0 -1
- package/dist/next-fileupload/uploadTimer.js.map +0 -1
- package/dist/next-fileupload/utilities.d.ts.map +0 -1
- package/dist/next-fileupload/utilities.js.map +0 -1
- package/dist/next-stream-file/index.d.ts.map +0 -1
- package/dist/next-stream-file/index.js.map +0 -1
- package/dist/utilities/initPage.d.ts +0 -12
- package/dist/utilities/initPage.d.ts.map +0 -1
- package/dist/utilities/initPage.js.map +0 -1
- package/dist/views/Edit/Default/SetStepNav/index.d.ts.map +0 -1
- package/dist/views/Edit/Default/SetStepNav/index.js.map +0 -1
- package/src/index.js +0 -1
- /package/dist/{next-fileupload → fetchAPI-multipart}/fileFactory.js +0 -0
- /package/dist/{next-fileupload → fetchAPI-multipart}/handlers.js +0 -0
- /package/dist/{next-fileupload → fetchAPI-multipart}/isEligibleRequest.d.ts +0 -0
- /package/dist/{next-fileupload → fetchAPI-multipart}/processNested.d.ts +0 -0
- /package/dist/{next-fileupload → fetchAPI-multipart}/uploadTimer.d.ts +0 -0
- /package/dist/{next-fileupload → fetchAPI-multipart}/uploadTimer.js +0 -0
- /package/dist/{next-stream-file → fetchAPI-stream-file}/index.d.ts +0 -0
- /package/dist/{next-stream-file → fetchAPI-stream-file}/index.js +0 -0
package/dist/cjs/withPayload.cjs
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"sources":["../../src/withPayload.js"],"names":[],"mappings":"AAAA;;;;GAIG;;;;;;;;;;;
|
|
1
|
+
{"version":3,"sources":["../../src/withPayload.js"],"names":[],"mappings":"AAAA;;;;GAIG;;;;;;;;;;;IAoEH,OAA0B;eAA1B;;IAnEa,WAAW;eAAX;;;AAAN,MAAM,cAAc,CAAC,aAAa,CAAC,CAAC;IACzC,OAAO;QACL,GAAG,UAAU;QACb,cAAc;YACZ,GAAI,YAAY,gBAAgB,CAAC,CAAC;YAClC,2BAA2B;gBACzB,QAAQ;uBACF,WAAW,YAAY,EAAE,2BAA2B,CAAC,OAAO,IAAI,EAAE;oBACtE;oBACA;oBACA;iBACD;YACH;YACA,kCAAkC;mBAC5B,YAAY,cAAc,oCAAoC,EAAE;gBACpE;gBACA;gBACA;gBACA;gBACA;gBACA;aACD;QACH;QACA,SAAS,CAAC,eAAe;YACvB,MAAM,wBACJ,OAAO,WAAW,OAAO,KAAK,aAC1B,WAAW,OAAO,CAAC,eAAe,kBAClC;YAEN,OAAO;gBACL,GAAG,qBAAqB;gBACxB,WAAW;uBACL,uBAAuB,aAAa,EAAE;oBAC1C;oBACA;oBACA;oBACA;iBACD;gBACD,gBAAgB;uBACV,uBAAuB,kBAAkB,EAAE;oBAC/C;wBAAE,QAAQ;oBAAwC;oBAClD;wBAAE,MAAM;oBAAwC;oBAChD;wBAAE,QAAQ;oBAAuC;oBACjD;wBAAE,MAAM;oBAAuC;iBAChD;gBACD,SAAS;oBACP,GAAI,uBAAuB,WAAW,CAAC,CAAC;oBACxC,OAAO;wBACL,GAAI,uBAAuB,SAAS,SAAS,CAAC,CAAC;oBACjD;oBACA,UAAU;wBACR,GAAI,uBAAuB,SAAS,YAAY,CAAC,CAAC;wBAClD,iCAAiC;wBACjC,oBAAoB;wBACpB,MAAM;wBACN,UAAU;wBACV,6BAA6B;wBAC7B,QAAQ;wBACR,kBAAkB;wBAClB,eAAe;oBACjB;gBACF;YACF;QACF;IACF;AACF;MAEA,WAAe","file":"withPayload.cjs","sourcesContent":["/**\n * @param {import('next').NextConfig} nextConfig\n *\n * @returns {import('next').NextConfig}\n * */\nexport const withPayload = (nextConfig = {}) => {\n return {\n ...nextConfig,\n experimental: {\n ...(nextConfig?.experimental || {}),\n outputFileTracingExcludes: {\n '**/*': [\n ...(nextConfig.experimental?.outputFileTracingExcludes?.['**/*'] || []),\n 'drizzle-kit',\n 'drizzle-kit/payload',\n 'libsql',\n ],\n },\n serverComponentsExternalPackages: [\n ...(nextConfig?.experimental?.serverComponentsExternalPackages || []),\n 'drizzle-kit',\n 'drizzle-kit/payload',\n 'libsql',\n 'pino',\n 'pino-pretty',\n 'graphql',\n ],\n },\n webpack: (webpackConfig, webpackOptions) => {\n const incomingWebpackConfig =\n typeof nextConfig.webpack === 'function'\n ? nextConfig.webpack(webpackConfig, webpackOptions)\n : webpackConfig\n\n return {\n ...incomingWebpackConfig,\n externals: [\n ...(incomingWebpackConfig?.externals || []),\n 'drizzle-kit',\n 'drizzle-kit/payload',\n 'sharp',\n 'libsql',\n ],\n ignoreWarnings: [\n ...(incomingWebpackConfig?.ignoreWarnings || []),\n { module: /node_modules\\/mongodb\\/lib\\/utils\\.js/ },\n { file: /node_modules\\/mongodb\\/lib\\/utils\\.js/ },\n { module: /node_modules\\/mongodb\\/lib\\/bson\\.js/ },\n { file: /node_modules\\/mongodb\\/lib\\/bson\\.js/ },\n ],\n resolve: {\n ...(incomingWebpackConfig?.resolve || {}),\n alias: {\n ...(incomingWebpackConfig?.resolve?.alias || {}),\n },\n fallback: {\n ...(incomingWebpackConfig?.resolve?.fallback || {}),\n '@aws-sdk/credential-providers': false,\n '@mongodb-js/zstd': false,\n aws4: false,\n kerberos: false,\n 'mongodb-client-encryption': false,\n snappy: false,\n 'supports-color': false,\n 'yocto-queue': false,\n },\n },\n }\n },\n }\n}\n\nexport default withPayload\n"]}
|
package/dist/exports/routes.d.ts
CHANGED
|
@@ -1,3 +1,3 @@
|
|
|
1
1
|
export { GRAPHQL_PLAYGROUND_GET, GRAPHQL_POST } from '../routes/graphql/index.js';
|
|
2
|
-
export { DELETE as REST_DELETE, GET as REST_GET, PATCH as REST_PATCH, POST as REST_POST, } from '../routes/rest/index.js';
|
|
2
|
+
export { DELETE as REST_DELETE, GET as REST_GET, OPTIONS as REST_OPTIONS, PATCH as REST_PATCH, POST as REST_POST, } from '../routes/rest/index.js';
|
|
3
3
|
//# sourceMappingURL=routes.d.ts.map
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"routes.d.ts","sourceRoot":"","sources":["../../src/exports/routes.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,sBAAsB,EAAE,YAAY,EAAE,MAAM,4BAA4B,CAAA;AAEjF,OAAO,EACL,MAAM,IAAI,WAAW,EACrB,GAAG,IAAI,QAAQ,EACf,KAAK,IAAI,UAAU,EACnB,IAAI,IAAI,SAAS,GAClB,MAAM,yBAAyB,CAAA"}
|
|
1
|
+
{"version":3,"file":"routes.d.ts","sourceRoot":"","sources":["../../src/exports/routes.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,sBAAsB,EAAE,YAAY,EAAE,MAAM,4BAA4B,CAAA;AAEjF,OAAO,EACL,MAAM,IAAI,WAAW,EACrB,GAAG,IAAI,QAAQ,EACf,OAAO,IAAI,YAAY,EACvB,KAAK,IAAI,UAAU,EACnB,IAAI,IAAI,SAAS,GAClB,MAAM,yBAAyB,CAAA"}
|
package/dist/exports/routes.js
CHANGED
|
@@ -1,4 +1,4 @@
|
|
|
1
1
|
export { GRAPHQL_PLAYGROUND_GET, GRAPHQL_POST } from '../routes/graphql/index.js';
|
|
2
|
-
export { DELETE as REST_DELETE, GET as REST_GET, PATCH as REST_PATCH, POST as REST_POST } from '../routes/rest/index.js';
|
|
2
|
+
export { DELETE as REST_DELETE, GET as REST_GET, OPTIONS as REST_OPTIONS, PATCH as REST_PATCH, POST as REST_POST } from '../routes/rest/index.js';
|
|
3
3
|
|
|
4
4
|
//# sourceMappingURL=routes.js.map
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"sources":["../../src/exports/routes.ts"],"sourcesContent":["export { GRAPHQL_PLAYGROUND_GET, GRAPHQL_POST } from '../routes/graphql/index.js'\n\nexport {\n DELETE as REST_DELETE,\n GET as REST_GET,\n PATCH as REST_PATCH,\n POST as REST_POST,\n} from '../routes/rest/index.js'\n"],"names":["GRAPHQL_PLAYGROUND_GET","GRAPHQL_POST","DELETE","REST_DELETE","GET","REST_GET","PATCH","REST_PATCH","POST","REST_POST"],"rangeMappings":";","mappings":"AAAA,SAASA,sBAAsB,EAAEC,YAAY,QAAQ,6BAA4B;AAEjF,SACEC,UAAUC,WAAW,EACrBC,OAAOC,QAAQ,EACfC,SAASC,UAAU,EACnBC,QAAQC,SAAS,QACZ,0BAAyB"}
|
|
1
|
+
{"version":3,"sources":["../../src/exports/routes.ts"],"sourcesContent":["export { GRAPHQL_PLAYGROUND_GET, GRAPHQL_POST } from '../routes/graphql/index.js'\n\nexport {\n DELETE as REST_DELETE,\n GET as REST_GET,\n OPTIONS as REST_OPTIONS,\n PATCH as REST_PATCH,\n POST as REST_POST,\n} from '../routes/rest/index.js'\n"],"names":["GRAPHQL_PLAYGROUND_GET","GRAPHQL_POST","DELETE","REST_DELETE","GET","REST_GET","OPTIONS","REST_OPTIONS","PATCH","REST_PATCH","POST","REST_POST"],"rangeMappings":";","mappings":"AAAA,SAASA,sBAAsB,EAAEC,YAAY,QAAQ,6BAA4B;AAEjF,SACEC,UAAUC,WAAW,EACrBC,OAAOC,QAAQ,EACfC,WAAWC,YAAY,EACvBC,SAASC,UAAU,EACnBC,QAAQC,SAAS,QACZ,0BAAyB"}
|
|
@@ -1,3 +1,9 @@
|
|
|
1
|
+
export { addDataAndFileToRequest } from '../utilities/addDataAndFileToRequest.js';
|
|
2
|
+
export { addLocalesToRequestFromData, sanitizeLocales } from '../utilities/addLocalesToRequest.js';
|
|
3
|
+
export { traverseFields } from '../utilities/buildFieldSchemaMap/traverseFields.js';
|
|
4
|
+
export { createPayloadRequest } from '../utilities/createPayloadRequest.js';
|
|
1
5
|
export { getNextRequestI18n } from '../utilities/getNextRequestI18n.js';
|
|
2
|
-
export { getPayloadHMR } from '../utilities/getPayloadHMR.js';
|
|
6
|
+
export { getPayloadHMR, reload } from '../utilities/getPayloadHMR.js';
|
|
7
|
+
export { headersWithCors } from '../utilities/headersWithCors.js';
|
|
8
|
+
export { initPage } from '../utilities/initPage/index.js';
|
|
3
9
|
//# sourceMappingURL=utilities.d.ts.map
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"utilities.d.ts","sourceRoot":"","sources":["../../src/exports/utilities.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,kBAAkB,EAAE,MAAM,oCAAoC,CAAA;AACvE,OAAO,EAAE,aAAa,EAAE,MAAM,+BAA+B,CAAA"}
|
|
1
|
+
{"version":3,"file":"utilities.d.ts","sourceRoot":"","sources":["../../src/exports/utilities.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,uBAAuB,EAAE,MAAM,yCAAyC,CAAA;AACjF,OAAO,EAAE,2BAA2B,EAAE,eAAe,EAAE,MAAM,qCAAqC,CAAA;AAClG,OAAO,EAAE,cAAc,EAAE,MAAM,oDAAoD,CAAA;AACnF,OAAO,EAAE,oBAAoB,EAAE,MAAM,sCAAsC,CAAA;AAC3E,OAAO,EAAE,kBAAkB,EAAE,MAAM,oCAAoC,CAAA;AACvE,OAAO,EAAE,aAAa,EAAE,MAAM,EAAE,MAAM,+BAA+B,CAAA;AACrE,OAAO,EAAE,eAAe,EAAE,MAAM,iCAAiC,CAAA;AACjE,OAAO,EAAE,QAAQ,EAAE,MAAM,gCAAgC,CAAA"}
|
|
@@ -1,4 +1,10 @@
|
|
|
1
|
+
export { addDataAndFileToRequest } from '../utilities/addDataAndFileToRequest.js';
|
|
2
|
+
export { addLocalesToRequestFromData, sanitizeLocales } from '../utilities/addLocalesToRequest.js';
|
|
3
|
+
export { traverseFields } from '../utilities/buildFieldSchemaMap/traverseFields.js';
|
|
4
|
+
export { createPayloadRequest } from '../utilities/createPayloadRequest.js';
|
|
1
5
|
export { getNextRequestI18n } from '../utilities/getNextRequestI18n.js';
|
|
2
|
-
export { getPayloadHMR } from '../utilities/getPayloadHMR.js';
|
|
6
|
+
export { getPayloadHMR, reload } from '../utilities/getPayloadHMR.js';
|
|
7
|
+
export { headersWithCors } from '../utilities/headersWithCors.js';
|
|
8
|
+
export { initPage } from '../utilities/initPage/index.js';
|
|
3
9
|
|
|
4
10
|
//# sourceMappingURL=utilities.js.map
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"sources":["../../src/exports/utilities.ts"],"sourcesContent":["export { getNextRequestI18n } from '../utilities/getNextRequestI18n.js'\nexport { getPayloadHMR } from '../utilities/getPayloadHMR.js'\n"],"names":["getNextRequestI18n","getPayloadHMR"],"rangeMappings":"
|
|
1
|
+
{"version":3,"sources":["../../src/exports/utilities.ts"],"sourcesContent":["export { addDataAndFileToRequest } from '../utilities/addDataAndFileToRequest.js'\nexport { addLocalesToRequestFromData, sanitizeLocales } from '../utilities/addLocalesToRequest.js'\nexport { traverseFields } from '../utilities/buildFieldSchemaMap/traverseFields.js'\nexport { createPayloadRequest } from '../utilities/createPayloadRequest.js'\nexport { getNextRequestI18n } from '../utilities/getNextRequestI18n.js'\nexport { getPayloadHMR, reload } from '../utilities/getPayloadHMR.js'\nexport { headersWithCors } from '../utilities/headersWithCors.js'\nexport { initPage } from '../utilities/initPage/index.js'\n"],"names":["addDataAndFileToRequest","addLocalesToRequestFromData","sanitizeLocales","traverseFields","createPayloadRequest","getNextRequestI18n","getPayloadHMR","reload","headersWithCors","initPage"],"rangeMappings":";;;;;;;","mappings":"AAAA,SAASA,uBAAuB,QAAQ,0CAAyC;AACjF,SAASC,2BAA2B,EAAEC,eAAe,QAAQ,sCAAqC;AAClG,SAASC,cAAc,QAAQ,qDAAoD;AACnF,SAASC,oBAAoB,QAAQ,uCAAsC;AAC3E,SAASC,kBAAkB,QAAQ,qCAAoC;AACvE,SAASC,aAAa,EAAEC,MAAM,QAAQ,gCAA+B;AACrE,SAASC,eAAe,QAAQ,kCAAiC;AACjE,SAASC,QAAQ,QAAQ,iCAAgC"}
|
|
@@ -1,5 +1,5 @@
|
|
|
1
1
|
/// <reference types="node" resolution-mode="require"/>
|
|
2
|
-
import type {
|
|
2
|
+
import type { FetchAPIFileUploadOptions, FileShape } from './index.js';
|
|
3
3
|
type FileFactoryOptions = {
|
|
4
4
|
buffer: Buffer;
|
|
5
5
|
encoding: string;
|
|
@@ -10,7 +10,7 @@ type FileFactoryOptions = {
|
|
|
10
10
|
tempFilePath: string;
|
|
11
11
|
truncated: boolean;
|
|
12
12
|
};
|
|
13
|
-
type FileFactory = (options: FileFactoryOptions, fileUploadOptions:
|
|
13
|
+
type FileFactory = (options: FileFactoryOptions, fileUploadOptions: FetchAPIFileUploadOptions) => FileShape;
|
|
14
14
|
export declare const fileFactory: FileFactory;
|
|
15
15
|
export {};
|
|
16
16
|
//# sourceMappingURL=fileFactory.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"fileFactory.d.ts","sourceRoot":"","sources":["../../src/fetchAPI-multipart/fileFactory.ts"],"names":[],"mappings":";AAAA,OAAO,KAAK,EAAE,yBAAyB,EAAE,SAAS,EAAE,MAAM,YAAY,CAAA;AAmCtE,KAAK,kBAAkB,GAAG;IACxB,MAAM,EAAE,MAAM,CAAA;IACd,QAAQ,EAAE,MAAM,CAAA;IAChB,IAAI,EAAE,MAAM,GAAG,MAAM,CAAA;IACrB,QAAQ,EAAE,MAAM,CAAA;IAChB,IAAI,EAAE,MAAM,CAAA;IACZ,IAAI,EAAE,MAAM,CAAA;IACZ,YAAY,EAAE,MAAM,CAAA;IACpB,SAAS,EAAE,OAAO,CAAA;CACnB,CAAA;AACD,KAAK,WAAW,GAAG,CACjB,OAAO,EAAE,kBAAkB,EAC3B,iBAAiB,EAAE,yBAAyB,KACzC,SAAS,CAAA;AACd,eAAO,MAAM,WAAW,EAAE,WA4BzB,CAAA"}
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"sources":["../../src/fetchAPI-multipart/fileFactory.ts"],"sourcesContent":["import type { FetchAPIFileUploadOptions, FileShape } from './index.js'\n\nimport {\n checkAndMakeDir,\n debugLog,\n isFunc,\n moveFile,\n promiseCallback,\n saveBufferToFile,\n} from './utilities.js'\n\ntype MoveFile = (\n filePath: string,\n options: FileFactoryOptions,\n fileUploadOptions: FetchAPIFileUploadOptions,\n) => (resolve: () => void, reject: () => void) => void\n\n/**\n * Returns Local function that moves the file to a different location on the filesystem\n * which takes two function arguments to make it compatible w/ Promise or Callback APIs\n */\nconst moveFromTemp: MoveFile = (filePath, options, fileUploadOptions) => (resolve, reject) => {\n debugLog(fileUploadOptions, `Moving temporary file ${options.tempFilePath} to ${filePath}`)\n moveFile(options.tempFilePath, filePath, promiseCallback(resolve, reject))\n}\n\n/**\n * Returns Local function that moves the file from buffer to a different location on the filesystem\n * which takes two function arguments to make it compatible w/ Promise or Callback APIs\n */\nconst moveFromBuffer: MoveFile = (filePath, options, fileUploadOptions) => (resolve, reject) => {\n debugLog(fileUploadOptions, `Moving uploaded buffer to ${filePath}`)\n saveBufferToFile(options.buffer, filePath, promiseCallback(resolve, reject))\n}\n\ntype FileFactoryOptions = {\n buffer: Buffer\n encoding: string\n hash: Buffer | string\n mimetype: string\n name: string\n size: number\n tempFilePath: string\n truncated: boolean\n}\ntype FileFactory = (\n options: FileFactoryOptions,\n fileUploadOptions: FetchAPIFileUploadOptions,\n) => FileShape\nexport const fileFactory: FileFactory = (options, fileUploadOptions) => {\n // see: https://github.com/richardgirges/express-fileupload/issues/14\n // firefox uploads empty file in case of cache miss when f5ing page.\n // resulting in unexpected behavior. if there is no file data, the file is invalid.\n // if (!fileUploadOptions.useTempFiles && !options.buffer.length) return;\n\n // Create and return file object.\n return {\n name: options.name,\n data: options.buffer,\n encoding: options.encoding,\n md5: options.hash,\n mimetype: options.mimetype,\n mv: (filePath: string, callback) => {\n // Define a proper move function.\n const moveFunc = fileUploadOptions.useTempFiles\n ? moveFromTemp(filePath, options, fileUploadOptions)\n : moveFromBuffer(filePath, options, fileUploadOptions)\n // Create a folder for a file.\n checkAndMakeDir(fileUploadOptions, filePath)\n // If callback is passed in, use the callback API, otherwise return a promise.\n const defaultReject = () => undefined\n return isFunc(callback) ? moveFunc(callback, defaultReject) : new Promise(moveFunc)\n },\n size: options.size,\n tempFilePath: options.tempFilePath,\n truncated: options.truncated,\n }\n}\n"],"names":["checkAndMakeDir","debugLog","isFunc","moveFile","promiseCallback","saveBufferToFile","moveFromTemp","filePath","options","fileUploadOptions","resolve","reject","tempFilePath","moveFromBuffer","buffer","fileFactory","name","data","encoding","md5","hash","mimetype","mv","callback","moveFunc","useTempFiles","defaultReject","undefined","Promise","size","truncated"],"rangeMappings":";;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;","mappings":"AAEA,SACEA,eAAe,EACfC,QAAQ,EACRC,MAAM,EACNC,QAAQ,EACRC,eAAe,EACfC,gBAAgB,QACX,iBAAgB;AAQvB;;;CAGC,GACD,MAAMC,eAAyB,CAACC,UAAUC,SAASC,oBAAsB,CAACC,SAASC;QACjFV,SAASQ,mBAAmB,CAAC,sBAAsB,EAAED,QAAQI,YAAY,CAAC,IAAI,EAAEL,SAAS,CAAC;QAC1FJ,SAASK,QAAQI,YAAY,EAAEL,UAAUH,gBAAgBM,SAASC;IACpE;AAEA;;;CAGC,GACD,MAAME,iBAA2B,CAACN,UAAUC,SAASC,oBAAsB,CAACC,SAASC;QACnFV,SAASQ,mBAAmB,CAAC,0BAA0B,EAAEF,SAAS,CAAC;QACnEF,iBAAiBG,QAAQM,MAAM,EAAEP,UAAUH,gBAAgBM,SAASC;IACtE;AAgBA,OAAO,MAAMI,cAA2B,CAACP,SAASC;IAChD,qEAAqE;IACrE,oEAAoE;IACpE,mFAAmF;IACnF,yEAAyE;IAEzE,iCAAiC;IACjC,OAAO;QACLO,MAAMR,QAAQQ,IAAI;QAClBC,MAAMT,QAAQM,MAAM;QACpBI,UAAUV,QAAQU,QAAQ;QAC1BC,KAAKX,QAAQY,IAAI;QACjBC,UAAUb,QAAQa,QAAQ;QAC1BC,IAAI,CAACf,UAAkBgB;YACrB,iCAAiC;YACjC,MAAMC,WAAWf,kBAAkBgB,YAAY,GAC3CnB,aAAaC,UAAUC,SAASC,qBAChCI,eAAeN,UAAUC,SAASC;YACtC,8BAA8B;YAC9BT,gBAAgBS,mBAAmBF;YACnC,8EAA8E;YAC9E,MAAMmB,gBAAgB,IAAMC;YAC5B,OAAOzB,OAAOqB,YAAYC,SAASD,UAAUG,iBAAiB,IAAIE,QAAQJ;QAC5E;QACAK,MAAMrB,QAAQqB,IAAI;QAClBjB,cAAcJ,QAAQI,YAAY;QAClCkB,WAAWtB,QAAQsB,SAAS;IAC9B;AACF,EAAC"}
|
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
/// <reference types="node" resolution-mode="require"/>
|
|
2
|
-
import type {
|
|
3
|
-
type Handler = (options:
|
|
2
|
+
import type { FetchAPIFileUploadOptions } from './index.js';
|
|
3
|
+
type Handler = (options: FetchAPIFileUploadOptions, fieldname: string, filename: string) => {
|
|
4
4
|
cleanup: () => void;
|
|
5
5
|
complete: () => Buffer;
|
|
6
6
|
dataHandler: (data: Buffer) => void;
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"handlers.d.ts","sourceRoot":"","sources":["../../src/fetchAPI-multipart/handlers.ts"],"names":[],"mappings":";AAIA,OAAO,KAAK,EAAE,yBAAyB,EAAE,MAAM,YAAY,CAAA;AAI3D,KAAK,OAAO,GAAG,CACb,OAAO,EAAE,yBAAyB,EAClC,SAAS,EAAE,MAAM,EACjB,QAAQ,EAAE,MAAM,KACb;IACH,OAAO,EAAE,MAAM,IAAI,CAAA;IACnB,QAAQ,EAAE,MAAM,MAAM,CAAA;IACtB,WAAW,EAAE,CAAC,IAAI,EAAE,MAAM,KAAK,IAAI,CAAA;IACnC,WAAW,EAAE,MAAM,MAAM,CAAA;IACzB,WAAW,EAAE,MAAM,MAAM,CAAA;IACzB,OAAO,EAAE,MAAM,MAAM,CAAA;IACrB,eAAe,EAAE,MAAM,OAAO,CAAC,OAAO,CAAC,CAAA;CACxC,CAAA;AAED,eAAO,MAAM,eAAe,EAAE,OAsD7B,CAAA;AAED,eAAO,MAAM,UAAU,EAAE,OAgCxB,CAAA"}
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"sources":["../../src/fetchAPI-multipart/handlers.ts"],"sourcesContent":["import crypto from 'crypto'\nimport fs, { WriteStream } from 'fs'\nimport path from 'path'\n\nimport type { FetchAPIFileUploadOptions } from './index.js'\n\nimport { checkAndMakeDir, debugLog, deleteFile, getTempFilename } from './utilities.js'\n\ntype Handler = (\n options: FetchAPIFileUploadOptions,\n fieldname: string,\n filename: string,\n) => {\n cleanup: () => void\n complete: () => Buffer\n dataHandler: (data: Buffer) => void\n getFilePath: () => string\n getFileSize: () => number\n getHash: () => string\n getWritePromise: () => Promise<boolean>\n}\n\nexport const tempFileHandler: Handler = (options, fieldname, filename) => {\n const dir = path.normalize(options.tempFileDir)\n const tempFilePath = path.join(process.cwd(), dir, getTempFilename())\n checkAndMakeDir({ createParentPath: true }, tempFilePath)\n\n debugLog(options, `Temporary file path is ${tempFilePath}`)\n\n const hash = crypto.createHash('md5')\n let fileSize = 0\n let completed = false\n\n debugLog(options, `Opening write stream for ${fieldname}->${filename}...`)\n const writeStream = fs.createWriteStream(tempFilePath)\n const writePromise = new Promise<boolean>((resolve, reject) => {\n writeStream.on('finish', () => resolve(true))\n writeStream.on('error', (err) => {\n debugLog(options, `Error write temp file: ${err}`)\n reject(err)\n })\n })\n\n return {\n cleanup: () => {\n completed = true\n debugLog(options, `Cleaning up temporary file ${tempFilePath}...`)\n writeStream.end()\n deleteFile(tempFilePath, (err) =>\n err\n ? debugLog(options, `Cleaning up temporary file ${tempFilePath} failed: ${err}`)\n : debugLog(options, `Cleaning up temporary file ${tempFilePath} done.`),\n )\n },\n complete: () => {\n completed = true\n debugLog(options, `Upload ${fieldname}->${filename} completed, bytes:${fileSize}.`)\n if (writeStream instanceof WriteStream) writeStream.end()\n // Return empty buff since data was uploaded into a temp file.\n return Buffer.concat([])\n },\n dataHandler: (data) => {\n if (completed === true) {\n debugLog(options, `Error: got ${fieldname}->${filename} data chunk for completed upload!`)\n return\n }\n writeStream.write(data)\n hash.update(data)\n fileSize += data.length\n debugLog(options, `Uploading ${fieldname}->${filename}, bytes:${fileSize}...`)\n },\n getFilePath: () => tempFilePath,\n getFileSize: () => fileSize,\n getHash: () => hash.digest('hex'),\n getWritePromise: () => writePromise,\n }\n}\n\nexport const memHandler: Handler = (options, fieldname, filename) => {\n const buffers: Buffer[] = []\n const hash = crypto.createHash('md5')\n let fileSize = 0\n let completed = false\n\n const getBuffer = () => Buffer.concat(buffers, fileSize)\n\n return {\n cleanup: () => {\n completed = true\n },\n complete: () => {\n debugLog(options, `Upload ${fieldname}->${filename} completed, bytes:${fileSize}.`)\n completed = true\n return getBuffer()\n },\n dataHandler: (data) => {\n if (completed === true) {\n debugLog(options, `Error: got ${fieldname}->${filename} data chunk for completed upload!`)\n return\n }\n buffers.push(data)\n hash.update(data)\n fileSize += data.length\n debugLog(options, `Uploading ${fieldname}->${filename}, bytes:${fileSize}...`)\n },\n getFilePath: () => '',\n getFileSize: () => fileSize,\n getHash: () => hash.digest('hex'),\n getWritePromise: () => Promise.resolve(true),\n }\n}\n"],"names":["crypto","fs","WriteStream","path","checkAndMakeDir","debugLog","deleteFile","getTempFilename","tempFileHandler","options","fieldname","filename","dir","normalize","tempFileDir","tempFilePath","join","process","cwd","createParentPath","hash","createHash","fileSize","completed","writeStream","createWriteStream","writePromise","Promise","resolve","reject","on","err","cleanup","end","complete","Buffer","concat","dataHandler","data","write","update","length","getFilePath","getFileSize","getHash","digest","getWritePromise","memHandler","buffers","getBuffer","push"],"rangeMappings":";;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;","mappings":"AAAA,OAAOA,YAAY,SAAQ;AAC3B,OAAOC,MAAMC,WAAW,QAAQ,KAAI;AACpC,OAAOC,UAAU,OAAM;AAIvB,SAASC,eAAe,EAAEC,QAAQ,EAAEC,UAAU,EAAEC,eAAe,QAAQ,iBAAgB;AAgBvF,OAAO,MAAMC,kBAA2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AMnB,QAAQC,OAAO,CAAC;IACzC;AACF,EAAC"}
|
|
@@ -11,7 +11,7 @@ export type FileShape = {
|
|
|
11
11
|
tempFilePath: string;
|
|
12
12
|
truncated: boolean;
|
|
13
13
|
};
|
|
14
|
-
export type
|
|
14
|
+
export type FetchAPIFileUploadOptions = {
|
|
15
15
|
/**
|
|
16
16
|
* Returns a HTTP 413 when the file is bigger than the size limit if `true`.
|
|
17
17
|
* Otherwise, it will add a `truncated = true` to the resulting file structure.
|
|
@@ -111,25 +111,25 @@ export type NextFileUploadOptions = {
|
|
|
111
111
|
*/
|
|
112
112
|
useTempFiles?: boolean | undefined;
|
|
113
113
|
} & Partial<BusboyConfig>;
|
|
114
|
-
type
|
|
114
|
+
type FetchAPIFileUploadResponseFile = {
|
|
115
115
|
data: Buffer;
|
|
116
116
|
mimetype: string;
|
|
117
117
|
name: string;
|
|
118
118
|
size: number;
|
|
119
119
|
tempFilePath?: string;
|
|
120
120
|
};
|
|
121
|
-
export type
|
|
121
|
+
export type FetchAPIFileUploadResponse = {
|
|
122
122
|
error?: {
|
|
123
123
|
code: number;
|
|
124
124
|
message: string;
|
|
125
125
|
};
|
|
126
126
|
fields: Record<string, string>;
|
|
127
|
-
files: Record<string,
|
|
127
|
+
files: Record<string, FetchAPIFileUploadResponseFile>;
|
|
128
128
|
};
|
|
129
|
-
type
|
|
130
|
-
options?:
|
|
129
|
+
type FetchAPIFileUpload = (args: {
|
|
130
|
+
options?: FetchAPIFileUploadOptions;
|
|
131
131
|
request: Request;
|
|
132
|
-
}) => Promise<
|
|
133
|
-
export declare const
|
|
132
|
+
}) => Promise<FetchAPIFileUploadResponse>;
|
|
133
|
+
export declare const fetchAPIFileUpload: FetchAPIFileUpload;
|
|
134
134
|
export {};
|
|
135
135
|
//# sourceMappingURL=index.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../../src/fetchAPI-multipart/index.ts"],"names":[],"mappings":";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G,SAAS,CAAA;IAChC;;;OAGG;IACH,aAAa,CAAC,EAAE,MAAM,GAAG,SAAS,CAAA;IAClC;;;OAGG;IACH,kBAAkB,CAAC,EAAE,OAAO,GAAG,SAAS,CAAA;IACxC;;;;;;OAMG;IACH,YAAY,CAAC,EAAE,OAAO,GAAG,SAAS,CAAA;CACnC,GAAG,OAAO,CAAC,YAAY,CAAC,CAAA;AAEzB,KAAK,8BAA8B,GAAG;IACpC,IAAI,EAAE,MAAM,CAAA;IACZ,QAAQ,EAAE,MAAM,CAAA;IAChB,IAAI,EAAE,MAAM,CAAA;IACZ,IAAI,EAAE,MAAM,CAAA;IACZ,YAAY,CAAC,EAAE,MAAM,CAAA;CACtB,CAAA;AAED,MAAM,MAAM,0BAA0B,GAAG;IACvC,KAAK,CAAC,EAAE;QACN,IAAI,EAAE,MAAM,CAAA;QACZ,OAAO,EAAE,MAAM,CAAA;KAChB,CAAA;IACD,MAAM,EAAE,MAAM,CAAC,MAAM,EAAE,MAAM,CAAC,CAAA;IAC9B,KAAK,EAAE,MAAM,CAAC,MAAM,EAAE,8BAA8B,CAAC,CAAA;CACtD,CAAA;AAED,KAAK,kBAAkB,GAAG,CAAC,IAAI,EAAE;IAC/B,OAAO,CAAC,EAAE,yBAAyB,CAAA;IACnC,OAAO,EAAE,OAAO,CAAA;CACjB,KAAK,OAAO,CAAC,0BAA0B,CAAC,CAAA;AACzC,eAAO,MAAM,kBAAkB,EAAE,kBAehC,CAAA"}
|
|
@@ -17,7 +17,7 @@ const DEFAULT_OPTIONS = {
|
|
|
17
17
|
uriDecodeFileNames: false,
|
|
18
18
|
useTempFiles: false
|
|
19
19
|
};
|
|
20
|
-
export const
|
|
20
|
+
export const fetchAPIFileUpload = async ({ options, request })=>{
|
|
21
21
|
const uploadOptions = {
|
|
22
22
|
...DEFAULT_OPTIONS,
|
|
23
23
|
...options
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"sources":["../../src/fetchAPI-multipart/index.ts"],"sourcesContent":["import type { BusboyConfig } from 'busboy'\n\nimport path from 'path'\n\nimport { isEligibleRequest } from './isEligibleRequest.js'\nimport { processMultipart } from './processMultipart.js'\nimport { debugLog } from './utilities.js'\n\nconst DEFAULT_OPTIONS = {\n abortOnLimit: false,\n createParentPath: false,\n debug: false,\n fileHandler: false,\n limitHandler: false,\n parseNested: false,\n preserveExtension: false,\n responseOnLimit: 'File size limit has been reached',\n safeFileNames: false,\n tempFileDir: path.join(process.cwd(), 'tmp'),\n uploadTimeout: 60000,\n uriDecodeFileNames: false,\n useTempFiles: false,\n}\n\nexport type FileShape = {\n data: Buffer\n encoding: string\n md5: Buffer | string\n mimetype: string\n mv: (filePath: string, callback: () => void) => Promise<void> | void\n name: string\n size: number\n tempFilePath: string\n truncated: boolean\n}\n\nexport type FetchAPIFileUploadOptions = {\n /**\n * Returns a HTTP 413 when the file is bigger than the size limit if `true`.\n * Otherwise, it will add a `truncated = true` to the resulting file structure.\n * @default false\n */\n abortOnLimit?: boolean | undefined\n /**\n * Automatically creates the directory path specified in `.mv(filePathName)`\n * @default false\n */\n createParentPath?: boolean | undefined\n /**\n * Turn on/off upload process logging. Can be useful for troubleshooting.\n * @default false\n */\n debug?: boolean | undefined\n /**\n * User defined limit handler which will be invoked if the file is bigger than configured limits.\n * @default false\n */\n limitHandler?: ((args: { request: Request; size: number }) => void) | boolean | undefined\n /**\n * By default, `req.body` and `req.files` are flattened like this:\n * `{'name': 'John', 'hobbies[0]': 'Cinema', 'hobbies[1]': 'Bike'}\n *\n * When this option is enabled they are parsed in order to be nested like this:\n * `{'name': 'John', 'hobbies': ['Cinema', 'Bike']}`\n * @default false\n */\n parseNested?: boolean | undefined\n /**\n * Preserves filename extension when using `safeFileNames` option.\n * If set to `true`, will default to an extension length of `3`.\n * If set to `number`, this will be the max allowable extension length.\n * If an extension is smaller than the extension length, it remains untouched. If the extension is longer,\n * it is shifted.\n * @default false\n *\n * @example\n * // true\n * app.use(fileUpload({ safeFileNames: true, preserveExtension: true }));\n * // myFileName.ext --> myFileName.ext\n *\n * @example\n * // max extension length 2, extension shifted\n * app.use(fileUpload({ safeFileNames: true, preserveExtension: 2 }));\n * // myFileName.ext --> myFileNamee.xt\n */\n preserveExtension?: boolean | number | undefined\n /**\n * Response which will be send to client if file size limit exceeded when `abortOnLimit` set to `true`.\n * @default 'File size limit has been reached'\n */\n responseOnLimit?: string | undefined\n /**\n * Strips characters from the upload's filename.\n * You can use custom regex to determine what to strip.\n * If set to `true`, non-alphanumeric characters _except_ dashes and underscores will be stripped.\n * This option is off by default.\n * @default false\n *\n * @example\n * // strip slashes from file names\n * app.use(fileUpload({ safeFileNames: /\\\\/g }))\n *\n * @example\n * app.use(fileUpload({ safeFileNames: true }))\n */\n safeFileNames?: RegExp | boolean | undefined\n /**\n * Path to store temporary files.\n * Used along with the `useTempFiles` option. By default this module uses `'tmp'` folder\n * in the current working directory.\n * You can use trailing slash, but it is not necessary.\n * @default './tmp'\n */\n tempFileDir?: string | undefined\n /**\n * This defines how long to wait for data before aborting. Set to `0` if you want to turn off timeout checks.\n * @default 60_000\n */\n uploadTimeout?: number | undefined\n /**\n * Applies uri decoding to file names if set `true`.\n * @default false\n */\n uriDecodeFileNames?: boolean | undefined\n /**\n * By default this module uploads files into RAM.\n * Setting this option to `true` turns on using temporary files instead of utilising RAM.\n * This avoids memory overflow issues when uploading large files or in case of uploading\n * lots of files at same time.\n * @default false\n */\n useTempFiles?: boolean | undefined\n} & Partial<BusboyConfig>\n\ntype FetchAPIFileUploadResponseFile = {\n data: Buffer\n mimetype: string\n name: string\n size: number\n tempFilePath?: string\n}\n\nexport type FetchAPIFileUploadResponse = {\n error?: {\n code: number\n message: string\n }\n fields: Record<string, string>\n files: Record<string, FetchAPIFileUploadResponseFile>\n}\n\ntype FetchAPIFileUpload = (args: {\n options?: FetchAPIFileUploadOptions\n request: Request\n}) => Promise<FetchAPIFileUploadResponse>\nexport const fetchAPIFileUpload: FetchAPIFileUpload = async ({ options, request }) => {\n const uploadOptions = { ...DEFAULT_OPTIONS, ...options }\n if (!isEligibleRequest(request)) {\n debugLog(uploadOptions, 'Request is not eligible for file upload!')\n return {\n error: {\n code: 500,\n message: 'Request is not eligible for file upload',\n },\n fields: undefined,\n files: undefined,\n }\n } else {\n return processMultipart({ options: uploadOptions, request })\n }\n}\n"],"names":["path","isEligibleRequest","processMultipart","debugLog","DEFAULT_OPTIONS","abortOnLimit","createParentPath","debug","fileHandler","limitHandler","parseNested","preserveExtension","responseOnLimit","safeFileNames","tempFileDir","join","process","cwd","uploadTimeout","uriDecodeFileNames","useTempFiles","fetchAPIFileUpload","options","request","uploadOptions","error","code","message","fields","undefined","files"],"rangeMappings":";;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;","mappings":"AAEA,OAAOA,UAAU,OAAM;AAEvB,SAASC,iBAAiB,QAAQ,yBAAwB;AAC1D,SAASC,gBAAgB,QAAQ,wBAAuB;AACxD,SAASC,QAAQ,QAAQ,iBAAgB;AAEzC,MAAMC,kBAAkB;IACtBC,cAAc;IACdC,kBAAkB;IAClBC,OAAO;IACPC,aAAa;IACbC,cAAc;IACdC,aAAa;IACbC,mBAAmB;IACnBC,iBAAiB;IACjBC,eAAe;IACfC,aAAad,KAAKe,IAAI,CAACC,QAAQC,GAAG,IAAI;IACtCC,eAAe;IACfC,oBAAoB;IACpBC,cAAc;AAChB;AAqIA,OAAO,MAAMC,qBAAyC,OAAO,EAAEC,OAAO,EAAEC,OAAO,EAAE;IAC/E,MAAMC,gBAAgB;QAAE,GAAGpB,eAAe;QAAE,GAAGkB,OAAO;IAAC;IACvD,IAAI,CAACrB,kBAAkBsB,UAAU;QAC/BpB,SAASqB,eAAe;QACxB,OAAO;YACLC,OAAO;gBACLC,MAAM;gBACNC,SAAS;YACX;YACAC,QAAQC;YACRC,OAAOD;QACT;IACF,OAAO;QACL,OAAO3B,iBAAiB;YAAEoB,SAASE;YAAeD;QAAQ;IAC5D;AACF,EAAC"}
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"isEligibleRequest.d.ts","sourceRoot":"","sources":["../../src/fetchAPI-multipart/isEligibleRequest.ts"],"names":[],"mappings":"AAiBA,eAAO,MAAM,iBAAiB,QAAS,OAAO,KAAG,OAMhD,CAAA"}
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"sources":["../../src/fetchAPI-multipart/isEligibleRequest.ts"],"sourcesContent":["const ACCEPTABLE_CONTENT_TYPE = /multipart\\/['\"()+-_]+(?:; ?['\"()+-_]*)+$/i\nconst UNACCEPTABLE_METHODS = new Set(['GET', 'HEAD', 'DELETE', 'OPTIONS', 'CONNECT', 'TRACE'])\n\nconst hasBody = (req: Request): boolean => {\n return Boolean(\n req.headers.get('transfer-encoding') ||\n (req.headers.get('content-length') && req.headers.get('content-length') !== '0'),\n )\n}\n\nconst hasAcceptableMethod = (req: Request): boolean => !UNACCEPTABLE_METHODS.has(req.method)\n\nconst hasAcceptableContentType = (req: Request): boolean => {\n const contType = req.headers.get('content-type')\n return contType.includes('boundary=') && ACCEPTABLE_CONTENT_TYPE.test(contType)\n}\n\nexport const isEligibleRequest = (req: Request): boolean => {\n try {\n return hasBody(req) && hasAcceptableMethod(req) && hasAcceptableContentType(req)\n } catch (e) {\n return false\n }\n}\n"],"names":["ACCEPTABLE_CONTENT_TYPE","UNACCEPTABLE_METHODS","Set","hasBody","req","Boolean","headers","get","hasAcceptableMethod","has","method","hasAcceptableContentType","contType","includes","test","isEligibleRequest","e"],"rangeMappings":";;;;;;;;;;;;;;;;;;;;;;;","mappings":"AAAA,MAAMA,0BAA0B;AAChC,MAAMC,uBAAuB,IAAIC,IAAI;IAAC;IAAO;IAAQ;IAAU;IAAW;IAAW;CAAQ;AAE7F,MAAMC,UAAU,CAACC;IACf,OAAOC,QACLD,IAAIE,OAAO,CAACC,GAAG,CAAC,wBACbH,IAAIE,OAAO,CAACC,GAAG,CAAC,qBAAqBH,IAAIE,OAAO,CAACC,GAAG,CAAC,sBAAsB;AAElF;AAEA,MAAMC,sBAAsB,CAACJ,MAA0B,CAACH,qBAAqBQ,GAAG,CAACL,IAAIM,MAAM;AAE3F,MAAMC,2BAA2B,CAACP;IAChC,MAAMQ,WAAWR,IAAIE,OAAO,CAACC,GAAG,CAAC;IACjC,OAAOK,SAASC,QAAQ,CAAC,gBAAgBb,wBAAwBc,IAAI,CAACF;AACxE;AAEA,OAAO,MAAMG,oBAAoB,CAACX;IAChC,IAAI;QACF,OAAOD,QAAQC,QAAQI,oBAAoBJ,QAAQO,yBAAyBP;IAC9E,EAAE,OAAOY,GAAG;QACV,OAAO;IACT;AACF,EAAC"}
|
|
@@ -0,0 +1,8 @@
|
|
|
1
|
+
import type { FetchAPIFileUploadOptions, FetchAPIFileUploadResponse } from './index.js';
|
|
2
|
+
type ProcessMultipart = (args: {
|
|
3
|
+
options: FetchAPIFileUploadOptions;
|
|
4
|
+
request: Request;
|
|
5
|
+
}) => Promise<FetchAPIFileUploadResponse>;
|
|
6
|
+
export declare const processMultipart: ProcessMultipart;
|
|
7
|
+
export {};
|
|
8
|
+
//# sourceMappingURL=processMultipart.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"processMultipart.d.ts","sourceRoot":"","sources":["../../src/fetchAPI-multipart/processMultipart.ts"],"names":[],"mappings":"AAIA,OAAO,KAAK,EAAE,yBAAyB,EAAE,0BAA0B,EAAE,MAAM,YAAY,CAAA;AAUvF,KAAK,gBAAgB,GAAG,CAAC,IAAI,EAAE;IAC7B,OAAO,EAAE,yBAAyB,CAAA;IAClC,OAAO,EAAE,OAAO,CAAA;CACjB,KAAK,OAAO,CAAC,0BAA0B,CAAC,CAAA;AACzC,eAAO,MAAM,gBAAgB,EAAE,gBAoL9B,CAAA"}
|
|
@@ -1,4 +1,5 @@
|
|
|
1
1
|
import Busboy from 'busboy';
|
|
2
|
+
import httpStatus from 'http-status';
|
|
2
3
|
import { APIError } from 'payload/errors';
|
|
3
4
|
import { fileFactory } from './fileFactory.js';
|
|
4
5
|
import { memHandler, tempFileHandler } from './handlers.js';
|
|
@@ -8,6 +9,14 @@ import { buildFields, debugLog, isFunc, parseFileName } from './utilities.js';
|
|
|
8
9
|
const waitFlushProperty = Symbol('wait flush property symbol');
|
|
9
10
|
export const processMultipart = async ({ options, request })=>{
|
|
10
11
|
let parsingRequest = true;
|
|
12
|
+
let fileCount = 0;
|
|
13
|
+
let filesCompleted = 0;
|
|
14
|
+
let allFilesHaveResolved;
|
|
15
|
+
let failedResolvingFiles;
|
|
16
|
+
const allFilesComplete = new Promise((res, rej)=>{
|
|
17
|
+
allFilesHaveResolved = res;
|
|
18
|
+
failedResolvingFiles = rej;
|
|
19
|
+
});
|
|
11
20
|
const result = {
|
|
12
21
|
fields: undefined,
|
|
13
22
|
files: undefined
|
|
@@ -26,6 +35,7 @@ export const processMultipart = async ({ options, request })=>{
|
|
|
26
35
|
});
|
|
27
36
|
// Build req.files fields
|
|
28
37
|
busboy.on('file', (field, file, info)=>{
|
|
38
|
+
fileCount += 1;
|
|
29
39
|
// Parse file name(cutting huge names, decoding, etc..).
|
|
30
40
|
const { encoding, filename: name, mimeType: mime } = info;
|
|
31
41
|
const filename = parseFileName(options, name);
|
|
@@ -57,7 +67,7 @@ export const processMultipart = async ({ options, request })=>{
|
|
|
57
67
|
debugLog(options, `Aborting upload because of size limit ${field}->${filename}.`);
|
|
58
68
|
cleanup();
|
|
59
69
|
parsingRequest = false;
|
|
60
|
-
throw new APIError(options.responseOnLimit,
|
|
70
|
+
throw new APIError(options.responseOnLimit, httpStatus.REQUEST_ENTITY_TOO_LARGE, {
|
|
61
71
|
size: getFileSize()
|
|
62
72
|
});
|
|
63
73
|
}
|
|
@@ -77,6 +87,7 @@ export const processMultipart = async ({ options, request })=>{
|
|
|
77
87
|
}
|
|
78
88
|
return debugLog(options, `Don't add file instance if original name and size are empty`);
|
|
79
89
|
}
|
|
90
|
+
filesCompleted += 1;
|
|
80
91
|
result.files = buildFields(result.files, field, fileFactory({
|
|
81
92
|
name: filename,
|
|
82
93
|
buffer: complete(),
|
|
@@ -91,33 +102,44 @@ export const processMultipart = async ({ options, request })=>{
|
|
|
91
102
|
request[waitFlushProperty] = [];
|
|
92
103
|
}
|
|
93
104
|
request[waitFlushProperty].push(writePromise);
|
|
105
|
+
if (filesCompleted === fileCount) {
|
|
106
|
+
allFilesHaveResolved();
|
|
107
|
+
}
|
|
94
108
|
});
|
|
95
109
|
file.on('error', (err)=>{
|
|
96
110
|
uploadTimer.clear();
|
|
97
111
|
debugLog(options, `File Error: ${err.message}`);
|
|
98
112
|
cleanup();
|
|
113
|
+
failedResolvingFiles(err);
|
|
99
114
|
});
|
|
115
|
+
// Start upload process.
|
|
100
116
|
debugLog(options, `New upload started ${field}->${filename}, bytes:${getFileSize()}`);
|
|
101
117
|
uploadTimer.set();
|
|
102
118
|
});
|
|
103
|
-
busboy.on('finish', ()=>{
|
|
119
|
+
busboy.on('finish', async ()=>{
|
|
104
120
|
debugLog(options, `Busboy finished parsing request.`);
|
|
105
121
|
if (options.parseNested) {
|
|
106
122
|
result.fields = processNested(result.fields);
|
|
107
123
|
result.files = processNested(result.files);
|
|
108
124
|
}
|
|
109
125
|
if (request[waitFlushProperty]) {
|
|
110
|
-
|
|
111
|
-
|
|
112
|
-
|
|
126
|
+
try {
|
|
127
|
+
await Promise.all(request[waitFlushProperty]).then(()=>{
|
|
128
|
+
delete request[waitFlushProperty];
|
|
129
|
+
});
|
|
130
|
+
} catch (err) {
|
|
131
|
+
debugLog(options, `Error waiting for file write promises: ${err}`);
|
|
132
|
+
}
|
|
113
133
|
}
|
|
134
|
+
return result;
|
|
114
135
|
});
|
|
115
136
|
busboy.on('error', (err)=>{
|
|
116
137
|
debugLog(options, `Busboy error`);
|
|
117
138
|
parsingRequest = false;
|
|
118
|
-
throw new APIError('Busboy error parsing multipart request',
|
|
139
|
+
throw new APIError('Busboy error parsing multipart request', httpStatus.BAD_REQUEST);
|
|
119
140
|
});
|
|
120
141
|
const reader = request.body.getReader();
|
|
142
|
+
// Start parsing request
|
|
121
143
|
while(parsingRequest){
|
|
122
144
|
const { done, value } = await reader.read();
|
|
123
145
|
if (done) {
|
|
@@ -127,6 +149,7 @@ export const processMultipart = async ({ options, request })=>{
|
|
|
127
149
|
busboy.write(value);
|
|
128
150
|
}
|
|
129
151
|
}
|
|
152
|
+
if (fileCount !== 0) await allFilesComplete;
|
|
130
153
|
return result;
|
|
131
154
|
};
|
|
132
155
|
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"sources":["../../src/fetchAPI-multipart/processMultipart.ts"],"sourcesContent":["import Busboy from 'busboy'\nimport httpStatus from 'http-status'\nimport { APIError } from 'payload/errors'\n\nimport type { FetchAPIFileUploadOptions, FetchAPIFileUploadResponse } from './index.js'\n\nimport { fileFactory } from './fileFactory.js'\nimport { memHandler, tempFileHandler } from './handlers.js'\nimport { processNested } from './processNested.js'\nimport { createUploadTimer } from './uploadTimer.js'\nimport { buildFields, debugLog, isFunc, parseFileName } from './utilities.js'\n\nconst waitFlushProperty = Symbol('wait flush property symbol')\n\ntype ProcessMultipart = (args: {\n options: FetchAPIFileUploadOptions\n request: Request\n}) => Promise<FetchAPIFileUploadResponse>\nexport const processMultipart: ProcessMultipart = async ({ options, request }) => {\n let parsingRequest = true\n\n let fileCount = 0\n let filesCompleted = 0\n let allFilesHaveResolved: (value?: unknown) => void\n let failedResolvingFiles: (err: Error) => void\n\n const allFilesComplete = new Promise((res, rej) => {\n allFilesHaveResolved = res\n failedResolvingFiles = rej\n })\n\n const result: FetchAPIFileUploadResponse = {\n fields: undefined,\n files: undefined,\n }\n\n const headersObject = {}\n request.headers.forEach((value, name) => {\n headersObject[name] = value\n })\n\n const busboy = Busboy({ ...options, headers: headersObject })\n\n // Build multipart req.body fields\n busboy.on('field', (field, val) => {\n result.fields = buildFields(result.fields, field, val)\n })\n\n // Build req.files fields\n busboy.on('file', (field, file, info) => {\n fileCount += 1\n // Parse file name(cutting huge names, decoding, etc..).\n const { encoding, filename: name, mimeType: mime } = info\n const filename = parseFileName(options, name)\n\n // Define methods and handlers for upload process.\n const { cleanup, complete, dataHandler, getFilePath, getFileSize, getHash, getWritePromise } =\n options.useTempFiles\n ? tempFileHandler(options, field, filename) // Upload into temporary file.\n : memHandler(options, field, filename) // Upload into RAM.\n\n const writePromise = options.useTempFiles\n ? getWritePromise().catch((err) => {\n busboy.end()\n cleanup()\n })\n : getWritePromise()\n\n const uploadTimer = createUploadTimer(options.uploadTimeout, () => {\n file.removeAllListeners('data')\n file.resume()\n const err = new Error(`Upload timeout for ${field}->${filename}, bytes:${getFileSize()}`)\n return file.destroy(err)\n })\n\n file.on('limit', () => {\n debugLog(options, `Size limit reached for ${field}->${filename}, bytes:${getFileSize()}`)\n uploadTimer.clear()\n\n if (isFunc(options.limitHandler)) {\n options.limitHandler({ request, size: getFileSize() })\n }\n\n // Return error and cleanup files if abortOnLimit set.\n if (options.abortOnLimit) {\n debugLog(options, `Aborting upload because of size limit ${field}->${filename}.`)\n cleanup()\n parsingRequest = false\n throw new APIError(options.responseOnLimit, httpStatus.REQUEST_ENTITY_TOO_LARGE, {\n size: getFileSize(),\n })\n }\n })\n\n file.on('data', (data) => {\n uploadTimer.set()\n dataHandler(data)\n })\n\n file.on('end', () => {\n const size = getFileSize()\n debugLog(options, `Upload finished ${field}->${filename}, bytes:${size}`)\n uploadTimer.clear()\n\n if (!name && size === 0) {\n if (options.useTempFiles) {\n cleanup()\n debugLog(options, `Removing the empty file ${field}->${filename}`)\n }\n return debugLog(options, `Don't add file instance if original name and size are empty`)\n }\n\n filesCompleted += 1\n\n result.files = buildFields(\n result.files,\n field,\n fileFactory(\n {\n name: filename,\n buffer: complete(),\n encoding,\n hash: getHash(),\n mimetype: mime,\n size,\n tempFilePath: getFilePath(),\n truncated: Boolean('truncated' in file && file.truncated),\n },\n options,\n ),\n )\n\n if (!request[waitFlushProperty]) {\n request[waitFlushProperty] = []\n }\n request[waitFlushProperty].push(writePromise)\n\n if (filesCompleted === fileCount) {\n allFilesHaveResolved()\n }\n })\n\n file.on('error', (err) => {\n uploadTimer.clear()\n debugLog(options, `File Error: ${err.message}`)\n cleanup()\n failedResolvingFiles(err)\n })\n\n // Start upload process.\n debugLog(options, `New upload started ${field}->${filename}, bytes:${getFileSize()}`)\n uploadTimer.set()\n })\n\n busboy.on('finish', async () => {\n debugLog(options, `Busboy finished parsing request.`)\n if (options.parseNested) {\n result.fields = processNested(result.fields)\n result.files = processNested(result.files)\n }\n\n if (request[waitFlushProperty]) {\n try {\n await Promise.all(request[waitFlushProperty]).then(() => {\n delete request[waitFlushProperty]\n })\n } catch (err) {\n debugLog(options, `Error waiting for file write promises: ${err}`)\n }\n }\n\n return result\n })\n\n busboy.on('error', (err) => {\n debugLog(options, `Busboy error`)\n parsingRequest = false\n throw new APIError('Busboy error parsing multipart request', httpStatus.BAD_REQUEST)\n })\n\n const reader = request.body.getReader()\n\n // Start parsing request\n while (parsingRequest) {\n const { done, value } = await reader.read()\n\n if (done) {\n parsingRequest = false\n }\n\n if (value) {\n busboy.write(value)\n }\n }\n\n if (fileCount !== 0) await allFilesComplete\n\n return result\n}\n"],"names":["Busboy","httpStatus","APIError","fileFactory","memHandler","tempFileHandler","processNested","createUploadTimer","buildFields","debugLog","isFunc","parseFileName","waitFlushProperty","Symbol","processMultipart","options","request","parsingRequest","fileCount","filesCompleted","allFilesHaveResolved","failedResolvingFiles","allFilesComplete","Promise","res","rej","result","fields","undefined","files","headersObject","headers","forEach","value","name","busboy","on","field","val","file","info","encoding","filename","mimeType","mime","cleanup","complete","dataHandler","getFilePath","getFileSize","getHash","getWritePromise","useTempFiles","writePromise","catch","err","end","uploadTimer","uploadTimeout","removeAllListeners","resume","Error","destroy","clear","limitHandler","size","abortOnLimit","responseOnLimit","REQUEST_ENTITY_TOO_LARGE","data","set","buffer","hash","mimetype","tempFilePath","truncated","Boolean","push","message","parseNested","all","then","BAD_REQUEST","reader","body","getReader","done","read","write"],"rangeMappings":";;;;;;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,GAAG;IACjB;IAEAnC,OAAOC,EAAE,CAAC,UAAU;QAClB3B,SAASM,SAAS,CAAC,gCAAgC,CAAC;QACpD,IAAIA,QAAQgE,WAAW,EAAE;YACvBrD,OAAOC,MAAM,GAAGrB,cAAcoB,OAAOC,MAAM;YAC3CD,OAAOG,KAAK,GAAGvB,cAAcoB,OAAOG,KAAK;QAC3C;QAEA,IAAIb,OAAO,CAACJ,kBAAkB,EAAE;YAC9B,IAAI;gBACF,MAAMW,QAAQyD,GAAG,CAAChE,OAAO,CAACJ,kBAAkB,EAAEqE,IAAI,CAAC;oBACjD,OAAOjE,OAAO,CAACJ,kBAAkB;gBACnC;YACF,EAAE,OAAO2C,KAAK;gBACZ9C,SAASM,SAAS,CAAC,uCAAuC,EAAEwC,IAAI,CAAC;YACnE;QACF;QAEA,OAAO7B;IACT;IAEAS,OAAOC,EAAE,CAAC,SAAS,CAACmB;QAClB9C,SAASM,SAAS,CAAC,YAAY,CAAC;QAChCE,iBAAiB;QACjB,MAAM,IAAIf,SAAS,0CAA0CD,WAAWiF,WAAW;IACrF;IAEA,MAAMC,SAASnE,QAAQoE,IAAI,CAACC,SAAS;IAErC,wBAAwB;IACxB,MAAOpE,eAAgB;QACrB,MAAM,EAAEqE,IAAI,EAAErD,KAAK,EAAE,GAAG,MAAMkD,OAAOI,IAAI;QAEzC,IAAID,MAAM;YACRrE,iBAAiB;QACnB;QAEA,IAAIgB,OAAO;YACTE,OAAOqD,KAAK,CAACvD;QACf;IACF;IAEA,IAAIf,cAAc,GAAG,MAAMI;IAE3B,OAAOI;AACT,EAAC"}
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"processNested.d.ts","sourceRoot":"","sources":["../../src/fetchAPI-multipart/processNested.ts"],"names":[],"mappings":"AAEA,eAAO,MAAM,aAAa,oBA6BzB,CAAA"}
|
|
@@ -3,7 +3,8 @@ export const processNested = function(data) {
|
|
|
3
3
|
if (!data || data.length < 1) return Object.create(null);
|
|
4
4
|
const d = Object.create(null), keys = Object.keys(data);
|
|
5
5
|
for(let i = 0; i < keys.length; i++){
|
|
6
|
-
|
|
6
|
+
const key = keys[i], value = data[key], keyParts = key.replace(new RegExp(/\[/g), '.').replace(new RegExp(/\]/g), '').split('.');
|
|
7
|
+
let current = d;
|
|
7
8
|
for(let index = 0; index < keyParts.length; index++){
|
|
8
9
|
const k = keyParts[index];
|
|
9
10
|
// Ensure we don't allow prototype pollution
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"sources":["../../src/fetchAPI-multipart/processNested.ts"],"sourcesContent":["import { isSafeFromPollution } from './utilities.js'\n\nexport const processNested = function (data) {\n if (!data || data.length < 1) return Object.create(null)\n\n const d = Object.create(null),\n keys = Object.keys(data)\n\n for (let i = 0; i < keys.length; i++) {\n const key = keys[i],\n value = data[key],\n keyParts = key.replace(new RegExp(/\\[/g), '.').replace(new RegExp(/\\]/g), '').split('.')\n let current = d\n\n for (let index = 0; index < keyParts.length; index++) {\n const k = keyParts[index]\n\n // Ensure we don't allow prototype pollution\n if (!isSafeFromPollution(current, k)) {\n continue\n }\n\n if (index >= keyParts.length - 1) {\n current[k] = value\n } else {\n if (!current[k]) current[k] = !keyParts[index + 1] ? [] : Object.create(null)\n current = current[k]\n }\n }\n }\n return d\n}\n"],"names":["isSafeFromPollution","processNested","data","length","Object","create","d","keys","i","key","value","keyParts","replace","RegExp","split","current","index","k"],"rangeMappings":";;;;;;;;;;;;;;;;;;;;;;","mappings":"AAAA,SAASA,mBAAmB,QAAQ,iBAAgB;AAEpD,OAAO,MAAMC,gBAAgB,SAAUC,IAAI;IACzC,IAAI,CAACA,QAAQA,KAAKC,MAAM,GAAG,GAAG,OAAOC,OAAOC,MAAM,CAAC;IAEnD,MAAMC,IAAIF,OAAOC,MAAM,CAAC,OACtBE,OAAOH,OAAOG,IAAI,CAACL;IAErB,IAAK,IAAIM,IAAI,GAAGA,IAAID,KAAKJ,MAAM,EAAEK,IAAK;QACpC,MAAMC,MAAMF,IAAI,CAACC,EAAE,EACjBE,QAAQR,IAAI,CAACO,IAAI,EACjBE,WAAWF,IAAIG,OAAO,CAAC,IAAIC,OAAO,QAAQ,KAAKD,OAAO,CAAC,IAAIC,OAAO,QAAQ,IAAIC,KAAK,CAAC;QACtF,IAAIC,UAAUT;QAEd,IAAK,IAAIU,QAAQ,GAAGA,QAAQL,SAASR,MAAM,EAAEa,QAAS;YACpD,MAAMC,IAAIN,QAAQ,CAACK,MAAM;YAEzB,4CAA4C;YAC5C,IAAI,CAAChB,oBAAoBe,SAASE,IAAI;gBACpC;YACF;YAEA,IAAID,SAASL,SAASR,MAAM,GAAG,GAAG;gBAChCY,OAAO,CAACE,EAAE,GAAGP;YACf,OAAO;gBACL,IAAI,CAACK,OAAO,CAACE,EAAE,EAAEF,OAAO,CAACE,EAAE,GAAG,CAACN,QAAQ,CAACK,QAAQ,EAAE,GAAG,EAAE,GAAGZ,OAAOC,MAAM,CAAC;gBACxEU,UAAUA,OAAO,CAACE,EAAE;YACtB;QACF;IACF;IACA,OAAOX;AACT,EAAC"}
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"uploadTimer.d.ts","sourceRoot":"","sources":["../../src/fetchAPI-multipart/uploadTimer.ts"],"names":[],"mappings":"AAAA,KAAK,iBAAiB,GAAG,CACvB,OAAO,CAAC,EAAE,MAAM,EAChB,QAAQ,CAAC,EAAE,MAAM,IAAI,KAClB;IACH,KAAK,EAAE,MAAM,IAAI,CAAA;IACjB,GAAG,EAAE,MAAM,OAAO,CAAA;CACnB,CAAA;AAED,eAAO,MAAM,iBAAiB,EAAE,iBAgB/B,CAAA"}
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"sources":["../../src/fetchAPI-multipart/uploadTimer.ts"],"sourcesContent":["type CreateUploadTimer = (\n timeout?: number,\n callback?: () => void,\n) => {\n clear: () => void\n set: () => boolean\n}\n\nexport const createUploadTimer: CreateUploadTimer = (timeout = 0, callback = () => {}) => {\n let timer = null\n\n const clear = () => {\n clearTimeout(timer)\n }\n\n const set = () => {\n // Do not start a timer if zero timeout or it hasn't been set.\n if (!timeout) return false\n clear()\n timer = setTimeout(callback, timeout)\n return true\n }\n\n return { clear, set }\n}\n"],"names":["createUploadTimer","timeout","callback","timer","clear","clearTimeout","set","setTimeout"],"rangeMappings":";;;;;;;;;;;;;;;;","mappings":"AAQA,OAAO,MAAMA,oBAAuC,CAACC,UAAU,CAAC,EAAEC,WAAW,KAAO,CAAC;IACnF,IAAIC,QAAQ;IAEZ,MAAMC,QAAQ;QACZC,aAAaF;IACf;IAEA,MAAMG,MAAM;QACV,8DAA8D;QAC9D,IAAI,CAACL,SAAS,OAAO;QACrBG;QACAD,QAAQI,WAAWL,UAAUD;QAC7B,OAAO;IACT;IAEA,OAAO;QAAEG;QAAOE;IAAI;AACtB,EAAC"}
|
|
@@ -1,8 +1,8 @@
|
|
|
1
|
-
import type {
|
|
1
|
+
import type { FetchAPIFileUploadOptions } from './index.js';
|
|
2
2
|
/**
|
|
3
3
|
* Logs message to console if options.debug option set to true.
|
|
4
4
|
*/
|
|
5
|
-
export declare const debugLog: (options:
|
|
5
|
+
export declare const debugLog: (options: FetchAPIFileUploadOptions, msg: string) => boolean;
|
|
6
6
|
/**
|
|
7
7
|
* Generates unique temporary file name. e.g. tmp-5000-156788789789.
|
|
8
8
|
*/
|
|
@@ -29,7 +29,7 @@ export declare const buildFields: BuildFields;
|
|
|
29
29
|
* Creates a folder if it does not exist
|
|
30
30
|
* for file specified in the path variable
|
|
31
31
|
*/
|
|
32
|
-
type CheckAndMakeDir = (fileUploadOptions:
|
|
32
|
+
type CheckAndMakeDir = (fileUploadOptions: FetchAPIFileUploadOptions, filePath: string) => boolean;
|
|
33
33
|
export declare const checkAndMakeDir: CheckAndMakeDir;
|
|
34
34
|
/**
|
|
35
35
|
* Delete a file.
|
|
@@ -59,7 +59,7 @@ export declare const parseFileNameExtension: ParseFileNameExtension;
|
|
|
59
59
|
/**
|
|
60
60
|
* Parse file name and extension.
|
|
61
61
|
*/
|
|
62
|
-
type ParseFileName = (opts:
|
|
62
|
+
type ParseFileName = (opts: FetchAPIFileUploadOptions, fileName: string) => string;
|
|
63
63
|
export declare const parseFileName: ParseFileName;
|
|
64
64
|
export {};
|
|
65
65
|
//# sourceMappingURL=utilities.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"utilities.d.ts","sourceRoot":"","sources":["../../src/fetchAPI-multipart/utilities.ts"],"names":[],"mappings":"AAIA,OAAO,KAAK,EAAE,yBAAyB,EAAE,MAAM,YAAY,CAAA;AAW3D;;GAEG;AACH,eAAO,MAAM,QAAQ,YAAa,yBAAyB,OAAO,MAAM,YAKvE,CAAA;AAED;;GAEG;AACH,eAAO,MAAM,eAAe,YAAY,MAAM,WAG7C,CAAA;AAED,KAAK,QAAQ,GAAG,CAAC,GAAG,IAAI,EAAE,GAAG,EAAE,KAAK,GAAG,CAAA;AACvC,eAAO,MAAM,MAAM,UAAW,GAAG,sBAEhC,CAAA;AAQD;;;GAGG;AACH,KAAK,eAAe,GAAG,CAAC,OAAO,EAAE,MAAM,IAAI,EAAE,MAAM,EAAE,CAAC,GAAG,EAAE,KAAK,KAAK,IAAI,KAAK,CAAC,GAAG,EAAE,KAAK,KAAK,IAAI,CAAA;AAClG,eAAO,MAAM,eAAe,EAAE,eAU7B,CAAA;AAOD;;GAEG;AACH,KAAK,mBAAmB,GAAG,CAAC,IAAI,EAAE,GAAG,EAAE,GAAG,EAAE,MAAM,KAAK,OAAO,CAAA;AAC9D,eAAO,MAAM,mBAAmB,EAAE,mBAQjC,CAAA;AAED;;GAEG;AACH,KAAK,WAAW,GAAG,CAAC,QAAQ,EAAE,GAAG,EAAE,KAAK,EAAE,MAAM,EAAE,KAAK,EAAE,GAAG,KAAK,GAAG,CAAA;AACpE,eAAO,MAAM,WAAW,EAAE,WAoBzB,CAAA;AAED;;;GAGG;AACH,KAAK,eAAe,GAAG,CAAC,iBAAiB,EAAE,yBAAyB,EAAE,QAAQ,EAAE,MAAM,KAAK,OAAO,CAAA;AAClG,eAAO,MAAM,eAAe,EAAE,eAQ7B,CAAA;AAED;;GAEG;AACH,KAAK,UAAU,GAAG,CAAC,QAAQ,EAAE,MAAM,EAAE,QAAQ,EAAE,CAAC,IAAI,EAAE,GAAG,KAAK,IAAI,KAAK,IAAI,CAAA;AAC3E,eAAO,MAAM,UAAU,EAAE,UACM,CAAA;AA4B/B;;;GAGG;AACH,KAAK,QAAQ,GAAG,CACd,GAAG,EAAE,MAAM,EACX,GAAG,EAAE,MAAM,EACX,QAAQ,EAAE,CAAC,GAAG,EAAE,KAAK,EAAE,OAAO,CAAC,EAAE,OAAO,KAAK,IAAI,KAC9C,IAAI,CAAA;AACT,eAAO,MAAM,QAAQ,EAAE,QASnB,CAAA;AAEJ;;;;GAIG;AACH,eAAO,MAAM,gBAAgB,oDAwB5B,CAAA;AA+BD;;GAEG;AACH,KAAK,sBAAsB,GAAG,CAC5B,iBAAiB,EAAE,OAAO,GAAG,MAAM,EACnC,QAAQ,EAAE,MAAM,KACb;IACH,SAAS,EAAE,MAAM,CAAA;IACjB,IAAI,EAAE,MAAM,CAAA;CACb,CAAA;AACD,eAAO,MAAM,sBAAsB,EAAE,sBAwBpC,CAAA;AAED;;GAEG;AACH,KAAK,aAAa,GAAG,CAAC,IAAI,EAAE,yBAAyB,EAAE,QAAQ,EAAE,MAAM,KAAK,MAAM,CAAA;AAClF,eAAO,MAAM,aAAa,EAAE,aAoB3B,CAAA"}
|
|
@@ -13,7 +13,7 @@ let tempCounter = 0;
|
|
|
13
13
|
*/ export const debugLog = (options, msg)=>{
|
|
14
14
|
const opts = options || {};
|
|
15
15
|
if (!opts.debug) return false;
|
|
16
|
-
console.log(`
|
|
16
|
+
console.log(`Next-file-upload: ${msg}`) // eslint-disable-line
|
|
17
17
|
;
|
|
18
18
|
return true;
|
|
19
19
|
};
|
|
@@ -199,9 +199,9 @@ export const parseFileName = (opts, fileName)=>{
|
|
|
199
199
|
// Set regular expression for the file name.
|
|
200
200
|
const nameRegex = typeof opts.safeFileNames === 'object' && opts.safeFileNames instanceof RegExp ? opts.safeFileNames : SAFE_FILE_NAME_REGEX;
|
|
201
201
|
// Parse file name extension.
|
|
202
|
-
|
|
203
|
-
if (extension.length) extension = '.' + extension.replace(nameRegex, '');
|
|
204
|
-
return name.replace(nameRegex, '').concat(extension);
|
|
202
|
+
const parsedFileName = parseFileNameExtension(opts.preserveExtension, parsedName);
|
|
203
|
+
if (parsedFileName.extension.length) parsedFileName.extension = '.' + parsedFileName.extension.replace(nameRegex, '');
|
|
204
|
+
return parsedFileName.name.replace(nameRegex, '').concat(parsedFileName.extension);
|
|
205
205
|
};
|
|
206
206
|
|
|
207
207
|
//# sourceMappingURL=utilities.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"sources":["../../src/fetchAPI-multipart/utilities.ts"],"sourcesContent":["import fs from 'fs'\nimport path from 'path'\nimport { Readable } from 'stream'\n\nimport type { FetchAPIFileUploadOptions } from './index.js'\n\n// Parameters for safe file name parsing.\nconst SAFE_FILE_NAME_REGEX = /[^\\w-]/g\nconst MAX_EXTENSION_LENGTH = 3\n\n// Parameters to generate unique temporary file names:\nconst TEMP_COUNTER_MAX = 65536\nconst TEMP_PREFIX = 'tmp'\nlet tempCounter = 0\n\n/**\n * Logs message to console if options.debug option set to true.\n */\nexport const debugLog = (options: FetchAPIFileUploadOptions, msg: string) => {\n const opts = options || {}\n if (!opts.debug) return false\n console.log(`Next-file-upload: ${msg}`) // eslint-disable-line\n return true\n}\n\n/**\n * Generates unique temporary file name. e.g. tmp-5000-156788789789.\n */\nexport const getTempFilename = (prefix: string = TEMP_PREFIX) => {\n tempCounter = tempCounter >= TEMP_COUNTER_MAX ? 1 : tempCounter + 1\n return `${prefix}-${tempCounter}-${Date.now()}`\n}\n\ntype FuncType = (...args: any[]) => any\nexport const isFunc = (value: any): value is FuncType => {\n return typeof value === 'function'\n}\n\n/**\n * Set errorFunc to the same value as successFunc for callback mode.\n */\ntype ErrorFunc = (resolve: () => void, reject: (err: Error) => void) => (err: Error) => void\nconst errorFunc: ErrorFunc = (resolve, reject) => (isFunc(reject) ? reject : resolve)\n\n/**\n * Return a callback function for promise resole/reject args.\n * Ensures that callback is called only once.\n */\ntype PromiseCallback = (resolve: () => void, reject: (err: Error) => void) => (err: Error) => void\nexport const promiseCallback: PromiseCallback = (resolve, reject) => {\n let hasFired = false\n return (err: Error) => {\n if (hasFired) {\n return\n }\n\n hasFired = true\n return err ? errorFunc(resolve, reject)(err) : resolve()\n }\n}\n\n// The default prototypes for both objects and arrays.\n// Used by isSafeFromPollution\nconst OBJECT_PROTOTYPE_KEYS = Object.getOwnPropertyNames(Object.prototype)\nconst ARRAY_PROTOTYPE_KEYS = Object.getOwnPropertyNames(Array.prototype)\n\n/**\n * Determines whether a key insertion into an object could result in a prototype pollution\n */\ntype IsSafeFromPollution = (base: any, key: string) => boolean\nexport const isSafeFromPollution: IsSafeFromPollution = (base, key) => {\n // We perform an instanceof check instead of Array.isArray as the former is more\n // permissive for cases in which the object as an Array prototype but was not constructed\n // via an Array constructor or literal.\n const TOUCHES_ARRAY_PROTOTYPE = base instanceof Array && ARRAY_PROTOTYPE_KEYS.includes(key)\n const TOUCHES_OBJECT_PROTOTYPE = OBJECT_PROTOTYPE_KEYS.includes(key)\n\n return !TOUCHES_ARRAY_PROTOTYPE && !TOUCHES_OBJECT_PROTOTYPE\n}\n\n/**\n * Build request field/file objects to return\n */\ntype BuildFields = (instance: any, field: string, value: any) => any\nexport const buildFields: BuildFields = (instance, field, value) => {\n // Do nothing if value is not set.\n if (value === null || value === undefined) return instance\n instance = instance || Object.create(null)\n\n if (!isSafeFromPollution(instance, field)) {\n return instance\n }\n // Non-array fields\n if (!instance[field]) {\n instance[field] = value\n return instance\n }\n // Array fields\n if (instance[field] instanceof Array) {\n instance[field].push(value)\n } else {\n instance[field] = [instance[field], value]\n }\n return instance\n}\n\n/**\n * Creates a folder if it does not exist\n * for file specified in the path variable\n */\ntype CheckAndMakeDir = (fileUploadOptions: FetchAPIFileUploadOptions, filePath: string) => boolean\nexport const checkAndMakeDir: CheckAndMakeDir = (fileUploadOptions, filePath) => {\n if (!fileUploadOptions.createParentPath) return false\n // Check whether folder for the file exists.\n const parentPath = path.dirname(filePath)\n // Create folder if it doesn't exist.\n if (!fs.existsSync(parentPath)) fs.mkdirSync(parentPath, { recursive: true })\n // Checks folder again and return a results.\n return fs.existsSync(parentPath)\n}\n\n/**\n * Delete a file.\n */\ntype DeleteFile = (filePath: string, callback: (args: any) => void) => void\nexport const deleteFile: DeleteFile = (filePath, callback: (args) => void) =>\n fs.unlink(filePath, callback)\n\n/**\n * Copy file via streams\n */\ntype CopyFile = (src: string, dst: string, callback: (err: Error) => void) => void\nconst copyFile: CopyFile = (src, dst, callback) => {\n // cbCalled flag and runCb helps to run cb only once.\n let cbCalled = false\n const runCb = (err?: Error) => {\n if (cbCalled) return\n cbCalled = true\n callback(err)\n }\n // Create read stream\n const readable = fs.createReadStream(src)\n readable.on('error', runCb)\n // Create write stream\n const writable = fs.createWriteStream(dst)\n writable.on('error', (err: Error) => {\n readable.destroy()\n runCb(err)\n })\n writable.on('close', () => runCb())\n // Copy file via piping streams.\n readable.pipe(writable)\n}\n\n/**\n * moveFile: moves the file from src to dst.\n * Firstly trying to rename the file if no luck copying it to dst and then deleting src.\n */\ntype MoveFile = (\n src: string,\n dst: string,\n callback: (err: Error, renamed?: boolean) => void,\n) => void\nexport const moveFile: MoveFile = (src, dst, callback) =>\n fs.rename(src, dst, (err) => {\n if (err) {\n // Try to copy file if rename didn't work.\n copyFile(src, dst, (cpErr) => (cpErr ? callback(cpErr) : deleteFile(src, callback)))\n return\n }\n // File was renamed successfully: Add true to the callback to indicate that.\n callback(null, true)\n })\n\n/**\n * Save buffer data to a file.\n * @param {Buffer} buffer - buffer to save to a file.\n * @param {string} filePath - path to a file.\n */\nexport const saveBufferToFile = (buffer, filePath, callback) => {\n if (!Buffer.isBuffer(buffer)) {\n return callback(new Error('buffer variable should be type of Buffer!'))\n }\n // Setup readable stream from buffer.\n let streamData = buffer\n const readStream = new Readable()\n readStream._read = () => {\n readStream.push(streamData)\n streamData = null\n }\n // Setup file system writable stream.\n const fstream = fs.createWriteStream(filePath)\n // console.log(\"Calling saveBuffer\");\n fstream.on('error', (err) => {\n // console.log(\"err cb\")\n callback(err)\n })\n fstream.on('close', () => {\n // console.log(\"close cb\");\n callback()\n })\n // Copy file via piping streams.\n readStream.pipe(fstream)\n}\n\n/**\n * Decodes uriEncoded file names.\n * @param {Object} opts - middleware options.\n * @param fileName {String} - file name to decode.\n * @returns {String}\n */\nconst uriDecodeFileName = (opts, fileName) => {\n if (!opts || !opts.uriDecodeFileNames) {\n return fileName\n }\n // Decode file name from URI with checking URI malformed errors.\n // See Issue https://github.com/richardgirges/express-fileupload/issues/342.\n try {\n return decodeURIComponent(fileName)\n } catch (err) {\n const matcher = /(%[a-f\\d]{2})/gi\n return fileName\n .split(matcher)\n .map((str) => {\n try {\n return decodeURIComponent(str)\n } catch (err) {\n return ''\n }\n })\n .join('')\n }\n}\n\n/**\n * Parses filename and extension and returns object {name, extension}.\n */\ntype ParseFileNameExtension = (\n preserveExtension: boolean | number,\n fileName: string,\n) => {\n extension: string\n name: string\n}\nexport const parseFileNameExtension: ParseFileNameExtension = (preserveExtension, fileName) => {\n const defaultResult = {\n name: fileName,\n extension: '',\n }\n if (!preserveExtension) return defaultResult\n\n // Define maximum extension length\n const maxExtLength =\n typeof preserveExtension === 'boolean' ? MAX_EXTENSION_LENGTH : preserveExtension\n\n const nameParts = fileName.split('.')\n if (nameParts.length < 2) return defaultResult\n\n let extension = nameParts.pop()\n if (extension.length > maxExtLength && maxExtLength > 0) {\n nameParts[nameParts.length - 1] += '.' + extension.substr(0, extension.length - maxExtLength)\n extension = extension.substr(-maxExtLength)\n }\n\n return {\n name: nameParts.join('.'),\n extension: maxExtLength ? extension : '',\n }\n}\n\n/**\n * Parse file name and extension.\n */\ntype ParseFileName = (opts: FetchAPIFileUploadOptions, fileName: string) => string\nexport const parseFileName: ParseFileName = (opts, fileName) => {\n // Check fileName argument\n if (!fileName || typeof fileName !== 'string') return getTempFilename()\n // Cut off file name if it's length more then 255.\n let parsedName = fileName.length <= 255 ? fileName : fileName.substr(0, 255)\n // Decode file name if uriDecodeFileNames option set true.\n parsedName = uriDecodeFileName(opts, parsedName)\n // Stop parsing file name if safeFileNames options hasn't been set.\n if (!opts.safeFileNames) return parsedName\n // Set regular expression for the file name.\n const nameRegex =\n typeof opts.safeFileNames === 'object' && opts.safeFileNames instanceof RegExp\n ? opts.safeFileNames\n : SAFE_FILE_NAME_REGEX\n // Parse file name extension.\n const parsedFileName = parseFileNameExtension(opts.preserveExtension, parsedName)\n if (parsedFileName.extension.length)\n parsedFileName.extension = '.' + parsedFileName.extension.replace(nameRegex, '')\n\n return parsedFileName.name.replace(nameRegex, '').concat(parsedFileName.extension)\n}\n"],"names":["fs","path","Readable","SAFE_FILE_NAME_REGEX","MAX_EXTENSION_LENGTH","TEMP_COUNTER_MAX","TEMP_PREFIX","tempCounter","debugLog","options","msg","opts","debug","console","log","getTempFilename","prefix","Date","now","isFunc","value","errorFunc","resolve","reject","promiseCallback","hasFired","err","OBJECT_PROTOTYPE_KEYS","Object","getOwnPropertyNames","prototype","ARRAY_PROTOTYPE_KEYS","Array","isSafeFromPollution","base","key","TOUCHES_ARRAY_PROTOTYPE","includes","TOUCHES_OBJECT_PROTOTYPE","buildFields","instance","field","undefined","create","push","checkAndMakeDir","fileUploadOptions","filePath","createParentPath","parentPath","dirname","existsSync","mkdirSync","recursive","deleteFile","callback","unlink","copyFile","src","dst","cbCalled","runCb","readable","createReadStream","on","writable","createWriteStream","destroy","pipe","moveFile","rename","cpErr","saveBufferToFile","buffer","Buffer","isBuffer","Error","streamData","readStream","_read","fstream","uriDecodeFileName","fileName","uriDecodeFileNames","decodeURIComponent","matcher","split","map","str","join","parseFileNameExtension","preserveExtension","defaultResult","name","extension","maxExtLength","nameParts","length","pop","substr","parseFileName","parsedName","safeFileNames","nameRegex","RegExp","parsedFileName","replace","concat"],"rangeMappings":";;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;","mappings":"AAAA,OAAOA,QAAQ,KAAI;AACnB,OAAOC,UAAU,OAAM;AACvB,SAASC,QAAQ,QAAQ,SAAQ;AAIjC,yCAAyC;AACzC,MAAMC,uBAAuB;AAC7B,MAAMC,uBAAuB;AAE7B,sDAAsD;AACtD,MAAMC,mBAAmB;AACzB,MAAMC,cAAc;AACpB,IAAIC,cAAc;AAElB;;CAEC,GACD,OAAO,MAAMC,WAAW,CAACC,SAAoCC;IAC3D,MAAMC,OAAOF,WAAW,CAAC;IACzB,IAAI,CAACE,KAAKC,KAAK,EAAE,OAAO;IACxBC,QAAQC,GAAG,CAAC,CAAC,kBAAkB,EAAEJ,IAAI,CAAC,EAAE,sBAAsB;;IAC9D,OAAO;AACT,EAAC;AAED;;CAEC,GACD,OAAO,MAAMK,kBAAkB,CAACC,SAAiBV,WAAW;IAC1DC,cAAcA,eAAeF,mBAAmB,IAAIE,cAAc;IAClE,OAAO,CAAC,EAAES,OAAO,CAAC,EAAET,YAAY,CAAC,EAAEU,KAAKC,GAAG,GAAG,CAAC;AACjD,EAAC;AAGD,OAAO,MAAMC,SAAS,CAACC;IACrB,OAAO,OAAOA,UAAU;AAC1B,EAAC;AAMD,MAAMC,YAAuB,CAACC,SAASC,SAAYJ,OAAOI,UAAUA,SAASD;AAO7E,OAAO,MAAME,kBAAmC,CAACF,SAASC;IACxD,IAAIE,WAAW;IACf,OAAO,CAACC;QACN,IAAID,UAAU;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rBK,WAAWC,eAAeD,YAAY;IACxC;AACF,EAAC;AAMD,OAAO,MAAMM,gBAA+B,CAACzF,MAAMuE;IACjD,0BAA0B;IAC1B,IAAI,CAACA,YAAY,OAAOA,aAAa,UAAU,OAAOnE;IACtD,kDAAkD;IAClD,IAAIsF,aAAanB,SAASe,MAAM,IAAI,MAAMf,WAAWA,SAASiB,MAAM,CAAC,GAAG;IACxE,0DAA0D;IAC1DE,aAAapB,kBAAkBtE,MAAM0F;IACrC,mEAAmE;IACnE,IAAI,CAAC1F,KAAK2F,aAAa,EAAE,OAAOD;IAChC,4CAA4C;IAC5C,MAAME,YACJ,OAAO5F,KAAK2F,aAAa,KAAK,YAAY3F,KAAK2F,aAAa,YAAYE,SACpE7F,KAAK2F,aAAa,GAClBnG;IACN,6BAA6B;IAC7B,MAAMsG,iBAAiBf,uBAAuB/E,KAAKgF,iBAAiB,EAAEU;IACtE,IAAII,eAAeX,SAAS,CAACG,MAAM,EACjCQ,eAAeX,SAAS,GAAG,MAAMW,eAAeX,SAAS,CAACY,OAAO,CAACH,WAAW;IAE/E,OAAOE,eAAeZ,IAAI,CAACa,OAAO,CAACH,WAAW,IAAII,MAAM,CAACF,eAAeX,SAAS;AACnF,EAAC"}
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../../src/fetchAPI-stream-file/index.ts"],"names":[],"mappings":";AAAA,OAAO,EAAE,MAAM,IAAI,CAAA;AAEnB,wBAAgB,gBAAgB,CAAC,QAAQ,KAAA,uBAWxC;AAED,wBAAuB,oBAAoB,CAAC,MAAM,EAAE,EAAE,CAAC,UAAU,6CAIhE;AAED,wBAAgB,UAAU,CAAC,IAAI,EAAE,MAAM,GAAG,cAAc,CAIvD"}
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"sources":["../../src/fetchAPI-stream-file/index.ts"],"sourcesContent":["import fs from 'fs'\n\nexport function iteratorToStream(iterator) {\n return new ReadableStream({\n async pull(controller) {\n const { done, value } = await iterator.next()\n if (done) {\n controller.close()\n } else {\n controller.enqueue(value)\n }\n },\n })\n}\n\nexport async function* nodeStreamToIterator(stream: fs.ReadStream) {\n for await (const chunk of stream) {\n yield new Uint8Array(chunk)\n }\n}\n\nexport function streamFile(path: string): ReadableStream {\n const nodeStream = fs.createReadStream(path)\n const data: ReadableStream = iteratorToStream(nodeStreamToIterator(nodeStream))\n return data\n}\n"],"names":["fs","iteratorToStream","iterator","ReadableStream","pull","controller","done","value","next","close","enqueue","nodeStreamToIterator","stream","chunk","Uint8Array","streamFile","path","nodeStream","createReadStream","data"],"rangeMappings":";;;;;;;;;;;;;;;;;;;;;;","mappings":"AAAA,OAAOA,QAAQ,KAAI;AAEnB,OAAO,SAASC,iBAAiBC,QAAQ;IACvC,OAAO,IAAIC,eAAe;QACxB,MAAMC,MAAKC,UAAU;YACnB,MAAM,EAAEC,IAAI,EAAEC,KAAK,EAAE,GAAG,MAAML,SAASM,IAAI;YAC3C,IAAIF,MAAM;gBACRD,WAAWI,KAAK;YAClB,OAAO;gBACLJ,WAAWK,OAAO,CAACH;YACrB;QACF;IACF;AACF;AAEA,OAAO,gBAAgBI,qBAAqBC,MAAqB;IAC/D,WAAW,MAAMC,SAASD,OAAQ;QAChC,MAAM,IAAIE,WAAWD;IACvB;AACF;AAEA,OAAO,SAASE,WAAWC,IAAY;IACrC,MAAMC,aAAajB,GAAGkB,gBAAgB,CAACF;IACvC,MAAMG,OAAuBlB,iBAAiBU,qBAAqBM;IACnE,OAAOE;AACT"}
|