mirror of
https://codeberg.org/scip/ephemerup.git
synced 2025-12-18 21:11:04 +01:00
fix endpoints
This commit is contained in:
@@ -106,7 +106,7 @@ func (db *Db) Delete(apicontext string, id string) error {
|
||||
return err
|
||||
}
|
||||
|
||||
func (db *Db) List(apicontext string, filter string) (*common.Uploads, error) {
|
||||
func (db *Db) UploadsList(apicontext string, filter string) (*common.Uploads, error) {
|
||||
uploads := &common.Uploads{}
|
||||
|
||||
err := db.bolt.View(func(tx *bolt.Tx) error {
|
||||
|
||||
@@ -34,7 +34,7 @@ type SetContext struct {
|
||||
Apicontext string `json:"apicontext" form:"apicontext"`
|
||||
}
|
||||
|
||||
func FilePut(c *fiber.Ctx, cfg *cfg.Config, db *Db) error {
|
||||
func UploadPost(c *fiber.Ctx, cfg *cfg.Config, db *Db) error {
|
||||
// supports upload of multiple files with:
|
||||
//
|
||||
// curl -X POST localhost:8080/putfile \
|
||||
@@ -106,6 +106,7 @@ func FilePut(c *fiber.Ctx, cfg *cfg.Config, db *Db) error {
|
||||
"Could not process uploaded file[s]: "+err.Error())
|
||||
}
|
||||
entry.File = Newfilename
|
||||
entry.Url = returnUrl
|
||||
|
||||
Log("Now serving %s from %s/%s", returnUrl, cfg.StorageDir, id)
|
||||
Log("Expire set to: %s", entry.Expire)
|
||||
@@ -117,12 +118,11 @@ func FilePut(c *fiber.Ctx, cfg *cfg.Config, db *Db) error {
|
||||
// everything went well so far
|
||||
res := &common.Uploads{Entries: []*common.Upload{entry}}
|
||||
res.Success = true
|
||||
res.Message = "Download url: " + returnUrl
|
||||
res.Code = fiber.StatusOK
|
||||
return c.Status(fiber.StatusOK).JSON(res)
|
||||
}
|
||||
|
||||
func FileGet(c *fiber.Ctx, cfg *cfg.Config, db *Db, shallExpire ...bool) error {
|
||||
func UploadFetch(c *fiber.Ctx, cfg *cfg.Config, db *Db, shallExpire ...bool) error {
|
||||
// deliver a file and delete it if expire is set to asap
|
||||
|
||||
// we ignore c.Params("file"), cause it may be malign. Also we've
|
||||
@@ -173,7 +173,7 @@ func FileGet(c *fiber.Ctx, cfg *cfg.Config, db *Db, shallExpire ...bool) error {
|
||||
}
|
||||
|
||||
// delete file, id dir and db entry
|
||||
func DeleteUpload(c *fiber.Ctx, cfg *cfg.Config, db *Db) error {
|
||||
func UploadDelete(c *fiber.Ctx, cfg *cfg.Config, db *Db) error {
|
||||
|
||||
id, err := common.Untaint(c.Params("id"), cfg.RegKey)
|
||||
if err != nil {
|
||||
@@ -206,7 +206,7 @@ func DeleteUpload(c *fiber.Ctx, cfg *cfg.Config, db *Db) error {
|
||||
}
|
||||
|
||||
// returns the whole list + error code, no post processing by server
|
||||
func List(c *fiber.Ctx, cfg *cfg.Config, db *Db) error {
|
||||
func UploadsList(c *fiber.Ctx, cfg *cfg.Config, db *Db) error {
|
||||
// fetch filter from body(json expected)
|
||||
setcontext := new(SetContext)
|
||||
if err := c.BodyParser(setcontext); err != nil {
|
||||
@@ -228,7 +228,7 @@ func List(c *fiber.Ctx, cfg *cfg.Config, db *Db) error {
|
||||
}
|
||||
|
||||
// get list
|
||||
uploads, err := db.List(apicontext, filter)
|
||||
uploads, err := db.UploadsList(apicontext, filter)
|
||||
if err != nil {
|
||||
return JsonStatus(c, fiber.StatusForbidden,
|
||||
"Unable to list uploads: "+err.Error())
|
||||
@@ -242,7 +242,7 @@ func List(c *fiber.Ctx, cfg *cfg.Config, db *Db) error {
|
||||
}
|
||||
|
||||
// returns just one upload obj + error code, no post processing by server
|
||||
func Describe(c *fiber.Ctx, cfg *cfg.Config, db *Db) error {
|
||||
func UploadDescribe(c *fiber.Ctx, cfg *cfg.Config, db *Db) error {
|
||||
id, err := common.Untaint(c.Params("id"), cfg.RegKey)
|
||||
if err != nil {
|
||||
return JsonStatus(c, fiber.StatusForbidden,
|
||||
|
||||
@@ -56,29 +56,29 @@ func Runserver(conf *cfg.Config, args []string) error {
|
||||
api := router.Group(conf.ApiPrefix + ApiVersion)
|
||||
{
|
||||
// upload
|
||||
api.Post("/uploads/", auth, func(c *fiber.Ctx) error {
|
||||
return FilePut(c, conf, db)
|
||||
api.Post("/uploads", auth, func(c *fiber.Ctx) error {
|
||||
return UploadPost(c, conf, db)
|
||||
})
|
||||
|
||||
// remove
|
||||
api.Delete("/uploads/:id/", auth, func(c *fiber.Ctx) error {
|
||||
err := DeleteUpload(c, conf, db)
|
||||
api.Delete("/uploads/:id", auth, func(c *fiber.Ctx) error {
|
||||
err := UploadDelete(c, conf, db)
|
||||
return SendResponse(c, "", err)
|
||||
})
|
||||
|
||||
// listing
|
||||
api.Get("/uploads", auth, func(c *fiber.Ctx) error {
|
||||
return List(c, conf, db)
|
||||
return UploadsList(c, conf, db)
|
||||
})
|
||||
|
||||
// info/describe
|
||||
api.Get("/upload/:id/", auth, func(c *fiber.Ctx) error {
|
||||
return Describe(c, conf, db)
|
||||
api.Get("/uploads/:id", auth, func(c *fiber.Ctx) error {
|
||||
return UploadDescribe(c, conf, db)
|
||||
})
|
||||
|
||||
// download w/o expire
|
||||
api.Get("/download/:id/", auth, func(c *fiber.Ctx) error {
|
||||
return FileGet(c, conf, db)
|
||||
api.Get("/uploads/:id/file", auth, func(c *fiber.Ctx) error {
|
||||
return UploadFetch(c, conf, db)
|
||||
})
|
||||
}
|
||||
|
||||
@@ -89,11 +89,11 @@ func Runserver(conf *cfg.Config, args []string) error {
|
||||
})
|
||||
|
||||
router.Get("/download/:id/:file", func(c *fiber.Ctx) error {
|
||||
return FileGet(c, conf, db, shallExpire)
|
||||
return UploadFetch(c, conf, db, shallExpire)
|
||||
})
|
||||
|
||||
router.Get("/download/:id/", func(c *fiber.Ctx) error {
|
||||
return FileGet(c, conf, db, shallExpire)
|
||||
router.Get("/download/:id", func(c *fiber.Ctx) error {
|
||||
return UploadFetch(c, conf, db, shallExpire)
|
||||
})
|
||||
}
|
||||
|
||||
|
||||
Reference in New Issue
Block a user