@payloadcms/next 3.15.2-canary.ee31a64 → 3.16.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/exports/utilities.d.ts +65 -5
- package/dist/exports/utilities.d.ts.map +1 -1
- package/dist/exports/utilities.js +49 -5
- package/dist/exports/utilities.js.map +1 -1
- package/dist/layouts/Root/index.d.ts.map +1 -1
- package/dist/layouts/Root/index.js +4 -4
- package/dist/layouts/Root/index.js.map +1 -1
- package/dist/routes/graphql/handler.d.ts.map +1 -1
- package/dist/routes/graphql/handler.js +1 -6
- package/dist/routes/graphql/handler.js.map +1 -1
- package/dist/routes/graphql/playground.d.ts +1 -1
- package/dist/routes/graphql/playground.d.ts.map +1 -1
- package/dist/routes/graphql/playground.js +1 -1
- package/dist/routes/graphql/playground.js.map +1 -1
- package/dist/routes/rest/index.d.ts +6 -26
- package/dist/routes/rest/index.d.ts.map +1 -1
- package/dist/routes/rest/index.js +25 -820
- package/dist/routes/rest/index.js.map +1 -1
- package/dist/routes/rest/og/index.d.ts +2 -8
- package/dist/routes/rest/og/index.d.ts.map +1 -1
- package/dist/routes/rest/og/index.js +3 -6
- package/dist/routes/rest/og/index.js.map +1 -1
- package/dist/utilities/getNextRequestI18n.d.ts +1 -1
- package/dist/utilities/getNextRequestI18n.d.ts.map +1 -1
- package/dist/utilities/getNextRequestI18n.js +1 -1
- package/dist/utilities/getNextRequestI18n.js.map +1 -1
- package/dist/utilities/getPayloadHMR.d.ts +8 -0
- package/dist/utilities/getPayloadHMR.d.ts.map +1 -1
- package/dist/utilities/getPayloadHMR.js +8 -0
- package/dist/utilities/getPayloadHMR.js.map +1 -1
- package/dist/utilities/getPreferences.d.ts +3 -0
- package/dist/utilities/getPreferences.d.ts.map +1 -0
- package/dist/utilities/{getPreference.js → getPreferences.js} +2 -2
- package/dist/utilities/getPreferences.js.map +1 -0
- package/dist/utilities/getRequestLocale.d.ts +3 -5
- package/dist/utilities/getRequestLocale.d.ts.map +1 -1
- package/dist/utilities/getRequestLocale.js +13 -6
- package/dist/utilities/getRequestLocale.js.map +1 -1
- package/dist/utilities/initPage/index.d.ts.map +1 -1
- package/dist/utilities/initPage/index.js +1 -3
- package/dist/utilities/initPage/index.js.map +1 -1
- package/dist/utilities/initReq.d.ts.map +1 -1
- package/dist/utilities/initReq.js +1 -2
- package/dist/utilities/initReq.js.map +1 -1
- package/dist/views/List/handleServerFunction.d.ts +1 -2
- package/dist/views/List/handleServerFunction.d.ts.map +1 -1
- package/dist/views/List/handleServerFunction.js.map +1 -1
- package/dist/views/List/index.d.ts.map +1 -1
- package/dist/views/List/index.js.map +1 -1
- package/package.json +7 -7
- package/dist/fetchAPI-multipart/fileFactory.d.ts +0 -16
- package/dist/fetchAPI-multipart/fileFactory.d.ts.map +0 -1
- package/dist/fetchAPI-multipart/fileFactory.js +0 -44
- package/dist/fetchAPI-multipart/fileFactory.js.map +0 -1
- package/dist/fetchAPI-multipart/handlers.d.ts +0 -14
- package/dist/fetchAPI-multipart/handlers.d.ts.map +0 -1
- package/dist/fetchAPI-multipart/handlers.js +0 -87
- package/dist/fetchAPI-multipart/handlers.js.map +0 -1
- package/dist/fetchAPI-multipart/index.d.ts +0 -32
- package/dist/fetchAPI-multipart/index.d.ts.map +0 -1
- package/dist/fetchAPI-multipart/index.js +0 -43
- package/dist/fetchAPI-multipart/index.js.map +0 -1
- package/dist/fetchAPI-multipart/isEligibleRequest.d.ts +0 -2
- package/dist/fetchAPI-multipart/isEligibleRequest.d.ts.map +0 -1
- package/dist/fetchAPI-multipart/isEligibleRequest.js +0 -18
- package/dist/fetchAPI-multipart/isEligibleRequest.js.map +0 -1
- package/dist/fetchAPI-multipart/processMultipart.d.ts +0 -9
- package/dist/fetchAPI-multipart/processMultipart.d.ts.map +0 -1
- package/dist/fetchAPI-multipart/processMultipart.js +0 -178
- package/dist/fetchAPI-multipart/processMultipart.js.map +0 -1
- package/dist/fetchAPI-multipart/processNested.d.ts +0 -2
- package/dist/fetchAPI-multipart/processNested.d.ts.map +0 -1
- package/dist/fetchAPI-multipart/processNested.js +0 -31
- package/dist/fetchAPI-multipart/processNested.js.map +0 -1
- package/dist/fetchAPI-multipart/uploadTimer.d.ts +0 -7
- package/dist/fetchAPI-multipart/uploadTimer.d.ts.map +0 -1
- package/dist/fetchAPI-multipart/uploadTimer.js +0 -20
- package/dist/fetchAPI-multipart/uploadTimer.js.map +0 -1
- package/dist/fetchAPI-multipart/utilities.d.ts +0 -65
- package/dist/fetchAPI-multipart/utilities.d.ts.map +0 -1
- package/dist/fetchAPI-multipart/utilities.js +0 -227
- package/dist/fetchAPI-multipart/utilities.js.map +0 -1
- package/dist/fetchAPI-stream-file/index.d.ts +0 -5
- package/dist/fetchAPI-stream-file/index.d.ts.map +0 -1
- package/dist/fetchAPI-stream-file/index.js +0 -27
- package/dist/fetchAPI-stream-file/index.js.map +0 -1
- package/dist/routes/rest/auth/access.d.ts +0 -3
- package/dist/routes/rest/auth/access.d.ts.map +0 -1
- package/dist/routes/rest/auth/access.js +0 -28
- package/dist/routes/rest/auth/access.js.map +0 -1
- package/dist/routes/rest/auth/forgotPassword.d.ts +0 -3
- package/dist/routes/rest/auth/forgotPassword.d.ts.map +0 -1
- package/dist/routes/rest/auth/forgotPassword.js +0 -34
- package/dist/routes/rest/auth/forgotPassword.js.map +0 -1
- package/dist/routes/rest/auth/init.d.ts +0 -3
- package/dist/routes/rest/auth/init.d.ts.map +0 -1
- package/dist/routes/rest/auth/init.js +0 -20
- package/dist/routes/rest/auth/init.js.map +0 -1
- package/dist/routes/rest/auth/login.d.ts +0 -3
- package/dist/routes/rest/auth/login.d.ts.map +0 -1
- package/dist/routes/rest/auth/login.js +0 -49
- package/dist/routes/rest/auth/login.js.map +0 -1
- package/dist/routes/rest/auth/logout.d.ts +0 -3
- package/dist/routes/rest/auth/logout.d.ts.map +0 -1
- package/dist/routes/rest/auth/logout.js +0 -40
- package/dist/routes/rest/auth/logout.js.map +0 -1
- package/dist/routes/rest/auth/me.d.ts +0 -3
- package/dist/routes/rest/auth/me.d.ts.map +0 -1
- package/dist/routes/rest/auth/me.js +0 -28
- package/dist/routes/rest/auth/me.js.map +0 -1
- package/dist/routes/rest/auth/refresh.d.ts +0 -3
- package/dist/routes/rest/auth/refresh.d.ts.map +0 -1
- package/dist/routes/rest/auth/refresh.js +0 -38
- package/dist/routes/rest/auth/refresh.js.map +0 -1
- package/dist/routes/rest/auth/registerFirstUser.d.ts +0 -3
- package/dist/routes/rest/auth/registerFirstUser.d.ts.map +0 -1
- package/dist/routes/rest/auth/registerFirstUser.js +0 -48
- package/dist/routes/rest/auth/registerFirstUser.js.map +0 -1
- package/dist/routes/rest/auth/resetPassword.d.ts +0 -3
- package/dist/routes/rest/auth/resetPassword.d.ts.map +0 -1
- package/dist/routes/rest/auth/resetPassword.js +0 -43
- package/dist/routes/rest/auth/resetPassword.js.map +0 -1
- package/dist/routes/rest/auth/unlock.d.ts +0 -3
- package/dist/routes/rest/auth/unlock.d.ts.map +0 -1
- package/dist/routes/rest/auth/unlock.js +0 -32
- package/dist/routes/rest/auth/unlock.js.map +0 -1
- package/dist/routes/rest/auth/verifyEmail.d.ts +0 -3
- package/dist/routes/rest/auth/verifyEmail.d.ts.map +0 -1
- package/dist/routes/rest/auth/verifyEmail.js +0 -27
- package/dist/routes/rest/auth/verifyEmail.js.map +0 -1
- package/dist/routes/rest/checkEndpoints.d.ts +0 -5
- package/dist/routes/rest/checkEndpoints.d.ts.map +0 -1
- package/dist/routes/rest/checkEndpoints.js +0 -14
- package/dist/routes/rest/checkEndpoints.js.map +0 -1
- package/dist/routes/rest/collections/count.d.ts +0 -3
- package/dist/routes/rest/collections/count.d.ts.map +0 -1
- package/dist/routes/rest/collections/count.js +0 -19
- package/dist/routes/rest/collections/count.js.map +0 -1
- package/dist/routes/rest/collections/create.d.ts +0 -3
- package/dist/routes/rest/collections/create.d.ts.map +0 -1
- package/dist/routes/rest/collections/create.js +0 -39
- package/dist/routes/rest/collections/create.js.map +0 -1
- package/dist/routes/rest/collections/delete.d.ts +0 -3
- package/dist/routes/rest/collections/delete.d.ts.map +0 -1
- package/dist/routes/rest/collections/delete.js +0 -57
- package/dist/routes/rest/collections/delete.js.map +0 -1
- package/dist/routes/rest/collections/deleteByID.d.ts +0 -3
- package/dist/routes/rest/collections/deleteByID.d.ts.map +0 -1
- package/dist/routes/rest/collections/deleteByID.js +0 -50
- package/dist/routes/rest/collections/deleteByID.js.map +0 -1
- package/dist/routes/rest/collections/docAccess.d.ts +0 -3
- package/dist/routes/rest/collections/docAccess.d.ts.map +0 -1
- package/dist/routes/rest/collections/docAccess.js +0 -22
- package/dist/routes/rest/collections/docAccess.js.map +0 -1
- package/dist/routes/rest/collections/duplicate.d.ts +0 -3
- package/dist/routes/rest/collections/duplicate.d.ts.map +0 -1
- package/dist/routes/rest/collections/duplicate.js +0 -47
- package/dist/routes/rest/collections/duplicate.js.map +0 -1
- package/dist/routes/rest/collections/find.d.ts +0 -3
- package/dist/routes/rest/collections/find.d.ts.map +0 -1
- package/dist/routes/rest/collections/find.js +0 -43
- package/dist/routes/rest/collections/find.js.map +0 -1
- package/dist/routes/rest/collections/findByID.d.ts +0 -3
- package/dist/routes/rest/collections/findByID.d.ts.map +0 -1
- package/dist/routes/rest/collections/findByID.js +0 -38
- package/dist/routes/rest/collections/findByID.js.map +0 -1
- package/dist/routes/rest/collections/findVersionByID.d.ts +0 -3
- package/dist/routes/rest/collections/findVersionByID.d.ts.map +0 -1
- package/dist/routes/rest/collections/findVersionByID.js +0 -36
- package/dist/routes/rest/collections/findVersionByID.js.map +0 -1
- package/dist/routes/rest/collections/findVersions.d.ts +0 -3
- package/dist/routes/rest/collections/findVersions.d.ts.map +0 -1
- package/dist/routes/rest/collections/findVersions.js +0 -39
- package/dist/routes/rest/collections/findVersions.js.map +0 -1
- package/dist/routes/rest/collections/preview.d.ts +0 -3
- package/dist/routes/rest/collections/preview.d.ts.map +0 -1
- package/dist/routes/rest/collections/preview.js +0 -49
- package/dist/routes/rest/collections/preview.js.map +0 -1
- package/dist/routes/rest/collections/restoreVersion.d.ts +0 -3
- package/dist/routes/rest/collections/restoreVersion.d.ts.map +0 -1
- package/dist/routes/rest/collections/restoreVersion.js +0 -40
- package/dist/routes/rest/collections/restoreVersion.js.map +0 -1
- package/dist/routes/rest/collections/update.d.ts +0 -3
- package/dist/routes/rest/collections/update.d.ts.map +0 -1
- package/dist/routes/rest/collections/update.js +0 -62
- package/dist/routes/rest/collections/update.js.map +0 -1
- package/dist/routes/rest/collections/updateByID.d.ts +0 -3
- package/dist/routes/rest/collections/updateByID.d.ts.map +0 -1
- package/dist/routes/rest/collections/updateByID.js +0 -55
- package/dist/routes/rest/collections/updateByID.js.map +0 -1
- package/dist/routes/rest/files/checkFileAccess.d.ts +0 -7
- package/dist/routes/rest/files/checkFileAccess.d.ts.map +0 -1
- package/dist/routes/rest/files/checkFileAccess.js +0 -57
- package/dist/routes/rest/files/checkFileAccess.js.map +0 -1
- package/dist/routes/rest/files/getFile.d.ts +0 -9
- package/dist/routes/rest/files/getFile.d.ts.map +0 -1
- package/dist/routes/rest/files/getFile.js +0 -70
- package/dist/routes/rest/files/getFile.js.map +0 -1
- package/dist/routes/rest/files/getFileTypeFallback.d.ts +0 -7
- package/dist/routes/rest/files/getFileTypeFallback.d.ts.map +0 -1
- package/dist/routes/rest/files/getFileTypeFallback.js +0 -20
- package/dist/routes/rest/files/getFileTypeFallback.js.map +0 -1
- package/dist/routes/rest/globals/docAccess.d.ts +0 -3
- package/dist/routes/rest/globals/docAccess.d.ts.map +0 -1
- package/dist/routes/rest/globals/docAccess.js +0 -20
- package/dist/routes/rest/globals/docAccess.js.map +0 -1
- package/dist/routes/rest/globals/findOne.d.ts +0 -3
- package/dist/routes/rest/globals/findOne.d.ts.map +0 -1
- package/dist/routes/rest/globals/findOne.js +0 -30
- package/dist/routes/rest/globals/findOne.js.map +0 -1
- package/dist/routes/rest/globals/findVersionByID.d.ts +0 -3
- package/dist/routes/rest/globals/findVersionByID.d.ts.map +0 -1
- package/dist/routes/rest/globals/findVersionByID.js +0 -30
- package/dist/routes/rest/globals/findVersionByID.js.map +0 -1
- package/dist/routes/rest/globals/findVersions.d.ts +0 -3
- package/dist/routes/rest/globals/findVersions.d.ts.map +0 -1
- package/dist/routes/rest/globals/findVersions.js +0 -39
- package/dist/routes/rest/globals/findVersions.js.map +0 -1
- package/dist/routes/rest/globals/preview.d.ts +0 -3
- package/dist/routes/rest/globals/preview.d.ts.map +0 -1
- package/dist/routes/rest/globals/preview.js +0 -47
- package/dist/routes/rest/globals/preview.js.map +0 -1
- package/dist/routes/rest/globals/restoreVersion.d.ts +0 -3
- package/dist/routes/rest/globals/restoreVersion.d.ts.map +0 -1
- package/dist/routes/rest/globals/restoreVersion.js +0 -34
- package/dist/routes/rest/globals/restoreVersion.js.map +0 -1
- package/dist/routes/rest/globals/update.d.ts +0 -3
- package/dist/routes/rest/globals/update.d.ts.map +0 -1
- package/dist/routes/rest/globals/update.js +0 -46
- package/dist/routes/rest/globals/update.js.map +0 -1
- package/dist/routes/rest/routeError.d.ts +0 -9
- package/dist/routes/rest/routeError.d.ts.map +0 -1
- package/dist/routes/rest/routeError.js +0 -83
- package/dist/routes/rest/routeError.js.map +0 -1
- package/dist/routes/rest/types.d.ts +0 -23
- package/dist/routes/rest/types.d.ts.map +0 -1
- package/dist/routes/rest/types.js +0 -2
- package/dist/routes/rest/types.js.map +0 -1
- package/dist/routes/rest/utilities/sanitizeCollectionID.d.ts +0 -9
- package/dist/routes/rest/utilities/sanitizeCollectionID.d.ts.map +0 -1
- package/dist/routes/rest/utilities/sanitizeCollectionID.js +0 -20
- package/dist/routes/rest/utilities/sanitizeCollectionID.js.map +0 -1
- package/dist/utilities/addDataAndFileToRequest.d.ts +0 -8
- package/dist/utilities/addDataAndFileToRequest.d.ts.map +0 -1
- package/dist/utilities/addDataAndFileToRequest.js +0 -47
- package/dist/utilities/addDataAndFileToRequest.js.map +0 -1
- package/dist/utilities/addLocalesToRequest.d.ts +0 -17
- package/dist/utilities/addLocalesToRequest.d.ts.map +0 -1
- package/dist/utilities/addLocalesToRequest.js +0 -65
- package/dist/utilities/addLocalesToRequest.js.map +0 -1
- package/dist/utilities/createPayloadRequest.d.ts +0 -11
- package/dist/utilities/createPayloadRequest.d.ts.map +0 -1
- package/dist/utilities/createPayloadRequest.js +0 -103
- package/dist/utilities/createPayloadRequest.js.map +0 -1
- package/dist/utilities/getPreference.d.ts +0 -3
- package/dist/utilities/getPreference.d.ts.map +0 -1
- package/dist/utilities/getPreference.js.map +0 -1
- package/dist/utilities/getRequestLanguage.d.ts +0 -12
- package/dist/utilities/getRequestLanguage.d.ts.map +0 -1
- package/dist/utilities/getRequestLanguage.js +0 -19
- package/dist/utilities/getRequestLanguage.js.map +0 -1
- package/dist/utilities/headersWithCors.d.ts +0 -8
- package/dist/utilities/headersWithCors.d.ts.map +0 -1
- package/dist/utilities/headersWithCors.js +0 -24
- package/dist/utilities/headersWithCors.js.map +0 -1
- package/dist/utilities/mergeHeaders.d.ts +0 -2
- package/dist/utilities/mergeHeaders.d.ts.map +0 -1
- package/dist/utilities/mergeHeaders.js +0 -10
- package/dist/utilities/mergeHeaders.js.map +0 -1
|
@@ -1,62 +0,0 @@
|
|
|
1
|
-
import { getTranslation } from '@payloadcms/translations';
|
|
2
|
-
import httpStatus from 'http-status';
|
|
3
|
-
import { sanitizePopulateParam, sanitizeSelectParam, updateOperation } from 'payload';
|
|
4
|
-
import { isNumber } from 'payload/shared';
|
|
5
|
-
import { headersWithCors } from '../../../utilities/headersWithCors.js';
|
|
6
|
-
export const update = async ({
|
|
7
|
-
collection,
|
|
8
|
-
req
|
|
9
|
-
}) => {
|
|
10
|
-
const {
|
|
11
|
-
depth,
|
|
12
|
-
draft,
|
|
13
|
-
limit,
|
|
14
|
-
overrideLock,
|
|
15
|
-
populate,
|
|
16
|
-
select,
|
|
17
|
-
where
|
|
18
|
-
} = req.query;
|
|
19
|
-
const result = await updateOperation({
|
|
20
|
-
collection,
|
|
21
|
-
data: req.data,
|
|
22
|
-
depth: isNumber(depth) ? Number(depth) : undefined,
|
|
23
|
-
draft: draft === 'true',
|
|
24
|
-
limit: isNumber(limit) ? Number(limit) : undefined,
|
|
25
|
-
overrideLock: Boolean(overrideLock === 'true'),
|
|
26
|
-
populate: sanitizePopulateParam(populate),
|
|
27
|
-
req,
|
|
28
|
-
select: sanitizeSelectParam(select),
|
|
29
|
-
where
|
|
30
|
-
});
|
|
31
|
-
const headers = headersWithCors({
|
|
32
|
-
headers: new Headers(),
|
|
33
|
-
req
|
|
34
|
-
});
|
|
35
|
-
if (result.errors.length === 0) {
|
|
36
|
-
const message = req.t('general:updatedCountSuccessfully', {
|
|
37
|
-
count: result.docs.length,
|
|
38
|
-
label: getTranslation(collection.config.labels[result.docs.length === 1 ? 'singular' : 'plural'], req.i18n)
|
|
39
|
-
});
|
|
40
|
-
return Response.json({
|
|
41
|
-
...result,
|
|
42
|
-
message
|
|
43
|
-
}, {
|
|
44
|
-
headers,
|
|
45
|
-
status: httpStatus.OK
|
|
46
|
-
});
|
|
47
|
-
}
|
|
48
|
-
const total = result.docs.length + result.errors.length;
|
|
49
|
-
const message = req.t('error:unableToUpdateCount', {
|
|
50
|
-
count: result.errors.length,
|
|
51
|
-
label: getTranslation(collection.config.labels[total === 1 ? 'singular' : 'plural'], req.i18n),
|
|
52
|
-
total
|
|
53
|
-
});
|
|
54
|
-
return Response.json({
|
|
55
|
-
...result,
|
|
56
|
-
message
|
|
57
|
-
}, {
|
|
58
|
-
headers,
|
|
59
|
-
status: httpStatus.BAD_REQUEST
|
|
60
|
-
});
|
|
61
|
-
};
|
|
62
|
-
//# sourceMappingURL=update.js.map
|
|
@@ -1 +0,0 @@
|
|
|
1
|
-
{"version":3,"file":"update.js","names":["getTranslation","httpStatus","sanitizePopulateParam","sanitizeSelectParam","updateOperation","isNumber","headersWithCors","update","collection","req","depth","draft","limit","overrideLock","populate","select","where","query","result","data","Number","undefined","Boolean","headers","Headers","errors","length","message","t","count","docs","label","config","labels","i18n","Response","json","status","OK","total","BAD_REQUEST"],"sources":["../../../../src/routes/rest/collections/update.ts"],"sourcesContent":["import type { Where } from 'payload'\n\nimport { getTranslation } from '@payloadcms/translations'\nimport httpStatus from 'http-status'\nimport { sanitizePopulateParam, sanitizeSelectParam, updateOperation } from 'payload'\nimport { isNumber } from 'payload/shared'\n\nimport type { CollectionRouteHandler } from '../types.js'\n\nimport { headersWithCors } from '../../../utilities/headersWithCors.js'\n\nexport const update: CollectionRouteHandler = async ({ collection, req }) => {\n const { depth, draft, limit, overrideLock, populate, select, where } = req.query as {\n depth?: string\n draft?: string\n limit?: string\n overrideLock?: string\n populate?: Record<string, unknown>\n select?: Record<string, unknown>\n where?: Where\n }\n\n const result = await updateOperation({\n collection,\n data: req.data,\n depth: isNumber(depth) ? Number(depth) : undefined,\n draft: draft === 'true',\n limit: isNumber(limit) ? Number(limit) : undefined,\n overrideLock: Boolean(overrideLock === 'true'),\n populate: sanitizePopulateParam(populate),\n req,\n select: sanitizeSelectParam(select),\n where,\n })\n\n const headers = headersWithCors({\n headers: new Headers(),\n req,\n })\n\n if (result.errors.length === 0) {\n const message = req.t('general:updatedCountSuccessfully', {\n count: result.docs.length,\n label: getTranslation(\n collection.config.labels[result.docs.length === 1 ? 'singular' : 'plural'],\n req.i18n,\n ),\n })\n\n return Response.json(\n {\n ...result,\n message,\n },\n {\n headers,\n status: httpStatus.OK,\n },\n )\n }\n\n const total = result.docs.length + result.errors.length\n const message = req.t('error:unableToUpdateCount', {\n count: result.errors.length,\n label: getTranslation(collection.config.labels[total === 1 ? 'singular' : 'plural'], req.i18n),\n total,\n })\n\n return Response.json(\n {\n ...result,\n message,\n },\n {\n headers,\n status: httpStatus.BAD_REQUEST,\n },\n )\n}\n"],"mappings":"AAEA,SAASA,cAAc,QAAQ;AAC/B,OAAOC,UAAA,MAAgB;AACvB,SAASC,qBAAqB,EAAEC,mBAAmB,EAAE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J,OAAA;MACAc,MAAA,EAAQpC,UAAA,CAAWqC;IACrB;EAEJ;EAEA,MAAMC,KAAA,GAAQrB,MAAA,CAAOY,IAAI,CAACJ,MAAM,GAAGR,MAAA,CAAOO,MAAM,CAACC,MAAM;EACvD,MAAMC,OAAA,GAAUlB,GAAA,CAAImB,CAAC,CAAC,6BAA6B;IACjDC,KAAA,EAAOX,MAAA,CAAOO,MAAM,CAACC,MAAM;IAC3BK,KAAA,EAAO/B,cAAA,CAAeQ,UAAA,CAAWwB,MAAM,CAACC,MAAM,CAACM,KAAA,KAAU,IAAI,aAAa,SAAS,EAAE9B,GAAA,CAAIyB,IAAI;IAC7FK;EACF;EAEA,OAAOJ,QAAA,CAASC,IAAI,CAClB;IACE,GAAGlB,MAAM;IACTS;EACF,GACA;IACEJ,OAAA;IACAc,MAAA,EAAQpC,UAAA,CAAWuC;EACrB;AAEJ","ignoreList":[]}
|
|
@@ -1 +0,0 @@
|
|
|
1
|
-
{"version":3,"file":"updateByID.d.ts","sourceRoot":"","sources":["../../../../src/routes/rest/collections/updateByID.ts"],"names":[],"mappings":"AAIA,OAAO,KAAK,EAAE,4BAA4B,EAAE,MAAM,aAAa,CAAA;AAK/D,eAAO,MAAM,UAAU,EAAE,4BAsDxB,CAAA"}
|
|
@@ -1,55 +0,0 @@
|
|
|
1
|
-
import httpStatus from 'http-status';
|
|
2
|
-
import { sanitizePopulateParam, sanitizeSelectParam, updateByIDOperation } from 'payload';
|
|
3
|
-
import { isNumber } from 'payload/shared';
|
|
4
|
-
import { headersWithCors } from '../../../utilities/headersWithCors.js';
|
|
5
|
-
import { sanitizeCollectionID } from '../utilities/sanitizeCollectionID.js';
|
|
6
|
-
export const updateByID = async ({
|
|
7
|
-
id: incomingID,
|
|
8
|
-
collection,
|
|
9
|
-
req
|
|
10
|
-
}) => {
|
|
11
|
-
const {
|
|
12
|
-
searchParams
|
|
13
|
-
} = req;
|
|
14
|
-
const depth = searchParams.get('depth');
|
|
15
|
-
const autosave = searchParams.get('autosave') === 'true';
|
|
16
|
-
const draft = searchParams.get('draft') === 'true';
|
|
17
|
-
const overrideLock = searchParams.get('overrideLock');
|
|
18
|
-
const publishSpecificLocale = req.query.publishSpecificLocale;
|
|
19
|
-
const id = sanitizeCollectionID({
|
|
20
|
-
id: incomingID,
|
|
21
|
-
collectionSlug: collection.config.slug,
|
|
22
|
-
payload: req.payload
|
|
23
|
-
});
|
|
24
|
-
const doc = await updateByIDOperation({
|
|
25
|
-
id,
|
|
26
|
-
autosave,
|
|
27
|
-
collection,
|
|
28
|
-
data: req.data,
|
|
29
|
-
depth: isNumber(depth) ? Number(depth) : undefined,
|
|
30
|
-
draft,
|
|
31
|
-
overrideLock: Boolean(overrideLock === 'true'),
|
|
32
|
-
populate: sanitizePopulateParam(req.query.populate),
|
|
33
|
-
publishSpecificLocale,
|
|
34
|
-
req,
|
|
35
|
-
select: sanitizeSelectParam(req.query.select)
|
|
36
|
-
});
|
|
37
|
-
let message = req.t('general:updatedSuccessfully');
|
|
38
|
-
if (draft) {
|
|
39
|
-
message = req.t('version:draftSavedSuccessfully');
|
|
40
|
-
}
|
|
41
|
-
if (autosave) {
|
|
42
|
-
message = req.t('version:autosavedSuccessfully');
|
|
43
|
-
}
|
|
44
|
-
return Response.json({
|
|
45
|
-
doc,
|
|
46
|
-
message
|
|
47
|
-
}, {
|
|
48
|
-
headers: headersWithCors({
|
|
49
|
-
headers: new Headers(),
|
|
50
|
-
req
|
|
51
|
-
}),
|
|
52
|
-
status: httpStatus.OK
|
|
53
|
-
});
|
|
54
|
-
};
|
|
55
|
-
//# sourceMappingURL=updateByID.js.map
|
|
@@ -1 +0,0 @@
|
|
|
1
|
-
{"version":3,"file":"updateByID.js","names":["httpStatus","sanitizePopulateParam","sanitizeSelectParam","updateByIDOperation","isNumber","headersWithCors","sanitizeCollectionID","updateByID","id","incomingID","collection","req","searchParams","depth","get","autosave","draft","overrideLock","publishSpecificLocale","query","collectionSlug","config","slug","payload","doc","data","Number","undefined","Boolean","populate","select","message","t","Response","json","headers","Headers","status","OK"],"sources":["../../../../src/routes/rest/collections/updateByID.ts"],"sourcesContent":["import httpStatus from 'http-status'\nimport { sanitizePopulateParam, sanitizeSelectParam, updateByIDOperation } from 'payload'\nimport { isNumber } from 'payload/shared'\n\nimport type { CollectionRouteHandlerWithID } from '../types.js'\n\nimport { headersWithCors } from '../../../utilities/headersWithCors.js'\nimport { sanitizeCollectionID } from '../utilities/sanitizeCollectionID.js'\n\nexport const updateByID: CollectionRouteHandlerWithID = async ({\n id: incomingID,\n collection,\n req,\n}) => {\n const { searchParams } = req\n const depth = searchParams.get('depth')\n const autosave = searchParams.get('autosave') === 'true'\n const draft = searchParams.get('draft') === 'true'\n const overrideLock = searchParams.get('overrideLock')\n const publishSpecificLocale = req.query.publishSpecificLocale as string | undefined\n\n const id = sanitizeCollectionID({\n id: incomingID,\n collectionSlug: collection.config.slug,\n payload: req.payload,\n })\n\n const doc = await updateByIDOperation({\n id,\n autosave,\n collection,\n data: req.data,\n depth: isNumber(depth) ? Number(depth) : undefined,\n draft,\n overrideLock: Boolean(overrideLock === 'true'),\n populate: sanitizePopulateParam(req.query.populate),\n publishSpecificLocale,\n req,\n select: sanitizeSelectParam(req.query.select),\n })\n\n let message = req.t('general:updatedSuccessfully')\n\n if (draft) {\n message = req.t('version:draftSavedSuccessfully')\n }\n if (autosave) {\n message = req.t('version:autosavedSuccessfully')\n }\n\n return Response.json(\n {\n doc,\n message,\n },\n {\n headers: headersWithCors({\n headers: new Headers(),\n req,\n }),\n status: httpStatus.OK,\n },\n )\n}\n"],"mappings":"AAAA,OAAOA,UAAA,MAAgB;AACvB,SAASC,qBAAqB,EAAEC,mBAAmB,EAAEC,mBAAmB,QAAQ;AAChF,SAASC,QAAQ,QAAQ;AAIzB,SAASC,eAAe,QAAQ;AAChC,SAASC,oBAAoB,QAAQ;AAErC,OAAO,MAAMC,UAAA,GAA2C,MAAAA,CAAO;EAC7DC,EAAA,EAAIC,UAAU;EACdC,UA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AAA,EAAS9B,eAAA,CAAgB;MACvB8B,OAAA,EAAS,IAAIC,OAAA;MACbzB;IACF;IACA0B,MAAA,EAAQrC,UAAA,CAAWsC;EACrB;AAEJ","ignoreList":[]}
|
|
@@ -1,7 +0,0 @@
|
|
|
1
|
-
import type { Collection, PayloadRequest, TypeWithID } from 'payload';
|
|
2
|
-
export declare function checkFileAccess({ collection, filename, req, }: {
|
|
3
|
-
collection: Collection;
|
|
4
|
-
filename: string;
|
|
5
|
-
req: PayloadRequest;
|
|
6
|
-
}): Promise<Response | TypeWithID>;
|
|
7
|
-
//# sourceMappingURL=checkFileAccess.d.ts.map
|
|
@@ -1 +0,0 @@
|
|
|
1
|
-
{"version":3,"file":"checkFileAccess.d.ts","sourceRoot":"","sources":["../../../../src/routes/rest/files/checkFileAccess.ts"],"names":[],"mappings":"AAAA,OAAO,KAAK,EAAE,UAAU,EAAE,cAAc,EAAE,UAAU,EAAS,MAAM,SAAS,CAAA;AAM5E,wBAAsB,eAAe,CAAC,EACpC,UAAU,EACV,QAAQ,EACR,GAAG,GACJ,EAAE;IACD,UAAU,EAAE,UAAU,CAAA;IACtB,QAAQ,EAAE,MAAM,CAAA;IAChB,GAAG,EAAE,cAAc,CAAA;CACpB,GAAG,OAAO,CAAC,QAAQ,GAAG,UAAU,CAAC,CAmDjC"}
|
|
@@ -1,57 +0,0 @@
|
|
|
1
|
-
import { executeAccess, Forbidden } from 'payload';
|
|
2
|
-
import { endpointsAreDisabled } from '../checkEndpoints.js';
|
|
3
|
-
export async function checkFileAccess({
|
|
4
|
-
collection,
|
|
5
|
-
filename,
|
|
6
|
-
req
|
|
7
|
-
}) {
|
|
8
|
-
const {
|
|
9
|
-
config
|
|
10
|
-
} = collection;
|
|
11
|
-
const disableEndpoints = endpointsAreDisabled({
|
|
12
|
-
endpoints: config.endpoints,
|
|
13
|
-
request: req
|
|
14
|
-
});
|
|
15
|
-
if (disableEndpoints) {
|
|
16
|
-
return disableEndpoints;
|
|
17
|
-
}
|
|
18
|
-
if (filename.includes('../') || filename.includes('..\\')) {
|
|
19
|
-
throw new Forbidden(req.t);
|
|
20
|
-
}
|
|
21
|
-
const accessResult = await executeAccess({
|
|
22
|
-
isReadingStaticFile: true,
|
|
23
|
-
req
|
|
24
|
-
}, config.access.read);
|
|
25
|
-
if (typeof accessResult === 'object') {
|
|
26
|
-
const queryToBuild = {
|
|
27
|
-
and: [{
|
|
28
|
-
or: [{
|
|
29
|
-
filename: {
|
|
30
|
-
equals: filename
|
|
31
|
-
}
|
|
32
|
-
}]
|
|
33
|
-
}, accessResult]
|
|
34
|
-
};
|
|
35
|
-
if (config.upload.imageSizes) {
|
|
36
|
-
config.upload.imageSizes.forEach(({
|
|
37
|
-
name
|
|
38
|
-
}) => {
|
|
39
|
-
queryToBuild.and[0].or.push({
|
|
40
|
-
[`sizes.${name}.filename`]: {
|
|
41
|
-
equals: filename
|
|
42
|
-
}
|
|
43
|
-
});
|
|
44
|
-
});
|
|
45
|
-
}
|
|
46
|
-
const doc = await req.payload.db.findOne({
|
|
47
|
-
collection: config.slug,
|
|
48
|
-
req,
|
|
49
|
-
where: queryToBuild
|
|
50
|
-
});
|
|
51
|
-
if (!doc) {
|
|
52
|
-
throw new Forbidden(req.t);
|
|
53
|
-
}
|
|
54
|
-
return doc;
|
|
55
|
-
}
|
|
56
|
-
}
|
|
57
|
-
//# sourceMappingURL=checkFileAccess.js.map
|
|
@@ -1 +0,0 @@
|
|
|
1
|
-
{"version":3,"file":"checkFileAccess.js","names":["executeAccess","Forbidden","endpointsAreDisabled","checkFileAccess","collection","filename","req","config","disableEndpoints","endpoints","request","includes","t","accessResult","isReadingStaticFile","access","read","queryToBuild","and","or","equals","upload","imageSizes","forEach","name","push","doc","payload","db","findOne","slug","where"],"sources":["../../../../src/routes/rest/files/checkFileAccess.ts"],"sourcesContent":["import type { Collection, PayloadRequest, TypeWithID, Where } from 'payload'\n\nimport { executeAccess, Forbidden } from 'payload'\n\nimport { endpointsAreDisabled } from '../checkEndpoints.js'\n\nexport async function checkFileAccess({\n collection,\n filename,\n req,\n}: {\n collection: Collection\n filename: string\n req: PayloadRequest\n}): Promise<Response | TypeWithID> {\n const { config } = collection\n const disableEndpoints = endpointsAreDisabled({ endpoints: config.endpoints, request: req })\n if (disableEndpoints) {\n return disableEndpoints\n }\n\n if (filename.includes('../') || filename.includes('..\\\\')) {\n throw new Forbidden(req.t)\n }\n\n const accessResult = await executeAccess({ isReadingStaticFile: true, req }, config.access.read)\n\n if (typeof accessResult === 'object') {\n const queryToBuild: Where = {\n and: [\n {\n or: [\n {\n filename: {\n equals: filename,\n },\n },\n ],\n },\n accessResult,\n ],\n }\n\n if (config.upload.imageSizes) {\n config.upload.imageSizes.forEach(({ name }) => {\n queryToBuild.and[0].or.push({\n [`sizes.${name}.filename`]: {\n equals: filename,\n },\n })\n })\n }\n\n const doc = await req.payload.db.findOne({\n collection: config.slug,\n req,\n where: queryToBuild,\n })\n\n if (!doc) {\n throw new Forbidden(req.t)\n }\n\n return doc\n }\n}\n"],"mappings":"AAEA,SAASA,aAAa,EAAEC,SAAS,QAAQ;AAEzC,SAASC,oBAAoB,QAAQ;AAErC,OAAO,eAAeC,gBAAgB;EACpCC,UAAU;EACVC,QAAQ;EACRC;AAAG,CAKJ;EACC,MAAM;IAAEC;EAAM,CAAE,GAAGH,UAAA;EACnB,MAAMI,gBAAA,GAAmBN,oBAAA,CAAqB;IAAEO,SAAA,EAAWF,MAAA,CAAOE,SAAS;IAAEC,OAAA,EAASJ;EAAI;EAC1F,IAAIE,gBAAA,EAAkB;IACpB,OAAOA,gBAAA;EACT;EAEA,IAAIH,QAAA,CAASM,QAAQ,CAAC,UAAUN,QAAA,CAASM,QAAQ,CAAC,SAAS;IACzD,MAAM,IAAIV,SAAA,CAAUK,GAAA,CAAIM,CAAC;EAC3B;EAEA,MAAMC,YAAA,GAAe,MAAMb,aAAA,CAAc;IAAEc,mBAAA,EAAqB;IAAMR;EAAI,GAAGC,MAAA,CAAOQ,MAAM,CAACC,IAAI;EAE/F,IAAI,OAAOH,YAAA,KAAiB,UAAU;IACpC,MAAMI,YAAA,GAAsB;MAC1BC,GAAA,EAAK,CACH;QACEC,EAAA,EAAI,CACF;UACEd,QAAA,EAAU;YACRe,MAAA,EAAQf;UACV;QACF;MAEJ,GACAQ,YAAA;IAEJ;IAEA,IAAIN,MAAA,CAAOc,MAAM,CAACC,UAAU,EAAE;MAC5Bf,MAAA,CAAOc,MAAM,CAACC,UAAU,CAACC,OAAO,CAAC,CAAC;QAAEC;MAAI,CAAE;QACxCP,YAAA,CAAaC,GAAG,CAAC,EAAE,CAACC,EAAE,CAACM,IAAI,CAAC;UAC1B,CAAC,SAASD,IAAA,WAAe,GAAG;YAC1BJ,MAAA,EAAQf;UACV;QACF;MACF;IACF;IAEA,MAAMqB,GAAA,GAAM,MAAMpB,GAAA,CAAIqB,OAAO,CAACC,EAAE,CAACC,OAAO,CAAC;MACvCzB,UAAA,EAAYG,MAAA,CAAOuB,IAAI;MACvBxB,GAAA;MACAyB,KAAA,EAAOd;IACT;IAEA,IAAI,CAACS,GAAA,EAAK;MACR,MAAM,IAAIzB,SAAA,CAAUK,GAAA,CAAIM,CAAC;IAC3B;IAEA,OAAOc,GAAA;EACT;AACF","ignoreList":[]}
|
|
@@ -1,9 +0,0 @@
|
|
|
1
|
-
import type { Collection, PayloadRequest } from 'payload';
|
|
2
|
-
type Args = {
|
|
3
|
-
collection: Collection;
|
|
4
|
-
filename: string;
|
|
5
|
-
req: PayloadRequest;
|
|
6
|
-
};
|
|
7
|
-
export declare const getFile: ({ collection, filename, req }: Args) => Promise<Response>;
|
|
8
|
-
export {};
|
|
9
|
-
//# sourceMappingURL=getFile.d.ts.map
|
|
@@ -1 +0,0 @@
|
|
|
1
|
-
{"version":3,"file":"getFile.d.ts","sourceRoot":"","sources":["../../../../src/routes/rest/files/getFile.ts"],"names":[],"mappings":"AAAA,OAAO,KAAK,EAAE,UAAU,EAAE,cAAc,EAAE,MAAM,SAAS,CAAA;AAezD,KAAK,IAAI,GAAG;IACV,UAAU,EAAE,UAAU,CAAA;IACtB,QAAQ,EAAE,MAAM,CAAA;IAChB,GAAG,EAAE,cAAc,CAAA;CACpB,CAAA;AACD,eAAO,MAAM,OAAO,kCAAyC,IAAI,KAAG,OAAO,CAAC,QAAQ,CAgEnF,CAAA"}
|
|
@@ -1,70 +0,0 @@
|
|
|
1
|
-
import { fileTypeFromFile } from 'file-type';
|
|
2
|
-
import fsPromises from 'fs/promises';
|
|
3
|
-
import httpStatus from 'http-status';
|
|
4
|
-
import path from 'path';
|
|
5
|
-
import { APIError } from 'payload';
|
|
6
|
-
import { streamFile } from '../../../fetchAPI-stream-file/index.js';
|
|
7
|
-
import { headersWithCors } from '../../../utilities/headersWithCors.js';
|
|
8
|
-
import { routeError } from '../routeError.js';
|
|
9
|
-
import { checkFileAccess } from './checkFileAccess.js';
|
|
10
|
-
import { getFileTypeFallback } from './getFileTypeFallback.js';
|
|
11
|
-
export const getFile = async ({
|
|
12
|
-
collection,
|
|
13
|
-
filename,
|
|
14
|
-
req
|
|
15
|
-
}) => {
|
|
16
|
-
try {
|
|
17
|
-
if (!collection.config.upload) {
|
|
18
|
-
throw new APIError(`This collection is not an upload collection: ${collection.config.slug}`, httpStatus.BAD_REQUEST);
|
|
19
|
-
}
|
|
20
|
-
const accessResult = await checkFileAccess({
|
|
21
|
-
collection,
|
|
22
|
-
filename,
|
|
23
|
-
req
|
|
24
|
-
});
|
|
25
|
-
if (accessResult instanceof Response) {
|
|
26
|
-
return accessResult;
|
|
27
|
-
}
|
|
28
|
-
if (collection.config.upload.handlers?.length) {
|
|
29
|
-
let customResponse = null;
|
|
30
|
-
for (const handler of collection.config.upload.handlers) {
|
|
31
|
-
customResponse = await handler(req, {
|
|
32
|
-
doc: accessResult,
|
|
33
|
-
params: {
|
|
34
|
-
collection: collection.config.slug,
|
|
35
|
-
filename
|
|
36
|
-
}
|
|
37
|
-
});
|
|
38
|
-
}
|
|
39
|
-
if (customResponse instanceof Response) {
|
|
40
|
-
return customResponse;
|
|
41
|
-
}
|
|
42
|
-
}
|
|
43
|
-
const fileDir = collection.config.upload?.staticDir || collection.config.slug;
|
|
44
|
-
const filePath = path.resolve(`${fileDir}/${filename}`);
|
|
45
|
-
const stats = await fsPromises.stat(filePath);
|
|
46
|
-
const data = streamFile(filePath);
|
|
47
|
-
const fileTypeResult = (await fileTypeFromFile(filePath)) || getFileTypeFallback(filePath);
|
|
48
|
-
let headers = new Headers();
|
|
49
|
-
headers.set('Content-Type', fileTypeResult.mime);
|
|
50
|
-
headers.set('Content-Length', stats.size + '');
|
|
51
|
-
headers = collection.config.upload?.modifyResponseHeaders ? collection.config.upload.modifyResponseHeaders({
|
|
52
|
-
headers
|
|
53
|
-
}) : headers;
|
|
54
|
-
return new Response(data, {
|
|
55
|
-
headers: headersWithCors({
|
|
56
|
-
headers,
|
|
57
|
-
req
|
|
58
|
-
}),
|
|
59
|
-
status: httpStatus.OK
|
|
60
|
-
});
|
|
61
|
-
} catch (err) {
|
|
62
|
-
return routeError({
|
|
63
|
-
collection,
|
|
64
|
-
config: req.payload.config,
|
|
65
|
-
err,
|
|
66
|
-
req
|
|
67
|
-
});
|
|
68
|
-
}
|
|
69
|
-
};
|
|
70
|
-
//# sourceMappingURL=getFile.js.map
|
|
@@ -1 +0,0 @@
|
|
|
1
|
-
{"version":3,"file":"getFile.js","names":["fileTypeFromFile","fsPromises","httpStatus","path","APIError","streamFile","headersWithCors","routeError","checkFileAccess","getFileTypeFallback","getFile","collection","filename","req","config","upload","slug","BAD_REQUEST","accessResult","Response","handlers","length","customResponse","handler","doc","params","fileDir","staticDir","filePath","resolve","stats","stat","data","fileTypeResult","headers","Headers","set","mime","size","modifyResponseHeaders","status","OK","err","payload"],"sources":["../../../../src/routes/rest/files/getFile.ts"],"sourcesContent":["import type { Collection, PayloadRequest } from 'payload'\n\nimport { fileTypeFromFile } from 'file-type'\nimport fsPromises from 'fs/promises'\nimport httpStatus from 'http-status'\nimport path from 'path'\nimport { APIError } from 'payload'\n\nimport { streamFile } from '../../../fetchAPI-stream-file/index.js'\nimport { headersWithCors } from '../../../utilities/headersWithCors.js'\nimport { routeError } from '../routeError.js'\nimport { checkFileAccess } from './checkFileAccess.js'\nimport { getFileTypeFallback } from './getFileTypeFallback.js'\n\n// /:collectionSlug/file/:filename\ntype Args = {\n collection: Collection\n filename: string\n req: PayloadRequest\n}\nexport const getFile = async ({ collection, filename, req }: Args): Promise<Response> => {\n try {\n if (!collection.config.upload) {\n throw new APIError(\n `This collection is not an upload collection: ${collection.config.slug}`,\n httpStatus.BAD_REQUEST,\n )\n }\n\n const accessResult = await checkFileAccess({\n collection,\n filename,\n req,\n })\n\n if (accessResult instanceof Response) {\n return accessResult\n }\n\n if (collection.config.upload.handlers?.length) {\n let customResponse = null\n for (const handler of collection.config.upload.handlers) {\n customResponse = await handler(req, {\n doc: accessResult,\n params: {\n collection: collection.config.slug,\n filename,\n },\n })\n }\n\n if (customResponse instanceof Response) {\n return customResponse\n }\n }\n\n const fileDir = collection.config.upload?.staticDir || collection.config.slug\n const filePath = path.resolve(`${fileDir}/${filename}`)\n const stats = await fsPromises.stat(filePath)\n const data = streamFile(filePath)\n const fileTypeResult = (await fileTypeFromFile(filePath)) || getFileTypeFallback(filePath)\n\n let headers = new Headers()\n headers.set('Content-Type', fileTypeResult.mime)\n headers.set('Content-Length', stats.size + '')\n headers = collection.config.upload?.modifyResponseHeaders\n ? collection.config.upload.modifyResponseHeaders({ headers })\n : headers\n\n return new Response(data, {\n headers: headersWithCors({\n headers,\n req,\n }),\n status: httpStatus.OK,\n })\n } catch (err) {\n return routeError({\n collection,\n config: req.payload.config,\n err,\n req,\n })\n }\n}\n"],"mappings":"AAEA,SAASA,gBAAgB,QAAQ;AACjC,OAAOC,UAAA,MAAgB;AACvB,OAAOC,UAAA,MAAgB;AACvB,OAAOC,IAAA,MAAU;AACjB,SAASC,QAAQ,QAAQ;AAEzB,SAASC,UAAU,QAAQ;AAC3B,SAASC,eA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,UAAA,CAAWuB,QAAA;IACxB,MAAMK,cAAA,GAAiB,OAAOjC,gBAAA,CAAiB4B,QAAA,MAAcnB,mBAAA,CAAoBmB,QAAA;IAEjF,IAAIM,OAAA,GAAU,IAAIC,OAAA;IAClBD,OAAA,CAAQE,GAAG,CAAC,gBAAgBH,cAAA,CAAeI,IAAI;IAC/CH,OAAA,CAAQE,GAAG,CAAC,kBAAkBN,KAAA,CAAMQ,IAAI,GAAG;IAC3CJ,OAAA,GAAUvB,UAAA,CAAWG,MAAM,CAACC,MAAM,EAAEwB,qBAAA,GAChC5B,UAAA,CAAWG,MAAM,CAACC,MAAM,CAACwB,qBAAqB,CAAC;MAAEL;IAAQ,KACzDA,OAAA;IAEJ,OAAO,IAAIf,QAAA,CAASa,IAAA,EAAM;MACxBE,OAAA,EAAS5B,eAAA,CAAgB;QACvB4B,OAAA;QACArB;MACF;MACA2B,MAAA,EAAQtC,UAAA,CAAWuC;IACrB;EACF,EAAE,OAAOC,GAAA,EAAK;IACZ,OAAOnC,UAAA,CAAW;MAChBI,UAAA;MACAG,MAAA,EAAQD,GAAA,CAAI8B,OAAO,CAAC7B,MAAM;MAC1B4B,GAAA;MACA7B;IACF;EACF;AACF","ignoreList":[]}
|
|
@@ -1 +0,0 @@
|
|
|
1
|
-
{"version":3,"file":"getFileTypeFallback.d.ts","sourceRoot":"","sources":["../../../../src/routes/rest/files/getFileTypeFallback.ts"],"names":[],"mappings":"AAAA,KAAK,UAAU,GAAG;IAChB,GAAG,EAAE,MAAM,CAAA;IACX,IAAI,EAAE,MAAM,CAAA;CACb,CAAA;AAiBD,eAAO,MAAM,mBAAmB,SAAU,MAAM,KAAG,UAOlD,CAAA"}
|
|
@@ -1,20 +0,0 @@
|
|
|
1
|
-
const extensionMap = {
|
|
2
|
-
css: 'text/css',
|
|
3
|
-
csv: 'text/csv',
|
|
4
|
-
htm: 'text/html',
|
|
5
|
-
html: 'text/html',
|
|
6
|
-
js: 'application/javascript',
|
|
7
|
-
json: 'application/json',
|
|
8
|
-
md: 'text/markdown',
|
|
9
|
-
svg: 'image/svg+xml',
|
|
10
|
-
xml: 'application/xml',
|
|
11
|
-
yml: 'application/x-yaml'
|
|
12
|
-
};
|
|
13
|
-
export const getFileTypeFallback = path => {
|
|
14
|
-
const ext = path.split('.').pop() || 'txt';
|
|
15
|
-
return {
|
|
16
|
-
ext,
|
|
17
|
-
mime: extensionMap[ext] || 'text/plain'
|
|
18
|
-
};
|
|
19
|
-
};
|
|
20
|
-
//# sourceMappingURL=getFileTypeFallback.js.map
|
|
@@ -1 +0,0 @@
|
|
|
1
|
-
{"version":3,"file":"getFileTypeFallback.js","names":["extensionMap","css","csv","htm","html","js","json","md","svg","xml","yml","getFileTypeFallback","path","ext","split","pop","mime"],"sources":["../../../../src/routes/rest/files/getFileTypeFallback.ts"],"sourcesContent":["type ReturnType = {\n ext: string\n mime: string\n}\n\nconst extensionMap: {\n [ext: string]: string\n} = {\n css: 'text/css',\n csv: 'text/csv',\n htm: 'text/html',\n html: 'text/html',\n js: 'application/javascript',\n json: 'application/json',\n md: 'text/markdown',\n svg: 'image/svg+xml',\n xml: 'application/xml',\n yml: 'application/x-yaml',\n}\n\nexport const getFileTypeFallback = (path: string): ReturnType => {\n const ext = path.split('.').pop() || 'txt'\n\n return {\n ext,\n mime: extensionMap[ext] || 'text/plain',\n }\n}\n"],"mappings":"AAKA,MAAMA,YAAA,GAEF;EACFC,GAAA,EAAK;EACLC,GAAA,EAAK;EACLC,GAAA,EAAK;EACLC,IAAA,EAAM;EACNC,EAAA,EAAI;EACJC,IAAA,EAAM;EACNC,EAAA,EAAI;EACJC,GAAA,EAAK;EACLC,GAAA,EAAK;EACLC,GAAA,EAAK;AACP;AAEA,OAAO,MAAMC,mBAAA,GAAuBC,IAAA;EAClC,MAAMC,GAAA,GAAMD,IAAA,CAAKE,KAAK,CAAC,KAAKC,GAAG,MAAM;EAErC,OAAO;IACLF,GAAA;IACAG,IAAA,EAAMhB,YAAY,CAACa,GAAA,CAAI,IAAI;EAC7B;AACF","ignoreList":[]}
|
|
@@ -1 +0,0 @@
|
|
|
1
|
-
{"version":3,"file":"docAccess.d.ts","sourceRoot":"","sources":["../../../../src/routes/rest/globals/docAccess.ts"],"names":[],"mappings":"AAGA,OAAO,KAAK,EAAE,kBAAkB,EAAE,MAAM,aAAa,CAAA;AAIrD,eAAO,MAAM,SAAS,EAAE,kBAavB,CAAA"}
|
|
@@ -1,20 +0,0 @@
|
|
|
1
|
-
import httpStatus from 'http-status';
|
|
2
|
-
import { docAccessOperationGlobal } from 'payload';
|
|
3
|
-
import { headersWithCors } from '../../../utilities/headersWithCors.js';
|
|
4
|
-
export const docAccess = async ({
|
|
5
|
-
globalConfig,
|
|
6
|
-
req
|
|
7
|
-
}) => {
|
|
8
|
-
const result = await docAccessOperationGlobal({
|
|
9
|
-
globalConfig,
|
|
10
|
-
req
|
|
11
|
-
});
|
|
12
|
-
return Response.json(result, {
|
|
13
|
-
headers: headersWithCors({
|
|
14
|
-
headers: new Headers(),
|
|
15
|
-
req
|
|
16
|
-
}),
|
|
17
|
-
status: httpStatus.OK
|
|
18
|
-
});
|
|
19
|
-
};
|
|
20
|
-
//# sourceMappingURL=docAccess.js.map
|
|
@@ -1 +0,0 @@
|
|
|
1
|
-
{"version":3,"file":"docAccess.js","names":["httpStatus","docAccessOperationGlobal","headersWithCors","docAccess","globalConfig","req","result","Response","json","headers","Headers","status","OK"],"sources":["../../../../src/routes/rest/globals/docAccess.ts"],"sourcesContent":["import httpStatus from 'http-status'\nimport { docAccessOperationGlobal } from 'payload'\n\nimport type { GlobalRouteHandler } from '../types.js'\n\nimport { headersWithCors } from '../../../utilities/headersWithCors.js'\n\nexport const docAccess: GlobalRouteHandler = async ({ globalConfig, req }) => {\n const result = await docAccessOperationGlobal({\n globalConfig,\n req,\n })\n\n return Response.json(result, {\n headers: headersWithCors({\n headers: new Headers(),\n req,\n }),\n status: httpStatus.OK,\n })\n}\n"],"mappings":"AAAA,OAAOA,UAAA,MAAgB;AACvB,SAASC,wBAAwB,QAAQ;AAIzC,SAASC,eAAe,QAAQ;AAEhC,OAAO,MAAMC,SAAA,GAAgC,MAAAA,CAAO;EAAEC,YAAY;EAAEC;AAAG,CAAE;EACvE,MAAMC,MAAA,GAAS,MAAML,wBAAA,CAAyB;IAC5CG,YAAA;IACAC;EACF;EAEA,OAAOE,QAAA,CAASC,IAAI,CAACF,MAAA,EAAQ;IAC3BG,OAAA,EAASP,eAAA,CAAgB;MACvBO,OAAA,EAAS,IAAIC,OAAA;MACbL;IACF;IACAM,MAAA,EAAQX,UAAA,CAAWY;EACrB;AACF","ignoreList":[]}
|
|
@@ -1 +0,0 @@
|
|
|
1
|
-
{"version":3,"file":"findOne.d.ts","sourceRoot":"","sources":["../../../../src/routes/rest/globals/findOne.ts"],"names":[],"mappings":"AAIA,OAAO,KAAK,EAAE,kBAAkB,EAAE,MAAM,aAAa,CAAA;AAIrD,eAAO,MAAM,OAAO,EAAE,kBAqBrB,CAAA"}
|
|
@@ -1,30 +0,0 @@
|
|
|
1
|
-
import httpStatus from 'http-status';
|
|
2
|
-
import { findOneOperation, sanitizePopulateParam, sanitizeSelectParam } from 'payload';
|
|
3
|
-
import { isNumber } from 'payload/shared';
|
|
4
|
-
import { headersWithCors } from '../../../utilities/headersWithCors.js';
|
|
5
|
-
export const findOne = async ({
|
|
6
|
-
globalConfig,
|
|
7
|
-
req
|
|
8
|
-
}) => {
|
|
9
|
-
const {
|
|
10
|
-
searchParams
|
|
11
|
-
} = req;
|
|
12
|
-
const depth = searchParams.get('depth');
|
|
13
|
-
const result = await findOneOperation({
|
|
14
|
-
slug: globalConfig.slug,
|
|
15
|
-
depth: isNumber(depth) ? Number(depth) : undefined,
|
|
16
|
-
draft: searchParams.get('draft') === 'true',
|
|
17
|
-
globalConfig,
|
|
18
|
-
populate: sanitizePopulateParam(req.query.populate),
|
|
19
|
-
req,
|
|
20
|
-
select: sanitizeSelectParam(req.query.select)
|
|
21
|
-
});
|
|
22
|
-
return Response.json(result, {
|
|
23
|
-
headers: headersWithCors({
|
|
24
|
-
headers: new Headers(),
|
|
25
|
-
req
|
|
26
|
-
}),
|
|
27
|
-
status: httpStatus.OK
|
|
28
|
-
});
|
|
29
|
-
};
|
|
30
|
-
//# sourceMappingURL=findOne.js.map
|
|
@@ -1 +0,0 @@
|
|
|
1
|
-
{"version":3,"file":"findOne.js","names":["httpStatus","findOneOperation","sanitizePopulateParam","sanitizeSelectParam","isNumber","headersWithCors","findOne","globalConfig","req","searchParams","depth","get","result","slug","Number","undefined","draft","populate","query","select","Response","json","headers","Headers","status","OK"],"sources":["../../../../src/routes/rest/globals/findOne.ts"],"sourcesContent":["import httpStatus from 'http-status'\nimport { findOneOperation, sanitizePopulateParam, sanitizeSelectParam } from 'payload'\nimport { isNumber } from 'payload/shared'\n\nimport type { GlobalRouteHandler } from '../types.js'\n\nimport { headersWithCors } from '../../../utilities/headersWithCors.js'\n\nexport const findOne: GlobalRouteHandler = async ({ globalConfig, req }) => {\n const { searchParams } = req\n const depth = searchParams.get('depth')\n\n const result = await findOneOperation({\n slug: globalConfig.slug,\n depth: isNumber(depth) ? Number(depth) : undefined,\n draft: searchParams.get('draft') === 'true',\n globalConfig,\n populate: sanitizePopulateParam(req.query.populate),\n req,\n select: sanitizeSelectParam(req.query.select),\n })\n\n return Response.json(result, {\n headers: headersWithCors({\n headers: new Headers(),\n req,\n }),\n status: httpStatus.OK,\n })\n}\n"],"mappings":"AAAA,OAAOA,UAAA,MAAgB;AACvB,SAASC,gBAAgB,EAAEC,qBAAqB,EAAEC,mBAAmB,QAAQ;AAC7E,SAASC,QAAQ,QAAQ;AAIzB,SAASC,eAAe,QAAQ;AAEhC,OAAO,MAAMC,OAAA,GAA8B,MAAAA,CAAO;EAAEC,YAAY;EAAEC;AAAG,CAAE;EACrE,MAAM;IAAEC;EAAY,CAAE,GAAGD,GAAA;EACzB,MAAME,KAAA,GAAQD,YAAA,CAAaE,GAAG,CAAC;EAE/B,MAAMC,MAAA,GAAS,MAAMX,gBAAA,CAAiB;IACpCY,IAAA,EAAMN,YAAA,CAAaM,IAAI;IACvBH,KAAA,EAAON,QAAA,CAASM,KAAA,IAASI,MAAA,CAAOJ,KAAA,IAASK,SAAA;IACzCC,KAAA,EAAOP,YAAA,CAAaE,GAAG,CAAC,aAAa;IACrCJ,YAAA;IACAU,QAAA,EAAUf,qBAAA,CAAsBM,GAAA,CAAIU,KAAK,CAACD,QAAQ;IAClDT,GAAA;IACAW,MAAA,EAAQhB,mBAAA,CAAoBK,GAAA,CAAIU,KAAK,CAACC,MAAM;EAC9C;EAEA,OAAOC,QAAA,CAASC,IAAI,CAACT,MAAA,EAAQ;IAC3BU,OAAA,EAASjB,eAAA,CAAgB;MACvBiB,OAAA,EAAS,IAAIC,OAAA;MACbf;IACF;IACAgB,MAAA,EAAQxB,UAAA,CAAWyB;EACrB;AACF","ignoreList":[]}
|
|
@@ -1 +0,0 @@
|
|
|
1
|
-
{"version":3,"file":"findVersionByID.d.ts","sourceRoot":"","sources":["../../../../src/routes/rest/globals/findVersionByID.ts"],"names":[],"mappings":"AAIA,OAAO,KAAK,EAAE,wBAAwB,EAAE,MAAM,aAAa,CAAA;AAI3D,eAAO,MAAM,eAAe,EAAE,wBAoB7B,CAAA"}
|
|
@@ -1,30 +0,0 @@
|
|
|
1
|
-
import httpStatus from 'http-status';
|
|
2
|
-
import { findVersionByIDOperationGlobal, sanitizePopulateParam, sanitizeSelectParam } from 'payload';
|
|
3
|
-
import { isNumber } from 'payload/shared';
|
|
4
|
-
import { headersWithCors } from '../../../utilities/headersWithCors.js';
|
|
5
|
-
export const findVersionByID = async ({
|
|
6
|
-
id,
|
|
7
|
-
globalConfig,
|
|
8
|
-
req
|
|
9
|
-
}) => {
|
|
10
|
-
const {
|
|
11
|
-
searchParams
|
|
12
|
-
} = req;
|
|
13
|
-
const depth = searchParams.get('depth');
|
|
14
|
-
const result = await findVersionByIDOperationGlobal({
|
|
15
|
-
id,
|
|
16
|
-
depth: isNumber(depth) ? Number(depth) : undefined,
|
|
17
|
-
globalConfig,
|
|
18
|
-
populate: sanitizePopulateParam(req.query.populate),
|
|
19
|
-
req,
|
|
20
|
-
select: sanitizeSelectParam(req.query.select)
|
|
21
|
-
});
|
|
22
|
-
return Response.json(result, {
|
|
23
|
-
headers: headersWithCors({
|
|
24
|
-
headers: new Headers(),
|
|
25
|
-
req
|
|
26
|
-
}),
|
|
27
|
-
status: httpStatus.OK
|
|
28
|
-
});
|
|
29
|
-
};
|
|
30
|
-
//# sourceMappingURL=findVersionByID.js.map
|
|
@@ -1 +0,0 @@
|
|
|
1
|
-
{"version":3,"file":"findVersionByID.js","names":["httpStatus","findVersionByIDOperationGlobal","sanitizePopulateParam","sanitizeSelectParam","isNumber","headersWithCors","findVersionByID","id","globalConfig","req","searchParams","depth","get","result","Number","undefined","populate","query","select","Response","json","headers","Headers","status","OK"],"sources":["../../../../src/routes/rest/globals/findVersionByID.ts"],"sourcesContent":["import httpStatus from 'http-status'\nimport { findVersionByIDOperationGlobal, sanitizePopulateParam, sanitizeSelectParam } from 'payload'\nimport { isNumber } from 'payload/shared'\n\nimport type { GlobalRouteHandlerWithID } from '../types.js'\n\nimport { headersWithCors } from '../../../utilities/headersWithCors.js'\n\nexport const findVersionByID: GlobalRouteHandlerWithID = async ({ id, globalConfig, req }) => {\n const { searchParams } = req\n const depth = searchParams.get('depth')\n\n const result = await findVersionByIDOperationGlobal({\n id,\n depth: isNumber(depth) ? Number(depth) : undefined,\n globalConfig,\n populate: sanitizePopulateParam(req.query.populate),\n req,\n select: sanitizeSelectParam(req.query.select),\n })\n\n return Response.json(result, {\n headers: headersWithCors({\n headers: new Headers(),\n req,\n }),\n status: httpStatus.OK,\n })\n}\n"],"mappings":"AAAA,OAAOA,UAAA,MAAgB;AACvB,SAASC,8BAA8B,EAAEC,qBAAqB,EAAEC,mBAAmB,QAAQ;AAC3F,SAASC,QAAQ,QAAQ;AAIzB,SAASC,eAAe,QAAQ;AAEhC,OAAO,MAAMC,eAAA,GAA4C,MAAAA,CAAO;EAAEC,EAAE;EAAEC,YAAY;EAAEC;AAAG,CAAE;EACvF,MAAM;IAAEC;EAAY,CAAE,GAAGD,GAAA;EACzB,MAAME,KAAA,GAAQD,YAAA,CAAaE,GAAG,CAAC;EAE/B,MAAMC,MAAA,GAAS,MAAMZ,8BAAA,CAA+B;IAClDM,EAAA;IACAI,KAAA,EAAOP,QAAA,CAASO,KAAA,IAASG,MAAA,CAAOH,KAAA,IAASI,SAAA;IACzCP,YAAA;IACAQ,QAAA,EAAUd,qBAAA,CAAsBO,GAAA,CAAIQ,KAAK,CAACD,QAAQ;IAClDP,GAAA;IACAS,MAAA,EAAQf,mBAAA,CAAoBM,GAAA,CAAIQ,KAAK,CAACC,MAAM;EAC9C;EAEA,OAAOC,QAAA,CAASC,IAAI,CAACP,MAAA,EAAQ;IAC3BQ,OAAA,EAAShB,eAAA,CAAgB;MACvBgB,OAAA,EAAS,IAAIC,OAAA;MACbb;IACF;IACAc,MAAA,EAAQvB,UAAA,CAAWwB;EACrB;AACF","ignoreList":[]}
|
|
@@ -1 +0,0 @@
|
|
|
1
|
-
{"version":3,"file":"findVersions.d.ts","sourceRoot":"","sources":["../../../../src/routes/rest/globals/findVersions.ts"],"names":[],"mappings":"AAMA,OAAO,KAAK,EAAE,kBAAkB,EAAE,MAAM,aAAa,CAAA;AAIrD,eAAO,MAAM,YAAY,EAAE,kBAgC1B,CAAA"}
|
|
@@ -1,39 +0,0 @@
|
|
|
1
|
-
import httpStatus from 'http-status';
|
|
2
|
-
import { findVersionsOperationGlobal, sanitizePopulateParam, sanitizeSelectParam } from 'payload';
|
|
3
|
-
import { isNumber } from 'payload/shared';
|
|
4
|
-
import { headersWithCors } from '../../../utilities/headersWithCors.js';
|
|
5
|
-
export const findVersions = async ({
|
|
6
|
-
globalConfig,
|
|
7
|
-
req
|
|
8
|
-
}) => {
|
|
9
|
-
const {
|
|
10
|
-
depth,
|
|
11
|
-
limit,
|
|
12
|
-
page,
|
|
13
|
-
pagination,
|
|
14
|
-
populate,
|
|
15
|
-
select,
|
|
16
|
-
sort,
|
|
17
|
-
where
|
|
18
|
-
} = req.query;
|
|
19
|
-
const result = await findVersionsOperationGlobal({
|
|
20
|
-
depth: isNumber(depth) ? Number(depth) : undefined,
|
|
21
|
-
globalConfig,
|
|
22
|
-
limit: isNumber(limit) ? Number(limit) : undefined,
|
|
23
|
-
page: isNumber(page) ? Number(page) : undefined,
|
|
24
|
-
pagination: pagination === 'false' ? false : undefined,
|
|
25
|
-
populate: sanitizePopulateParam(populate),
|
|
26
|
-
req,
|
|
27
|
-
select: sanitizeSelectParam(select),
|
|
28
|
-
sort: typeof sort === 'string' ? sort.split(',') : undefined,
|
|
29
|
-
where
|
|
30
|
-
});
|
|
31
|
-
return Response.json(result, {
|
|
32
|
-
headers: headersWithCors({
|
|
33
|
-
headers: new Headers(),
|
|
34
|
-
req
|
|
35
|
-
}),
|
|
36
|
-
status: httpStatus.OK
|
|
37
|
-
});
|
|
38
|
-
};
|
|
39
|
-
//# sourceMappingURL=findVersions.js.map
|
|
@@ -1 +0,0 @@
|
|
|
1
|
-
{"version":3,"file":"findVersions.js","names":["httpStatus","findVersionsOperationGlobal","sanitizePopulateParam","sanitizeSelectParam","isNumber","headersWithCors","findVersions","globalConfig","req","depth","limit","page","pagination","populate","select","sort","where","query","result","Number","undefined","split","Response","json","headers","Headers","status","OK"],"sources":["../../../../src/routes/rest/globals/findVersions.ts"],"sourcesContent":["import type { Where } from 'payload'\n\nimport httpStatus from 'http-status'\nimport { findVersionsOperationGlobal, sanitizePopulateParam, sanitizeSelectParam } from 'payload'\nimport { isNumber } from 'payload/shared'\n\nimport type { GlobalRouteHandler } from '../types.js'\n\nimport { headersWithCors } from '../../../utilities/headersWithCors.js'\n\nexport const findVersions: GlobalRouteHandler = async ({ globalConfig, req }) => {\n const { depth, limit, page, pagination, populate, select, sort, where } = req.query as {\n depth?: string\n limit?: string\n page?: string\n pagination?: string\n populate?: Record<string, unknown>\n select?: Record<string, unknown>\n sort?: string\n where?: Where\n }\n\n const result = await findVersionsOperationGlobal({\n depth: isNumber(depth) ? Number(depth) : undefined,\n globalConfig,\n limit: isNumber(limit) ? Number(limit) : undefined,\n page: isNumber(page) ? Number(page) : undefined,\n pagination: pagination === 'false' ? false : undefined,\n populate: sanitizePopulateParam(populate),\n req,\n select: sanitizeSelectParam(select),\n sort: typeof sort === 'string' ? sort.split(',') : undefined,\n where,\n })\n\n return Response.json(result, {\n headers: headersWithCors({\n headers: new Headers(),\n req,\n }),\n status: httpStatus.OK,\n })\n}\n"],"mappings":"AAEA,OAAOA,UAAA,MAAgB;AACvB,SAASC,2BAA2B,EAAEC,qBAAqB,EAAEC,mBAAmB,QAAQ;AACxF,SAASC,QAAQ,QAAQ;AAIzB,SAASC,eAAe,QAAQ;AAEhC,OAAO,MAAMC,YAAA,GAAmC,MAAAA,CAAO;EAAEC,YAAY;EAAEC;AAAG,CAAE;EAC1E,MAAM;IAAEC,KAAK;IAAEC,KAAK;IAAEC,IAAI;IAAEC,UAAU;IAAEC,QAAQ;IAAEC,MAAM;IAAEC,IAAI;IAAEC;EAAK,CAAE,GAAGR,GAAA,CAAIS,KAAK;EAWnF,MAAMC,MAAA,GAAS,MAAMjB,2BAAA,CAA4B;IAC/CQ,KAAA,EAAOL,QAAA,CAASK,KAAA,IAASU,MAAA,CAAOV,KAAA,IAASW,SAAA;IACzCb,YAAA;IACAG,KAAA,EAAON,QAAA,CAASM,KAAA,IAASS,MAAA,CAAOT,KAAA,IAASU,SAAA;IACzCT,IAAA,EAAMP,QAAA,CAASO,IAAA,IAAQQ,MAAA,CAAOR,IAAA,IAAQS,SAAA;IACtCR,UAAA,EAAYA,UAAA,KAAe,UAAU,QAAQQ,SAAA;IAC7CP,QAAA,EAAUX,qBAAA,CAAsBW,QAAA;IAChCL,GAAA;IACAM,MAAA,EAAQX,mBAAA,CAAoBW,MAAA;IAC5BC,IAAA,EAAM,OAAOA,IAAA,KAAS,WAAWA,IAAA,CAAKM,KAAK,CAAC,OAAOD,SAAA;IACnDJ;EACF;EAEA,OAAOM,QAAA,CAASC,IAAI,CAACL,MAAA,EAAQ;IAC3BM,OAAA,EAASnB,eAAA,CAAgB;MACvBmB,OAAA,EAAS,IAAIC,OAAA;MACbjB;IACF;IACAkB,MAAA,EAAQ1B,UAAA,CAAW2B;EACrB;AACF","ignoreList":[]}
|
|
@@ -1 +0,0 @@
|
|
|
1
|
-
{"version":3,"file":"preview.d.ts","sourceRoot":"","sources":["../../../../src/routes/rest/globals/preview.ts"],"names":[],"mappings":"AAIA,OAAO,KAAK,EAAE,kBAAkB,EAAE,MAAM,aAAa,CAAA;AAKrD,eAAO,MAAM,OAAO,EAAE,kBA2CrB,CAAA"}
|
|
@@ -1,47 +0,0 @@
|
|
|
1
|
-
import httpStatus from 'http-status';
|
|
2
|
-
import { extractJWT, findOneOperation } from 'payload';
|
|
3
|
-
import { isNumber } from 'payload/shared';
|
|
4
|
-
import { headersWithCors } from '../../../utilities/headersWithCors.js';
|
|
5
|
-
import { routeError } from '../routeError.js';
|
|
6
|
-
export const preview = async ({
|
|
7
|
-
globalConfig,
|
|
8
|
-
req
|
|
9
|
-
}) => {
|
|
10
|
-
const {
|
|
11
|
-
searchParams
|
|
12
|
-
} = req;
|
|
13
|
-
const depth = searchParams.get('depth');
|
|
14
|
-
const doc = await findOneOperation({
|
|
15
|
-
slug: globalConfig.slug,
|
|
16
|
-
depth: isNumber(depth) ? Number(depth) : undefined,
|
|
17
|
-
draft: searchParams.get('draft') === 'true',
|
|
18
|
-
globalConfig,
|
|
19
|
-
req
|
|
20
|
-
});
|
|
21
|
-
let previewURL;
|
|
22
|
-
const generatePreviewURL = req.payload.config.globals.find(config => config.slug === globalConfig.slug)?.admin?.preview;
|
|
23
|
-
const token = extractJWT(req);
|
|
24
|
-
if (typeof generatePreviewURL === 'function') {
|
|
25
|
-
try {
|
|
26
|
-
previewURL = await generatePreviewURL(doc, {
|
|
27
|
-
locale: req.locale,
|
|
28
|
-
req,
|
|
29
|
-
token
|
|
30
|
-
});
|
|
31
|
-
} catch (err) {
|
|
32
|
-
return routeError({
|
|
33
|
-
config: req.payload.config,
|
|
34
|
-
err,
|
|
35
|
-
req
|
|
36
|
-
});
|
|
37
|
-
}
|
|
38
|
-
}
|
|
39
|
-
return Response.json(previewURL, {
|
|
40
|
-
headers: headersWithCors({
|
|
41
|
-
headers: new Headers(),
|
|
42
|
-
req
|
|
43
|
-
}),
|
|
44
|
-
status: httpStatus.OK
|
|
45
|
-
});
|
|
46
|
-
};
|
|
47
|
-
//# sourceMappingURL=preview.js.map
|
|
@@ -1 +0,0 @@
|
|
|
1
|
-
{"version":3,"file":"preview.js","names":["httpStatus","extractJWT","findOneOperation","isNumber","headersWithCors","routeError","preview","globalConfig","req","searchParams","depth","get","doc","slug","Number","undefined","draft","previewURL","generatePreviewURL","payload","config","globals","find","admin","token","locale","err","Response","json","headers","Headers","status","OK"],"sources":["../../../../src/routes/rest/globals/preview.ts"],"sourcesContent":["import httpStatus from 'http-status'\nimport { extractJWT, findOneOperation } from 'payload'\nimport { isNumber } from 'payload/shared'\n\nimport type { GlobalRouteHandler } from '../types.js'\n\nimport { headersWithCors } from '../../../utilities/headersWithCors.js'\nimport { routeError } from '../routeError.js'\n\nexport const preview: GlobalRouteHandler = async ({ globalConfig, req }) => {\n const { searchParams } = req\n const depth = searchParams.get('depth')\n\n const doc = await findOneOperation({\n slug: globalConfig.slug,\n depth: isNumber(depth) ? Number(depth) : undefined,\n draft: searchParams.get('draft') === 'true',\n globalConfig,\n req,\n })\n\n let previewURL: string\n\n const generatePreviewURL = req.payload.config.globals.find(\n (config) => config.slug === globalConfig.slug,\n )?.admin?.preview\n\n const token = extractJWT(req)\n\n if (typeof generatePreviewURL === 'function') {\n try {\n previewURL = await generatePreviewURL(doc, {\n locale: req.locale,\n req,\n token,\n })\n } catch (err) {\n return routeError({\n config: req.payload.config,\n err,\n req,\n })\n }\n }\n\n return Response.json(previewURL, {\n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