Skip to content

SudoSOS Back-end API / internal/files / FileService

Class: FileService ​

Constructors ​

Constructor ​

ts
new FileService(workdir?, storageMethod?): FileService;

Parameters ​

ParameterType
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 ​

ParameterType
fileBaseFile
fileDataBuffer

Returns ​

Promise<BaseFile>


deleteEntityFile() ​

ts
deleteEntityFile(entityFile): Promise<void>;

Delete entity file from database

Parameters ​

ParameterType
entityFile| ProductImage | BannerImage

Returns ​

Promise<void>


deleteSimpleFile() ​

ts
deleteSimpleFile(id): Promise<void>;

Delete the simple file with given ID from storage and database

Parameters ​

ParameterType
idnumber

Returns ​

Promise<void>


getSimpleFile() ​

ts
getSimpleFile(id): Promise<DownloadFileResponse>;

Get the given simple file object and data from storage

Parameters ​

ParameterType
idnumber

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 ​

ParameterType
entity| Product | Banner
uploadedFileUploadedFile
createdByUser

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 ​

ParameterTypeDefault valueDescription
entityTundefinedThe entity that has the pdf property
PdfType() => SundefinedThe pdf type, must be manually specified since the entities pdf can be undefined
fileDataBufferundefinedThe file data
createdByUserundefinedThe user that created the file
hashstringundefinedThe hash of the parameters the pdf was rendered from
managerEntityManagerAppDataSource.managerThe 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 ​

ParameterType
createdByUser
uploadedFileUploadedFile
fileEntitySimpleFileRequest

Returns ​

Promise<BaseFile>