From 89c9b4ebceec34a9db4869ac2c29d014b8bcf8ea Mon Sep 17 00:00:00 2001 From: Timmy Welch Date: Fri, 18 Oct 2024 11:19:50 -0700 Subject: [PATCH] Allow truncating image files to save space --- cmd/comic-hasher/main.go | 27 +++++++++++++++++---------- 1 file changed, 17 insertions(+), 10 deletions(-) diff --git a/cmd/comic-hasher/main.go b/cmd/comic-hasher/main.go index 964c8ae..29116e0 100644 --- a/cmd/comic-hasher/main.go +++ b/cmd/comic-hasher/main.go @@ -136,16 +136,18 @@ type Encoder func(any) ([]byte, error) type Decoder func([]byte, interface{}) error type Opts struct { - cpuprofile string - coverPath string - sqlitePath string - loadEmbeddedHashes bool - saveEmbeddedHashes bool - format Format - hashesPath string - storageType Storage - onlyHashNewIDs bool - cv struct { + cpuprofile string + coverPath string + sqlitePath string + loadEmbeddedHashes bool + saveEmbeddedHashes bool + format Format + hashesPath string + storageType Storage + onlyHashNewIDs bool + truncateHashedImages bool + + cv struct { downloadCovers bool APIKey string path 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.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.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.StringVar(&opts.cv.APIKey, "cv-api-key", "", "API Key to use to access the ComicVine API") @@ -183,6 +186,7 @@ func main() { panic(err) } } + opts.onlyHashNewIDs = opts.onlyHashNewIDs || opts.truncateHashedImages if opts.cv.downloadCovers { if opts.cv.APIKey == "" { log.Fatal("No ComicVine API Key provided") @@ -763,6 +767,9 @@ func downloadProcessor(opts Opts, imagePaths chan cv.Download, server Server) { if err != nil { continue // skip this image } + if opts.truncateHashedImages { + file.Truncate(0) + } file.Close() im := ch.Im{