From b7dca3878655edcb458f7ba69e6b49a26ad9f9d7 Mon Sep 17 00:00:00 2001 From: DrMint <29893320+DrMint@users.noreply.github.com> Date: Thu, 4 Apr 2024 17:21:59 +0200 Subject: [PATCH] Removed video, combined all images --- .../BackgroundImages/BackgroundImages.ts | 23 ----- src/collections/Collectibles/Collectibles.ts | 2 +- src/collections/Pages/Pages.ts | 2 +- src/collections/Recorders/Recorders.ts | 2 +- .../Recorders/endpoints/importFromStrapi.ts | 2 +- .../RecordersThumbnails.ts | 42 -------- src/collections/Videos/Videos.ts | 93 ------------------ .../Videos/endpoints/importFromStrapi.ts | 88 ----------------- .../VideosChannels/VideosChannels.ts | 39 -------- src/constants.ts | 10 -- src/payload.config.ts | 8 -- src/types/collections.ts | 95 +------------------ 12 files changed, 7 insertions(+), 399 deletions(-) delete mode 100644 src/collections/BackgroundImages/BackgroundImages.ts delete mode 100644 src/collections/RecordersThumbnails/RecordersThumbnails.ts delete mode 100644 src/collections/Videos/Videos.ts delete mode 100644 src/collections/Videos/endpoints/importFromStrapi.ts delete mode 100644 src/collections/VideosChannels/VideosChannels.ts diff --git a/src/collections/BackgroundImages/BackgroundImages.ts b/src/collections/BackgroundImages/BackgroundImages.ts deleted file mode 100644 index 45d6516..0000000 --- a/src/collections/BackgroundImages/BackgroundImages.ts +++ /dev/null @@ -1,23 +0,0 @@ -import { Collections } from "../../constants"; -import { buildImageCollectionConfig } from "../../utils/imageCollectionConfig"; - -const fields = { - filename: "filename", - mimeType: "mimeType", - filesize: "filesize", - posts: "posts", - updatedAt: "updatedAt", -} as const satisfies Record; - -export const BackgroundImages = buildImageCollectionConfig({ - slug: Collections.BackgroundImages, - labels: { - singular: "Background Image", - plural: "Background Images", - }, - admin: { defaultColumns: [fields.filename, fields.posts, fields.updatedAt] }, - upload: { - imageSizes: [], - }, - fields: [], -}); diff --git a/src/collections/Collectibles/Collectibles.ts b/src/collections/Collectibles/Collectibles.ts index 8764c82..838831f 100644 --- a/src/collections/Collectibles/Collectibles.ts +++ b/src/collections/Collectibles/Collectibles.ts @@ -206,7 +206,7 @@ export const Collectibles = buildVersionedCollectionConfig({ fields: [ imageField({ name: fields.backgroundImage, - relationTo: Collections.BackgroundImages, + relationTo: Collections.Images, admin: { description: "The image used as background from the webpage.\ diff --git a/src/collections/Pages/Pages.ts b/src/collections/Pages/Pages.ts index 2157382..ff244b0 100644 --- a/src/collections/Pages/Pages.ts +++ b/src/collections/Pages/Pages.ts @@ -101,7 +101,7 @@ export const Pages = buildVersionedCollectionConfig({ }), imageField({ name: fields.backgroundImage, - relationTo: Collections.BackgroundImages, + relationTo: Collections.Images, admin: { description: "The image used as background from the webpage.\ diff --git a/src/collections/Recorders/Recorders.ts b/src/collections/Recorders/Recorders.ts index 0b4f6d9..a45c5d9 100644 --- a/src/collections/Recorders/Recorders.ts +++ b/src/collections/Recorders/Recorders.ts @@ -89,7 +89,7 @@ export const Recorders = buildCollectionConfig({ }, imageField({ name: fields.avatar, - relationTo: Collections.RecordersThumbnails, + relationTo: Collections.Images, }), ]), { diff --git a/src/collections/Recorders/endpoints/importFromStrapi.ts b/src/collections/Recorders/endpoints/importFromStrapi.ts index 32d9ff2..b895bed 100644 --- a/src/collections/Recorders/endpoints/importFromStrapi.ts +++ b/src/collections/Recorders/endpoints/importFromStrapi.ts @@ -27,7 +27,7 @@ export const importFromStrapi = createStrapiImportEndpoint({ collection: Collections.Recorders, import: async ({ username, anonymize, anonymous_code, languages, avatar, bio: bios }, user) => { const avatarId = await uploadStrapiImage({ - collection: Collections.RecordersThumbnails, + collection: Collections.Images, image: avatar, }); diff --git a/src/collections/RecordersThumbnails/RecordersThumbnails.ts b/src/collections/RecordersThumbnails/RecordersThumbnails.ts deleted file mode 100644 index 3545546..0000000 --- a/src/collections/RecordersThumbnails/RecordersThumbnails.ts +++ /dev/null @@ -1,42 +0,0 @@ -import { Collections } from "../../constants"; -import { backPropagationField } from "../../fields/backPropagationField/backPropagationField"; -import { buildImageCollectionConfig } from "../../utils/imageCollectionConfig"; - -const fields = { - filename: "filename", - mimeType: "mimeType", - filesize: "filesize", - recorder: "recorder", - updatedAt: "updatedAt", -} as const satisfies Record; - -export const RecordersThumbnails = buildImageCollectionConfig({ - slug: Collections.RecordersThumbnails, - labels: { - singular: "Recorders Thumbnail", - plural: "Recorders Thumbnails", - }, - admin: { defaultColumns: [fields.filename, fields.recorder, fields.updatedAt] }, - upload: { - imageSizes: [ - { - name: "square", - height: 150, - width: 150, - fit: "cover", - formatOptions: { - format: "webp", - options: { effort: 6, quality: 80, alphaQuality: 80 }, - }, - }, - ], - }, - fields: [ - backPropagationField({ - name: fields.recorder, - hasMany: false, - relationTo: Collections.Recorders, - where: ({ id }) => ({ avatar: { equals: id } }), - }), - ], -}); diff --git a/src/collections/Videos/Videos.ts b/src/collections/Videos/Videos.ts deleted file mode 100644 index f189132..0000000 --- a/src/collections/Videos/Videos.ts +++ /dev/null @@ -1,93 +0,0 @@ -import { CollectionConfig } from "payload/types"; -import { mustBeAdmin } from "../../accesses/collections/mustBeAdmin"; -import { CollectionGroups, Collections, VideoSources } from "../../constants"; -import { rowField } from "../../fields/rowField/rowField"; -import { buildCollectionConfig } from "../../utils/collectionConfig"; -import { importFromStrapi } from "./endpoints/importFromStrapi"; - -const fields = { - uid: "uid", - gone: "gone", - source: "source", - liveChat: "liveChat", - title: "title", - description: "description", - publishedDate: "publishedDate", - views: "views", - likes: "likes", - channel: "channel", -} as const satisfies Record; - -export const Videos: CollectionConfig = buildCollectionConfig({ - slug: Collections.Videos, - labels: { - singular: "Video", - plural: "Videos", - }, - defaultSort: fields.uid, - admin: { - useAsTitle: fields.title, - defaultColumns: [ - fields.uid, - fields.title, - fields.source, - fields.gone, - fields.liveChat, - fields.publishedDate, - fields.views, - fields.likes, - fields.channel, - ], - group: CollectionGroups.Media, - disableDuplicate: true, - }, - access: { - create: mustBeAdmin, - delete: mustBeAdmin, - }, - endpoints: [importFromStrapi], - timestamps: false, - fields: [ - rowField([ - { name: fields.uid, type: "text", required: true, unique: true }, - { - name: fields.gone, - type: "checkbox", - defaultValue: false, - required: true, - admin: { - description: - "Is the video no longer available (deleted, privatized, unlisted, blocked...)", - }, - }, - { - name: fields.source, - type: "select", - required: true, - options: Object.entries(VideoSources).map(([_, value]) => ({ - label: value, - value: value, - })), - }, - ]), - { name: fields.title, type: "text", required: true }, - { name: fields.description, type: "textarea" }, - rowField([ - { name: fields.likes, type: "number" }, - { name: fields.views, type: "number" }, - ]), - { - name: fields.publishedDate, - type: "date", - admin: { - date: { pickerAppearance: "dayOnly", displayFormat: "yyyy-MM-dd" }, - }, - required: true, - }, - { - name: fields.channel, - type: "relationship", - relationTo: Collections.VideosChannels, - }, - ], -}); diff --git a/src/collections/Videos/endpoints/importFromStrapi.ts b/src/collections/Videos/endpoints/importFromStrapi.ts deleted file mode 100644 index 31a3848..0000000 --- a/src/collections/Videos/endpoints/importFromStrapi.ts +++ /dev/null @@ -1,88 +0,0 @@ -import payload from "payload"; -import { Collections, VideoSources } from "../../../constants"; -import { createStrapiImportEndpoint } from "../../../endpoints/createStrapiImportEndpoint"; -import { isDefined, isUndefined } from "../../../utils/asserts"; - -type StapiVideo = { - uid: string; - title: string; - description: string; - published_date: { - year?: number; - month?: number; - day?: number; - }; - views: number; - likes: number; - source?: VideoSources; - gone: boolean; - channel: { data?: { attributes: { uid: string; title: string; subscribers: number } } }; -}; - -export const importFromStrapi = createStrapiImportEndpoint({ - strapi: { - collection: "videos", - params: { populate: "published_date,channel" }, - }, - payload: { - collection: Collections.Videos, - import: async ( - { - uid, - title, - description, - views, - likes, - gone, - source, - published_date: { year, month, day }, - channel, - }, - user - ) => { - if (isUndefined(source)) throw new Error("A source is required to create a Video"); - if (source === VideoSources.YouTube && isUndefined(channel.data)) - throw new Error("A channel is required to create a YouTube Video"); - - let videoChannelId; - if (isDefined(channel.data)) { - try { - await payload.create({ - collection: Collections.VideosChannels, - data: { - uid: channel.data.attributes.uid, - title: channel.data.attributes.title, - subscribers: channel.data.attributes.subscribers, - }, - user, - }); - } catch (e) {} - - const result = await payload.find({ - collection: Collections.VideosChannels, - where: { uid: { equals: channel.data.attributes.uid } }, - }); - - if (result.docs[0]) { - videoChannelId = result.docs[0].id; - } - } - - await payload.create({ - collection: Collections.Videos, - data: { - uid, - title, - description, - views, - likes, - gone, - source, - publishedDate: `${year}-${month}-${day}`, - channel: videoChannelId, - }, - user, - }); - }, - }, -}); diff --git a/src/collections/VideosChannels/VideosChannels.ts b/src/collections/VideosChannels/VideosChannels.ts deleted file mode 100644 index 429019b..0000000 --- a/src/collections/VideosChannels/VideosChannels.ts +++ /dev/null @@ -1,39 +0,0 @@ -import { CollectionConfig } from "payload/types"; -import { mustBeAdmin } from "../../accesses/collections/mustBeAdmin"; -import { CollectionGroups, Collections } from "../../constants"; -import { rowField } from "../../fields/rowField/rowField"; -import { buildCollectionConfig } from "../../utils/collectionConfig"; - -const fields = { - uid: "uid", - title: "title", - subscribers: "subscribers", - videos: "videos", -} as const satisfies Record; - -export const VideosChannels: CollectionConfig = buildCollectionConfig({ - slug: Collections.VideosChannels, - labels: { - singular: "Videos Channel", - plural: "Videos Channels", - }, - defaultSort: fields.title, - admin: { - useAsTitle: fields.title, - defaultColumns: [fields.uid, fields.title, fields.subscribers, fields.videos], - group: CollectionGroups.Media, - disableDuplicate: true, - }, - access: { - create: mustBeAdmin, - delete: mustBeAdmin, - }, - timestamps: false, - fields: [ - { name: fields.uid, type: "text", required: true, unique: true }, - rowField([ - { name: fields.title, type: "text", required: true }, - { name: fields.subscribers, type: "number" }, - ]), - ], -}); diff --git a/src/constants.ts b/src/constants.ts index d6de9de..2a97703 100644 --- a/src/constants.ts +++ b/src/constants.ts @@ -11,9 +11,6 @@ export enum Collections { Pages = "pages", PagesThumbnails = "pages-thumbnails", Recorders = "recorders", - RecordersThumbnails = "recorders-thumbnails", - VideosChannels = "videos-channels", - Videos = "videos", Folders = "folders", Tags = "tags", TagsGroups = "tags-groups", @@ -21,7 +18,6 @@ export enum Collections { Wordings = "wordings", Collectibles = "collectibles", GenericContents = "generic-contents", - BackgroundImages = "background-images", HomeFolders = "home-folders", } @@ -79,12 +75,6 @@ export enum CollectionStatus { Published = "published", } -export enum VideoSources { - YouTube = "YouTube", - NicoNico = "NicoNico", - Tumblr = "Tumblr", -} - export enum PageType { Content = "Content", Post = "Post", diff --git a/src/payload.config.ts b/src/payload.config.ts index 16cf6de..7555174 100644 --- a/src/payload.config.ts +++ b/src/payload.config.ts @@ -2,7 +2,6 @@ import { webpackBundler } from "@payloadcms/bundler-webpack"; import { mongooseAdapter } from "@payloadcms/db-mongodb"; import path from "path"; import { buildConfig } from "payload/config"; -import { BackgroundImages } from "./collections/BackgroundImages/BackgroundImages"; import { ChronologyEvents } from "./collections/ChronologyEvents/ChronologyEvents"; import { Collectibles } from "./collections/Collectibles/Collectibles"; import { Currencies } from "./collections/Currencies/Currencies"; @@ -14,11 +13,8 @@ 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 { RecordersThumbnails } from "./collections/RecordersThumbnails/RecordersThumbnails"; import { Tags } from "./collections/Tags/Tags"; import { TagsGroups } from "./collections/TagsGroups/TagsGroups"; -import { Videos } from "./collections/Videos/Videos"; -import { VideosChannels } from "./collections/VideosChannels/VideosChannels"; import { Wordings } from "./collections/Wordings/Wordings"; import { Icon } from "./components/Icon"; import { Logo } from "./components/Logo"; @@ -47,10 +43,6 @@ export default buildConfig({ Notes, Images, - BackgroundImages, - RecordersThumbnails, - Videos, - VideosChannels, Tags, TagsGroups, diff --git a/src/types/collections.ts b/src/types/collections.ts index 39113a9..0f4f61c 100644 --- a/src/types/collections.ts +++ b/src/types/collections.ts @@ -49,10 +49,6 @@ export interface Config { "chronology-events": ChronologyEvent; notes: Note; images: Image; - "background-images": BackgroundImage; - "recorders-thumbnails": RecordersThumbnail; - videos: Video; - "videos-channels": VideosChannel; tags: Tag; "tags-groups": TagsGroup; recorders: Recorder; @@ -76,7 +72,7 @@ export interface Page { slug: string; type: "Content" | "Post" | "Generic"; thumbnail?: string | Image | null; - backgroundImage?: string | BackgroundImage | null; + backgroundImage?: string | Image | null; tags?: (string | Tag)[] | null; authors?: (string | Recorder)[] | null; translations: { @@ -160,31 +156,6 @@ export interface Image { }; }; } -/** - * This interface was referenced by `Config`'s JSON-Schema - * via the `definition` "background-images". - */ -export interface BackgroundImage { - 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; - }; - }; -} /** * This interface was referenced by `Config`'s JSON-Schema * via the `definition` "tags". @@ -233,7 +204,7 @@ export interface TagsGroup { export interface Recorder { id: string; username: string; - avatar?: string | RecordersThumbnail | null; + avatar?: string | Image | null; languages?: (string | Language)[] | null; biographies?: RecorderBiographies; role?: ("Admin" | "Recorder" | "Api")[] | null; @@ -247,40 +218,6 @@ export interface Recorder { lockUntil?: string | null; password?: string | null; } -/** - * This interface was referenced by `Config`'s JSON-Schema - * via the `definition` "recorders-thumbnails". - */ -export interface RecordersThumbnail { - id: string; - recorder?: (string | null) | Recorder; - 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; - }; - square?: { - 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` "folders". @@ -371,7 +308,7 @@ export interface Collectible { } | null; id?: string | null; }[]; - backgroundImage?: string | BackgroundImage | null; + backgroundImage?: string | Image | null; gallery?: | { image: string | Image; @@ -685,32 +622,6 @@ export interface Note { updatedAt: string; createdAt: string; } -/** - * This interface was referenced by `Config`'s JSON-Schema - * via the `definition` "videos". - */ -export interface Video { - id: string; - uid: string; - gone: boolean; - source: "YouTube" | "NicoNico" | "Tumblr"; - title: string; - description?: string | null; - likes?: number | null; - views?: number | null; - publishedDate: string; - channel?: (string | null) | VideosChannel; -} -/** - * This interface was referenced by `Config`'s JSON-Schema - * via the `definition` "videos-channels". - */ -export interface VideosChannel { - id: string; - uid: string; - title: string; - subscribers?: number | null; -} /** * This interface was referenced by `Config`'s JSON-Schema * via the `definition` "wordings".