Lots of things, again

This commit is contained in:
DrMint 2023-08-14 14:03:08 +02:00
parent d9f84f59a8
commit f56ba4675f
43 changed files with 2505 additions and 1907 deletions

70
package-lock.json generated
View File

@ -12,15 +12,10 @@
"@fontsource/vollkorn": "^5.0.8", "@fontsource/vollkorn": "^5.0.8",
"clean-deep": "^3.4.0", "clean-deep": "^3.4.0",
"cross-env": "^7.0.3", "cross-env": "^7.0.3",
"dotenv": "^16.3.1",
"express": "^4.18.2",
"language-tags": "^1.0.8", "language-tags": "^1.0.8",
"luxon": "^3.4.0", "luxon": "^3.4.0",
"payload": "^1.13.3", "payload": "^1.13.3",
"qs": "^6.11.2", "styled-components": "^6.0.7"
"slugify": "^1.6.6",
"styled-components": "^6.0.7",
"unset-value": "^2.0.1"
}, },
"devDependencies": { "devDependencies": {
"@types/dotenv": "^8.2.0", "@types/dotenv": "^8.2.0",
@ -6887,6 +6882,7 @@
"version": "16.3.1", "version": "16.3.1",
"resolved": "https://registry.npmjs.org/dotenv/-/dotenv-16.3.1.tgz", "resolved": "https://registry.npmjs.org/dotenv/-/dotenv-16.3.1.tgz",
"integrity": "sha512-IPzF4w4/Rd94bA9imS68tZBaYyBWSCE47V1RGuMrB94iyTOIEwRmVL2x/4An+6mETpLrKJ5hQkB8W4kFAadeIQ==", "integrity": "sha512-IPzF4w4/Rd94bA9imS68tZBaYyBWSCE47V1RGuMrB94iyTOIEwRmVL2x/4An+6mETpLrKJ5hQkB8W4kFAadeIQ==",
"dev": true,
"engines": { "engines": {
"node": ">=12" "node": ">=12"
}, },
@ -7565,17 +7561,6 @@
"url": "https://github.com/privatenumber/get-tsconfig?sponsor=1" "url": "https://github.com/privatenumber/get-tsconfig?sponsor=1"
} }
}, },
"node_modules/get-value": {
"version": "3.0.1",
"resolved": "https://registry.npmjs.org/get-value/-/get-value-3.0.1.tgz",
"integrity": "sha512-mKZj9JLQrwMBtj5wxi6MH8Z5eSKaERpAwjg43dPtlGI1ZVEgH/qC7T8/6R2OBSUA+zzHBZgICsVJaEIV2tKTDA==",
"dependencies": {
"isobject": "^3.0.1"
},
"engines": {
"node": ">=6.0"
}
},
"node_modules/github-from-package": { "node_modules/github-from-package": {
"version": "0.0.0", "version": "0.0.0",
"resolved": "https://registry.npmjs.org/github-from-package/-/github-from-package-0.0.0.tgz", "resolved": "https://registry.npmjs.org/github-from-package/-/github-from-package-0.0.0.tgz",
@ -7817,29 +7802,6 @@
"url": "https://github.com/sponsors/ljharb" "url": "https://github.com/sponsors/ljharb"
} }
}, },
"node_modules/has-value": {
"version": "2.0.2",
"resolved": "https://registry.npmjs.org/has-value/-/has-value-2.0.2.tgz",
"integrity": "sha512-ybKOlcRsK2MqrM3Hmz/lQxXHZ6ejzSPzpNabKB45jb5qDgJvKPa3SdapTsTLwEb9WltgWpOmNax7i+DzNOk4TA==",
"dependencies": {
"get-value": "^3.0.0",
"has-values": "^2.0.1"
},
"engines": {
"node": ">=6"
}
},
"node_modules/has-values": {
"version": "2.0.1",
"resolved": "https://registry.npmjs.org/has-values/-/has-values-2.0.1.tgz",
"integrity": "sha512-+QdH3jOmq9P8GfdjFg0eJudqx1FqU62NQJ4P16rOEHeRdl7ckgwn6uqQjzYE0ZoHVV/e5E2esuJ5Gl5+HUW19w==",
"dependencies": {
"kind-of": "^6.0.2"
},
"engines": {
"node": ">=6"
}
},
"node_modules/he": { "node_modules/he": {
"version": "1.2.0", "version": "1.2.0",
"resolved": "https://registry.npmjs.org/he/-/he-1.2.0.tgz", "resolved": "https://registry.npmjs.org/he/-/he-1.2.0.tgz",
@ -12644,14 +12606,6 @@
"resolved": "https://registry.npmjs.org/tiny-invariant/-/tiny-invariant-1.0.6.tgz", "resolved": "https://registry.npmjs.org/tiny-invariant/-/tiny-invariant-1.0.6.tgz",
"integrity": "sha512-FOyLWWVjG+aC0UqG76V53yAWdXfH8bO6FNmyZOuUrzDzK8DI3/JRY25UD7+g49JWM1LXwymsKERB+DzI0dTEQA==" "integrity": "sha512-FOyLWWVjG+aC0UqG76V53yAWdXfH8bO6FNmyZOuUrzDzK8DI3/JRY25UD7+g49JWM1LXwymsKERB+DzI0dTEQA=="
}, },
"node_modules/slugify": {
"version": "1.6.6",
"resolved": "https://registry.npmjs.org/slugify/-/slugify-1.6.6.tgz",
"integrity": "sha512-h+z7HKHYXj6wJU+AnS/+IH8Uh9fdcX1Lrhg1/VMdf9PwoBQXFcXiAdsy2tSK0P6gKwJLXp02r90ahUCqHk9rrw==",
"engines": {
"node": ">=8.0.0"
}
},
"node_modules/smart-buffer": { "node_modules/smart-buffer": {
"version": "4.2.0", "version": "4.2.0",
"resolved": "https://registry.npmjs.org/smart-buffer/-/smart-buffer-4.2.0.tgz", "resolved": "https://registry.npmjs.org/smart-buffer/-/smart-buffer-4.2.0.tgz",
@ -13540,26 +13494,6 @@
"node": ">= 0.8" "node": ">= 0.8"
} }
}, },
"node_modules/unset-value": {
"version": "2.0.1",
"resolved": "https://registry.npmjs.org/unset-value/-/unset-value-2.0.1.tgz",
"integrity": "sha512-2hvrBfjUE00PkqN+q0XP6yRAOGrR06uSiUoIQGZkc7GxvQ9H7v8quUPNtZjMg4uux69i8HWpIjLPUKwCuRGyNg==",
"dependencies": {
"has-value": "^2.0.2",
"isobject": "^4.0.0"
},
"engines": {
"node": ">=10"
}
},
"node_modules/unset-value/node_modules/isobject": {
"version": "4.0.0",
"resolved": "https://registry.npmjs.org/isobject/-/isobject-4.0.0.tgz",
"integrity": "sha512-S/2fF5wH8SJA/kmwr6HYhK/RI/OkhD84k8ntalo0iJjZikgq1XFvR5M8NPT1x5F7fBwCG3qHfnzeP/Vh/ZxCUA==",
"engines": {
"node": ">=0.10.0"
}
},
"node_modules/untildify": { "node_modules/untildify": {
"version": "4.0.0", "version": "4.0.0",
"resolved": "https://registry.npmjs.org/untildify/-/untildify-4.0.0.tgz", "resolved": "https://registry.npmjs.org/untildify/-/untildify-4.0.0.tgz",

View File

@ -24,15 +24,10 @@
"@fontsource/vollkorn": "^5.0.8", "@fontsource/vollkorn": "^5.0.8",
"clean-deep": "^3.4.0", "clean-deep": "^3.4.0",
"cross-env": "^7.0.3", "cross-env": "^7.0.3",
"dotenv": "^16.3.1",
"express": "^4.18.2",
"language-tags": "^1.0.8", "language-tags": "^1.0.8",
"luxon": "^3.4.0", "luxon": "^3.4.0",
"payload": "^1.13.3", "payload": "^1.13.3",
"qs": "^6.11.2", "styled-components": "^6.0.7"
"slugify": "^1.6.6",
"styled-components": "^6.0.7",
"unset-value": "^2.0.1"
}, },
"devDependencies": { "devDependencies": {
"@types/dotenv": "^8.2.0", "@types/dotenv": "^8.2.0",

View File

@ -1,10 +1,13 @@
import { CollectionConfig } from "payload/types"; import { CollectionConfig } from "payload/types";
import { mustBeAdmin } from "../../accesses/mustBeAdmin"; import { mustBeAdmin } from "../../accesses/mustBeAdmin";
import { CollectionGroups, Collections } from "../../constants"; import { CollectionGroups, Collections } from "../../constants";
import { backPropagationField } from "../../fields/backPropagationField/backPropagationField";
import { slugField } from "../../fields/slugField/slugField"; import { slugField } from "../../fields/slugField/slugField";
import { localizedFields } from "../../fields/translatedFields/translatedFields"; import { translatedFields } from "../../fields/translatedFields/translatedFields";
import { buildCollectionConfig } from "../../utils/collectionConfig"; import { buildCollectionConfig } from "../../utils/collectionConfig";
import { importFromStrapi } from "./endpoints/importFromStrapi"; import { importFromStrapi } from "./endpoints/importFromStrapi";
import { beforeValidateEndingGreaterThanStarting } from "./hooks/beforeValidateEndingGreaterThanStarting";
import { beforeValidateNoIntersection } from "./hooks/beforeValidateNoIntersection";
const fields = { const fields = {
slug: "slug", slug: "slug",
@ -13,15 +16,15 @@ const fields = {
translations: "translations", translations: "translations",
translationsTitle: "title", translationsTitle: "title",
translationsDescription: "description", translationsDescription: "description",
events: "events",
} as const satisfies Record<string, string>; } as const satisfies Record<string, string>;
export const ChronologyEras: CollectionConfig = buildCollectionConfig( export const ChronologyEras: CollectionConfig = buildCollectionConfig({
Collections.ChronologyEras, slug: Collections.ChronologyEras,
{ labels: {
singular: "Chronology Era", singular: "Chronology Era",
plural: "Chronology Eras", plural: "Chronology Eras",
}, },
() => ({
defaultSort: fields.startingYear, defaultSort: fields.startingYear,
admin: { admin: {
group: CollectionGroups.Collections, group: CollectionGroups.Collections,
@ -32,6 +35,9 @@ export const ChronologyEras: CollectionConfig = buildCollectionConfig(
create: mustBeAdmin, create: mustBeAdmin,
delete: mustBeAdmin, delete: mustBeAdmin,
}, },
hooks: {
beforeValidate: [beforeValidateEndingGreaterThanStarting, beforeValidateNoIntersection],
},
endpoints: [importFromStrapi], endpoints: [importFromStrapi],
fields: [ fields: [
slugField({ name: fields.slug }), slugField({ name: fields.slug }),
@ -54,7 +60,7 @@ export const ChronologyEras: CollectionConfig = buildCollectionConfig(
}, },
], ],
}, },
localizedFields({ translatedFields({
name: fields.translations, name: fields.translations,
admin: { useAsTitle: fields.translationsTitle }, admin: { useAsTitle: fields.translationsTitle },
fields: [ fields: [
@ -65,6 +71,16 @@ export const ChronologyEras: CollectionConfig = buildCollectionConfig(
}, },
], ],
}), }),
backPropagationField({
name: fields.events,
hasMany: true,
relationTo: Collections.ChronologyItems,
where: ({ startingYear, endingYear }) => ({
and: [
{ "date.year": { greater_than_equal: startingYear } },
{ "date.year": { less_than_equal: endingYear } },
], ],
}) }),
); }),
],
});

View File

@ -0,0 +1,10 @@
import { CollectionBeforeValidateHook } from "payload/types";
import { ChronologyEra } from "../../../types/collections";
export const beforeValidateEndingGreaterThanStarting: CollectionBeforeValidateHook<
ChronologyEra
> = async ({ data: { startingYear, endingYear } }) => {
if (endingYear < startingYear) {
throw new Error("The ending year cannot be before the starting year.");
}
};

View File

@ -0,0 +1,23 @@
import payload from "payload";
import { CollectionBeforeValidateHook } from "payload/types";
import { Collections } from "../../../constants";
import { ChronologyEra } from "../../../types/collections";
import { hasIntersection } from "../../../utils/asserts";
export const beforeValidateNoIntersection: CollectionBeforeValidateHook<ChronologyEra> = async ({
data: { startingYear, endingYear },
}) => {
const otherEras = await payload.find({
collection: Collections.ChronologyEras,
limit: 100,
});
otherEras.docs.forEach((otherEra: ChronologyEra) => {
if (hasIntersection([startingYear, endingYear], [otherEra.startingYear, otherEra.endingYear])) {
throw new Error(
`This era (${startingYear} -> ${endingYear}) is intersecting with the era\
"${otherEra.slug}" (${otherEra.startingYear} -> ${otherEra.endingYear})`
);
}
});
};

View File

