feat: complete remediation phase 3
Some checks failed
Automated Container Build / build-and-push (push) Failing after 15s
Some checks failed
Automated Container Build / build-and-push (push) Failing after 15s
This commit is contained in:
parent
0221e277a6
commit
6772ba8c43
10 changed files with 63 additions and 20 deletions
|
|
@ -554,7 +554,7 @@ func (h *FSHandler) Delete(c *fiber.Ctx) error {
|
|||
isPermanent := c.Query("permanent") == "true"
|
||||
if isPermanent {
|
||||
// Ensure we don't delete the root
|
||||
if resolvedPath == c.Locals("resolvedPath").(string) && relativePath == "." {
|
||||
if resolvedPath == h.Config.StorageDir && relativePath == "." {
|
||||
return c.Status(fiber.StatusForbidden).JSON(fiber.Map{"error": "cannot permanently delete root"})
|
||||
}
|
||||
|
||||
|
|
@ -592,8 +592,14 @@ func (h *FSHandler) Delete(c *fiber.Ctx) error {
|
|||
|
||||
if err := os.Rename(resolvedPath, trashPath); err != nil {
|
||||
fmt.Printf("Rename error %s -> %s: %v. Attempting copy & delete fallback...\n", resolvedPath, trashPath, err)
|
||||
if err := copyFile(resolvedPath, trashPath); err != nil {
|
||||
return c.Status(fiber.StatusInternalServerError).JSON(fiber.Map{"error": "failed to move to trash"})
|
||||
if isDir == 1 {
|
||||
if err := copyDir(resolvedPath, trashPath); err != nil {
|
||||
return c.Status(fiber.StatusInternalServerError).JSON(fiber.Map{"error": "failed to move directory to trash"})
|
||||
}
|
||||
} else {
|
||||
if err := copyFile(resolvedPath, trashPath); err != nil {
|
||||
return c.Status(fiber.StatusInternalServerError).JSON(fiber.Map{"error": "failed to move file to trash"})
|
||||
}
|
||||
}
|
||||
safeRemovePath(h.Config.StorageDir, resolvedPath)
|
||||
}
|
||||
|
|
|
|||
|
|
@ -119,13 +119,11 @@ func (h *ShareHandler) ListShares(c *fiber.Ctx) error {
|
|||
|
||||
// Skip expired shares
|
||||
if expiresAt != nil {
|
||||
t, err := time.Parse("2006-01-02 15:04:05-07:00", *expiresAt)
|
||||
if err == nil && time.Now().After(t) {
|
||||
// To handle different time formats, we could parse it more robustly
|
||||
// but for now, we'll let frontend also check or we just check here.
|
||||
t, err := time.Parse(time.RFC3339, *expiresAt)
|
||||
if err != nil {
|
||||
t, err = time.Parse("2006-01-02 15:04:05", *expiresAt)
|
||||
}
|
||||
t2, err2 := time.Parse(time.RFC3339, *expiresAt)
|
||||
if err2 == nil && time.Now().After(t2) {
|
||||
if err == nil && time.Now().After(t) {
|
||||
continue
|
||||
}
|
||||
}
|
||||
|
|
|
|||
|
|
@ -21,6 +21,16 @@ import (
|
|||
"golang.org/x/net/webdav"
|
||||
)
|
||||
|
||||
type statusCapture struct {
|
||||
http.ResponseWriter
|
||||
statusCode int
|
||||
}
|
||||
|
||||
func (sc *statusCapture) WriteHeader(code int) {
|
||||
sc.statusCode = code
|
||||
sc.ResponseWriter.WriteHeader(code)
|
||||
}
|
||||
|
||||
type WebDAVHandler struct {
|
||||
Handler *webdav.Handler
|
||||
DB *database.DB
|
||||
|
|
@ -117,11 +127,11 @@ func (h *WebDAVHandler) Handle(c *fiber.Ctx) error {
|
|||
// Adapt Fiber's FastHTTP to standard net/http for the WebDAV handler
|
||||
fasthttpadaptor.NewFastHTTPHandlerFunc(func(w http.ResponseWriter, r *http.Request) {
|
||||
relPath := strings.TrimPrefix(r.URL.Path, "/webdav")
|
||||
// Native WebDAV handles overwriting automatically
|
||||
h.Handler.ServeHTTP(w, r)
|
||||
|
||||
// If it was a PUT request, we should sync it with our DB (checksum, size, etc.)
|
||||
if r.Method == "PUT" && r.Response != nil && r.Response.StatusCode >= 200 && r.Response.StatusCode < 300 {
|
||||
capture := &statusCapture{ResponseWriter: w, statusCode: 200}
|
||||
h.Handler.ServeHTTP(capture, r)
|
||||
|
||||
if r.Method == "PUT" && capture.statusCode >= 200 && capture.statusCode < 300 {
|
||||
h.syncToDB(relPath)
|
||||
}
|
||||
})(c.Context())
|
||||
|
|
|
|||
Reference in a new issue