2022-12-22 04:45:15 +00:00
|
|
|
package admin
|
|
|
|
|
|
|
|
import (
|
2023-01-31 04:38:30 +00:00
|
|
|
"encoding/json"
|
2023-04-04 05:15:17 +00:00
|
|
|
"fmt"
|
2024-11-28 17:54:36 +00:00
|
|
|
"forge.lightcrystal.systems/nilix/felt/admin/util"
|
|
|
|
"forge.lightcrystal.systems/nilix/felt/models"
|
|
|
|
"forge.lightcrystal.systems/nilix/felt/mongodb"
|
|
|
|
"forge.lightcrystal.systems/nilix/quartzgun/auth"
|
|
|
|
. "forge.lightcrystal.systems/nilix/quartzgun/middleware"
|
|
|
|
"forge.lightcrystal.systems/nilix/quartzgun/rateLimiter"
|
|
|
|
"forge.lightcrystal.systems/nilix/quartzgun/renderer"
|
|
|
|
"forge.lightcrystal.systems/nilix/quartzgun/router"
|
|
|
|
. "forge.lightcrystal.systems/nilix/quartzgun/util"
|
2023-02-10 05:45:09 +00:00
|
|
|
"html/template"
|
2023-03-04 05:05:57 +00:00
|
|
|
"io/ioutil"
|
2023-02-10 05:45:09 +00:00
|
|
|
"net/http"
|
2023-03-04 05:05:57 +00:00
|
|
|
"os"
|
|
|
|
"path/filepath"
|
2023-07-06 04:27:38 +00:00
|
|
|
"regexp"
|
2024-05-04 01:21:51 +00:00
|
|
|
"strings"
|
2022-12-22 04:45:15 +00:00
|
|
|
)
|
|
|
|
|
2022-12-22 16:39:39 +00:00
|
|
|
func apiGetTableList(next http.Handler, udb auth.UserStore) http.Handler {
|
2022-12-22 04:45:15 +00:00
|
|
|
handlerFunc := func(w http.ResponseWriter, req *http.Request) {
|
|
|
|
|
2022-12-25 04:02:35 +00:00
|
|
|
user := util.GetUserFromToken(req)
|
|
|
|
self, err := util.GetTablesByUser(user, udb)
|
2022-12-22 04:45:15 +00:00
|
|
|
if err != nil {
|
2022-12-25 04:02:35 +00:00
|
|
|
w.WriteHeader(404)
|
|
|
|
} else {
|
|
|
|
AddContextValue(req, "tableList", self)
|
2022-12-22 04:45:15 +00:00
|
|
|
}
|
2022-12-25 04:02:35 +00:00
|
|
|
next.ServeHTTP(w, req)
|
|
|
|
}
|
2022-12-22 04:45:15 +00:00
|
|
|
|
2022-12-25 04:02:35 +00:00
|
|
|
return http.HandlerFunc(handlerFunc)
|
|
|
|
}
|
|
|
|
|
|
|
|
func apiGetTableData(next http.Handler, udb auth.UserStore, dbAdapter mongodb.DbAdapter) http.Handler {
|
|
|
|
handlerFunc := func(w http.ResponseWriter, req *http.Request) {
|
|
|
|
|
2023-02-10 05:45:09 +00:00
|
|
|
urlParams := req.Context().Value("params").(map[string]string)
|
|
|
|
tableName := urlParams["Slug"]
|
2022-12-25 04:02:35 +00:00
|
|
|
tableKey := models.TableKey{
|
2023-02-10 05:45:09 +00:00
|
|
|
Name: tableName,
|
|
|
|
Passcode: req.FormValue("passcode"),
|
2022-12-25 04:02:35 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
if dbAdapter.CheckTable(tableKey) {
|
|
|
|
mapUrl, _ := dbAdapter.GetMapImageUrl(tableKey)
|
|
|
|
auxMessage, _ := dbAdapter.GetAuxMessage(tableKey)
|
2023-07-08 07:42:31 +00:00
|
|
|
tokens, _ := dbAdapter.GetTokens(tableKey, false)
|
2023-02-10 05:45:09 +00:00
|
|
|
diceRolls, _ := dbAdapter.GetDiceRolls(tableKey)
|
2022-12-25 04:02:35 +00:00
|
|
|
|
|
|
|
AddContextValue(req, "tableData", models.Table{
|
2023-07-08 05:56:41 +00:00
|
|
|
Name: tableKey.Name,
|
|
|
|
Passcode: tableKey.Passcode,
|
|
|
|
DiceRolls: diceRolls,
|
|
|
|
MapImageUrl: mapUrl,
|
|
|
|
Tokens: tokens,
|
|
|
|
AuxMessage: auxMessage,
|
2022-12-25 04:02:35 +00:00
|
|
|
})
|
|
|
|
} else {
|
|
|
|
w.WriteHeader(404)
|
2022-12-22 04:45:15 +00:00
|
|
|
}
|
|
|
|
|
2022-12-22 16:39:39 +00:00
|
|
|
next.ServeHTTP(w, req)
|
2022-12-22 04:45:15 +00:00
|
|
|
}
|
|
|
|
|
2022-12-22 16:39:39 +00:00
|
|
|
return http.HandlerFunc(handlerFunc)
|
|
|
|
}
|
|
|
|
|
2022-12-25 04:02:35 +00:00
|
|
|
func apiCreateTable(next http.Handler, udb auth.UserStore, dbAdapter mongodb.DbAdapter) http.Handler {
|
|
|
|
handlerFunc := func(w http.ResponseWriter, req *http.Request) {
|
2023-01-31 04:38:30 +00:00
|
|
|
tableKey := models.TableKey{}
|
|
|
|
err := json.NewDecoder(req.Body).Decode(&tableKey)
|
|
|
|
if err != nil {
|
|
|
|
w.WriteHeader(400)
|
|
|
|
next.ServeHTTP(w, req)
|
|
|
|
return
|
|
|
|
}
|
2022-12-25 04:02:35 +00:00
|
|
|
|
2023-07-06 04:27:38 +00:00
|
|
|
r := regexp.MustCompile("^[a-zA-Z0-9_]+$")
|
|
|
|
if !r.MatchString(tableKey.Name) || !r.MatchString(tableKey.Passcode) {
|
|
|
|
w.WriteHeader(422)
|
|
|
|
next.ServeHTTP(w, req)
|
|
|
|
return
|
|
|
|
}
|
|
|
|
|
2022-12-25 04:02:35 +00:00
|
|
|
// table name is primary key so w edon't need to check
|
2023-01-28 07:28:15 +00:00
|
|
|
err = dbAdapter.CreateTable(tableKey)
|
2022-12-25 04:02:35 +00:00
|
|
|
|
|
|
|
if err != nil {
|
|
|
|
AddContextValue(req, "result", err.Error())
|
|
|
|
// TODO: parse error and change the status
|
|
|
|
w.WriteHeader(500)
|
|
|
|
} else {
|
|
|
|
user := util.GetUserFromToken(req)
|
|
|
|
tables, err := util.GetTablesByUser(user, udb)
|
|
|
|
tables = append(tables, tableKey)
|
|
|
|
err = util.SetTablesForUser(user, tables, udb)
|
|
|
|
if err != nil {
|
|
|
|
w.WriteHeader(500)
|
|
|
|
} else {
|
|
|
|
w.WriteHeader(201)
|
|
|
|
}
|
|
|
|
}
|
|
|
|
next.ServeHTTP(w, req)
|
|
|
|
}
|
|
|
|
|
|
|
|
return http.HandlerFunc(handlerFunc)
|
|
|
|
}
|
|
|
|
|
2023-07-10 05:41:30 +00:00
|
|
|
func apiDestroyTable(next http.Handler, udb auth.UserStore, dbAdapter mongodb.DbAdapter, uploads string) http.Handler {
|
2022-12-25 04:02:35 +00:00
|
|
|
handlerFunc := func(w http.ResponseWriter, req *http.Request) {
|
|
|
|
// check table actually belongs to this user
|
2023-01-05 04:59:54 +00:00
|
|
|
user := util.GetUserFromToken(req)
|
|
|
|
tables, err := util.GetTablesByUser(user, udb)
|
|
|
|
|
|
|
|
if err == nil {
|
|
|
|
|
|
|
|
destroy := false
|
|
|
|
i := 0
|
2023-01-31 04:38:30 +00:00
|
|
|
|
2023-02-26 05:43:38 +00:00
|
|
|
table := models.TableKey{}
|
|
|
|
err = json.NewDecoder(req.Body).Decode(&table)
|
|
|
|
if err != nil {
|
|
|
|
w.WriteHeader(400)
|
2023-04-06 04:33:38 +00:00
|
|
|
return
|
2023-01-05 04:59:54 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
for j, t := range tables {
|
|
|
|
if t.Name == table.Name && t.Passcode == table.Passcode {
|
2023-01-31 04:38:30 +00:00
|
|
|
|
|
|
|
// try to destroy it
|
|
|
|
destroy = dbAdapter.DestroyTable(table) == nil
|
|
|
|
i = j
|
|
|
|
break
|
|
|
|
}
|
2023-01-05 04:59:54 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
if destroy {
|
2023-07-10 05:41:30 +00:00
|
|
|
os.RemoveAll(filepath.Join(uploads, table.Name))
|
2023-01-05 04:59:54 +00:00
|
|
|
newTables := append(tables[:i], tables[i+1:]...)
|
|
|
|
util.SetTablesForUser(user, newTables, udb)
|
|
|
|
w.WriteHeader(204)
|
|
|
|
} else {
|
|
|
|
w.WriteHeader(404)
|
|
|
|
}
|
2023-03-04 05:05:57 +00:00
|
|
|
next.ServeHTTP(w, req)
|
2023-01-31 04:38:30 +00:00
|
|
|
|
2023-01-05 04:59:54 +00:00
|
|
|
} else {
|
|
|
|
w.WriteHeader(500)
|
|
|
|
}
|
|
|
|
next.ServeHTTP(w, req)
|
2022-12-25 04:02:35 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
return http.HandlerFunc(handlerFunc)
|
2022-12-22 04:45:15 +00:00
|
|
|
}
|
|
|
|
|
2023-05-15 04:57:18 +00:00
|
|
|
func apiUploadImg(next http.Handler, dbAdapter mongodb.DbAdapter, uploads, uploadType string, uploadMax int) http.Handler {
|
2023-02-26 05:43:38 +00:00
|
|
|
handlerFunc := func(w http.ResponseWriter, req *http.Request) {
|
2023-03-04 05:05:57 +00:00
|
|
|
// get table from request body
|
2023-04-04 05:15:17 +00:00
|
|
|
r, err := req.MultipartReader()
|
2023-03-04 05:05:57 +00:00
|
|
|
if err != nil {
|
2023-04-04 05:15:17 +00:00
|
|
|
fmt.Println(err.Error())
|
|
|
|
}
|
|
|
|
|
|
|
|
f, err := r.ReadForm(int64(uploadMax << 20))
|
|
|
|
if err != nil {
|
|
|
|
fmt.Println(err.Error())
|
|
|
|
}
|
|
|
|
|
|
|
|
tableKey := models.TableKey{
|
|
|
|
Name: f.Value["name"][0],
|
|
|
|
Passcode: f.Value["passcode"][0],
|
2023-03-04 05:05:57 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
// check if this table exists
|
|
|
|
if !dbAdapter.CheckTable(tableKey) {
|
2023-07-04 07:08:01 +00:00
|
|
|
w.WriteHeader(404)
|
2023-03-04 05:05:57 +00:00
|
|
|
next.ServeHTTP(w, req)
|
|
|
|
return
|
|
|
|
}
|
|
|
|
|
2023-02-26 05:43:38 +00:00
|
|
|
// ensure data storage dir exists
|
2023-03-04 05:05:57 +00:00
|
|
|
info, err := os.Stat(uploads)
|
|
|
|
if !info.IsDir() {
|
2023-04-04 05:15:17 +00:00
|
|
|
fmt.Println("uploads dir aint no dir")
|
2023-03-04 05:05:57 +00:00
|
|
|
w.WriteHeader(500)
|
|
|
|
next.ServeHTTP(w, req)
|
2023-04-04 05:15:17 +00:00
|
|
|
return
|
2023-03-04 05:05:57 +00:00
|
|
|
} else if err != nil {
|
2023-04-04 05:15:17 +00:00
|
|
|
err = os.MkdirAll(uploads, 0755)
|
2023-03-04 05:05:57 +00:00
|
|
|
if err != nil {
|
2023-04-04 05:15:17 +00:00
|
|
|
fmt.Println(err.Error())
|
2023-03-04 05:05:57 +00:00
|
|
|
w.WriteHeader(500)
|
|
|
|
next.ServeHTTP(w, req)
|
|
|
|
}
|
|
|
|
}
|
2023-04-04 05:15:17 +00:00
|
|
|
err = os.MkdirAll(filepath.Join(uploads, tableKey.Name, uploadType), 0755)
|
2023-02-26 05:43:38 +00:00
|
|
|
// check for filename; call create to overwrite regardless
|
|
|
|
// get file data from multipart form
|
2023-04-04 05:15:17 +00:00
|
|
|
header := f.File["file"][0]
|
2024-05-04 01:21:51 +00:00
|
|
|
if strings.Contains(header.Filename, "/") {
|
2024-11-28 17:54:36 +00:00
|
|
|
w.WriteHeader(422)
|
|
|
|
next.ServeHTTP(w, req)
|
|
|
|
return
|
2024-05-04 01:21:51 +00:00
|
|
|
}
|
2023-04-04 05:15:17 +00:00
|
|
|
file, err := header.Open()
|
2023-03-04 05:05:57 +00:00
|
|
|
if err != nil {
|
2023-04-04 05:15:17 +00:00
|
|
|
fmt.Println(err.Error())
|
2023-03-04 05:05:57 +00:00
|
|
|
w.WriteHeader(500)
|
|
|
|
next.ServeHTTP(w, req)
|
2024-05-04 01:21:51 +00:00
|
|
|
return
|
2023-03-04 05:05:57 +00:00
|
|
|
}
|
|
|
|
fileData, err := ioutil.ReadAll(file)
|
|
|
|
if err != nil {
|
|
|
|
w.WriteHeader(500)
|
|
|
|
next.ServeHTTP(w, req)
|
2024-05-04 01:21:51 +00:00
|
|
|
return
|
2023-03-04 05:05:57 +00:00
|
|
|
}
|
2023-02-26 05:43:38 +00:00
|
|
|
// write to file
|
2023-03-04 05:05:57 +00:00
|
|
|
destPath := filepath.Join(uploads, tableKey.Name, uploadType, header.Filename)
|
2023-04-04 05:15:17 +00:00
|
|
|
fmt.Println(destPath)
|
2023-03-04 05:05:57 +00:00
|
|
|
dest, err := os.Create(destPath)
|
|
|
|
if err != nil {
|
2023-04-04 05:15:17 +00:00
|
|
|
fmt.Println(err.Error())
|
2023-03-04 05:05:57 +00:00
|
|
|
w.WriteHeader(500)
|
|
|
|
next.ServeHTTP(w, req)
|
2023-04-06 04:33:38 +00:00
|
|
|
return
|
2023-03-04 05:05:57 +00:00
|
|
|
}
|
|
|
|
dest.Write(fileData)
|
|
|
|
dest.Close()
|
2023-04-04 05:15:17 +00:00
|
|
|
|
2023-03-04 05:05:57 +00:00
|
|
|
// respond with URL so UI can update
|
|
|
|
AddContextValue(req, "location", "/uploads/"+tableKey.Name+"/"+uploadType+"/"+header.Filename)
|
|
|
|
next.ServeHTTP(w, req)
|
2023-02-26 05:43:38 +00:00
|
|
|
}
|
|
|
|
|
2023-02-26 21:22:18 +00:00
|
|
|
return http.HandlerFunc(handlerFunc)
|
2023-02-26 05:43:38 +00:00
|
|
|
}
|
|
|
|
|
2023-07-04 07:08:01 +00:00
|
|
|
func apiListImages(next http.Handler, uploads string, uploadType string, udb auth.UserStore, dbAdapter mongodb.DbAdapter) http.Handler {
|
2023-04-06 04:33:38 +00:00
|
|
|
handlerFunc := func(w http.ResponseWriter, req *http.Request) {
|
|
|
|
urlParams := req.Context().Value("params").(map[string]string)
|
|
|
|
tableName := urlParams["Slug"]
|
2023-07-04 07:08:01 +00:00
|
|
|
tableKey := models.TableKey{
|
|
|
|
Name: tableName,
|
|
|
|
Passcode: req.FormValue("passcode"),
|
2023-04-06 04:33:38 +00:00
|
|
|
}
|
|
|
|
|
2023-07-04 07:08:01 +00:00
|
|
|
// check table actually belongs to this user
|
|
|
|
user := util.GetUserFromToken(req)
|
|
|
|
tables, err := util.GetTablesByUser(user, udb)
|
|
|
|
|
|
|
|
if err == nil {
|
|
|
|
|
|
|
|
ok := false
|
|
|
|
|
|
|
|
for _, t := range tables {
|
|
|
|
if t.Name == tableKey.Name && t.Passcode == tableKey.Passcode {
|
|
|
|
ok = true
|
|
|
|
}
|
2023-04-06 04:33:38 +00:00
|
|
|
}
|
|
|
|
|
2023-07-04 07:08:01 +00:00
|
|
|
if ok {
|
|
|
|
if dbAdapter.CheckTable(tableKey) {
|
|
|
|
destPath := filepath.Join(uploads, tableName, uploadType)
|
|
|
|
files, err := ioutil.ReadDir(destPath)
|
|
|
|
|
|
|
|
if err != nil {
|
|
|
|
w.WriteHeader(500)
|
|
|
|
next.ServeHTTP(w, req)
|
|
|
|
return
|
|
|
|
}
|
|
|
|
|
|
|
|
fileNames := []string{}
|
|
|
|
for _, file := range files {
|
|
|
|
if !file.IsDir() {
|
|
|
|
fileNames = append(fileNames, "/uploads/"+tableName+"/"+uploadType+"/"+file.Name())
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
AddContextValue(req, "files", fileNames)
|
|
|
|
next.ServeHTTP(w, req)
|
|
|
|
return
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
2023-07-05 07:20:56 +00:00
|
|
|
w.WriteHeader(422)
|
|
|
|
next.ServeHTTP(w, req)
|
2023-04-06 04:33:38 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
return http.HandlerFunc(handlerFunc)
|
|
|
|
}
|
|
|
|
|
2023-07-04 07:08:01 +00:00
|
|
|
func apiDeleteImage(next http.Handler, uploads string, uploadType string, udb auth.UserStore, dbAdapter mongodb.DbAdapter) http.Handler {
|
|
|
|
handlerFunc := func(w http.ResponseWriter, req *http.Request) {
|
|
|
|
// put the path together
|
2023-07-05 07:20:56 +00:00
|
|
|
urlParams := req.Context().Value("params").(map[string]string)
|
2023-07-05 05:54:43 +00:00
|
|
|
tableName := urlParams["table"]
|
2023-07-04 07:08:01 +00:00
|
|
|
tableKey := models.TableKey{
|
|
|
|
Name: tableName,
|
|
|
|
Passcode: req.FormValue("passcode"),
|
|
|
|
}
|
|
|
|
|
|
|
|
// check table actually belongs to this user
|
|
|
|
user := util.GetUserFromToken(req)
|
|
|
|
tables, err := util.GetTablesByUser(user, udb)
|
|
|
|
|
|
|
|
if err == nil {
|
|
|
|
|
|
|
|
ok := false
|
|
|
|
|
|
|
|
for _, t := range tables {
|
|
|
|
if t.Name == tableKey.Name && t.Passcode == tableKey.Passcode {
|
|
|
|
ok = true
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
if ok {
|
|
|
|
if dbAdapter.CheckTable(tableKey) {
|
2023-07-05 07:20:56 +00:00
|
|
|
// if the file exists, delete it and return 201
|
|
|
|
filename := urlParams["file"]
|
2024-05-04 01:21:51 +00:00
|
|
|
if strings.Contains(filename, "/") {
|
2024-11-28 17:54:36 +00:00
|
|
|
w.WriteHeader(422)
|
|
|
|
next.ServeHTTP(w, req)
|
|
|
|
return
|
2024-05-04 01:21:51 +00:00
|
|
|
}
|
2023-07-05 07:20:56 +00:00
|
|
|
fullPath := filepath.Join(uploads, tableName, uploadType, filename)
|
|
|
|
s, err := os.Stat(fullPath)
|
|
|
|
if err == nil && !s.IsDir() {
|
|
|
|
err = os.Remove(fullPath)
|
|
|
|
if err == nil {
|
|
|
|
w.WriteHeader(201)
|
|
|
|
next.ServeHTTP(w, req)
|
|
|
|
return
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
2023-07-04 07:08:01 +00:00
|
|
|
}
|
|
|
|
// otherwise, return an error
|
2023-07-05 05:54:43 +00:00
|
|
|
w.WriteHeader(500)
|
|
|
|
next.ServeHTTP(w, req)
|
2023-07-04 07:08:01 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
return http.HandlerFunc(handlerFunc)
|
2023-05-15 04:57:18 +00:00
|
|
|
}
|
|
|
|
|
2023-02-26 21:22:18 +00:00
|
|
|
func CreateAdminInterface(udb auth.UserStore, dbAdapter mongodb.DbAdapter, uploads string, uploadMaxMB int) http.Handler {
|
2022-12-22 04:45:15 +00:00
|
|
|
// create quartzgun router
|
2023-07-10 05:41:30 +00:00
|
|
|
rtr := &router.Router{Fallback: *template.Must(template.ParseFiles("templates/error.html"))}
|
2022-12-25 04:02:35 +00:00
|
|
|
|
2024-11-28 17:54:36 +00:00
|
|
|
rl := rateLimiter.IpRateLimiter{
|
|
|
|
Data: map[string]*rateLimiter.RateLimitData{},
|
|
|
|
Seconds: 5,
|
|
|
|
AttemptsAllowed: 5,
|
|
|
|
}
|
|
|
|
|
2022-12-22 16:39:39 +00:00
|
|
|
scopes := map[string]string{}
|
2022-12-22 04:45:15 +00:00
|
|
|
|
2024-11-28 17:54:36 +00:00
|
|
|
rtr.Post("/api/auth/", Throttle(Provision(udb, 84), rl.RateLimit))
|
2023-02-26 21:22:18 +00:00
|
|
|
|
|
|
|
// table management
|
2022-12-25 04:02:35 +00:00
|
|
|
rtr.Get("/api/table/", Validate(apiGetTableList(renderer.JSON("tableList"), udb), udb, scopes))
|
|
|
|
rtr.Get(`/api/table/(?P<Slug>\S+)`, Validate(apiGetTableData(renderer.JSON("tableData"), udb, dbAdapter), udb, scopes))
|
|
|
|
rtr.Post("/api/table/", Validate(apiCreateTable(renderer.JSON("result"), udb, dbAdapter), udb, scopes))
|
2023-07-10 05:41:30 +00:00
|
|
|
rtr.Delete(`/api/table/(?P<Slug>\S+)`, Validate(apiDestroyTable(renderer.JSON("result"), udb, dbAdapter, uploads), udb, scopes))
|
2022-12-22 04:45:15 +00:00
|
|
|
|
2023-02-26 21:22:18 +00:00
|
|
|
// asset management
|
2023-05-15 04:57:18 +00:00
|
|
|
rtr.Post(`/api/upload/(?P<Slug>\S+)/map/`, Validate(apiUploadImg(renderer.JSON("location"), dbAdapter, uploads, "map", uploadMaxMB), udb, scopes))
|
2023-07-04 07:08:01 +00:00
|
|
|
rtr.Get(`/api/upload/(?P<Slug>\S+)/map/`, Validate(apiListImages(renderer.JSON("files"), uploads, "map", udb, dbAdapter), udb, scopes))
|
|
|
|
rtr.Delete(`/api/upload/(?P<table>\S+)/map/(?P<file>\S+)`, Validate(apiDeleteImage(renderer.JSON("deleted"), uploads, "map", udb, dbAdapter), udb, scopes))
|
|
|
|
rtr.Delete(`/api/upload/(?P<table>\S+)/token/(?P<file>\S+)`, Validate(apiDeleteImage(renderer.JSON("deleted"), uploads, "token", udb, dbAdapter), udb, scopes))
|
2023-05-15 04:57:18 +00:00
|
|
|
rtr.Post(`/api/upload/(?P<Slug>\S+)/token/`, Validate(apiUploadImg(renderer.JSON("location"), dbAdapter, uploads, "token", uploadMaxMB), udb, scopes))
|
2023-07-04 07:08:01 +00:00
|
|
|
rtr.Get(`/api/upload/(?P<Slug>\S+)/token/`, Validate(apiListImages(renderer.JSON("files"), uploads, "token", udb, dbAdapter), udb, scopes))
|
2023-02-26 21:22:18 +00:00
|
|
|
|
2022-12-22 16:39:39 +00:00
|
|
|
return http.HandlerFunc(rtr.ServeHTTP)
|
2022-12-22 04:45:15 +00:00
|
|
|
}
|