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 { - - @FileIcon(file.Type) -
- - {file.Name} - -
- + if !file.Done { + + @FileIcon(file.Type) +
+ + {file.Name} + +
+ + + + Corrupted +
+
+ + } else { + + @FileIcon(file.Type) +
+ + {file.Name} + +
+ + } + { file.Size }
@@ -135,51 +153,53 @@ templ MainContent(files []types.FileData, user types.User, allowance *types.Allo ") + _, templ_7745c5c3_Err = templ_7745c5c3_Buffer.WriteString("
") if templ_7745c5c3_Err != nil { return templ_7745c5c3_Err } @@ -552,9 +670,9 @@ func FileIcon(fileType string) templ.Component { defer templ.ReleaseBuffer(templ_7745c5c3_Buffer) } ctx = templ.InitializeContext(ctx) - templ_7745c5c3_Var30 := templ.GetChildren(ctx) - if templ_7745c5c3_Var30 == nil { - templ_7745c5c3_Var30 = templ.NopComponent + templ_7745c5c3_Var34 := templ.GetChildren(ctx) + if templ_7745c5c3_Var34 == nil { + templ_7745c5c3_Var34 = templ.NopComponent } ctx = templ.ClearChildren(ctx) if fileType == "jpg" || fileType == "jpeg" || fileType == "png" || fileType == "gif" || fileType == "bmp" || fileType == "tiff" { @@ -593,9 +711,9 @@ func Main(title string, files []types.FileData, user types.User, allowance *type defer templ.ReleaseBuffer(templ_7745c5c3_Buffer) } ctx = templ.InitializeContext(ctx) - templ_7745c5c3_Var31 := templ.GetChildren(ctx) - if templ_7745c5c3_Var31 == nil { - templ_7745c5c3_Var31 = templ.NopComponent + templ_7745c5c3_Var35 := templ.GetChildren(ctx) + if templ_7745c5c3_Var35 == nil { + templ_7745c5c3_Var35 = templ.NopComponent } ctx = templ.ClearChildren(ctx) templ_7745c5c3_Err = component(title, files, user, allowance).Render(ctx, templ_7745c5c3_Buffer)