@ -6,32 +6,34 @@ import {
publishStatusFilters, publishStatusFilters,
} from "../../components/QuickFilters"; } from "../../components/QuickFilters";
import { CollectionGroups, Collections } from "../../constants"; import { CollectionGroups, Collections } from "../../constants";
import { localizedFields } from "../../fields/translatedFields/translatedFields"; import { translatedFields } from "../../fields/translatedFields/translatedFields";
import { isDefined, isUndefined } from "../../utils/asserts"; import { isEmpty, isUndefined } from "../../utils/asserts";
import { buildVersionedCollectionConfig } from "../../utils/versionedCollectionConfig"; import { buildVersionedCollectionConfig } from "../../utils/versionedCollectionConfig";
import { importFromStrapi } from "./endpoints/importFromStrapi"; import { importFromStrapi } from "./endpoints/importFromStrapi";
import { beforeValidatePopulateNameField } from "./hooks/beforeValidatePopulateNameField";
const fields = { const fields = {
name: "name", name: "name",
events: "events", events: "events",
eventsSource: "source",
eventsTranslations: "translations", eventsTranslations: "translations",
eventsTranslationsTitle: "title", eventsTranslationsTitle: "title",
eventsTranslationsDescription: "description", eventsTranslationsDescription: "description",
eventsTranslationsNotes: "notes", eventsTranslationsNotes: "notes",
date: "date", date: "date",
year: "year", dateYear: "year",
month: "month", dateMonth: "month",
day: "day", dateDay: "day",
era: "era",
status: "_status", status: "_status",
} as const satisfies Record<string, string>; } as const satisfies Record<string, string>;
export const ChronologyItems: CollectionConfig = buildVersionedCollectionConfig( export const ChronologyItems: CollectionConfig = buildVersionedCollectionConfig({
Collections.ChronologyItems, slug: Collections.ChronologyItems,
{ labels: {
singular: "Chronology Item", singular: "Chronology Item",
plural: "Chronology Items", plural: "Chronology Items",
}, },
() => ({
defaultSort: fields.name, defaultSort: fields.name,
admin: { admin: {
group: CollectionGroups.Collections, group: CollectionGroups.Collections,
@ -57,45 +59,33 @@ export const ChronologyItems: CollectionConfig = buildVersionedCollectionConfig(
type: "text", type: "text",
admin: { hidden: true }, admin: { hidden: true },
hooks: { hooks: {
beforeValidate: [ beforeValidate: [beforeValidatePopulateNameField],
({
data: {
date: { year, month, day },
},
}) =>
[
String(year ?? "?????").padStart(5, "0"),
String(month ?? "??").padStart(2, "0"),
String(day ?? "??").padStart(2, "0"),
].join("-"),
],
}, },
}, },
{ {
type: "group", type: "group",
name: fields.date, name: fields.date,
validate: ({ year, month, day } = {}) => { validate: ({ year, month, day } = {}) => {
if (isDefined(day)) { if (isUndefined(day)) return true;
if (isUndefined(month)) return "A month is required if a day is set"; if (isUndefined(month)) return "A month is required if a day is set";
const stringDate = `${year}/${month}/${day}`; const stringDate = `${year}/${month}/${day}`;
if (!DateTime.fromObject({ year, month, day }).isValid) if (!DateTime.fromObject({ year, month, day }).isValid) {
return `The given date (${stringDate}) is not a valid date.`; return `The given date (${stringDate}) is not a valid date.`;
} }
return true;
}, },
fields: [ fields: [
{ {
type: "row", type: "row",
fields: [ fields: [
{ {
name: fields.year, name: fields.dateYear,
type: "number", type: "number",
required: true, required: true,
min: 0, min: 0,
admin: { width: "33%" }, admin: { width: "33%" },
}, },
{ name: fields.month, type: "number", min: 1, max: 12, admin: { width: "33%" } }, { name: fields.dateMonth, type: "number", min: 1, max: 12, admin: { width: "33%" } },
{ name: fields.day, type: "number", min: 1, max: 31, admin: { width: "33%" } }, { name: fields.dateDay, type: "number", min: 1, max: 31, admin: { width: "33%" } },
], ],
}, },
], ],
@ -103,18 +93,50 @@ export const ChronologyItems: CollectionConfig = buildVersionedCollectionConfig(
{ {
name: fields.events, name: fields.events,
type: "array", type: "array",
required: true,
minRows: 1,
fields: [ fields: [
localizedFields({ {
name: fields.eventsSource,
type: "relationship",
relationTo: [Collections.Contents, Collections.LibraryItems],
// required: true,
admin: { allowCreate: false },
},
translatedFields({
name: fields.eventsTranslations, name: fields.eventsTranslations,
admin: { useAsTitle: fields.eventsTranslationsTitle }, required: true,
minRows: 1,
admin: {
useAsTitle: fields.eventsTranslationsTitle,
hasSourceLanguage: true,
hasCredits: true,
},
fields: [ fields: [
{ name: fields.eventsTranslationsTitle, type: "text" }, {
{ name: fields.eventsTranslationsDescription, type: "textarea" }, name: fields.eventsTranslationsTitle,
validate: (_, { siblingData: { description, title } }) => {
if (isEmpty(description) && isEmpty(title)) {
return "This field is required if no description is set.";
}
return true;
},
type: "text",
},
{
name: fields.eventsTranslationsDescription,
validate: (_, { siblingData: { description, title } }) => {
if (isEmpty(description) && isEmpty(title)) {
return "This field is required if no title is set.";
}
return true;
},
type: "textarea",
},
{ name: fields.eventsTranslationsNotes, type: "textarea" }, { name: fields.eventsTranslationsNotes, type: "textarea" },
], ],
}), }),
], ],
}, },
], ],
}) });
);

View File

@ -11,7 +11,7 @@ export const importFromStrapi = createStrapiImportEndpoint<ChronologyItem>({
}, },
payload: { payload: {
collection: Collections.ChronologyItems, collection: Collections.ChronologyItems,
convert: ({ year, month, day, events }) => ({ convert: ({ year, month, day, events }, user) => ({
date: { year, month, day }, date: { year, month, day },
events: events.map((event) => ({ events: events.map((event) => ({
translations: event.translations.map(({ title, description, note, language }) => ({ translations: event.translations.map(({ title, description, note, language }) => ({
@ -19,6 +19,10 @@ export const importFromStrapi = createStrapiImportEndpoint<ChronologyItem>({
description, description,
note, note,
language: language.data.attributes.code, language: language.data.attributes.code,
sourceLanguage: "en",
...(language.data.attributes.code === "en"
? { transcribers: [user.id] }
: { translators: [user.id] }),
})), })),
})), })),
}), }),

View File

@ -0,0 +1,20 @@
import { FieldHook } from "payload/dist/fields/config/types";
import { ChronologyItem } from "../../../types/collections";
import { isDefined, isUndefined } from "../../../utils/asserts";
export const beforeValidatePopulateNameField: FieldHook<
ChronologyItem,
ChronologyItem["name"],
ChronologyItem
> = ({ data: { date } }) => {
if (isUndefined(date?.year)) return "????-??-??";
const { year, month, day } = date;
let result = String(year).padStart(5, " ");
if (isDefined(month)) {
result += `-${String(date.month).padStart(2, "0")}`;
if (isDefined(day)) {
result += `-${String(date.day).padStart(2, "0")}`;
}
}
return result;
};

View File

@ -1,8 +1,9 @@
import { CollectionGroups, Collections, FileTypes, KeysTypes } from "../../constants"; import { CollectionGroups, Collections, FileTypes, KeysTypes } from "../../constants";
import { fileField } from "../../fields/fileField/fileField"; import { fileField } from "../../fields/fileField/fileField";
import { imageField } from "../../fields/imageField/imageField"; import { imageField } from "../../fields/imageField/imageField";
import { keysField } from "../../fields/keysField/keysField";
import { slugField } from "../../fields/slugField/slugField"; import { slugField } from "../../fields/slugField/slugField";
import { localizedFields } from "../../fields/translatedFields/translatedFields"; import { translatedFields } from "../../fields/translatedFields/translatedFields";
import { beforeDuplicateAddCopyTo } from "../../hooks/beforeDuplicateAddCopyTo"; import { beforeDuplicateAddCopyTo } from "../../hooks/beforeDuplicateAddCopyTo";
import { beforeDuplicatePiping } from "../../hooks/beforeDuplicatePiping"; import { beforeDuplicatePiping } from "../../hooks/beforeDuplicatePiping";
import { beforeDuplicateUnpublish } from "../../hooks/beforeDuplicateUnpublish"; import { beforeDuplicateUnpublish } from "../../hooks/beforeDuplicateUnpublish";
@ -33,13 +34,12 @@ const fields = {
updatedBy: "updatedBy", updatedBy: "updatedBy",
} as const satisfies Record<string, string>; } as const satisfies Record<string, string>;
export const Contents = buildVersionedCollectionConfig( export const Contents = buildVersionedCollectionConfig({
Collections.Contents, slug: Collections.Contents,
{ labels: {
singular: "Content", singular: "Content",
plural: "Contents", plural: "Contents",
}, },
() => ({
defaultSort: fields.slug, defaultSort: fields.slug,
admin: { admin: {
useAsTitle: fields.slug, useAsTitle: fields.slug,
@ -77,24 +77,20 @@ export const Contents = buildVersionedCollectionConfig(
{ {
type: "row", type: "row",
fields: [ fields: [
{ keysField({
name: fields.categories, name: fields.categories,
type: "relationship", relationTo: KeysTypes.Categories,
relationTo: [Collections.Keys],
filterOptions: { type: { equals: KeysTypes.Categories } },
hasMany: true, hasMany: true,
admin: { allowCreate: false, width: "50%" }, admin: { allowCreate: false, width: "50%" },
}, }),
{ keysField({
name: fields.type, name: fields.type,
type: "relationship", relationTo: KeysTypes.Contents,
relationTo: [Collections.Keys],
filterOptions: { type: { equals: KeysTypes.Contents } },
admin: { allowCreate: false, width: "50%" }, admin: { allowCreate: false, width: "50%" },
}, }),
], ],
}, },
localizedFields({ translatedFields({
name: fields.translations, name: fields.translations,
admin: { useAsTitle: fields.title, hasSourceLanguage: true }, admin: { useAsTitle: fields.title, hasSourceLanguage: true },
required: true, required: true,
@ -218,5 +214,4 @@ export const Contents = buildVersionedCollectionConfig(
], ],
}), }),
], ],
}) });
);

View File

@ -1,6 +1,6 @@
import { CollectionGroups, Collections } from "../../constants"; import { CollectionGroups, Collections } from "../../constants";
import { slugField } from "../../fields/slugField/slugField"; import { slugField } from "../../fields/slugField/slugField";
import { localizedFields } from "../../fields/translatedFields/translatedFields"; import { translatedFields } from "../../fields/translatedFields/translatedFields";
import { buildCollectionConfig } from "../../utils/collectionConfig"; import { buildCollectionConfig } from "../../utils/collectionConfig";
const fields = { const fields = {
@ -11,13 +11,12 @@ const fields = {
contents: "contents", contents: "contents",
} as const satisfies Record<string, string>; } as const satisfies Record<string, string>;
export const ContentsFolders = buildCollectionConfig( export const ContentsFolders = buildCollectionConfig({
Collections.ContentsFolders, slug: Collections.ContentsFolders,
{ labels: {
singular: "Contents Folder", singular: "Contents Folder",
plural: "Contents Folders", plural: "Contents Folders",
}, },
() => ({
defaultSort: fields.slug, defaultSort: fields.slug,
admin: { admin: {
useAsTitle: fields.slug, useAsTitle: fields.slug,
@ -29,7 +28,7 @@ export const ContentsFolders = buildCollectionConfig(
versions: false, versions: false,
fields: [ fields: [
slugField({ name: fields.slug }), slugField({ name: fields.slug }),
localizedFields({ translatedFields({
name: fields.translations, name: fields.translations,
interfaceName: "ContentFoldersTranslation", interfaceName: "ContentFoldersTranslation",
admin: { admin: {
@ -57,5 +56,4 @@ export const ContentsFolders = buildCollectionConfig(
], ],
}, },
], ],
}) });
);

View File

@ -1,5 +1,5 @@
import { CollectionGroups, Collections } from "../../constants"; import { CollectionGroups, Collections } from "../../constants";
import { buildCollectionConfig } from "../../utils/collectionConfig"; import { buildImageCollectionConfig } from "../../utils/imageCollectionConfig";
const fields = { const fields = {
filename: "filename", filename: "filename",
@ -7,13 +7,12 @@ const fields = {
filesize: "filesize", filesize: "filesize",
} as const satisfies Record<string, string>; } as const satisfies Record<string, string>;
export const ContentsThumbnails = buildCollectionConfig( export const ContentsThumbnails = buildImageCollectionConfig({
Collections.ContentsThumbnails, slug: Collections.ContentsThumbnails,
{ labels: {
singular: "Contents Thumbnail", singular: "Contents Thumbnail",
plural: "Contents Thumbnails", plural: "Contents Thumbnails",
}, },
({ uploadDir }) => ({
defaultSort: fields.filename, defaultSort: fields.filename,
admin: { admin: {
useAsTitle: fields.filename, useAsTitle: fields.filename,
@ -21,8 +20,6 @@ export const ContentsThumbnails = buildCollectionConfig(
group: CollectionGroups.Media, group: CollectionGroups.Media,
}, },
upload: { upload: {
staticDir: uploadDir,
mimeTypes: ["image/*"],
imageSizes: [ imageSizes: [
{ {
name: "og", name: "og",
@ -45,5 +42,4 @@ export const ContentsThumbnails = buildCollectionConfig(
], ],
}, },
fields: [], fields: [],
}) });
);

View File

@ -8,13 +8,12 @@ const fields = {
id: "id", id: "id",
} as const satisfies Record<string, string>; } as const satisfies Record<string, string>;
export const Currencies = buildCollectionConfig( export const Currencies = buildCollectionConfig({
Collections.Currencies, slug: Collections.Currencies,
{ labels: {
singular: "Currency", singular: "Currency",
plural: "Currencies", plural: "Currencies",
}, },
() => ({
defaultSort: fields.id, defaultSort: fields.id,
admin: { admin: {
pagination: { defaultLimit: 100 }, pagination: { defaultLimit: 100 },
@ -40,5 +39,4 @@ export const Currencies = buildCollectionConfig(
}, },
}, },
], ],
}) });
);

View File

@ -6,13 +6,12 @@ const fields = {
type: "type", type: "type",
} as const satisfies Record<string, string>; } as const satisfies Record<string, string>;
export const Files = buildCollectionConfig( export const Files = buildCollectionConfig({
Collections.Files, slug: Collections.Files,
{ labels: {
singular: "File", singular: "File",
plural: "Files", plural: "Files",
}, },
() => ({
defaultSort: fields.filename, defaultSort: fields.filename,
admin: { admin: {
useAsTitle: fields.filename, useAsTitle: fields.filename,
@ -32,5 +31,4 @@ export const Files = buildCollectionConfig(
options: Object.entries(FileTypes).map(([value, label]) => ({ label, value })), options: Object.entries(FileTypes).map(([value, label]) => ({ label, value })),
}, },
], ],
}) });
);

View File

@ -2,7 +2,7 @@ import payload from "payload";
import { mustBeAdmin } from "../../accesses/mustBeAdmin"; import { mustBeAdmin } from "../../accesses/mustBeAdmin";
import { QuickFilters } from "../../components/QuickFilters"; import { QuickFilters } from "../../components/QuickFilters";
import { CollectionGroups, Collections, KeysTypes, LanguageCodes } from "../../constants"; import { CollectionGroups, Collections, KeysTypes, LanguageCodes } from "../../constants";
import { localizedFields } from "../../fields/translatedFields/translatedFields"; import { translatedFields } from "../../fields/translatedFields/translatedFields";
import { beforeDuplicateAddCopyTo } from "../../hooks/beforeDuplicateAddCopyTo"; import { beforeDuplicateAddCopyTo } from "../../hooks/beforeDuplicateAddCopyTo";
import { Key } from "../../types/collections"; import { Key } from "../../types/collections";
import { isDefined } from "../../utils/asserts"; import { isDefined } from "../../utils/asserts";
@ -19,13 +19,12 @@ const fields = {
const keysTypesWithShort: (keyof typeof KeysTypes)[] = ["Categories", "GamePlatforms"]; const keysTypesWithShort: (keyof typeof KeysTypes)[] = ["Categories", "GamePlatforms"];
export const Keys = buildCollectionConfig( export const Keys = buildCollectionConfig({
Collections.Keys, slug: Collections.Keys,
{ labels: {
singular: "Key", singular: "Key",
plural: "Keys", plural: "Keys",
}, },
() => ({
defaultSort: fields.name, defaultSort: fields.name,
admin: { admin: {
useAsTitle: fields.name, useAsTitle: fields.name,
@ -87,7 +86,7 @@ export const Keys = buildCollectionConfig(
required: true, required: true,
options: Object.entries(KeysTypes).map(([value, label]) => ({ label, value })), options: Object.entries(KeysTypes).map(([value, label]) => ({ label, value })),
}, },
localizedFields({ translatedFields({
name: fields.translations, name: fields.translations,
interfaceName: "CategoryTranslations", interfaceName: "CategoryTranslations",
admin: { admin: {
@ -117,5 +116,4 @@ export const Keys = buildCollectionConfig(
], ],
}), }),
], ],
}) });
);

View File

@ -10,13 +10,12 @@ const fields = {
name: "name", name: "name",
} as const satisfies Record<string, string>; } as const satisfies Record<string, string>;
export const Languages = buildCollectionConfig( export const Languages = buildCollectionConfig({
Collections.Languages, slug: Collections.Languages,
{ labels: {
singular: "Language", singular: "Language",
plural: "Languages", plural: "Languages",
}, },
() => ({
defaultSort: fields.name, defaultSort: fields.name,
admin: { admin: {
useAsTitle: fields.name, useAsTitle: fields.name,
@ -36,7 +35,8 @@ export const Languages = buildCollectionConfig(
required: true, required: true,
validate: (value, options) => { validate: (value, options) => {
if (!/^[a-z]{2}(-[a-z]{2})?$/g.test(value)) { if (!/^[a-z]{2}(-[a-z]{2})?$/g.test(value)) {
return "The code must be a valid BCP 47 language tag and lowercase (i.e: en, pt-pt, fr, zh-tw...)"; return "The code must be a valid BCP 47 language \
tag and lowercase (i.e: en, pt-pt, fr, zh-tw...)";
} }
return text(value, options); return text(value, options);
}, },
@ -48,5 +48,4 @@ export const Languages = buildCollectionConfig(
required: true, required: true,
}, },
], ],
}) });
);

View File

@ -7,35 +7,55 @@ import {
LibraryItemsTypes, LibraryItemsTypes,
} from "../../constants"; } from "../../constants";
import { imageField } from "../../fields/imageField/imageField"; import { imageField } from "../../fields/imageField/imageField";
import { keysField } from "../../fields/keysField/keysField";
import { optionalGroupField } from "../../fields/optionalGroupField/optionalGroupField"; import { optionalGroupField } from "../../fields/optionalGroupField/optionalGroupField";
import { slugField } from "../../fields/slugField/slugField"; import { slugField } from "../../fields/slugField/slugField";
import { translatedFields } from "../../fields/translatedFields/translatedFields";
import { beforeDuplicateAddCopyTo } from "../../hooks/beforeDuplicateAddCopyTo"; import { beforeDuplicateAddCopyTo } from "../../hooks/beforeDuplicateAddCopyTo";
import { beforeDuplicatePiping } from "../../hooks/beforeDuplicatePiping"; import { beforeDuplicatePiping } from "../../hooks/beforeDuplicatePiping";
import { beforeDuplicateUnpublish } from "../../hooks/beforeDuplicateUnpublish"; import { beforeDuplicateUnpublish } from "../../hooks/beforeDuplicateUnpublish";
import { LibraryItem } from "../../types/collections"; import { LibraryItem } from "../../types/collections";
import { isDefined } from "../../utils/asserts";
import { buildVersionedCollectionConfig } from "../../utils/versionedCollectionConfig"; import { buildVersionedCollectionConfig } from "../../utils/versionedCollectionConfig";
import { RowLabel } from "./components/RowLabel"; import { RowLabel } from "./components/RowLabel";
import { getBySlug } from "./endpoints/getBySlug"; import { getBySlug } from "./endpoints/getBySlug";
const fields = { const fields = {
status: "status", status: "_status",
slug: "slug", slug: "slug",
thumbnail: "thumbnail", thumbnail: "thumbnail",
pretitle: "pretitle", pretitle: "pretitle",
title: "title", title: "title",
subtitle: "subtitle", subtitle: "subtitle",
translations: "translations",
translationsDescription: "description",
rootItem: "rootItem", rootItem: "rootItem",
primary: "primary", primary: "primary",
digital: "digital", digital: "digital",
downloadable: "downloadable", downloadable: "downloadable",
size: "size", size: "size",
width: "width", width: "width",
height: "height", height: "height",
thickness: "thickness", thickness: "thickness",
price: "price", price: "price",
priceAmount: "amount", priceAmount: "amount",
priceCurrency: "currency", priceCurrency: "currency",
releaseDate: "releaseDate", releaseDate: "releaseDate",
gallery: "gallery",
galleryImage: "image",
urls: "urls",
urlsUrl: "url",
categories: "categories",
itemType: "itemType", itemType: "itemType",
textual: "textual", textual: "textual",
textualSubtype: "subtype", textualSubtype: "subtype",
@ -43,24 +63,51 @@ const fields = {
textualPageCount: "pageCount", textualPageCount: "pageCount",
textualPageOrder: "pageOrder", textualPageOrder: "pageOrder",
textualLanguages: "languages", textualLanguages: "languages",
audio: "audio", audio: "audio",
audioSubtype: "audioSubtype", audioSubtype: "audioSubtype",
scans: "scans", scans: "scans",
scansCover: "cover", scansCover: "cover",
scansCoverFlapFront: "flapFront",
scansCoverFront: "front", scansCoverFront: "front",
scansCoverSpine: "spine", scansCoverSpine: "spine",
scansCoverBack: "back", scansCoverBack: "back",
scansCoverFlapBack: "flapBack",
scansCoverInsideFlapFront: "insideFlapFront",
scansCoverInsideFront: "insideFront",
scansCoverInsideBack: "insideBack",
scansCoverInsideFlapBack: "insideFlapBack",
scansDustjacket: "dustjacket", scansDustjacket: "dustjacket",
scansDustjacketFlapFront: "flapFront",
scansDustjacketFront: "front", scansDustjacketFront: "front",
scansDustjacketSpine: "spine", scansDustjacketSpine: "spine",
scansDustjacketBack: "back", scansDustjacketBack: "back",
scansDustjacketFlapBack: "flapBack",
scansDustjacketInsideFlapFront: "insideFlapFront",
scansDustjacketInsideFront: "insideFront",
scansDustjacketInsideSpine: "insideSpine",
scansDustjacketInsideBack: "insideBack",
scansDustjacketInsideFlapBack: "insideFlapBack",
scansObi: "obi", scansObi: "obi",
scansObiFlapFront: "flapFront",
scansObiFront: "front", scansObiFront: "front",
scansObiSpine: "spine", scansObiSpine: "spine",
scansObiBack: "back", scansObiBack: "back",
scansObiFlapBack: "flapBack",
scansObiInsideFlapFront: "insideFlapFront",
scansObiInsideFront: "insideFront",
scansObiInsideSpine: "insideSpine",
scansObiInsideBack: "insideBack",
scansObiInsideFlapBack: "insideFlapBack",
scansPages: "pages", scansPages: "pages",
scansPagesPage: "page", scansPagesPage: "page",
scansPagesImage: "image", scansPagesImage: "image",
contents: "contents", contents: "contents",
contentsContent: "content", contentsContent: "content",
contentsPageStart: "pageStart", contentsPageStart: "pageStart",
@ -70,13 +117,12 @@ const fields = {
contentsNote: "note", contentsNote: "note",
} as const satisfies Record<string, string>; } as const satisfies Record<string, string>;
export const LibraryItems = buildVersionedCollectionConfig( export const LibraryItems = buildVersionedCollectionConfig({
Collections.LibraryItems, slug: Collections.LibraryItems,
{ labels: {
singular: "Library Item", singular: "Library Item",
plural: "Library Items", plural: "Library Items",
}, },
() => ({
defaultSort: fields.slug, defaultSort: fields.slug,
admin: { admin: {
useAsTitle: fields.slug, useAsTitle: fields.slug,
@ -94,11 +140,34 @@ export const LibraryItems = buildVersionedCollectionConfig(
preview: (doc) => `https://accords-library.com/library/${doc.slug}`, preview: (doc) => `https://accords-library.com/library/${doc.slug}`,
}, },
endpoints: [getBySlug], endpoints: [getBySlug],
fields: [
{
name: fields.itemType,
type: "radio",
options: Object.entries(LibraryItemsTypes).map(([value, label]) => ({
label,
value,
})),
admin: {
layout: "horizontal",
},
},
{
type: "tabs",
admin: {
condition: ({ itemType }) => isDefined(itemType),
},
tabs: [
{
label: "Overview",
fields: [ fields: [
{ {
type: "row", type: "row",
fields: [ fields: [
slugField({ name: fields.slug, admin: { width: "50%" } }), slugField({
name: fields.slug,
admin: { width: "50%" },
}),
imageField({ imageField({
name: fields.thumbnail, name: fields.thumbnail,
relationTo: Collections.LibraryItemsThumbnails, relationTo: Collections.LibraryItemsThumbnails,
@ -161,6 +230,25 @@ export const LibraryItems = buildVersionedCollectionConfig(
}, },
], ],
}, },
],
},
{
label: "Images",
fields: [
{
name: fields.gallery,
type: "array",
admin: {
description:
"Additional images of the item (unboxing, on shelf, promotional images...)",
},
fields: [
imageField({
name: fields.galleryImage,
relationTo: Collections.LibraryItemsGallery,
}),
],
},
optionalGroupField({ optionalGroupField({
name: fields.scans, name: fields.scans,
fields: [ fields: [
@ -172,21 +260,61 @@ export const LibraryItems = buildVersionedCollectionConfig(
fields: [ fields: [
imageField({ imageField({
name: fields.scansCoverFront, name: fields.scansCoverFront,
relationTo: Collections.LibraryItemsThumbnails, relationTo: Collections.LibraryItemsScans,
admin: { width: "33%" }, admin: { width: "33%" },
}), }),
imageField({ imageField({
name: fields.scansCoverSpine, name: fields.scansCoverSpine,
relationTo: Collections.LibraryItemsThumbnails, relationTo: Collections.LibraryItemsScans,
admin: { width: "33%" }, admin: { width: "33%" },
}), }),
imageField({ imageField({
name: fields.scansCoverBack, name: fields.scansCoverBack,
relationTo: Collections.LibraryItemsThumbnails, relationTo: Collections.LibraryItemsScans,
admin: { width: "33%" }, admin: { width: "33%" },
}), }),
], ],
}, },
{
type: "row",
fields: [
imageField({
name: fields.scansCoverInsideFront,
relationTo: Collections.LibraryItemsScans,
admin: { width: "50%" },
}),
imageField({
name: fields.scansCoverBack,
relationTo: Collections.LibraryItemsScans,
admin: { width: "50%" },
}),
],
},
{
type: "row",
fields: [
imageField({
name: fields.scansCoverFlapFront,
relationTo: Collections.LibraryItemsScans,
admin: { width: "25%" },
}),
imageField({
name: fields.scansCoverFlapBack,
relationTo: Collections.LibraryItemsScans,
admin: { width: "25%" },
}),
imageField({
name: fields.scansCoverInsideFlapFront,
relationTo: Collections.LibraryItemsScans,
admin: { width: "25%" },
}),
imageField({
name: fields.scansCoverInsideFlapBack,
relationTo: Collections.LibraryItemsScans,
admin: { width: "25%" },
}),
],
},
], ],
}), }),
optionalGroupField({ optionalGroupField({
@ -204,21 +332,66 @@ export const LibraryItems = buildVersionedCollectionConfig(
fields: [ fields: [
imageField({ imageField({
name: fields.scansDustjacketFront, name: fields.scansDustjacketFront,
relationTo: Collections.LibraryItemsThumbnails, relationTo: Collections.LibraryItemsScans,
admin: { width: "33%" }, admin: { width: "33%" },
}), }),
imageField({ imageField({
name: fields.scansDustjacketSpine, name: fields.scansDustjacketSpine,
relationTo: Collections.LibraryItemsThumbnails, relationTo: Collections.LibraryItemsScans,
admin: { width: "33%" }, admin: { width: "33%" },
}), }),
imageField({ imageField({
name: fields.scansDustjacketBack, name: fields.scansDustjacketBack,
relationTo: Collections.LibraryItemsThumbnails, relationTo: Collections.LibraryItemsScans,
admin: { width: "33%" }, admin: { width: "33%" },
}), }),
], ],
}, },
{
type: "row",
fields: [
imageField({
name: fields.scansDustjacketInsideFront,
relationTo: Collections.LibraryItemsScans,
admin: { width: "33%" },
}),
imageField({
name: fields.scansDustjacketInsideSpine,
relationTo: Collections.LibraryItemsScans,
admin: { width: "33%" },
}),
imageField({
name: fields.scansDustjacketInsideBack,
relationTo: Collections.LibraryItemsScans,
admin: { width: "33%" },
}),
],
},
{
type: "row",
fields: [
imageField({
name: fields.scansDustjacketFlapFront,
relationTo: Collections.LibraryItemsScans,
admin: { width: "25%" },
}),
imageField({
name: fields.scansDustjacketFlapBack,
relationTo: Collections.LibraryItemsScans,
admin: { width: "25%" },
}),
imageField({
name: fields.scansDustjacketInsideFlapFront,
relationTo: Collections.LibraryItemsScans,
admin: { width: "25%" },
}),
imageField({
name: fields.scansDustjacketInsideFlapBack,
relationTo: Collections.LibraryItemsScans,
admin: { width: "25%" },
}),
],
},
], ],
}), }),
optionalGroupField({ optionalGroupField({
@ -236,21 +409,66 @@ export const LibraryItems = buildVersionedCollectionConfig(
fields: [ fields: [
imageField({ imageField({
name: fields.scansObiFront, name: fields.scansObiFront,
relationTo: Collections.LibraryItemsThumbnails, relationTo: Collections.LibraryItemsScans,
admin: { width: "33%" }, admin: { width: "33%" },
}), }),
imageField({ imageField({
name: fields.scansObiSpine, name: fields.scansObiSpine,
relationTo: Collections.LibraryItemsThumbnails, relationTo: Collections.LibraryItemsScans,
admin: { width: "33%" }, admin: { width: "33%" },
}), }),
imageField({ imageField({
name: fields.scansObiBack, name: fields.scansObiBack,
relationTo: Collections.LibraryItemsThumbnails, relationTo: Collections.LibraryItemsScans,
admin: { width: "33%" }, admin: { width: "33%" },
}), }),
], ],
}, },
{
type: "row",
fields: [
imageField({
name: fields.scansObiInsideFront,
relationTo: Collections.LibraryItemsScans,
admin: { width: "33%" },
}),
imageField({
name: fields.scansObiInsideSpine,
relationTo: Collections.LibraryItemsScans,
admin: { width: "33%" },
}),
imageField({
name: fields.scansObiInsideBack,
relationTo: Collections.LibraryItemsScans,
admin: { width: "33%" },
}),
],
},
{
type: "row",
fields: [
imageField({
name: fields.scansObiFlapFront,
relationTo: Collections.LibraryItemsScans,
admin: { width: "25%" },
}),
imageField({
name: fields.scansObiFlapBack,
relationTo: Collections.LibraryItemsScans,
admin: { width: "25%" },
}),
imageField({
name: fields.scansObiInsideFlapFront,
relationTo: Collections.LibraryItemsScans,
admin: { width: "25%" },
}),
imageField({
name: fields.scansObiInsideFlapBack,
relationTo: Collections.LibraryItemsScans,
admin: { width: "25%" },
}),
],
},
], ],
}), }),
{ {
@ -277,7 +495,7 @@ export const LibraryItems = buildVersionedCollectionConfig(
}, },
imageField({ imageField({
name: fields.scansPagesImage, name: fields.scansPagesImage,
relationTo: Collections.LibraryItemsThumbnails, relationTo: Collections.LibraryItemsScans,
required: true, required: true,
admin: { width: "66%" }, admin: { width: "66%" },
}), }),
@ -287,6 +505,130 @@ export const LibraryItems = buildVersionedCollectionConfig(
}, },
], ],
}), }),
],
},
{
label: "Type",
admin: { condition: () => false },
fields: [
{
name: fields.textual,
type: "group",
admin: {
condition: (data: Partial<LibraryItem>) =>
data.itemType === LibraryItemsTypes.Textual,
},
fields: [
{
type: "row",
fields: [
keysField({
name: fields.textualSubtype,
relationTo: KeysTypes.LibraryTextual,
hasMany: true,
admin: { allowCreate: false, width: "50%" },
}),
{
name: fields.textualLanguages,
type: "relationship",
relationTo: Collections.Languages,
hasMany: true,
admin: { allowCreate: false, width: "50%" },
},
],
},
{
type: "row",
fields: [
{
name: fields.textualPageCount,
type: "number",
min: 1,
admin: { width: "33%" },
},
{
name: fields.textualBindingType,
type: "radio",
options: Object.entries(LibraryItemsTextualBindingTypes).map(
([value, label]) => ({
label,
value,
})
),
admin: {
layout: "horizontal",
width: "33%",
},
},
{
name: fields.textualPageOrder,
type: "radio",
options: Object.entries(LibraryItemsTextualPageOrders).map(
([value, label]) => ({
label,
value,
})
),
admin: {
layout: "horizontal",
width: "33%",
},
},
],
},
],
},
{
name: fields.audio,
type: "group",
admin: {
condition: (data: Partial<LibraryItem>) =>
data.itemType === LibraryItemsTypes.Audio,
},
fields: [
{
type: "row",
fields: [
keysField({
name: fields.audioSubtype,
relationTo: KeysTypes.LibraryAudio,
hasMany: true,
admin: { allowCreate: false, width: "50%" },
}),
],
},
],
},
],
},
{
label: "Details",
fields: [
{
type: "row",
fields: [
{
name: fields.releaseDate,
type: "date",
admin: {
date: { pickerAppearance: "dayOnly", displayFormat: "yyyy-MM-dd" },
width: "50%",
},
},
keysField({
name: fields.categories,
relationTo: KeysTypes.Categories,
hasMany: true,
admin: { allowCreate: false, width: "50%" },
}),
],
},
translatedFields({
name: fields.translations,
label: "Descriptions",
admin: { initCollapsed: true },
fields: [{ name: fields.translationsDescription, type: "textarea", required: true }],
}),
optionalGroupField({ optionalGroupField({
name: fields.size, name: fields.size,
admin: { condition: (data) => !data.digital }, admin: { condition: (data) => !data.digital },
@ -317,7 +659,7 @@ export const LibraryItems = buildVersionedCollectionConfig(
}), }),
optionalGroupField({ optionalGroupField({
name: fields.price, name: fields.price,
admin: { className: "group-array" }, admin: { className: "group-array", width: "50%" },
fields: [ fields: [
{ {
type: "row", type: "row",
@ -341,98 +683,20 @@ export const LibraryItems = buildVersionedCollectionConfig(
], ],
}), }),
{ {
name: fields.itemType, name: fields.urls,
type: "radio", label: "URLs",
options: Object.entries(LibraryItemsTypes).map(([value, label]) => ({ label, value })), type: "array",
admin: { admin: {
layout: "horizontal", description: "Links to official websites where to get/buy the item.",
width: "50%",
}, },
}, fields: [{ name: fields.urlsUrl, type: "text", required: true }],
{
name: fields.textual,
type: "group",
admin: {
condition: (data: Partial<LibraryItem>) => data.itemType === LibraryItemsTypes.Textual,
},
fields: [
{
type: "row",
fields: [
{
name: fields.textualSubtype,
label: "Subtype",
type: "relationship",
relationTo: [Collections.Keys],
filterOptions: { type: { equals: KeysTypes.LibraryTextual } },
hasMany: true,
admin: { allowCreate: false, width: "50%" },
},
{
name: fields.textualLanguages,
type: "relationship",
relationTo: [Collections.Languages],
hasMany: true,
admin: { allowCreate: false, width: "50%" },
}, },
], ],
}, },
{ {
type: "row", label: "Contents",
fields: [ fields: [
{ name: fields.textualPageCount, type: "number", min: 1, admin: { width: "33%" } },
{
name: fields.textualBindingType,
label: "Binding Type",
type: "radio",
options: Object.entries(LibraryItemsTextualBindingTypes).map(([value, label]) => ({
label,
value,
})),
admin: {
layout: "horizontal",
width: "33%",
},
},
{
name: fields.textualPageOrder,
label: "Page Order",
type: "radio",
options: Object.entries(LibraryItemsTextualPageOrders).map(([value, label]) => ({
label,
value,
})),
admin: {
layout: "horizontal",
width: "33%",
},
},
],
},
],
},
{
name: fields.audio,
type: "group",
admin: {
condition: (data: Partial<LibraryItem>) => data.itemType === LibraryItemsTypes.Audio,
},
fields: [
{
type: "row",
fields: [
{
name: fields.audioSubtype,
label: "Subtype",
type: "relationship",
relationTo: [Collections.Keys],
filterOptions: { type: { equals: KeysTypes.LibraryAudio } },
hasMany: true,
admin: { allowCreate: false, width: "50%" },
},
],
},
],
},
{ {
name: fields.contents, name: fields.contents,
type: "array", type: "array",
@ -446,9 +710,7 @@ export const LibraryItems = buildVersionedCollectionConfig(
{ {
type: "row", type: "row",
admin: { admin: {
condition: ({ itemType }) => { condition: ({ itemType }) => itemType === LibraryItemsTypes.Textual,
return itemType === LibraryItemsTypes.Textual;
},
}, },
fields: [ fields: [
{ {
@ -461,9 +723,8 @@ export const LibraryItems = buildVersionedCollectionConfig(
{ {
type: "row", type: "row",
admin: { admin: {
condition: ({ itemType }) => { condition: ({ itemType }) =>
return itemType === LibraryItemsTypes.Audio || itemType === LibraryItemsTypes.Video; itemType === LibraryItemsTypes.Audio || itemType === LibraryItemsTypes.Video,
},
}, },
fields: [ fields: [
{ {
@ -477,21 +738,15 @@ export const LibraryItems = buildVersionedCollectionConfig(
name: fields.contentsNote, name: fields.contentsNote,
type: "textarea", type: "textarea",
admin: { admin: {
condition: ({ itemType }) => { condition: ({ itemType }) =>
return itemType === LibraryItemsTypes.Game || itemType === LibraryItemsTypes.Other; itemType === LibraryItemsTypes.Game || itemType === LibraryItemsTypes.Other,
},
},
},
],
},
{
name: fields.releaseDate,
type: "date",
admin: {
date: { pickerAppearance: "dayOnly", displayFormat: "yyyy-MM-dd" },
position: "sidebar",
}, },
}, },
], ],
}) },
); ],
},
],
},
],
});

View File

@ -0,0 +1,44 @@
import { CollectionGroups, Collections } from "../../constants";
import { buildImageCollectionConfig } from "../../utils/imageCollectionConfig";
const fields = {
filename: "filename",
mimeType: "mimeType",
filesize: "filesize",
} as const satisfies Record<string, string>;
export const LibraryItemsGallery = buildImageCollectionConfig({
slug: Collections.LibraryItemsGallery,
labels: {
singular: "Library Item Gallery",
plural: "Library Item Gallery",
},
defaultSort: fields.filename,
admin: {
useAsTitle: fields.filename,
disableDuplicate: true,
group: CollectionGroups.Media,
},
upload: {
imageSizes: [
{
name: "small",
height: 512,
width: 512,
fit: "cover",
formatOptions: {
format: "webp",
options: { effort: 6, quality: 60, alphaQuality: 60 },
},
},
{
name: "max",
formatOptions: {
format: "webp",
options: { effort: 6, quality: 80, alphaQuality: 80 },
},
},
],
},
fields: [],
});

View File

@ -0,0 +1,57 @@
import { CollectionGroups, Collections } from "../../constants";
import { buildImageCollectionConfig } from "../../utils/imageCollectionConfig";
const fields = {
filename: "filename",
mimeType: "mimeType",
filesize: "filesize",
} as const satisfies Record<string, string>;
export const LibraryItemsScans = buildImageCollectionConfig({
slug: Collections.LibraryItemsScans,
labels: {
singular: "Library Item Scans",
plural: "Library Item Scans",
},
defaultSort: fields.filename,
admin: {
useAsTitle: fields.filename,
disableDuplicate: true,
group: CollectionGroups.Media,
},
upload: {
imageSizes: [
{
name: "og",
height: 1024,
width: 1024,
fit: "contain",
formatOptions: {
format: "jpg",
options: { progressive: true, mozjpeg: true, compressionLevel: 9, quality: 80 },
},
},
{
name: "medium",
height: 1024,
width: 1024,
fit: "contain",
formatOptions: {
format: "webp",
options: { effort: 6, quality: 80, alphaQuality: 80 },
},
},
{
name: "large",
height: 2048,
width: 2048,
fit: "contain",
formatOptions: {
format: "webp",
options: { effort: 6, quality: 80, alphaQuality: 80 },
},
},
],
},
fields: [],
});

View File

@ -1,5 +1,5 @@
import { CollectionGroups, Collections } from "../../constants"; import { CollectionGroups, Collections } from "../../constants";
import { buildCollectionConfig } from "../../utils/collectionConfig"; import { buildImageCollectionConfig } from "../../utils/imageCollectionConfig";
const fields = { const fields = {
filename: "filename", filename: "filename",
@ -7,13 +7,12 @@ const fields = {
filesize: "filesize", filesize: "filesize",
} as const satisfies Record<string, string>; } as const satisfies Record<string, string>;
export const LibraryItemsThumbnails = buildCollectionConfig( export const LibraryItemsThumbnails = buildImageCollectionConfig({
Collections.LibraryItemsThumbnails, slug: Collections.LibraryItemsThumbnails,
{ labels: {
singular: "Library Item Thumbnail", singular: "Library Item Thumbnail",
plural: "Library Item Thumbnails", plural: "Library Item Thumbnails",
}, },
({ uploadDir }) => ({
defaultSort: fields.filename, defaultSort: fields.filename,
admin: { admin: {
useAsTitle: fields.filename, useAsTitle: fields.filename,
@ -21,34 +20,30 @@ export const LibraryItemsThumbnails = buildCollectionConfig(
group: CollectionGroups.Media, group: CollectionGroups.Media,
}, },
upload: { upload: {
staticDir: uploadDir,
mimeTypes: ["image/*"],
imageSizes: [ imageSizes: [
{ {
name: "og", name: "og",
height: 1024, height: 1024,
width: 1024, width: 1024,
fit: "contain", fit: "inside",
formatOptions: { formatOptions: {
format: "jpg", format: "jpg",
options: { progressive: true, mozjpeg: true, compressionLevel: 9, quality: 80 }, options: { progressive: true, mozjpeg: true, compressionLevel: 9, quality: 80 },
}, },
}, },
{ {
name: "medium", name: "square",
height: 1024, height: 1024,
width: 1024, width: 1024,
fit: "contain", fit: "contain",
background: { r: 0, g: 0, b: 0, alpha: 0 },
formatOptions: { formatOptions: {
format: "webp", format: "webp",
options: { effort: 6, quality: 80, alphaQuality: 80 }, options: { effort: 6, quality: 80, alphaQuality: 80 },
}, },
}, },
{ {
name: "large", name: "max",
height: 2048,
width: 2048,
fit: "contain",
formatOptions: { formatOptions: {
format: "webp", format: "webp",
options: { effort: 6, quality: 80, alphaQuality: 80 }, options: { effort: 6, quality: 80, alphaQuality: 80 },
@ -57,5 +52,4 @@ export const LibraryItemsThumbnails = buildCollectionConfig(
], ],
}, },
fields: [], fields: [],
}) });
);

View File

@ -2,7 +2,7 @@ import { QuickFilters, publishStatusFilters } from "../../components/QuickFilter
import { CollectionGroups, Collections, KeysTypes } from "../../constants"; import { CollectionGroups, Collections, KeysTypes } from "../../constants";
import { imageField } from "../../fields/imageField/imageField"; import { imageField } from "../../fields/imageField/imageField";
import { slugField } from "../../fields/slugField/slugField"; import { slugField } from "../../fields/slugField/slugField";
import { localizedFields } from "../../fields/translatedFields/translatedFields"; import { translatedFields } from "../../fields/translatedFields/translatedFields";
import { beforeDuplicateAddCopyTo } from "../../hooks/beforeDuplicateAddCopyTo"; import { beforeDuplicateAddCopyTo } from "../../hooks/beforeDuplicateAddCopyTo";
import { beforeDuplicatePiping } from "../../hooks/beforeDuplicatePiping"; import { beforeDuplicatePiping } from "../../hooks/beforeDuplicatePiping";
import { beforeDuplicateUnpublish } from "../../hooks/beforeDuplicateUnpublish"; import { beforeDuplicateUnpublish } from "../../hooks/beforeDuplicateUnpublish";
@ -26,13 +26,12 @@ const fields = {
proofreaders: "proofreaders", proofreaders: "proofreaders",
} as const satisfies Record<string, string>; } as const satisfies Record<string, string>;
export const Posts = buildVersionedCollectionConfig( export const Posts = buildVersionedCollectionConfig({
Collections.Posts, slug: Collections.Posts,
{ labels: {
singular: "Post", singular: "Post",
plural: "Posts", plural: "Posts",
}, },
() => ({
defaultSort: fields.slug, defaultSort: fields.slug,
admin: { admin: {
useAsTitle: fields.slug, useAsTitle: fields.slug,
@ -95,7 +94,7 @@ export const Posts = buildVersionedCollectionConfig(
}, },
], ],
}, },
localizedFields({ translatedFields({
name: fields.translations, name: fields.translations,
admin: { useAsTitle: fields.title, hasSourceLanguage: true }, admin: { useAsTitle: fields.title, hasSourceLanguage: true },
required: true, required: true,
@ -124,10 +123,7 @@ export const Posts = buildVersionedCollectionConfig(
width: "50%", width: "50%",
}, },
validate: (translators, { siblingData }) => { validate: (translators, { siblingData }) => {
if ( if (isUndefined(siblingData.language) || isUndefined(siblingData.sourceLanguage)) {
isUndefined(siblingData.language) ||
isUndefined(siblingData.sourceLanguage)
) {
return true; return true;
} }
if (siblingData.language === siblingData.sourceLanguage) { if (siblingData.language === siblingData.sourceLanguage) {
@ -172,5 +168,4 @@ export const Posts = buildVersionedCollectionConfig(
}, },
}, },
], ],
}) });
);

View File

@ -1,5 +1,5 @@
import { CollectionGroups, Collections } from "../../constants"; import { CollectionGroups, Collections } from "../../constants";
import { buildCollectionConfig } from "../../utils/collectionConfig"; import { buildImageCollectionConfig } from "../../utils/imageCollectionConfig";
const fields = { const fields = {
filename: "filename", filename: "filename",
@ -7,13 +7,12 @@ const fields = {
filesize: "filesize", filesize: "filesize",
} as const satisfies Record<string, string>; } as const satisfies Record<string, string>;
export const PostsThumbnails = buildCollectionConfig( export const PostsThumbnails = buildImageCollectionConfig({
Collections.PostsThumbnails, slug: Collections.PostsThumbnails,
{ labels: {
singular: "Post Thumbnail", singular: "Post Thumbnail",
plural: "Post Thumbnails", plural: "Post Thumbnails",
}, },
({ uploadDir }) => ({
defaultSort: fields.filename, defaultSort: fields.filename,
admin: { admin: {
useAsTitle: fields.filename, useAsTitle: fields.filename,
@ -21,8 +20,6 @@ export const PostsThumbnails = buildCollectionConfig(
group: CollectionGroups.Media, group: CollectionGroups.Media,
}, },
upload: { upload: {
staticDir: uploadDir,
mimeTypes: ["image/*"],
imageSizes: [ imageSizes: [
{ {
name: "og", name: "og",
@ -45,5 +42,4 @@ export const PostsThumbnails = buildCollectionConfig(
], ],
}, },
fields: [], fields: [],
}) });
);

View File

@ -3,7 +3,7 @@ import { mustBeAdmin } from "../../accesses/mustBeAdmin";
import { QuickFilters } from "../../components/QuickFilters"; import { QuickFilters } from "../../components/QuickFilters";
import { CollectionGroups, Collections, RecordersRoles } from "../../constants"; import { CollectionGroups, Collections, RecordersRoles } from "../../constants";
import { imageField } from "../../fields/imageField/imageField"; import { imageField } from "../../fields/imageField/imageField";
import { localizedFields } from "../../fields/translatedFields/translatedFields"; import { translatedFields } from "../../fields/translatedFields/translatedFields";
import { buildCollectionConfig } from "../../utils/collectionConfig"; import { buildCollectionConfig } from "../../utils/collectionConfig";
import { importFromStrapi } from "./endpoints/importFromStrapi"; import { importFromStrapi } from "./endpoints/importFromStrapi";
import { beforeLoginMustHaveAtLeastOneRole } from "./hooks/beforeLoginMustHaveAtLeastOneRole"; import { beforeLoginMustHaveAtLeastOneRole } from "./hooks/beforeLoginMustHaveAtLeastOneRole";
@ -18,13 +18,12 @@ const fields = {
role: "role", role: "role",
} as const satisfies Record<string, string>; } as const satisfies Record<string, string>;
export const Recorders = buildCollectionConfig( export const Recorders = buildCollectionConfig({
Collections.Recorders, slug: Collections.Recorders,
{ labels: {
singular: "Recorder", singular: "Recorder",
plural: "Recorders", plural: "Recorders",
}, },
() => ({
defaultSort: fields.username, defaultSort: fields.username,
admin: { admin: {
useAsTitle: fields.username, useAsTitle: fields.username,
@ -104,7 +103,7 @@ export const Recorders = buildCollectionConfig(
description: "List of language(s) that this recorder is familiar with", description: "List of language(s) that this recorder is familiar with",
}, },
}, },
localizedFields({ translatedFields({
name: fields.biographies, name: fields.biographies,
interfaceName: "RecorderBiographies", interfaceName: "RecorderBiographies",
admin: { admin: {
@ -140,5 +139,4 @@ export const Recorders = buildCollectionConfig(
}, },
}, },
], ],
}) });
);

View File

@ -1,6 +1,6 @@
import { CollectionGroups, Collections } from "../../constants"; import { CollectionGroups, Collections } from "../../constants";
import { backPropagationField } from "../../fields/backPropagationField/backPropagationField"; import { backPropagationField } from "../../fields/backPropagationField/backPropagationField";
import { buildCollectionConfig } from "../../utils/collectionConfig"; import { buildImageCollectionConfig } from "../../utils/imageCollectionConfig";
const fields = { const fields = {
filename: "filename", filename: "filename",
@ -9,13 +9,12 @@ const fields = {
recorder: "recorder", recorder: "recorder",
} as const satisfies Record<string, string>; } as const satisfies Record<string, string>;
export const RecordersThumbnails = buildCollectionConfig( export const RecordersThumbnails = buildImageCollectionConfig({
Collections.RecordersThumbnails, slug: Collections.RecordersThumbnails,
{ labels: {
singular: "Recorders Thumbnail", singular: "Recorders Thumbnail",
plural: "Recorders Thumbnails", plural: "Recorders Thumbnails",
}, },
({ uploadDir }) => ({
defaultSort: fields.filename, defaultSort: fields.filename,
admin: { admin: {
useAsTitle: fields.filename, useAsTitle: fields.filename,
@ -23,9 +22,6 @@ export const RecordersThumbnails = buildCollectionConfig(
group: CollectionGroups.Media, group: CollectionGroups.Media,
}, },
upload: { upload: {
staticDir: uploadDir,
adminThumbnail: "small",
mimeTypes: ["image/*"],
imageSizes: [ imageSizes: [
{ {
name: "og", name: "og",
@ -52,8 +48,7 @@ export const RecordersThumbnails = buildCollectionConfig(
name: fields.recorder, name: fields.recorder,
hasMany: false, hasMany: false,
relationTo: Collections.Recorders, relationTo: Collections.Recorders,
where: (id) => ({ avatar: { equals: id } }), where: ({ id }) => ({ avatar: { equals: id } }),
}), }),
], ],
}) });
);

View File

@ -17,13 +17,12 @@ const fields = {
channel: "channel", channel: "channel",
} as const satisfies Record<string, string>; } as const satisfies Record<string, string>;
export const Videos: CollectionConfig = buildCollectionConfig( export const Videos: CollectionConfig = buildCollectionConfig({
Collections.Videos, slug: Collections.Videos,
{ labels: {
singular: "Video", singular: "Video",
plural: "Videos", plural: "Videos",
}, },
() => ({
defaultSort: fields.uid, defaultSort: fields.uid,
admin: { admin: {
useAsTitle: fields.title, useAsTitle: fields.title,
@ -99,5 +98,4 @@ export const Videos: CollectionConfig = buildCollectionConfig(
admin: { position: "sidebar" }, admin: { position: "sidebar" },
}, },
], ],
}) });
);

View File

@ -11,13 +11,12 @@ const fields = {
videos: "videos", videos: "videos",
} as const satisfies Record<string, string>; } as const satisfies Record<string, string>;
export const VideosChannels: CollectionConfig = buildCollectionConfig( export const VideosChannels: CollectionConfig = buildCollectionConfig({
Collections.VideosChannels, slug: Collections.VideosChannels,
{ labels: {
singular: "Videos Channel", singular: "Videos Channel",
plural: "Videos Channels", plural: "Videos Channels",
}, },
() => ({
defaultSort: fields.title, defaultSort: fields.title,
admin: { admin: {
useAsTitle: fields.title, useAsTitle: fields.title,
@ -41,5 +40,4 @@ export const VideosChannels: CollectionConfig = buildCollectionConfig(
], ],
}, },
], ],
}) });
);

View File

@ -1,7 +1,8 @@
import { CollectionGroups, Collections, KeysTypes } from "../../constants"; import { CollectionGroups, Collections, KeysTypes } from "../../constants";
import { imageField } from "../../fields/imageField/imageField"; import { imageField } from "../../fields/imageField/imageField";
import { keysField } from "../../fields/keysField/keysField";
import { slugField } from "../../fields/slugField/slugField"; import { slugField } from "../../fields/slugField/slugField";
import { localizedFields } from "../../fields/translatedFields/translatedFields"; import { translatedFields } from "../../fields/translatedFields/translatedFields";
import { buildVersionedCollectionConfig } from "../../utils/versionedCollectionConfig"; import { buildVersionedCollectionConfig } from "../../utils/versionedCollectionConfig";
import { AppearanceRowLabel } from "./components/AppearanceRowLabel"; import { AppearanceRowLabel } from "./components/AppearanceRowLabel";
import { importFromStrapi } from "./endpoints/importFromStrapi"; import { importFromStrapi } from "./endpoints/importFromStrapi";
@ -23,10 +24,9 @@ const fields = {
status: "_status", status: "_status",
}; };
export const Weapons = buildVersionedCollectionConfig( export const Weapons = buildVersionedCollectionConfig({
Collections.Weapons, slug: Collections.Weapons,
{ singular: "Weapon", plural: "Weapons" }, labels: { singular: "Weapon", plural: "Weapons" },
() => ({
defaultSort: fields.slug, defaultSort: fields.slug,
admin: { admin: {
useAsTitle: fields.slug, useAsTitle: fields.slug,
@ -56,14 +56,12 @@ export const Weapons = buildVersionedCollectionConfig(
{ {
type: "row", type: "row",
fields: [ fields: [
{ keysField({
name: fields.type, name: fields.type,
type: "relationship", relationTo: KeysTypes.Weapons,
relationTo: Collections.Keys,
required: true, required: true,
filterOptions: { type: { equals: KeysTypes.Weapons } },
admin: { allowCreate: false, width: "50%" }, admin: { allowCreate: false, width: "50%" },
}, }),
{ {
name: fields.group, name: fields.group,
type: "relationship", type: "relationship",
@ -85,16 +83,14 @@ export const Weapons = buildVersionedCollectionConfig(
}, },
}, },
fields: [ fields: [
{ keysField({
name: fields.appearancesCategories, name: fields.appearancesCategories,
type: "relationship",
required: true, required: true,
hasMany: true, hasMany: true,
relationTo: Collections.Keys, relationTo: KeysTypes.Categories,
filterOptions: { type: { equals: KeysTypes.Categories } },
admin: { allowCreate: false }, admin: { allowCreate: false },
}, }),
localizedFields({ translatedFields({
name: fields.appearancesTranslations, name: fields.appearancesTranslations,
required: true, required: true,
minRows: 1, minRows: 1,
@ -159,5 +155,4 @@ export const Weapons = buildVersionedCollectionConfig(
], ],
}, },
], ],
}) });
);

View File

@ -1,7 +1,7 @@
import { CollectionGroups, Collections } from "../../constants"; import { CollectionGroups, Collections } from "../../constants";
import { backPropagationField } from "../../fields/backPropagationField/backPropagationField"; import { backPropagationField } from "../../fields/backPropagationField/backPropagationField";
import { slugField } from "../../fields/slugField/slugField"; import { slugField } from "../../fields/slugField/slugField";
import { localizedFields } from "../../fields/translatedFields/translatedFields"; import { translatedFields } from "../../fields/translatedFields/translatedFields";
import { buildCollectionConfig } from "../../utils/collectionConfig"; import { buildCollectionConfig } from "../../utils/collectionConfig";
const fields = { const fields = {
@ -12,10 +12,9 @@ const fields = {
weapons: "weapons", weapons: "weapons",
}; };
export const WeaponsGroups = buildCollectionConfig( export const WeaponsGroups = buildCollectionConfig({
Collections.WeaponsGroups, slug: Collections.WeaponsGroups,
{ singular: "Weapons Group", plural: "Weapon Groups" }, labels: { singular: "Weapons Group", plural: "Weapon Groups" },
() => ({
defaultSort: fields.slug, defaultSort: fields.slug,
admin: { admin: {
useAsTitle: fields.slug, useAsTitle: fields.slug,
@ -25,7 +24,7 @@ export const WeaponsGroups = buildCollectionConfig(
timestamps: false, timestamps: false,
fields: [ fields: [
slugField({ name: fields.slug }), slugField({ name: fields.slug }),
localizedFields({ translatedFields({
name: fields.translations, name: fields.translations,
admin: { useAsTitle: fields.translationsName }, admin: { useAsTitle: fields.translationsName },
fields: [{ name: fields.translationsName, type: "text", required: true }], fields: [{ name: fields.translationsName, type: "text", required: true }],
@ -34,8 +33,7 @@ export const WeaponsGroups = buildCollectionConfig(
name: fields.weapons, name: fields.weapons,
relationTo: Collections.Weapons, relationTo: Collections.Weapons,
hasMany: true, hasMany: true,
where: (id) => ({ group: { equals: id } }), where: ({ id }) => ({ group: { equals: id } }),
}), }),
], ],
}) });
);

View File

@ -1,5 +1,5 @@
import { CollectionGroups, Collections } from "../../constants"; import { CollectionGroups, Collections } from "../../constants";
import { buildCollectionConfig } from "../../utils/collectionConfig"; import { buildImageCollectionConfig } from "../../utils/imageCollectionConfig";
const fields = { const fields = {
filename: "filename", filename: "filename",
@ -7,13 +7,12 @@ const fields = {
filesize: "filesize", filesize: "filesize",
} as const satisfies Record<string, string>; } as const satisfies Record<string, string>;
export const WeaponsThumbnails = buildCollectionConfig( export const WeaponsThumbnails = buildImageCollectionConfig({
Collections.WeaponsThumbnails, slug: Collections.WeaponsThumbnails,
{ labels: {
singular: "Weapons Thumbnail", singular: "Weapons Thumbnail",
plural: "Weapons Thumbnails", plural: "Weapons Thumbnails",
}, },
({ uploadDir }) => ({
defaultSort: fields.filename, defaultSort: fields.filename,
admin: { admin: {
useAsTitle: fields.filename, useAsTitle: fields.filename,
@ -21,14 +20,12 @@ export const WeaponsThumbnails = buildCollectionConfig(
group: CollectionGroups.Media, group: CollectionGroups.Media,
}, },
upload: { upload: {
staticDir: uploadDir,
adminThumbnail: "small",
mimeTypes: ["image/*"],
imageSizes: [ imageSizes: [
{ {
name: "og", name: "og",
height: 256, height: 512,
width: 256, width: 512,
fit: "inside",
formatOptions: { formatOptions: {
format: "jpg", format: "jpg",
options: { progressive: true, mozjpeg: true, compressionLevel: 9, quality: 80 }, options: { progressive: true, mozjpeg: true, compressionLevel: 9, quality: 80 },
@ -36,8 +33,28 @@ export const WeaponsThumbnails = buildCollectionConfig(
}, },
{ {
name: "small", name: "small",
height: 128, height: 256,
width: 128, width: 256,
fit: "contain",
background: { r: 0, g: 0, b: 0, alpha: 0 },
formatOptions: {
format: "webp",
options: { effort: 6, quality: 70, alphaQuality: 70 },
},
},
{
name: "medium",
height: 1024,
width: 1024,
fit: "contain",
background: { r: 0, g: 0, b: 0, alpha: 0 },
formatOptions: {
format: "webp",
options: { effort: 6, quality: 80, alphaQuality: 80 },
},
},
{
name: "max",
formatOptions: { formatOptions: {
format: "webp", format: "webp",
options: { effort: 6, quality: 80, alphaQuality: 80 }, options: { effort: 6, quality: 80, alphaQuality: 80 },
@ -46,5 +63,4 @@ export const WeaponsThumbnails = buildCollectionConfig(
], ],
}, },
fields: [], fields: [],
}) });
);

View File

@ -1,4 +1,3 @@
import React from "react";
import { styled } from "styled-components"; import { styled } from "styled-components";
export const Icon = styled.div` export const Icon = styled.div`
@ -9,4 +8,8 @@ export const Icon = styled.div`
mask-size: contain; mask-size: contain;
mask-repeat: no-repeat; mask-repeat: no-repeat;
mask-position: center; mask-position: center;
-webkit-mask: url("/public/accords.svg");
-webkit-mask-size: contain;
-webkit-mask-repeat: no-repeat;
-webkit-mask-position: center;
`; `;

View File

@ -1,5 +1,5 @@
import React from "react";
import "@fontsource/vollkorn/700.css"; import "@fontsource/vollkorn/700.css";
import React from "react";
import { styled } from "styled-components"; import { styled } from "styled-components";
export const Logo = (): JSX.Element => ( export const Logo = (): JSX.Element => (
@ -34,4 +34,8 @@ const Icon = styled.div`
mask-size: contain; mask-size: contain;
mask-repeat: no-repeat; mask-repeat: no-repeat;
mask-position: center; mask-position: center;
-webkit-mask: url("/public/accords.svg");
-webkit-mask-size: contain;
-webkit-mask-repeat: no-repeat;
-webkit-mask-position: center;
`; `;

View File

@ -10,6 +10,8 @@ export enum Collections {
Languages = "languages", Languages = "languages",
LibraryItems = "library-items", LibraryItems = "library-items",
LibraryItemsThumbnails = "library-items-thumbnails", LibraryItemsThumbnails = "library-items-thumbnails",
LibraryItemsScans = "library-items-scans",
LibraryItemsGallery = "library-items-gallery",
Posts = "posts", Posts = "posts",
PostsThumbnails = "posts-thumbnails", PostsThumbnails = "posts-thumbnails",
Recorders = "recorders", Recorders = "recorders",
@ -87,4 +89,5 @@ export enum CollectionStatus {
export enum VideoSources { export enum VideoSources {
YouTube = "YouTube", YouTube = "YouTube",
NicoNico = "NicoNico", NicoNico = "NicoNico",
Tumblr = "Tumblr",
} }

View File

@ -39,7 +39,7 @@ type Params<T> = {
payload: { payload: {
collection: string; collection: string;
import?: (strapiObject: any, user: any) => Promise<void>; import?: (strapiObject: any, user: any) => Promise<void>;
convert?: (strapiObject: any) => PayloadCreateData<T>; convert?: (strapiObject: any, user: any) => PayloadCreateData<T>;
}; };
}; };
@ -60,7 +60,7 @@ export const importStrapiEntries = async <T>({
} else if (isDefined(payloadParams.convert)) { } else if (isDefined(payloadParams.convert)) {
await payload.create({ await payload.create({
collection: payloadParams.collection, collection: payloadParams.collection,
data: payloadParams.convert(attributes), data: payloadParams.convert(attributes, user),
user, user,
}); });
} else { } else {

View File

@ -4,18 +4,20 @@ import { RelationshipField, Where } from "payload/types";
import { isNotEmpty } from "../../utils/asserts"; import { isNotEmpty } from "../../utils/asserts";
type BackPropagationField = FieldBase & { type BackPropagationField = FieldBase & {
where: (id: string) => Where; where: (data: any) => Where;
relationTo: string; relationTo: string;
hasMany: boolean; hasMany?: boolean;
}; };
export const backPropagationField = ({ export const backPropagationField = ({
admin, admin,
hooks: { beforeChange = [], afterRead = [], ...otherHooks } = {}, hooks: { beforeChange = [], afterRead = [], ...otherHooks } = {},
where, where,
hasMany = false,
...params ...params
}: BackPropagationField): RelationshipField => ({ }: BackPropagationField): RelationshipField => ({
...params, ...params,
type: "relationship", type: "relationship",
hasMany: hasMany,
admin: { ...admin, readOnly: true }, admin: { ...admin, readOnly: true },
hooks: { hooks: {
...otherHooks, ...otherHooks,
@ -31,17 +33,17 @@ export const backPropagationField = ({
if (isNotEmpty(data.id)) { if (isNotEmpty(data.id)) {
const result = await payload.find({ const result = await payload.find({
collection: params.relationTo, collection: params.relationTo,
where: where(data.id), where: where(data),
limit: 100, limit: 100,
depth: 0, depth: 0,
}); });
if (params.hasMany) { if (hasMany) {
return result.docs.map((doc) => doc.id); return result.docs.map((doc) => doc.id);
} else { } else {
return result.docs[0].id; return result.docs[0].id;
} }
} }
return params.hasMany ? [] : undefined; return hasMany ? [] : undefined;
}, },
], ],
}, },

View File

@ -1,9 +1,23 @@
import { Props } from "payload/components/views/Cell"; import { Props } from "payload/components/views/Cell";
import { useState, useEffect } from "react"; import React, { useEffect, useMemo, useState } from "react";
import React from "react"; import { Link } from "react-router-dom";
import { styled } from "styled-components";
import { isUndefined } from "../../utils/asserts"; import { isUndefined } from "../../utils/asserts";
export const Cell = ({ cellData, field }: Props): JSX.Element => { const Image = styled.img`
height: 3rem;
width: 3rem;
object-fit: contain;
transition: 0.2s transform;
transition-timing-function: cubic-bezier(0.075, 0.82, 0.165, 1);
position: absolute;
transform: translateY(-50%) scale(1);
&:hover {
transform: translateY(-50%) scale(3);
}
`;
export const Cell = ({ cellData, field, rowData, collection }: Props): JSX.Element => {
const [imageURL, setImageURL] = useState<string>(); const [imageURL, setImageURL] = useState<string>();
useEffect(() => { useEffect(() => {
const fetchUrl = async () => { const fetchUrl = async () => {
@ -11,18 +25,14 @@ export const Cell = ({ cellData, field }: Props): JSX.Element => {
if (typeof cellData !== "string") return; if (typeof cellData !== "string") return;
if (field.type !== "upload") return; if (field.type !== "upload") return;
const result = await (await fetch(`/api/${field.relationTo}/${cellData}`)).json(); const result = await (await fetch(`/api/${field.relationTo}/${cellData}`)).json();
setImageURL(result.url); setImageURL(result.sizes.thumb.url);
}; };
fetchUrl(); fetchUrl();
}, [cellData]); }, [cellData]);
const link = useMemo(
return ( () => `/admin/collections/${collection.slug}/${rowData.id}`,
<> [collection.slug, rowData.id]
{imageURL ? (
<img style={{ height: "3rem", borderRadius: "100%", aspectRatio: "1/1" }} src={imageURL} />
) : (
"<No Image>"
)}
</>
); );
return <Link to={link}>{imageURL ? <Image src={imageURL} /> : "<No Image>"}</Link>;
}; };

View File

@ -0,0 +1,23 @@
import { FieldBase, RelationshipField } from "payload/dist/fields/config/types";
import { Collections, KeysTypes } from "../../constants";
type KeysField = FieldBase & {
relationTo: KeysTypes;
hasMany?: boolean;
admin: RelationshipField["admin"];
};
export const keysField = ({
relationTo,
hasMany = false,
...props
}: KeysField): RelationshipField => ({
...props,
type: "relationship",
hasMany: hasMany,
relationTo: Collections.Keys,
filterOptions: { type: { equals: getKeysTypesKey(relationTo) } },
});
const getKeysTypesKey = (keyType: KeysTypes): string =>
Object.entries(KeysTypes).find(([, value]) => value === keyType)[0];

View File

@ -1,8 +1,7 @@
import { array } from "payload/dist/fields/validations"; import { array } from "payload/dist/fields/validations";
import { ArrayField, Field } from "payload/types"; import { ArrayField, Field } from "payload/types";
import { Collections } from "../../constants"; import { Collections } from "../../constants";
import { isDefined, isUndefined } from "../../utils/asserts"; import { hasDuplicates, isDefined, isUndefined } from "../../utils/asserts";
import { hasDuplicates } from "../../utils/validation";
import { Cell } from "./Cell"; import { Cell } from "./Cell";
import { RowLabel } from "./RowLabel"; import { RowLabel } from "./RowLabel";
@ -14,7 +13,7 @@ const fieldsNames = {
proofreaders: "proofreaders", proofreaders: "proofreaders",
} as const satisfies Record<string, string>; } as const satisfies Record<string, string>;
type LocalizedFieldsProps = Omit<ArrayField, "type" | "admin" | "validate"> & { type LocalizedFieldsProps = Omit<ArrayField, "type" | "admin"> & {
admin?: ArrayField["admin"] & { admin?: ArrayField["admin"] & {
useAsTitle?: string; useAsTitle?: string;
hasSourceLanguage?: boolean; hasSourceLanguage?: boolean;
@ -43,7 +42,8 @@ const creditFields: Field = {
type: "row", type: "row",
admin: { admin: {
condition: (_, siblingData) => condition: (_, siblingData) =>
isDefined(siblingData.language) && isDefined(siblingData.sourceLanguage), isDefined(siblingData[fieldsNames.language]) &&
isDefined(siblingData[fieldsNames.sourceLanguage]),
}, },
fields: [ fields: [
{ {
@ -52,18 +52,28 @@ const creditFields: Field = {
type: "relationship", type: "relationship",
relationTo: "recorders", relationTo: "recorders",
hasMany: true, hasMany: true,
hooks: {
beforeChange: [
({ siblingData }) => {
if (siblingData[fieldsNames.language] !== siblingData[fieldsNames.sourceLanguage]) {
delete siblingData[fieldsNames.transcribers];
}
},
],
},
admin: { admin: {
condition: (_, siblingData) => siblingData.language === siblingData.sourceLanguage, condition: (_, siblingData) => siblingData.language === siblingData.sourceLanguage,
width: "50%", width: "50%",
}, },
validate: (count, { siblingData }) => { validate: (count, { siblingData }) => {
if (siblingData.language !== siblingData.sourceLanguage) { if (siblingData[fieldsNames.language] !== siblingData[fieldsNames.sourceLanguage]) {
return true; return true;
} }
if (isDefined(count) && count.length > 0) { if (isDefined(count) && count.length > 0) {
return true; return true;
} }
return "This field is required when the language is the same as the source language."; return `This field is required when the ${fieldsNames.language} \
is the same as the ${fieldsNames.sourceLanguage}.`;
}, },
}, },
{ {
@ -72,18 +82,29 @@ const creditFields: Field = {
type: "relationship", type: "relationship",
relationTo: "recorders", relationTo: "recorders",
hasMany: true, hasMany: true,
hooks: {
beforeChange: [
({ siblingData }) => {
if (siblingData[fieldsNames.language] === siblingData[fieldsNames.sourceLanguage]) {
delete siblingData[fieldsNames.translators];
}
},
],
},
admin: { admin: {
condition: (_, siblingData) => siblingData.language !== siblingData.sourceLanguage, condition: (_, siblingData) =>
siblingData[fieldsNames.language] !== siblingData[fieldsNames.sourceLanguage],
width: "50%", width: "50%",
}, },
validate: (count, { siblingData }) => { validate: (count, { siblingData }) => {
if (siblingData.language === siblingData.sourceLanguage) { if (siblingData[fieldsNames.language] === siblingData[fieldsNames.sourceLanguage]) {
return true; return true;
} }
if (isDefined(count) && count.length > 0) { if (isDefined(count) && count.length > 0) {
return true; return true;
} }
return "This field is required when the language is different from the source language."; return `This field is required when the ${fieldsNames.language} \
is different from the ${fieldsNames.sourceLanguage}.`;
}, },
}, },
{ {
@ -97,8 +118,9 @@ const creditFields: Field = {
], ],
}; };
export const localizedFields = ({ export const translatedFields = ({
fields, fields,
validate,
admin: { useAsTitle, hasSourceLanguage, hasCredits, ...admin } = {}, admin: { useAsTitle, hasSourceLanguage, hasCredits, ...admin } = {},
...otherProps ...otherProps
}: LocalizedFieldsProps): ArrayField => ({ }: LocalizedFieldsProps): ArrayField => ({
@ -111,13 +133,13 @@ export const localizedFields = ({
Cell({ Cell({
cellData: cellData:
cellData?.map((row) => ({ cellData?.map((row) => ({
language: row.language, language: row[fieldsNames.language],
title: isDefined(useAsTitle) ? row[useAsTitle] : undefined, title: isDefined(useAsTitle) ? row[useAsTitle] : undefined,
})) ?? [], })) ?? [],
}), }),
RowLabel: ({ data }) => RowLabel: ({ data }) =>
RowLabel({ RowLabel({
language: data.language, language: data[fieldsNames.language],
title: isDefined(useAsTitle) ? data[useAsTitle] : undefined, title: isDefined(useAsTitle) ? data[useAsTitle] : undefined,
}), }),
}, },
@ -127,11 +149,16 @@ export const localizedFields = ({
const defaultValidation = array(value, options); const defaultValidation = array(value, options);
if (defaultValidation !== true) return defaultValidation; if (defaultValidation !== true) return defaultValidation;
if (isDefined(validate)) {
const propsValidation = validate(value, options);
if (propsValidation !== true) return propsValidation;
}
const data = options.data[otherProps.name] as ArrayData; const data = options.data[otherProps.name] as ArrayData;
if (isUndefined(data)) return true; if (isUndefined(data)) return true;
if (typeof data === "number") return true; if (typeof data === "number") return true;
const languages = data.map((biography) => biography.language); const languages = data.map((rows) => rows[fieldsNames.language]);
if (hasDuplicates(languages)) { if (hasDuplicates(languages)) {
return `There cannot be multiple ${otherProps.name} with the same ${fieldsNames.language}`; return `There cannot be multiple ${otherProps.name} with the same ${fieldsNames.language}`;
} }

View File

@ -10,6 +10,8 @@ import { Files } from "./collections/Files/Files";
import { Keys } from "./collections/Keys/Keys"; import { Keys } from "./collections/Keys/Keys";
import { Languages } from "./collections/Languages/Languages"; import { Languages } from "./collections/Languages/Languages";
import { LibraryItems } from "./collections/LibraryItems/LibraryItems"; import { LibraryItems } from "./collections/LibraryItems/LibraryItems";
import { LibraryItemsGallery } from "./collections/LibraryItemsGallery/LibraryItemsGallery";
import { LibraryItemsScans } from "./collections/LibraryItemsScans/LibraryItemsScans";
import { LibraryItemsThumbnails } from "./collections/LibraryItemsThumbnails/LibraryItemsThumbnails"; import { LibraryItemsThumbnails } from "./collections/LibraryItemsThumbnails/LibraryItemsThumbnails";
import { Posts } from "./collections/Posts/Posts"; import { Posts } from "./collections/Posts/Posts";
import { PostsThumbnails } from "./collections/PostsThumbnails/PostsThumbnails"; import { PostsThumbnails } from "./collections/PostsThumbnails/PostsThumbnails";
@ -48,6 +50,8 @@ export default buildConfig({
WeaponsThumbnails, WeaponsThumbnails,
ContentsThumbnails, ContentsThumbnails,
LibraryItemsThumbnails, LibraryItemsThumbnails,
LibraryItemsScans,
LibraryItemsGallery,
RecordersThumbnails, RecordersThumbnails,
PostsThumbnails, PostsThumbnails,
Files, Files,

View File

@ -36,6 +36,8 @@ export interface Config {
"weapons-thumbnails": WeaponsThumbnail; "weapons-thumbnails": WeaponsThumbnail;
"contents-thumbnails": ContentsThumbnail; "contents-thumbnails": ContentsThumbnail;
"library-items-thumbnails": LibraryItemThumbnail; "library-items-thumbnails": LibraryItemThumbnail;
"library-items-scans": LibraryItemScans;
"library-items-gallery": LibraryItemGallery;
"recorders-thumbnails": RecordersThumbnail; "recorders-thumbnails": RecordersThumbnail;
"posts-thumbnails": PostThumbnail; "posts-thumbnails": PostThumbnail;
files: File; files: File;
@ -50,6 +52,7 @@ export interface Config {
} }
export interface LibraryItem { export interface LibraryItem {
id: string; id: string;
itemType?: "Textual" | "Audio" | "Video" | "Game" | "Other";
slug: string; slug: string;
thumbnail?: string | LibraryItemThumbnail; thumbnail?: string | LibraryItemThumbnail;
pretitle?: string; pretitle?: string;
@ -59,32 +62,72 @@ export interface LibraryItem {
primary: boolean; primary: boolean;
digital: boolean; digital: boolean;
downloadable: boolean; downloadable: boolean;
gallery?: {
image?: string | LibraryItemGallery;
id?: string;
}[];
scans?: { scans?: {
cover?: { cover?: {
front?: string | LibraryItemThumbnail; front?: string | LibraryItemScans;
spine?: string | LibraryItemThumbnail; spine?: string | LibraryItemScans;
back?: string | LibraryItemThumbnail; back?: string | LibraryItemScans;
insideFront?: string | LibraryItemScans;
flapFront?: string | LibraryItemScans;
flapBack?: string | LibraryItemScans;
insideFlapFront?: string | LibraryItemScans;
insideFlapBack?: string | LibraryItemScans;
id?: string; id?: string;
}[]; }[];
dustjacket?: { dustjacket?: {
front?: string | LibraryItemThumbnail; front?: string | LibraryItemScans;
spine?: string | LibraryItemThumbnail; spine?: string | LibraryItemScans;
back?: string | LibraryItemThumbnail; back?: string | LibraryItemScans;
insideFront?: string | LibraryItemScans;
insideSpine?: string | LibraryItemScans;
insideBack?: string | LibraryItemScans;
flapFront?: string | LibraryItemScans;
flapBack?: string | LibraryItemScans;
insideFlapFront?: string | LibraryItemScans;
insideFlapBack?: string | LibraryItemScans;
id?: string; id?: string;
}[]; }[];
obi?: { obi?: {
front?: string | LibraryItemThumbnail; front?: string | LibraryItemScans;
spine?: string | LibraryItemThumbnail; spine?: string | LibraryItemScans;
back?: string | LibraryItemThumbnail; back?: string | LibraryItemScans;
insideFront?: string | LibraryItemScans;
insideSpine?: string | LibraryItemScans;
insideBack?: string | LibraryItemScans;
flapFront?: string | LibraryItemScans;
flapBack?: string | LibraryItemScans;
insideFlapFront?: string | LibraryItemScans;
insideFlapBack?: string | LibraryItemScans;
id?: string; id?: string;
}[]; }[];
pages?: { pages?: {
page: number; page: number;
image: string | LibraryItemThumbnail; image: string | LibraryItemScans;
id?: string; id?: string;
}[]; }[];
id?: string; id?: string;
}[]; }[];
textual?: {
subtype?: string[] | Key[];
languages?: string[] | Language[];
pageCount?: number;
bindingType?: "Paperback" | "Hardcover";
pageOrder?: "LeftToRight" | "RightToLeft";
};
audio?: {
audioSubtype?: string[] | Key[];
};
releaseDate?: string;
categories?: string[] | Key[];
translations?: {
language: string | Language;
description: string;
id?: string;
}[];
size?: { size?: {
width: number; width: number;
height: number; height: number;
@ -96,41 +139,10 @@ export interface LibraryItem {
currency: string | Currency; currency: string | Currency;
id?: string; id?: string;
}[]; }[];
itemType?: "Textual" | "Audio" | "Video" | "Game" | "Other"; urls?: {
textual?: { url: string;
subtype?: id?: string;
| {
value: string;
relationTo: "keys";
}[]
| {
value: Key;
relationTo: "keys";
}[]; }[];
languages?:
| {
value: string;
relationTo: "languages";
}[]
| {
value: Language;
relationTo: "languages";
}[];
pageCount?: number;
bindingType?: "Paperback" | "Hardcover";
pageOrder?: "LeftToRight" | "RightToLeft";
};
audio?: {
audioSubtype?:
| {
value: string;
relationTo: "keys";
}[]
| {
value: Key;
relationTo: "keys";
}[];
};
contents?: { contents?: {
content: string | Content; content: string | Content;
pageStart?: number; pageStart?: number;
@ -140,7 +152,6 @@ export interface LibraryItem {
note?: string; note?: string;
id?: string; id?: string;
}[]; }[];
releaseDate?: string;
updatedBy: string | Recorder; updatedBy: string | Recorder;
updatedAt: string; updatedAt: string;
createdAt: string; createdAt: string;
@ -157,6 +168,96 @@ export interface LibraryItemThumbnail {
width?: number; width?: number;
height?: number; height?: number;
sizes?: { sizes?: {
thumb?: {
url?: string;
width?: number;
height?: number;
mimeType?: string;
filesize?: number;
filename?: string;
};
og?: {
url?: string;
width?: number;
height?: number;
mimeType?: string;
filesize?: number;
filename?: string;
};
square?: {
url?: string;
width?: number;
height?: number;
mimeType?: string;
filesize?: number;
filename?: string;
};
max?: {
url?: string;
width?: number;
height?: number;
mimeType?: string;
filesize?: number;
filename?: string;
};
};
}
export interface LibraryItemGallery {
id: string;
updatedAt: string;
createdAt: string;
url?: string;
filename?: string;
mimeType?: string;
filesize?: number;
width?: number;
height?: number;
sizes?: {
thumb?: {
url?: string;
width?: number;
height?: number;
mimeType?: string;
filesize?: number;
filename?: string;
};
small?: {
url?: string;
width?: number;
height?: number;
mimeType?: string;
filesize?: number;
filename?: string;
};
max?: {
url?: string;
width?: number;
height?: number;
mimeType?: string;
filesize?: number;
filename?: string;
};
};
}
export interface LibraryItemScans {
id: string;
updatedAt: string;
createdAt: string;
url?: string;
filename?: string;
mimeType?: string;
filesize?: number;
width?: number;
height?: number;
sizes?: {
thumb?: {
url?: string;
width?: number;
height?: number;
mimeType?: string;
filesize?: number;
filename?: string;
};
og?: { og?: {
url?: string; url?: string;
width?: number; width?: number;
@ -183,9 +284,6 @@ export interface LibraryItemThumbnail {
}; };
}; };
} }
export interface Currency {
id: string;
}
export interface Key { export interface Key {
id: string; id: string;
name: string; name: string;
@ -206,23 +304,15 @@ export interface Language {
id: string; id: string;
name: string; name: string;
} }
export interface Currency {
id: string;
}
export interface Content { export interface Content {
id: string; id: string;
slug: string; slug: string;
thumbnail?: string | ContentsThumbnail; thumbnail?: string | ContentsThumbnail;
categories?: categories?: string[] | Key[];
| { type?: string | Key;
value: string;
relationTo: "keys";
}[]
| {
value: Key;
relationTo: "keys";
}[];
type?: {
value: string | Key;
relationTo: "keys";
};
translations: { translations: {
language: string | Language; language: string | Language;
sourceLanguage: string | Language; sourceLanguage: string | Language;
@ -256,6 +346,14 @@ export interface ContentsThumbnail {
width?: number; width?: number;
height?: number; height?: number;
sizes?: { sizes?: {
thumb?: {
url?: string;
width?: number;
height?: number;
mimeType?: string;
filesize?: number;
filename?: string;
};
og?: { og?: {
url?: string; url?: string;
width?: number; width?: number;
@ -303,6 +401,14 @@ export interface RecordersThumbnail {
width?: number; width?: number;
height?: number; height?: number;
sizes?: { sizes?: {
thumb?: {
url?: string;
width?: number;
height?: number;
mimeType?: string;
filesize?: number;
filename?: string;
};
og?: { og?: {
url?: string; url?: string;
width?: number; width?: number;
@ -574,6 +680,14 @@ export interface PostThumbnail {
width?: number; width?: number;
height?: number; height?: number;
sizes?: { sizes?: {
thumb?: {
url?: string;
width?: number;
height?: number;
mimeType?: string;
filesize?: number;
filename?: string;
};
og?: { og?: {
url?: string; url?: string;
width?: number; width?: number;
@ -600,12 +714,25 @@ export interface ChronologyItem {
month?: number; month?: number;
day?: number; day?: number;
}; };
events?: { events: {
translations?: { source?:
| {
value: string | Content;
relationTo: "contents";
}
| {
value: string | LibraryItem;
relationTo: "library-items";
};
translations: {
language: string | Language; language: string | Language;
sourceLanguage: string | Language;
title?: string; title?: string;
description?: string; description?: string;
notes?: string; notes?: string;
transcribers?: string[] | Recorder[];
translators?: string[] | Recorder[];
proofreaders?: string[] | Recorder[];
id?: string; id?: string;
}[]; }[];
id?: string; id?: string;
@ -626,6 +753,7 @@ export interface ChronologyEra {
description?: string; description?: string;
id?: string; id?: string;
}[]; }[];
events?: string[] | ChronologyItem[];
updatedAt: string; updatedAt: string;
createdAt: string; createdAt: string;
} }
@ -669,6 +797,14 @@ export interface WeaponsThumbnail {
width?: number; width?: number;
height?: number; height?: number;
sizes?: { sizes?: {
thumb?: {
url?: string;
width?: number;
height?: number;
mimeType?: string;
filesize?: number;
filename?: string;
};
og?: { og?: {
url?: string; url?: string;
width?: number; width?: number;
@ -685,6 +821,22 @@ export interface WeaponsThumbnail {
filesize?: number; filesize?: number;
filename?: string; filename?: string;
}; };
medium?: {
url?: string;
width?: number;
height?: number;
mimeType?: string;
filesize?: number;
filename?: string;
};
max?: {
url?: string;
width?: number;
height?: number;
mimeType?: string;
filesize?: number;
filename?: string;
};
}; };
} }
export interface WeaponsGroup { export interface WeaponsGroup {
@ -701,7 +853,7 @@ export interface Video {
id: string; id: string;
uid: string; uid: string;
gone: boolean; gone: boolean;
source: "YouTube" | "NicoNico"; source: "YouTube" | "NicoNico" | "Tumblr";
title: string; title: string;
description?: string; description?: string;
likes?: number; likes?: number;

View File

@ -10,3 +10,17 @@ export const isValidDate = (date: Date): boolean => date instanceof Date && !isN
export const isNotEmpty = (value: string | null | undefined): value is string => export const isNotEmpty = (value: string | null | undefined): value is string =>
isDefined(value) && value.trim().length > 0; isDefined(value) && value.trim().length > 0;
export const isEmpty = (value: string | null | undefined): value is string =>
isUndefined(value) || value.trim().length === 0;
type Span = [number, number];
export const hasNoIntersection = (a: Span, b: Span): boolean => {
const [aStart, aEnd] = a;
const [bStart, bEnd] = b;
return aEnd < bStart || aStart > bEnd;
};
export const hasIntersection = (a: Span, b: Span): boolean => !hasNoIntersection(a, b);
export const hasDuplicates = <T>(list: T[]): boolean => list.length !== new Set(list).size;

View File

@ -1,22 +1,12 @@
import { CollectionConfig } from "payload/types"; import { CollectionConfig } from "payload/types";
import { Collections } from "../constants"; import { Collections } from "../constants";
export type BuildCollectionConfig = Omit<CollectionConfig, "slug" | "typescript" | "labels">; export type BuildCollectionConfig = Omit<CollectionConfig, "slug" | "typescript" | "labels"> & {
slug: Collections;
export type GenerationFunctionProps = { labels: { singular: string; plural: string };
uploadDir: string;
}; };
export const buildCollectionConfig = ( export const buildCollectionConfig = (config: BuildCollectionConfig): CollectionConfig => ({
slug: Collections,
labels: { singular: string; plural: string },
generationFunction: (props: GenerationFunctionProps) => BuildCollectionConfig
): CollectionConfig => {
const uploadDir = `../uploads/${slug}`;
const config = generationFunction({ uploadDir });
return {
...config, ...config,
slug, typescript: { interface: config.labels.singular },
typescript: { interface: labels.singular }, });
};
};

View File

@ -0,0 +1,34 @@
import { ImageSize } from "payload/dist/uploads/types";
import { CollectionConfig } from "payload/types";
import { BuildCollectionConfig, buildCollectionConfig } from "./collectionConfig";
type BuildImageCollectionConfig = Omit<BuildCollectionConfig, "upload"> & {
upload: { imageSizes: ImageSize[] };
};
export const buildImageCollectionConfig = ({
upload: { imageSizes },
...otherConfig
}: BuildImageCollectionConfig): CollectionConfig =>
buildCollectionConfig({
...otherConfig,
upload: {
staticDir: `../uploads/${otherConfig.slug}`,
mimeTypes: ["image/*"],
adminThumbnail: "thumb",
imageSizes: [
{
name: "thumb",
height: 128,
width: 128,
fit: "contain",
background: { r: 0, g: 0, b: 0, alpha: 0 },
formatOptions: {
format: "webp",
options: { effort: 6, quality: 50, alphaQuality: 50 },
},
},
...imageSizes,
],
},
});

View File

@ -1 +0,0 @@
export const hasDuplicates = <T>(list: T[]): boolean => list.length !== new Set(list).size;

View File

@ -1,10 +1,6 @@
import { CollectionBeforeChangeHook, CollectionConfig, RelationshipField } from "payload/types"; import { CollectionBeforeChangeHook, CollectionConfig, RelationshipField } from "payload/types";
import { Collections } from "../constants"; import { Collections } from "../constants";
import { import { BuildCollectionConfig } from "./collectionConfig";
BuildCollectionConfig,
GenerationFunctionProps,
buildCollectionConfig,
} from "./collectionConfig";
const fields = { updatedBy: "updatedBy" }; const fields = { updatedBy: "updatedBy" };
@ -23,18 +19,11 @@ const updatedByField = (): RelationshipField => ({
type BuildVersionedCollectionConfig = Omit<BuildCollectionConfig, "timestamps" | "versions">; type BuildVersionedCollectionConfig = Omit<BuildCollectionConfig, "timestamps" | "versions">;
export const buildVersionedCollectionConfig = ( export const buildVersionedCollectionConfig = ({
slug: Collections,
labels: { singular: string; plural: string },
generationFunction: (props: GenerationFunctionProps) => BuildVersionedCollectionConfig
): CollectionConfig => {
const {
hooks: { beforeChange, ...otherHooks } = {}, hooks: { beforeChange, ...otherHooks } = {},
fields, fields,
...otherParams ...otherParams
} = buildCollectionConfig(slug, labels, generationFunction); }: BuildVersionedCollectionConfig): CollectionConfig => ({
return {
...otherParams, ...otherParams,
timestamps: true, timestamps: true,
versions: { drafts: { autosave: { interval: 2000 } } }, versions: { drafts: { autosave: { interval: 2000 } } },
@ -43,5 +32,4 @@ export const buildVersionedCollectionConfig = (
beforeChange: [...(beforeChange ?? []), beforeChangeUpdatedBy], beforeChange: [...(beforeChange ?? []), beforeChangeUpdatedBy],
}, },
fields: [...fields, updatedByField()], fields: [...fields, updatedByField()],
}; });
};