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,
hash,
manager?
): Promise<S>;Upload a pdf file, replacing the entity's current pdf if it has one. The new file is written before the old one is removed, so a failed upload keeps the issued pdf.
Type Parameters ​
| Type Parameter |
|---|
T extends object |
S extends Pdf |
Parameters ​
| Parameter | Type | Default value | Description |
|---|---|---|---|
entity | T | undefined | The entity that has the pdf property |
PdfType | () => S | undefined | The pdf type, must be manually specified since the entities pdf can be undefined |
fileData | Buffer | undefined | The file data |
createdBy | User | undefined | The user that created the file |
hash | string | undefined | The hash of the parameters the pdf was rendered from |
manager | EntityManager | AppDataSource.manager | The entity manager to save with, so the pdf follows the caller's transaction |
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>