services

package
v0.0.0-...-d042ab0 Latest Latest
Warning

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

Go to latest
Published: Apr 15, 2025 License: MIT Imports: 29 Imported by: 0

Documentation

Index

Constants

View Source
const (
	MAX_PREVIEWABLE_VIDEO_SIZE = 150 * 1000 * 1000
)

Variables

This section is empty.

Functions

This section is empty.

Types

type AuthService

type AuthService struct {
	DB *gorm.DB
}

func NewAuthService

func NewAuthService(db *gorm.DB) *AuthService

func (*AuthService) Login

func (authS *AuthService) Login(email, password string) (string, error)

type DeletedFilesAndFoldersList

type DeletedFilesAndFoldersList struct {
	DeletedFiles   []string `json:"deleted_files"`
	DeletedFolders []string `json:"deleted_folders"`
}

type Disposition

type Disposition struct {
	Default         int `json:"default"`
	Dub             int `json:"dub"`
	Original        int `json:"original"`
	Comment         int `json:"comment"`
	Lyrics          int `json:"lyrics"`
	Karaoke         int `json:"karaoke"`
	Forced          int `json:"forced"`
	HearingImpaired int `json:"hearing_impaired"`
	VisualImpaired  int `json:"visual_impaired"`
	CleanEffects    int `json:"clean_effects"`
	AttachedPic     int `json:"attached_pic"`
	TimedThumbnails int `json:"timed_thumbnails"`
	Captions        int `json:"captions"`
	Descriptions    int `json:"descriptions"`
	Metadata        int `json:"metadata"`
	Dependent       int `json:"dependent"`
	StillImage      int `json:"still_image"`
}

type FileService

type FileService struct {
	DB           *gorm.DB
	BucketClient *models.BucketClient
}

func NewFileService

func NewFileService(db *gorm.DB) *FileService

NewFileService creates a new FileService with the given database connection.

Note that the BucketClient field of the returned FileService is nil, because it is only available after the JWTMiddleware has been called. This is necessary because the JWTMiddleware is responsible for setting the BucketClient on the Gin context.

func (*FileService) DeleteFilePermanent

func (fs *FileService) DeleteFilePermanent(userID, fileID uint) error

DeleteFilePermanent permanently deletes a file by deleting the file itself and its associated objects such as thumbnails and HLS files. It returns an error if the file does not exist, or if there was an internal server error.

func (*FileService) DeleteFileTemp

func (fs *FileService) DeleteFileTemp(userID, fileID uint) error

DeleteFileTemp soft deletes a file by setting its deleted_at field to the current time. It returns an error if the file does not exist, or if there was an internal server error.

func (*FileService) EmptyTrashCan

func (fs *FileService) EmptyTrashCan(userID uint) error

EmptyTrashCan deletes all files in a user's trash can. It returns an error if there was an internal server error.

func (*FileService) GetPresignedURL

func (fs *FileService) GetPresignedURL(userID uint, fileCode string) (*url.URL, error)

func (*FileService) ListFavoriteFiles

func (fs *FileService) ListFavoriteFiles(userID uint) ([]models.File, error)

ListFavoriteFiles lists all files of a user that are marked as favorite.

If an internal server error occurs, it returns a ServerError. Otherwise, it returns a list of favorite files of the user.

func (*FileService) ListTrashCanFiles

func (fs *FileService) ListTrashCanFiles(userID uint) ([]models.File, error)

ListTrashCanFiles lists all files of a user that are trashed.

If an internal server error occurs, it returns a ServerError. Otherwise, it returns a list of trashed files of the user.

func (*FileService) PatchFile

func (fs *FileService) PatchFile(userID, fileID uint, patchBody models.FilePatchBody) (*models.File, error)

PatchFile updates a file by given file id and user id.

This function also supports restoring a file from trash can by setting Restore to true.

If the file is not found, it returns a NotFoundError. If other errors occur, it returns a ServerError.

func (*FileService) SetBucketClient

func (fs *FileService) SetBucketClient(bc *models.BucketClient)

func (*FileService) SetDB

func (fs *FileService) SetDB(db *gorm.DB)

func (*FileService) UpdateFile

func (fs *FileService) UpdateFile(userID, fileID uint, updateBody models.FileUpdateBody) (*models.File, error)

UpdateFile updates a file by given file id and user id.

This function also supports restoring a file from trash can by setting Restore to true.

If the file is not found, it returns a NotFoundError. If other errors occur, it returns a ServerError.

type FolderService

type FolderService struct {
	DB           *gorm.DB
	BucketClient *models.BucketClient
}

func NewFolderService

func NewFolderService(db *gorm.DB) *FolderService

func (*FolderService) CreateFolder

func (fs *FolderService) CreateFolder(folderName, parentFolderCode string, userID uint) (*models.Folder, error)

