From fc921703cf04b5cf5334112d0328af165b413d94 Mon Sep 17 00:00:00 2001 From: DrMint <29893320+DrMint@users.noreply.github.com> Date: Fri, 5 Apr 2024 12:53:59 +0200 Subject: [PATCH] Moved scans to their own Collection --- src/collections/Collectibles/Collectibles.ts | 60 ++++++------- src/collections/Scans/Scans.ts | 32 +++++++ src/constants.ts | 1 + src/payload.config.ts | 2 + src/types/collections.ts | 94 +++++++++++++------- 5 files changed, 129 insertions(+), 60 deletions(-) create mode 100644 src/collections/Scans/Scans.ts diff --git a/src/collections/Collectibles/Collectibles.ts b/src/collections/Collectibles/Collectibles.ts index fc1194c..f0a4f8c 100644 --- a/src/collections/Collectibles/Collectibles.ts +++ b/src/collections/Collectibles/Collectibles.ts @@ -260,43 +260,43 @@ export const Collectibles = buildVersionedCollectionConfig({ rowField([ imageField({ name: fields.scansCoverFront, - relationTo: Collections.Images, + relationTo: Collections.Scans, }), imageField({ name: fields.scansCoverSpine, - relationTo: Collections.Images, + relationTo: Collections.Scans, }), imageField({ name: fields.scansCoverBack, - relationTo: Collections.Images, + relationTo: Collections.Scans, }), ]), rowField([ imageField({ name: fields.scansCoverInsideFront, - relationTo: Collections.Images, + relationTo: Collections.Scans, }), imageField({ name: fields.scansCoverInsideBack, - relationTo: Collections.Images, + relationTo: Collections.Scans, }), ]), rowField([ imageField({ name: fields.scansCoverFlapFront, - relationTo: Collections.Images, + relationTo: Collections.Scans, }), imageField({ name: fields.scansCoverFlapBack, - relationTo: Collections.Images, + relationTo: Collections.Scans, }), imageField({ name: fields.scansCoverInsideFlapFront, - relationTo: Collections.Images, + relationTo: Collections.Scans, }), imageField({ name: fields.scansCoverInsideFlapBack, - relationTo: Collections.Images, + relationTo: Collections.Scans, }), ]), ], @@ -313,47 +313,47 @@ export const Collectibles = buildVersionedCollectionConfig({ rowField([ imageField({ name: fields.scansDustjacketFront, - relationTo: Collections.Images, + relationTo: Collections.Scans, }), imageField({ name: fields.scansDustjacketSpine, - relationTo: Collections.Images, + relationTo: Collections.Scans, }), imageField({ name: fields.scansDustjacketBack, - relationTo: Collections.Images, + relationTo: Collections.Scans, }), ]), rowField([ imageField({ name: fields.scansDustjacketInsideFront, - relationTo: Collections.Images, + relationTo: Collections.Scans, }), imageField({ name: fields.scansDustjacketInsideSpine, - relationTo: Collections.Images, + relationTo: Collections.Scans, }), imageField({ name: fields.scansDustjacketInsideBack, - relationTo: Collections.Images, + relationTo: Collections.Scans, }), ]), rowField([ imageField({ name: fields.scansDustjacketFlapFront, - relationTo: Collections.Images, + relationTo: Collections.Scans, }), imageField({ name: fields.scansDustjacketFlapBack, - relationTo: Collections.Images, + relationTo: Collections.Scans, }), imageField({ name: fields.scansDustjacketInsideFlapFront, - relationTo: Collections.Images, + relationTo: Collections.Scans, }), imageField({ name: fields.scansDustjacketInsideFlapBack, - relationTo: Collections.Images, + relationTo: Collections.Scans, }), ]), ], @@ -370,47 +370,47 @@ export const Collectibles = buildVersionedCollectionConfig({ rowField([ imageField({ name: fields.scansObiFront, - relationTo: Collections.Images, + relationTo: Collections.Scans, }), imageField({ name: fields.scansObiSpine, - relationTo: Collections.Images, + relationTo: Collections.Scans, }), imageField({ name: fields.scansObiBack, - relationTo: Collections.Images, + relationTo: Collections.Scans, }), ]), rowField([ imageField({ name: fields.scansObiInsideFront, - relationTo: Collections.Images, + relationTo: Collections.Scans, }), imageField({ name: fields.scansObiInsideSpine, - relationTo: Collections.Images, + relationTo: Collections.Scans, }), imageField({ name: fields.scansObiInsideBack, - relationTo: Collections.Images, + relationTo: Collections.Scans, }), ]), rowField([ imageField({ name: fields.scansObiFlapFront, - relationTo: Collections.Images, + relationTo: Collections.Scans, }), imageField({ name: fields.scansObiFlapBack, - relationTo: Collections.Images, + relationTo: Collections.Scans, }), imageField({ name: fields.scansObiInsideFlapFront, - relationTo: Collections.Images, + relationTo: Collections.Scans, }), imageField({ name: fields.scansObiInsideFlapBack, - relationTo: Collections.Images, + relationTo: Collections.Scans, }), ]), ], @@ -436,7 +436,7 @@ export const Collectibles = buildVersionedCollectionConfig({ }, imageField({ name: fields.scansPagesImage, - relationTo: Collections.Images, + relationTo: Collections.Scans, required: true, }), ]), diff --git a/src/collections/Scans/Scans.ts b/src/collections/Scans/Scans.ts new file mode 100644 index 0000000..8e31a8d --- /dev/null +++ b/src/collections/Scans/Scans.ts @@ -0,0 +1,32 @@ +import { Collections } from "../../constants"; +import { buildImageCollectionConfig } from "../../utils/imageCollectionConfig"; + +const fields = { + filename: "filename", + mimeType: "mimeType", + filesize: "filesize", + updatedAt: "updatedAt", +} as const satisfies Record; + +export const Scans = buildImageCollectionConfig({ + slug: Collections.Scans, + labels: { + singular: "Scan", + plural: "Scans", + }, + admin: { defaultColumns: [fields.filename, fields.updatedAt], hidden: true }, + upload: { + imageSizes: [ + { + name: "og", + height: 750, + width: 1125, + formatOptions: { + format: "jpg", + options: { progressive: true, mozjpeg: true, compressionLevel: 9, quality: 60 }, + }, + }, + ], + }, + fields: [], +}); diff --git a/src/constants.ts b/src/constants.ts index d856ad5..e229978 100644 --- a/src/constants.ts +++ b/src/constants.ts @@ -20,6 +20,7 @@ export enum Collections { GenericContents = "generic-contents", HomeFolders = "home-folders", Videos = "videos", + Scans = "scans", } export enum CollectionGroups { diff --git a/src/payload.config.ts b/src/payload.config.ts index 9caaa30..ccb3027 100644 --- a/src/payload.config.ts +++ b/src/payload.config.ts @@ -14,6 +14,7 @@ import { Languages } from "./collections/Languages/Languages"; import { Notes } from "./collections/Notes/Notes"; import { Pages } from "./collections/Pages/Pages"; import { Recorders } from "./collections/Recorders/Recorders"; +import { Scans } from "./collections/Scans/Scans"; import { Tags } from "./collections/Tags/Tags"; import { TagsGroups } from "./collections/TagsGroups/TagsGroups"; import { Videos } from "./collections/Videos/Videos"; @@ -51,6 +52,7 @@ export default buildConfig({ Videos, VideosSubtitles, VideosChannels, + Scans, Tags, TagsGroups, diff --git a/src/types/collections.ts b/src/types/collections.ts index 7ba0b59..0cd1f5a 100644 --- a/src/types/collections.ts +++ b/src/types/collections.ts @@ -25,6 +25,7 @@ export interface Config { notes: Note; images: Image; videos: Video; + scans: Scan; tags: Tag; "tags-groups": TagsGroup; recorders: Recorder; @@ -297,46 +298,46 @@ export interface Collectible { typesetters?: (string | Recorder)[] | null; coverEnabled?: boolean | null; cover?: { - front?: string | Image | null; - spine?: string | Image | null; - back?: string | Image | null; - insideFront?: string | Image | null; - insideBack?: string | Image | null; - flapFront?: string | Image | null; - flapBack?: string | Image | null; - insideFlapFront?: string | Image | null; - insideFlapBack?: string | Image | null; + front?: string | Scan | null; + spine?: string | Scan | null; + back?: string | Scan | null; + insideFront?: string | Scan | null; + insideBack?: string | Scan | null; + flapFront?: string | Scan | null; + flapBack?: string | Scan | null; + insideFlapFront?: string | Scan | null; + insideFlapBack?: string | Scan | null; }; dustjacketEnabled?: boolean | null; dustjacket?: { - front?: string | Image | null; - spine?: string | Image | null; - back?: string | Image | null; - insideFront?: string | Image | null; - insideSpine?: string | Image | null; - insideBack?: string | Image | null; - flapFront?: string | Image | null; - flapBack?: string | Image | null; - insideFlapFront?: string | Image | null; - insideFlapBack?: string | Image | null; + front?: string | Scan | null; + spine?: string | Scan | null; + back?: string | Scan | null; + insideFront?: string | Scan | null; + insideSpine?: string | Scan | null; + insideBack?: string | Scan | null; + flapFront?: string | Scan | null; + flapBack?: string | Scan | null; + insideFlapFront?: string | Scan | null; + insideFlapBack?: string | Scan | null; }; obiEnabled?: boolean | null; obi?: { - front?: string | Image | null; - spine?: string | Image | null; - back?: string | Image | null; - insideFront?: string | Image | null; - insideSpine?: string | Image | null; - insideBack?: string | Image | null; - flapFront?: string | Image | null; - flapBack?: string | Image | null; - insideFlapFront?: string | Image | null; - insideFlapBack?: string | Image | null; + front?: string | Scan | null; + spine?: string | Scan | null; + back?: string | Scan | null; + insideFront?: string | Scan | null; + insideSpine?: string | Scan | null; + insideBack?: string | Scan | null; + flapFront?: string | Scan | null; + flapBack?: string | Scan | null; + insideFlapFront?: string | Scan | null; + insideFlapBack?: string | Scan | null; }; pages?: | { page: number; - image: string | Image; + image: string | Scan; id?: string | null; }[] | null; @@ -433,6 +434,39 @@ export interface Collectible { createdAt: string; _status?: ("draft" | "published") | null; } +/** + * This interface was referenced by `Config`'s JSON-Schema + * via the `definition` "scans". + */ +export interface Scan { + id: string; + updatedAt: string; + createdAt: string; + url?: string | null; + filename?: string | null; + mimeType?: string | null; + filesize?: number | null; + width?: number | null; + height?: number | null; + sizes?: { + thumb?: { + url?: string | null; + width?: number | null; + height?: number | null; + mimeType?: string | null; + filesize?: number | null; + filename?: string | null; + }; + og?: { + url?: string | null; + width?: number | null; + height?: number | null; + mimeType?: string | null; + filesize?: number | null; + filename?: string | null; + }; + }; +} /** * This interface was referenced by `Config`'s JSON-Schema * via the `definition` "currencies".