diff --git a/.gitignore b/.gitignore index 12c24a0..f875625 100644 --- a/.gitignore +++ b/.gitignore @@ -1,2 +1,3 @@ comics db.sqlite +media \ No newline at end of file diff --git a/comics.go b/comics.go index 8ba3c28..6e2edbd 100644 --- a/comics.go +++ b/comics.go @@ -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)