Integrate S3 storage solution into the project
This commit is contained in:
@ -7,7 +7,6 @@ import (
|
||||
"github.com/fossyy/filekeeper/utils"
|
||||
fileView "github.com/fossyy/filekeeper/view/client/file"
|
||||
"net/http"
|
||||
"path/filepath"
|
||||
"strconv"
|
||||
)
|
||||
|
||||
@ -16,6 +15,7 @@ func GET(w http.ResponseWriter, r *http.Request) {
|
||||
query := r.URL.Query().Get("q")
|
||||
status := r.URL.Query().Get("status")
|
||||
var fileStatus types.FileStatus
|
||||
|
||||
if status == "private" {
|
||||
fileStatus = types.Private
|
||||
} else if status == "public" {
|
||||
@ -23,6 +23,7 @@ func GET(w http.ResponseWriter, r *http.Request) {
|
||||
} else {
|
||||
fileStatus = types.All
|
||||
}
|
||||
|
||||
files, err := app.Server.Database.GetFiles(userSession.UserID.String(), query, fileStatus)
|
||||
if err != nil {
|
||||
app.Server.Logger.Error(err.Error())
|
||||
@ -33,12 +34,16 @@ func GET(w http.ResponseWriter, r *http.Request) {
|
||||
var filesData []types.FileData
|
||||
|
||||
for _, file := range files {
|
||||
saveFolder := filepath.Join("uploads", userSession.UserID.String(), file.ID.String())
|
||||
prefix := fmt.Sprintf("%s/%s/chunk_", file.OwnerID.String(), file.ID.String())
|
||||
|
||||
pattern := fmt.Sprintf("%s/chunk_*", saveFolder)
|
||||
chunkFiles, err := filepath.Glob(pattern)
|
||||
existingChunks, err := app.Server.Storage.ListObjects(r.Context(), prefix)
|
||||
if err != nil {
|
||||
app.Server.Logger.Error(err.Error())
|
||||
w.WriteHeader(http.StatusInternalServerError)
|
||||
return
|
||||
}
|
||||
|
||||
missingChunk := err != nil || len(chunkFiles) != int(file.TotalChunk)
|
||||
missingChunk := len(existingChunks) != int(file.TotalChunk)
|
||||
|
||||
filesData = append(filesData, types.FileData{
|
||||
ID: file.ID.String(),
|
||||
@ -62,5 +67,4 @@ func GET(w http.ResponseWriter, r *http.Request) {
|
||||
}
|
||||
|
||||
w.WriteHeader(http.StatusForbidden)
|
||||
return
|
||||
}
|
||||
|
Reference in New Issue
Block a user