Skip to content

Commit

Permalink
Release v0.5 with new images command.
Browse files Browse the repository at this point in the history
Use images command to save images in an album and prevent duplicate
uploads to that same album.
  • Loading branch information
movestill committed Mar 7, 2021
1 parent 2782e06 commit d88507a
Show file tree
Hide file tree
Showing 3 changed files with 11 additions and 6 deletions.
2 changes: 1 addition & 1 deletion CHANGELOG.md
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
# Change Log

## Unreleased
## v0.5 07Marh2021

* Upgraded to Go 1.16
* Use go modules
Expand Down
13 changes: 8 additions & 5 deletions core/db.go
Original file line number Diff line number Diff line change
Expand Up @@ -20,12 +20,11 @@ import (
"fmt"
"log"
"os"
"path"

_ "github.com/mattn/go-sqlite3"
)

const dbFile = "./images.db"

const imageTable = "images"
const imageTableVersion = 1
const imageTableHashIndexName = "images_hash_index"
Expand All @@ -46,7 +45,9 @@ var imgTableInsertSQL = fmt.Sprintf("INSERT INTO %s (album_key, hash, filename)
var imgTableDeleteSQL = fmt.Sprintf("DELETE FROM %s WHERE album_key = ?;", imageTable)
var imgTableGetDupesSQL = fmt.Sprintf("SELECT filename FROM %s WHERE album_key = ? AND hash = ?", imageTable)

func init() {
// Ensure DB exists and is a compatible version.
func initDB() {
dbFile := path.Join(smuggoDirFlag, "images.db")
var createDb = false
_, pathErr := os.Stat(dbFile)
if pathErr != nil {
Expand All @@ -57,6 +58,7 @@ func init() {
if err != nil {
log.Fatalf("Error opening database %s: %q\n", dbFile, err)
}
defer db.Close()

if createDb {
createTables(db, imageTableVersion)
Expand All @@ -65,15 +67,16 @@ func init() {
if err := validateTables(db); err != nil {
log.Fatal(err)
}

defer db.Close()
}

func openDB() *sql.DB {
dbFile := path.Join(smuggoDirFlag, "images.db")

db, err := sql.Open("sqlite3", dbFile)
if err != nil {
log.Fatalf("Error opening database %s: %q\n", dbFile, err)
}

return db
}

Expand Down
2 changes: 2 additions & 0 deletions core/main.go
Original file line number Diff line number Diff line change
Expand Up @@ -91,6 +91,8 @@ func main() {
return
}

initDB()

// Normal code path where an API key must exist.
authInit()

Expand Down

0 comments on commit d88507a

Please sign in to comment.