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",
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: [
{

View File

@ -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: [
{

View File

@ -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: [
{

View File

@ -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: [

View File

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

View File

@ -4,8 +4,8 @@ import slugify from "slugify";
export type BuildCollectionConfig = Omit<CollectionConfig, "slug" | "typescript" | "labels">;
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,