Add indication for file upload errors and corruption

This commit is contained in:
2024-09-16 19:55:37 +07:00
parent cfd3bbb985
commit 17e55a3e90
5 changed files with 529 additions and 344 deletions

View File

@ -1,11 +1,14 @@
package visibilityHandler
import (
"fmt"
"github.com/fossyy/filekeeper/app"
"github.com/fossyy/filekeeper/types"
"github.com/fossyy/filekeeper/utils"
fileView "github.com/fossyy/filekeeper/view/client/file"
"net/http"
"os"
"path/filepath"
"strconv"
)
@ -30,12 +33,23 @@ func PUT(w http.ResponseWriter, r *http.Request) {
app.Server.Logger.Error(err.Error())
return
}
saveFolder := filepath.Join("uploads", userSession.UserID.String(), file.ID.String(), file.Name)
missingChunk := false
for j := 0; j < int(file.TotalChunk); j++ {
fileName := fmt.Sprintf("%s/chunk_%d", saveFolder, j)
if _, err := os.Stat(fileName); os.IsNotExist(err) {
missingChunk = true
break
}
}
fileData := types.FileData{
ID: file.ID.String(),
Name: file.Name,
Size: utils.ConvertFileSize(file.Size),
IsPrivate: !file.IsPrivate,
Type: file.Type,
Done: !missingChunk,
Downloaded: strconv.FormatUint(file.Downloaded, 10),
}
component := fileView.JustFile(fileData)