Compare commits
1 Commits
main
...
absolute-p
Author | SHA1 | Date |
---|---|---|
DrMint | 6c021fdc94 |
|
@ -13,11 +13,8 @@ SEEDING_ADMIN_USERNAME=admin_name
|
|||
SEEDING_ADMIN_EMAIL=email@domain.com
|
||||
SEEDING_ADMIN_PASSWORD=somepassword
|
||||
|
||||
WEB_SERVER_HOOK_TOKEN=webhooktoken5e6ea45ef4e66eaa151612bdcb599df
|
||||
WEB_SERVER_HOOK_URL=https://accords-library.com/some/path
|
||||
|
||||
MEILISEARCH_HOOK_TOKEN=webhooktoken5e6ea45ef4e66eaa151612bdcb599df
|
||||
MEILISEARCH_HOOK_URL=https://meili.domain.com
|
||||
WEB_HOOK_TOKEN=webhooktoken5e6ea45ef4e66eaa151612bdcb599df
|
||||
WEB_HOOK_URI=https://accords-library.com/some/path
|
||||
|
||||
SFTP_PRIVATE_KEY="-----BEGIN RSA PRIVATE KEY-----\nxxxxxxxxxx..."
|
||||
SFTP_USERNAME=someuser
|
||||
|
|
|
@ -1,2 +0,0 @@
|
|||
src/shared/*
|
||||
dist
|
|
@ -1,7 +1,7 @@
|
|||
{
|
||||
"editor.rulers": [100],
|
||||
"editor.tabSize": 2,
|
||||
"typescript.preferences.importModuleSpecifier": "relative",
|
||||
"typescript.preferences.importModuleSpecifier": "non-relative",
|
||||
"explorer.fileNesting.enabled": true,
|
||||
"explorer.fileNesting.patterns": {
|
||||
"package.json": ".git*, package-lock.json, yarn.lock, pnpm-lock.yaml, bun.lockb, .ncurc.*, .nvmrc, *.config.cjs, *.config.js, *.config.ts, *config.json, .*ignore",
|
||||
|
|
File diff suppressed because it is too large
Load Diff
21
package.json
21
package.json
|
@ -10,7 +10,7 @@
|
|||
"build:server": "tsc",
|
||||
"build": "npm run copyfiles && npm run build:payload && npm run build:server",
|
||||
"serve": "cross-env PAYLOAD_CONFIG_PATH=dist/payload.config.js NODE_ENV=production node dist/server.js",
|
||||
"copyfiles": "copyfiles -u 1 \"src/**/*.{html,css,scss,ttf,woff,woff2,eot,svg,jpg,png}\" dist/",
|
||||
"copyfiles": "copyfiles -u 1 \"src/**/*.{html,css,scss,ttf,woff,woff2,eot,svg,jpg,png}\" dist/ && copyfiles -u 1 \"src/sdk.ts\" dist/ && copyfiles -u 1 \"src/constants.ts\" dist/ && copyfiles -u 1 \"src/types/collections.ts\" dist/",
|
||||
"generate:types": "cross-env PAYLOAD_CONFIG_PATH=src/payload.config.ts payload generate:types",
|
||||
"unused-exports": "ts-unused-exports ./tsconfig.json --excludePathsFromReport='src/payload.config.ts;src/types/collections.ts;src/shared/*'",
|
||||
"prettier": "prettier --list-different --end-of-line auto --write src",
|
||||
|
@ -18,23 +18,22 @@
|
|||
"fetch-submodules": "cd src/shared && git pull && cd ../..",
|
||||
"precommit": "npm run fetch-submodules && npm run generate:types && npm run prettier && npm run unused-exports && npm run tsc",
|
||||
"upgrade": "ncu",
|
||||
"prod": "rm -rf build && rm -rf dist && npm ci && npm run build && npm run serve"
|
||||
"prod": "rm -rf build && rm -rf dist && npm ci && npm run precommit && npm run build && npm run serve"
|
||||
},
|
||||
"dependencies": {
|
||||
"@fontsource/vollkorn": "5.0.20",
|
||||
"@iconify-json/material-symbols": "^1.1.87",
|
||||
"@iconify-json/material-symbols": "^1.1.83",
|
||||
"@payloadcms/bundler-webpack": "1.0.7",
|
||||
"@payloadcms/db-mongodb": "1.7.2",
|
||||
"@payloadcms/richtext-lexical": "0.11.3",
|
||||
"@payloadcms/db-mongodb": "1.5.2",
|
||||
"@payloadcms/richtext-lexical": "0.11.2",
|
||||
"cross-env": "7.0.3",
|
||||
"dotenv": "^16.4.5",
|
||||
"language-tags": "1.0.9",
|
||||
"luxon": "3.5.0",
|
||||
"payload": "2.26.0",
|
||||
"payloadcms-relationships": "github:DrMint/payloadcms-relationships",
|
||||
"luxon": "3.4.4",
|
||||
"payload": "2.23.1",
|
||||
"payloadcms-sftp-storage": "1.0.1",
|
||||
"sharp": "0.33.4",
|
||||
"styled-components": "6.1.12"
|
||||
"styled-components": "6.1.11"
|
||||
},
|
||||
"devDependencies": {
|
||||
"@types/express": "4.17.21",
|
||||
|
@ -45,9 +44,11 @@
|
|||
"@types/styled-components": "5.1.34",
|
||||
"copyfiles": "2.4.1",
|
||||
"nodemon": "3.1.4",
|
||||
"prettier": "3.3.3",
|
||||
"prettier": "3.3.2",
|
||||
"ts-node": "10.9.2",
|
||||
"ts-unused-exports": "10.1.0",
|
||||
"tsconfig-paths": "^4.2.0",
|
||||
"tsconfig-paths-webpack-plugin": "^4.1.0",
|
||||
"typescript": "5.4.5"
|
||||
}
|
||||
}
|
||||
|
|
|
@ -1,7 +1,7 @@
|
|||
import { Access } from "payload/config";
|
||||
import { Recorder } from "../../types/collections";
|
||||
import { isDefined, isUndefined } from "../../utils/asserts";
|
||||
import { RecordersRoles } from "../../shared/payload/constants";
|
||||
import { RecordersRoles } from "src/shared/payload/constants";
|
||||
import { Recorder } from "src/types/collections";
|
||||
import { isUndefined, isDefined } from "src/utils/asserts";
|
||||
|
||||
export const mustBeAdmin: Access<unknown, Recorder> = ({ req: { user } }): boolean => {
|
||||
if (isUndefined(user)) return false;
|
||||
|
|
|
@ -1,7 +1,7 @@
|
|||
import { Access } from "payload/config";
|
||||
import { Recorder } from "../../types/collections";
|
||||
import { isUndefined } from "../../utils/asserts";
|
||||
import { RecordersRoles } from "../../shared/payload/constants";
|
||||
import { RecordersRoles } from "src/shared/payload/constants";
|
||||
import { Recorder } from "src/types/collections";
|
||||
import { isUndefined } from "src/utils/asserts";
|
||||
|
||||
export const mustBeAdminOrSelf: Access<unknown, Recorder> = ({ req: { user } }) => {
|
||||
if (isUndefined(user)) return false;
|
||||
|
|
|
@ -1,7 +1,7 @@
|
|||
import { User } from "payload/auth";
|
||||
import { Recorder } from "../../types/collections";
|
||||
import { isDefined, isUndefined } from "../../utils/asserts";
|
||||
import { RecordersRoles } from "../../shared/payload/constants";
|
||||
import { RecordersRoles } from "src/shared/payload/constants";
|
||||
import { Recorder } from "src/types/collections";
|
||||
import { isUndefined, isDefined } from "src/utils/asserts";
|
||||
|
||||
export const shownOnlyToAdmin = ({ user }: { user: User }): boolean => {
|
||||
if (isUndefined(user)) return false;
|
||||
|
|
|
@ -1,7 +1,7 @@
|
|||
import { FieldAccess } from "payload/types";
|
||||
import { Recorder } from "../../types/collections";
|
||||
import { isDefined, isUndefined } from "../../utils/asserts";
|
||||
import { RecordersRoles } from "../../shared/payload/constants";
|
||||
import { RecordersRoles } from "src/shared/payload/constants";
|
||||
import { Recorder } from "src/types/collections";
|
||||
import { isUndefined, isDefined } from "src/utils/asserts";
|
||||
|
||||
export const mustBeAdmin: FieldAccess<any, any, Recorder> = ({ req: { user } }): boolean => {
|
||||
if (isUndefined(user)) return false;
|
||||
|
|
|
@ -1,6 +1,6 @@
|
|||
import { Block } from "payload/types";
|
||||
import { rowField } from "../../fields/rowField/rowField";
|
||||
import { AttributeTypes, Collections } from "../../shared/payload/constants";
|
||||
import { rowField } from "src/fields/rowField/rowField";
|
||||
import { Collections, AttributeTypes } from "src/shared/payload/constants";
|
||||
|
||||
export const numberBlock: Block = {
|
||||
slug: "numberBlock",
|
||||
|
|
|
@ -1,6 +1,6 @@
|
|||
import { Block } from "payload/types";
|
||||
import { rowField } from "../../fields/rowField/rowField";
|
||||
import { Collections, AttributeTypes } from "../../shared/payload/constants";
|
||||
import { rowField } from "src/fields/rowField/rowField";
|
||||
import { Collections, AttributeTypes } from "src/shared/payload/constants";
|
||||
|
||||
export const tagsBlock: Block = {
|
||||
slug: "tagsBlock",
|
||||
|
|
|
@ -1,6 +1,6 @@
|
|||
import { Block } from "payload/types";
|
||||
import { rowField } from "../../fields/rowField/rowField";
|
||||
import { AttributeTypes, Collections } from "../../shared/payload/constants";
|
||||
import { rowField } from "src/fields/rowField/rowField";
|
||||
import { Collections, AttributeTypes } from "src/shared/payload/constants";
|
||||
|
||||
export const textBlock: Block = {
|
||||
slug: "textBlock",
|
||||
|
|
|
@ -1,5 +1,5 @@
|
|||
import { Block } from "payload/types";
|
||||
import { BreakBlockType } from "../shared/payload/constants";
|
||||
import { BreakBlockType } from "src/shared/payload/constants";
|
||||
|
||||
export const breakBlock: Block = {
|
||||
slug: "breakBlock",
|
||||
|
|
|
@ -1,5 +1,5 @@
|
|||
import { Block } from "payload/types";
|
||||
import { createEditor } from "../utils/editor";
|
||||
import { createEditor } from "src/utils/editor";
|
||||
|
||||
export const cueBlock: Block = {
|
||||
slug: "cueBlock",
|
||||
|
|
|
@ -1,5 +1,5 @@
|
|||
import { Block } from "payload/types";
|
||||
import { createEditor } from "../utils/editor";
|
||||
import { createEditor } from "src/utils/editor";
|
||||
|
||||
export const lineBlock: Block = {
|
||||
slug: "lineBlock",
|
||||
|
|
|
@ -1,7 +1,7 @@
|
|||
import { Block } from "payload/types";
|
||||
import { createEditor } from "../utils/editor";
|
||||
import { breakBlock } from "./breakBlock";
|
||||
import { transcriptBlock } from "./transcriptBlock";
|
||||
import { breakBlock } from "src/blocks/breakBlock";
|
||||
import { transcriptBlock } from "src/blocks/transcriptBlock";
|
||||
import { createEditor } from "src/utils/editor";
|
||||
|
||||
const generateRecursiveSectionBlock = (depth = 1, maxDepth = 5): Block => ({
|
||||
slug: "sectionBlock",
|
||||
|
|
|
@ -1,6 +1,6 @@
|
|||
import { Block } from "payload/types";
|
||||
import { cueBlock } from "./cueBlock";
|
||||
import { lineBlock } from "./lineBlock";
|
||||
import { cueBlock } from "src/blocks/cueBlock";
|
||||
import { lineBlock } from "src/blocks/lineBlock";
|
||||
|
||||
export const transcriptBlock: Block = {
|
||||
slug: "transcriptBlock",
|
||||
|
|
|
@ -1,11 +1,11 @@
|
|||
import { CollectionConfig } from "payload/types";
|
||||
import { mustBeAdmin } from "../../accesses/fields/mustBeAdmin";
|
||||
import { iconField } from "../../fields/iconField/iconField";
|
||||
import { rowField } from "../../fields/rowField/rowField";
|
||||
import { slugField } from "../../fields/slugField/slugField";
|
||||
import { translatedFields } from "../../fields/translatedFields/translatedFields";
|
||||
import { buildCollectionConfig } from "../../utils/collectionConfig";
|
||||
import { Collections, CollectionGroups, AttributeTypes } from "../../shared/payload/constants";
|
||||
import { mustBeAdmin } from "src/accesses/fields/mustBeAdmin";
|
||||
import { iconField } from "src/fields/iconField/iconField";
|
||||
import { rowField } from "src/fields/rowField/rowField";
|
||||
import { slugField } from "src/fields/slugField/slugField";
|
||||
import { translatedFields } from "src/fields/translatedFields/translatedFields";
|
||||
import { Collections, CollectionGroups, AttributeTypes } from "src/shared/payload/constants";
|
||||
import { buildCollectionConfig } from "src/utils/collectionConfig";
|
||||
|
||||
const fields = {
|
||||
slug: "slug",
|
||||
|
|
|
@ -1,11 +1,11 @@
|
|||
import { attributesField } from "../../fields/attributesField/attributesField";
|
||||
import { creditsField } from "../../fields/creditsField/creditsField";
|
||||
import { imageField } from "../../fields/imageField/imageField";
|
||||
import { rowField } from "../../fields/rowField/rowField";
|
||||
import { translatedFields } from "../../fields/translatedFields/translatedFields";
|
||||
import { Collections, CollectionGroups } from "../../shared/payload/constants";
|
||||
import { buildCollectionConfig } from "../../utils/collectionConfig";
|
||||
import { createEditor } from "../../utils/editor";
|
||||
import { attributesField } from "src/fields/attributesField/attributesField";
|
||||
import { creditsField } from "src/fields/creditsField/creditsField";
|
||||
import { imageField } from "src/fields/imageField/imageField";
|
||||
import { rowField } from "src/fields/rowField/rowField";
|
||||
import { translatedFields } from "src/fields/translatedFields/translatedFields";
|
||||
import { Collections, CollectionGroups } from "src/shared/payload/constants";
|
||||
import { buildCollectionConfig } from "src/utils/collectionConfig";
|
||||
import { createEditor } from "src/utils/editor";
|
||||
import { getByID } from "./endpoints/getByID";
|
||||
|
||||
const fields = {
|
||||
|
@ -31,7 +31,6 @@ export const Audios = buildCollectionConfig({
|
|||
admin: {
|
||||
group: CollectionGroups.Media,
|
||||
preview: ({ id }) => `${process.env.PAYLOAD_PUBLIC_FRONTEND_BASE_URL}/en/audios/${id}`,
|
||||
useAsTitle: fields.filename,
|
||||
defaultColumns: [
|
||||
fields.filename,
|
||||
fields.thumbnail,
|
||||
|
|
|
@ -1,22 +1,20 @@
|
|||
import payload from "payload";
|
||||
import { Audio } from "../../../types/collections";
|
||||
import { CollectionEndpoint } from "../../../types/payload";
|
||||
import { isAudio, isMediaThumbnail, isNotEmpty } from "../../../utils/asserts";
|
||||
import {
|
||||
convertAttributesToEndpointAttributes,
|
||||
convertCreditsToEndpointCredits,
|
||||
convertMediaThumbnailToEndpointPayloadImage,
|
||||
convertRTCToEndpointRTC,
|
||||
convertRelationshipsToEndpointRelations,
|
||||
getLanguageId,
|
||||
} from "../../../utils/endpoints";
|
||||
import { Collections } from "../../../shared/payload/constants";
|
||||
import { Collections } from "src/shared/payload/constants";
|
||||
import {
|
||||
PayloadMedia,
|
||||
EndpointAudioPreview,
|
||||
EndpointAudio,
|
||||
} from "../../../shared/payload/endpoint-types";
|
||||
import { findIncomingRelationships } from "payloadcms-relationships";
|
||||
} from "src/shared/payload/endpoint-types";
|
||||
import { CollectionEndpoint } from "src/types/payload";
|
||||
import { isAudio, isNotEmpty, isMediaThumbnail } from "src/utils/asserts";
|
||||
import {
|
||||
convertAttributesToEndpointAttributes,
|
||||
getLanguageId,
|
||||
convertMediaThumbnailToEndpointPayloadImage,
|
||||
convertRTCToEndpointRTC,
|
||||
convertCreditsToEndpointCredits,
|
||||
} from "src/utils/endpoints";
|
||||
import { Audio } from "src/types/collections";
|
||||
|
||||
export const getByID: CollectionEndpoint = {
|
||||
method: "get",
|
||||
|
@ -46,7 +44,7 @@ export const getByID: CollectionEndpoint = {
|
|||
return res.sendStatus(404);
|
||||
}
|
||||
|
||||
return res.status(200).json(await convertAudioToEndpointAudio(result));
|
||||
return res.status(200).json(convertAudioToEndpointAudio(result));
|
||||
} catch {
|
||||
return res.sendStatus(404);
|
||||
}
|
||||
|
@ -81,8 +79,8 @@ export const convertAudioToEndpointAudioPreview = ({
|
|||
: {}),
|
||||
});
|
||||
|
||||
const convertAudioToEndpointAudio = async (audio: Audio & PayloadMedia): Promise<EndpointAudio> => {
|
||||
const { translations, createdAt, updatedAt, filesize, credits, id } = audio;
|
||||
const convertAudioToEndpointAudio = (audio: Audio & PayloadMedia): EndpointAudio => {
|
||||
const { translations, createdAt, updatedAt, filesize, credits } = audio;
|
||||
return {
|
||||
...convertAudioToEndpointAudioPreview(audio),
|
||||
createdAt,
|
||||
|
@ -97,8 +95,5 @@ const convertAudioToEndpointAudio = async (audio: Audio & PayloadMedia): Promise
|
|||
...(isNotEmpty(description) ? { description: convertRTCToEndpointRTC(description) } : {}),
|
||||
})) ?? [],
|
||||
credits: convertCreditsToEndpointCredits(credits),
|
||||
backlinks: convertRelationshipsToEndpointRelations(
|
||||
await findIncomingRelationships(Collections.Audios, id)
|
||||
),
|
||||
};
|
||||
};
|
||||
|
|
|
@ -1,14 +1,4 @@
|
|||
import { CollectionConfig } from "payload/types";
|
||||
import {
|
||||
QuickFilters,
|
||||
languageBasedFilters,
|
||||
publishStatusFilters,
|
||||
} from "../../components/QuickFilters";
|
||||
import { creditsField } from "../../fields/creditsField/creditsField";
|
||||
import { rowField } from "../../fields/rowField/rowField";
|
||||
import { translatedFields } from "../../fields/translatedFields/translatedFields";
|
||||
import { createEditor } from "../../utils/editor";
|
||||
import { buildVersionedCollectionConfig } from "../../utils/versionedCollectionConfig";
|
||||
import { collectibleBlock } from "./blocks/collectibleBlock";
|
||||
import { pageBlock } from "./blocks/contentBlock";
|
||||
import { urlBlock } from "./blocks/urlBlock";
|
||||
|
@ -19,7 +9,17 @@ import { beforeValidatePopulateNameField } from "./hooks/beforeValidatePopulateN
|
|||
import { validateDate } from "./validations/validateDate";
|
||||
import { validateEventsTranslationsDescription } from "./validations/validateEventsTranslationsDescription";
|
||||
import { validateEventsTranslationsTitle } from "./validations/validateEventsTranslationsTitle";
|
||||
import { Collections, CollectionGroups } from "../../shared/payload/constants";
|
||||
import {
|
||||
QuickFilters,
|
||||
languageBasedFilters,
|
||||
publishStatusFilters,
|
||||
} from "src/components/QuickFilters";
|
||||
import { creditsField } from "src/fields/creditsField/creditsField";
|
||||
import { rowField } from "src/fields/rowField/rowField";
|
||||
import { translatedFields } from "src/fields/translatedFields/translatedFields";
|
||||
import { Collections, CollectionGroups } from "src/shared/payload/constants";
|
||||
import { createEditor } from "src/utils/editor";
|
||||
import { buildVersionedCollectionConfig } from "src/utils/versionedCollectionConfig";
|
||||
|
||||
const fields = {
|
||||
name: "name",
|
||||
|
|
|
@ -1,6 +1,6 @@
|
|||
import { Block } from "payload/types";
|
||||
import { translatedFields } from "../../../fields/translatedFields/translatedFields";
|
||||
import { Collections } from "../../../shared/payload/constants";
|
||||
import { translatedFields } from "src/fields/translatedFields/translatedFields";
|
||||
import { Collections } from "src/shared/payload/constants";
|
||||
|
||||
export const collectibleBlock: Block = {
|
||||
slug: "collectibleBlock",
|
||||
|
|
|
@ -1,5 +1,5 @@
|
|||
import { Block } from "payload/types";
|
||||
import { Collections } from "../../../shared/payload/constants";
|
||||
import { Collections } from "src/shared/payload/constants";
|
||||
|
||||
export const pageBlock: Block = {
|
||||
slug: "pageBlock",
|
||||
|
|
|
@ -1,16 +1,12 @@
|
|||
import payload from "payload";
|
||||
import { ChronologyEvent, CollectibleBlock } from "../../../types/collections";
|
||||
import { CollectionEndpoint } from "../../../types/payload";
|
||||
import { isDefined, isNotEmpty, isPayloadType } from "../../../utils/asserts";
|
||||
import { convertCreditsToEndpointCredits, getDomainFromUrl } from "../../../utils/endpoints";
|
||||
import { convertCollectibleToEndpointCollectiblePreview } from "../../Collectibles/endpoints/getBySlugEndpoint";
|
||||
import { convertPageToEndpointPagePreview } from "../../Pages/endpoints/getBySlugEndpoint";
|
||||
import { Collections } from "../../../shared/payload/constants";
|
||||
import {
|
||||
EndpointChronologyEvent,
|
||||
EndpointCollectibleRelationRange,
|
||||
EndpointRelation,
|
||||
} from "../../../shared/payload/endpoint-types";
|
||||
import { convertCollectibleToEndpointCollectiblePreview } from "src/collections/Collectibles/endpoints/getBySlugEndpoint";
|
||||
import { convertPageToEndpointPagePreview } from "src/collections/Pages/endpoints/getBySlugEndpoint";
|
||||
import { Collections } from "src/shared/payload/constants";
|
||||
import { EndpointChronologyEvent, EndpointSource } from "src/shared/payload/endpoint-types";
|
||||
import { ChronologyEvent, CollectibleBlock } from "src/types/collections";
|
||||
import { CollectionEndpoint } from "src/types/payload";
|
||||
import { isDefined, isPayloadType, isNotEmpty } from "src/utils/asserts";
|
||||
import { convertCreditsToEndpointCredits, getDomainFromUrl } from "src/utils/endpoints";
|
||||
|
||||
export const getAllEndpoint: CollectionEndpoint = {
|
||||
method: "get",
|
||||
|
@ -52,13 +48,13 @@ export const getAllEndpoint: CollectionEndpoint = {
|
|||
if (aDay !== bDay) return aDay - bDay;
|
||||
return 0;
|
||||
})
|
||||
.map<EndpointChronologyEvent>(convertEventToEndpointEvent);
|
||||
.map<EndpointChronologyEvent>(eventToEndpointEvent);
|
||||
|
||||
res.status(200).json(events);
|
||||
},
|
||||
};
|
||||
|
||||
export const convertEventToEndpointEvent = ({
|
||||
export const eventToEndpointEvent = ({
|
||||
date: { year, day, month },
|
||||
events,
|
||||
id,
|
||||
|
@ -84,35 +80,31 @@ export const convertEventToEndpointEvent = ({
|
|||
})),
|
||||
});
|
||||
|
||||
const handleSources = (
|
||||
sources: ChronologyEvent["events"][number]["sources"]
|
||||
): EndpointRelation[] => {
|
||||
const handleSources = (sources: ChronologyEvent["events"][number]["sources"]): EndpointSource[] => {
|
||||
return (
|
||||
sources?.flatMap<EndpointRelation>((source) => {
|
||||
sources?.flatMap<EndpointSource>((source) => {
|
||||
switch (source.blockType) {
|
||||
case "collectibleBlock":
|
||||
const range = handleRange(source.range);
|
||||
if (!isPayloadType(source.collectible)) return [];
|
||||
return {
|
||||
type: Collections.Collectibles,
|
||||
value: convertCollectibleToEndpointCollectiblePreview(source.collectible),
|
||||
type: "collectible",
|
||||
collectible: convertCollectibleToEndpointCollectiblePreview(source.collectible),
|
||||
...(isDefined(range) ? { range } : {}),
|
||||
};
|
||||
|
||||
case "pageBlock":
|
||||
if (!isPayloadType(source.page)) return [];
|
||||
return {
|
||||
type: Collections.Pages,
|
||||
value: convertPageToEndpointPagePreview(source.page),
|
||||
type: "page",
|
||||
page: convertPageToEndpointPagePreview(source.page),
|
||||
};
|
||||
|
||||
case "urlBlock":
|
||||
return {
|
||||
type: "url",
|
||||
value: {
|
||||
url: source.url,
|
||||
label: getDomainFromUrl(source.url),
|
||||
},
|
||||
url: source.url,
|
||||
label: getDomainFromUrl(source.url),
|
||||
};
|
||||
}
|
||||
}) ?? []
|
||||
|
@ -121,7 +113,7 @@ const handleSources = (
|
|||
|
||||
const handleRange = (
|
||||
rawRange: CollectibleBlock["range"]
|
||||
): EndpointCollectibleRelationRange | undefined => {
|
||||
): Extract<EndpointSource, { type: "collectible" }>["range"] => {
|
||||
const range = rawRange?.[0];
|
||||
|
||||
switch (range?.blockType) {
|
||||
|
|
|
@ -1,7 +1,7 @@
|
|||
import payload from "payload";
|
||||
import { CollectionEndpoint } from "../../../types/payload";
|
||||
import { convertEventToEndpointEvent } from "./getAllEndpoint";
|
||||
import { Collections } from "../../../shared/payload/constants";
|
||||
import { eventToEndpointEvent } from "./getAllEndpoint";
|
||||
import { Collections } from "src/shared/payload/constants";
|
||||
import { CollectionEndpoint } from "src/types/payload";
|
||||
|
||||
export const getByID: CollectionEndpoint = {
|
||||
method: "get",
|
||||
|
@ -27,7 +27,7 @@ export const getByID: CollectionEndpoint = {
|
|||
id: req.params.id,
|
||||
});
|
||||
|
||||
return res.status(200).json(convertEventToEndpointEvent(result));
|
||||
return res.status(200).json(eventToEndpointEvent(result));
|
||||
} catch {
|
||||
return res.sendStatus(404);
|
||||
}
|
||||
|
|
|
@ -1,8 +1,8 @@
|
|||
import { createStrapiImportEndpoint } from "../../../endpoints/createStrapiImportEndpoint";
|
||||
import { Collections } from "../../../shared/payload/constants";
|
||||
import { StrapiLanguage } from "../../../types/strapi";
|
||||
import { isDefined, isUndefined } from "../../../utils/asserts";
|
||||
import { plainTextToLexical } from "../../../utils/string";
|
||||
import { createStrapiImportEndpoint } from "src/endpoints/createStrapiImportEndpoint";
|
||||
import { Collections } from "src/shared/payload/constants";
|
||||
import { StrapiLanguage } from "src/types/strapi";
|
||||
import { isUndefined, isDefined } from "src/utils/asserts";
|
||||
import { plainTextToLexical } from "src/utils/string";
|
||||
|
||||
type StrapiChronologyItem = {
|
||||
year: number;
|
||||
|
|
|
@ -1,6 +1,6 @@
|
|||
import { FieldHook } from "payload/dist/fields/config/types";
|
||||
import { ChronologyEvent } from "../../../types/collections";
|
||||
import { isDefined, isUndefined } from "../../../utils/asserts";
|
||||
import { ChronologyEvent } from "src/types/collections";
|
||||
import { isUndefined, isDefined } from "src/utils/asserts";
|
||||
|
||||
export const beforeValidatePopulateNameField: FieldHook<
|
||||
ChronologyEvent,
|
||||
|
|
|
@ -1,7 +1,7 @@
|
|||
import { DateTime } from "luxon";
|
||||
import { Validate } from "payload/types";
|
||||
import { ChronologyEvent } from "../../../types/collections";
|
||||
import { isUndefined } from "../../../utils/asserts";
|
||||
import { ChronologyEvent } from "src/types/collections";
|
||||
import { isUndefined } from "src/utils/asserts";
|
||||
|
||||
export const validateDate: Validate<ChronologyEvent["date"] | undefined> = (date) => {
|
||||
if (isUndefined(date)) return "This field is required.";
|
||||
|
|
|
@ -1,6 +1,6 @@
|
|||
import { Validate } from "payload/types";
|
||||
import { ChronologyEvent } from "../../../types/collections";
|
||||
import { isEmpty } from "../../../utils/asserts";
|
||||
import { ChronologyEvent } from "src/types/collections";
|
||||
import { isEmpty } from "src/utils/asserts";
|
||||
|
||||
export const validateEventsTranslationsDescription: Validate<
|
||||
string | undefined,
|
||||
|
|
|
@ -1,6 +1,6 @@
|
|||
import { Validate } from "payload/types";
|
||||
import { ChronologyEvent } from "../../../types/collections";
|
||||
import { isEmpty } from "../../../utils/asserts";
|
||||
import { ChronologyEvent } from "src/types/collections";
|
||||
import { isEmpty } from "src/utils/asserts";
|
||||
|
||||
export const validateEventsTranslationsTitle: Validate<
|
||||
string | undefined,
|
||||
|
|
|
@ -1,29 +1,33 @@
|
|||
import { RowLabelArgs } from "payload/dist/admin/components/forms/RowLabel/types";
|
||||
import { attributesField } from "../../fields/attributesField/attributesField";
|
||||
import { componentField } from "../../fields/componentField/componentField";
|
||||
import { creditsField } from "../../fields/creditsField/creditsField";
|
||||
import { imageField } from "../../fields/imageField/imageField";
|
||||
import { rowField } from "../../fields/rowField/rowField";
|
||||
import { slugField } from "../../fields/slugField/slugField";
|
||||
import { translatedFields } from "../../fields/translatedFields/translatedFields";
|
||||
import { beforeDuplicateAddCopyTo } from "../../hooks/beforeDuplicateAddCopyTo";
|
||||
import { beforeDuplicatePiping } from "../../hooks/beforeDuplicatePiping";
|
||||
import { beforeDuplicateUnpublish } from "../../hooks/beforeDuplicateUnpublish";
|
||||
import { createEditor } from "../../utils/editor";
|
||||
import { buildVersionedCollectionConfig } from "../../utils/versionedCollectionConfig";
|
||||
import { Where } from "payload/types";
|
||||
import { RowLabel } from "./components/RowLabel";
|
||||
import { getBySlugEndpoint } from "./endpoints/getBySlugEndpoint";
|
||||
import { getBySlugEndpointGallery } from "./endpoints/getBySlugEndpointGallery";
|
||||
import { getBySlugEndpointGalleryImage } from "./endpoints/getBySlugEndpointGalleryImage";
|
||||
import { getBySlugEndpointScanPage } from "./endpoints/getBySlugEndpointScanPage";
|
||||
import { getBySlugEndpointScans } from "./endpoints/getBySlugEndpointScans";
|
||||
import { attributesField } from "src/fields/attributesField/attributesField";
|
||||
import { backPropagationField } from "src/fields/backPropagationField/backPropagationField";
|
||||
import { componentField } from "src/fields/componentField/componentField";
|
||||
import { creditsField } from "src/fields/creditsField/creditsField";
|
||||
import { imageField } from "src/fields/imageField/imageField";
|
||||
import { rowField } from "src/fields/rowField/rowField";
|
||||
import { slugField } from "src/fields/slugField/slugField";
|
||||
import { translatedFields } from "src/fields/translatedFields/translatedFields";
|
||||
import { beforeDuplicateAddCopyTo } from "src/hooks/beforeDuplicateAddCopyTo";
|
||||
import { beforeDuplicatePiping } from "src/hooks/beforeDuplicatePiping";
|
||||
import { beforeDuplicateUnpublish } from "src/hooks/beforeDuplicateUnpublish";
|
||||
import {
|
||||
Collections,
|
||||
CollectionGroups,
|
||||
CollectibleNature,
|
||||
CollectibleBindingTypes,
|
||||
CollectiblePageOrders,
|
||||
} from "../../shared/payload/constants";
|
||||
} from "src/shared/payload/constants";
|
||||
import { Collectible } from "src/types/collections";
|
||||
import { isPayloadType } from "src/utils/asserts";
|
||||
import { createEditor } from "src/utils/editor";
|
||||
import { buildVersionedCollectionConfig } from "src/utils/versionedCollectionConfig";
|
||||
|
||||
const fields = {
|
||||
status: "_status",
|
||||
|
@ -691,9 +695,42 @@ export const Collectibles = buildVersionedCollectionConfig({
|
|||
},
|
||||
],
|
||||
},
|
||||
|
||||
rowField([
|
||||
backPropagationField({
|
||||
name: fields.folders,
|
||||
relationTo: Collections.Folders,
|
||||
hasMany: true,
|
||||
where: ({ id }) => ({
|
||||
and: [
|
||||
{ "files.value": { equals: id } },
|
||||
{ "files.relationTo": { equals: Collections.Collectibles } },
|
||||
] as Where[],
|
||||
}),
|
||||
admin: {
|
||||
description: `You can go to the "Folders" collection to include this collectible in a folder.`,
|
||||
},
|
||||
}),
|
||||
backPropagationField({
|
||||
name: fields.parentItems,
|
||||
relationTo: Collections.Collectibles,
|
||||
hasMany: true,
|
||||
where: ({ id }) => ({ [fields.subitems]: { equals: id } }),
|
||||
}),
|
||||
]),
|
||||
],
|
||||
},
|
||||
],
|
||||
},
|
||||
],
|
||||
custom: {
|
||||
getBackPropagatedRelationships: ({ subitems, contents }: Collectible) => {
|
||||
const result: string[] = [];
|
||||
subitems?.forEach((subitem) => result.push(isPayloadType(subitem) ? subitem.id : subitem));
|
||||
contents?.forEach(({ content: { relationTo, value } }) => {
|
||||
if (relationTo === "pages") result.push(isPayloadType(value) ? value.id : value);
|
||||
});
|
||||
return result;
|
||||
},
|
||||
},
|
||||
});
|
||||
|
|
|
@ -1,6 +1,6 @@
|
|||
import React from "react";
|
||||
import { isDefined } from "src/utils/asserts";
|
||||
import styled from "styled-components";
|
||||
import { isDefined } from "../../../utils/asserts";
|
||||
|
||||
interface Props {
|
||||
page?: number;
|
||||
|
|
|
@ -1,41 +1,37 @@
|
|||
import { createGetByEndpoint } from "../../../endpoints/createGetByEndpoint";
|
||||
import { Collections, CollectibleNature } from "../../../shared/payload/constants";
|
||||
import { convertAudioToEndpointAudioPreview } from "src/collections/Audios/endpoints/getByID";
|
||||
import { convertFileToEndpointFilePreview } from "src/collections/Files/endpoints/getByID";
|
||||
import { convertPageToEndpointPagePreview } from "src/collections/Pages/endpoints/getBySlugEndpoint";
|
||||
import { convertRecorderToEndpointRecorderPreview } from "src/collections/Recorders/endpoints/getByID";
|
||||
import { convertVideoToEndpointVideoPreview } from "src/collections/Videos/endpoints/getByID";
|
||||
import { createGetByEndpoint } from "src/endpoints/createGetByEndpoint";
|
||||
import { Collections, CollectibleNature } from "src/shared/payload/constants";
|
||||
import { EndpointCollectiblePreview, EndpointCollectible } from "src/shared/payload/endpoint-types";
|
||||
import { Collectible } from "src/types/collections";
|
||||
import {
|
||||
EndpointCollectiblePreview,
|
||||
EndpointCollectible,
|
||||
} from "../../../shared/payload/endpoint-types";
|
||||
import { Collectible } from "../../../types/collections";
|
||||
import {
|
||||
isAudio,
|
||||
isDefined,
|
||||
isFile,
|
||||
isImage,
|
||||
isNotEmpty,
|
||||
isPayloadArrayType,
|
||||
isPayloadType,
|
||||
isNotEmpty,
|
||||
isDefined,
|
||||
isPayloadArrayType,
|
||||
isPublished,
|
||||
isFile,
|
||||
isScan,
|
||||
isAudio,
|
||||
isVideo,
|
||||
} from "../../../utils/asserts";
|
||||
} from "src/utils/asserts";
|
||||
import {
|
||||
convertAttributesToEndpointAttributes,
|
||||
convertImageToEndpointPayloadImage,
|
||||
convertRelationshipsToEndpointRelations,
|
||||
convertScanToEndpointScanImage,
|
||||
convertAttributesToEndpointAttributes,
|
||||
getDomainFromUrl,
|
||||
} from "../../../utils/endpoints";
|
||||
import { convertAudioToEndpointAudioPreview } from "../../Audios/endpoints/getByID";
|
||||
import { convertFileToEndpointFilePreview } from "../../Files/endpoints/getByID";
|
||||
import { convertPageToEndpointPagePreview } from "../../Pages/endpoints/getBySlugEndpoint";
|
||||
import { convertRecorderToEndpointRecorderPreview } from "../../Recorders/endpoints/getByID";
|
||||
import { convertVideoToEndpointVideoPreview } from "../../Videos/endpoints/getByID";
|
||||
import { findIncomingRelationships } from "payloadcms-relationships";
|
||||
convertSourceToEndpointSource,
|
||||
convertScanToEndpointScanImage,
|
||||
} from "src/utils/endpoints";
|
||||
|
||||
export const getBySlugEndpoint = createGetByEndpoint({
|
||||
collection: Collections.Collectibles,
|
||||
attribute: "slug",
|
||||
depth: 3,
|
||||
handler: async (collectible) => await convertCollectibleToEndpointCollectible(collectible),
|
||||
handler: (collectible) => convertCollectibleToEndpointCollectible(collectible),
|
||||
});
|
||||
|
||||
export const convertCollectibleToEndpointCollectiblePreview = ({
|
||||
|
@ -65,11 +61,8 @@ export const convertCollectibleToEndpointCollectiblePreview = ({
|
|||
...handlePrice(price, priceEnabled),
|
||||
});
|
||||
|
||||
const convertCollectibleToEndpointCollectible = async (
|
||||
collectible: Collectible
|
||||
): Promise<EndpointCollectible> => {
|
||||
const convertCollectibleToEndpointCollectible = (collectible: Collectible): EndpointCollectible => {
|
||||
const {
|
||||
id,
|
||||
nature,
|
||||
urls,
|
||||
subitems,
|
||||
|
@ -84,6 +77,8 @@ const convertCollectibleToEndpointCollectible = async (
|
|||
weightEnabled,
|
||||
pageInfo,
|
||||
pageInfoEnabled,
|
||||
parentItems,
|
||||
folders,
|
||||
backgroundImage,
|
||||
translations,
|
||||
scans: rawScans,
|
||||
|
@ -130,9 +125,7 @@ const convertCollectibleToEndpointCollectible = async (
|
|||
...(isPayloadType(updatedBy)
|
||||
? { updatedBy: convertRecorderToEndpointRecorderPreview(updatedBy) }
|
||||
: {}),
|
||||
backlinks: convertRelationshipsToEndpointRelations(
|
||||
await findIncomingRelationships(Collections.Collectibles, id)
|
||||
),
|
||||
parentPages: convertSourceToEndpointSource({ collectibles: parentItems, folders }),
|
||||
};
|
||||
};
|
||||
|
||||
|
|
|
@ -1,9 +1,11 @@
|
|||
import { createGetByEndpoint } from "../../../endpoints/createGetByEndpoint";
|
||||
import { Collections } from "../../../shared/payload/constants";
|
||||
import { EndpointCollectibleGallery } from "../../../shared/payload/endpoint-types";
|
||||
import { isImage, isNotEmpty, isPayloadType } from "../../../utils/asserts";
|
||||
import { convertImageToEndpointPayloadImage } from "../../../utils/endpoints";
|
||||
import { convertCollectibleToEndpointCollectiblePreview } from "./getBySlugEndpoint";
|
||||
import { createGetByEndpoint } from "src/endpoints/createGetByEndpoint";
|
||||
import { Collections } from "src/shared/payload/constants";
|
||||
import { EndpointCollectibleGallery } from "src/shared/payload/endpoint-types";
|
||||
import { isPayloadType, isNotEmpty, isImage } from "src/utils/asserts";
|
||||
import {
|
||||
convertImageToEndpointPayloadImage,
|
||||
convertSourceToEndpointSource,
|
||||
} from "src/utils/endpoints";
|
||||
|
||||
export const getBySlugEndpointGallery = createGetByEndpoint({
|
||||
collection: Collections.Collectibles,
|
||||
|
@ -27,12 +29,7 @@ export const getBySlugEndpointGallery = createGetByEndpoint({
|
|||
gallery?.flatMap(({ image }) =>
|
||||
isImage(image) ? convertImageToEndpointPayloadImage(image) : []
|
||||
) ?? [],
|
||||
backlinks: [
|
||||
{
|
||||
type: Collections.Collectibles,
|
||||
value: convertCollectibleToEndpointCollectiblePreview(collectible),
|
||||
},
|
||||
],
|
||||
parentPages: convertSourceToEndpointSource({ collectibles: [collectible] }),
|
||||
};
|
||||
},
|
||||
});
|
||||
|
|
|
@ -1,11 +1,12 @@
|
|||
import payload from "payload";
|
||||
import { Collectible, Image } from "../../../types/collections";
|
||||
import { CollectionEndpoint } from "../../../types/payload";
|
||||
import { isDefined, isImage, isNotEmpty, isPayloadType } from "../../../utils/asserts";
|
||||
import { convertImageToEndpointImage } from "../../Images/endpoints/getByID";
|
||||
import { Collections } from "../../../shared/payload/constants";
|
||||
import { EndpointCollectibleGalleryImage } from "../../../shared/payload/endpoint-types";
|
||||
import { convertCollectibleToEndpointCollectiblePreview } from "./getBySlugEndpoint";
|
||||
import { convertImageToEndpointImage } from "src/collections/Images/endpoints/getByID";
|
||||
import { Collections } from "src/shared/payload/constants";
|
||||
import { EndpointCollectibleGalleryImage } from "src/shared/payload/endpoint-types";
|
||||
import { Collectible } from "src/types/collections";
|
||||
import { CollectionEndpoint } from "src/types/payload";
|
||||
import { isImage, isPayloadType, isNotEmpty, isDefined } from "src/utils/asserts";
|
||||
import { convertSourceToEndpointSource } from "src/utils/endpoints";
|
||||
import { Image } from "src/types/collections";
|
||||
|
||||
export const getBySlugEndpointGalleryImage: CollectionEndpoint = {
|
||||
path: "/slug/:slug/gallery/:index",
|
||||
|
@ -51,7 +52,8 @@ export const getBySlugEndpointGalleryImage: CollectionEndpoint = {
|
|||
const nextIndex = getNextIndex(index, collectible.gallery);
|
||||
|
||||
const scanPage: EndpointCollectibleGalleryImage = {
|
||||
image: await convertImageToEndpointImage(image),
|
||||
image: convertImageToEndpointImage(image),
|
||||
parentPages: convertSourceToEndpointSource({ gallery: [collectible] }),
|
||||
slug,
|
||||
translations:
|
||||
collectible.translations?.map(({ language, title, description, pretitle, subtitle }) => ({
|
||||
|
@ -63,13 +65,6 @@ export const getBySlugEndpointGalleryImage: CollectionEndpoint = {
|
|||
})) ?? [],
|
||||
...(isDefined(previousIndex) ? { previousIndex } : {}),
|
||||
...(isDefined(nextIndex) ? { nextIndex } : {}),
|
||||
backlinks: [
|
||||
{
|
||||
type: Collections.Collectibles,
|
||||
subpage: "gallery",
|
||||
value: convertCollectibleToEndpointCollectiblePreview(collectible),
|
||||
},
|
||||
],
|
||||
};
|
||||
|
||||
res.status(200).send(scanPage);
|
||||
|
|
|
@ -1,11 +1,10 @@
|
|||
import payload from "payload";
|
||||
import { Collectible, Scan } from "../../../types/collections";
|
||||
import { CollectionEndpoint } from "../../../types/payload";
|
||||
import { isDefined, isNotEmpty, isPayloadType, isScan } from "../../../utils/asserts";
|
||||
import { convertScanToEndpointScanImage } from "../../../utils/endpoints";
|
||||
import { Collections } from "../../../shared/payload/constants";
|
||||
import { EndpointCollectibleScanPage } from "../../../shared/payload/endpoint-types";
|
||||
import { convertCollectibleToEndpointCollectiblePreview } from "./getBySlugEndpoint";
|
||||
import { Collections } from "src/shared/payload/constants";
|
||||
import { EndpointCollectibleScanPage } from "src/shared/payload/endpoint-types";
|
||||
import { Collectible, Scan } from "src/types/collections";
|
||||
import { CollectionEndpoint } from "src/types/payload";
|
||||
import { isScan, isPayloadType, isNotEmpty, isDefined } from "src/utils/asserts";
|
||||
import { convertScanToEndpointScanImage, convertSourceToEndpointSource } from "src/utils/endpoints";
|
||||
|
||||
export const getBySlugEndpointScanPage: CollectionEndpoint = {
|
||||
path: "/slug/:slug/scans/:index",
|
||||
|
@ -52,6 +51,7 @@ export const getBySlugEndpointScanPage: CollectionEndpoint = {
|
|||
|
||||
const scanPage: EndpointCollectibleScanPage = {
|
||||
image: convertScanToEndpointScanImage(scan, index),
|
||||
parentPages: convertSourceToEndpointSource({ scans: [collectible] }),
|
||||
slug,
|
||||
translations:
|
||||
collectible.translations?.map(({ language, title, description, pretitle, subtitle }) => ({
|
||||
|
@ -63,13 +63,6 @@ export const getBySlugEndpointScanPage: CollectionEndpoint = {
|
|||
})) ?? [],
|
||||
...(isDefined(previousIndex) ? { previousIndex } : {}),
|
||||
...(isDefined(nextIndex) ? { nextIndex } : {}),
|
||||
backlinks: [
|
||||
{
|
||||
type: Collections.Collectibles,
|
||||
subpage: "scans",
|
||||
value: convertCollectibleToEndpointCollectiblePreview(collectible),
|
||||
},
|
||||
],
|
||||
};
|
||||
|
||||
res.status(200).send(scanPage);
|
||||
|
|
|
@ -1,14 +1,14 @@
|
|||
import { createGetByEndpoint } from "../../../endpoints/createGetByEndpoint";
|
||||
import { Collections } from "../../../shared/payload/constants";
|
||||
import { EndpointCollectibleScans } from "../../../shared/payload/endpoint-types";
|
||||
import { Collectible } from "../../../types/collections";
|
||||
import { isImage, isNotEmpty, isPayloadType, isScan } from "../../../utils/asserts";
|
||||
import { createGetByEndpoint } from "src/endpoints/createGetByEndpoint";
|
||||
import { Collections } from "src/shared/payload/constants";
|
||||
import { EndpointCollectibleScans } from "src/shared/payload/endpoint-types";
|
||||
import { Collectible } from "src/types/collections";
|
||||
import { isPayloadType, isNotEmpty, isImage, isScan } from "src/utils/asserts";
|
||||
import {
|
||||
convertCreditsToEndpointCredits,
|
||||
convertImageToEndpointPayloadImage,
|
||||
convertSourceToEndpointSource,
|
||||
convertCreditsToEndpointCredits,
|
||||
convertScanToEndpointScanImage,
|
||||
} from "../../../utils/endpoints";
|
||||
import { convertCollectibleToEndpointCollectiblePreview } from "./getBySlugEndpoint";
|
||||
} from "src/utils/endpoints";
|
||||
|
||||
export const getBySlugEndpointScans = createGetByEndpoint({
|
||||
collection: Collections.Collectibles,
|
||||
|
@ -29,12 +29,7 @@ export const getBySlugEndpointScans = createGetByEndpoint({
|
|||
})) ?? [],
|
||||
...(isImage(thumbnail) ? { thumbnail: convertImageToEndpointPayloadImage(thumbnail) } : {}),
|
||||
...(scansEnabled && scans ? handleScans(scans) : { credits: [], pages: [] }),
|
||||
backlinks: [
|
||||
{
|
||||
type: Collections.Collectibles,
|
||||
value: convertCollectibleToEndpointCollectiblePreview(collectible),
|
||||
},
|
||||
],
|
||||
parentPages: convertSourceToEndpointSource({ collectibles: [collectible] }),
|
||||
};
|
||||
},
|
||||
});
|
||||
|
|
|
@ -1,9 +1,9 @@
|
|||
import { CollectionConfig } from "payload/types";
|
||||
import { iconField } from "../../fields/iconField/iconField";
|
||||
import { slugField } from "../../fields/slugField/slugField";
|
||||
import { translatedFields } from "../../fields/translatedFields/translatedFields";
|
||||
import { buildCollectionConfig } from "../../utils/collectionConfig";
|
||||
import { Collections, CollectionGroups } from "../../shared/payload/constants";
|
||||
import { iconField } from "src/fields/iconField/iconField";
|
||||
import { slugField } from "src/fields/slugField/slugField";
|
||||
import { translatedFields } from "src/fields/translatedFields/translatedFields";
|
||||
import { Collections, CollectionGroups } from "src/shared/payload/constants";
|
||||
import { buildCollectionConfig } from "src/utils/collectionConfig";
|
||||
|
||||
const fields = {
|
||||
slug: "slug",
|
||||
|
|
|
@ -1,10 +1,10 @@
|
|||
import { text } from "payload/dist/fields/validations";
|
||||
import { mustBeAdmin } from "../../accesses/collections/mustBeAdmin";
|
||||
import { shownOnlyToAdmin } from "../../accesses/collections/shownOnlyToAdmin";
|
||||
import { buildCollectionConfig } from "../../utils/collectionConfig";
|
||||
import { getAllEndpoint } from "./endpoints/getAllEndpoint";
|
||||
import { importFromStrapi } from "./endpoints/importFromStrapi";
|
||||
import { Collections, CollectionGroups } from "../../shared/payload/constants";
|
||||
import { shownOnlyToAdmin } from "src/accesses/collections/shownOnlyToAdmin";
|
||||
import { mustBeAdmin } from "src/accesses/fields/mustBeAdmin";
|
||||
import { Collections, CollectionGroups } from "src/shared/payload/constants";
|
||||
import { buildCollectionConfig } from "src/utils/collectionConfig";
|
||||
|
||||
const fields = {
|
||||
id: "id",
|
||||
|
|
|
@ -1,7 +1,7 @@
|
|||
import payload from "payload";
|
||||
import { Currency } from "../../../types/collections";
|
||||
import { CollectionEndpoint } from "../../../types/payload";
|
||||
import { Collections } from "../../../shared/payload/constants";
|
||||
import { Collections } from "src/shared/payload/constants";
|
||||
import { Currency } from "src/types/collections";
|
||||
import { CollectionEndpoint } from "src/types/payload";
|
||||
|
||||
export const getAllEndpoint: CollectionEndpoint = {
|
||||
method: "get",
|
||||
|
|
|
@ -1,5 +1,5 @@
|
|||
import { createStrapiImportEndpoint } from "../../../endpoints/createStrapiImportEndpoint";
|
||||
import { Collections } from "../../../shared/payload/constants";
|
||||
import { createStrapiImportEndpoint } from "src/endpoints/createStrapiImportEndpoint";
|
||||
import { Collections } from "src/shared/payload/constants";
|
||||
|
||||
type StrapiLanguage = {
|
||||
code: string;
|
||||
|
|
|
@ -1,11 +1,11 @@
|
|||
import { attributesField } from "../../fields/attributesField/attributesField";
|
||||
import { creditsField } from "../../fields/creditsField/creditsField";
|
||||
import { imageField } from "../../fields/imageField/imageField";
|
||||
import { rowField } from "../../fields/rowField/rowField";
|
||||
import { translatedFields } from "../../fields/translatedFields/translatedFields";
|
||||
import { CollectionGroups, Collections } from "../../shared/payload/constants";
|
||||
import { buildCollectionConfig } from "../../utils/collectionConfig";
|
||||
import { createEditor } from "../../utils/editor";
|
||||
import { attributesField } from "src/fields/attributesField/attributesField";
|
||||
import { creditsField } from "src/fields/creditsField/creditsField";
|
||||
import { imageField } from "src/fields/imageField/imageField";
|
||||
import { rowField } from "src/fields/rowField/rowField";
|
||||
import { translatedFields } from "src/fields/translatedFields/translatedFields";
|
||||
import { Collections, CollectionGroups } from "src/shared/payload/constants";
|
||||
import { buildCollectionConfig } from "src/utils/collectionConfig";
|
||||
import { createEditor } from "src/utils/editor";
|
||||
import { getByID } from "./endpoints/getByID";
|
||||
|
||||
const fields = {
|
||||
|
|
|
@ -1,22 +1,16 @@
|
|||
import payload from "payload";
|
||||
import { File } from "../../../types/collections";
|
||||
import { CollectionEndpoint } from "../../../types/payload";
|
||||
import { isFile, isMediaThumbnail, isNotEmpty } from "../../../utils/asserts";
|
||||
import { Collections } from "src/shared/payload/constants";
|
||||
import { PayloadMedia, EndpointFilePreview, EndpointFile } from "src/shared/payload/endpoint-types";
|
||||
import { CollectionEndpoint } from "src/types/payload";
|
||||
import { isFile, isNotEmpty, isMediaThumbnail } from "src/utils/asserts";
|
||||
import {
|
||||
convertAttributesToEndpointAttributes,
|
||||
convertCreditsToEndpointCredits,
|
||||
getLanguageId,
|
||||
convertMediaThumbnailToEndpointPayloadImage,
|
||||
convertRTCToEndpointRTC,
|
||||
convertRelationshipsToEndpointRelations,
|
||||
getLanguageId,
|
||||
} from "../../../utils/endpoints";
|
||||
import { Collections } from "../../../shared/payload/constants";
|
||||
import {
|
||||
PayloadMedia,
|
||||
EndpointFilePreview,
|
||||
EndpointFile,
|
||||
} from "../../../shared/payload/endpoint-types";
|
||||
import { findIncomingRelationships } from "payloadcms-relationships";
|
||||
convertCreditsToEndpointCredits,
|
||||
} from "src/utils/endpoints";
|
||||
import { File } from "src/types/collections";
|
||||
|
||||
export const getByID: CollectionEndpoint = {
|
||||
method: "get",
|
||||
|
@ -46,7 +40,7 @@ export const getByID: CollectionEndpoint = {
|
|||
return res.sendStatus(404);
|
||||
}
|
||||
|
||||
return res.status(200).json(await convertFileToEndpointFile(result));
|
||||
return res.status(200).json(convertFileToEndpointFile(result));
|
||||
} catch {
|
||||
return res.sendStatus(404);
|
||||
}
|
||||
|
@ -81,8 +75,8 @@ export const convertFileToEndpointFilePreview = ({
|
|||
: {}),
|
||||
});
|
||||
|
||||
const convertFileToEndpointFile = async (file: File & PayloadMedia): Promise<EndpointFile> => {
|
||||
const { translations, createdAt, updatedAt, filesize, credits, id } = file;
|
||||
const convertFileToEndpointFile = (file: File & PayloadMedia): EndpointFile => {
|
||||
const { translations, createdAt, updatedAt, filesize, credits } = file;
|
||||
|
||||
return {
|
||||
...convertFileToEndpointFilePreview(file),
|
||||
|
@ -98,8 +92,5 @@ const convertFileToEndpointFile = async (file: File & PayloadMedia): Promise<End
|
|||
...(isNotEmpty(description) ? { description: convertRTCToEndpointRTC(description) } : {}),
|
||||
})) ?? [],
|
||||
credits: convertCreditsToEndpointCredits(credits),
|
||||
backlinks: convertRelationshipsToEndpointRelations(
|
||||
await findIncomingRelationships(Collections.Files, id)
|
||||
),
|
||||
};
|
||||
};
|
||||
|
|
|
@ -1,10 +1,13 @@
|
|||
import { iconField } from "../../fields/iconField/iconField";
|
||||
import { rowField } from "../../fields/rowField/rowField";
|
||||
import { slugField } from "../../fields/slugField/slugField";
|
||||
import { translatedFields } from "../../fields/translatedFields/translatedFields";
|
||||
import { Collections, CollectionGroups } from "../../shared/payload/constants";
|
||||
import { buildCollectionConfig } from "../../utils/collectionConfig";
|
||||
import { createEditor } from "../../utils/editor";
|
||||
import { backPropagationField } from "src/fields/backPropagationField/backPropagationField";
|
||||
import { iconField } from "src/fields/iconField/iconField";
|
||||
import { rowField } from "src/fields/rowField/rowField";
|
||||
import { slugField } from "src/fields/slugField/slugField";
|
||||
import { translatedFields } from "src/fields/translatedFields/translatedFields";
|
||||
import { Collections, CollectionGroups } from "src/shared/payload/constants";
|
||||
import { Folder } from "src/types/collections";
|
||||
import { isPayloadType } from "src/utils/asserts";
|
||||
import { buildCollectionConfig } from "src/utils/collectionConfig";
|
||||
import { createEditor } from "src/utils/editor";
|
||||
import { getBySlugEndpoint } from "./endpoints/getBySlugEndpoint";
|
||||
|
||||
const fields = {
|
||||
|
@ -41,7 +44,16 @@ export const Folders = buildCollectionConfig({
|
|||
},
|
||||
endpoints: [getBySlugEndpoint],
|
||||
fields: [
|
||||
rowField([slugField({ name: fields.slug }), iconField({ name: fields.icon })]),
|
||||
rowField([
|
||||
slugField({ name: fields.slug }),
|
||||
iconField({ name: fields.icon }),
|
||||
backPropagationField({
|
||||
name: fields.parentFolders,
|
||||
relationTo: Collections.Folders,
|
||||
hasMany: true,
|
||||
where: ({ id }) => ({ "sections.subfolders": { equals: id } }),
|
||||
}),
|
||||
]),
|
||||
translatedFields({
|
||||
name: fields.translations,
|
||||
admin: { useAsTitle: fields.translationsName },
|
||||
|
@ -100,4 +112,21 @@ export const Folders = buildCollectionConfig({
|
|||
hasMany: true,
|
||||
},
|
||||
],
|
||||
|
||||
custom: {
|
||||
getBackPropagatedRelationships: ({ files, sections }: Folder) => {
|
||||
const result: string[] = [];
|
||||
files?.forEach(({ relationTo, value }) => {
|
||||
if (relationTo === "collectibles" || relationTo === "pages") {
|
||||
result.push(isPayloadType(value) ? value.id : value);
|
||||
}
|
||||
});
|
||||
sections?.forEach(({ subfolders }) =>
|
||||
subfolders?.forEach((folder) => {
|
||||
result.push(isPayloadType(folder) ? folder.id : folder);
|
||||
})
|
||||
);
|
||||
return result;
|
||||
},
|
||||
},
|
||||
});
|
||||
|
|
|
@ -1,25 +1,24 @@
|
|||
import { createGetByEndpoint } from "../../../endpoints/createGetByEndpoint";
|
||||
import { findIncomingRelationships } from "payloadcms-relationships";
|
||||
import { Collections } from "../../../shared/payload/constants";
|
||||
import { EndpointFolderPreview, EndpointFolder } from "../../../shared/payload/endpoint-types";
|
||||
import { Folder, Language } from "../../../types/collections";
|
||||
import { convertAudioToEndpointAudioPreview } from "src/collections/Audios/endpoints/getByID";
|
||||
import { convertCollectibleToEndpointCollectiblePreview } from "src/collections/Collectibles/endpoints/getBySlugEndpoint";
|
||||
import { convertFileToEndpointFilePreview } from "src/collections/Files/endpoints/getByID";
|
||||
import { convertImageToEndpointImagePreview } from "src/collections/Images/endpoints/getByID";
|
||||
import { convertPageToEndpointPagePreview } from "src/collections/Pages/endpoints/getBySlugEndpoint";
|
||||
import { convertVideoToEndpointVideoPreview } from "src/collections/Videos/endpoints/getByID";
|
||||
import { createGetByEndpoint } from "src/endpoints/createGetByEndpoint";
|
||||
import { Collections } from "src/shared/payload/constants";
|
||||
import { EndpointFolderPreview, EndpointFolder } from "src/shared/payload/endpoint-types";
|
||||
import { Folder, Language } from "src/types/collections";
|
||||
import {
|
||||
isAudio,
|
||||
isDefined,
|
||||
isFile,
|
||||
isImage,
|
||||
isNotEmpty,
|
||||
isPayloadType,
|
||||
isPublished,
|
||||
isImage,
|
||||
isAudio,
|
||||
isVideo,
|
||||
} from "../../../utils/asserts";
|
||||
import { convertRelationshipsToEndpointRelations, getLanguageId } from "../../../utils/endpoints";
|
||||
import { convertAudioToEndpointAudioPreview } from "../../Audios/endpoints/getByID";
|
||||
import { convertCollectibleToEndpointCollectiblePreview } from "../../Collectibles/endpoints/getBySlugEndpoint";
|
||||
import { convertFileToEndpointFilePreview } from "../../Files/endpoints/getByID";
|
||||
import { convertImageToEndpointImagePreview } from "../../Images/endpoints/getByID";
|
||||
import { convertPageToEndpointPagePreview } from "../../Pages/endpoints/getBySlugEndpoint";
|
||||
import { convertVideoToEndpointVideoPreview } from "../../Videos/endpoints/getByID";
|
||||
isFile,
|
||||
} from "src/utils/asserts";
|
||||
import { getLanguageId, convertSourceToEndpointSource } from "src/utils/endpoints";
|
||||
|
||||
export const getBySlugEndpoint = createGetByEndpoint({
|
||||
collection: Collections.Folders,
|
||||
|
@ -44,8 +43,8 @@ export const convertFolderToEndpointFolderPreview = ({
|
|||
})) ?? [],
|
||||
});
|
||||
|
||||
const convertFolderToEndpointFolder = async (folder: Folder): Promise<EndpointFolder> => {
|
||||
const { translations, sections, files, id } = folder;
|
||||
const convertFolderToEndpointFolder = (folder: Folder): EndpointFolder => {
|
||||
const { translations, sections, files, parentFolders } = folder;
|
||||
|
||||
return {
|
||||
...convertFolderToEndpointFolderPreview(folder),
|
||||
|
@ -117,9 +116,7 @@ const convertFolderToEndpointFolder = async (folder: Folder): Promise<EndpointFo
|
|||
return [];
|
||||
}
|
||||
}) ?? [],
|
||||
backlinks: convertRelationshipsToEndpointRelations(
|
||||
await findIncomingRelationships(Collections.Folders, id)
|
||||
),
|
||||
parentPages: convertSourceToEndpointSource({ folders: parentFolders }),
|
||||
};
|
||||
};
|
||||
|
||||
|
|
|
@ -1,10 +1,10 @@
|
|||
import { CollectionConfig } from "payload/types";
|
||||
import { QuickFilters, languageBasedFilters } from "../../components/QuickFilters";
|
||||
import { rowField } from "../../fields/rowField/rowField";
|
||||
import { translatedFields } from "../../fields/translatedFields/translatedFields";
|
||||
import { beforeDuplicateAddCopyTo } from "../../hooks/beforeDuplicateAddCopyTo";
|
||||
import { buildCollectionConfig } from "../../utils/collectionConfig";
|
||||
import { Collections, CollectionGroups } from "../../shared/payload/constants";
|
||||
import { QuickFilters, languageBasedFilters } from "src/components/QuickFilters";
|
||||
import { rowField } from "src/fields/rowField/rowField";
|
||||
import { translatedFields } from "src/fields/translatedFields/translatedFields";
|
||||
import { beforeDuplicateAddCopyTo } from "src/hooks/beforeDuplicateAddCopyTo";
|
||||
import { Collections, CollectionGroups } from "src/shared/payload/constants";
|
||||
import { buildCollectionConfig } from "src/utils/collectionConfig";
|
||||
|
||||
const fields = {
|
||||
name: "name",
|
||||
|
|
|
@ -1,15 +1,15 @@
|
|||
import { createImageSizesRegenerationEndpoint } from "../../endpoints/imageSizesRegenerationEndpoint";
|
||||
import { attributesField } from "../../fields/attributesField/attributesField";
|
||||
import { creditsField } from "../../fields/creditsField/creditsField";
|
||||
import { rowField } from "../../fields/rowField/rowField";
|
||||
import { translatedFields } from "../../fields/translatedFields/translatedFields";
|
||||
import { Collections } from "../../shared/payload/constants";
|
||||
import { createEditor } from "../../utils/editor";
|
||||
import { createImageSizesRegenerationEndpoint } from "src/endpoints/imageSizesRegenerationEndpoint";
|
||||
import { attributesField } from "src/fields/attributesField/attributesField";
|
||||
import { creditsField } from "src/fields/creditsField/creditsField";
|
||||
import { rowField } from "src/fields/rowField/rowField";
|
||||
import { translatedFields } from "src/fields/translatedFields/translatedFields";
|
||||
import { Collections } from "src/shared/payload/constants";
|
||||
import { createEditor } from "src/utils/editor";
|
||||
import {
|
||||
buildImageCollectionConfig,
|
||||
generateOpenGraphSize,
|
||||
generateWebpSize,
|
||||
} from "../../utils/imageCollectionConfig";
|
||||
} from "src/utils/imageCollectionConfig";
|
||||
import { getByID } from "./endpoints/getByID";
|
||||
|
||||
const fields = {
|
||||
|
@ -36,7 +36,6 @@ export const Images = buildImageCollectionConfig({
|
|||
admin: {
|
||||
preview: ({ id }) => `${process.env.PAYLOAD_PUBLIC_FRONTEND_BASE_URL}/en/images/${id}`,
|
||||
defaultColumns: [fields.filename, fields.posts, fields.updatedAt],
|
||||
useAsTitle: fields.filename,
|
||||
},
|
||||
upload: {
|
||||
imageSizes: [
|
||||
|
|
|
@ -1,22 +1,20 @@
|
|||
import payload from "payload";
|
||||
import { Image } from "../../../types/collections";
|
||||
import { CollectionEndpoint } from "../../../types/payload";
|
||||
import { isImage, isNotEmpty, isPayloadImage } from "../../../utils/asserts";
|
||||
import {
|
||||
convertAttributesToEndpointAttributes,
|
||||
convertCreditsToEndpointCredits,
|
||||
convertRTCToEndpointRTC,
|
||||
convertRelationshipsToEndpointRelations,
|
||||
convertSizesToPayloadImages,
|
||||
getLanguageId,
|
||||
} from "../../../utils/endpoints";
|
||||
import { Collections } from "../../../shared/payload/constants";
|
||||
import { Collections } from "src/shared/payload/constants";
|
||||
import {
|
||||
PayloadImage,
|
||||
EndpointImagePreview,
|
||||
EndpointImage,
|
||||
} from "../../../shared/payload/endpoint-types";
|
||||
import { findIncomingRelationships } from "payloadcms-relationships";
|
||||
} from "src/shared/payload/endpoint-types";
|
||||
import { CollectionEndpoint } from "src/types/payload";
|
||||
import { isImage, isNotEmpty, isPayloadImage } from "src/utils/asserts";
|
||||
import {
|
||||
convertAttributesToEndpointAttributes,
|
||||
getLanguageId,
|
||||
convertSizesToPayloadImages,
|
||||
convertRTCToEndpointRTC,
|
||||
convertCreditsToEndpointCredits,
|
||||
} from "src/utils/endpoints";
|
||||
import { Image } from "src/types/collections";
|
||||
|
||||
export const getByID: CollectionEndpoint = {
|
||||
method: "get",
|
||||
|
@ -46,7 +44,7 @@ export const getByID: CollectionEndpoint = {
|
|||
return res.sendStatus(404);
|
||||
}
|
||||
|
||||
return res.status(200).json(await convertImageToEndpointImage(result));
|
||||
return res.status(200).json(convertImageToEndpointImage(result));
|
||||
} catch {
|
||||
return res.sendStatus(404);
|
||||
}
|
||||
|
@ -95,10 +93,8 @@ export const convertImageToEndpointImagePreview = ({
|
|||
...(isPayloadImage(sizes?.og) ? { openGraph: sizes.og } : {}),
|
||||
});
|
||||
|
||||
export const convertImageToEndpointImage = async (
|
||||
image: Image & PayloadImage
|
||||
): Promise<EndpointImage> => {
|
||||
const { translations, createdAt, updatedAt, filesize, credits, id } = image;
|
||||
export const convertImageToEndpointImage = (image: Image & PayloadImage): EndpointImage => {
|
||||
const { translations, createdAt, updatedAt, filesize, credits } = image;
|
||||
return {
|
||||
...convertImageToEndpointImagePreview(image),
|
||||
createdAt,
|
||||
|
@ -113,8 +109,5 @@ export const convertImageToEndpointImage = async (
|
|||
...(isNotEmpty(description) ? { description: convertRTCToEndpointRTC(description) } : {}),
|
||||
})) ?? [],
|
||||
credits: convertCreditsToEndpointCredits(credits),
|
||||
backlinks: convertRelationshipsToEndpointRelations(
|
||||
await findIncomingRelationships(Collections.Images, id)
|
||||
),
|
||||
};
|
||||
};
|
||||
|
|
|
@ -1,11 +1,10 @@
|
|||
import { text } from "payload/dist/fields/validations";
|
||||
import { mustBeAdmin } from "../../accesses/collections/mustBeAdmin";
|
||||
import { shownOnlyToAdmin } from "../../accesses/collections/shownOnlyToAdmin";
|
||||
import { rowField } from "../../fields/rowField/rowField";
|
||||
import { buildCollectionConfig } from "../../utils/collectionConfig";
|
||||
import { getAllEndpoint } from "./endpoints/getAllEndpoint";
|
||||
import { importFromStrapi } from "./endpoints/importFromStrapi";
|
||||
import { Collections, CollectionGroups } from "../../shared/payload/constants";
|
||||
import { shownOnlyToAdmin } from "src/accesses/collections/shownOnlyToAdmin";
|
||||
import { mustBeAdmin } from "src/accesses/fields/mustBeAdmin";
|
||||
import { rowField } from "src/fields/rowField/rowField";
|
||||
import { Collections, CollectionGroups } from "src/shared/payload/constants";
|
||||
import { buildCollectionConfig } from "src/utils/collectionConfig";
|
||||
|
||||
const fields = {
|
||||
id: "id",
|
||||
|
@ -30,7 +29,7 @@ export const Languages = buildCollectionConfig({
|
|||
},
|
||||
access: { create: mustBeAdmin, update: mustBeAdmin, delete: mustBeAdmin },
|
||||
timestamps: false,
|
||||
endpoints: [importFromStrapi, getAllEndpoint],
|
||||
endpoints: [getAllEndpoint],
|
||||
fields: [
|
||||
{
|
||||
name: fields.id,
|
||||
|
|
|
@ -1,7 +1,7 @@
|
|||
import payload from "payload";
|
||||
import { Language } from "../../../types/collections";
|
||||
import { CollectionEndpoint } from "../../../types/payload";
|
||||
import { Collections } from "../../../shared/payload/constants";
|
||||
import { Collections } from "src/shared/payload/constants";
|
||||
import { Language } from "src/types/collections";
|
||||
import { CollectionEndpoint } from "src/types/payload";
|
||||
|
||||
export const getAllEndpoint: CollectionEndpoint = {
|
||||
method: "get",
|
||||
|
|
|
@ -1,18 +0,0 @@
|
|||
import { createStrapiImportEndpoint } from "../../../endpoints/createStrapiImportEndpoint";
|
||||
import { Collections } from "../../../shared/payload/constants";
|
||||
|
||||
type StrapiLanguage = {
|
||||
name: string;
|
||||
code: string;
|
||||
};
|
||||
|
||||
export const importFromStrapi = createStrapiImportEndpoint<StrapiLanguage>({
|
||||
strapi: {
|
||||
collection: "languages",
|
||||
params: {},
|
||||
},
|
||||
payload: {
|
||||
collection: Collections.Languages,
|
||||
convert: ({ code, name }) => ({ id: code, name }),
|
||||
},
|
||||
});
|
|
@ -1,11 +1,11 @@
|
|||
import { shownOnlyToAdmin } from "../../accesses/collections/shownOnlyToAdmin";
|
||||
import { createImageSizesRegenerationEndpoint } from "../../endpoints/imageSizesRegenerationEndpoint";
|
||||
import { Collections } from "../../shared/payload/constants";
|
||||
import { shownOnlyToAdmin } from "src/accesses/collections/shownOnlyToAdmin";
|
||||
import { createImageSizesRegenerationEndpoint } from "src/endpoints/imageSizesRegenerationEndpoint";
|
||||
import { Collections } from "src/shared/payload/constants";
|
||||
import {
|
||||
buildImageCollectionConfig,
|
||||
generateOpenGraphSize,
|
||||
generateWebpSize,
|
||||
} from "../../utils/imageCollectionConfig";
|
||||
} from "src/utils/imageCollectionConfig";
|
||||
|
||||
const fields = {
|
||||
filename: "filename",
|
||||
|
|
|
@ -1,20 +1,22 @@
|
|||
import { breakBlock } from "../../blocks/breakBlock";
|
||||
import { sectionBlock } from "../../blocks/sectionBlock";
|
||||
import { transcriptBlock } from "../../blocks/transcriptBlock";
|
||||
import { QuickFilters, publishStatusFilters } from "../../components/QuickFilters";
|
||||
import { attributesField } from "../../fields/attributesField/attributesField";
|
||||
import { creditsField } from "../../fields/creditsField/creditsField";
|
||||
import { imageField } from "../../fields/imageField/imageField";
|
||||
import { rowField } from "../../fields/rowField/rowField";
|
||||
import { slugField } from "../../fields/slugField/slugField";
|
||||
import { translatedFields } from "../../fields/translatedFields/translatedFields";
|
||||
import { beforeDuplicateAddCopyTo } from "../../hooks/beforeDuplicateAddCopyTo";
|
||||
import { beforeDuplicatePiping } from "../../hooks/beforeDuplicatePiping";
|
||||
import { beforeDuplicateUnpublish } from "../../hooks/beforeDuplicateUnpublish";
|
||||
import { createEditor } from "../../utils/editor";
|
||||
import { buildVersionedCollectionConfig } from "../../utils/versionedCollectionConfig";
|
||||
import { Where } from "payload/types";
|
||||
import { getBySlugEndpoint } from "./endpoints/getBySlugEndpoint";
|
||||
import { Collections, CollectionGroups } from "../../shared/payload/constants";
|
||||
import { breakBlock } from "src/blocks/breakBlock";
|
||||
import { sectionBlock } from "src/blocks/sectionBlock";
|
||||
import { transcriptBlock } from "src/blocks/transcriptBlock";
|
||||
import { QuickFilters, publishStatusFilters } from "src/components/QuickFilters";
|
||||
import { attributesField } from "src/fields/attributesField/attributesField";
|
||||
import { backPropagationField } from "src/fields/backPropagationField/backPropagationField";
|
||||
import { creditsField } from "src/fields/creditsField/creditsField";
|
||||
import { imageField } from "src/fields/imageField/imageField";
|
||||
import { rowField } from "src/fields/rowField/rowField";
|
||||
import { slugField } from "src/fields/slugField/slugField";
|
||||
import { translatedFields } from "src/fields/translatedFields/translatedFields";
|
||||
import { beforeDuplicateAddCopyTo } from "src/hooks/beforeDuplicateAddCopyTo";
|
||||
import { beforeDuplicatePiping } from "src/hooks/beforeDuplicatePiping";
|
||||
import { beforeDuplicateUnpublish } from "src/hooks/beforeDuplicateUnpublish";
|
||||
import { Collections, CollectionGroups } from "src/shared/payload/constants";
|
||||
import { createEditor } from "src/utils/editor";
|
||||
import { buildVersionedCollectionConfig } from "src/utils/versionedCollectionConfig";
|
||||
|
||||
const fields = {
|
||||
slug: "slug",
|
||||
|
@ -29,7 +31,8 @@ const fields = {
|
|||
summary: "summary",
|
||||
content: "content",
|
||||
credits: "credits",
|
||||
sourceUrls: "sourceUrls",
|
||||
collectibles: "collectibles",
|
||||
folders: "folders",
|
||||
} as const satisfies Record<string, string>;
|
||||
|
||||
export const Pages = buildVersionedCollectionConfig({
|
||||
|
@ -41,7 +44,13 @@ export const Pages = buildVersionedCollectionConfig({
|
|||
defaultSort: fields.slug,
|
||||
admin: {
|
||||
useAsTitle: fields.slug,
|
||||
defaultColumns: [fields.slug, fields.thumbnail, fields.backgroundImage, fields.translations],
|
||||
defaultColumns: [
|
||||
fields.slug,
|
||||
fields.thumbnail,
|
||||
fields.backgroundImage,
|
||||
fields.translations,
|
||||
fields.folders,
|
||||
],
|
||||
group: CollectionGroups.Collections,
|
||||
preview: ({ slug }) => `${process.env.PAYLOAD_PUBLIC_FRONTEND_BASE_URL}/en/pages/${slug}`,
|
||||
components: {
|
||||
|
@ -114,18 +123,31 @@ export const Pages = buildVersionedCollectionConfig({
|
|||
}),
|
||||
},
|
||||
creditsField({ name: fields.credits }),
|
||||
{
|
||||
name: fields.sourceUrls,
|
||||
label: "Source URLs",
|
||||
type: "text",
|
||||
hasMany: true,
|
||||
admin: {
|
||||
description:
|
||||
"If the content originates from an external source (e.g: fandom.com, an online interview...) you can add a link to the original page(s) here",
|
||||
width: "50%",
|
||||
},
|
||||
},
|
||||
],
|
||||
}),
|
||||
rowField([
|
||||
backPropagationField({
|
||||
name: fields.folders,
|
||||
relationTo: Collections.Folders,
|
||||
hasMany: true,
|
||||
where: ({ id }) => ({
|
||||
and: [
|
||||
{ "files.value": { equals: id } },
|
||||
{ "files.relationTo": { equals: Collections.Pages } },
|
||||
] as Where[],
|
||||
}),
|
||||
}),
|
||||
backPropagationField({
|
||||
name: fields.collectibles,
|
||||
hasMany: true,
|
||||
relationTo: Collections.Collectibles,
|
||||
where: ({ id }) => ({
|
||||
and: [
|
||||
{ "contents.content.value": { equals: id } },
|
||||
{ "contents.content.relationTo": { equals: Collections.Pages } },
|
||||
] as Where[],
|
||||
}),
|
||||
}),
|
||||
]),
|
||||
],
|
||||
});
|
||||
|
|
|
@ -1,28 +1,26 @@
|
|||
import { createGetByEndpoint } from "../../../endpoints/createGetByEndpoint";
|
||||
import { findIncomingRelationships } from "payloadcms-relationships";
|
||||
import { Collections, BreakBlockType } from "../../../shared/payload/constants";
|
||||
import { convertRecorderToEndpointRecorderPreview } from "src/collections/Recorders/endpoints/getByID";
|
||||
import { createGetByEndpoint } from "src/endpoints/createGetByEndpoint";
|
||||
import { Collections, BreakBlockType } from "src/shared/payload/constants";
|
||||
import {
|
||||
EndpointPagePreview,
|
||||
EndpointPage,
|
||||
TableOfContentEntry,
|
||||
} from "../../../shared/payload/endpoint-types";
|
||||
} from "src/shared/payload/endpoint-types";
|
||||
import {
|
||||
RichTextContent,
|
||||
isNodeBlockNode,
|
||||
isBlockNodeSectionBlock,
|
||||
isBlockNodeBreakBlock,
|
||||
} from "../../../shared/payload/rich-text";
|
||||
import { Page } from "../../../types/collections";
|
||||
import { isImage, isNotEmpty, isPayloadType } from "../../../utils/asserts";
|
||||
} from "src/shared/payload/rich-text";
|
||||
import { Page } from "src/types/collections";
|
||||
import { isImage, isPayloadType, isNotEmpty } from "src/utils/asserts";
|
||||
import {
|
||||
convertAttributesToEndpointAttributes,
|
||||
convertCreditsToEndpointCredits,
|
||||
convertImageToEndpointPayloadImage,
|
||||
convertAttributesToEndpointAttributes,
|
||||
convertRTCToEndpointRTC,
|
||||
convertRelationshipsToEndpointRelations,
|
||||
getDomainFromUrl,
|
||||
} from "../../../utils/endpoints";
|
||||
import { convertRecorderToEndpointRecorderPreview } from "../../Recorders/endpoints/getByID";
|
||||
convertCreditsToEndpointCredits,
|
||||
convertSourceToEndpointSource,
|
||||
} from "src/utils/endpoints";
|
||||
|
||||
export const getBySlugEndpoint = createGetByEndpoint({
|
||||
collection: Collections.Pages,
|
||||
|
@ -51,8 +49,8 @@ export const convertPageToEndpointPagePreview = ({
|
|||
updatedAt,
|
||||
});
|
||||
|
||||
const convertPageToEndpointPage = async (page: Page): Promise<EndpointPage> => {
|
||||
const { translations, backgroundImage, createdAt, updatedBy, id } = page;
|
||||
const convertPageToEndpointPage = (page: Page): EndpointPage => {
|
||||
const { translations, collectibles, folders, backgroundImage, createdAt, updatedBy } = page;
|
||||
|
||||
return {
|
||||
...convertPageToEndpointPagePreview(page),
|
||||
|
@ -60,17 +58,7 @@ const convertPageToEndpointPage = async (page: Page): Promise<EndpointPage> => {
|
|||
? { backgroundImage: convertImageToEndpointPayloadImage(backgroundImage) }
|
||||
: {}),
|
||||
translations: translations.map(
|
||||
({
|
||||
content,
|
||||
language,
|
||||
sourceLanguage,
|
||||
title,
|
||||
pretitle,
|
||||
subtitle,
|
||||
summary,
|
||||
credits,
|
||||
sourceUrls,
|
||||
}) => ({
|
||||
({ content, language, sourceLanguage, title, pretitle, subtitle, summary, credits }) => ({
|
||||
language: isPayloadType(language) ? language.id : language,
|
||||
sourceLanguage: isPayloadType(sourceLanguage) ? sourceLanguage.id : sourceLanguage,
|
||||
...(isNotEmpty(pretitle) ? { pretitle } : {}),
|
||||
|
@ -80,20 +68,13 @@ const convertPageToEndpointPage = async (page: Page): Promise<EndpointPage> => {
|
|||
content: convertRTCToEndpointRTC(content),
|
||||
toc: handleToc(content),
|
||||
credits: convertCreditsToEndpointCredits(credits),
|
||||
sourceUrls:
|
||||
sourceUrls?.map((url) => ({
|
||||
url,
|
||||
label: getDomainFromUrl(url),
|
||||
})) ?? [],
|
||||
})
|
||||
),
|
||||
createdAt,
|
||||
...(isPayloadType(updatedBy)
|
||||
? { updatedBy: convertRecorderToEndpointRecorderPreview(updatedBy) }
|
||||
: {}),
|
||||
backlinks: convertRelationshipsToEndpointRelations(
|
||||
await findIncomingRelationships(Collections.Pages, id)
|
||||
),
|
||||
parentPages: convertSourceToEndpointSource({ collectibles, folders }),
|
||||
};
|
||||
};
|
||||
|
||||
|
|
|
@ -1,16 +1,16 @@
|
|||
import { mustBeAdmin as mustBeAdminForCollections } from "../../accesses/collections/mustBeAdmin";
|
||||
import { mustBeAdminOrSelf } from "../../accesses/collections/mustBeAdminOrSelf";
|
||||
import { mustBeAdmin as mustBeAdminForFields } from "../../accesses/fields/mustBeAdmin";
|
||||
import { QuickFilters } from "../../components/QuickFilters";
|
||||
import { imageField } from "../../fields/imageField/imageField";
|
||||
import { rowField } from "../../fields/rowField/rowField";
|
||||
import { translatedFields } from "../../fields/translatedFields/translatedFields";
|
||||
import { Collections, CollectionGroups, RecordersRoles } from "../../shared/payload/constants";
|
||||
import { buildCollectionConfig } from "../../utils/collectionConfig";
|
||||
import { createEditor } from "../../utils/editor";
|
||||
import { mustBeAdminOrSelf } from "src/accesses/collections/mustBeAdminOrSelf";
|
||||
import { QuickFilters } from "src/components/QuickFilters";
|
||||
import { imageField } from "src/fields/imageField/imageField";
|
||||
import { rowField } from "src/fields/rowField/rowField";
|
||||
import { translatedFields } from "src/fields/translatedFields/translatedFields";
|
||||
import { Collections, CollectionGroups, RecordersRoles } from "src/shared/payload/constants";
|
||||
import { buildCollectionConfig } from "src/utils/collectionConfig";
|
||||
import { createEditor } from "src/utils/editor";
|
||||
import { getByID } from "./endpoints/getByID";
|
||||
import { importFromStrapi } from "./endpoints/importFromStrapi";
|
||||
import { beforeLoginMustHaveAtLeastOneRole } from "./hooks/beforeLoginMustHaveAtLeastOneRole";
|
||||
import { mustBeAdmin as mustBeAdminForCollections } from "src/accesses/collections/mustBeAdmin";
|
||||
import { mustBeAdmin as mustBeAdminForFields } from "src/accesses/fields/mustBeAdmin";
|
||||
|
||||
const fields = {
|
||||
username: "username",
|
||||
|
|
|
@ -1,13 +1,10 @@
|
|||
import payload from "payload";
|
||||
import { Recorder } from "../../../types/collections";
|
||||
import { CollectionEndpoint } from "../../../types/payload";
|
||||
import { isImage, isPayloadType } from "../../../utils/asserts";
|
||||
import {
|
||||
convertImageToEndpointPayloadImage,
|
||||
convertRTCToEndpointRTC,
|
||||
} from "../../../utils/endpoints";
|
||||
import { Collections } from "../../../shared/payload/constants";
|
||||
import { EndpointRecorderPreview, EndpointRecorder } from "../../../shared/payload/endpoint-types";
|
||||
import { Collections } from "src/shared/payload/constants";
|
||||
import { EndpointRecorderPreview, EndpointRecorder } from "src/shared/payload/endpoint-types";
|
||||
import { Recorder } from "src/types/collections";
|
||||
import { CollectionEndpoint } from "src/types/payload";
|
||||
import { isPayloadType, isImage } from "src/utils/asserts";
|
||||
import { convertImageToEndpointPayloadImage, convertRTCToEndpointRTC } from "src/utils/endpoints";
|
||||
|
||||
export const getByID: CollectionEndpoint = {
|
||||
method: "get",
|
||||
|
|
|
@ -1,10 +1,10 @@
|
|||
import payload from "payload";
|
||||
import { createStrapiImportEndpoint } from "../../../endpoints/createStrapiImportEndpoint";
|
||||
import { Recorder } from "../../../types/collections";
|
||||
import { StrapiImage, StrapiLanguage } from "../../../types/strapi";
|
||||
import { isDefined } from "../../../utils/asserts";
|
||||
import { uploadStrapiImage } from "../../../utils/localApi";
|
||||
import { Collections } from "../../../shared/payload/constants";
|
||||
import { createStrapiImportEndpoint } from "src/endpoints/createStrapiImportEndpoint";
|
||||
import { Collections } from "src/shared/payload/constants";
|
||||
import { Recorder } from "src/types/collections";
|
||||
import { StrapiImage, StrapiLanguage } from "src/types/strapi";
|
||||
import { isDefined } from "src/utils/asserts";
|
||||
import { uploadStrapiImage } from "src/utils/localApi";
|
||||
|
||||
type StrapiRecorder = {
|
||||
username: string;
|
||||
|
|
|
@ -1,7 +1,7 @@
|
|||
import { shownOnlyToAdmin } from "../../accesses/collections/shownOnlyToAdmin";
|
||||
import { createImageSizesRegenerationEndpoint } from "../../endpoints/imageSizesRegenerationEndpoint";
|
||||
import { Collections } from "../../shared/payload/constants";
|
||||
import { buildImageCollectionConfig, generateWebpSize } from "../../utils/imageCollectionConfig";
|
||||
import { shownOnlyToAdmin } from "src/accesses/collections/shownOnlyToAdmin";
|
||||
import { createImageSizesRegenerationEndpoint } from "src/endpoints/imageSizesRegenerationEndpoint";
|
||||
import { Collections } from "src/shared/payload/constants";
|
||||
import { buildImageCollectionConfig, generateWebpSize } from "src/utils/imageCollectionConfig";
|
||||
|
||||
const fields = {
|
||||
filename: "filename",
|
||||
|
@ -17,7 +17,6 @@ export const Scans = buildImageCollectionConfig({
|
|||
plural: "Scans",
|
||||
},
|
||||
admin: {
|
||||
useAsTitle: fields.filename,
|
||||
defaultColumns: [fields.filename, fields.updatedAt],
|
||||
hidden: shownOnlyToAdmin,
|
||||
},
|
||||
|
|
|
@ -1,10 +1,10 @@
|
|||
import { CollectionConfig } from "payload/types";
|
||||
import { rowField } from "../../fields/rowField/rowField";
|
||||
import { slugField } from "../../fields/slugField/slugField";
|
||||
import { translatedFields } from "../../fields/translatedFields/translatedFields";
|
||||
import { beforeDuplicateAddCopyTo } from "../../hooks/beforeDuplicateAddCopyTo";
|
||||
import { buildCollectionConfig } from "../../utils/collectionConfig";
|
||||
import { Collections, CollectionGroups } from "../../shared/payload/constants";
|
||||
import { rowField } from "src/fields/rowField/rowField";
|
||||
import { slugField } from "src/fields/slugField/slugField";
|
||||
import { translatedFields } from "src/fields/translatedFields/translatedFields";
|
||||
import { beforeDuplicateAddCopyTo } from "src/hooks/beforeDuplicateAddCopyTo";
|
||||
import { Collections, CollectionGroups } from "src/shared/payload/constants";
|
||||
import { buildCollectionConfig } from "src/utils/collectionConfig";
|
||||
|
||||
const fields = {
|
||||
slug: "slug",
|
||||
|
|
|
@ -1,12 +1,14 @@
|
|||
import { attributesField } from "../../fields/attributesField/attributesField";
|
||||
import { componentField } from "../../fields/componentField/componentField";
|
||||
import { creditsField } from "../../fields/creditsField/creditsField";
|
||||
import { imageField } from "../../fields/imageField/imageField";
|
||||
import { rowField } from "../../fields/rowField/rowField";
|
||||
import { translatedFields } from "../../fields/translatedFields/translatedFields";
|
||||
import { Collections, CollectionGroups } from "../../shared/payload/constants";
|
||||
import { buildCollectionConfig } from "../../utils/collectionConfig";
|
||||
import { createEditor } from "../../utils/editor";
|
||||
import { attributesField } from "src/fields/attributesField/attributesField";
|
||||
import { componentField } from "src/fields/componentField/componentField";
|
||||
import { creditsField } from "src/fields/creditsField/creditsField";
|
||||
import { imageField } from "src/fields/imageField/imageField";
|
||||
import { rowField } from "src/fields/rowField/rowField";
|
||||
import { translatedFields } from "src/fields/translatedFields/translatedFields";
|
||||
import { Collections, CollectionGroups } from "src/shared/payload/constants";
|
||||
import { Video } from "src/types/collections";
|
||||
import { isPayloadType } from "src/utils/asserts";
|
||||
import { buildCollectionConfig } from "src/utils/collectionConfig";
|
||||
import { createEditor } from "src/utils/editor";
|
||||
import { getByID } from "./endpoints/getByID";
|
||||
|
||||
const fields = {
|
||||
|
@ -38,7 +40,6 @@ export const Videos = buildCollectionConfig({
|
|||
labels: { singular: "Video", plural: "Videos" },
|
||||
defaultSort: fields.filename,
|
||||
admin: {
|
||||
useAsTitle: fields.filename,
|
||||
group: CollectionGroups.Media,
|
||||
preview: ({ id }) => `${process.env.PAYLOAD_PUBLIC_FRONTEND_BASE_URL}/en/videos/${id}`,
|
||||
defaultColumns: [
|
||||
|
@ -128,4 +129,12 @@ export const Videos = buildCollectionConfig({
|
|||
],
|
||||
}),
|
||||
],
|
||||
custom: {
|
||||
getBackPropagatedRelationships: ({ platform, platformEnabled }: Video) => {
|
||||
if (!platform || !platformEnabled) {
|
||||
return [];
|
||||
}
|
||||
return [isPayloadType(platform.channel) ? platform.channel.id : platform.channel];
|
||||
},
|
||||
},
|
||||
});
|
||||
|
|
|
@ -1,30 +1,28 @@
|
|||
import payload from "payload";
|
||||
import { Video } from "../../../types/collections";
|
||||
import { CollectionEndpoint } from "../../../types/payload";
|
||||
import {
|
||||
isDefined,
|
||||
isEmpty,
|
||||
isMediaThumbnail,
|
||||
isNotEmpty,
|
||||
isPayloadType,
|
||||
isUndefined,
|
||||
isVideo,
|
||||
} from "../../../utils/asserts";
|
||||
import {
|
||||
convertAttributesToEndpointAttributes,
|
||||
convertCreditsToEndpointCredits,
|
||||
convertMediaThumbnailToEndpointPayloadImage,
|
||||
convertRTCToEndpointRTC,
|
||||
convertRelationshipsToEndpointRelations,
|
||||
getLanguageId,
|
||||
} from "../../../utils/endpoints";
|
||||
import { Collections } from "../../../shared/payload/constants";
|
||||
import { Collections } from "src/shared/payload/constants";
|
||||
import {
|
||||
PayloadMedia,
|
||||
EndpointVideoPreview,
|
||||
EndpointVideo,
|
||||
} from "../../../shared/payload/endpoint-types";
|
||||
import { findIncomingRelationships } from "payloadcms-relationships";
|
||||
} from "src/shared/payload/endpoint-types";
|
||||
import { Video } from "src/types/collections";
|
||||
import { CollectionEndpoint } from "src/types/payload";
|
||||
import {
|
||||
isVideo,
|
||||
isNotEmpty,
|
||||
isMediaThumbnail,
|
||||
isUndefined,
|
||||
isPayloadType,
|
||||
isEmpty,
|
||||
isDefined,
|
||||
} from "src/utils/asserts";
|
||||
import {
|
||||
convertAttributesToEndpointAttributes,
|
||||
getLanguageId,
|
||||
convertMediaThumbnailToEndpointPayloadImage,
|
||||
convertRTCToEndpointRTC,
|
||||
convertCreditsToEndpointCredits,
|
||||
} from "src/utils/endpoints";
|
||||
|
||||
export const getByID: CollectionEndpoint = {
|
||||
method: "get",
|
||||
|
@ -54,7 +52,7 @@ export const getByID: CollectionEndpoint = {
|
|||
return res.sendStatus(404);
|
||||
}
|
||||
|
||||
return res.status(200).json(await convertVideoToEndpointVideo(result));
|
||||
return res.status(200).json(convertVideoToEndpointVideo(result));
|
||||
} catch {
|
||||
return res.sendStatus(404);
|
||||
}
|
||||
|
@ -100,8 +98,8 @@ export const convertVideoToEndpointVideoPreview = ({
|
|||
}) ?? [],
|
||||
});
|
||||
|
||||
const convertVideoToEndpointVideo = async (video: Video & PayloadMedia): Promise<EndpointVideo> => {
|
||||
const { translations, createdAt, updatedAt, filesize, platform, platformEnabled, credits, id } =
|
||||
const convertVideoToEndpointVideo = (video: Video & PayloadMedia): EndpointVideo => {
|
||||
const { translations, createdAt, updatedAt, filesize, platform, platformEnabled, credits } =
|
||||
video;
|
||||
|
||||
return {
|
||||
|
@ -127,8 +125,5 @@ const convertVideoToEndpointVideo = async (video: Video & PayloadMedia): Promise
|
|||
}
|
||||
: {}),
|
||||
credits: convertCreditsToEndpointCredits(credits),
|
||||
backlinks: convertRelationshipsToEndpointRelations(
|
||||
await findIncomingRelationships(Collections.Videos, id)
|
||||
),
|
||||
};
|
||||
};
|
||||
|
|
|
@ -1,7 +1,8 @@
|
|||
import { CollectionConfig } from "payload/types";
|
||||
import { rowField } from "../../fields/rowField/rowField";
|
||||
import { buildCollectionConfig } from "../../utils/collectionConfig";
|
||||
import { Collections, CollectionGroups } from "../../shared/payload/constants";
|
||||
import { backPropagationField } from "src/fields/backPropagationField/backPropagationField";
|
||||
import { rowField } from "src/fields/rowField/rowField";
|
||||
import { Collections, CollectionGroups } from "src/shared/payload/constants";
|
||||
import { buildCollectionConfig } from "src/utils/collectionConfig";
|
||||
|
||||
const fields = {
|
||||
url: "url",
|
||||
|
@ -30,5 +31,11 @@ export const VideosChannels: CollectionConfig = buildCollectionConfig({
|
|||
{ name: fields.title, type: "text", required: true },
|
||||
{ name: fields.subscribers, type: "number", required: true },
|
||||
]),
|
||||
backPropagationField({
|
||||
name: fields.videos,
|
||||
relationTo: Collections.Videos,
|
||||
hasMany: true,
|
||||
where: ({ id }) => ({ "platform.channel": { equals: id } }),
|
||||
}),
|
||||
],
|
||||
});
|
||||
|
|
|
@ -1,18 +1,13 @@
|
|||
import { shownOnlyToAdmin } from "../../accesses/collections/shownOnlyToAdmin";
|
||||
import { Collections, CollectionGroups } from "../../shared/payload/constants";
|
||||
import { buildCollectionConfig } from "../../utils/collectionConfig";
|
||||
import { shownOnlyToAdmin } from "src/accesses/collections/shownOnlyToAdmin";
|
||||
import { Collections, CollectionGroups } from "src/shared/payload/constants";
|
||||
import { buildCollectionConfig } from "src/utils/collectionConfig";
|
||||
|
||||
export const VideosSubtitles = buildCollectionConfig({
|
||||
slug: Collections.VideosSubtitles,
|
||||
labels: { singular: "Video Subtitle", plural: "Videos Subtitles" },
|
||||
admin: {
|
||||
useAsTitle: "filename",
|
||||
group: CollectionGroups.Media,
|
||||
disableDuplicate: true,
|
||||
hidden: shownOnlyToAdmin,
|
||||
},
|
||||
admin: { group: CollectionGroups.Media, disableDuplicate: true, hidden: shownOnlyToAdmin },
|
||||
upload: {
|
||||
// mimeTypes: ["text/*"], Disable because of a bug on Chrome windows where the MIME is detected as application/octet-stream instead of text/vtt or text/plain
|
||||
mimeTypes: ["text/*"],
|
||||
disableLocalStorage: true,
|
||||
},
|
||||
timestamps: false,
|
||||
|
|
|
@ -1,10 +1,10 @@
|
|||
import { GlobalConfig } from "payload/types";
|
||||
import { mustBeAdmin } from "../../accesses/collections/mustBeAdmin";
|
||||
import { imageField } from "../../fields/imageField/imageField";
|
||||
import { rowField } from "../../fields/rowField/rowField";
|
||||
import { getConfigEndpoint } from "./endpoints/getConfigEndpoint";
|
||||
import { Collections, CollectionGroups } from "../../shared/payload/constants";
|
||||
import { globalAfterChangeSendChangesWebhook } from "../../hooks/afterOperationSendChangesWebhook";
|
||||
import { mustBeAdmin } from "src/accesses/fields/mustBeAdmin";
|
||||
import { imageField } from "src/fields/imageField/imageField";
|
||||
import { rowField } from "src/fields/rowField/rowField";
|
||||
import { globalAfterChangeWebhook } from "src/hooks/afterOperationWebhook";
|
||||
import { Collections, CollectionGroups } from "src/shared/payload/constants";
|
||||
|
||||
const fields = {
|
||||
homeBackgroundImage: "homeBackgroundImage",
|
||||
|
@ -32,7 +32,7 @@ export const WebsiteConfig: GlobalConfig = {
|
|||
access: { update: mustBeAdmin, read: mustBeAdmin },
|
||||
endpoints: [getConfigEndpoint],
|
||||
hooks: {
|
||||
afterChange: [globalAfterChangeSendChangesWebhook],
|
||||
afterChange: [globalAfterChangeWebhook],
|
||||
},
|
||||
fields: [
|
||||
rowField([
|
||||
|
|
|
@ -1,10 +1,10 @@
|
|||
import payload from "payload";
|
||||
import { CollectionEndpoint } from "../../../types/payload";
|
||||
import { isImage, isPayloadType } from "../../../utils/asserts";
|
||||
import { convertImageToEndpointPayloadImage } from "../../../utils/endpoints";
|
||||
import { convertFolderToEndpointFolderPreview } from "../../Folders/endpoints/getBySlugEndpoint";
|
||||
import { Collections } from "../../../shared/payload/constants";
|
||||
import { EndpointWebsiteConfig } from "../../../shared/payload/endpoint-types";
|
||||
import { convertFolderToEndpointFolderPreview } from "src/collections/Folders/endpoints/getBySlugEndpoint";
|
||||
import { Collections } from "src/shared/payload/constants";
|
||||
import { EndpointWebsiteConfig } from "src/shared/payload/endpoint-types";
|
||||
import { CollectionEndpoint } from "src/types/payload";
|
||||
import { isImage, isPayloadType } from "src/utils/asserts";
|
||||
import { convertImageToEndpointPayloadImage } from "src/utils/endpoints";
|
||||
|
||||
export const getConfigEndpoint: CollectionEndpoint = {
|
||||
method: "get",
|
||||
|
|
|
@ -1,12 +1,12 @@
|
|||
import { CollectionConfig } from "payload/types";
|
||||
import { mustBeAdmin } from "../../accesses/collections/mustBeAdmin";
|
||||
import { QuickFilters, languageBasedFilters } from "../../components/QuickFilters";
|
||||
import { rowField } from "../../fields/rowField/rowField";
|
||||
import { translatedFields } from "../../fields/translatedFields/translatedFields";
|
||||
import { beforeDuplicateAddCopyTo } from "../../hooks/beforeDuplicateAddCopyTo";
|
||||
import { buildCollectionConfig } from "../../utils/collectionConfig";
|
||||
import { getAllEndpoint } from "./endpoints/getAllEndpoint";
|
||||
import { Collections, CollectionGroups } from "../../shared/payload/constants";
|
||||
import { mustBeAdmin } from "src/accesses/fields/mustBeAdmin";
|
||||
import { QuickFilters, languageBasedFilters } from "src/components/QuickFilters";
|
||||
import { rowField } from "src/fields/rowField/rowField";
|
||||
import { translatedFields } from "src/fields/translatedFields/translatedFields";
|
||||
import { beforeDuplicateAddCopyTo } from "src/hooks/beforeDuplicateAddCopyTo";
|
||||
import { Collections, CollectionGroups } from "src/shared/payload/constants";
|
||||
import { buildCollectionConfig } from "src/utils/collectionConfig";
|
||||
|
||||
const fields = {
|
||||
name: "name",
|
||||
|
|
|
@ -1,8 +1,8 @@
|
|||
import payload from "payload";
|
||||
import { CollectionEndpoint } from "../../../types/payload";
|
||||
import { isPayloadType } from "../../../utils/asserts";
|
||||
import { Collections } from "../../../shared/payload/constants";
|
||||
import { EndpointWording } from "../../../shared/payload/endpoint-types";
|
||||
import { Collections } from "src/shared/payload/constants";
|
||||
import { EndpointWording } from "src/shared/payload/endpoint-types";
|
||||
import { CollectionEndpoint } from "src/types/payload";
|
||||
import { isPayloadType } from "src/utils/asserts";
|
||||
|
||||
export const getAllEndpoint: CollectionEndpoint = {
|
||||
method: "get",
|
||||
|
|
|
@ -2,8 +2,8 @@ import { Options } from "payload/dist/collections/operations/local/find";
|
|||
import QueryString from "qs";
|
||||
import React from "react";
|
||||
import { Link } from "react-router-dom";
|
||||
import { LanguageCodes } from "src/shared/payload/constants";
|
||||
import styled from "styled-components";
|
||||
import { LanguageCodes } from "../shared/payload/constants";
|
||||
|
||||
type Props = {
|
||||
slug: string;
|
||||
|
|
|
@ -1,6 +1,6 @@
|
|||
import payload, { GeneratedTypes } from "payload";
|
||||
import { CollectionEndpoint } from "../types/payload";
|
||||
import { isPublished } from "../utils/asserts";
|
||||
import { CollectionEndpoint } from "src/types/payload";
|
||||
import { isPublished } from "src/utils/asserts";
|
||||
|
||||
interface Params<C extends keyof GeneratedTypes["collections"], R> {
|
||||
collection: C;
|
||||
|
|
|
@ -1,8 +1,8 @@
|
|||
import payload, { GeneratedTypes } from "payload";
|
||||
import QueryString from "qs";
|
||||
import { Recorder } from "../types/collections";
|
||||
import { CollectionEndpoint } from "../types/payload";
|
||||
import { isDefined } from "../utils/asserts";
|
||||
import { Recorder } from "src/types/collections";
|
||||
import { CollectionEndpoint } from "src/types/payload";
|
||||
import { isDefined } from "src/utils/asserts";
|
||||
|
||||
const getAllStrapiEntries = async (collectionSlug: string, params: Object): Promise<any[]> => {
|
||||
let page = 1;
|
||||
|
|
|
@ -1,27 +1,11 @@
|
|||
import payload from "payload";
|
||||
import { Endpoint } from "payload/config";
|
||||
import { Collections } from "../shared/payload/constants";
|
||||
import { EndpointChange } from "../shared/payload/webhooks";
|
||||
import {
|
||||
getEndpointChangesForAudio,
|
||||
getEndpointChangesForChronologyEvent,
|
||||
getEndpointChangesForCollectible,
|
||||
getEndpointChangesForCurrency,
|
||||
getEndpointChangesForFile,
|
||||
getEndpointChangesForFolder,
|
||||
getEndpointChangesForImage,
|
||||
getEndpointChangesForLanguage,
|
||||
getEndpointChangesForPage,
|
||||
getEndpointChangesForRecorder,
|
||||
getEndpointChangesForVideo,
|
||||
getEndpointChangesForWebsiteConfig,
|
||||
getEndpointChangesForWording,
|
||||
} from "../hooks/afterOperationSendChangesWebhook";
|
||||
import { uniqueBy } from "../utils/array";
|
||||
import { Collections } from "src/shared/payload/constants";
|
||||
import { EndpointAllIds } from "src/shared/payload/endpoint-types";
|
||||
|
||||
export const getAllEndpoint: Endpoint = {
|
||||
export const getAllIds: Endpoint = {
|
||||
method: "get",
|
||||
path: "/all",
|
||||
path: "/all-ids",
|
||||
handler: async (req, res) => {
|
||||
if (!req.user) {
|
||||
return res.status(403).send({
|
||||
|
@ -111,22 +95,18 @@ export const getAllEndpoint: Endpoint = {
|
|||
},
|
||||
});
|
||||
|
||||
const result: EndpointChange[] = [
|
||||
...getEndpointChangesForWebsiteConfig(),
|
||||
...getEndpointChangesForLanguage(),
|
||||
...getEndpointChangesForCurrency(),
|
||||
...getEndpointChangesForWording(),
|
||||
...folders.docs.flatMap(getEndpointChangesForFolder),
|
||||
...pages.docs.flatMap(getEndpointChangesForPage),
|
||||
...collectibles.docs.flatMap(getEndpointChangesForCollectible),
|
||||
...audios.docs.flatMap(getEndpointChangesForAudio),
|
||||
...images.docs.flatMap(getEndpointChangesForImage),
|
||||
...videos.docs.flatMap(getEndpointChangesForVideo),
|
||||
...files.docs.flatMap(getEndpointChangesForFile),
|
||||
...recorders.docs.flatMap(getEndpointChangesForRecorder),
|
||||
...chronologyEvents.docs.flatMap(getEndpointChangesForChronologyEvent),
|
||||
];
|
||||
const result: EndpointAllIds = {
|
||||
collectibles: { slugs: collectibles.docs.map(({ slug }) => slug) },
|
||||
pages: { slugs: pages.docs.map(({ slug }) => slug) },
|
||||
folders: { slugs: folders.docs.map(({ slug }) => slug) },
|
||||
videos: { ids: videos.docs.map(({ id }) => id) },
|
||||
audios: { ids: audios.docs.map(({ id }) => id) },
|
||||
images: { ids: images.docs.map(({ id }) => id) },
|
||||
files: { ids: files.docs.map(({ id }) => id) },
|
||||
recorders: { ids: recorders.docs.map(({ id }) => id) },
|
||||
chronologyEvents: { ids: chronologyEvents.docs.map(({ id }) => id) },
|
||||
};
|
||||
|
||||
return res.status(200).send(uniqueBy(result, ({ url }) => url));
|
||||
return res.status(200).send(result);
|
||||
},
|
||||
};
|
|
@ -0,0 +1,208 @@
|
|||
import payload from "payload";
|
||||
import { Endpoint } from "payload/config";
|
||||
import { Collections } from "src/shared/payload/constants";
|
||||
import { EndpointAllSDKUrls } from "src/shared/payload/endpoint-types";
|
||||
import { getSDKEndpoint } from "src/shared/payload/sdk";
|
||||
import { Collectible } from "src/types/collections";
|
||||
|
||||
export const getAllSDKUrlsEndpoint: Endpoint = {
|
||||
method: "get",
|
||||
path: "/all-sdk-urls",
|
||||
handler: async (req, res) => {
|
||||
if (!req.user) {
|
||||
return res.status(403).send({
|
||||
errors: [
|
||||
{
|
||||
message: "You are not allowed to perform this action.",
|
||||
},
|
||||
],
|
||||
});
|
||||
}
|
||||
|
||||
const collectibles = await payload.find({
|
||||
collection: Collections.Collectibles,
|
||||
depth: 0,
|
||||
pagination: false,
|
||||
user: req.user,
|
||||
where: {
|
||||
_status: {
|
||||
equals: "published",
|
||||
},
|
||||
},
|
||||
});
|
||||
|
||||
const pages = await payload.find({
|
||||
collection: Collections.Pages,
|
||||
depth: 0,
|
||||
pagination: false,
|
||||
user: req.user,
|
||||
where: {
|
||||
_status: {
|
||||
equals: "published",
|
||||
},
|
||||
},
|
||||
});
|
||||
|
||||
const folders = await payload.find({
|
||||
collection: Collections.Folders,
|
||||
depth: 0,
|
||||
pagination: false,
|
||||
user: req.user,
|
||||
});
|
||||
|
||||
const videos = await payload.find({
|
||||
collection: Collections.Videos,
|
||||
depth: 0,
|
||||
pagination: false,
|
||||
user: req.user,
|
||||
});
|
||||
|
||||
const audios = await payload.find({
|
||||
collection: Collections.Audios,
|
||||
depth: 0,
|
||||
pagination: false,
|
||||
user: req.user,
|
||||
});
|
||||
|
||||
const images = await payload.find({
|
||||
collection: Collections.Images,
|
||||
depth: 0,
|
||||
pagination: false,
|
||||
user: req.user,
|
||||
});
|
||||
|
||||
const files = await payload.find({
|
||||
collection: Collections.Files,
|
||||
depth: 0,
|
||||
pagination: false,
|
||||
user: req.user,
|
||||
});
|
||||
|
||||
const recorders = await payload.find({
|
||||
collection: Collections.Recorders,
|
||||
depth: 0,
|
||||
pagination: false,
|
||||
user: req.user,
|
||||
});
|
||||
|
||||
const chronologyEvents = await payload.find({
|
||||
collection: Collections.ChronologyEvents,
|
||||
depth: 0,
|
||||
pagination: false,
|
||||
user: req.user,
|
||||
where: {
|
||||
_status: {
|
||||
equals: "published",
|
||||
},
|
||||
},
|
||||
});
|
||||
|
||||
const urls = new Set([
|
||||
getSDKEndpoint.getConfigEndpoint(),
|
||||
getSDKEndpoint.getLanguagesEndpoint(),
|
||||
getSDKEndpoint.getCurrenciesEndpoint(),
|
||||
getSDKEndpoint.getWordingsEndpoint(),
|
||||
|
||||
...folders.docs.flatMap((doc) => getSDKUrlsForDocument(Collections.Folders, doc)),
|
||||
...pages.docs.flatMap((doc) => getSDKUrlsForDocument(Collections.Pages, doc)),
|
||||
...chronologyEvents.docs.flatMap((doc) =>
|
||||
getSDKUrlsForDocument(Collections.ChronologyEvents, doc)
|
||||
),
|
||||
...videos.docs.flatMap((doc) => getSDKUrlsForDocument(Collections.Videos, doc)),
|
||||
...audios.docs.flatMap((doc) => getSDKUrlsForDocument(Collections.Audios, doc)),
|
||||
...images.docs.flatMap((doc) => getSDKUrlsForDocument(Collections.Images, doc)),
|
||||
...files.docs.flatMap((doc) => getSDKUrlsForDocument(Collections.Files, doc)),
|
||||
...collectibles.docs.flatMap((doc) => getSDKUrlsForDocument(Collections.Collectibles, doc)),
|
||||
...recorders.docs.flatMap((doc) => getSDKUrlsForDocument(Collections.Recorders, doc)),
|
||||
]);
|
||||
|
||||
const result: EndpointAllSDKUrls = {
|
||||
urls: [...urls],
|
||||
};
|
||||
|
||||
return res.status(200).send(result);
|
||||
},
|
||||
};
|
||||
|
||||
export const getSDKUrlsForDocument = (collection: Collections, doc: any): string[] => {
|
||||
switch (collection) {
|
||||
case Collections.WebsiteConfig:
|
||||
return [getSDKEndpoint.getConfigEndpoint()];
|
||||
|
||||
case Collections.Folders:
|
||||
return [getSDKEndpoint.getFolderEndpoint(doc.slug)];
|
||||
|
||||
case Collections.Languages:
|
||||
return [getSDKEndpoint.getLanguagesEndpoint()];
|
||||
|
||||
case Collections.Currencies:
|
||||
return [getSDKEndpoint.getCurrenciesEndpoint()];
|
||||
|
||||
case Collections.Wordings:
|
||||
return [getSDKEndpoint.getWordingsEndpoint()];
|
||||
|
||||
case Collections.Pages:
|
||||
return [getSDKEndpoint.getPageEndpoint(doc.slug)];
|
||||
|
||||
case Collections.Collectibles: {
|
||||
const { slug, gallery, scans, scansEnabled } = doc as Collectible;
|
||||
const urls: string[] = [getSDKEndpoint.getCollectibleEndpoint(slug)];
|
||||
if (gallery && gallery.length > 0) {
|
||||
urls.push(getSDKEndpoint.getCollectibleGalleryEndpoint(slug));
|
||||
urls.push(
|
||||
...gallery.map((_, index) =>
|
||||
getSDKEndpoint.getCollectibleGalleryImageEndpoint(slug, index.toString())
|
||||
)
|
||||
);
|
||||
}
|
||||
if (scans && scansEnabled) {
|
||||
urls.push(getSDKEndpoint.getCollectibleScansEndpoint(slug));
|
||||
// TODO: Add other pages for cover, obi, dustjacket...
|
||||
if (scans.pages) {
|
||||
urls.push(
|
||||
...scans.pages.map(({ page }) =>
|
||||
getSDKEndpoint.getCollectibleScanPageEndpoint(slug, page.toString())
|
||||
)
|
||||
);
|
||||
}
|
||||
}
|
||||
return urls;
|
||||
}
|
||||
|
||||
case Collections.ChronologyEvents:
|
||||
return [
|
||||
getSDKEndpoint.getChronologyEventsEndpoint(),
|
||||
getSDKEndpoint.getChronologyEventByIDEndpoint(doc.id),
|
||||
];
|
||||
|
||||
case Collections.Images:
|
||||
return [getSDKEndpoint.getImageByIDEndpoint(doc.id)];
|
||||
|
||||
case Collections.Audios:
|
||||
return [getSDKEndpoint.getAudioByIDEndpoint(doc.id)];
|
||||
|
||||
case Collections.Videos:
|
||||
return [getSDKEndpoint.getVideoByIDEndpoint(doc.id)];
|
||||
|
||||
case Collections.Recorders:
|
||||
return [getSDKEndpoint.getRecorderByIDEndpoint(doc.id)];
|
||||
|
||||
case Collections.Files:
|
||||
return [getSDKEndpoint.getFileByIDEndpoint(doc.id)];
|
||||
|
||||
case Collections.Attributes:
|
||||
case Collections.CreditsRole:
|
||||
case Collections.GenericContents:
|
||||
case Collections.MediaThumbnails:
|
||||
case Collections.Scans:
|
||||
case Collections.Tags:
|
||||
case Collections.VideosChannels:
|
||||
case Collections.VideosSubtitles:
|
||||
return [];
|
||||
|
||||
default: {
|
||||
console.warn("Unrecognized collection", collection);
|
||||
return [];
|
||||
}
|
||||
}
|
||||
};
|
|
@ -1,5 +1,5 @@
|
|||
import payload from "payload";
|
||||
import { CollectionEndpoint } from "../types/payload";
|
||||
import { CollectionEndpoint } from "src/types/payload";
|
||||
|
||||
export const createImageSizesRegenerationEndpoint = (
|
||||
collection: "images" | "scans" | "media-thumbnails"
|
||||
|
|
|
@ -1,7 +1,7 @@
|
|||
import { BlockField } from "payload/dist/fields/config/types";
|
||||
import { numberBlock } from "../../blocks/attributeBlocks/numberBlock";
|
||||
import { tagsBlock } from "../../blocks/attributeBlocks/tagsBlock";
|
||||
import { textBlock } from "../../blocks/attributeBlocks/textBlock";
|
||||
import { numberBlock } from "src/blocks/attributeBlocks/numberBlock";
|
||||
import { tagsBlock } from "src/blocks/attributeBlocks/tagsBlock";
|
||||
import { textBlock } from "src/blocks/attributeBlocks/textBlock";
|
||||
|
||||
type AttributesFieldProps = Omit<BlockField, "type" | "blocks">;
|
||||
|
||||
|
|
|
@ -0,0 +1,51 @@
|
|||
import payload, { GeneratedTypes } from "payload";
|
||||
import { FieldBase, SingleRelationshipField } from "payload/dist/fields/config/types";
|
||||
import { Where } from "payload/types";
|
||||
import { isEmpty } from "src/utils/asserts";
|
||||
|
||||
type BackPropagationField = FieldBase & {
|
||||
where: (data: any) => Where;
|
||||
relationTo: keyof GeneratedTypes["collections"];
|
||||
hasMany?: boolean;
|
||||
};
|
||||
export const backPropagationField = ({
|
||||
admin,
|
||||
hooks: { beforeChange = [], afterRead = [], ...otherHooks } = {},
|
||||
where,
|
||||
hasMany = false,
|
||||
...params
|
||||
}: BackPropagationField): SingleRelationshipField => ({
|
||||
...params,
|
||||
type: "relationship",
|
||||
hasMany: hasMany,
|
||||
admin: { ...admin, readOnly: true },
|
||||
hooks: {
|
||||
...otherHooks,
|
||||
beforeChange: [
|
||||
...beforeChange,
|
||||
({ siblingData }) => {
|
||||
delete siblingData[params.name];
|
||||
},
|
||||
],
|
||||
afterRead: [
|
||||
...afterRead,
|
||||
async ({ data, context }) => {
|
||||
if (isEmpty(data?.id) || context.stopPropagation) {
|
||||
return hasMany ? [] : undefined;
|
||||
}
|
||||
const result = await payload.find({
|
||||
collection: params.relationTo,
|
||||
where: where(data),
|
||||
limit: 100,
|
||||
depth: 0,
|
||||
context: { stopPropagation: true },
|
||||
});
|
||||
if (hasMany) {
|
||||
return result.docs.map((doc) => doc.id);
|
||||
} else {
|
||||
return result.docs[0]?.id;
|
||||
}
|
||||
},
|
||||
],
|
||||
},
|
||||
});
|
|
@ -0,0 +1,47 @@
|
|||
import payload, { GeneratedTypes } from "payload";
|
||||
import { SanitizedCollectionConfig, SanitizedGlobalConfig } from "payload/types";
|
||||
|
||||
export const getAddedBackPropagationRelationships = async (
|
||||
config: SanitizedCollectionConfig | SanitizedGlobalConfig,
|
||||
doc: any,
|
||||
previousDoc?: any
|
||||
): Promise<string[]> => {
|
||||
if (!("getBackPropagatedRelationships" in config.custom)) {
|
||||
return [];
|
||||
}
|
||||
|
||||
const getBackPropagatedRelationships: (doc: any) => string[] =
|
||||
config.custom.getBackPropagatedRelationships;
|
||||
|
||||
if (!previousDoc) {
|
||||
return getBackPropagatedRelationships(doc);
|
||||
}
|
||||
|
||||
let currentIds: string[];
|
||||
let previousIds: string[];
|
||||
|
||||
if (config.versions.drafts) {
|
||||
const versions = await payload.findVersions({
|
||||
collection: config.slug as keyof GeneratedTypes["collections"],
|
||||
sort: "-updatedAt",
|
||||
limit: 2,
|
||||
where: {
|
||||
and: [{ parent: { equals: doc.id } }, { "version._status": { equals: "published" } }],
|
||||
},
|
||||
});
|
||||
|
||||
const currentVersion = versions.docs[0]?.version;
|
||||
const previousVersion = versions.docs[1]?.version;
|
||||
|
||||
if (!currentVersion) return [];
|
||||
if (!previousVersion) return getBackPropagatedRelationships(currentVersion);
|
||||
|
||||
currentIds = getBackPropagatedRelationships(currentVersion);
|
||||
previousIds = getBackPropagatedRelationships(previousVersion);
|
||||
} else {
|
||||
currentIds = getBackPropagatedRelationships(doc);
|
||||
previousIds = getBackPropagatedRelationships(previousDoc);
|
||||
}
|
||||
|
||||
return currentIds.filter((id) => !previousIds.includes(id));
|
||||
};
|
|
@ -1,5 +1,5 @@
|
|||
import { CollapsibleField, Condition, Field } from "payload/types";
|
||||
import { capitalize } from "../../utils/string";
|
||||
import { capitalize } from "src/utils/string";
|
||||
|
||||
type Props = {
|
||||
name: string;
|
||||
|
|
|
@ -1,9 +1,9 @@
|
|||
import { array } from "payload/dist/fields/validations";
|
||||
import { ArrayField } from "payload/types";
|
||||
import { Credits } from "../../types/collections";
|
||||
import { hasDuplicates, isDefined, isPayloadType, isUndefined } from "../../utils/asserts";
|
||||
import { rowField } from "../rowField/rowField";
|
||||
import { Collections } from "../../shared/payload/constants";
|
||||
import { rowField } from "src/fields/rowField/rowField";
|
||||
import { Collections } from "src/shared/payload/constants";
|
||||
import { Credits } from "src/types/collections";
|
||||
import { isDefined, isUndefined, isPayloadType, hasDuplicates } from "src/utils/asserts";
|
||||
|
||||
type Props = Omit<ArrayField, "type" | "fields">;
|
||||
|
||||
|
|
|
@ -1,6 +1,6 @@
|
|||
import { icons } from "@iconify-json/material-symbols";
|
||||
import { TextField } from "payload/types";
|
||||
import { isEmpty } from "../../utils/asserts";
|
||||
import { isEmpty } from "src/utils/asserts";
|
||||
|
||||
type Props = Omit<TextField, "type" | "hasMany" | "maxRows" | "minRows">;
|
||||
|
||||
|
|
|
@ -1,7 +1,7 @@
|
|||
import { Props } from "payload/components/views/Cell";
|
||||
import React, { useEffect, useMemo, useState } from "react";
|
||||
import { Link } from "react-router-dom";
|
||||
import { isUndefined } from "../../utils/asserts";
|
||||
import { isUndefined } from "src/utils/asserts";
|
||||
|
||||
export const Cell = ({ cellData, field, rowData, collection }: Props): JSX.Element => {
|
||||
const [imageURL, setImageURL] = useState<string>();
|
||||
|
|
|
@ -1,5 +1,5 @@
|
|||
import { TextField } from "payload/types";
|
||||
import { isUndefined } from "../../utils/asserts";
|
||||
import { isUndefined } from "src/utils/asserts";
|
||||
|
||||
type Props = Omit<TextField, "type" | "hasMany" | "minRows" | "maxRows">;
|
||||
|
||||
|
|
|
@ -1,7 +1,7 @@
|
|||
import React from "react";
|
||||
import { Language } from "../../types/collections";
|
||||
import { isDefined } from "../../utils/asserts";
|
||||
import { formatLanguageCode } from "../../utils/string";
|
||||
import { Language } from "src/types/collections";
|
||||
import { isDefined } from "src/utils/asserts";
|
||||
import { formatLanguageCode } from "src/utils/string";
|
||||
|
||||
interface Props {
|
||||
cellData: { language?: string | Language; title?: string }[];
|
||||
|
|
|
@ -1,8 +1,8 @@
|
|||
import React from "react";
|
||||
import { Language } from "src/types/collections";
|
||||
import { isDefined } from "src/utils/asserts";
|
||||
import { formatLanguageCode, shortenEllipsis } from "src/utils/string";
|
||||
import styled from "styled-components";
|
||||
import { Language } from "../../types/collections";
|
||||
import { isDefined } from "../../utils/asserts";
|
||||
import { formatLanguageCode, shortenEllipsis } from "../../utils/string";
|
||||
|
||||
interface Props {
|
||||
language?: Language | string;
|
||||
|
|
|
@ -1,11 +1,11 @@
|
|||
import { RowLabelArgs } from "payload/dist/admin/components/forms/RowLabel/types";
|
||||
import { array } from "payload/dist/fields/validations";
|
||||
import { ArrayField, Field } from "payload/types";
|
||||
import { hasDuplicates, isDefined, isUndefined } from "../../utils/asserts";
|
||||
import { rowField } from "../rowField/rowField";
|
||||
import { Cell } from "./Cell";
|
||||
import { RowLabel } from "./RowLabel";
|
||||
import { Collections } from "../../shared/payload/constants";
|
||||
import { rowField } from "src/fields/rowField/rowField";
|
||||
import { Collections } from "src/shared/payload/constants";
|
||||
import { isDefined, isUndefined, hasDuplicates } from "src/utils/asserts";
|
||||
|
||||
const fieldsNames = {
|
||||
language: "language",
|
||||
|
|
|
@ -1,432 +0,0 @@
|
|||
import { Collections } from "../shared/payload/constants";
|
||||
import { SDKEndpointNames, getSDKEndpoint } from "../shared/payload/sdk";
|
||||
import { EndpointChange } from "../shared/payload/webhooks";
|
||||
import {
|
||||
Audio,
|
||||
ChronologyEvent,
|
||||
Collectible,
|
||||
File,
|
||||
Folder,
|
||||
Image,
|
||||
Page,
|
||||
Recorder,
|
||||
Relationship,
|
||||
Video,
|
||||
} from "../types/collections";
|
||||
import { isDefined, isPayloadType } from "../utils/asserts";
|
||||
import {
|
||||
AfterChangeHook,
|
||||
AfterDeleteHook,
|
||||
BeforeChangeHook,
|
||||
BeforeDeleteHook,
|
||||
} from "payload/dist/collections/config/types";
|
||||
import { GeneratedTypes } from "payload";
|
||||
import { uniqueBy } from "../utils/array";
|
||||
import { GlobalAfterChangeHook } from "payload/types";
|
||||
import { findRelationByID } from "payloadcms-relationships/dist/utils";
|
||||
|
||||
export const beforeChangePrepareChanges: BeforeChangeHook = async ({
|
||||
collection,
|
||||
originalDoc,
|
||||
context,
|
||||
data,
|
||||
}) => {
|
||||
if ("_status" in data && data._status === "draft") return data;
|
||||
if (!originalDoc) return data;
|
||||
|
||||
context.beforeChangeChanges = await getChanges(
|
||||
collection.slug as keyof GeneratedTypes["collections"],
|
||||
originalDoc
|
||||
);
|
||||
|
||||
return data;
|
||||
};
|
||||
|
||||
export const afterChangeSendChangesWebhook: AfterChangeHook = async ({
|
||||
doc,
|
||||
collection,
|
||||
context,
|
||||
}) => {
|
||||
if ("_status" in doc && doc._status === "draft") return doc;
|
||||
|
||||
const changes = await getChanges(collection.slug as keyof GeneratedTypes["collections"], doc);
|
||||
const previousChanges = context.beforeChangeChanges as EndpointChange[] | undefined;
|
||||
|
||||
if (isDefined(previousChanges)) {
|
||||
await sendWebhookMessage(uniqueBy([...previousChanges, ...changes], ({ url }) => url));
|
||||
} else {
|
||||
await sendWebhookMessage(changes);
|
||||
}
|
||||
|
||||
return doc;
|
||||
};
|
||||
|
||||
export const beforeDeletePrepareChanges: BeforeDeleteHook = async ({ id, collection, context }) => {
|
||||
context.beforeDeleteChanges = await getChanges(
|
||||
collection.slug as keyof GeneratedTypes["collections"],
|
||||
{ id }
|
||||
);
|
||||
};
|
||||
|
||||
export const afterDeleteSendChangesWebhook: AfterDeleteHook = async ({ doc, context }) => {
|
||||
const changes = context.beforeDeleteChanges as EndpointChange[] | undefined;
|
||||
if (isDefined(changes)) {
|
||||
await sendWebhookMessage(changes);
|
||||
}
|
||||
return doc;
|
||||
};
|
||||
|
||||
export const globalAfterChangeSendChangesWebhook: GlobalAfterChangeHook = async ({
|
||||
doc,
|
||||
global,
|
||||
}) => {
|
||||
const changes: EndpointChange[] = [];
|
||||
|
||||
switch (global.slug as keyof GeneratedTypes["globals"]) {
|
||||
case Collections.WebsiteConfig:
|
||||
changes.push(...getEndpointChangesForWebsiteConfig());
|
||||
break;
|
||||
|
||||
default:
|
||||
break;
|
||||
}
|
||||
await sendWebhookMessage(uniqueBy(changes, ({ url }) => url));
|
||||
return doc;
|
||||
};
|
||||
|
||||
const getChanges = async (
|
||||
slug: keyof GeneratedTypes["collections"],
|
||||
doc: any
|
||||
): Promise<EndpointChange[]> => {
|
||||
if (slug === "relationships") return [];
|
||||
if (slug === "payload-migrations") return [];
|
||||
if (slug === "payload-preferences") return [];
|
||||
|
||||
let relation: Relationship;
|
||||
try {
|
||||
relation = await findRelationByID(slug, doc.id);
|
||||
} catch (e) {
|
||||
relation = {
|
||||
id: "",
|
||||
document: {
|
||||
relationTo: slug,
|
||||
value: doc,
|
||||
},
|
||||
outgoingRelations: [],
|
||||
};
|
||||
}
|
||||
|
||||
const changes: EndpointChange[] = getEndpointChangesFromDocument(relation.document);
|
||||
|
||||
relation.incomingRelations?.forEach((relation) =>
|
||||
changes.push(...getEndpointChangesFromIncomingRelation(relation))
|
||||
);
|
||||
|
||||
relation.outgoingRelations?.forEach((relation) =>
|
||||
changes.push(...getEndpointChangesFromOutgoingRelation(relation))
|
||||
);
|
||||
|
||||
return uniqueBy(changes, ({ url }) => url);
|
||||
};
|
||||
|
||||
// -------------------------------------------------------------------------------------------------
|
||||
|
||||
const getEndpointChangesFromDocument = ({
|
||||
relationTo,
|
||||
value,
|
||||
}: NonNullable<Relationship["document"]>): EndpointChange[] => {
|
||||
if (!isPayloadType(value)) return [];
|
||||
switch (relationTo) {
|
||||
case Collections.Folders:
|
||||
return getEndpointChangesForFolder(value);
|
||||
|
||||
case Collections.Pages:
|
||||
return getEndpointChangesForPage(value);
|
||||
|
||||
case Collections.Collectibles:
|
||||
return getEndpointChangesForCollectible(value);
|
||||
|
||||
case Collections.Audios:
|
||||
return getEndpointChangesForAudio(value);
|
||||
|
||||
case Collections.Images:
|
||||
return getEndpointChangesForImage(value);
|
||||
|
||||
case Collections.Videos:
|
||||
return getEndpointChangesForVideo(value);
|
||||
|
||||
case Collections.Files:
|
||||
return getEndpointChangesForFile(value);
|
||||
|
||||
case Collections.Recorders:
|
||||
return getEndpointChangesForRecorder(value);
|
||||
|
||||
case Collections.ChronologyEvents:
|
||||
return getEndpointChangesForChronologyEvent(value);
|
||||
|
||||
case Collections.Languages:
|
||||
return getEndpointChangesForLanguage();
|
||||
|
||||
case Collections.Currencies:
|
||||
return getEndpointChangesForCurrency();
|
||||
|
||||
case Collections.Wordings:
|
||||
return getEndpointChangesForWording();
|
||||
|
||||
case Collections.Attributes:
|
||||
case Collections.CreditsRole:
|
||||
case Collections.GenericContents:
|
||||
case Collections.MediaThumbnails:
|
||||
case Collections.Scans:
|
||||
case Collections.Tags:
|
||||
case Collections.VideosChannels:
|
||||
case Collections.VideosSubtitles:
|
||||
default:
|
||||
return [];
|
||||
}
|
||||
};
|
||||
|
||||
const getEndpointChangesFromIncomingRelation = ({
|
||||
relationTo,
|
||||
value,
|
||||
}: NonNullable<Relationship["incomingRelations"]>[number]): EndpointChange[] => {
|
||||
if (!isPayloadType(value)) return [];
|
||||
switch (relationTo) {
|
||||
case Collections.Folders:
|
||||
return getEndpointChangesForFolder(value);
|
||||
|
||||
case Collections.Pages:
|
||||
return getEndpointChangesForPage(value);
|
||||
|
||||
case Collections.Collectibles:
|
||||
return getEndpointChangesForCollectible(value);
|
||||
|
||||
case Collections.Audios:
|
||||
return getEndpointChangesForAudio(value);
|
||||
|
||||
case Collections.Images:
|
||||
return getEndpointChangesForImage(value);
|
||||
|
||||
case Collections.Videos:
|
||||
return getEndpointChangesForVideo(value);
|
||||
|
||||
case Collections.Files:
|
||||
return getEndpointChangesForFile(value);
|
||||
|
||||
case Collections.Recorders:
|
||||
return getEndpointChangesForRecorder(value);
|
||||
|
||||
case Collections.ChronologyEvents:
|
||||
return getEndpointChangesForChronologyEvent(value);
|
||||
|
||||
case Collections.Languages:
|
||||
case Collections.Currencies:
|
||||
case Collections.Wordings:
|
||||
case Collections.Attributes:
|
||||
case Collections.CreditsRole:
|
||||
case Collections.GenericContents:
|
||||
case Collections.MediaThumbnails:
|
||||
case Collections.Scans:
|
||||
case Collections.Tags:
|
||||
case Collections.VideosChannels:
|
||||
case Collections.VideosSubtitles:
|
||||
default:
|
||||
return [];
|
||||
}
|
||||
};
|
||||
|
||||
const getEndpointChangesFromOutgoingRelation = ({
|
||||
relationTo,
|
||||
value,
|
||||
}: NonNullable<Relationship["outgoingRelations"]>[number]): EndpointChange[] => {
|
||||
if (!isPayloadType(value)) return [];
|
||||
switch (relationTo) {
|
||||
case Collections.Folders:
|
||||
return getEndpointChangesForFolder(value);
|
||||
|
||||
case Collections.Pages:
|
||||
return getEndpointChangesForPage(value);
|
||||
|
||||
case Collections.Collectibles:
|
||||
return getEndpointChangesForCollectible(value);
|
||||
|
||||
case Collections.Audios:
|
||||
return getEndpointChangesForAudio(value);
|
||||
|
||||
case Collections.Images:
|
||||
return getEndpointChangesForImage(value);
|
||||
|
||||
case Collections.Videos:
|
||||
return getEndpointChangesForVideo(value);
|
||||
|
||||
case Collections.Files:
|
||||
return getEndpointChangesForFile(value);
|
||||
|
||||
case Collections.Languages:
|
||||
case Collections.Currencies:
|
||||
case Collections.Wordings:
|
||||
case Collections.Attributes:
|
||||
case Collections.CreditsRole:
|
||||
case Collections.GenericContents:
|
||||
case Collections.MediaThumbnails:
|
||||
case Collections.Scans:
|
||||
case Collections.Tags:
|
||||
case Collections.VideosChannels:
|
||||
case Collections.VideosSubtitles:
|
||||
case Collections.ChronologyEvents:
|
||||
case Collections.Recorders:
|
||||
default:
|
||||
return [];
|
||||
}
|
||||
};
|
||||
|
||||
export const getEndpointChangesForWebsiteConfig = (): EndpointChange[] => [
|
||||
{
|
||||
type: SDKEndpointNames.getWebsiteConfig,
|
||||
url: getSDKEndpoint.getWebsiteConfig(),
|
||||
},
|
||||
];
|
||||
|
||||
export const getEndpointChangesForFolder = ({ slug }: Folder): EndpointChange[] => [
|
||||
{ type: SDKEndpointNames.getFolder, slug, url: getSDKEndpoint.getFolder(slug) },
|
||||
];
|
||||
|
||||
export const getEndpointChangesForLanguage = (): EndpointChange[] => [
|
||||
{ type: SDKEndpointNames.getLanguages, url: getSDKEndpoint.getLanguages() },
|
||||
];
|
||||
|
||||
export const getEndpointChangesForCurrency = (): EndpointChange[] => [
|
||||
{ type: SDKEndpointNames.getCurrencies, url: getSDKEndpoint.getCurrencies() },
|
||||
];
|
||||
|
||||
export const getEndpointChangesForWording = (): EndpointChange[] => [
|
||||
{ type: SDKEndpointNames.getWordings, url: getSDKEndpoint.getWordings() },
|
||||
];
|
||||
|
||||
export const getEndpointChangesForPage = ({ slug }: Page): EndpointChange[] => [
|
||||
{ type: SDKEndpointNames.getPage, slug, url: getSDKEndpoint.getPage(slug) },
|
||||
];
|
||||
|
||||
export const getEndpointChangesForCollectible = ({
|
||||
slug,
|
||||
gallery,
|
||||
scans,
|
||||
scansEnabled,
|
||||
}: Collectible): EndpointChange[] => {
|
||||
const changes: EndpointChange[] = [];
|
||||
|
||||
changes.push({
|
||||
type: SDKEndpointNames.getCollectible,
|
||||
slug,
|
||||
url: getSDKEndpoint.getCollectible(slug),
|
||||
});
|
||||
|
||||
if (gallery && gallery.length > 0) {
|
||||
changes.push({
|
||||
type: SDKEndpointNames.getCollectibleGallery,
|
||||
slug,
|
||||
url: getSDKEndpoint.getCollectibleGallery(slug),
|
||||
});
|
||||
gallery.forEach((_, indexNumber) => {
|
||||
const index = indexNumber.toString();
|
||||
changes.push({
|
||||
type: SDKEndpointNames.getCollectibleGalleryImage,
|
||||
slug,
|
||||
index: index,
|
||||
url: getSDKEndpoint.getCollectibleGalleryImage(slug, index),
|
||||
});
|
||||
});
|
||||
}
|
||||
|
||||
if (scans && scansEnabled) {
|
||||
changes.push({
|
||||
type: SDKEndpointNames.getCollectibleScans,
|
||||
slug,
|
||||
url: getSDKEndpoint.getCollectibleScans(slug),
|
||||
});
|
||||
|
||||
// TODO: Add other changes for cover, obi, dustjacket...
|
||||
|
||||
scans.pages?.forEach(({ page }) => {
|
||||
const index = page.toString();
|
||||
changes.push({
|
||||
type: SDKEndpointNames.getCollectibleScanPage,
|
||||
slug,
|
||||
index: index,
|
||||
url: getSDKEndpoint.getCollectibleScanPage(slug, index),
|
||||
});
|
||||
});
|
||||
}
|
||||
|
||||
return changes;
|
||||
};
|
||||
|
||||
export const getEndpointChangesForAudio = ({ id }: Audio): EndpointChange[] => [
|
||||
{ type: SDKEndpointNames.getAudioByID, id, url: getSDKEndpoint.getAudioByID(id) },
|
||||
];
|
||||
|
||||
export const getEndpointChangesForImage = ({ id }: Image): EndpointChange[] => [
|
||||
{ type: SDKEndpointNames.getImageByID, id, url: getSDKEndpoint.getImageByID(id) },
|
||||
];
|
||||
|
||||
export const getEndpointChangesForVideo = ({ id }: Video): EndpointChange[] => [
|
||||
{ type: SDKEndpointNames.getVideoByID, id, url: getSDKEndpoint.getVideoByID(id) },
|
||||
];
|
||||
|
||||
export const getEndpointChangesForFile = ({ id }: File): EndpointChange[] => [
|
||||
{ type: SDKEndpointNames.getFileByID, id, url: getSDKEndpoint.getFileByID(id) },
|
||||
];
|
||||
|
||||
export const getEndpointChangesForRecorder = ({ id }: Recorder): EndpointChange[] => [
|
||||
{ type: SDKEndpointNames.getRecorderByID, id, url: getSDKEndpoint.getRecorderByID(id) },
|
||||
];
|
||||
|
||||
export const getEndpointChangesForChronologyEvent = ({ id }: ChronologyEvent): EndpointChange[] => [
|
||||
{
|
||||
type: SDKEndpointNames.getChronologyEventByID,
|
||||
id,
|
||||
url: getSDKEndpoint.getChronologyEventByID(id),
|
||||
},
|
||||
{
|
||||
type: SDKEndpointNames.getChronologyEvents,
|
||||
url: getSDKEndpoint.getChronologyEvents(),
|
||||
},
|
||||
];
|
||||
|
||||
// -------------------------------------------------------------------------------------------------
|
||||
|
||||
const webhookTargets: { url: string; token: string }[] = [
|
||||
{
|
||||
url: process.env.WEB_SERVER_HOOK_URL ?? "",
|
||||
token: process.env.WEB_SERVER_HOOK_TOKEN ?? "",
|
||||
},
|
||||
{
|
||||
url: process.env.MEILISEARCH_HOOK_URL ?? "",
|
||||
token: process.env.MEILISEARCH_HOOK_TOKEN ?? "",
|
||||
},
|
||||
];
|
||||
|
||||
const sendWebhookMessage = async (changes: EndpointChange[]) => {
|
||||
if (changes.length === 0) return;
|
||||
try {
|
||||
await Promise.all(
|
||||
webhookTargets.flatMap(({ url, token }) => {
|
||||
if (!url) return;
|
||||
return fetch(url, {
|
||||
headers: {
|
||||
Authorization: `Bearer ${token}`,
|
||||
"Content-Type": "application/json",
|
||||
},
|
||||
body: JSON.stringify(changes),
|
||||
method: "POST",
|
||||
});
|
||||
})
|
||||
);
|
||||
} catch (e) {
|
||||
if (e instanceof Error) {
|
||||
console.warn("Error while sending webhook", e.message);
|
||||
} else {
|
||||
console.warn("Error while sending webhook", e);
|
||||
}
|
||||
}
|
||||
};
|
|
@ -0,0 +1,81 @@
|
|||
import {
|
||||
AfterDeleteHook,
|
||||
AfterChangeHook as CollectionAfterChangeHook,
|
||||
} from "payload/dist/collections/config/types";
|
||||
import { AfterChangeHook as GlobalAfterChangeHook } from "payload/dist/globals/config/types";
|
||||
import { getSDKUrlsForDocument } from "src/endpoints/getAllSDKUrlsEndpoint";
|
||||
import { getAddedBackPropagationRelationships } from "src/fields/backPropagationField/backPropagationUtils";
|
||||
import { Collections } from "src/shared/payload/constants";
|
||||
import { AfterOperationWebHookMessage } from "src/shared/payload/webhooks";
|
||||
|
||||
export const globalAfterChangeWebhook: GlobalAfterChangeHook = async ({
|
||||
global,
|
||||
doc,
|
||||
previousDoc,
|
||||
}) => {
|
||||
const collection = global.slug as Collections;
|
||||
await sendWebhookMessage({
|
||||
collection,
|
||||
addedDependantIds: await getAddedBackPropagationRelationships(global, doc, previousDoc),
|
||||
urls: getSDKUrlsForDocument(collection, doc),
|
||||
});
|
||||
return doc;
|
||||
};
|
||||
|
||||
export const collectionAfterChangeWebhook: CollectionAfterChangeHook = async ({
|
||||
collection,
|
||||
doc,
|
||||
previousDoc,
|
||||
operation,
|
||||
}) => {
|
||||
const collectionSlug = collection.slug as Collections;
|
||||
console.log("afterChange", operation, collectionSlug, doc.id);
|
||||
|
||||
if ("_status" in doc && doc._status === "draft") {
|
||||
return doc;
|
||||
}
|
||||
|
||||
if (!("id" in doc)) {
|
||||
return doc;
|
||||
}
|
||||
|
||||
await sendWebhookMessage({
|
||||
collection: collectionSlug,
|
||||
id: doc.id,
|
||||
addedDependantIds: await getAddedBackPropagationRelationships(collection, doc, previousDoc),
|
||||
urls: getSDKUrlsForDocument(collectionSlug, doc),
|
||||
});
|
||||
|
||||
return doc;
|
||||
};
|
||||
|
||||
export const afterDeleteWebhook: AfterDeleteHook = async ({ collection, doc }) => {
|
||||
const collectionSlug = collection.slug as Collections;
|
||||
console.log("afterDelete", collection.slug, doc.id);
|
||||
|
||||
if (!("id" in doc)) {
|
||||
return doc;
|
||||
}
|
||||
|
||||
await sendWebhookMessage({
|
||||
collection: collectionSlug,
|
||||
id: doc.id,
|
||||
addedDependantIds: [],
|
||||
urls: getSDKUrlsForDocument(collectionSlug, doc),
|
||||
});
|
||||
|
||||
return doc;
|
||||
};
|
||||
|
||||
const sendWebhookMessage = async (message: AfterOperationWebHookMessage) => {
|
||||
await fetch(`${process.env.WEB_HOOK_URI}/collection-operation`, {
|
||||
headers: {
|
||||
Authorization: `Bearer ${process.env.WEB_HOOK_TOKEN}`,
|
||||
"Content-Type": "application/json",
|
||||
},
|
||||
body: JSON.stringify(message),
|
||||
method: "POST",
|
||||
}).catch((e) => {
|
||||
console.warn("Error while sending webhook", e);
|
||||
});
|
||||
};
|
|
@ -1,5 +1,5 @@
|
|||
import { BeforeDuplicate } from "payload/types";
|
||||
import { CollectionStatus } from "../shared/payload/constants";
|
||||
import { CollectionStatus } from "src/shared/payload/constants";
|
||||
|
||||
export const beforeDuplicateUnpublish: BeforeDuplicate = ({ data }) => ({
|
||||
...data,
|
||||
|
|
|
@ -4,35 +4,34 @@ import { cloudStorage } from "@payloadcms/plugin-cloud-storage";
|
|||
import path from "path";
|
||||
import { buildConfig } from "payload/config";
|
||||
import { sftpAdapter } from "payloadcms-sftp-storage";
|
||||
import { Attributes } from "./collections/Attributes/Attributes";
|
||||
import { Audios } from "./collections/Audios/Audios";
|
||||
import { ChronologyEvents } from "./collections/ChronologyEvents/ChronologyEvents";
|
||||
import { Collectibles } from "./collections/Collectibles/Collectibles";
|
||||
import { CreditsRoles } from "./collections/CreditsRoles/CreditsRoles";
|
||||
import { Currencies } from "./collections/Currencies/Currencies";
|
||||
import { Files } from "./collections/Files/Files";
|
||||
import { Folders } from "./collections/Folders/Folders";
|
||||
import { GenericContents } from "./collections/GenericContents/GenericContents";
|
||||
import { Images } from "./collections/Images/Images";
|
||||
import { Languages } from "./collections/Languages/Languages";
|
||||
import { MediaThumbnails } from "./collections/MediaThumbnails/MediaThumbnails";
|
||||
import { Pages } from "./collections/Pages/Pages";
|
||||
import { Recorders } from "./collections/Recorders/Recorders";
|
||||
import { Scans } from "./collections/Scans/Scans";
|
||||
import { Tags } from "./collections/Tags/Tags";
|
||||
import { Videos } from "./collections/Videos/Videos";
|
||||
import { VideosChannels } from "./collections/VideosChannels/VideosChannels";
|
||||
import { VideosSubtitles } from "./collections/VideosSubtitles/VideosSubtitles";
|
||||
import { WebsiteConfig } from "./collections/WebsiteConfig/WebsiteConfig";
|
||||
import { Wordings } from "./collections/Wordings/Wordings";
|
||||
import { Icon } from "./components/Icon";
|
||||
import { Logo } from "./components/Logo";
|
||||
import { getAllEndpoint } from "./endpoints/getAllEndpoint";
|
||||
import { createEditor } from "./utils/editor";
|
||||
import { Collections } from "./shared/payload/constants";
|
||||
import { relationshipsPlugin } from "payloadcms-relationships";
|
||||
import { shownOnlyToAdmin } from "./accesses/collections/shownOnlyToAdmin";
|
||||
import { mustBeAdmin } from "./accesses/fields/mustBeAdmin";
|
||||
import { Attributes } from "src/collections/Attributes/Attributes";
|
||||
import { Audios } from "src/collections/Audios/Audios";
|
||||
import { ChronologyEvents } from "src/collections/ChronologyEvents/ChronologyEvents";
|
||||
import { Collectibles } from "src/collections/Collectibles/Collectibles";
|
||||
import { CreditsRoles } from "src/collections/CreditsRoles/CreditsRoles";
|
||||
import { Currencies } from "src/collections/Currencies/Currencies";
|
||||
import { Files } from "src/collections/Files/Files";
|
||||
import { Folders } from "src/collections/Folders/Folders";
|
||||
import { GenericContents } from "src/collections/GenericContents/GenericContents";
|
||||
import { Images } from "src/collections/Images/Images";
|
||||
import { Languages } from "src/collections/Languages/Languages";
|
||||
import { MediaThumbnails } from "src/collections/MediaThumbnails/MediaThumbnails";
|
||||
import { Pages } from "src/collections/Pages/Pages";
|
||||
import { Recorders } from "src/collections/Recorders/Recorders";
|
||||
import { Scans } from "src/collections/Scans/Scans";
|
||||
import { Tags } from "src/collections/Tags/Tags";
|
||||
import { Videos } from "src/collections/Videos/Videos";
|
||||
import { VideosChannels } from "src/collections/VideosChannels/VideosChannels";
|
||||
import { VideosSubtitles } from "src/collections/VideosSubtitles/VideosSubtitles";
|
||||
import { WebsiteConfig } from "src/collections/WebsiteConfig/WebsiteConfig";
|
||||
import { Wordings } from "src/collections/Wordings/Wordings";
|
||||
import { Icon } from "src/components/Icon";
|
||||
import { Logo } from "src/components/Logo";
|
||||
import { getAllIds } from "src/endpoints/getAllIdsEndpoint";
|
||||
import { getAllSDKUrlsEndpoint } from "src/endpoints/getAllSDKUrlsEndpoint";
|
||||
import { Collections } from "src/shared/payload/constants";
|
||||
import { createEditor } from "src/utils/editor";
|
||||
// import TsconfigPathsPlugin from "tsconfig-paths-webpack-plugin";
|
||||
|
||||
const configuredSftpAdapter = sftpAdapter({
|
||||
connectOptions: {
|
||||
|
@ -56,6 +55,22 @@ export default buildConfig({
|
|||
},
|
||||
css: path.resolve(__dirname, "styles.scss"),
|
||||
bundler: webpackBundler(),
|
||||
webpack: (config) => ({
|
||||
...config,
|
||||
resolve: {
|
||||
...config.resolve,
|
||||
// plugins: [
|
||||
// ...(config.resolve?.plugins ?? []),
|
||||
// new TsconfigPathsPlugin({
|
||||
// /* options: see below */
|
||||
// }),
|
||||
// ],
|
||||
alias: {
|
||||
...config.resolve?.alias,
|
||||
"src/": path.resolve(__dirname, "src"),
|
||||
},
|
||||
},
|
||||
}),
|
||||
},
|
||||
editor: createEditor({}),
|
||||
collections: [
|
||||
|
@ -90,7 +105,7 @@ export default buildConfig({
|
|||
typescript: {
|
||||
outputFile: path.resolve(__dirname, "types/collections.ts"),
|
||||
},
|
||||
endpoints: [getAllEndpoint],
|
||||
endpoints: [getAllSDKUrlsEndpoint, getAllIds],
|
||||
graphQL: {
|
||||
disable: true,
|
||||
},
|
||||
|
@ -98,20 +113,6 @@ export default buildConfig({
|
|||
skip: () => true,
|
||||
},
|
||||
plugins: [
|
||||
relationshipsPlugin({
|
||||
// rebuildOnInit: true,
|
||||
collectionConfig: {
|
||||
admin: {
|
||||
hidden: shownOnlyToAdmin,
|
||||
},
|
||||
access: {
|
||||
update: mustBeAdmin,
|
||||
create: mustBeAdmin,
|
||||
delete: mustBeAdmin,
|
||||
},
|
||||
},
|
||||
}),
|
||||
|
||||
cloudStorage({
|
||||
collections: {
|
||||
[Collections.Videos]: {
|
||||
|
|
|
@ -1,9 +1,8 @@
|
|||
import "dotenv/config";
|
||||
import express from "express";
|
||||
import path from "path";
|
||||
import payload from "payload";
|
||||
import { isUndefined } from "./utils/asserts";
|
||||
import { Collections, RecordersRoles } from "./shared/payload/constants";
|
||||
import { Collections, RecordersRoles } from "src/shared/payload/constants";
|
||||
import { isUndefined, isDefined } from "src/utils/asserts";
|
||||
|
||||
const app = express();
|
||||
|
||||
|
@ -28,36 +27,32 @@ const start = async () => {
|
|||
express: app,
|
||||
onInit: async () => {
|
||||
payload.logger.info(`Payload Admin URL: ${payload.getAdminURL()}`);
|
||||
const recorders = await payload.find({ collection: Collections.Recorders });
|
||||
|
||||
const seedFirstUser = async () => {
|
||||
const recorders = await payload.find({ collection: Collections.Recorders });
|
||||
// If no recorders, we seed some initial data
|
||||
if (
|
||||
isDefined(process.env.SEEDING_ADMIN_EMAIL) &&
|
||||
isDefined(process.env.SEEDING_ADMIN_PASSWORD) &&
|
||||
isDefined(process.env.SEEDING_ADMIN_USERNAME)
|
||||
) {
|
||||
if (recorders.docs.length === 0) {
|
||||
payload.logger.info("Seeding some initial data");
|
||||
|
||||
if (recorders.docs.length > 0) return;
|
||||
if (isUndefined(process.env.SEEDING_ADMIN_EMAIL)) return;
|
||||
if (isUndefined(process.env.SEEDING_ADMIN_PASSWORD)) return;
|
||||
if (isUndefined(process.env.SEEDING_ADMIN_USERNAME)) return;
|
||||
|
||||
payload.logger.info("Seeding your first user");
|
||||
|
||||
await payload.create({
|
||||
collection: Collections.Recorders,
|
||||
data: {
|
||||
email: process.env.SEEDING_ADMIN_EMAIL,
|
||||
password: process.env.SEEDING_ADMIN_PASSWORD,
|
||||
username: process.env.SEEDING_ADMIN_USERNAME,
|
||||
role: [RecordersRoles.Admin, RecordersRoles.Api],
|
||||
anonymize: false,
|
||||
},
|
||||
});
|
||||
};
|
||||
|
||||
await seedFirstUser();
|
||||
await payload.create({
|
||||
collection: Collections.Recorders,
|
||||
data: {
|
||||
email: process.env.SEEDING_ADMIN_EMAIL,
|
||||
password: process.env.SEEDING_ADMIN_PASSWORD,
|
||||
username: process.env.SEEDING_ADMIN_USERNAME,
|
||||
role: [RecordersRoles.Admin, RecordersRoles.Api],
|
||||
anonymize: false,
|
||||
},
|
||||
});
|
||||
}
|
||||
}
|
||||
},
|
||||
});
|
||||
|
||||
// Add your own express routes here
|
||||
app.use("/public", express.static(path.join(__dirname, "../public")));
|
||||
|
||||
app.get("/robots.txt", (_, res) => {
|
||||
res.type("text/plain");
|
||||
res.send("User-agent: *\nDisallow: /");
|
||||
|
|
|
@ -1 +0,0 @@
|
|||
Subproject commit c2702ea508dde59264ee66100054bacc0834c029
|
|
@ -40,7 +40,6 @@ export interface Config {
|
|||
currencies: Currency;
|
||||
wordings: Wording;
|
||||
"generic-contents": GenericContent;
|
||||
relationships: Relationship;
|
||||
"payload-preferences": PayloadPreference;
|
||||
"payload-migrations": PayloadMigration;
|
||||
};
|
||||
|
@ -95,9 +94,10 @@ export interface Page {
|
|||
[k: string]: unknown;
|
||||
};
|
||||
credits?: Credits;
|
||||
sourceUrls?: string[] | null;
|
||||
id?: string | null;
|
||||
}[];
|
||||
folders?: (string | Folder)[] | null;
|
||||
collectibles?: (string | Collectible)[] | null;
|
||||
updatedBy: string | Recorder;
|
||||
updatedAt: string;
|
||||
createdAt: string;
|
||||
|
@ -352,6 +352,79 @@ export interface Recorder {
|
|||
lockUntil?: string | null;
|
||||
password?: string | null;
|
||||
}
|
||||
/**
|
||||
* This interface was referenced by `Config`'s JSON-Schema
|
||||
* via the `definition` "folders".
|
||||
*/
|
||||
export interface Folder {
|
||||
id: string;
|
||||
slug: string;
|
||||
icon?: string | null;
|
||||
parentFolders?: (string | Folder)[] | null;
|
||||
translations: {
|
||||
language: string | Language;
|
||||
name: string;
|
||||
description?: {
|
||||
root: {
|
||||
type: string;
|
||||
children: {
|
||||
type: string;
|
||||
version: number;
|
||||
[k: string]: unknown;
|
||||
}[];
|
||||
direction: ("ltr" | "rtl") | null;
|
||||
format: "left" | "start" | "center" | "right" | "end" | "justify" | "";
|
||||
indent: number;
|
||||
version: number;
|
||||
};
|
||||
[k: string]: unknown;
|
||||
} | null;
|
||||
id?: string | null;
|
||||
}[];
|
||||
sections?:
|
||||
| {
|
||||
translations?:
|
||||
| {
|
||||
language: string | Language;
|
||||
name: string;
|
||||
id?: string | null;
|
||||
}[]
|
||||
| null;
|
||||
subfolders?: (string | Folder)[] | null;
|
||||
id?: string | null;
|
||||
}[]
|
||||
| null;
|
||||
files?:
|
||||
| (
|
||||
| {
|
||||
relationTo: "collectibles";
|
||||
value: string | Collectible;
|
||||
}
|
||||
| {
|
||||
relationTo: "pages";
|
||||
value: string | Page;
|
||||
}
|
||||
| {
|
||||
relationTo: "videos";
|
||||
value: string | Video;
|
||||
}
|
||||
| {
|
||||
relationTo: "images";
|
||||
value: string | Image;
|
||||
}
|
||||
| {
|
||||
relationTo: "audios";
|
||||
value: string | Audio;
|
||||
}
|
||||
| {
|
||||
relationTo: "files";
|
||||
value: string | File;
|
||||
}
|
||||
)[]
|
||||
| null;
|
||||
updatedAt: string;
|
||||
createdAt: string;
|
||||
}
|
||||
/**
|
||||
* This interface was referenced by `Config`'s JSON-Schema
|
||||
* via the `definition` "collectibles".
|
||||
|
@ -535,6 +608,8 @@ export interface Collectible {
|
|||
id?: string | null;
|
||||
}[]
|
||||
| null;
|
||||
folders?: (string | Folder)[] | null;
|
||||
parentItems?: (string | Collectible)[] | null;
|
||||
updatedBy: string | Recorder;
|
||||
updatedAt: string;
|
||||
createdAt: string;
|
||||
|
@ -876,78 +951,7 @@ export interface VideosChannel {
|
|||
url: string;
|
||||
title: string;
|
||||
subscribers: number;
|
||||
}
|
||||
/**
|
||||
* This interface was referenced by `Config`'s JSON-Schema
|
||||
* via the `definition` "folders".
|
||||
*/
|
||||
export interface Folder {
|
||||
id: string;
|
||||
slug: string;
|
||||
icon?: string | null;
|
||||
translations: {
|
||||
language: string | Language;
|
||||
name: string;
|
||||
description?: {
|
||||
root: {
|
||||
type: string;
|
||||
children: {
|
||||
type: string;
|
||||
version: number;
|
||||
[k: string]: unknown;
|
||||
}[];
|
||||
direction: ("ltr" | "rtl") | null;
|
||||
format: "left" | "start" | "center" | "right" | "end" | "justify" | "";
|
||||
indent: number;
|
||||
version: number;
|
||||
};
|
||||
[k: string]: unknown;
|
||||
} | null;
|
||||
id?: string | null;
|
||||
}[];
|
||||
sections?:
|
||||
| {
|
||||
translations?:
|
||||
| {
|
||||
language: string | Language;
|
||||
name: string;
|
||||
id?: string | null;
|
||||
}[]
|
||||
| null;
|
||||
subfolders?: (string | Folder)[] | null;
|
||||
id?: string | null;
|
||||
}[]
|
||||
| null;
|
||||
files?:
|
||||
| (
|
||||
| {
|
||||
relationTo: "collectibles";
|
||||
value: string | Collectible;
|
||||
}
|
||||
| {
|
||||
relationTo: "pages";
|
||||
value: string | Page;
|
||||
}
|
||||
| {
|
||||
relationTo: "videos";
|
||||
value: string | Video;
|
||||
}
|
||||
| {
|
||||
relationTo: "images";
|
||||
value: string | Image;
|
||||
}
|
||||
| {
|
||||
relationTo: "audios";
|
||||
value: string | Audio;
|
||||
}
|
||||
| {
|
||||
relationTo: "files";
|
||||
value: string | File;
|
||||
}
|
||||
)[]
|
||||
| null;
|
||||
updatedAt: string;
|
||||
createdAt: string;
|
||||
videos?: (string | Video)[] | null;
|
||||
}
|
||||
/**
|
||||
* This interface was referenced by `Config`'s JSON-Schema
|
||||
|
@ -1078,262 +1082,6 @@ export interface Wording {
|
|||
updatedAt: string;
|
||||
createdAt: string;
|
||||
}
|
||||
/**
|
||||
* This interface was referenced by `Config`'s JSON-Schema
|
||||
* via the `definition` "relationships".
|
||||
*/
|
||||
export interface Relationship {
|
||||
id: string;
|
||||
document:
|
||||
| {
|
||||
relationTo: "pages";
|
||||
value: string | Page;
|
||||
}
|
||||
| {
|
||||
relationTo: "collectibles";
|
||||
value: string | Collectible;
|
||||
}
|
||||
| {
|
||||
relationTo: "folders";
|
||||
value: string | Folder;
|
||||
}
|
||||
| {
|
||||
relationTo: "chronology-events";
|
||||
value: string | ChronologyEvent;
|
||||
}
|
||||
| {
|
||||
relationTo: "images";
|
||||
value: string | Image;
|
||||
}
|
||||
| {
|
||||
relationTo: "audios";
|
||||
value: string | Audio;
|
||||
}
|
||||
| {
|
||||
relationTo: "media-thumbnails";
|
||||
value: string | MediaThumbnail;
|
||||
}
|
||||
| {
|
||||
relationTo: "videos";
|
||||
value: string | Video;
|
||||
}
|
||||
| {
|
||||
relationTo: "videos-subtitles";
|
||||
value: string | VideoSubtitle;
|
||||
}
|
||||
| {
|
||||
relationTo: "videos-channels";
|
||||
value: string | VideosChannel;
|
||||
}
|
||||
| {
|
||||
relationTo: "files";
|
||||
value: string | File;
|
||||
}
|
||||
| {
|
||||
relationTo: "scans";
|
||||
value: string | Scan;
|
||||
}
|
||||
| {
|
||||
relationTo: "tags";
|
||||
value: string | Tag;
|
||||
}
|
||||
| {
|
||||
relationTo: "attributes";
|
||||
value: string | Attribute;
|
||||
}
|
||||
| {
|
||||
relationTo: "credits-roles";
|
||||
value: string | CreditsRole;
|
||||
}
|
||||
| {
|
||||
relationTo: "recorders";
|
||||
value: string | Recorder;
|
||||
}
|
||||
| {
|
||||
relationTo: "languages";
|
||||
value: string | Language;
|
||||
}
|
||||
| {
|
||||
relationTo: "currencies";
|
||||
value: string | Currency;
|
||||
}
|
||||
| {
|
||||
relationTo: "wordings";
|
||||
value: string | Wording;
|
||||
}
|
||||
| {
|
||||
relationTo: "generic-contents";
|
||||
value: string | GenericContent;
|
||||
};
|
||||
incomingRelations?:
|
||||
| (
|
||||
| {
|
||||
relationTo: "pages";
|
||||
value: string | Page;
|
||||
}
|
||||
| {
|
||||
relationTo: "collectibles";
|
||||
value: string | Collectible;
|
||||
}
|
||||
| {
|
||||
relationTo: "folders";
|
||||
value: string | Folder;
|
||||
}
|
||||
| {
|
||||
relationTo: "chronology-events";
|
||||
value: string | ChronologyEvent;
|
||||
}
|
||||
| {
|
||||
relationTo: "images";
|
||||
value: string | Image;
|
||||
}
|
||||
| {
|
||||
relationTo: "audios";
|
||||
value: string | Audio;
|
||||
}
|
||||
| {
|
||||
relationTo: "media-thumbnails";
|
||||
value: string | MediaThumbnail;
|
||||
}
|
||||
| {
|
||||
relationTo: "videos";
|
||||
value: string | Video;
|
||||
}
|
||||
| {
|
||||
relationTo: "videos-subtitles";
|
||||
value: string | VideoSubtitle;
|
||||
}
|
||||
| {
|
||||
relationTo: "videos-channels";
|
||||
value: string | VideosChannel;
|
||||
}
|
||||
| {
|
||||
relationTo: "files";
|
||||
value: string | File;
|
||||
}
|
||||
| {
|
||||
relationTo: "scans";
|
||||
value: string | Scan;
|
||||
}
|
||||
| {
|
||||
relationTo: "tags";
|
||||
value: string | Tag;
|
||||
}
|
||||
| {
|
||||
relationTo: "attributes";
|
||||
value: string | Attribute;
|
||||
}
|
||||
| {
|
||||
relationTo: "credits-roles";
|
||||
value: string | CreditsRole;
|
||||
}
|
||||
| {
|
||||
relationTo: "recorders";
|
||||
value: string | Recorder;
|
||||
}
|
||||
| {
|
||||
relationTo: "languages";
|
||||
value: string | Language;
|
||||
}
|
||||
| {
|
||||
relationTo: "currencies";
|
||||
value: string | Currency;
|
||||
}
|
||||
| {
|
||||
relationTo: "wordings";
|
||||
value: string | Wording;
|
||||
}
|
||||
| {
|
||||
relationTo: "generic-contents";
|
||||
value: string | GenericContent;
|
||||
}
|
||||
)[]
|
||||
| null;
|
||||
outgoingRelations?:
|
||||
| (
|
||||
| {
|
||||
relationTo: "pages";
|
||||
value: string | Page;
|
||||
}
|
||||
| {
|
||||
relationTo: "collectibles";
|
||||
value: string | Collectible;
|
||||
}
|
||||
| {
|
||||
relationTo: "folders";
|
||||
value: string | Folder;
|
||||
}
|
||||
| {
|
||||
relationTo: "chronology-events";
|
||||
value: string | ChronologyEvent;
|
||||
}
|
||||
| {
|
||||
relationTo: "images";
|
||||
value: string | Image;
|
||||
}
|
||||
| {
|
||||
relationTo: "audios";
|
||||
value: string | Audio;
|
||||
}
|
||||
| {
|
||||
relationTo: "media-thumbnails";
|
||||
value: string | MediaThumbnail;
|
||||
}
|
||||
| {
|
||||
relationTo: "videos";
|
||||
value: string | Video;
|
||||
}
|
||||
| {
|
||||
relationTo: "videos-subtitles";
|
||||
value: string | VideoSubtitle;
|
||||
}
|
||||
| {
|
||||
relationTo: "videos-channels";
|
||||
value: string | VideosChannel;
|
||||
}
|
||||
| {
|
||||
relationTo: "files";
|
||||
value: string | File;
|
||||
}
|
||||
| {
|
||||
relationTo: "scans";
|
||||
value: string | Scan;
|
||||
}
|
||||
| {
|
||||
relationTo: "tags";
|
||||
value: string | Tag;
|
||||
}
|
||||
| {
|
||||
relationTo: "attributes";
|
||||
value: string | Attribute;
|
||||
}
|
||||
| {
|
||||
relationTo: "credits-roles";
|
||||
value: string | CreditsRole;
|
||||
}
|
||||
| {
|
||||
relationTo: "recorders";
|
||||
value: string | Recorder;
|
||||
}
|
||||
| {
|
||||
relationTo: "languages";
|
||||
value: string | Language;
|
||||
}
|
||||
| {
|
||||
relationTo: "currencies";
|
||||
value: string | Currency;
|
||||
}
|
||||
| {
|
||||
relationTo: "wordings";
|
||||
value: string | Wording;
|
||||
}
|
||||
| {
|
||||
relationTo: "generic-contents";
|
||||
value: string | GenericContent;
|
||||
}
|
||||
)[]
|
||||
| null;
|
||||
}
|
||||
/**
|
||||
* This interface was referenced by `Config`'s JSON-Schema
|
||||
* via the `definition` "payload-preferences".
|
||||
|
|
|
@ -1,9 +0,0 @@
|
|||
export const uniqueBy = <T, K extends string | number>(array: T[], getKey: (item: T) => K) => {
|
||||
const alreadyFoundKeys: K[] = [];
|
||||
return array.filter((item) => {
|
||||
var currentItemKey = getKey(item);
|
||||
if (alreadyFoundKeys.includes(currentItemKey)) return false;
|
||||
alreadyFoundKeys.push(currentItemKey);
|
||||
return true;
|
||||
});
|
||||
};
|
|
@ -1,6 +1,7 @@
|
|||
import { PayloadImage, PayloadMedia } from "../shared/payload/endpoint-types";
|
||||
import { RichTextContent, isNodeParagraphNode } from "../shared/payload/rich-text";
|
||||
import { Audio, File, Image, MediaThumbnail, Scan, Video } from "../types/collections";
|
||||
import { PayloadImage, PayloadMedia } from "src/shared/payload/endpoint-types";
|
||||
import { RichTextContent, isNodeParagraphNode } from "src/shared/payload/rich-text";
|
||||
import { Scan, MediaThumbnail, Video, Image, Audio } from "src/types/collections";
|
||||
import { File } from "src/types/collections";
|
||||
|
||||
export const isDefined = <T>(value: T | null | undefined): value is T =>
|
||||
value !== null && value !== undefined;
|
||||
|
|
|
@ -1,21 +1,20 @@
|
|||
import { GeneratedTypes } from "payload";
|
||||
import { CollectionConfig } from "payload/types";
|
||||
import { formatToPascalCase } from "./string";
|
||||
import {
|
||||
afterChangeSendChangesWebhook,
|
||||
afterDeleteSendChangesWebhook,
|
||||
beforeChangePrepareChanges,
|
||||
beforeDeletePrepareChanges,
|
||||
} from "../hooks/afterOperationSendChangesWebhook";
|
||||
import { collectionAfterChangeWebhook, afterDeleteWebhook } from "src/hooks/afterOperationWebhook";
|
||||
import { formatToPascalCase } from "src/utils/string";
|
||||
|
||||
type CollectionConfigWithPlugins = CollectionConfig;
|
||||
|
||||
export type BuildCollectionConfig = Omit<
|
||||
CollectionConfigWithPlugins,
|
||||
"slug" | "typescript" | "labels"
|
||||
"slug" | "typescript" | "labels" | "custom"
|
||||
> & {
|
||||
slug: keyof GeneratedTypes["collections"];
|
||||
labels: { singular: string; plural: string };
|
||||
custom?: {
|
||||
getBackPropagatedRelationships?: (object: any) => string[];
|
||||
[key: string]: unknown;
|
||||
};
|
||||
};
|
||||
|
||||
export const buildCollectionConfig = (config: BuildCollectionConfig): CollectionConfig => ({
|
||||
|
@ -23,9 +22,7 @@ export const buildCollectionConfig = (config: BuildCollectionConfig): Collection
|
|||
typescript: { interface: formatToPascalCase(config.labels.singular) },
|
||||
hooks: {
|
||||
...config.hooks,
|
||||
beforeChange: [...(config.hooks?.beforeChange ?? []), beforeChangePrepareChanges],
|
||||
afterChange: [...(config.hooks?.afterChange ?? []), afterChangeSendChangesWebhook],
|
||||
beforeDelete: [...(config.hooks?.beforeDelete ?? []), beforeDeletePrepareChanges],
|
||||
afterDelete: [...(config.hooks?.afterDelete ?? []), afterDeleteSendChangesWebhook],
|
||||
afterChange: [...(config.hooks?.afterChange ?? []), collectionAfterChangeWebhook],
|
||||
afterDelete: [...(config.hooks?.afterDelete ?? []), afterDeleteWebhook],
|
||||
},
|
||||
});
|
||||
|
|
|
@ -1,23 +1,19 @@
|
|||
import { convertAudioToEndpointAudioPreview } from "../collections/Audios/endpoints/getByID";
|
||||
import { convertEventToEndpointEvent } from "../collections/ChronologyEvents/endpoints/getAllEndpoint";
|
||||
import { convertCollectibleToEndpointCollectiblePreview } from "../collections/Collectibles/endpoints/getBySlugEndpoint";
|
||||
import { convertFileToEndpointFilePreview } from "../collections/Files/endpoints/getByID";
|
||||
import { convertFolderToEndpointFolderPreview } from "../collections/Folders/endpoints/getBySlugEndpoint";
|
||||
import { convertImageToEndpointImagePreview } from "../collections/Images/endpoints/getByID";
|
||||
import { convertPageToEndpointPagePreview } from "../collections/Pages/endpoints/getBySlugEndpoint";
|
||||
import { convertRecorderToEndpointRecorderPreview } from "../collections/Recorders/endpoints/getByID";
|
||||
import { convertVideoToEndpointVideoPreview } from "../collections/Videos/endpoints/getByID";
|
||||
import { AttributeTypes, Collections } from "../shared/payload/constants";
|
||||
import { convertAudioToEndpointAudioPreview } from "src/collections/Audios/endpoints/getByID";
|
||||
import { convertImageToEndpointImagePreview } from "src/collections/Images/endpoints/getByID";
|
||||
import { convertRecorderToEndpointRecorderPreview } from "src/collections/Recorders/endpoints/getByID";
|
||||
import { convertVideoToEndpointVideoPreview } from "src/collections/Videos/endpoints/getByID";
|
||||
import { AttributeTypes } from "src/shared/payload/constants";
|
||||
import {
|
||||
EndpointTag,
|
||||
EndpointSource,
|
||||
EndpointSourcePreview,
|
||||
EndpointRole,
|
||||
EndpointCredit,
|
||||
EndpointAttribute,
|
||||
PayloadImage,
|
||||
EndpointScanImage,
|
||||
EndpointPayloadImage,
|
||||
EndpointRelation,
|
||||
} from "../shared/payload/endpoint-types";
|
||||
} from "src/shared/payload/endpoint-types";
|
||||
import {
|
||||
RichTextContent,
|
||||
isNodeBlockNode,
|
||||
|
@ -30,33 +26,35 @@ import {
|
|||
isUploadNodeImageNode,
|
||||
isUploadNodeAudioNode,
|
||||
isUploadNodeVideoNode,
|
||||
} from "../shared/payload/rich-text";
|
||||
} from "src/shared/payload/rich-text";
|
||||
import {
|
||||
Audio,
|
||||
Credits,
|
||||
CreditsRole,
|
||||
Image,
|
||||
Language,
|
||||
MediaThumbnail,
|
||||
NumberBlock,
|
||||
Relationship,
|
||||
Scan,
|
||||
Tag,
|
||||
TagsBlock,
|
||||
TextBlock,
|
||||
Audio,
|
||||
Video,
|
||||
} from "../types/collections";
|
||||
Collectible,
|
||||
Folder,
|
||||
Language,
|
||||
CreditsRole,
|
||||
Credits,
|
||||
TagsBlock,
|
||||
NumberBlock,
|
||||
TextBlock,
|
||||
Scan,
|
||||
MediaThumbnail,
|
||||
Tag,
|
||||
} from "src/types/collections";
|
||||
import {
|
||||
isPayloadType,
|
||||
isImage,
|
||||
isAudio,
|
||||
isVideo,
|
||||
isNotEmpty,
|
||||
isPayloadArrayType,
|
||||
isPublished,
|
||||
isDefined,
|
||||
isEmpty,
|
||||
isFile,
|
||||
isImage,
|
||||
isPayloadArrayType,
|
||||
isPayloadImage,
|
||||
isPayloadType,
|
||||
isVideo,
|
||||
} from "./asserts";
|
||||
} from "src/utils/asserts";
|
||||
|
||||
const convertTagToEndpointTag = ({ id, slug, page, translations }: Tag): EndpointTag => ({
|
||||
id,
|
||||
|
@ -141,64 +139,86 @@ export const convertRTCToEndpointRTC = (
|
|||
};
|
||||
};
|
||||
|
||||
export const convertRelationshipsToEndpointRelations = (
|
||||
relationships: Relationship["incomingRelations"] | Relationship["outgoingRelations"]
|
||||
): EndpointRelation[] =>
|
||||
relationships?.flatMap<EndpointRelation>(({ relationTo, value }) => {
|
||||
if (!isPayloadType(value)) return [];
|
||||
switch (relationTo) {
|
||||
case Collections.Folders:
|
||||
return { type: Collections.Folders, value: convertFolderToEndpointFolderPreview(value) };
|
||||
// TODO: Handle URL sources
|
||||
export const convertSourceToEndpointSource = ({
|
||||
collectibles,
|
||||
folders,
|
||||
gallery,
|
||||
scans,
|
||||
}: {
|
||||
collectibles?: (string | Collectible)[] | null | undefined;
|
||||
scans?: (string | Collectible)[] | null | undefined;
|
||||
gallery?: (string | Collectible)[] | null | undefined;
|
||||
folders?: (string | Folder)[] | null | undefined;
|
||||
}): EndpointSource[] => {
|
||||
const result: EndpointSource[] = [];
|
||||
|
||||
case Collections.Pages:
|
||||
return { type: Collections.Pages, value: convertPageToEndpointPagePreview(value) };
|
||||
const convertFolderToEndpointSourcePreview = ({
|
||||
id,
|
||||
slug,
|
||||
translations,
|
||||
}: Folder): EndpointSourcePreview => ({
|
||||
id,
|
||||
slug,
|
||||
translations: translations.map(({ language, name }) => ({
|
||||
language: isPayloadType(language) ? language.id : language,
|
||||
title: name,
|
||||
})),
|
||||
});
|
||||
|
||||
case Collections.Collectibles:
|
||||
return {
|
||||
type: Collections.Collectibles,
|
||||
value: convertCollectibleToEndpointCollectiblePreview(value),
|
||||
};
|
||||
const convertCollectibleToEndpointSourcePreview = ({
|
||||
id,
|
||||
slug,
|
||||
translations,
|
||||
}: Collectible): EndpointSourcePreview => ({
|
||||
id,
|
||||
slug,
|
||||
translations: translations.map(({ language, title, pretitle, subtitle }) => ({
|
||||
language: isPayloadType(language) ? language.id : language,
|
||||
title,
|
||||
...(isNotEmpty(pretitle) ? { pretitle } : {}),
|
||||
...(isNotEmpty(subtitle) ? { subtitle } : {}),
|
||||
})),
|
||||
});
|
||||
|
||||
case Collections.Images:
|
||||
if (!isImage(value)) return [];
|
||||
return { type: Collections.Images, value: convertImageToEndpointImagePreview(value) };
|
||||
if (collectibles && isPayloadArrayType(collectibles)) {
|
||||
collectibles.filter(isPublished).forEach((collectible) => {
|
||||
result.push({
|
||||
type: "collectible",
|
||||
collectible: convertCollectibleToEndpointSourcePreview(collectible),
|
||||
});
|
||||
});
|
||||
}
|
||||
|
||||
case Collections.Videos:
|
||||
if (!isVideo(value)) return [];
|
||||
return { type: Collections.Videos, value: convertVideoToEndpointVideoPreview(value) };
|
||||
if (scans && isPayloadArrayType(scans)) {
|
||||
scans.filter(isPublished).forEach((collectible) => {
|
||||
result.push({
|
||||
type: "scans",
|
||||
collectible: convertCollectibleToEndpointSourcePreview(collectible),
|
||||
});
|
||||
});
|
||||
}
|
||||
|
||||
case Collections.Audios:
|
||||
if (!isAudio(value)) return [];
|
||||
return { type: Collections.Audios, value: convertAudioToEndpointAudioPreview(value) };
|
||||
if (gallery && isPayloadArrayType(gallery)) {
|
||||
gallery.filter(isPublished).forEach((collectible) => {
|
||||
result.push({
|
||||
type: "gallery",
|
||||
collectible: convertCollectibleToEndpointSourcePreview(collectible),
|
||||
});
|
||||
});
|
||||
}
|
||||
|
||||
case Collections.Files:
|
||||
if (!isFile(value)) return [];
|
||||
return { type: Collections.Files, value: convertFileToEndpointFilePreview(value) };
|
||||
if (folders && isPayloadArrayType(folders)) {
|
||||
folders.forEach((folder) => {
|
||||
result.push({
|
||||
type: "folder",
|
||||
folder: convertFolderToEndpointSourcePreview(folder),
|
||||
});
|
||||
});
|
||||
}
|
||||
|
||||
case Collections.Recorders:
|
||||
return {
|
||||
type: Collections.Recorders,
|
||||
value: convertRecorderToEndpointRecorderPreview(value),
|
||||
};
|
||||
|
||||
case Collections.ChronologyEvents:
|
||||
return { type: Collections.ChronologyEvents, value: convertEventToEndpointEvent(value) };
|
||||
|
||||
case Collections.MediaThumbnails:
|
||||
case Collections.VideosSubtitles:
|
||||
case Collections.VideosChannels:
|
||||
case Collections.Scans:
|
||||
case Collections.Tags:
|
||||
case Collections.Attributes:
|
||||
case Collections.CreditsRole:
|
||||
case Collections.Languages:
|
||||
case Collections.Currencies:
|
||||
case Collections.Wordings:
|
||||
case Collections.GenericContents:
|
||||
default:
|
||||
return [];
|
||||
}
|
||||
}) ?? [];
|
||||
return result;
|
||||
};
|
||||
|
||||
export const getDomainFromUrl = (url: string): string => {
|
||||
const urlObject = new URL(url);
|
||||
|
|
|
@ -1,8 +1,8 @@
|
|||
import { ImageSize } from "payload/dist/uploads/types";
|
||||
import { CollectionConfig } from "payload/types";
|
||||
import { publicAccess } from "../accesses/publicAccess";
|
||||
import { BuildCollectionConfig, buildCollectionConfig } from "./collectionConfig";
|
||||
import { CollectionGroups } from "../shared/payload/constants";
|
||||
import { publicAccess } from "src/accesses/publicAccess";
|
||||
import { CollectionGroups } from "src/shared/payload/constants";
|
||||
import { BuildCollectionConfig, buildCollectionConfig } from "src/utils/collectionConfig";
|
||||
|
||||
const fields = {
|
||||
filename: "filename",
|
||||
|
|
|
@ -1,6 +1,6 @@
|
|||
import payload, { GeneratedTypes } from "payload";
|
||||
import { StrapiImage } from "../types/strapi";
|
||||
import { isDefined } from "./asserts";
|
||||
import { StrapiImage } from "src/types/strapi";
|
||||
import { isDefined } from "src/utils/asserts";
|
||||
|
||||
type UploadStrapiImage = {
|
||||
image: StrapiImage;
|
||||
|
|
|
@ -1,12 +1,12 @@
|
|||
import tags from "language-tags";
|
||||
import { isUndefined } from "./asserts";
|
||||
import { RichTextContent } from "../shared/payload/rich-text";
|
||||
import { RichTextContent } from "src/shared/payload/rich-text";
|
||||
import { isUndefined } from "src/utils/asserts";
|
||||
|
||||
export const shortenEllipsis = (text: string, length: number): string =>
|
||||
text.length - 3 > length ? `${text.substring(0, length)}...` : text;
|
||||
|
||||
export const formatLanguageCode = (code: string): string =>
|
||||
tags(code).valid() ? (tags(code).language()?.descriptions()[0] ?? code) : code;
|
||||
tags(code).valid() ? tags(code).language()?.descriptions()[0] ?? code : code;
|
||||
|
||||
export const capitalize = (string: string): string => {
|
||||
const [firstLetter, ...otherLetters] = string;
|
||||
|
|
|
@ -1,6 +1,6 @@
|
|||
import { CollectionBeforeChangeHook, CollectionConfig, RelationshipField } from "payload/types";
|
||||
import { BuildCollectionConfig, buildCollectionConfig } from "./collectionConfig";
|
||||
import { Collections } from "../shared/payload/constants";
|
||||
import { Collections } from "src/shared/payload/constants";
|
||||
import { BuildCollectionConfig, buildCollectionConfig } from "src/utils/collectionConfig";
|
||||
|
||||
const fields = { updatedBy: "updatedBy" };
|
||||
|
||||
|
|
|
@ -32,7 +32,7 @@
|
|||
"module": "commonjs" /* Specify what module code is generated. */,
|
||||
"rootDir": "./src" /* Specify the root folder within your source files. */,
|
||||
// "moduleResolution": "node10", /* Specify how TypeScript looks up a file from a given module specifier. */
|
||||
// "baseUrl": "./", /* Specify the base directory to resolve non-relative module names. */
|
||||
"baseUrl": "." /* Specify the base directory to resolve non-relative module names. */,
|
||||
"paths": {
|
||||
"payload/generated-types": ["./src/payload-types.ts"]
|
||||
} /* Specify a set of entries that re-map imports to additional lookup locations. */,
|
||||
|
@ -116,6 +116,7 @@
|
|||
"exclude": ["node_modules", "dist", "build"],
|
||||
"ts-node": {
|
||||
"transpileOnly": true,
|
||||
"swc": true
|
||||
"swc": true,
|
||||
"require": ["tsconfig-paths/register"]
|
||||
}
|
||||
}
|
||||
|
|
Loading…
Reference in New Issue