feat: add file visibility toggle for files

This commit is contained in:
2024-09-15 23:59:19 +07:00
parent dc330cc72f
commit b246d85fac
22 changed files with 738 additions and 144 deletions

View File

@ -3,6 +3,7 @@ package downloadHandler
import (
"fmt"
"github.com/fossyy/filekeeper/app"
"github.com/fossyy/filekeeper/session"
"github.com/fossyy/filekeeper/types/models"
"io"
"net/http"
@ -21,6 +22,17 @@ func GET(w http.ResponseWriter, r *http.Request) {
return
}
status, userSession, _ := session.GetSession(r)
if file.IsPrivate {
if status == session.Unauthorized || status == session.InvalidSession {
w.WriteHeader(http.StatusForbidden)
return
} else if file.OwnerID != userSession.UserID {
w.WriteHeader(http.StatusUnauthorized)
return
}
}
uploadDir := "uploads"
currentDir, _ := os.Getwd()
basePath := filepath.Join(currentDir, uploadDir)