Skip to content

Commit 5d10d5d

Browse files
committed
Added Total size column, display max files in table as well
1 parent e8f5601 commit 5d10d5d

File tree

2 files changed

+18
-2
lines changed

2 files changed

+18
-2
lines changed

internal/models/FileRequest.go

Lines changed: 12 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,24 +1,30 @@
11
package models
22

3-
import "time"
3+
import (
4+
"time"
5+
6+
"github.com/forceu/gokapi/internal/helper"
7+
)
48

59
type 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
1823
func (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+
}

internal/webserver/web/templates/html_uploadrequest.tmpl

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -25,6 +25,7 @@
2525
<tr>
2626
<th scope="col">Name</th>
2727
<th scope="col">Uploaded Files</th>
28+
<th scope="col">Total Size</th>
2829
<th scope="col">Last Upload</th>
2930
<th scope="col">Expiry</th>
3031
{{ if .ActiveUser.HasPermissionListOtherUploads }}
@@ -38,7 +39,12 @@
3839
{{ range .FileRequests }}
3940
<tr id="row-{{ .Id }}">
4041
<td>{{ .Name }}</td>
42+
{{ if eq .MaxFiles 0 }}
4143
<td>{{ .UploadedFiles }}</td>
44+
{{ else }}
45+
<td>{{ .UploadedFiles }} / {{ .MaxFiles }}</td>
46+
{{ end }}
47+
<td>{{ .GetReadableTotalSize }}</td>
4248
<td><span id="cell-lastupdate-{{ .Id }}"></span></td>
4349
<script>insertDateWithNegative({{ .LastUpload }}, "cell-lastupdate-{{ .Id }}", "None");</script>
4450
<td><span id="cell-expiry-{{ .Id }}"></span></td>

0 commit comments

Comments
 (0)