func (*FolderService) DeleteFolderPermanent

func (fs *FolderService) DeleteFolderPermanent(folderCode string, userID uint) (*DeletedFilesAndFoldersList, error)

DeleteFolderPermanent deletes a folder and all its contents permanently. If the folder is not found, it returns a NotFoundError. If other errors occur, it returns a ServerError.

func (*FolderService) DeleteFolderTemp

func (fs *FolderService) DeleteFolderTemp(folderCode string, userID uint) error

DeleteFolderTemp deletes a folder temporarily. If the folder is not found, it returns a NotFoundError. If other errors occur, it returns a ServerError.

func (*FolderService) FetchFolderFiles

func (fs *FolderService) FetchFolderFiles(userID uint, folderCode string) ([]*models.File, error)

FetchFolderFiles fetches all files in the given folder.

If the folder is not found, it returns a NotFoundError. If other errors occur, it returns a ServerError.

func (*FolderService) GetFolderDetail

func (fs *FolderService) GetFolderDetail(userID uint, folderCode string) (*models.Folder, error)

func (*FolderService) ListFavoriteFolders

func (fs *FolderService) ListFavoriteFolders(userID uint) (*models.FolderResponse, error)

func (*FolderService) ListFolders

func (fs *FolderService) ListFolders(userID uint, folderCode string) (*models.FolderResponse, error)

ListFolders lists all folders of a user, with the given params.

If folderCode is "root", it will list all top-level folders. If folderCode is not "root", it will list all subfolders of the folder with the given folderCode.

The returned FolderResponse contains a list of folders, and their hierarchy.

If the folder is not found, it returns a NotFoundError. If other errors occur, it returns a ServerError.

func (*FolderService) ListTrashFolders

func (fs *FolderService) ListTrashFolders(userID uint) (*models.FolderResponse, error)

func (*FolderService) PatchFolder

func (fs *FolderService) PatchFolder(userID uint, folderCode string, folderUpdateBody models.FolderUpdateBody) (*models.Folder, error)

PatchFolder updates a folder. If folderUpdateBody.Restore is true, it will restore a soft-deleted folder. Refactor, isolate each field update to its own method

func (*FolderService) PostUploadProcess

func (fs *FolderService) PostUploadProcess(file *models.File, uploadedFileBytes []byte)

func (*FolderService) RecursivelyRestoreFoldersUpwards

func (fs *FolderService) RecursivelyRestoreFoldersUpwards(parentFolder *models.Folder) error

Only used when we're trying to restore a deleted (temp) folder but its parent or grandparent or great-grandparent or whatever that is, is deleted (temp)

func (*FolderService) SetBucketClient

func (fs *FolderService) SetBucketClient(bc *models.BucketClient)

func (*FolderService) SetDB

func (fs *FolderService) SetDB(db *gorm.DB)

func (*FolderService) UploadFile

func (fs *FolderService) UploadFile(userID uint, folderCode string, file *multipart.FileHeader) (*models.File, []byte, error)

type Format

type Format struct {
	Filename       string     `json:"filename"`
	NbStreams      int        `json:"nb_streams"`
	NbPrograms     int        `json:"nb_programs"`
	FormatName     string     `json:"format_name"`
	FormatLongName string     `json:"format_long_name"`
	StartTime      string     `json:"start_time"`
	Duration       string     `json:"duration"`
	Size           string     `json:"size"`
	BitRate        string     `json:"bit_rate"`
	ProbeScore     int        `json:"probe_score"`
	Tags           FormatTags `json:"tags"`
}

type FormatTags

type FormatTags struct {
	MajorBrand       string `json:"major_brand"`
	MinorVersion     string `json:"minor_version"`
	CompatibleBrands string `json:"compatible_brands"`
	Encoder          string `json:"encoder"`
}

type HLSService

type HLSService struct {
	DB           *gorm.DB
	BucketClient *models.BucketClient
}

func NewHLSService

func NewHLSService(db *gorm.DB, bc *models.BucketClient) *HLSService

func (*HLSService) DeleteHLSFiles

func (hs *HLSService) DeleteHLSFiles(file *models.File) error

func (*HLSService) GetMasterPlaylist

func (hs *HLSService) GetMasterPlaylist(fileCode string) (*minio.Object, *int64, error)

GetMasterPlaylist fetches the master playlist of a HLS file given its file code.

It returns the master playlist object, its size, and an error if any. If the file does not exist, it returns a NotFoundError. If there was an internal server error, it returns a ServerError.

func (*HLSService) GetSegment

func (hs *HLSService) GetSegment(fileCode, segNum string) (*minio.Object, *int64, error)

GetSegment fetches a segment of a HLS file given its file code and segment number.

It returns the segment object, its size, and an error if any. If the file does not exist, it returns a NotFoundError. If there was an internal server error, it returns a ServerError.

