mirror of
https://codeberg.org/scip/ephemerup.git
synced 2025-12-17 20:50:56 +01:00
add download, fix empty apicontext, add url to describe
This commit is contained in:
@@ -49,6 +49,7 @@ type Upload struct {
|
||||
Members []string `json:"members"` // contains multiple files, so File is an archive
|
||||
Uploaded Timestamp `json:"uploaded"`
|
||||
Context string `json:"context"`
|
||||
Url string `json:"url"`
|
||||
}
|
||||
|
||||
// this one is also used for marshalling to the client
|
||||
@@ -170,5 +171,10 @@ func GetApicontext(c *fiber.Ctx) (string, error) {
|
||||
return "", fmt.Errorf("Unable to initialize session store from context: " + err.Error())
|
||||
}
|
||||
|
||||
return sess.Get("apicontext").(string), nil
|
||||
apicontext := sess.Get("apicontext")
|
||||
if apicontext != nil {
|
||||
return apicontext.(string), nil
|
||||
}
|
||||
|
||||
return "", nil
|
||||
}
|
||||
|
||||
@@ -25,6 +25,7 @@ import (
|
||||
|
||||
"os"
|
||||
"path/filepath"
|
||||
"strings"
|
||||
"time"
|
||||
)
|
||||
|
||||
@@ -260,6 +261,10 @@ func Describe(c *fiber.Ctx, cfg *cfg.Config, db *Db) error {
|
||||
"No upload with that id could be found!")
|
||||
}
|
||||
|
||||
for _, upload := range uploads.Entries {
|
||||
upload.Url = strings.Join([]string{cfg.Url, "download", id, upload.File}, "/")
|
||||
}
|
||||
|
||||
// if we reached this point we can signal success
|
||||
uploads.Success = true
|
||||
uploads.Code = fiber.StatusOK
|
||||
|
||||
@@ -54,28 +54,31 @@ func Runserver(conf *cfg.Config, args []string) error {
|
||||
// authenticated routes
|
||||
api := router.Group(conf.ApiPrefix + ApiVersion)
|
||||
{
|
||||
// authenticated routes
|
||||
// upload
|
||||
api.Post("/file/", auth, func(c *fiber.Ctx) error {
|
||||
return FilePut(c, conf, db)
|
||||
})
|
||||
|
||||
// download w/o expire
|
||||
api.Get("/file/:id/:file", auth, func(c *fiber.Ctx) error {
|
||||
return FileGet(c, conf, db)
|
||||
})
|
||||
|
||||
api.Get("/file/:id/", auth, func(c *fiber.Ctx) error {
|
||||
return FileGet(c, conf, db)
|
||||
})
|
||||
|
||||
// remove
|
||||
api.Delete("/file/:id/", auth, func(c *fiber.Ctx) error {
|
||||
err := DeleteUpload(c, conf, db)
|
||||
return SendResponse(c, "", err)
|
||||
})
|
||||
|
||||
// listing
|
||||
api.Get("/list/", auth, func(c *fiber.Ctx) error {
|
||||
return List(c, conf, db)
|
||||
})
|
||||
|
||||
// info
|
||||
api.Get("/upload/:id/", auth, func(c *fiber.Ctx) error {
|
||||
return Describe(c, conf, db)
|
||||
})
|
||||
|
||||
Reference in New Issue
Block a user