26 lines
1.2 KiB
TypeScript
26 lines
1.2 KiB
TypeScript
import type { CollectionBeforeOperationHook } from 'payload';
|
|
/**
|
|
* Normalizes a filename: slugifies the NAME part (diacritics, spaces, case)
|
|
* while preserving the extension. Keeps uploaded media URLs clean and portable.
|
|
*
|
|
* "Zdjęcie jeden nad morzem.jpg" → "zdjecie-jeden-nad-morzem.jpg"
|
|
* "Faktura #12 (2024).PDF" → "faktura-12-2024.pdf"
|
|
* "already-clean.webp" → "already-clean.webp"
|
|
*
|
|
* Why not toSlug(): toSlug uses strict:true, which would strip the dot and
|
|
* merge name+extension. Here we split on the LAST dot, slug the stem, lowercase
|
|
* the extension, and rejoin.
|
|
*/
|
|
export declare function normalizeFilename(filename: string): string;
|
|
/**
|
|
* beforeOperation hook for an upload collection (e.g. Media). Rewrites the
|
|
* incoming file's name to its normalized form before Payload stores it, so both
|
|
* the stored file and its DB filename are clean. Works with local disk and with
|
|
* cloud storage adapters (R2/S3) — it runs before the storage layer.
|
|
*
|
|
* Wire into your Media collection:
|
|
* import { normalizeFilenameHook } from '@intecion/ipal-kit'
|
|
* hooks: { beforeOperation: [normalizeFilenameHook] }
|
|
*/
|
|
export declare const normalizeFilenameHook: CollectionBeforeOperationHook;
|