From 1cda67478228dc58afaf28d0aa7d328ed5da25aa Mon Sep 17 00:00:00 2001 From: DrMint <29893320+DrMint@users.noreply.github.com> Date: Sun, 23 Jul 2023 02:05:54 +0200 Subject: [PATCH] Improve upload directories --- src/collections/ContentThumbnails/ContentThumbnails.ts | 4 ++-- .../LibraryItemThumbnails/LibraryItemThumbnails.ts | 4 ++-- src/collections/PostThumbnails/PostThumbnails.ts | 4 ++-- src/collections/RecorderThumbnails/RecorderThumbnails.ts | 4 ++-- src/collections/Users.ts | 1 - src/utils/collectionConfig.ts | 5 +++-- src/utils/string.ts | 2 +- 7 files changed, 12 insertions(+), 12 deletions(-) diff --git a/src/collections/ContentThumbnails/ContentThumbnails.ts b/src/collections/ContentThumbnails/ContentThumbnails.ts index fcd29a6..749eb21 100644 --- a/src/collections/ContentThumbnails/ContentThumbnails.ts +++ b/src/collections/ContentThumbnails/ContentThumbnails.ts @@ -12,14 +12,14 @@ export const ContentThumbnails = buildCollectionConfig( singular: "Content Thumbnail", plural: "Content Thumbnails", }, - ({ labels }) => ({ + ({ uploadDir }) => ({ defaultSort: fields.filename, admin: { useAsTitle: fields.filename, group: CollectionGroup.Media, }, upload: { - staticDir: `../uploads/${labels.plural}`, + staticDir: uploadDir, mimeTypes: ["image/*"], imageSizes: [ { diff --git a/src/collections/LibraryItemThumbnails/LibraryItemThumbnails.ts b/src/collections/LibraryItemThumbnails/LibraryItemThumbnails.ts index 73a96a3..801283f 100644 --- a/src/collections/LibraryItemThumbnails/LibraryItemThumbnails.ts +++ b/src/collections/LibraryItemThumbnails/LibraryItemThumbnails.ts @@ -12,14 +12,14 @@ export const LibraryItemThumbnails = buildCollectionConfig( singular: "Library Item Thumbnail", plural: "Library Item Thumbnails", }, - ({ labels }) => ({ + ({ uploadDir }) => ({ defaultSort: fields.filename, admin: { useAsTitle: fields.filename, group: CollectionGroup.Media, }, upload: { - staticDir: `../uploads/${labels.plural}`, + staticDir: uploadDir, mimeTypes: ["image/*"], imageSizes: [ { diff --git a/src/collections/PostThumbnails/PostThumbnails.ts b/src/collections/PostThumbnails/PostThumbnails.ts index 45fd3a1..7972957 100644 --- a/src/collections/PostThumbnails/PostThumbnails.ts +++ b/src/collections/PostThumbnails/PostThumbnails.ts @@ -12,14 +12,14 @@ export const PostThumbnails = buildCollectionConfig( singular: "Post Thumbnail", plural: "Post Thumbnails", }, - ({ labels }) => ({ + ({ uploadDir }) => ({ defaultSort: fields.filename, admin: { useAsTitle: fields.filename, group: CollectionGroup.Media, }, upload: { - staticDir: `../uploads/${labels.plural}`, + staticDir: uploadDir, mimeTypes: ["image/*"], imageSizes: [ { diff --git a/src/collections/RecorderThumbnails/RecorderThumbnails.ts b/src/collections/RecorderThumbnails/RecorderThumbnails.ts index 3cc3bff..33bfae3 100644 --- a/src/collections/RecorderThumbnails/RecorderThumbnails.ts +++ b/src/collections/RecorderThumbnails/RecorderThumbnails.ts @@ -12,14 +12,14 @@ export const RecorderThumbnails = buildCollectionConfig( singular: "Recorder Thumbnail", plural: "Recorder Thumbnails", }, - ({ labels }) => ({ + ({ uploadDir }) => ({ defaultSort: fields.filename, admin: { useAsTitle: fields.filename, group: CollectionGroup.Media, }, upload: { - staticDir: `../uploads/${labels.plural}`, + staticDir: uploadDir, adminThumbnail: "small", mimeTypes: ["image/*"], imageSizes: [ diff --git a/src/collections/Users.ts b/src/collections/Users.ts index a956ef5..aac5a47 100644 --- a/src/collections/Users.ts +++ b/src/collections/Users.ts @@ -31,7 +31,6 @@ export const Users = buildCollectionConfig( name: fields.recorder, type: "relationship", relationTo: Recorders.slug, - required: true, admin: { width: "33%" }, }, { diff --git a/src/utils/collectionConfig.ts b/src/utils/collectionConfig.ts index 6392a11..dd91d49 100644 --- a/src/utils/collectionConfig.ts +++ b/src/utils/collectionConfig.ts @@ -4,8 +4,8 @@ import slugify from "slugify"; export type BuildCollectionConfig = Omit; export type GenerationFunctionProps = { - labels: { singular: string; plural: string }; slug: string; + uploadDir: string; }; export const buildCollectionConfig = ( @@ -13,7 +13,8 @@ export const buildCollectionConfig = ( generationFunction: (props: GenerationFunctionProps) => BuildCollectionConfig ): CollectionConfig => { const slug = slugify(labels.plural, { lower: true, strict: true, trim: true }); - const config = generationFunction({ labels, slug }); + const uploadDir = `../uploads/${slug}`; + const config = generationFunction({ slug, uploadDir }); return { ...config, slug, diff --git a/src/utils/string.ts b/src/utils/string.ts index c684cd3..6522a24 100644 --- a/src/utils/string.ts +++ b/src/utils/string.ts @@ -4,4 +4,4 @@ export const shortenEllipsis = (text: string, length: number): string => text.length - 3 > length ? `${text.substring(0, length)}...` : text; export const formatLanguageCode = (code: string): string => - ISO6391.validate(code) ? ISO6391.getName(code) : code; \ No newline at end of file + ISO6391.validate(code) ? ISO6391.getName(code) : code;