update mods

This commit is contained in:
2025-12-02 21:17:12 +01:00
parent 513b7b726e
commit ce8a14cc91
9 changed files with 214 additions and 180 deletions

View File

@@ -18,10 +18,11 @@ package api
import (
"fmt"
"github.com/gofiber/fiber/v2"
"time"
"codeberg.org/scip/ephemerup/cfg"
"codeberg.org/scip/ephemerup/common"
"time"
"github.com/gofiber/fiber/v2"
)
const ApiVersion string = "/v1"
@@ -47,17 +48,17 @@ func Ts() string {
}
/*
Retrieve the API Context name from the session, assuming is has
been successfully authenticated. However, if there are no api
contexts defined, we'll use 'default' (set in
auth.validateAPIKey()).
Retrieve the API Context name from the session, assuming is has
been successfully authenticated. However, if there are no api
contexts defined, we'll use 'default' (set in
auth.validateAPIKey()).
If there's no apicontext in the session, assume unauth user, return ""
If there's no apicontext in the session, assume unauth user, return ""
*/
func SessionGetApicontext(c *fiber.Ctx) (string, error) {
sess, err := Sessionstore.Get(c)
if err != nil {
return "", fmt.Errorf("Unable to initialize session store from context: " + err.Error())
return "", fmt.Errorf("Unable to initialize session store from context: %s", err.Error())
}
apicontext := sess.Get("apicontext")
@@ -69,14 +70,14 @@ func SessionGetApicontext(c *fiber.Ctx) (string, error) {
}
/*
Retrieve the formid (aka onetime api key) from the session. It is
configured if an upload request has been successfully authenticated
using a onetime key.
Retrieve the formid (aka onetime api key) from the session. It is
configured if an upload request has been successfully authenticated
using a onetime key.
*/
func SessionGetFormId(c *fiber.Ctx) (string, error) {
sess, err := Sessionstore.Get(c)
if err != nil {
return "", fmt.Errorf("Unable to initialize session store from context: " + err.Error())
return "", fmt.Errorf("Unable to initialize session store from context: %s", err.Error())
}
formid := sess.Get("formid")
@@ -88,12 +89,13 @@ func SessionGetFormId(c *fiber.Ctx) (string, error) {
}
/*
Calculate if time is up based on start time.Time and
duration. Returns true if time is expired. Start time comes from
the database.
Calculate if time is up based on start time.Time and
duration. Returns true if time is expired. Start time comes from
the database.
aka:
if(now - start) >= duration { time is up}
if(now - start) >= duration { time is up}
*/
func IsExpired(conf *cfg.Config, start time.Time, duration string) bool {
var expiretime int // seconds