Work on image rendering

This commit is contained in:
Dominic Ferrando
2025-04-18 14:38:46 -04:00
parent ac9c516550
commit 4265b8583b
9 changed files with 53 additions and 22 deletions
+3 -3
View File
@@ -70,7 +70,7 @@ func GetThread(db *sql.DB, threadId int) (Thread, error) {
}
func GetPosts(db *sql.DB, threadId int) ([]Post, error) {
rows, err := db.Query(`SELECT id, thread_id, author, body, created_at FROM posts where thread_id = ?`, threadId)
rows, err := db.Query(`SELECT id, thread_id, author, body, created_at, media_path FROM posts where thread_id = ?`, threadId)
if err != nil {
return nil, err
}
@@ -79,7 +79,7 @@ func GetPosts(db *sql.DB, threadId int) ([]Post, error) {
var result []Post
for rows.Next() {
var p Post
err := rows.Scan(&p.Id, &p.ThreadId, &p.Author, &p.Body, &p.CreatedAt)
err := rows.Scan(&p.Id, &p.ThreadId, &p.Author, &p.Body, &p.CreatedAt, &p.MediaPath)
if err != nil {
return nil, err
}
@@ -106,7 +106,7 @@ func PutThread(db *sql.DB, boardSlug string, subject string, body string) error
return err
}
_, err = tx.Exec(`INSERT INTO posts (thread_id, body) VALUES (?, ?)`, threadId, body)
_, err = tx.Exec(`INSERT INTO posts (thread_id, body, media_path) VALUES (?, ?, ?)`, threadId, body, "default.png")
if err != nil {
return err
}
+1
View File
@@ -23,4 +23,5 @@ type Post struct {
Author string
Body string
CreatedAt time.Time
MediaPath string
}
+4 -6
View File
@@ -26,6 +26,7 @@ CREATE TABLE IF NOT EXISTS posts (
author TEXT DEFAULT 'Anonymous',
body TEXT NOT NULL,
created_at DATETIME DEFAULT CURRENT_TIMESTAMP,
media_path TEXT NOT NULL DEFAULT '',
FOREIGN KEY (thread_id) REFERENCES threads(id) ON DELETE CASCADE
);
@@ -46,11 +47,8 @@ INSERT INTO boards (slug, name, tag) VALUES
'comfy',
'Welcome to /comfy/.'
);
INSERT INTO posts (thread_id, body) VALUES (
INSERT INTO posts (thread_id, body, media_path) VALUES (
(SELECT id FROM threads WHERE subject LIKE 'Welcome to /comfy/.%'),
'Post comfy. Be nice.'
);
INSERT INTO posts (thread_id, body) VALUES (
(SELECT id FROM threads WHERE subject LIKE 'Welcome to /comfy/.%'),
'Henlo fren.'
'Post comfy. Be nice.',
'1.jpg'
);