fix: some weird upload bugs

This commit is contained in:
2025-11-30 19:39:47 +00:00
parent a3110b67c3
commit ccdeaf0364
5 changed files with 17 additions and 6 deletions

View File

@@ -19,7 +19,8 @@ import (
func NewServer(c Config) (*fiber.App, error) { func NewServer(c Config) (*fiber.App, error) {
app := fiber.New(fiber.Config{ app := fiber.New(fiber.Config{
ErrorHandler: httperr.ErrorHandler, ErrorHandler: httperr.ErrorHandler,
StreamRequestBody: true,
}) })
app.Use(logger.New()) app.Use(logger.New())

View File

@@ -2,6 +2,7 @@ package upload
import ( import (
"errors" "errors"
"fmt"
"github.com/get-drexa/drexa/internal/account" "github.com/get-drexa/drexa/internal/account"
"github.com/get-drexa/drexa/internal/httperr" "github.com/get-drexa/drexa/internal/httperr"
@@ -57,6 +58,10 @@ func (h *HTTPHandler) Create(c *fiber.Ctx) error {
return httperr.Internal(err) return httperr.Internal(err)
} }
if upload.UploadURL == "" {
upload.UploadURL = fmt.Sprintf("%s%s/%s/content", c.BaseURL(), c.OriginalURL(), upload.ID)
}
return c.JSON(upload) return c.JSON(upload)
} }
@@ -68,9 +73,12 @@ func (h *HTTPHandler) ReceiveContent(c *fiber.Ctx) error {
uploadID := c.Params("uploadID") uploadID := c.Params("uploadID")
err := h.service.ReceiveUpload(c.Context(), h.db, account.ID, uploadID, c.Request().BodyStream()) err := h.service.ReceiveUpload(c.Context(), h.db, account.ID, uploadID, c.Context().RequestBodyStream())
defer c.Request().CloseBodyStream() defer c.Context().Request.CloseBodyStream()
if err != nil { if err != nil {
if errors.Is(err, ErrNotFound) {
return c.SendStatus(fiber.StatusNotFound)
}
return httperr.Internal(err) return httperr.Internal(err)
} }

View File

@@ -3,6 +3,7 @@ package upload
import ( import (
"context" "context"
"errors" "errors"
"fmt"
"io" "io"
"sync" "sync"
"time" "time"
@@ -84,6 +85,7 @@ func (s *Service) CreateUpload(ctx context.Context, db bun.IDB, accountID uuid.U
} }
func (s *Service) ReceiveUpload(ctx context.Context, db bun.IDB, accountID uuid.UUID, uploadID string, reader io.Reader) error { func (s *Service) ReceiveUpload(ctx context.Context, db bun.IDB, accountID uuid.UUID, uploadID string, reader io.Reader) error {
fmt.Printf("reader: %v\n", reader)
n, ok := s.pendingUploads.Load(uploadID) n, ok := s.pendingUploads.Load(uploadID)
if !ok { if !ok {
return ErrNotFound return ErrNotFound

View File

@@ -12,7 +12,7 @@ import (
const absolutePathQuery = `WITH RECURSIVE path AS ( const absolutePathQuery = `WITH RECURSIVE path AS (
SELECT id, parent_id, name, 1 as depth SELECT id, parent_id, name, 1 as depth
FROM vfs_nodes WHERE id = $1 AND deleted_at IS NULL FROM vfs_nodes WHERE id = ? AND deleted_at IS NULL
UNION ALL UNION ALL

View File

@@ -228,7 +228,7 @@ func (vfs *VirtualFS) WriteFile(ctx context.Context, db bun.IDB, node *Node, con
setCols = append(setCols, "mime_type", "blob_key", "size", "status") setCols = append(setCols, "mime_type", "blob_key", "size", "status")
} }
_, err := db.NewUpdate().Model(&node). _, err := db.NewUpdate().Model(node).
Column(setCols...). Column(setCols...).
WherePK(). WherePK().
Exec(ctx) Exec(ctx)
@@ -260,7 +260,7 @@ func (vfs *VirtualFS) CreateDirectory(ctx context.Context, db bun.IDB, accountID
Name: name, Name: name,
} }
_, err = db.NewInsert().Model(&node).Exec(ctx) _, err = db.NewInsert().Model(node).Exec(ctx)
if err != nil { if err != nil {
if database.IsUniqueViolation(err) { if database.IsUniqueViolation(err) {
return nil, ErrNodeConflict return nil, ErrNodeConflict