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" "bufio"
"crypto/rand" "crypto/rand"
"crypto/rsa" "crypto/rsa"
"crypto/sha512"
"database/sql" "database/sql"
"fmt" "fmt"
"io/ioutil"
"net" "net"
"os" "os"
"os/signal" "os/signal"
@ -52,24 +50,8 @@ import (
"humungus.tedunangst.com/r/webs/login" "humungus.tedunangst.com/r/webs/login"
) )
var savedassetparams = make(map[string]string)
var re_plainname = regexp.MustCompile("^[[:alnum:]_-]+$") 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 dbtimeformat = "2006-01-02 15:04:05"
var alreadyopendb *sql.DB var alreadyopendb *sql.DB

17
web.go
View File

@ -17,6 +17,7 @@ package main
import ( import (
"bytes" "bytes"
"crypto/sha512"
"database/sql" "database/sql"
"fmt" "fmt"
"html/template" "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() { func serve() {
db := opendatabase() db := opendatabase()
login.Init(login.InitArgs{Db: db, Logger: ilog, Insecure: develMode, SameSiteStrict: !develMode}) login.Init(login.InitArgs{Db: db, Logger: ilog, Insecure: develMode, SameSiteStrict: !develMode})