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

@ -136,16 +136,18 @@ type Encoder func(any) ([]byte, error)
type Decoder func([]byte, interface{}) error type Decoder func([]byte, interface{}) error
type Opts struct { type Opts struct {
cpuprofile string cpuprofile string
coverPath string coverPath string
sqlitePath string sqlitePath string
loadEmbeddedHashes bool loadEmbeddedHashes bool
saveEmbeddedHashes bool saveEmbeddedHashes bool
format Format format Format
hashesPath string hashesPath string
storageType Storage storageType Storage
onlyHashNewIDs bool onlyHashNewIDs bool
cv struct { truncateHashedImages bool
cv struct {
downloadCovers bool downloadCovers bool
APIKey string APIKey string
path 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.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{