this is web code

This commit is contained in:
Ted Unangst 2023-08-31 02:48:07 -04:00
parent 0a66a0e13a
commit ae3843690f
2 changed files with 17 additions and 18 deletions

18
util.go
View File

@ -36,10 +36,8 @@ import (
"bufio"
"crypto/rand"
"crypto/rsa"
"crypto/sha512"
"database/sql"
"fmt"
"io/ioutil"
"net"
"os"
"os/signal"
@ -52,24 +50,8 @@ import (
"humungus.tedunangst.com/r/webs/login"
)
var savedassetparams = make(map[string]string)
var re_plainname = regexp.MustCompile("^[[:alnum:]_-]+$")
func getassetparam(file string) string {
if p, ok := savedassetparams[file]; ok {
return p
}
data, err := ioutil.ReadFile(file)
if err != nil {
return ""
}
hasher := sha512.New()
hasher.Write(data)
return fmt.Sprintf("?v=%.8x", hasher.Sum(nil))
}
var dbtimeformat = "2006-01-02 15:04:05"
var alreadyopendb *sql.DB

17
web.go
View File

@ -17,6 +17,7 @@ package main
import (
"bytes"
"crypto/sha512"
"database/sql"
"fmt"
"html/template"
@ -2692,6 +2693,22 @@ func emuinit() {
})
}
var savedassetparams = make(map[string]string)
func getassetparam(file string) string {
if p, ok := savedassetparams[file]; ok {
return p
}
data, err := os.ReadFile(file)
if err != nil {
return ""
}
hasher := sha512.New()
hasher.Write(data)
return fmt.Sprintf("?v=%.8x", hasher.Sum(nil))
}
func serve() {
db := opendatabase()
login.Init(login.InitArgs{Db: db, Logger: ilog, Insecure: develMode, SameSiteStrict: !develMode})