Allow truncating image files to save space

This commit is contained in:
Timmy Welch 2024-10-18 11:19:50 -07:00
parent a65cadf106
commit 89c9b4ebce

View File

@ -145,6 +145,8 @@ type Opts struct {
hashesPath string hashesPath string
storageType Storage storageType Storage
onlyHashNewIDs bool onlyHashNewIDs bool
truncateHashedImages bool
cv struct { cv struct {
downloadCovers bool downloadCovers bool
APIKey string APIKey string
@ -169,6 +171,7 @@ func main() {
flag.Var(&opts.format, "save-format", "Specify the format to export hashes to (json, msgpack)") flag.Var(&opts.format, "save-format", "Specify the format to export hashes to (json, msgpack)")
flag.Var(&opts.storageType, "storage-type", "Specify the storage type used internally to search hashes (sqlite,sqlite3,map,basicmap,vptree)") flag.Var(&opts.storageType, "storage-type", "Specify the storage type used internally to search hashes (sqlite,sqlite3,map,basicmap,vptree)")
flag.BoolVar(&opts.onlyHashNewIDs, "only-hash-new-ids", true, "Only hashes new covers from CV/local path (Note: If there are multiple covers for the same ID they may get queued at the same time and hashed on the first run)") flag.BoolVar(&opts.onlyHashNewIDs, "only-hash-new-ids", true, "Only hashes new covers from CV/local path (Note: If there are multiple covers for the same ID they may get queued at the same time and hashed on the first run)")
flag.BoolVar(&opts.truncateHashedImages, "trucate-hashed-images", true, "Truncates downloaded images after hashing them, useful to save space, implies -only-hash-new-ids")
flag.BoolVar(&opts.cv.downloadCovers, "cv-dl-covers", false, "Downloads all covers from ComicVine and adds them to the server") flag.BoolVar(&opts.cv.downloadCovers, "cv-dl-covers", false, "Downloads all covers from ComicVine and adds them to the server")
flag.StringVar(&opts.cv.APIKey, "cv-api-key", "", "API Key to use to access the ComicVine API") flag.StringVar(&opts.cv.APIKey, "cv-api-key", "", "API Key to use to access the ComicVine API")
@ -183,6 +186,7 @@ func main() {
panic(err) panic(err)
} }
} }
opts.onlyHashNewIDs = opts.onlyHashNewIDs || opts.truncateHashedImages
if opts.cv.downloadCovers { if opts.cv.downloadCovers {
if opts.cv.APIKey == "" { if opts.cv.APIKey == "" {
log.Fatal("No ComicVine API Key provided") log.Fatal("No ComicVine API Key provided")
@ -763,6 +767,9 @@ func downloadProcessor(opts Opts, imagePaths chan cv.Download, server Server) {
if err != nil { if err != nil {
continue // skip this image continue // skip this image
} }
if opts.truncateHashedImages {
file.Truncate(0)
}
file.Close() file.Close()
im := ch.Im{ im := ch.Im{