diff --git a/handler/file/file.go b/handler/file/file.go index 4e370bd..28d1b0e 100644 --- a/handler/file/file.go +++ b/handler/file/file.go @@ -8,6 +8,8 @@ import ( "github.com/fossyy/filekeeper/utils" fileView "github.com/fossyy/filekeeper/view/client/file" "net/http" + "os" + "path/filepath" "strconv" ) @@ -20,14 +22,25 @@ func GET(w http.ResponseWriter, r *http.Request) { return } var filesData []types.FileData - for i := 0; i < len(files); i++ { + for _, file := range files { + 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 + } + } filesData = append(filesData, types.FileData{ - ID: files[i].ID.String(), - Name: files[i].Name, - Size: utils.ConvertFileSize(files[i].Size), - IsPrivate: files[i].IsPrivate, - Type: files[i].Type, - Downloaded: strconv.FormatUint(files[i].Downloaded, 10), + 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), }) } diff --git a/handler/file/visibility/visibility.go b/handler/file/visibility/visibility.go index 3e59a52..a7f4e8b 100644 --- a/handler/file/visibility/visibility.go +++ b/handler/file/visibility/visibility.go @@ -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) diff --git a/types/types.go b/types/types.go index 8510e8c..98eef82 100644 --- a/types/types.go +++ b/types/types.go @@ -32,6 +32,7 @@ type FileData struct { Size string IsPrivate bool Type string + Done bool Downloaded string } diff --git a/view/client/file/file.templ b/view/client/file/file.templ index b938bf3..934a9ea 100644 --- a/view/client/file/file.templ +++ b/view/client/file/file.templ @@ -71,14 +71,32 @@ templ MainContent(files []types.FileData, user types.User, allowance *types.Allo
for _, file := range files {