From 768f0cec610ba664a056c45c8ee113f7e3b22895 Mon Sep 17 00:00:00 2001 From: Dominic Ferrando Date: Thu, 24 Apr 2025 23:39:29 -0400 Subject: [PATCH] More fixing --- .gitignore | 4 ++-- Makefile | 4 ---- go.mod | 8 +++----- internal/util/posts.go | 4 ++-- web/main.go | 11 +++++++---- web/static/thread.js | 6 +++--- web/views/board.templ | 2 +- web/views/thread.templ | 8 ++++---- 8 files changed, 22 insertions(+), 25 deletions(-) diff --git a/.gitignore b/.gitignore index 4827b9b..c774b27 100644 --- a/.gitignore +++ b/.gitignore @@ -3,8 +3,8 @@ internal/database/comfychan.db tmp out -web/static/media/posts/ -web/static/media/posts/ +media + # Devenv .devenv* devenv.local.nix diff --git a/Makefile b/Makefile index 302ceaa..be2f80b 100644 --- a/Makefile +++ b/Makefile @@ -19,10 +19,6 @@ db/seed: db/seed/f: rm ./internal/database/comfychan.db && sqlite3 ./internal/database/comfychan.db < ./internal/database/seed.sql -img/clear: - rm -rf ./web/static/media/posts || true - - build: go build -o ./out/comfychan ./web diff --git a/go.mod b/go.mod index 07b80be..9dcd070 100644 --- a/go.mod +++ b/go.mod @@ -4,12 +4,10 @@ go 1.23.3 require ( github.com/a-h/templ v0.3.857 + github.com/disintegration/imaging v1.6.2 github.com/go-chi/chi/v5 v5.2.1 github.com/mattn/go-sqlite3 v1.14.28 + golang.org/x/crypto v0.37.0 ) -require ( - github.com/disintegration/imaging v1.6.2 // indirect - golang.org/x/crypto v0.37.0 // indirect - golang.org/x/image v0.0.0-20191009234506-e7c1f5e7dbb8 // indirect -) +require golang.org/x/image v0.0.0-20191009234506-e7c1f5e7dbb8 // indirect diff --git a/internal/util/posts.go b/internal/util/posts.go index fe7c4af..0156744 100644 --- a/internal/util/posts.go +++ b/internal/util/posts.go @@ -23,8 +23,8 @@ const FILE_MEM_LIMIT int64 = 10 << 20 const MAX_REQUEST_BYTES int64 = FILE_MEM_LIMIT + (1 << 20) var ( - POST_MEDIA_FULL_PATH = "web/static/media/posts/full" - POST_MEDIA_THUMB_PATH = "web/static/media/posts/thumb" + POST_MEDIA_FULL_PATH = "media/posts/full" + POST_MEDIA_THUMB_PATH = "media/posts/thumb" ) const MAX_THREAD_COUNT = 50 diff --git a/web/main.go b/web/main.go index a580420..a17d997 100644 --- a/web/main.go +++ b/web/main.go @@ -75,10 +75,8 @@ func main() { dataDir = "." // for development } - log.Println("DATADIR: ", dataDir) - util.POST_MEDIA_FULL_PATH = filepath.Join(dataDir, util.POST_MEDIA_FULL_PATH) - util.POST_MEDIA_THUMB_PATH = filepath.Join(dataDir, util.POST_MEDIA_FULL_PATH) + util.POST_MEDIA_THUMB_PATH = filepath.Join(dataDir, util.POST_MEDIA_THUMB_PATH) util.DATABASE_PATH = filepath.Join(dataDir, util.DATABASE_PATH) util.STATIC_PATH = filepath.Join(dataDir, util.STATIC_PATH) @@ -94,9 +92,14 @@ func main() { r.Handle("/static/*", disableCacheInDevMode( - http.StripPrefix("/static", + http.StripPrefix("/static/", http.FileServer(http.Dir(util.STATIC_PATH))))) + r.Handle("/media/*", + disableCacheInDevMode( + http.StripPrefix("/media/", + http.FileServer(http.Dir(filepath.Join(dataDir, "media")))))) + // ----------------- // ----------------- diff --git a/web/static/thread.js b/web/static/thread.js index 36f3172..41ca2af 100644 --- a/web/static/thread.js +++ b/web/static/thread.js @@ -44,7 +44,7 @@ function togglePostFile(el) { const vidEl = imgEl.parentElement.querySelector("video"); const closeVidBtn = imgEl.parentElement.querySelector(".link-button"); if (vidEl.style.display === "none") { - vidEl.src = "/static/media/posts/full/" + imgEl.dataset.full; + vidEl.src = "/media/posts/full/" + imgEl.dataset.full; vidEl.style.display = ""; imgEl.style.display = "none"; closeVidBtn.style.display = ""; @@ -59,11 +59,11 @@ function togglePostFile(el) { else { if (imgEl.classList.contains("post-img-full")) { imgEl.classList.remove("post-img-full"); - imgEl.src = "/static/media/posts/thumb/" + imgEl.dataset.thumb; + imgEl.src = "/media/posts/thumb/" + imgEl.dataset.thumb; } else { imgEl.classList.add("post-img-full"); - imgEl.src = "/static/media/posts/full/" + imgEl.dataset.full; + imgEl.src = "/media/posts/full/" + imgEl.dataset.full; } } } diff --git a/web/views/board.templ b/web/views/board.templ index 852d223..c782fee 100644 --- a/web/views/board.templ +++ b/web/views/board.templ @@ -92,7 +92,7 @@ templ ThreadsCatalog(previews []CatalogThreadPreview, catalogContext CatalogCont diff --git a/web/views/thread.templ b/web/views/thread.templ index d81284f..7424233 100644 --- a/web/views/thread.templ +++ b/web/views/thread.templ @@ -76,7 +76,7 @@ templ PostOriginal(post database.Post, thread database.Thread) { style=" display: none;" >[close] File: - + { post.MediaPath }
@@ -86,7 +86,7 @@ templ PostOriginal(post database.Post, thread database.Thread) { [close] File: - + { post.MediaPath }
@@ -169,7 +169,7 @@ templ PostReply(post database.Post, threadContext ThreadContext) {