SudoSOS Back-end API / internal/files / FileService
Class: FileService ​
Constructors ​
Constructor ​
ts
new FileService(workdir?, storageMethod?): FileService;Parameters ​
| Parameter | Type |
|---|---|
workdir? | string |
storageMethod? | "disk" |
Returns ​
FileService
Methods ​
createFile() ​
ts
createFile(file, fileData): Promise<BaseFile>;Create a new file in storage, given the provided parameters
Parameters ​
| Parameter | Type |
|---|---|
file | BaseFile |
fileData | Buffer |
Returns ​
Promise<BaseFile>
deleteEntityFile() ​
ts
deleteEntityFile(entityFile): Promise<void>;Delete entity file from database
Parameters ​
| Parameter | Type |
|---|---|
entityFile | | ProductImage | BannerImage |
Returns ​
Promise<void>
deleteSimpleFile() ​
ts
deleteSimpleFile(id): Promise<void>;Delete the simple file with given ID from storage and database
Parameters ​
| Parameter | Type |
|---|---|
id | number |
Returns ​
Promise<void>
getSimpleFile() ​
ts
getSimpleFile(id): Promise<DownloadFileResponse>;Get the given simple file object and data from storage
Parameters ​
| Parameter | Type |
|---|---|
id | number |
Returns ​
Promise<DownloadFileResponse>
uploadEntityImage() ​
ts
uploadEntityImage(
entity,
uploadedFile,
createdBy): Promise<ProductImage>;Upload an entity image to the given entity and replace the old one, if it exists
Parameters ​
| Parameter | Type |
|---|---|
entity | | Product | Banner |
uploadedFile | UploadedFile |
createdBy | User |
Returns ​
Promise<ProductImage>
uploadPdf() ​
ts
uploadPdf<T, S>(
entity,
PdfType,
fileData,
createdBy): Promise<S>;Upload a pdf file
Type Parameters ​
| Type Parameter |
|---|
T extends IPdfAble<S> |
S extends Pdf |
Parameters ​
| Parameter | Type | Description |
|---|---|---|
entity | T | The entity that has the pdf property |
PdfType | () => S | The pdf type, must be manually specified since the entities pdf can be undefined |
fileData | Buffer | The file data |
createdBy | User | The user that created the file |
Returns ​
Promise<S>
uploadSimpleFile() ​
ts
uploadSimpleFile(
createdBy,
uploadedFile,
fileEntity): Promise<BaseFile>;Upload a simple file to the database and put in storage
Parameters ​
| Parameter | Type |
|---|---|
createdBy | User |
uploadedFile | UploadedFile |
fileEntity | SimpleFileRequest |
Returns ​
Promise<BaseFile>