staging thumbnails
This commit is contained in:
+2
-1
@@ -1,4 +1,5 @@
|
|||||||
internal/database/comfychan.db
|
internal/database/comfychan.db
|
||||||
**/*_templ.go
|
**/*_templ.go
|
||||||
tmp
|
tmp
|
||||||
web/static/img/posts
|
web/static/img/posts/full/*
|
||||||
|
web/static/img/posts/thumb/*
|
||||||
|
|||||||
@@ -19,3 +19,6 @@ db/seed:
|
|||||||
db/seed/f:
|
db/seed/f:
|
||||||
rm ./internal/database/comfychan.db && sqlite3 ./internal/database/comfychan.db < ./internal/database/seed.sql
|
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
|
||||||
|
|||||||
@@ -39,16 +39,3 @@ CREATE TABLE IF NOT EXISTS posts (
|
|||||||
INSERT INTO boards (slug, name, tag) VALUES
|
INSERT INTO boards (slug, name, tag) VALUES
|
||||||
('comfy', 'Comfy', 'Be comfy, fren'),
|
('comfy', 'Comfy', 'Be comfy, fren'),
|
||||||
('g', 'Technology', 'Beep boop');
|
('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'
|
|
||||||
);
|
|
||||||
|
|||||||
+27
-8
@@ -19,7 +19,10 @@ import (
|
|||||||
_ "github.com/mattn/go-sqlite3"
|
_ "github.com/mattn/go-sqlite3"
|
||||||
)
|
)
|
||||||
|
|
||||||
|
// 10 MB memory limit
|
||||||
const FILE_MEM_LIMIT int64 = 10 << 20
|
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
|
var dev = true
|
||||||
|
|
||||||
@@ -34,17 +37,35 @@ func disableCacheInDevMode(next http.Handler) http.Handler {
|
|||||||
}
|
}
|
||||||
|
|
||||||
func savePostFile(file *multipart.File, header *multipart.FileHeader) error {
|
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 {
|
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
|
return err
|
||||||
}
|
}
|
||||||
defer dst.Close()
|
|
||||||
|
|
||||||
if _, err := io.Copy(dst, *file); err != nil {
|
if _, err := (*file).Seek(0, 0); err != nil { // rewind file
|
||||||
log.Printf("io.Copy: %v", err)
|
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
|
return err
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -144,7 +165,6 @@ func main() {
|
|||||||
subject := r.FormValue("subject")
|
subject := r.FormValue("subject")
|
||||||
body := r.FormValue("body")
|
body := r.FormValue("body")
|
||||||
|
|
||||||
// 10 MB memory limit
|
|
||||||
if err := r.ParseMultipartForm(FILE_MEM_LIMIT); err != nil {
|
if err := r.ParseMultipartForm(FILE_MEM_LIMIT); err != nil {
|
||||||
http.Error(w, "Failed to parse form", http.StatusBadRequest)
|
http.Error(w, "Failed to parse form", http.StatusBadRequest)
|
||||||
log.Printf("ParseMultipartForm: %v", err)
|
log.Printf("ParseMultipartForm: %v", err)
|
||||||
@@ -186,7 +206,6 @@ func main() {
|
|||||||
body := r.FormValue("body")
|
body := r.FormValue("body")
|
||||||
mediaPath := ""
|
mediaPath := ""
|
||||||
|
|
||||||
// 10 MB memory limit
|
|
||||||
if err := r.ParseMultipartForm(FILE_MEM_LIMIT); err != nil {
|
if err := r.ParseMultipartForm(FILE_MEM_LIMIT); err != nil {
|
||||||
http.Error(w, "Failed to parse form", http.StatusBadRequest)
|
http.Error(w, "Failed to parse form", http.StatusBadRequest)
|
||||||
log.Printf("ParseMultipartForm: %v", err)
|
log.Printf("ParseMultipartForm: %v", err)
|
||||||
|
|||||||
Binary file not shown.
|
Before Width: | Height: | Size: 38 KiB |
Binary file not shown.
|
Before Width: | Height: | Size: 119 KiB |
@@ -65,6 +65,7 @@ body {
|
|||||||
border: 2px solid rgba(111, 111, 111, 0.34);
|
border: 2px solid rgba(111, 111, 111, 0.34);
|
||||||
width: 200px;
|
width: 200px;
|
||||||
max-height: 192px;
|
max-height: 192px;
|
||||||
|
overflow: scroll;
|
||||||
}
|
}
|
||||||
|
|
||||||
.catalog-preview h1 {
|
.catalog-preview h1 {
|
||||||
@@ -87,6 +88,8 @@ body {
|
|||||||
max-height: 70%;
|
max-height: 70%;
|
||||||
max-width: 80%;
|
max-width: 80%;
|
||||||
margin-bottom: 10px;
|
margin-bottom: 10px;
|
||||||
|
border: 1px solid #B7C5D9;
|
||||||
|
box-shadow: 0 0 3px rgba(0, 0, 0, 0.25);
|
||||||
}
|
}
|
||||||
|
|
||||||
/* NEW THREAD BUTTON/FORM */
|
/* NEW THREAD BUTTON/FORM */
|
||||||
|
|||||||
@@ -74,7 +74,7 @@ templ ThreadsCatalog(previews []CatalogThreadPreview) {
|
|||||||
for _, preview := range previews {
|
for _, preview := range previews {
|
||||||
<div class="catalog-preview">
|
<div class="catalog-preview">
|
||||||
<a href={ templ.URL(preview.ThreadURL) }>
|
<a href={ templ.URL(preview.ThreadURL) }>
|
||||||
<img class="catalog-preview-img" src={ fmt.Sprintf("/static/img/posts/%s", preview.MediaPath) }/>
|
<img class="catalog-preview-img" src={ fmt.Sprintf("/static/img/posts/full/%s", preview.MediaPath) }/>
|
||||||
</a>
|
</a>
|
||||||
<h1>
|
<h1>
|
||||||
<a href={ templ.URL(preview.ThreadURL) } class="thread-subject catalog-preview-link">{ preview.Subject }</a>
|
<a href={ templ.URL(preview.ThreadURL) } class="thread-subject catalog-preview-link">{ preview.Subject }</a>
|
||||||
|
|||||||
@@ -20,7 +20,7 @@ templ ThreadPost(post database.Post, thread *database.Thread) {
|
|||||||
<article id={ fmt.Sprintf("post-%d", post.Id) } class={ getPostClass(isOp) }>
|
<article id={ fmt.Sprintf("post-%d", post.Id) } class={ getPostClass(isOp) }>
|
||||||
if post.MediaPath != "" {
|
if post.MediaPath != "" {
|
||||||
<div class="post-img-container">
|
<div class="post-img-container">
|
||||||
<img src={ fmt.Sprintf("/static/img/posts/%s", post.MediaPath) } class="post-img"/>
|
<img src={ fmt.Sprintf("/static/img/posts/full/%s", post.MediaPath) } class="post-img"/>
|
||||||
</div>
|
</div>
|
||||||
}
|
}
|
||||||
<header class="post-header">
|
<header class="post-header">
|
||||||
|
|||||||
Reference in New Issue
Block a user