update module URLs to use hacklab.nilfm.cc; use struct tags for json

This commit is contained in:
Iris Lightshard 2023-01-30 21:38:30 -07:00
parent d64fb026d9
commit 92a30dd9fc
Signed by: nilix
GPG key ID: 3B7FBC22144E6398
11 changed files with 70 additions and 69 deletions

3
.gitignore vendored
View file

@ -1,5 +1,6 @@
felt
go.work
go.work.sum
user.db
mongodb/data/*
mongodb/.env
mongodb/.env

View file

@ -1,17 +1,17 @@
package admin
import (
"encoding/json"
"html/template"
"encoding/json"
"html/template"
"net/http"
"nilfm.cc/git/felt/admin/util"
"nilfm.cc/git/felt/models"
"nilfm.cc/git/felt/mongodb"
"nilfm.cc/git/quartzgun/auth"
. "nilfm.cc/git/quartzgun/middleware"
"nilfm.cc/git/quartzgun/renderer"
"nilfm.cc/git/quartzgun/router"
. "nilfm.cc/git/quartzgun/util"
"hacklab.nilfm.cc/felt/admin/util"
"hacklab.nilfm.cc/felt/models"
"hacklab.nilfm.cc/felt/mongodb"
"hacklab.nilfm.cc/quartzgun/auth"
. "hacklab.nilfm.cc/quartzgun/middleware"
"hacklab.nilfm.cc/quartzgun/renderer"
"hacklab.nilfm.cc/quartzgun/router"
. "hacklab.nilfm.cc/quartzgun/util"
)
func apiGetTableList(next http.Handler, udb auth.UserStore) http.Handler {
@ -67,13 +67,13 @@ func apiGetTableData(next http.Handler, udb auth.UserStore, dbAdapter mongodb.Db
func apiCreateTable(next http.Handler, udb auth.UserStore, dbAdapter mongodb.DbAdapter) http.Handler {
handlerFunc := func(w http.ResponseWriter, req *http.Request) {
tableKey := models.TableKey{}
err := json.NewDecoder(req.Body).Decode(&tableKey)
if err != nil {
w.WriteHeader(400)
next.ServeHTTP(w, req)
return
}
tableKey := models.TableKey{}
err := json.NewDecoder(req.Body).Decode(&tableKey)
if err != nil {
w.WriteHeader(400)
next.ServeHTTP(w, req)
return
}
// table name is primary key so w edon't need to check
err = dbAdapter.CreateTable(tableKey)
@ -109,7 +109,7 @@ func apiDestroyTable(next http.Handler, udb auth.UserStore, dbAdapter mongodb.Db
destroy := false
i := 0
tableName := req.Context().Value("Slug")
tablePass := req.Form["passcode"][0]
@ -120,12 +120,12 @@ func apiDestroyTable(next http.Handler, udb auth.UserStore, dbAdapter mongodb.Db
for j, t := range tables {
if t.Name == table.Name && t.Passcode == table.Passcode {
// try to destroy it
destroy = dbAdapter.DestroyTable(table) == nil
i = j
break
}
// try to destroy it
destroy = dbAdapter.DestroyTable(table) == nil
i = j
break
}
}
if destroy {
@ -135,7 +135,7 @@ func apiDestroyTable(next http.Handler, udb auth.UserStore, dbAdapter mongodb.Db
} else {
w.WriteHeader(404)
}
} else {
w.WriteHeader(500)
}
@ -147,7 +147,7 @@ func apiDestroyTable(next http.Handler, udb auth.UserStore, dbAdapter mongodb.Db
func CreateAdminInterface(udb auth.UserStore, dbAdapter mongodb.DbAdapter) http.Handler {
// create quartzgun router
rtr := &router.Router{ Fallback: *template.Must(template.ParseFiles("static/error.html")) }
rtr := &router.Router{Fallback: *template.Must(template.ParseFiles("static/error.html"))}
scopes := map[string]string{}

View file

@ -3,8 +3,8 @@ package util
import (
"encoding/base64"
"net/http"
"nilfm.cc/git/felt/models"
"nilfm.cc/git/quartzgun/auth"
"hacklab.nilfm.cc/felt/models"
"hacklab.nilfm.cc/quartzgun/auth"
"strings"
)

View file

@ -2,7 +2,7 @@ package cmd
import (
"fmt"
"nilfm.cc/git/quartzgun/auth"
"hacklab.nilfm.cc/quartzgun/auth"
"strings"
)

View file

@ -8,12 +8,12 @@ import (
"log"
"net/http"
"nhooyr.io/websocket"
"nilfm.cc/git/felt/admin"
"nilfm.cc/git/felt/models"
"nilfm.cc/git/felt/mongodb"
"nilfm.cc/git/quartzgun/auth"
"nilfm.cc/git/quartzgun/cookie"
"nilfm.cc/git/quartzgun/renderer"
"hacklab.nilfm.cc/felt/admin"
"hacklab.nilfm.cc/felt/models"
"hacklab.nilfm.cc/felt/mongodb"
"hacklab.nilfm.cc/quartzgun/auth"
"hacklab.nilfm.cc/quartzgun/cookie"
"hacklab.nilfm.cc/quartzgun/renderer"
"sync"
"time"
)

4
go.mod
View file

@ -1,12 +1,12 @@
module nilfm.cc/git/felt
module hacklab.nilfm.cc/felt
go 1.19
require (
go.mongodb.org/mongo-driver v1.11.0
golang.org/x/time v0.1.0
hacklab.nilfm.cc/quartzgun v0.3.0
nhooyr.io/websocket v1.8.7
nilfm.cc/git/quartzgun v0.2.1
)
require (

4
go.sum
View file

@ -103,7 +103,7 @@ gopkg.in/yaml.v2 v2.2.8/go.mod h1:hI93XBmqTisBFMUTm0b8Fm+jr3Dg1NNxqwp+5A1VGuI=
gopkg.in/yaml.v3 v3.0.0-20200313102051-9f266ea9e77c/go.mod h1:K4uyk7z7BCEPqu6E+C64Yfv1cQ7kz7rIZviUmN+EgEM=
gopkg.in/yaml.v3 v3.0.1 h1:fxVm/GzAzEWqLHuvctI91KS9hhNmmWOoWu0XTYJS7CA=
gopkg.in/yaml.v3 v3.0.1/go.mod h1:K4uyk7z7BCEPqu6E+C64Yfv1cQ7kz7rIZviUmN+EgEM=
hacklab.nilfm.cc/quartzgun v0.3.0 h1:nOTZaKaKv7q+08Y5vghOIYoMO9g+FAYQUyHzcQP6jUU=
hacklab.nilfm.cc/quartzgun v0.3.0/go.mod h1:P6qK4HB0CD/xfyRq8wdEGevAPFDDmv0KCaESSvv93LU=
nhooyr.io/websocket v1.8.7 h1:usjR2uOr/zjjkVMy0lW+PPohFok7PCow5sDjLgX4P4g=
nhooyr.io/websocket v1.8.7/go.mod h1:B70DZP8IakI65RVQ51MsWP/8jndNma26DVA/nFSCgW0=
nilfm.cc/git/quartzgun v0.2.1 h1:R2Mi07c+nzaZL+x0atPXBoPoOXvDiLKqi3lcl81T6BA=
nilfm.cc/git/quartzgun v0.2.1/go.mod h1:/DDvt1DtzNuUf3HHaP29WMei/kkdaRW+ySmEzybvVto=

View file

@ -5,9 +5,9 @@ import (
"log"
"net"
"net/http"
"nilfm.cc/git/felt/gametable"
"nilfm.cc/git/felt/mongodb"
"nilfm.cc/git/quartzgun/indentalUserDB"
"hacklab.nilfm.cc/felt/gametable"
"hacklab.nilfm.cc/felt/mongodb"
"hacklab.nilfm.cc/quartzgun/indentalUserDB"
"os"
"os/signal"
"time"
@ -34,7 +34,7 @@ func run() error {
udb := indentalUserDB.CreateIndentalUserDB(
"./user.db")
udb.AddUser("nilix", "questing")
gt := gametable.New(dbEngine, udb)

View file

@ -5,39 +5,39 @@ import (
)
type TableKey struct {
Name string `json:name`
Passcode string `json:passcode`
Name string `json:"name"`
Passcode string `json:"passcode"`
}
type DiceRoll struct {
Faces uint8
Roll []uint8
Player string
Note string
Timestamp time.Time
Faces uint8 `json:"faces"`
Roll []uint8 `json:"roll"`
Player string `json:"player"`
Note string `json:"note"`
Timestamp time.Time `json:"timestamp"`
}
type Token struct {
Id string
Name string
SpriteUri string
X int
Y int
Id string `json:"id"`
Name string `json:"name"`
SpriteUri string `json:"spriteUrl"`
X int `json:"x"`
Y int `json:"y"`
}
type Table struct {
Name string
Passcode string
MapImageUrl string
DiceRolls []DiceRoll
Tokens []Token
AvailableTokens []Token
AuxMessage string
Name string `json:"name"`
Passcode string `json:"passcode"`
MapImageUrl string `json:"mapImageUrl"`
DiceRolls []DiceRoll `json:"diceRolls"`
Tokens []Token `json:"tokens"`
AvailableTokens []Token `json:"availableTokens"`
AuxMessage string `json:"auxMessage"`
}
type TableMessage struct {
Roll DiceRoll
Token Token
MapImg string
AuxMsg string
Roll DiceRoll `json:"roll"`
Token Token `json:"token"`
MapImg string `json:"mapImg"`
AuxMsg string `json:"auxMsg"`
}

View file

@ -7,7 +7,7 @@ import (
"go.mongodb.org/mongo-driver/bson"
"go.mongodb.org/mongo-driver/mongo"
"go.mongodb.org/mongo-driver/mongo/options"
"nilfm.cc/git/felt/models"
"hacklab.nilfm.cc/felt/models"
"time"
)

View file

@ -17,7 +17,7 @@ async function getTables() {
const tableList = await res.json();
let tableListHTML = "<ul>\n";
for (const t of tableList) {
tableListHTML += `<li><a href="#">${t.Name}</a></li>\n`
tableListHTML += `<li><a href="#">${t.name}</a></li>\n`
}
tableListHTML += "</ul>"
adminZone.innerHTML = tableListHTML;