diff --git a/.gitignore b/.gitignore index db7cd78..103efe3 100644 --- a/.gitignore +++ b/.gitignore @@ -1,4 +1,5 @@ internal/database/comfychan.db **/*_templ.go tmp -web/static/img/posts +web/static/img/posts/full/* +web/static/img/posts/thumb/* diff --git a/Makefile b/Makefile index fa7952f..0962b2c 100644 --- a/Makefile +++ b/Makefile @@ -19,3 +19,6 @@ db/seed: db/seed/f: rm ./internal/database/comfychan.db && sqlite3 ./internal/database/comfychan.db < ./internal/database/seed.sql +img/clear: + rm -f ./web/static/img/posts/full/* || true + rm -f ./web/static/img/posts/thumb/* || true diff --git a/internal/database/seed.sql b/internal/database/seed.sql index b2256f4..35ef6f8 100644 --- a/internal/database/seed.sql +++ b/internal/database/seed.sql @@ -39,16 +39,3 @@ CREATE TABLE IF NOT EXISTS posts ( INSERT INTO boards (slug, name, tag) VALUES ('comfy', 'Comfy', 'Be comfy, fren'), ('g', 'Technology', 'Beep boop'); - --- Welcome threads - - -- /comfy/ - INSERT INTO threads (board_slug, subject) VALUES ( - 'comfy', - 'Welcome to /comfy/.' - ); - INSERT INTO posts (thread_id, body, media_path) VALUES ( - (SELECT id FROM threads WHERE subject LIKE 'Welcome to /comfy/.%'), - 'Post comfy. Be nice.', - '1.jpg' - ); diff --git a/web/main.go b/web/main.go index 8de6c33..fcbd4a1 100644 --- a/web/main.go +++ b/web/main.go @@ -19,7 +19,10 @@ import ( _ "github.com/mattn/go-sqlite3" ) +// 10 MB memory limit const FILE_MEM_LIMIT int64 = 10 << 20 +const POST_IMG_FULL_PATH = "web/static/img/posts/full" +const POST_IMG_THUMB_PATH = "web/static/img/posts/thumb" var dev = true @@ -34,17 +37,35 @@ func disableCacheInDevMode(next http.Handler) http.Handler { } func savePostFile(file *multipart.File, header *multipart.FileHeader) error { - dstPath := filepath.Join("web/static/img/posts", header.Filename) + dstPathFull := filepath.Join(POST_IMG_FULL_PATH, header.Filename) + dstPathThumb := filepath.Join(POST_IMG_THUMB_PATH, header.Filename) - dst, err := os.Create(dstPath) + // save full + dstFull, err := os.Create(dstPathFull) if err != nil { - log.Printf("os.Create: %v", err) + log.Printf("os.Create (full): %v", err) + return err + } + defer dstFull.Close() + if _, err := io.Copy(dstFull, *file); err != nil { + log.Printf("io.Copy (full): %v", err) return err } - defer dst.Close() - if _, err := io.Copy(dst, *file); err != nil { - log.Printf("io.Copy: %v", err) + if _, err := (*file).Seek(0, 0); err != nil { // rewind file + log.Printf("seek file (thumb): %v", err) + return err + } + + // save thumbnail + dstThumb, err := os.Create(dstPathThumb) + if err != nil { + log.Printf("os.Create (thumb): %v", err) + return err + } + defer dstThumb.Close() + if _, err := io.Copy(dstThumb, *file); err != nil { + log.Printf("io.Copy (thumb): %v", err) return err } @@ -144,7 +165,6 @@ func main() { subject := r.FormValue("subject") body := r.FormValue("body") - // 10 MB memory limit if err := r.ParseMultipartForm(FILE_MEM_LIMIT); err != nil { http.Error(w, "Failed to parse form", http.StatusBadRequest) log.Printf("ParseMultipartForm: %v", err) @@ -186,7 +206,6 @@ func main() { body := r.FormValue("body") mediaPath := "" - // 10 MB memory limit if err := r.ParseMultipartForm(FILE_MEM_LIMIT); err != nil { http.Error(w, "Failed to parse form", http.StatusBadRequest) log.Printf("ParseMultipartForm: %v", err) diff --git a/web/static/img/posts/1.jpg b/web/static/img/posts/1.jpg deleted file mode 100644 index 64383cc..0000000 Binary files a/web/static/img/posts/1.jpg and /dev/null differ diff --git a/web/static/img/posts/default.png b/web/static/img/posts/default.png deleted file mode 100644 index 2d00a48..0000000 Binary files a/web/static/img/posts/default.png and /dev/null differ diff --git a/web/static/index.css b/web/static/index.css index a8a31eb..cfa397e 100644 --- a/web/static/index.css +++ b/web/static/index.css @@ -65,6 +65,7 @@ body { border: 2px solid rgba(111, 111, 111, 0.34); width: 200px; max-height: 192px; + overflow: scroll; } .catalog-preview h1 { @@ -87,6 +88,8 @@ body { max-height: 70%; max-width: 80%; margin-bottom: 10px; + border: 1px solid #B7C5D9; + box-shadow: 0 0 3px rgba(0, 0, 0, 0.25); } /* NEW THREAD BUTTON/FORM */ diff --git a/web/views/board.templ b/web/views/board.templ index 5dcb301..087eda9 100644 --- a/web/views/board.templ +++ b/web/views/board.templ @@ -74,7 +74,7 @@ templ ThreadsCatalog(previews []CatalogThreadPreview) { for _, preview := range previews {