Skip to content

Commit

Permalink
fix file upload in /Marti/sync/upload
Browse files Browse the repository at this point in the history
  • Loading branch information
kdudkov committed Jan 9, 2025
1 parent eabca74 commit 15c811a
Show file tree
Hide file tree
Showing 4 changed files with 13 additions and 4 deletions.
8 changes: 6 additions & 2 deletions cmd/goatak_server/marti_api.go
Original file line number Diff line number Diff line change
Expand Up @@ -39,7 +39,11 @@ type MartiAPI struct {

func NewMartiApi(app *App, addr string) *MartiAPI {
api := &MartiAPI{
f: fiber.New(fiber.Config{EnablePrintRoutes: false, DisableStartupMessage: true, BodyLimit: 64 * 1024 * 1024}),
f: fiber.New(fiber.Config{
EnablePrintRoutes: false,
DisableStartupMessage: true,
BodyLimit: 64 * 1024 * 1024,
StreamRequestBody: true}),
addr: addr,
}

Expand Down Expand Up @@ -314,7 +318,7 @@ func (app *App) uploadFile(ctx *fiber.Ctx, uid, filename string) (*im.Content, e
username := Username(ctx)
user := app.users.GetUser(username)

hash, n, err := app.files.PutFile("", ctx.Request().BodyStream())
hash, n, err := app.files.PutFile("", ctx.Context().RequestBodyStream())

if err != nil {
app.logger.Error("save file error", slog.Any("error", err))
Expand Down
4 changes: 2 additions & 2 deletions internal/model/mission.go
Original file line number Diff line number Diff line change
Expand Up @@ -23,7 +23,7 @@ type Mission struct {
Tool string
Groups string
Keywords string
Points []*MissionPoint
Files []*MissionFile
Points []*MissionPoint `gorm:"constraint:OnDelete:CASCADE"`
Files []*MissionFile `gorm:"constraint:OnDelete:CASCADE"`
Token string
}
1 change: 1 addition & 0 deletions internal/model/mission_file.go
Original file line number Diff line number Diff line change
Expand Up @@ -24,6 +24,7 @@ type Content struct {
Tool string `gorm:"index"`
Keywords string
Kw tools.StringSet `gorm:"-"`
MissionFiles []*MissionFile `gorm:"constraint:OnDelete:CASCADE"`
}

type MissionFile struct {
Expand Down
4 changes: 4 additions & 0 deletions internal/pm/blob_manager.go
Original file line number Diff line number Diff line change
Expand Up @@ -58,6 +58,10 @@ func (m *BlobManager) GetFileStat(hash string) (os.FileInfo, error) {
}

func (m *BlobManager) PutFile(hash string, r io.Reader) (string, int64, error) {
if r == nil {
return "", 0, fmt.Errorf("no reader")
}

m.mx.Lock()
defer m.mx.Unlock()

Expand Down

0 comments on commit 15c811a

Please sign in to comment.