img clues in http

master v0.0.1
Bel LaPointe 2023-04-07 13:53:11 -06:00
parent 08abc8b48f
commit aacc5d2fc6
3 changed files with 18 additions and 3 deletions

View File

@ -26,6 +26,8 @@ func HTTP(port int, db DB) error {
foo := func(w http.ResponseWriter, r *http.Request) {
if r.URL.Path == "/" {
httpGUI(w, r)
} else if strings.HasPrefix(r.URL.Path, "/static/") {
httpStatic(w, r)
} else if strings.HasPrefix(r.URL.Path, "/api/questions") && strings.HasSuffix(r.URL.Path, "/answers") && r.Method == http.MethodPost {
httpPostQuestionAnswers(w, r)
} else {
@ -105,6 +107,13 @@ func httpGUI(w http.ResponseWriter, r *http.Request) {
w.Write([]byte(body))
}
func httpStatic(w http.ResponseWriter, r *http.Request) {
p := strings.TrimPrefix(r.URL.Path, "/static/")
p = strings.ReplaceAll(p, "/..", "/")
p = path.Clean(p)
http.ServeFile(w, r, p)
}
func httpAssignments(ctx context.Context) (interface{}, error) {
db := extract(ctx).DB
user := extract(ctx).User

View File

@ -99,7 +99,13 @@
let clues = ""
for (var i in todo[1].Clues) {
clues += `<details><summary>clue #${i}</summary>${todo[1].Clues[i]}</details>`
clues += `<details><summary>clue #${i}</summary>`
if (todo[1].Clues[i].startsWith("img:")) {
clues += `<img src="static/${todo[1].Clues[i].slice(4, 1000)}"/>`
} else {
clues += todo[1].Clues[i]
}
clues += `</details>`
}
form.children.clues.innerHTML = clues
form.children.clues.value = todo[1].Clues

View File

@ -7,7 +7,7 @@ knowledge:
- solution B
clues:
- clue1 of 2
- clue2 of 2
- img:testdata/tofugu.d/sa-hiragana-0.png
tags:
- ops
- data-platform
@ -52,5 +52,5 @@ users:
tags:
assignments:
- ops
cadence: 5h0m0s
cadence: 5s
resolution: 1