testing clientside token stuff
This commit is contained in:
parent
f797337074
commit
825f2ac762
5 changed files with 60 additions and 24 deletions
|
@ -273,10 +273,11 @@ func apiListImages(next http.Handler, uploads string, uploadType string, udb aut
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
w.WriteHeader(422)
|
w.WriteHeader(422)
|
||||||
next.ServeHTTP(w, req)
|
next.ServeHTTP(w, req)
|
||||||
return
|
return
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
return http.HandlerFunc(handlerFunc)
|
return http.HandlerFunc(handlerFunc)
|
||||||
}
|
}
|
||||||
|
@ -284,7 +285,7 @@ func apiListImages(next http.Handler, uploads string, uploadType string, udb aut
|
||||||
func apiDeleteImage(next http.Handler, uploads string, uploadType string, udb auth.UserStore, dbAdapter mongodb.DbAdapter) http.Handler {
|
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) {
|
handlerFunc := func(w http.ResponseWriter, req *http.Request) {
|
||||||
// put the path together
|
// put the path together
|
||||||
urlParams := req.Context().Value("params").(map[string]string)
|
urlParams := req.Context().Value("params").(map[string]string)
|
||||||
tableName := urlParams["table"]
|
tableName := urlParams["table"]
|
||||||
tableKey := models.TableKey{
|
tableKey := models.TableKey{
|
||||||
Name: tableName,
|
Name: tableName,
|
||||||
|
@ -307,20 +308,20 @@ func apiDeleteImage(next http.Handler, uploads string, uploadType string, udb au
|
||||||
|
|
||||||
if ok {
|
if ok {
|
||||||
if dbAdapter.CheckTable(tableKey) {
|
if dbAdapter.CheckTable(tableKey) {
|
||||||
// if the file exists, delete it and return 201
|
// if the file exists, delete it and return 201
|
||||||
filename := urlParams["file"]
|
filename := urlParams["file"]
|
||||||
fullPath := filepath.Join(uploads, tableName, uploadType, filename)
|
fullPath := filepath.Join(uploads, tableName, uploadType, filename)
|
||||||
s, err := os.Stat(fullPath)
|
s, err := os.Stat(fullPath)
|
||||||
if err == nil && !s.IsDir() {
|
if err == nil && !s.IsDir() {
|
||||||
err = os.Remove(fullPath)
|
err = os.Remove(fullPath)
|
||||||
if err == nil {
|
if err == nil {
|
||||||
w.WriteHeader(201)
|
w.WriteHeader(201)
|
||||||
next.ServeHTTP(w, req)
|
next.ServeHTTP(w, req)
|
||||||
return
|
return
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
// otherwise, return an error
|
// otherwise, return an error
|
||||||
w.WriteHeader(500)
|
w.WriteHeader(500)
|
||||||
|
|
|
@ -165,13 +165,14 @@ func (self *GameTableServer) publish(msg []byte) {
|
||||||
}
|
}
|
||||||
|
|
||||||
err = self.writeToDB(&tableMsg)
|
err = self.writeToDB(&tableMsg)
|
||||||
|
// sanitize auth for rebroadcast
|
||||||
tableMsg.Auth = nil
|
tableMsg.Auth = nil
|
||||||
clean, err := json.Marshal(tableMsg)
|
clean, err := json.Marshal(tableMsg)
|
||||||
fmt.Println(string(clean[:]))
|
|
||||||
if err != nil {
|
if err != nil {
|
||||||
fmt.Println(err.Error())
|
fmt.Println(err.Error())
|
||||||
return
|
return
|
||||||
}
|
}
|
||||||
|
|
||||||
self.publishLimiter.Wait(context.Background())
|
self.publishLimiter.Wait(context.Background())
|
||||||
|
|
||||||
for s, k := range self.subscribers {
|
for s, k := range self.subscribers {
|
||||||
|
@ -241,8 +242,6 @@ func (self *GameTableServer) writeToDB(tableMsg *models.TableMessage) error {
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
tableMsg.Auth = nil
|
|
||||||
return nil
|
return nil
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
|
@ -40,8 +40,9 @@ async function getTable(name, pass) {
|
||||||
infoHtml += "<label>Maps couldn't be retrieved</label>";
|
infoHtml += "<label>Maps couldn't be retrieved</label>";
|
||||||
}
|
}
|
||||||
adminZone.innerHTML = infoHtml;
|
adminZone.innerHTML = infoHtml;
|
||||||
}
|
|
||||||
else {
|
// also, we have to fill and toggle the tokens window
|
||||||
|
} else {
|
||||||
console.log(res.status);
|
console.log(res.status);
|
||||||
}
|
}
|
||||||
} catch (err) {
|
} catch (err) {
|
||||||
|
|
|
@ -1,9 +1,11 @@
|
||||||
let map = null;
|
let map = null;
|
||||||
let mapImg = null;
|
let mapImg = null;
|
||||||
|
let tokens = [];
|
||||||
|
|
||||||
function initializeMap(mapImgUrl) {
|
function initializeMap(mapImgUrl) {
|
||||||
if (!map) {
|
if (!map) {
|
||||||
map = L.map('map', { minZoom: 0, maxZoom: 4, crs: L.CRS.Simple });
|
map = L.map('map', { minZoom: 0, maxZoom: 4, crs: L.CRS.Simple });
|
||||||
|
map.on("zoomend", resizeMarkers);
|
||||||
}
|
}
|
||||||
if (mapImg) {
|
if (mapImg) {
|
||||||
mapImg.removeFrom(map);
|
mapImg.removeFrom(map);
|
||||||
|
@ -12,4 +14,37 @@ function initializeMap(mapImgUrl) {
|
||||||
mapImg.addTo(map);
|
mapImg.addTo(map);
|
||||||
map.setMaxBounds([[-180,180],[180,-180]]);
|
map.setMaxBounds([[-180,180],[180,-180]]);
|
||||||
map.setView([0,0], 2);
|
map.setView([0,0], 2);
|
||||||
|
}
|
||||||
|
|
||||||
|
// this works but assumes the map is square (reasonable limitation I think)
|
||||||
|
function resizeMarkers() {
|
||||||
|
tokens.forEach(t=>{
|
||||||
|
const icon = t.m.options.icon;
|
||||||
|
const scaleFactor = mapImg._image.clientWidth / mapImg._image.naturalWidth;
|
||||||
|
icon.options.iconSize = [scaleFactor * t.sz[0], scaleFactor * t.sz[1]];
|
||||||
|
t.m.setIcon(icon);
|
||||||
|
});
|
||||||
|
}
|
||||||
|
|
||||||
|
function addToken(token) {
|
||||||
|
const self = { sz: token.sz, m: L.marker(token.pos, {
|
||||||
|
icon: L.icon({
|
||||||
|
iconUrl: token.img,
|
||||||
|
iconSize: token.sz,
|
||||||
|
}),
|
||||||
|
title: token.name,
|
||||||
|
draggable: true,
|
||||||
|
autoPan: true
|
||||||
|
})};
|
||||||
|
|
||||||
|
tokens.push(self);
|
||||||
|
self.m.addTo(map);
|
||||||
|
}
|
||||||
|
|
||||||
|
// token for testing in browser console
|
||||||
|
const t = {
|
||||||
|
img: "https://nilfm.cc/favicon.png",
|
||||||
|
sz: [32,32],
|
||||||
|
pos: [0,0],
|
||||||
|
name: "test",
|
||||||
}
|
}
|
|
@ -155,7 +155,7 @@ pre {
|
||||||
|
|
||||||
nav {
|
nav {
|
||||||
display: grid;
|
display: grid;
|
||||||
grid-template-columns: 1fr 1fr;
|
grid-template-columns: auto 1fr;
|
||||||
}
|
}
|
||||||
|
|
||||||
.leaflet-container {
|
.leaflet-container {
|
||||||
|
|
Loading…
Reference in a new issue