@payloadcms/figma 0.1.0-internal.e071575 → 1.0.0-beta.0
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/LICENSE.md +1 -1
- package/dist/{utils → adapters}/asset-collection.d.ts +17 -3
- package/dist/adapters/asset-collection.js +242 -0
- package/dist/{utils → adapters}/build-lambda-zip.d.ts +8 -7
- package/dist/adapters/build-lambda-zip.js +111 -0
- package/dist/adapters/configureNextjsCache.d.ts +8 -0
- package/dist/adapters/configureNextjsCache.js +55 -0
- package/dist/adapters/deploy-output/inspectNextjsOutput/getNextRelativeAppDir.d.ts +1 -0
- package/dist/adapters/deploy-output/inspectNextjsOutput/getNextRelativeAppDir.js +15 -0
- package/dist/adapters/deploy-output/inspectNextjsOutput.d.ts +12 -0
- package/dist/adapters/deploy-output/inspectNextjsOutput.js +28 -0
- package/dist/adapters/deploy-output/inspectNitroOutput.d.ts +9 -0
- package/dist/adapters/deploy-output/inspectNitroOutput.js +13 -0
- package/dist/adapters/deploy-output/isFile.d.ts +1 -0
- package/dist/adapters/deploy-output/isFile.js +4 -0
- package/dist/adapters/deploy-output/readJson.d.ts +1 -0
- package/dist/adapters/deploy-output/readJson.js +9 -0
- package/dist/adapters/deploy-output/resolveNitroOutputLayout.d.ts +8 -0
- package/dist/adapters/deploy-output/resolveNitroOutputLayout.js +16 -0
- package/dist/adapters/deploy-output/resolveOutputPath.d.ts +2 -0
- package/dist/adapters/deploy-output/resolveOutputPath.js +9 -0
- package/dist/adapters/deploy-output/resolveWithin.d.ts +1 -0
- package/dist/adapters/deploy-output/resolveWithin.js +12 -0
- package/dist/adapters/fs-utils.d.ts +39 -0
- package/dist/adapters/fs-utils.js +135 -0
- package/dist/adapters/index.d.ts +4 -0
- package/dist/adapters/index.js +3 -0
- package/dist/adapters/lambda-runtime/nextjs-cache.d.ts +40 -0
- package/dist/adapters/lambda-runtime/nextjs-cache.js +174 -0
- package/dist/adapters/nextjs.d.ts +12 -0
- package/dist/adapters/nextjs.js +67 -0
- package/dist/adapters/nitro.d.ts +8 -0
- package/dist/adapters/nitro.js +193 -0
- package/dist/adapters/secret-files.d.ts +25 -0
- package/dist/adapters/secret-files.js +50 -0
- package/dist/adapters/types.d.ts +42 -0
- package/dist/adapters/types.js +1 -0
- package/dist/{utils/adapters → adapters}/vite.d.ts +2 -2
- package/dist/adapters/vite.js +33 -0
- package/dist/api/check-project-subdomain-availability.d.ts +12 -0
- package/dist/api/check-project-subdomain-availability.js +32 -0
- package/dist/api/control-plane-error.d.ts +6 -0
- package/dist/api/control-plane-error.js +8 -0
- package/dist/api/control-plane-fetch.d.ts +7 -0
- package/dist/api/control-plane-fetch.js +37 -0
- package/dist/api/control-plane.d.ts +12 -9
- package/dist/api/control-plane.js +28 -48
- package/dist/api/create-project.d.ts +18 -0
- package/dist/api/create-project.js +37 -0
- package/dist/api/list-project-workspaces.d.ts +8 -0
- package/dist/api/list-project-workspaces.js +28 -0
- package/dist/api/project-resource-type.d.ts +1 -0
- package/dist/api/project-resource-type.js +1 -0
- package/dist/auth/headless-oauth-flow.d.ts +23 -0
- package/dist/auth/headless-oauth-flow.js +73 -0
- package/dist/auth/oauth-flow.d.ts +2 -0
- package/dist/auth/oauth-flow.js +30 -8
- package/dist/auth/refresh.js +12 -12
- package/dist/auth/requested-scopes.d.ts +1 -0
- package/dist/auth/requested-scopes.js +3 -0
- package/dist/auth/token-store.d.ts +20 -1
- package/dist/auth/token-store.js +47 -0
- package/dist/auth/types.d.ts +17 -3
- package/dist/cli.d.ts +39 -0
- package/dist/cli.js +71 -36
- package/dist/commands/bootstrap.js +5 -1
- package/dist/commands/build-lambda-zip.js +1 -1
- package/dist/commands/deploy.d.ts +12 -0
- package/dist/commands/deploy.js +63 -25
- package/dist/commands/detect-project-resource-type.d.ts +3 -0
- package/dist/commands/detect-project-resource-type.js +28 -0
- package/dist/commands/init.d.ts +2 -2
- package/dist/commands/init.js +235 -80
- package/dist/commands/login.d.ts +11 -1
- package/dist/commands/login.js +66 -4
- package/dist/commands/prompt-to-create-project/format-project-subdomain.d.ts +1 -0
- package/dist/commands/prompt-to-create-project/format-project-subdomain.js +3 -0
- package/dist/commands/prompt-to-create-project/format-unavailable-subdomain-reason.d.ts +1 -0
- package/dist/commands/prompt-to-create-project/format-unavailable-subdomain-reason.js +7 -0
- package/dist/commands/prompt-to-create-project/get-default-project-name.d.ts +1 -0
- package/dist/commands/prompt-to-create-project/get-default-project-name.js +13 -0
- package/dist/commands/prompt-to-create-project/prompt-for-available-subdomain.d.ts +7 -0
- package/dist/commands/prompt-to-create-project/prompt-for-available-subdomain.js +32 -0
- package/dist/commands/prompt-to-create-project/resolve-project-region.d.ts +8 -0
- package/dist/commands/prompt-to-create-project/resolve-project-region.js +27 -0
- package/dist/commands/prompt-to-create-project/resolve-project-subdomain.d.ts +9 -0
- package/dist/commands/prompt-to-create-project/resolve-project-subdomain.js +54 -0
- package/dist/commands/prompt-to-create-project/resolve-text-input.d.ts +9 -0
- package/dist/commands/prompt-to-create-project/resolve-text-input.js +23 -0
- package/dist/commands/prompt-to-create-project/resolve-workspace-plan-key.d.ts +12 -0
- package/dist/commands/prompt-to-create-project/resolve-workspace-plan-key.js +36 -0
- package/dist/commands/prompt-to-create-project/validate-subdomain.d.ts +1 -0
- package/dist/commands/prompt-to-create-project/validate-subdomain.js +9 -0
- package/dist/commands/prompt-to-create-project.d.ts +24 -0
- package/dist/commands/prompt-to-create-project.js +69 -0
- package/dist/commands/setup-agent.d.ts +12 -0
- package/dist/commands/setup-agent.js +123 -0
- package/dist/commands/upgrade.js +65 -1
- package/dist/commands/upload-schema.js +3 -4
- package/dist/commands/write-project-configuration.d.ts +12 -0
- package/dist/commands/write-project-configuration.js +16 -0
- package/dist/config/oauth.js +6 -1
- package/dist/constants.d.ts +0 -2
- package/dist/constants.js +0 -3
- package/dist/db-content-api/generated/content-api-types.d.ts +6 -2
- package/dist/db-content-api/index.d.ts +1 -1
- package/dist/db-content-api/index.js +121 -72
- package/dist/db-content-api/utilities/data/index.js +8 -2
- package/dist/db-content-api/utilities/data/injectGlobalType.d.ts +6 -0
- package/dist/db-content-api/utilities/data/injectGlobalType.js +11 -0
- package/dist/db-content-api/utilities/data/removeVirtualFields.d.ts +3 -11
- package/dist/db-content-api/utilities/data/removeVirtualFields.js +12 -50
- package/dist/db-content-api/utilities/isRecord.d.ts +9 -0
- package/dist/db-content-api/utilities/isRecord.js +19 -0
- package/dist/db-content-api/utilities/joins.js +5 -1
- package/dist/db-content-api/utilities/meta/resolvesToRelationshipValue.d.ts +10 -0
- package/dist/db-content-api/utilities/meta/resolvesToRelationshipValue.js +95 -0
- package/dist/db-content-api/utilities/meta/stringifyIdsInWhere.d.ts +9 -0
- package/dist/db-content-api/utilities/meta/stringifyIdsInWhere.js +112 -0
- package/dist/db-content-api/utilities/schema/buildDocumentSchema.js +9 -4
- package/dist/db-content-api/utilities/schema/getDocumentSchema.d.ts +3 -0
- package/dist/db-content-api/utilities/schema/getDocumentSchema.js +24 -0
- package/dist/db-content-api/utilities/where.d.ts +2 -6
- package/dist/db-content-api/utilities/where.js +20 -9
- package/dist/exports/client.d.ts +2 -0
- package/dist/exports/client.js +2 -0
- package/dist/exports/views.d.ts +1 -0
- package/dist/exports/views.js +1 -0
- package/dist/imageSizeOptions.d.ts +23 -0
- package/dist/imageSizeOptions.js +26 -0
- package/dist/index.d.ts +2 -0
- package/dist/index.js +2 -0
- package/dist/lib/write-agent-config.d.ts +12 -0
- package/dist/lib/write-agent-config.js +52 -0
- package/dist/next/image-loader.d.ts +6 -0
- package/dist/next/image-loader.js +14 -0
- package/dist/oauth/components/LoginButton/index.js +66 -19
- package/dist/oauth/components/LoginButton/index.scss +121 -15
- package/dist/oauth/defaults.js +4 -1
- package/dist/oauth/endpoints/getLoginEndpoint.js +5 -2
- package/dist/oauth/index.js +8 -7
- package/dist/oauth/utilities/getAdminCollectionSlug.d.ts +1 -1
- package/dist/oauth/utilities/getAuthorizeURL.d.ts +1 -0
- package/dist/oauth/utilities/getAuthorizeURL.js +5 -1
- package/dist/plugin/build-config.d.ts +13 -3
- package/dist/plugin/build-config.js +250 -49
- package/dist/plugin/cache-revalidation-hooks.d.ts +6 -0
- package/dist/plugin/cache-revalidation-hooks.js +69 -0
- package/dist/plugin/cloud-limits/CloudLimitModal/index.d.ts +9 -0
- package/dist/plugin/cloud-limits/CloudLimitModal/index.js +66 -0
- package/dist/plugin/cloud-limits/CloudLimitModal/index.scss +56 -0
- package/dist/plugin/cloud-limits/CloudLimitProvider/index.d.ts +4 -0
- package/dist/plugin/cloud-limits/CloudLimitProvider/index.js +110 -0
- package/dist/plugin/cloud-limits/LimitReachedView/index.css +14 -0
- package/dist/plugin/cloud-limits/LimitReachedView/index.d.ts +4 -0
- package/dist/plugin/cloud-limits/LimitReachedView/index.js +52 -0
- package/dist/plugin/cloud-limits/SlugRegistryContext/index.d.ts +7 -0
- package/dist/plugin/cloud-limits/SlugRegistryContext/index.js +3 -0
- package/dist/plugin/cloud-limits/SlugTracker/index.d.ts +1 -0
- package/dist/plugin/cloud-limits/SlugTracker/index.js +27 -0
- package/dist/plugin/cloud-limits/icons/ExternalLinkIcon.d.ts +3 -0
- package/dist/plugin/cloud-limits/icons/ExternalLinkIcon.js +30 -0
- package/dist/plugin/cloud-limits/routes.d.ts +2 -0
- package/dist/plugin/cloud-limits/routes.js +4 -0
- package/dist/plugin/cloud-limits/server/redirectInitialAutosaveCreate.d.ts +9 -0
- package/dist/plugin/cloud-limits/server/redirectInitialAutosaveCreate.js +28 -0
- package/dist/plugin/cloud-limits/shared.d.ts +10 -0
- package/dist/plugin/cloud-limits/shared.js +52 -0
- package/dist/plugin/cloud-limits/utilities/cloudLimitInterceptor.d.ts +2 -0
- package/dist/plugin/cloud-limits/utilities/cloudLimitInterceptor.js +134 -0
- package/dist/plugin/cloud-limits/utilities/toasts.d.ts +4 -0
- package/dist/plugin/cloud-limits/utilities/toasts.js +19 -0
- package/dist/plugin/make-permission-access/make-permission-access.d.ts +8 -0
- package/dist/plugin/make-permission-access/make-permission-access.js +24 -0
- package/dist/plugin/sandbox-upload-fetch.d.ts +22 -20
- package/dist/plugin/sandbox-upload-fetch.js +15 -21
- package/dist/skills/deploy-to-figma/SKILL.md +234 -0
- package/dist/skills/deploy-to-figma/references/cli-reference.md +146 -0
- package/dist/storage-content-api/api-types.d.ts +5 -2
- package/dist/storage-content-api/buildBaseMediaResponseHeaders.d.ts +1 -0
- package/dist/storage-content-api/buildBaseMediaResponseHeaders.js +8 -0
- package/dist/storage-content-api/buildClientUploadFetchBackHeaders.d.ts +12 -0
- package/dist/storage-content-api/buildClientUploadFetchBackHeaders.js +26 -0
- package/dist/storage-content-api/buildMediaRequestHeaders.d.ts +1 -0
- package/dist/storage-content-api/buildMediaRequestHeaders.js +14 -0
- package/dist/storage-content-api/buildMediaResponseHeaders.d.ts +4 -0
- package/dist/storage-content-api/buildMediaResponseHeaders.js +52 -0
- package/dist/storage-content-api/client-uploads/generate.d.ts +7 -3
- package/dist/storage-content-api/client-uploads/generate.js +22 -21
- package/dist/storage-content-api/copyFile.d.ts +16 -0
- package/dist/storage-content-api/copyFile.js +90 -0
- package/dist/storage-content-api/deleteFile.d.ts +8 -0
- package/dist/storage-content-api/deleteFile.js +18 -0
- package/dist/storage-content-api/getDownloadResponseHeaderPolicy.d.ts +11 -0
- package/dist/storage-content-api/getDownloadResponseHeaderPolicy.js +33 -0
- package/dist/storage-content-api/getMediaType.d.ts +1 -0
- package/dist/storage-content-api/getMediaType.js +3 -0
- package/dist/storage-content-api/handleUpload.d.ts +1 -2
- package/dist/storage-content-api/handleUpload.js +13 -157
- package/dist/storage-content-api/hasSupportedContentEncoding.d.ts +1 -0
- package/dist/storage-content-api/hasSupportedContentEncoding.js +6 -0
- package/dist/storage-content-api/index.js +17 -8
- package/dist/storage-content-api/mediaErrorResponse.d.ts +1 -0
- package/dist/storage-content-api/mediaErrorResponse.js +12 -0
- package/dist/storage-content-api/resolveDownloadResponseHeaders.d.ts +5 -0
- package/dist/storage-content-api/resolveDownloadResponseHeaders.js +13 -0
- package/dist/storage-content-api/shouldAttachMedia.d.ts +1 -0
- package/dist/storage-content-api/shouldAttachMedia.js +34 -0
- package/dist/storage-content-api/staticHandler.d.ts +2 -1
- package/dist/storage-content-api/staticHandler.js +87 -32
- package/dist/storage-content-api/types.d.ts +4 -1
- package/dist/storage-content-api/uploadFileData.d.ts +10 -0
- package/dist/storage-content-api/uploadFileData.js +145 -0
- package/dist/translations/ar.d.ts +12 -0
- package/dist/translations/ar.js +12 -0
- package/dist/translations/az.d.ts +12 -0
- package/dist/translations/az.js +12 -0
- package/dist/translations/bg.d.ts +12 -0
- package/dist/translations/bg.js +12 -0
- package/dist/translations/bnBd.d.ts +12 -0
- package/dist/translations/bnBd.js +12 -0
- package/dist/translations/bnIn.d.ts +12 -0
- package/dist/translations/bnIn.js +12 -0
- package/dist/translations/ca.d.ts +12 -0
- package/dist/translations/ca.js +12 -0
- package/dist/translations/cs.d.ts +12 -0
- package/dist/translations/cs.js +12 -0
- package/dist/translations/da.d.ts +12 -0
- package/dist/translations/da.js +12 -0
- package/dist/translations/de.d.ts +12 -0
- package/dist/translations/de.js +12 -0
- package/dist/translations/en.d.ts +12 -0
- package/dist/translations/en.js +12 -0
- package/dist/translations/es.d.ts +12 -0
- package/dist/translations/es.js +12 -0
- package/dist/translations/et.d.ts +12 -0
- package/dist/translations/et.js +12 -0
- package/dist/translations/fa.d.ts +12 -0
- package/dist/translations/fa.js +12 -0
- package/dist/translations/fr.d.ts +12 -0
- package/dist/translations/fr.js +12 -0
- package/dist/translations/he.d.ts +12 -0
- package/dist/translations/he.js +12 -0
- package/dist/translations/hr.d.ts +12 -0
- package/dist/translations/hr.js +12 -0
- package/dist/translations/hu.d.ts +12 -0
- package/dist/translations/hu.js +12 -0
- package/dist/translations/hy.d.ts +12 -0
- package/dist/translations/hy.js +12 -0
- package/dist/translations/id.d.ts +12 -0
- package/dist/translations/id.js +12 -0
- package/dist/translations/index.d.ts +533 -0
- package/dist/translations/index.js +90 -0
- package/dist/translations/is.d.ts +12 -0
- package/dist/translations/is.js +12 -0
- package/dist/translations/it.d.ts +12 -0
- package/dist/translations/it.js +12 -0
- package/dist/translations/ja.d.ts +12 -0
- package/dist/translations/ja.js +12 -0
- package/dist/translations/ko.d.ts +12 -0
- package/dist/translations/ko.js +12 -0
- package/dist/translations/lt.d.ts +12 -0
- package/dist/translations/lt.js +12 -0
- package/dist/translations/lv.d.ts +12 -0
- package/dist/translations/lv.js +12 -0
- package/dist/translations/my.d.ts +12 -0
- package/dist/translations/my.js +12 -0
- package/dist/translations/nb.d.ts +12 -0
- package/dist/translations/nb.js +12 -0
- package/dist/translations/nl.d.ts +12 -0
- package/dist/translations/nl.js +12 -0
- package/dist/translations/pl.d.ts +12 -0
- package/dist/translations/pl.js +12 -0
- package/dist/translations/pt.d.ts +12 -0
- package/dist/translations/pt.js +12 -0
- package/dist/translations/ro.d.ts +12 -0
- package/dist/translations/ro.js +12 -0
- package/dist/translations/rs.d.ts +12 -0
- package/dist/translations/rs.js +12 -0
- package/dist/translations/rsLatin.d.ts +12 -0
- package/dist/translations/rsLatin.js +12 -0
- package/dist/translations/ru.d.ts +12 -0
- package/dist/translations/ru.js +12 -0
- package/dist/translations/sk.d.ts +12 -0
- package/dist/translations/sk.js +12 -0
- package/dist/translations/sl.d.ts +12 -0
- package/dist/translations/sl.js +12 -0
- package/dist/translations/sv.d.ts +12 -0
- package/dist/translations/sv.js +12 -0
- package/dist/translations/ta.d.ts +12 -0
- package/dist/translations/ta.js +12 -0
- package/dist/translations/th.d.ts +12 -0
- package/dist/translations/th.js +12 -0
- package/dist/translations/tr.d.ts +12 -0
- package/dist/translations/tr.js +12 -0
- package/dist/translations/uk.d.ts +12 -0
- package/dist/translations/uk.js +12 -0
- package/dist/translations/vi.d.ts +12 -0
- package/dist/translations/vi.js +12 -0
- package/dist/translations/zh.d.ts +12 -0
- package/dist/translations/zh.js +12 -0
- package/dist/translations/zhTw.d.ts +12 -0
- package/dist/translations/zhTw.js +12 -0
- package/dist/types.d.ts +11 -0
- package/dist/utils/assert-never.d.ts +1 -0
- package/dist/utils/assert-never.js +3 -0
- package/dist/utils/build-detection.d.ts +6 -1
- package/dist/utils/build-detection.js +68 -89
- package/dist/utils/cache-bootstrap.js +1 -0
- package/dist/utils/deploy-adapter.d.ts +3 -35
- package/dist/utils/deploy-adapter.js +25 -14
- package/dist/utils/env-management.d.ts +15 -0
- package/dist/utils/env-management.js +47 -0
- package/dist/utils/lambda-config.js +18 -23
- package/dist/utils/load-payload-config.js +1 -6
- package/dist/utils/messages.js +24 -3
- package/dist/utils/next-image-loader-config.d.ts +2 -0
- package/dist/utils/next-image-loader-config.js +63 -0
- package/dist/utils/next-image-loader-file.d.ts +2 -0
- package/dist/utils/next-image-loader-file.js +11 -0
- package/dist/utils/payload-config-ast.d.ts +5 -0
- package/dist/utils/payload-config-ast.js +73 -4
- package/dist/utils/payload-config-modifier.js +3 -0
- package/dist/utils/payload-generate.d.ts +10 -0
- package/dist/utils/payload-generate.js +59 -0
- package/dist/utils/payload-secret.d.ts +28 -0
- package/dist/utils/payload-secret.js +34 -0
- package/dist/utils/pnpm-builds.d.ts +14 -0
- package/dist/utils/pnpm-builds.js +125 -0
- package/dist/utils/s3-upload.js +4 -1
- package/package.json +32 -7
- package/dist/lib/download-skill.d.ts +0 -12
- package/dist/lib/download-skill.js +0 -77
- package/dist/storage-content-api/handleDelete.d.ts +0 -7
- package/dist/storage-content-api/handleDelete.js +0 -15
- package/dist/storage-content-api/utilities/getSafeFilename.d.ts +0 -11
- package/dist/storage-content-api/utilities/getSafeFilename.js +0 -59
- package/dist/storage-content-api/utilities/index.d.ts +0 -2
- package/dist/storage-content-api/utilities/index.js +0 -2
- package/dist/storage-content-api/utilities/parseUploadReference.d.ts +0 -17
- package/dist/storage-content-api/utilities/parseUploadReference.js +0 -27
- package/dist/utils/adapters/nextjs.d.ts +0 -8
- package/dist/utils/adapters/nextjs.js +0 -61
- package/dist/utils/adapters/nitro.d.ts +0 -8
- package/dist/utils/adapters/nitro.js +0 -172
- package/dist/utils/adapters/vite.js +0 -31
- package/dist/utils/asset-collection.js +0 -144
- package/dist/utils/build-lambda-zip.js +0 -90
- package/dist/utils/fs-utils.d.ts +0 -12
- package/dist/utils/fs-utils.js +0 -55
|
@@ -1,13 +1,17 @@
|
|
|
1
|
-
import
|
|
1
|
+
import { resolveSignedURLKey } from '@payloadcms/plugin-cloud-storage/utilities';
|
|
2
2
|
import { APIError, Forbidden } from 'payload';
|
|
3
|
-
import {
|
|
4
|
-
|
|
3
|
+
import { assertClientUploadAllowed } from 'payload/internal';
|
|
4
|
+
import { passesMakeViewerWriteGate } from '../../plugin/make-permission-access/make-permission-access.js';
|
|
5
|
+
const defaultAccess = ({ req })=>Boolean(req.user) && passesMakeViewerWriteGate(req.user);
|
|
5
6
|
/**
|
|
6
7
|
* v4 client-upload entry point. Payload core calls this from
|
|
7
8
|
* `POST /api/upload-instructions`; we sign a Content API upload URL and hand the
|
|
8
|
-
* browser an `http` PUT instruction plus
|
|
9
|
-
*
|
|
10
|
-
|
|
9
|
+
* browser an `http` PUT instruction plus a signed upload receipt.
|
|
10
|
+
*
|
|
11
|
+
* Each upload gets its own `_objectKey`, so it never overwrites another object.
|
|
12
|
+
* Payload verifies the receipt before it reads the uploaded file back through
|
|
13
|
+
* `staticHandler`, and it does not upload the original again in `handleUpload`.
|
|
14
|
+
*/ export const getGenerateUploadInstructions = ({ access = defaultAccess, client, collectionPrefix = '' })=>{
|
|
11
15
|
const generate = async ({ collectionSlug, docPrefix, filename, filesize, mimeType, overrideAccess, req })=>{
|
|
12
16
|
if (!overrideAccess && !await access({
|
|
13
17
|
collectionSlug,
|
|
@@ -15,21 +19,24 @@ const defaultAccess = ({ req })=>!!req.user;
|
|
|
15
19
|
})) {
|
|
16
20
|
throw new Forbidden();
|
|
17
21
|
}
|
|
18
|
-
|
|
22
|
+
assertClientUploadAllowed({
|
|
23
|
+
collection: req.payload.collections[collectionSlug]?.config,
|
|
24
|
+
filename,
|
|
25
|
+
mimeType
|
|
26
|
+
});
|
|
27
|
+
const { sanitizedFilename, storageFilePath, uploadReference } = await resolveSignedURLKey({
|
|
28
|
+
collectionPrefix,
|
|
19
29
|
collectionSlug,
|
|
20
|
-
|
|
30
|
+
docPrefix,
|
|
31
|
+
filename,
|
|
21
32
|
req
|
|
22
33
|
});
|
|
23
|
-
// Key by `<prefix>/<filename>` to match the read path (staticHandler/generateURL
|
|
24
|
-
// via getFilePrefix) and handleUpload. The Figma plugin sets no prefix, so
|
|
25
|
-
// docPrefix is blank today and this is just the filename.
|
|
26
|
-
const fileKey = path.posix.join(docPrefix ?? '', safeFilename);
|
|
27
34
|
const { data, error, response } = await client.POST('/api/v0/uploads/sign', {
|
|
28
35
|
body: {
|
|
29
36
|
collectionId: collectionSlug,
|
|
30
37
|
contentType: mimeType,
|
|
31
38
|
expiresIn: 3600,
|
|
32
|
-
filename:
|
|
39
|
+
filename: storageFilePath
|
|
33
40
|
}
|
|
34
41
|
});
|
|
35
42
|
if (error) {
|
|
@@ -43,16 +50,10 @@ const defaultAccess = ({ req })=>!!req.user;
|
|
|
43
50
|
return {
|
|
44
51
|
type: 'http',
|
|
45
52
|
file: {
|
|
46
|
-
|
|
47
|
-
filename: safeFilename,
|
|
53
|
+
filename: sanitizedFilename,
|
|
48
54
|
mimeType,
|
|
49
55
|
size: filesize,
|
|
50
|
-
uploadReference
|
|
51
|
-
clientUploaded: true,
|
|
52
|
-
filename: safeFilename,
|
|
53
|
-
mimeType,
|
|
54
|
-
prefix: docPrefix ?? ''
|
|
55
|
-
}
|
|
56
|
+
uploadReference
|
|
56
57
|
},
|
|
57
58
|
// The presigned URL is signed with `contentType: mimeType`, so the browser
|
|
58
59
|
// PUT must carry a matching Content-Type header or S3 rejects the signature.
|
|
@@ -0,0 +1,16 @@
|
|
|
1
|
+
import type { CopyFile } from '@payloadcms/plugin-cloud-storage/types';
|
|
2
|
+
import type { StorageClient } from './client.js';
|
|
3
|
+
type Args = {
|
|
4
|
+
client: StorageClient;
|
|
5
|
+
};
|
|
6
|
+
/**
|
|
7
|
+
* Copies `from` to `to` and keeps `from`, so older versions can still read it.
|
|
8
|
+
*
|
|
9
|
+
* The Content API has no copy endpoint, so the bytes are downloaded and uploaded again with
|
|
10
|
+
* the source Content-Type. The Content API stores no other object metadata.
|
|
11
|
+
*
|
|
12
|
+
* The destination check is not atomic. Payload puts a new `_objectKey` in `to`, so two
|
|
13
|
+
* copies to the same key at the same time are not expected.
|
|
14
|
+
*/
|
|
15
|
+
export declare const getCopyFile: ({ client }: Args) => CopyFile;
|
|
16
|
+
export {};
|
|
@@ -0,0 +1,90 @@
|
|
|
1
|
+
import { APIError } from 'payload';
|
|
2
|
+
import { uploadFileData } from './uploadFileData.js';
|
|
3
|
+
const PRESIGNED_DOWNLOAD_URL_EXPIRES_IN_SECONDS = 300;
|
|
4
|
+
/**
|
|
5
|
+
* Copies `from` to `to` and keeps `from`, so older versions can still read it.
|
|
6
|
+
*
|
|
7
|
+
* The Content API has no copy endpoint, so the bytes are downloaded and uploaded again with
|
|
8
|
+
* the source Content-Type. The Content API stores no other object metadata.
|
|
9
|
+
*
|
|
10
|
+
* The destination check is not atomic. Payload puts a new `_objectKey` in `to`, so two
|
|
11
|
+
* copies to the same key at the same time are not expected.
|
|
12
|
+
*/ export const getCopyFile = ({ client })=>{
|
|
13
|
+
return async ({ collection, from, mimeType, req, to })=>{
|
|
14
|
+
if (from === to) {
|
|
15
|
+
throw new Error('Storage copy requires different source and destination keys');
|
|
16
|
+
}
|
|
17
|
+
const collectionId = collection.slug;
|
|
18
|
+
// The Content API role can list the bucket, so a missing object returns 404, not 403.
|
|
19
|
+
const destination = await fetchObject({
|
|
20
|
+
client,
|
|
21
|
+
collectionId,
|
|
22
|
+
headers: {
|
|
23
|
+
Range: 'bytes=0-0'
|
|
24
|
+
},
|
|
25
|
+
key: to,
|
|
26
|
+
signal: req.signal
|
|
27
|
+
});
|
|
28
|
+
await cancelResponseBody(destination);
|
|
29
|
+
if (destination.status !== 404) {
|
|
30
|
+
if (destination.ok || destination.status === 416) {
|
|
31
|
+
throw new APIError(`Storage destination already exists: ${to}`, 409);
|
|
32
|
+
}
|
|
33
|
+
throw new Error(`Failed to check storage destination: ${destination.status}`);
|
|
34
|
+
}
|
|
35
|
+
const source = await fetchObject({
|
|
36
|
+
client,
|
|
37
|
+
collectionId,
|
|
38
|
+
key: from,
|
|
39
|
+
signal: req.signal
|
|
40
|
+
});
|
|
41
|
+
if (!source.ok) {
|
|
42
|
+
await cancelResponseBody(source);
|
|
43
|
+
throw new Error(`Failed to read storage source: ${source.status}`);
|
|
44
|
+
}
|
|
45
|
+
const fileData = Buffer.from(await source.arrayBuffer());
|
|
46
|
+
await uploadFileData({
|
|
47
|
+
client,
|
|
48
|
+
collectionId,
|
|
49
|
+
fileData,
|
|
50
|
+
fileKey: to,
|
|
51
|
+
mimeType: source.headers.get('Content-Type') || mimeType || 'application/octet-stream'
|
|
52
|
+
});
|
|
53
|
+
};
|
|
54
|
+
};
|
|
55
|
+
async function fetchObject({ client, collectionId, headers, key, signal }) {
|
|
56
|
+
const { data, error, response } = await client.POST('/api/v0/uploads/download/sign', {
|
|
57
|
+
body: {
|
|
58
|
+
collectionId,
|
|
59
|
+
expiresIn: PRESIGNED_DOWNLOAD_URL_EXPIRES_IN_SECONDS,
|
|
60
|
+
filename: key,
|
|
61
|
+
responseHeaders: {
|
|
62
|
+
cacheControl: 'private, no-store'
|
|
63
|
+
}
|
|
64
|
+
}
|
|
65
|
+
});
|
|
66
|
+
if (error) {
|
|
67
|
+
throw new APIError(`Failed to get presigned download URL: ${error.message}`, response.status, {
|
|
68
|
+
code: error.code
|
|
69
|
+
});
|
|
70
|
+
}
|
|
71
|
+
if (!data) {
|
|
72
|
+
throw new Error('No response while getting presigned download URL');
|
|
73
|
+
}
|
|
74
|
+
try {
|
|
75
|
+
return await fetch(data.url, {
|
|
76
|
+
headers,
|
|
77
|
+
signal
|
|
78
|
+
});
|
|
79
|
+
} catch {
|
|
80
|
+
// Fetch errors can contain the signed URL; throw only a fixed message to avoid exposing it.
|
|
81
|
+
throw new Error('Failed to fetch file from storage');
|
|
82
|
+
}
|
|
83
|
+
}
|
|
84
|
+
async function cancelResponseBody(response) {
|
|
85
|
+
try {
|
|
86
|
+
await response.body?.cancel();
|
|
87
|
+
} catch {
|
|
88
|
+
// The body is not read; cancellation is best-effort cleanup.
|
|
89
|
+
}
|
|
90
|
+
}
|
|
@@ -0,0 +1,8 @@
|
|
|
1
|
+
import type { DeleteFile } from '@payloadcms/plugin-cloud-storage/types';
|
|
2
|
+
import type { StorageClient } from './client.js';
|
|
3
|
+
type Args = {
|
|
4
|
+
client: StorageClient;
|
|
5
|
+
};
|
|
6
|
+
/** Deletes the object at `storageFilePath`. Payload resolves the complete path. */
|
|
7
|
+
export declare const getDeleteFile: ({ client }: Args) => DeleteFile;
|
|
8
|
+
export {};
|
|
@@ -0,0 +1,18 @@
|
|
|
1
|
+
import { APIError } from 'payload';
|
|
2
|
+
/** Deletes the object at `storageFilePath`. Payload resolves the complete path. */ export const getDeleteFile = ({ client })=>{
|
|
3
|
+
return async ({ collection, storageFilePath })=>{
|
|
4
|
+
const { error, response } = await client.DELETE('/api/v0/uploads/{collectionId}/{filename}', {
|
|
5
|
+
params: {
|
|
6
|
+
path: {
|
|
7
|
+
collectionId: collection.slug,
|
|
8
|
+
filename: storageFilePath
|
|
9
|
+
}
|
|
10
|
+
}
|
|
11
|
+
});
|
|
12
|
+
if (error || !response.ok) {
|
|
13
|
+
throw new APIError(`Failed to delete file: ${error?.message ?? response.statusText}`, response.status, {
|
|
14
|
+
code: error?.code
|
|
15
|
+
});
|
|
16
|
+
}
|
|
17
|
+
};
|
|
18
|
+
};
|
|
@@ -0,0 +1,11 @@
|
|
|
1
|
+
import type { Payload } from 'payload';
|
|
2
|
+
export declare const DEFAULT_MEDIA_CACHE_CONTROL = "private, no-store";
|
|
3
|
+
export declare const MAX_MEDIA_CACHE_CONTROL_LENGTH = 1024;
|
|
4
|
+
type DownloadResponseHeaderPolicy = {
|
|
5
|
+
cacheControl: string;
|
|
6
|
+
};
|
|
7
|
+
export declare const getDownloadResponseHeaderPolicy: ({ logger, responseHeaders, }: {
|
|
8
|
+
logger: Pick<Payload["logger"], "debug">;
|
|
9
|
+
responseHeaders: Headers;
|
|
10
|
+
}) => DownloadResponseHeaderPolicy;
|
|
11
|
+
export {};
|
|
@@ -0,0 +1,33 @@
|
|
|
1
|
+
export const DEFAULT_MEDIA_CACHE_CONTROL = 'private, no-store';
|
|
2
|
+
export const MAX_MEDIA_CACHE_CONTROL_LENGTH = 1024;
|
|
3
|
+
const PRINTABLE_ASCII_REGEX = /^[\x20-\x7e]+$/;
|
|
4
|
+
export const getDownloadResponseHeaderPolicy = ({ logger, responseHeaders })=>{
|
|
5
|
+
const configuredCacheControl = responseHeaders.get('Cache-Control')?.trim();
|
|
6
|
+
const isCacheControlValid = hasValidCacheControl(configuredCacheControl);
|
|
7
|
+
const hasIgnoredHeaders = [
|
|
8
|
+
...responseHeaders.keys()
|
|
9
|
+
].some((name)=>name !== 'cache-control');
|
|
10
|
+
const rejectedCacheControlOverride = !isCacheControlValid;
|
|
11
|
+
if (hasIgnoredHeaders || rejectedCacheControlOverride) {
|
|
12
|
+
logger.debug({
|
|
13
|
+
hasIgnoredResponseHeaders: hasIgnoredHeaders,
|
|
14
|
+
msg: 'Filtered media response header overrides',
|
|
15
|
+
rejectedCacheControlOverride
|
|
16
|
+
});
|
|
17
|
+
}
|
|
18
|
+
return {
|
|
19
|
+
cacheControl: isCacheControlValid && configuredCacheControl ? configuredCacheControl : DEFAULT_MEDIA_CACHE_CONTROL
|
|
20
|
+
};
|
|
21
|
+
};
|
|
22
|
+
function hasValidCacheControl(cacheControl) {
|
|
23
|
+
if (cacheControl == null) {
|
|
24
|
+
return false;
|
|
25
|
+
}
|
|
26
|
+
if (cacheControl.length === 0 || cacheControl.length > MAX_MEDIA_CACHE_CONTROL_LENGTH) {
|
|
27
|
+
return false;
|
|
28
|
+
}
|
|
29
|
+
if (!PRINTABLE_ASCII_REGEX.test(cacheControl)) {
|
|
30
|
+
return false;
|
|
31
|
+
}
|
|
32
|
+
return true;
|
|
33
|
+
}
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
export declare function getMediaType(headers: Headers): string;
|
|
@@ -4,7 +4,6 @@ import type { StorageClient } from './client.js';
|
|
|
4
4
|
type Args = {
|
|
5
5
|
client: StorageClient;
|
|
6
6
|
collection: CollectionConfig;
|
|
7
|
-
prefix?: string;
|
|
8
7
|
};
|
|
9
|
-
export declare const getHandleUpload: ({ client, collection
|
|
8
|
+
export declare const getHandleUpload: ({ client, collection }: Args) => HandleUpload;
|
|
10
9
|
export {};
|
|
@@ -1,162 +1,18 @@
|
|
|
1
1
|
import fs from 'fs';
|
|
2
|
-
import
|
|
3
|
-
|
|
4
|
-
|
|
5
|
-
const
|
|
6
|
-
|
|
7
|
-
const MAX_FILE_SIZE_BEFORE_MULTIPART = 100 * 1024 * 1024 // 100MB
|
|
8
|
-
;
|
|
9
|
-
export const getHandleUpload = ({ client, collection, prefix = '' })=>{
|
|
10
|
-
return async ({ data, file })=>{
|
|
11
|
-
// Skip if the client already uploaded THIS SPECIFIC file. Resized versions
|
|
12
|
-
// (different filename) should still be uploaded.
|
|
13
|
-
const reference = parseUploadReference(file.uploadReference);
|
|
14
|
-
const isOriginalClientUploaded = reference.clientUploaded === true && file.filename === reference.filename;
|
|
15
|
-
if (isOriginalClientUploaded) {
|
|
16
|
-
return data;
|
|
17
|
-
}
|
|
18
|
-
const collectionId = collection.slug;
|
|
19
|
-
const fileKey = path.posix.join(data.prefix || prefix, file.filename);
|
|
2
|
+
import { uploadFileData } from './uploadFileData.js';
|
|
3
|
+
// Payload skips the original of a verified direct browser upload, so every file here
|
|
4
|
+
// must be written. `storageFilePath` already includes the prefixes and `_objectKey`.
|
|
5
|
+
export const getHandleUpload = ({ client, collection })=>{
|
|
6
|
+
return async ({ data, file, storageFilePath })=>{
|
|
20
7
|
const fileData = file.tempFilePath ? fs.readFileSync(file.tempFilePath) : file.buffer;
|
|
21
|
-
|
|
22
|
-
|
|
23
|
-
|
|
24
|
-
|
|
25
|
-
|
|
26
|
-
|
|
27
|
-
|
|
28
|
-
|
|
29
|
-
});
|
|
30
|
-
} else {
|
|
31
|
-
await uploadSingleFile({
|
|
32
|
-
client,
|
|
33
|
-
collectionId,
|
|
34
|
-
fileData,
|
|
35
|
-
fileKey,
|
|
36
|
-
mimeType: file.mimeType
|
|
37
|
-
});
|
|
38
|
-
}
|
|
8
|
+
await uploadFileData({
|
|
9
|
+
client,
|
|
10
|
+
collectionId: collection.slug,
|
|
11
|
+
fileData,
|
|
12
|
+
fileKey: storageFilePath,
|
|
13
|
+
fileSize: file.filesize || fileData.length,
|
|
14
|
+
mimeType: file.mimeType
|
|
15
|
+
});
|
|
39
16
|
return data;
|
|
40
17
|
};
|
|
41
18
|
};
|
|
42
|
-
async function uploadSingleFile({ client, collectionId, fileData, fileKey, mimeType }) {
|
|
43
|
-
const { data, error, response } = await client.POST('/api/v0/uploads/sign', {
|
|
44
|
-
body: {
|
|
45
|
-
collectionId,
|
|
46
|
-
contentType: mimeType,
|
|
47
|
-
expiresIn: 3600,
|
|
48
|
-
filename: fileKey
|
|
49
|
-
}
|
|
50
|
-
});
|
|
51
|
-
if (error) {
|
|
52
|
-
throw new APIError(`Failed to get presigned upload URL: ${error.message}`, response.status, {
|
|
53
|
-
code: error.code
|
|
54
|
-
});
|
|
55
|
-
}
|
|
56
|
-
if (!data) {
|
|
57
|
-
throw new Error('No response while getting presigned upload URL');
|
|
58
|
-
}
|
|
59
|
-
const uploadResponse = await fetch(data.url, {
|
|
60
|
-
// TS's BodyInit type rejects Buffer<ArrayBufferLike>; wrap as Uint8Array
|
|
61
|
-
// (a valid ArrayBufferView) — byte-identical.
|
|
62
|
-
body: new Uint8Array(fileData),
|
|
63
|
-
headers: {
|
|
64
|
-
'Content-Type': mimeType
|
|
65
|
-
},
|
|
66
|
-
method: 'PUT'
|
|
67
|
-
});
|
|
68
|
-
if (!uploadResponse.ok) {
|
|
69
|
-
throw new Error(`Failed to upload to S3: ${uploadResponse.status} ${uploadResponse.statusText}`);
|
|
70
|
-
}
|
|
71
|
-
}
|
|
72
|
-
async function uploadMultipart({ client, collectionId, fileData, fileKey, mimeType }) {
|
|
73
|
-
const { data: initiateData, error: initiateError, response: initiateResponse } = await client.POST('/api/v0/uploads/multipart/initiate', {
|
|
74
|
-
body: {
|
|
75
|
-
collectionId,
|
|
76
|
-
contentType: mimeType,
|
|
77
|
-
filename: fileKey
|
|
78
|
-
}
|
|
79
|
-
});
|
|
80
|
-
if (initiateError) {
|
|
81
|
-
throw new APIError(`Failed to initiate multipart upload: ${initiateError.message}`, initiateResponse.status, {
|
|
82
|
-
code: initiateError.code
|
|
83
|
-
});
|
|
84
|
-
}
|
|
85
|
-
if (!initiateData) {
|
|
86
|
-
throw new Error('No response while initiating multipart upload');
|
|
87
|
-
}
|
|
88
|
-
const { uploadId } = initiateData;
|
|
89
|
-
try {
|
|
90
|
-
const numParts = Math.ceil(fileData.length / PART_SIZE);
|
|
91
|
-
const partNumbers = Array.from({
|
|
92
|
-
length: numParts
|
|
93
|
-
}, (_, i)=>i + 1);
|
|
94
|
-
const { data: partsData, error: partsError, response: partsResponse } = await client.POST('/api/v0/uploads/multipart/parts', {
|
|
95
|
-
body: {
|
|
96
|
-
collectionId,
|
|
97
|
-
expiresIn: 3600,
|
|
98
|
-
filename: fileKey,
|
|
99
|
-
partNumbers,
|
|
100
|
-
uploadId
|
|
101
|
-
}
|
|
102
|
-
});
|
|
103
|
-
if (partsError) {
|
|
104
|
-
throw new APIError(`Failed to get part URLs: ${partsError.message}`, partsResponse.status, {
|
|
105
|
-
code: partsError.code
|
|
106
|
-
});
|
|
107
|
-
}
|
|
108
|
-
if (!partsData) {
|
|
109
|
-
throw new Error('No response while getting part URLs');
|
|
110
|
-
}
|
|
111
|
-
const { parts } = partsData;
|
|
112
|
-
if (!parts || !Array.isArray(parts)) {
|
|
113
|
-
throw new Error('Invalid response from part URLs endpoint: parts is not an array');
|
|
114
|
-
}
|
|
115
|
-
const uploadedParts = await Promise.all(parts.map(async ({ partNumber, url })=>{
|
|
116
|
-
const start = (partNumber - 1) * PART_SIZE;
|
|
117
|
-
const end = Math.min(start + PART_SIZE, fileData.length);
|
|
118
|
-
const partData = fileData.slice(start, end);
|
|
119
|
-
const uploadResponse = await fetch(url, {
|
|
120
|
-
body: partData,
|
|
121
|
-
headers: {
|
|
122
|
-
'Content-Type': mimeType
|
|
123
|
-
},
|
|
124
|
-
method: 'PUT'
|
|
125
|
-
});
|
|
126
|
-
const etag = uploadResponse.headers.get('ETag');
|
|
127
|
-
if (!etag) {
|
|
128
|
-
throw new Error(`No ETag returned for part ${partNumber}`);
|
|
129
|
-
}
|
|
130
|
-
return {
|
|
131
|
-
ETag: etag,
|
|
132
|
-
PartNumber: partNumber
|
|
133
|
-
};
|
|
134
|
-
}));
|
|
135
|
-
const { error: completeError, response: completeResponse } = await client.POST('/api/v0/uploads/multipart/complete', {
|
|
136
|
-
body: {
|
|
137
|
-
collectionId,
|
|
138
|
-
filename: fileKey,
|
|
139
|
-
parts: uploadedParts,
|
|
140
|
-
uploadId
|
|
141
|
-
}
|
|
142
|
-
});
|
|
143
|
-
if (completeError) {
|
|
144
|
-
throw new APIError(`Failed to complete multipart upload: ${completeError.message}`, completeResponse.status, {
|
|
145
|
-
code: completeError.code
|
|
146
|
-
});
|
|
147
|
-
}
|
|
148
|
-
} catch (error) {
|
|
149
|
-
try {
|
|
150
|
-
await client.POST('/api/v0/uploads/multipart/abort', {
|
|
151
|
-
body: {
|
|
152
|
-
collectionId,
|
|
153
|
-
filename: fileKey,
|
|
154
|
-
uploadId
|
|
155
|
-
}
|
|
156
|
-
});
|
|
157
|
-
} catch {
|
|
158
|
-
// Ignore abort errors
|
|
159
|
-
}
|
|
160
|
-
throw error;
|
|
161
|
-
}
|
|
162
|
-
}
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
export declare function hasSupportedContentEncoding(headers: Headers): boolean;
|
|
@@ -0,0 +1,6 @@
|
|
|
1
|
+
// Fetch can automatically decompress a file without updating its size or byte-range headers.
|
|
2
|
+
// Reject compressed responses so the headers still match the bytes we send.
|
|
3
|
+
export function hasSupportedContentEncoding(headers) {
|
|
4
|
+
const contentEncoding = headers.get('content-encoding')?.trim().toLowerCase();
|
|
5
|
+
return contentEncoding == null || contentEncoding === '' || contentEncoding === 'identity';
|
|
6
|
+
}
|
|
@@ -1,35 +1,44 @@
|
|
|
1
1
|
import { createStorageClient } from './client.js';
|
|
2
2
|
import { getGenerateUploadInstructions } from './client-uploads/generate.js';
|
|
3
|
+
import { getCopyFile } from './copyFile.js';
|
|
4
|
+
import { getDeleteFile } from './deleteFile.js';
|
|
3
5
|
import { getGenerateURL } from './generateURL.js';
|
|
4
|
-
import { getHandleDelete } from './handleDelete.js';
|
|
5
6
|
import { getHandleUpload } from './handleUpload.js';
|
|
6
7
|
import { getHandler } from './staticHandler.js';
|
|
7
8
|
export function contentApiStorageAdapter(config) {
|
|
8
9
|
return ({ collection, prefix })=>{
|
|
9
10
|
const client = createStorageClient(config);
|
|
10
11
|
const baseUrl = config.baseUrl;
|
|
12
|
+
const deleteFile = getDeleteFile({
|
|
13
|
+
client
|
|
14
|
+
});
|
|
11
15
|
return {
|
|
12
16
|
name: 'content-api',
|
|
17
|
+
copyFile: getCopyFile({
|
|
18
|
+
client
|
|
19
|
+
}),
|
|
20
|
+
deleteFile,
|
|
13
21
|
generateURL: getGenerateURL({
|
|
14
22
|
baseUrl
|
|
15
23
|
}),
|
|
16
|
-
handleDelete:
|
|
17
|
-
client
|
|
18
|
-
}),
|
|
24
|
+
handleDelete: deleteFile,
|
|
19
25
|
handleUpload: getHandleUpload({
|
|
20
26
|
client,
|
|
21
|
-
collection
|
|
22
|
-
prefix
|
|
27
|
+
collection
|
|
23
28
|
}),
|
|
24
29
|
staticHandler: getHandler({
|
|
25
30
|
client,
|
|
26
|
-
collection
|
|
31
|
+
collection,
|
|
32
|
+
prefix
|
|
27
33
|
}),
|
|
28
34
|
uploadInstructions: {
|
|
29
35
|
enabled: true,
|
|
30
36
|
generate: getGenerateUploadInstructions({
|
|
31
|
-
|
|
37
|
+
access: config.uploadInstructionsAccess,
|
|
38
|
+
client,
|
|
39
|
+
collectionPrefix: prefix
|
|
32
40
|
}),
|
|
41
|
+
requiresUploadReceipt: true,
|
|
33
42
|
useInAdmin: true
|
|
34
43
|
}
|
|
35
44
|
};
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
export declare function mediaErrorResponse(status: number, body: string, contentRange?: string): Response;
|
|
@@ -0,0 +1,12 @@
|
|
|
1
|
+
import { buildBaseMediaResponseHeaders } from './buildBaseMediaResponseHeaders.js';
|
|
2
|
+
export function mediaErrorResponse(status, body, contentRange) {
|
|
3
|
+
const headers = buildBaseMediaResponseHeaders();
|
|
4
|
+
headers.set('Content-Type', 'text/plain;charset=UTF-8');
|
|
5
|
+
if (contentRange) {
|
|
6
|
+
headers.set('Content-Range', contentRange);
|
|
7
|
+
}
|
|
8
|
+
return new Response(body, {
|
|
9
|
+
headers,
|
|
10
|
+
status
|
|
11
|
+
});
|
|
12
|
+
}
|
|
@@ -0,0 +1,13 @@
|
|
|
1
|
+
import { DEFAULT_MEDIA_CACHE_CONTROL } from './getDownloadResponseHeaderPolicy.js';
|
|
2
|
+
export const resolveDownloadResponseHeaders = ({ collection, payloadResponseHeaders })=>{
|
|
3
|
+
let headers = new Headers(payloadResponseHeaders);
|
|
4
|
+
if (!headers.has('Cache-Control')) {
|
|
5
|
+
headers.set('Cache-Control', DEFAULT_MEDIA_CACHE_CONTROL);
|
|
6
|
+
}
|
|
7
|
+
if (collection.upload && typeof collection.upload === 'object' && typeof collection.upload.modifyResponseHeaders === 'function') {
|
|
8
|
+
headers = collection.upload.modifyResponseHeaders({
|
|
9
|
+
headers
|
|
10
|
+
}) || headers;
|
|
11
|
+
}
|
|
12
|
+
return headers;
|
|
13
|
+
};
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
export declare function shouldAttachMedia(upstreamHeaders: Headers): boolean;
|
|
@@ -0,0 +1,34 @@
|
|
|
1
|
+
import { getMediaType } from './getMediaType.js';
|
|
2
|
+
// Only these media types may render inline on the application's origin.
|
|
3
|
+
// Unknown or active content must download as an attachment.
|
|
4
|
+
const INLINE_MEDIA_TYPES = new Set([
|
|
5
|
+
'application/font-woff',
|
|
6
|
+
'audio/aac',
|
|
7
|
+
'audio/flac',
|
|
8
|
+
'audio/mp4',
|
|
9
|
+
'audio/mpeg',
|
|
10
|
+
'audio/ogg',
|
|
11
|
+
'audio/wav',
|
|
12
|
+
'audio/webm',
|
|
13
|
+
'font/otf',
|
|
14
|
+
'font/ttf',
|
|
15
|
+
'font/woff',
|
|
16
|
+
'font/woff2',
|
|
17
|
+
'image/avif',
|
|
18
|
+
'image/bmp',
|
|
19
|
+
'image/gif',
|
|
20
|
+
'image/jpeg',
|
|
21
|
+
'image/png',
|
|
22
|
+
'image/vnd.microsoft.icon',
|
|
23
|
+
'image/webp',
|
|
24
|
+
'image/x-icon',
|
|
25
|
+
'video/mp4',
|
|
26
|
+
'video/mpeg',
|
|
27
|
+
'video/ogg',
|
|
28
|
+
'video/quicktime',
|
|
29
|
+
'video/webm'
|
|
30
|
+
]);
|
|
31
|
+
export function shouldAttachMedia(upstreamHeaders) {
|
|
32
|
+
const mediaType = getMediaType(upstreamHeaders);
|
|
33
|
+
return !mediaType || !INLINE_MEDIA_TYPES.has(mediaType);
|
|
34
|
+
}
|
|
@@ -4,6 +4,7 @@ import type { StorageClient } from './client.js';
|
|
|
4
4
|
type Args = {
|
|
5
5
|
client: StorageClient;
|
|
6
6
|
collection: CollectionConfig;
|
|
7
|
+
prefix?: string;
|
|
7
8
|
};
|
|
8
|
-
export declare const getHandler: ({ client, collection }: Args) => StaticHandler;
|
|
9
|
+
export declare const getHandler: ({ client, collection, prefix }: Args) => StaticHandler;
|
|
9
10
|
export {};
|