Add recursive deletion for S3 objects to enable folder deletion
This commit is contained in:
@ -31,14 +31,14 @@ func DELETE(w http.ResponseWriter, r *http.Request) {
|
||||
return
|
||||
}
|
||||
|
||||
err = app.Server.Service.RemoveUserFilesCache(r.Context(), userSession.UserID)
|
||||
err = app.Server.Cache.RemoveUserFilesCache(r.Context(), userSession.UserID)
|
||||
if err != nil {
|
||||
w.WriteHeader(http.StatusInternalServerError)
|
||||
app.Server.Logger.Error(err.Error())
|
||||
return
|
||||
}
|
||||
|
||||
err = app.Server.Storage.Delete(r.Context(), fmt.Sprintf("%s/%s", file.OwnerID.String(), file.ID.String()))
|
||||
err = app.Server.Storage.DeleteRecursive(r.Context(), fmt.Sprintf("%s/%s", file.OwnerID.String(), file.ID.String()))
|
||||
if err != nil {
|
||||
w.WriteHeader(http.StatusInternalServerError)
|
||||
app.Server.Logger.Error(err.Error())
|
||||
|
@ -12,7 +12,7 @@ import (
|
||||
|
||||
func GET(w http.ResponseWriter, r *http.Request) {
|
||||
userSession := r.Context().Value("user").(types.User)
|
||||
files, err := app.Server.Service.GetUserFiles(r.Context(), userSession.UserID)
|
||||
files, err := app.Server.Cache.GetUserFiles(r.Context(), userSession.UserID)
|
||||
if err != nil {
|
||||
w.WriteHeader(http.StatusInternalServerError)
|
||||
app.Server.Logger.Error(err.Error())
|
||||
@ -21,7 +21,7 @@ func GET(w http.ResponseWriter, r *http.Request) {
|
||||
var filesData []types.FileData
|
||||
|
||||
for _, file := range files {
|
||||
userFile, err := app.Server.Service.GetFileDetail(r.Context(), file.ID)
|
||||
userFile, err := app.Server.Cache.GetFileDetail(r.Context(), file.ID)
|
||||
if err != nil {
|
||||
w.WriteHeader(http.StatusInternalServerError)
|
||||
app.Server.Logger.Error(err.Error())
|
||||
@ -38,7 +38,7 @@ func GET(w http.ResponseWriter, r *http.Request) {
|
||||
return
|
||||
}
|
||||
|
||||
usage, err := app.Server.Service.CalculateUserStorageUsage(r.Context(), userSession.UserID.String())
|
||||
usage, err := app.Server.Cache.CalculateUserStorageUsage(r.Context(), userSession.UserID.String())
|
||||
if err != nil {
|
||||
w.WriteHeader(http.StatusInternalServerError)
|
||||
app.Server.Logger.Error(err.Error())
|
||||
|
@ -31,7 +31,7 @@ func GET(w http.ResponseWriter, r *http.Request) {
|
||||
var filesData []types.FileData
|
||||
|
||||
for _, file := range files {
|
||||
userFile, err := app.Server.Service.GetFileDetail(r.Context(), file.ID)
|
||||
userFile, err := app.Server.Cache.GetFileDetail(r.Context(), file.ID)
|
||||
if err != nil {
|
||||
w.WriteHeader(http.StatusInternalServerError)
|
||||
app.Server.Logger.Error(err.Error())
|
||||
|
@ -36,21 +36,21 @@ func PATCH(w http.ResponseWriter, r *http.Request) {
|
||||
return
|
||||
}
|
||||
|
||||
err = app.Server.Service.RemoveFileCache(r.Context(), fileID)
|
||||
err = app.Server.Cache.RemoveFileCache(r.Context(), fileID)
|
||||
if err != nil {
|
||||
w.WriteHeader(http.StatusInternalServerError)
|
||||
app.Server.Logger.Error(err.Error())
|
||||
return
|
||||
}
|
||||
|
||||
err = app.Server.Service.RemoveUserFilesCache(r.Context(), userSession.UserID)
|
||||
err = app.Server.Cache.RemoveUserFilesCache(r.Context(), userSession.UserID)
|
||||
if err != nil {
|
||||
w.WriteHeader(http.StatusInternalServerError)
|
||||
app.Server.Logger.Error(err.Error())
|
||||
return
|
||||
}
|
||||
|
||||
userFile, err := app.Server.Service.GetFileDetail(r.Context(), newFile.ID)
|
||||
userFile, err := app.Server.Cache.GetFileDetail(r.Context(), newFile.ID)
|
||||
if err != nil {
|
||||
w.WriteHeader(http.StatusInternalServerError)
|
||||
app.Server.Logger.Error(err.Error())
|
||||
|
@ -9,7 +9,7 @@ import (
|
||||
|
||||
func GET(w http.ResponseWriter, r *http.Request) {
|
||||
userSession := r.Context().Value("user").(types.User)
|
||||
files, err := app.Server.Service.GetUserFiles(r.Context(), userSession.UserID)
|
||||
files, err := app.Server.Cache.GetUserFiles(r.Context(), userSession.UserID)
|
||||
if err != nil {
|
||||
w.WriteHeader(http.StatusInternalServerError)
|
||||
app.Server.Logger.Error(err.Error())
|
||||
@ -18,7 +18,7 @@ func GET(w http.ResponseWriter, r *http.Request) {
|
||||
var filesData []types.FileData
|
||||
|
||||
for _, file := range files {
|
||||
userFile, err := app.Server.Service.GetFileDetail(r.Context(), file.ID)
|
||||
userFile, err := app.Server.Cache.GetFileDetail(r.Context(), file.ID)
|
||||
if err != nil {
|
||||
w.WriteHeader(http.StatusInternalServerError)
|
||||
app.Server.Logger.Error(err.Error())
|
||||
|
@ -16,7 +16,7 @@ func POST(w http.ResponseWriter, r *http.Request) {
|
||||
return
|
||||
}
|
||||
|
||||
file, err := app.Server.Service.GetFile(r.Context(), fileID)
|
||||
file, err := app.Server.Cache.GetFile(r.Context(), fileID)
|
||||
if err != nil {
|
||||
app.Server.Logger.Error("error getting upload info: " + err.Error())
|
||||
w.WriteHeader(http.StatusInternalServerError)
|
||||
@ -52,7 +52,7 @@ func POST(w http.ResponseWriter, r *http.Request) {
|
||||
app.Server.Logger.Error("error copying byte to file dst: " + err.Error())
|
||||
return
|
||||
}
|
||||
err = app.Server.Service.UpdateFileChunk(r.Context(), file.ID, file.OwnerID, rawIndex, file.TotalChunk)
|
||||
err = app.Server.Cache.UpdateFileChunk(r.Context(), file.ID, file.OwnerID, rawIndex, file.TotalChunk)
|
||||
if err != nil {
|
||||
w.WriteHeader(http.StatusInternalServerError)
|
||||
app.Server.Logger.Error(err.Error())
|
||||
|
@ -29,21 +29,21 @@ func PUT(w http.ResponseWriter, r *http.Request) {
|
||||
return
|
||||
}
|
||||
|
||||
err = app.Server.Service.RemoveFileCache(r.Context(), fileID)
|
||||
err = app.Server.Cache.RemoveFileCache(r.Context(), fileID)
|
||||
if err != nil {
|
||||
w.WriteHeader(http.StatusInternalServerError)
|
||||
app.Server.Logger.Error(err.Error())
|
||||
return
|
||||
}
|
||||
|
||||
err = app.Server.Service.RemoveUserFilesCache(r.Context(), userSession.UserID)
|
||||
err = app.Server.Cache.RemoveUserFilesCache(r.Context(), userSession.UserID)
|
||||
if err != nil {
|
||||
w.WriteHeader(http.StatusInternalServerError)
|
||||
app.Server.Logger.Error(err.Error())
|
||||
return
|
||||
}
|
||||
|
||||
userFile, err := app.Server.Service.GetFileDetail(r.Context(), file.ID)
|
||||
userFile, err := app.Server.Cache.GetFileDetail(r.Context(), file.ID)
|
||||
if err != nil {
|
||||
w.WriteHeader(http.StatusInternalServerError)
|
||||
app.Server.Logger.Error(err.Error())
|
||||
|
Reference in New Issue
Block a user