Messing around with blog editor
This commit is contained in:
@@ -0,0 +1,42 @@
|
|||||||
|
package main
|
||||||
|
|
||||||
|
import (
|
||||||
|
"embed"
|
||||||
|
"io"
|
||||||
|
"log"
|
||||||
|
"net/http"
|
||||||
|
|
||||||
|
"github.com/CalebQ42/darkstorm-server/internal/backend"
|
||||||
|
"github.com/CalebQ42/darkstorm-server/internal/blog"
|
||||||
|
)
|
||||||
|
|
||||||
|
//go:embed embed
|
||||||
|
var editorFS embed.FS
|
||||||
|
|
||||||
|
type Editor struct {
|
||||||
|
blogApp *blog.BlogApp
|
||||||
|
back *backend.Backend
|
||||||
|
}
|
||||||
|
|
||||||
|
func NewBlogEditor(blogApp *blog.BlogApp, back *backend.Backend) Editor {
|
||||||
|
return Editor{blogApp: blogApp, back: back}
|
||||||
|
}
|
||||||
|
|
||||||
|
func (e Editor) LoginPage(w http.ResponseWriter, r *http.Request) {
|
||||||
|
page, err := editorFS.Open("embed/login.html")
|
||||||
|
defer page.Close()
|
||||||
|
if err != nil {
|
||||||
|
log.Println("error getting login.html:", err)
|
||||||
|
sendContent(w, r, "error getting page", "", "")
|
||||||
|
return
|
||||||
|
}
|
||||||
|
dat, err := io.ReadAll(page)
|
||||||
|
if err != nil {
|
||||||
|
log.Println("error reading login.html:", err)
|
||||||
|
sendContent(w, r, "error getting page", "", "")
|
||||||
|
return
|
||||||
|
}
|
||||||
|
sendContent(w, r, string(dat), "", "")
|
||||||
|
}
|
||||||
|
|
||||||
|
func (e Editor) Editor(w http.ResponseWriter, r *http.Request) {}
|
||||||
@@ -0,0 +1,14 @@
|
|||||||
|
<script src="https://unpkg.com/htmx-ext-json-enc@2.0.1/json-enc.js"></script>
|
||||||
|
<script>
|
||||||
|
document.addEventListener("htmx:beforeOnLoad", function (e) {
|
||||||
|
console.log(e);
|
||||||
|
e.preventDefault();
|
||||||
|
});
|
||||||
|
</script>
|
||||||
|
<form id="loginForm" hx-post="https://api.darkstorm.tech/user/login">
|
||||||
|
<label for="username">Username:</label>
|
||||||
|
<input name="username" id="usernameInput"></input>
|
||||||
|
<label for="password">Password:</label>
|
||||||
|
<input name="password" type="password" id="passwordInput"></input>
|
||||||
|
<button id="loginButton" type="submit">Login</button>
|
||||||
|
</form>
|
||||||
@@ -147,9 +147,12 @@ func setupWebsite(mux *http.ServeMux) {
|
|||||||
url, _ := url.Parse("https://localhost:30000")
|
url, _ := url.Parse("https://localhost:30000")
|
||||||
mux.Handle("rpg.darkstorm.tech/", httputil.NewSingleHostReverseProxy(url))
|
mux.Handle("rpg.darkstorm.tech/", httputil.NewSingleHostReverseProxy(url))
|
||||||
}
|
}
|
||||||
|
edit := NewBlogEditor(blogApp, back)
|
||||||
mux.HandleFunc("GET /files/{w...}", filesRequest)
|
mux.HandleFunc("GET /files/{w...}", filesRequest)
|
||||||
mux.HandleFunc("GET /portfolio", portfolioRequest)
|
mux.HandleFunc("GET /portfolio", portfolioRequest)
|
||||||
mux.HandleFunc("GET /list", blogListHandle)
|
mux.HandleFunc("GET /list", blogListHandle)
|
||||||
|
mux.HandleFunc("GET /login", edit.LoginPage)
|
||||||
|
mux.HandleFunc("GET /editor/", edit.Editor)
|
||||||
mux.HandleFunc("/", mainHandle)
|
mux.HandleFunc("/", mainHandle)
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -159,10 +162,6 @@ func mainHandle(w http.ResponseWriter, r *http.Request) {
|
|||||||
latestBlogsHandle(w, r)
|
latestBlogsHandle(w, r)
|
||||||
return
|
return
|
||||||
}
|
}
|
||||||
if path == "login" {
|
|
||||||
sendContent(w, r, loginScreen, "", "")
|
|
||||||
return
|
|
||||||
}
|
|
||||||
stat, err := os.Stat(filepath.Join(*webRoot, path))
|
stat, err := os.Stat(filepath.Join(*webRoot, path))
|
||||||
if err == nil && !stat.IsDir() {
|
if err == nil && !stat.IsDir() {
|
||||||
http.ServeFile(w, r, filepath.Join(*webRoot, path))
|
http.ServeFile(w, r, filepath.Join(*webRoot, path))
|
||||||
@@ -177,14 +176,3 @@ func mainHandle(w http.ResponseWriter, r *http.Request) {
|
|||||||
}
|
}
|
||||||
blogHandle(w, r, path)
|
blogHandle(w, r, path)
|
||||||
}
|
}
|
||||||
|
|
||||||
const loginScreen = `
|
|
||||||
<script src="https://unpkg.com/htmx-ext-json-enc@2.0.1/json-enc.js"></script>
|
|
||||||
<form id="loginForm" onsubmit="login(event)">
|
|
||||||
<label for="username">Username:</label>
|
|
||||||
<input name="username" id="usernameInput"></input>
|
|
||||||
<label for="password">Password:</label>
|
|
||||||
<input name="password" type="password" id="passwordInput"></input>
|
|
||||||
<button id="loginButton" type="submit">Login</button>
|
|
||||||
</form>
|
|
||||||
`
|
|
||||||
|
|||||||
Reference in New Issue
Block a user