feat: add a Status method for uploads
This commit is contained in:
parent
d0e59c8729
commit
1f195cf328
|
@ -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 {
|
||||
|
|
Loading…
Reference in New Issue