added publish option

This commit is contained in:
TheLastBilly 2023-05-19 00:26:54 -04:00
parent 5cac64d907
commit 700983cb12
2 changed files with 29 additions and 1 deletions

1
.gitignore vendored
View File

@ -1,2 +1,3 @@
comics
db.sqlite
media

View File

@ -38,7 +38,7 @@ func (c *Comic) readRow(db * sql.Rows) error {
const dbSquema string = `
CREATE TABLE IF NOT EXISTS comic (
id INTEGER NOT NULL PRIMARY KEY AUTOINCREMENT,
datetime DATETIME NOT NULL,
datetime DATETIME DEFAULT CURRENT_TIMESTAMP,
title CHAR(50),
image CHAR(200),
description TEXT,
@ -221,6 +221,12 @@ func return500(w http.ResponseWriter, r * http.Request) {
returnError(w, r, http.StatusInternalServerError)
}
func newComic(title string, image string, description string, tags string) error {
_, err := db.Exec("INSERT INTO comic(title, image, description, tags) VALUES(?, ?, ?, ?);",
title, image, description, tags)
return err
}
func main() {
var err error
@ -238,6 +244,12 @@ func main() {
Required: false, Help: "Defines the address the web server will listen to", Default: "127.0.0.1"})
port := parser.Int("p", "port", &argparse.Options{
Required: false, Help: "Defines the port the web server will listen to", Default: 8080})
publish := parser.Flag("u", "publish", &argparse.Options{
Required: false, Help: "Creates new commics. Needs both -i and -l", Default: false})
title := parser.String("l", "title", &argparse.Options{
Required: false, Help: "Title for new comic", Default: ""})
image := parser.String("i", "image", &argparse.Options{
Required: false, Help: "Image path for new comic", Default: ""})
err = parser.Parse(os.Args)
if err != nil {
@ -256,6 +268,21 @@ func main() {
log.Fatal(err)
}
if *publish {
if len(*image) < 1 {
panic("missing -i")
}
if len(*title) < 1 {
panic("missing -l")
}
err = newComic(*title, *image, "", "")
if err != nil {
log.Fatal(err)
}
log.Println(fmt.Sprintf("comic \"%s\" created", *title))
return
}
// views
http.HandleFunc("/", indexView)
http.HandleFunc("/latest", latestView)