chore: verified download mechanism
This commit is contained in:
@@ -16,7 +16,7 @@ func spawnFileRoutes(file *gin.RouterGroup, env utility.Environment, db *gorm.DB
|
|||||||
// /file/<file-name>
|
// /file/<file-name>
|
||||||
file.GET("/:filename", func(c *gin.Context) {
|
file.GET("/:filename", func(c *gin.Context) {
|
||||||
f := c.Param("filename")
|
f := c.Param("filename")
|
||||||
p := filepath.Join(env.DataDirectory, "content", f)
|
p := filepath.Join(env.ContentDirectory, f)
|
||||||
|
|
||||||
c.File(p)
|
c.File(p)
|
||||||
})
|
})
|
||||||
@@ -50,9 +50,9 @@ func spawnFileRoutes(file *gin.RouterGroup, env utility.Environment, db *gorm.DB
|
|||||||
|
|
||||||
if err := database.RegisterFile(db, fileData); err != nil {
|
if err := database.RegisterFile(db, fileData); err != nil {
|
||||||
if errors.Is(err, gorm.ErrDuplicatedKey) {
|
if errors.Is(err, gorm.ErrDuplicatedKey) {
|
||||||
slog.Debug("discarding file since its a duplicate", "error", err)
|
slog.Debug("discarding file since its checksum is a duplicate", "error", err)
|
||||||
c.JSON(http.StatusConflict, RespObj{
|
c.JSON(http.StatusConflict, RespObj{
|
||||||
Msg: "file is a duplicate",
|
Msg: "file checksum already exists",
|
||||||
})
|
})
|
||||||
} else {
|
} else {
|
||||||
slog.Error("failed to insert filedata to the database", "error", err)
|
slog.Error("failed to insert filedata to the database", "error", err)
|
||||||
@@ -74,7 +74,8 @@ func spawnFileRoutes(file *gin.RouterGroup, env utility.Environment, db *gorm.DB
|
|||||||
|
|
||||||
slog.Info("saved file to local filesystem and database")
|
slog.Info("saved file to local filesystem and database")
|
||||||
c.JSON(http.StatusCreated, RespObj{
|
c.JSON(http.StatusCreated, RespObj{
|
||||||
Msg: "file has succesfully been uploaded",
|
Msg: "file has succesfully been uploaded",
|
||||||
|
Data: fileData,
|
||||||
})
|
})
|
||||||
})
|
})
|
||||||
}
|
}
|
||||||
|
|||||||
Reference in New Issue
Block a user