11package models
22
3- import "time"
3+ import (
4+ "time"
5+
6+ "github.com/forceu/gokapi/internal/helper"
7+ )
48
59type FileRequest struct {
610 Id int `json:"id" redis:"id"` // The internal ID of the file request
7- UserId int `json:"userid" redis:"userid"` // The user ID of the owner
11+ UserId int `json:"userid" redis:"userid"` // The user ID of the owner
812 MaxFiles int `json:"maxfiles" redis:"maxfiles"` // The maximum number of files allowed
913 MaxSize int `json:"maxsize" redis:"maxsize"` // The maximum file size allowed in MB
1014 Expiry int64 `json:"expiry" redis:"expiry"` // The expiry time of the file request
1115 CreationDate int64 `json:"creationdate" redis:"creationdate"` // The timestamp of the file request creation
1216 Name string `json:"name" redis:"name"` // The given name for the file request
1317 UploadedFiles int `json:"uploadedfiles" redis:"-"` // Contains the number of uploaded files for this request. Needs to be calculated with Populate()
1418 LastUpload int64 `json:"lastupload" redis:"-"` // Contains the timestamp of the last upload for this request. Needs to be calculated with Populate()
19+ TotalFileSize int64 `json:"totalfilesize" redis:"-"` // Contains the file size of all uploaded files. Needs to be calculated with Populate()
1520}
1621
1722// Populate inserts the number of uploaded files and the last upload date
1823func (f * FileRequest ) Populate (files map [string ]File ) {
1924 for _ , file := range files {
2025 if file .UploadRequestId == f .Id {
2126 f .UploadedFiles ++
27+ f .TotalFileSize = f .TotalFileSize + file .SizeBytes
2228 if file .UploadDate > f .LastUpload {
2329 f .LastUpload = file .UploadDate
2430 }
@@ -33,3 +39,7 @@ func (f *FileRequest) GetReadableDateLastUpdate() string {
3339 }
3440 return time .Unix (f .LastUpload , 0 ).Format ("2006-01-02 15:04:05" )
3541}
42+
43+ func (f * FileRequest ) GetReadableTotalSize () string {
44+ return helper .ByteCountSI (f .TotalFileSize )
45+ }
0 commit comments