@unchainedshop/core-files
File management module for the Unchained Engine. Handles media file metadata storage and URL normalization.
npm install @unchainedshop/core-files
import { configureFilesModule } from '@unchainedshop/core-files' ;
const filesModule = await configureFilesModule ( {
db,
options : {
transformUrl : ( url , params ) => url , // Optional URL transformation
} ,
} ) ;
// Create a file record
const fileId = await filesModule . create ( {
name : 'product-image.jpg' ,
type : 'image/jpeg' ,
path : 'products/123' ,
url : '/uploads/product-image.jpg' ,
} ) ;
// Find file and normalize URL
const file = await filesModule . findFile ( { fileId } ) ;
const normalizedUrl = filesModule . normalizeUrl ( file . url , { } ) ;
Export
Description
configureFilesModule
Configure and return the files module
Method
Description
findFile
Find file by ID or URL
findFiles
Find files with custom selector
Method
Description
create
Create a new file record
update
Update an existing file
delete
Delete a file record
deleteMany
Delete multiple file records
unexpire
Remove expiration from a file
Method
Description
normalizeUrl
Normalize and transform file URL
Export
Description
getFileAdapter
Get configured file storage adapter
getFileFromFileData
Convert file data to File object
filesSettings
Access file module settings
Export
Description
File
File document type
FilesModule
Module interface type
FilesSettingsOptions
Configuration options type
const filesModule = await configureFilesModule ( {
db,
options : {
transformUrl : ( url , params ) => {
// Transform URLs for CDN, thumbnails, etc.
return `https://cdn.example.com${ url } ` ;
} ,
} ,
} ) ;
Event
Description
FILE_CREATE
Emitted when a file is created
FILE_UPDATE
Emitted when a file is updated
FILE_REMOVE
Emitted when a file is removed
EUPL-1.2