@adonis-agora/media
Version:
Media-library for AdonisJS — owner collections (MIME whitelist, single-file replace, ordering), image conversions (eager/lazy), pluggable content transformers (HLS video via mediabunny, metadata probe, image blur-up placeholder), and column attachments, a
21 lines • 1.3 kB
TypeScript
/**
* Validate a client-supplied upload file name before it is interpolated into a storage key.
*
* Unlike a transformer's own output path — validated by `assertSafeArtifactPath` in
* `media_library.ts`, which only has to keep the transformer's OWN bookkeeping honest — a
* `fileName` comes straight off the wire (a multipart field, a TUS `Upload-Metadata` header) and
* must be treated as hostile.
*
* A file name is, by definition, a single path segment: it names a file, not a location. So
* anything that would add or change segments — a `/` or `\`, an empty string, a bare `.` or `..`,
* a control character — is rejected outright with {@link UnsafeFileNameError}, never silently
* stripped down to a "safe" basename. That mirrors `assertSafeArtifactPath`'s stance: a
* traversal-shaped input is never something to normalize into place.
*
* Every call site that builds a storage key from a client-supplied file name must route it through
* here first: `MediaLibrary#layoutPath`, the default `keyFor` of `DirectUploadHandler` and
* `TusUploadHandler`, and `AttachmentManager#createFromFile` (the separate adonis-attachment-style
* API in `attachment.ts`).
*/
export declare function sanitizeFileName(fileName: string): string;
//# sourceMappingURL=file_name.d.ts.map