func (*HLSService) ProcessHLS

func (hs *HLSService) ProcessHLS(filePath string, file *models.File)

func (*HLSService) SetBucketClient

func (hs *HLSService) SetBucketClient(bc *models.BucketClient)

func (*HLSService) SetDB

func (hs *HLSService) SetDB(db *gorm.DB)

type ProbeResult

type ProbeResult struct {
	Streams []Stream `json:"streams"`
	Format  Format   `json:"format"`
}

type Service

type Service interface {
	SetDB(db *gorm.DB)
	SetBucketClient(bc *models.BucketClient)
}

type Stream

type Stream struct {
	Index              int         `json:"index"`
	CodecName          string      `json:"codec_name"`
	CodecLongName      string      `json:"codec_long_name"`
	Profile            string      `json:"profile"`
	CodecType          string      `json:"codec_type"`
	CodecTagString     string      `json:"codec_tag_string"`
	CodecTag           string      `json:"codec_tag"`
	Width              int         `json:"width"`
	Height             int         `json:"height"`
	CodedWidth         int         `json:"coded_width"`
	CodedHeight        int         `json:"coded_height"`
	ClosedCaptions     int         `json:"closed_captions"`
	FilmGrain          int         `json:"film_grain"`
	HasBFrames         int         `json:"has_b_frames"`
	SampleAspectRatio  string      `json:"sample_aspect_ratio"`
	DisplayAspectRatio string      `json:"display_aspect_ratio"`
	PixFmt             string      `json:"pix_fmt"`
	Level              int         `json:"level"`
	ColorRange         string      `json:"color_range"`
	ColorSpace         string      `json:"color_space"`
	ColorTransfer      string      `json:"color_transfer"`
	ColorPrimaries     string      `json:"color_primaries"`
	ChromaLocation     string      `json:"chroma_location"`
	FieldOrder         string      `json:"field_order"`
	Refs               int         `json:"refs"`
	IsAvc              string      `json:"is_avc"`
	NalLengthSize      string      `json:"nal_length_size"`
	ID                 string      `json:"id"`
	RFrameRate         string      `json:"r_frame_rate"`
	AvgFrameRate       string      `json:"avg_frame_rate"`
	TimeBase           string      `json:"time_base"`
	StartPts           int         `json:"start_pts"`
	StartTime          string      `json:"start_time"`
	DurationTs         int         `json:"duration_ts"`
	Duration           string      `json:"duration"`
	BitRate            string      `json:"bit_rate"`
	BitsPerRawSample   string      `json:"bits_per_raw_sample"`
	NbFrames           string      `json:"nb_frames"`
	ExtradataSize      int         `json:"extradata_size"`
	Disposition        Disposition `json:"disposition"`
	Tags               Tags        `json:"tags"`
	SampleFmt          string      `json:"sample_fmt"`
	SampleRate         string      `json:"sample_rate"`
	Channels           int         `json:"channels"`
	ChannelLayout      string      `json:"channel_layout"`
	BitsPerSample      int         `json:"bits_per_sample"`
	InitialPadding     int         `json:"initial_padding"`
}

type Tags

type Tags struct {
	Language    string `json:"language"`
	HandlerName string `json:"handler_name"`
	VendorID    string `json:"vendor_id"`
}

type ThumbnailService

type ThumbnailService struct {
	DB           *gorm.DB
	BucketClient *models.BucketClient
}

func NewThumbnailService

func NewThumbnailService(db *gorm.DB, bc *models.BucketClient) *ThumbnailService

func (*ThumbnailService) DeleteThumbnail

func (ts *ThumbnailService) DeleteThumbnail(thumbnail *models.Thumbnail) error

func (*ThumbnailService) GenerateThumbnail

func (ts *ThumbnailService) GenerateThumbnail(filePath string, file *models.File)

func (*ThumbnailService) GetThumbnail

func (ts *ThumbnailService) GetThumbnail(fileCode string, userID uint, isDeleted bool) (*minio.Object, error)

func (*ThumbnailService) SetBucketClient

func (ts *ThumbnailService) SetBucketClient(bc *models.BucketClient)

func (*ThumbnailService) SetDB

func (ts *ThumbnailService) SetDB(db *gorm.DB)

type UserService

type UserService struct {
	DB          *gorm.DB
	MinioClient *minio.Client
}

func NewUserService

func NewUserService(db *gorm.DB, mc *minio.Client) *UserService

func (*UserService) CreateUser

func (us *UserService) CreateUser(userBody *models.UserBody) (*models.User, error)

func (*UserService) SetDB

func (us *UserService) SetDB(db *gorm.DB)

func (*UserService) SetMinioClient

func (us *UserService) SetMinioClient(mc *minio.Client)

Jump to

Keyboard shortcuts

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