Improve upload directories

This commit is contained in:
DrMint 2023-07-23 02:05:54 +02:00
parent 65286f0c66
commit 1cda674782
7 changed files with 12 additions and 12 deletions

View File

@ -12,14 +12,14 @@ export const ContentThumbnails = buildCollectionConfig(
singular: "Content Thumbnail", singular: "Content Thumbnail",
plural: "Content Thumbnails", plural: "Content Thumbnails",
}, },
({ labels }) => ({ ({ uploadDir }) => ({
defaultSort: fields.filename, defaultSort: fields.filename,
admin: { admin: {
useAsTitle: fields.filename, useAsTitle: fields.filename,
group: CollectionGroup.Media, group: CollectionGroup.Media,
}, },
upload: { upload: {
staticDir: `../uploads/${labels.plural}`, staticDir: uploadDir,
mimeTypes: ["image/*"], mimeTypes: ["image/*"],
imageSizes: [ imageSizes: [
{ {

View File

@ -12,14 +12,14 @@ export const LibraryItemThumbnails = buildCollectionConfig(
singular: "Library Item Thumbnail", singular: "Library Item Thumbnail",
plural: "Library Item Thumbnails", plural: "Library Item Thumbnails",
}, },
({ labels }) => ({ ({ uploadDir }) => ({
defaultSort: fields.filename, defaultSort: fields.filename,
admin: { admin: {
useAsTitle: fields.filename, useAsTitle: fields.filename,
group: CollectionGroup.Media, group: CollectionGroup.Media,
}, },
upload: { upload: {
staticDir: `../uploads/${labels.plural}`, staticDir: uploadDir,
mimeTypes: ["image/*"], mimeTypes: ["image/*"],
imageSizes: [ imageSizes: [
{ {

View File

@ -12,14 +12,14 @@ export const PostThumbnails = buildCollectionConfig(
singular: "Post Thumbnail", singular: "Post Thumbnail",
plural: "Post Thumbnails", plural: "Post Thumbnails",
}, },
({ labels }) => ({ ({ uploadDir }) => ({
defaultSort: fields.filename, defaultSort: fields.filename,
admin: { admin: {
useAsTitle: fields.filename, useAsTitle: fields.filename,
group: CollectionGroup.Media, group: CollectionGroup.Media,
}, },
upload: { upload: {
staticDir: `../uploads/${labels.plural}`, staticDir: uploadDir,
mimeTypes: ["image/*"], mimeTypes: ["image/*"],
imageSizes: [ imageSizes: [
{ {

View File

@ -12,14 +12,14 @@ export const RecorderThumbnails = buildCollectionConfig(
singular: "Recorder Thumbnail", singular: "Recorder Thumbnail",
plural: "Recorder Thumbnails", plural: "Recorder Thumbnails",
}, },
({ labels }) => ({ ({ uploadDir }) => ({
defaultSort: fields.filename, defaultSort: fields.filename,
admin: { admin: {
useAsTitle: fields.filename, useAsTitle: fields.filename,
group: CollectionGroup.Media, group: CollectionGroup.Media,
}, },
upload: { upload: {
staticDir: `../uploads/${labels.plural}`, staticDir: uploadDir,
adminThumbnail: "small", adminThumbnail: "small",
mimeTypes: ["image/*"], mimeTypes: ["image/*"],
imageSizes: [ imageSizes: [

View File

@ -31,7 +31,6 @@ export const Users = buildCollectionConfig(
name: fields.recorder, name: fields.recorder,
type: "relationship", type: "relationship",
relationTo: Recorders.slug, relationTo: Recorders.slug,
required: true,
admin: { width: "33%" }, admin: { width: "33%" },
}, },
{ {

View File

@ -4,8 +4,8 @@ import slugify from "slugify";
export type BuildCollectionConfig = Omit<CollectionConfig, "slug" | "typescript" | "labels">; export type BuildCollectionConfig = Omit<CollectionConfig, "slug" | "typescript" | "labels">;
export type GenerationFunctionProps = { export type GenerationFunctionProps = {
labels: { singular: string; plural: string };
slug: string; slug: string;
uploadDir: string;
}; };
export const buildCollectionConfig = ( export const buildCollectionConfig = (
@ -13,7 +13,8 @@ export const buildCollectionConfig = (
generationFunction: (props: GenerationFunctionProps) => BuildCollectionConfig generationFunction: (props: GenerationFunctionProps) => BuildCollectionConfig
): CollectionConfig => { ): CollectionConfig => {
const slug = slugify(labels.plural, { lower: true, strict: true, trim: true }); 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 { return {
...config, ...config,
slug, slug,