file

package
v1.0.68 Latest Latest
Warning

This package is not in the latest version of its module.

Go to latest
Published: Aug 22, 2025 License: MIT Imports: 10 Imported by: 0

Documentation

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

This section is empty.

Types

type FileService

type FileService struct {
	// contains filtered or unexported fields
}

func NewFileService

func NewFileService(ctx *context.ERPContext, baseURL string) *FileService

NewFileService creates a new instance of FileService.

It takes an ERPContext and a baseURL as parameter and returns a pointer to a FileService.

It uses the ERPContext to initialize the FileService and run the migration for the FileModel database schema.

func (*FileService) DeleteFile

func (s *FileService) DeleteFile(id string) error

DeleteFile deletes a file by its ID.

It takes an ID as parameter and retrieves the associated FileModel from the database. If the file provider is "local", it deletes the file from the local file system. If the file provider is "firebase", it deletes the file from the Firebase Storage. The function then deletes the FileModel from the database. It returns an error if any of the operations fail.

func (*FileService) GetFileByID

func (s *FileService) GetFileByID(id string) (*models.FileModel, error)

GetFileByID retrieves a file by its ID.

It takes an ID as parameter and returns the FileModel if found, otherwise an error.

func (*FileService) UpdateFileByID

func (s *FileService) UpdateFileByID(id string, file *models.FileModel) error

func (*FileService) UpdateFileRefByID

func (s *FileService) UpdateFileRefByID(id string, refID, refType string) error

UpdateFileRefByID updates the reference ID and type of a file in the database by its ID.

It takes a string id, a string refID, and a string refType as parameters. The function returns an error if the update operation fails.

func (*FileService) UploadFile

func (s *FileService) UploadFile(file []byte, provider, folder string, fileObj *models.FileModel) error

UploadFile uploads a file to a provider.

It takes a byte array, a provider, a folder and a pointer to a FileModel as parameter.

It detects the mime type of the file from the byte array and then calls the UploadFileToFirebaseStorage method of the Firestore service if the provider is "firebase", or writes the file to the local file system if the provider is "local".

It returns an error if there is an error uploading the file to the provider.

func (*FileService) UploadFileFromBase64

func (s *FileService) UploadFileFromBase64(base64String, provider, folder string, fileObj *models.FileModel) error

UploadFileFromBase64 uploads a file from a base64 encoded string.

It takes a base64 encoded string, a provider, a folder and a pointer to a FileModel as parameter.

It decodes the base64 string into a byte array and then calls UploadFile with the byte array and the given parameters.

It returns an error if there is an error decoding the base64 string or uploading the file.

Jump to

Keyboard shortcuts

? : This menu
/ : Search site
f or F : Jump to
y or Y : Canonical URL