feat: add a Status method for uploads

This commit is contained in:
Derrick Hammer 2023-06-06 16:33:14 -04:00
parent d0e59c8729
commit 1f195cf328
Signed by: pcfreak30
GPG Key ID: C997C339BE476FF2
1 changed files with 32 additions and 0 deletions

View File

@ -20,6 +20,12 @@ import (
"strings"
)
const (
STATUS_UPLOADED = iota
STATUS_UPLOADING = iota
STATUS_NOT_FOUND = iota
)
var client *resty.Client
func Init() {
@ -176,6 +182,32 @@ func Download(hash string) (io.Reader, error) {
}
}
func Status(hash string) int {
var count int64
uploadItem := db.Get().Table("uploads").Where(&model.Upload{Hash: hash}).Count(&count)
if uploadItem.Error != nil {
logger.Get().Error("Failed querying upload from db", zap.Error(uploadItem.Error))
}
if count > 0 {
return STATUS_UPLOADED
}
tusItem := db.Get().Table("tus").Where(&model.Tus{Hash: hash}).Count(&count)
if tusItem.Error != nil {
logger.Get().Error("Failed querying upload from db", zap.Error(tusItem.Error))
}
if count > 0 {
return STATUS_UPLOADING
}
return STATUS_NOT_FOUND
}
func objectUrlBuilder(hash string, bus bool, proof bool) string {
path := []string{}
if bus {