rename store to cache
This commit is contained in:
parent
81fd9dbcf4
commit
23eb6d131c
48
main.go
48
main.go
@ -23,23 +23,23 @@ import (
|
||||
"github.com/schollz/progressbar/v3"
|
||||
)
|
||||
|
||||
type Store struct {
|
||||
type Cache struct {
|
||||
MostRecent string
|
||||
Pages int
|
||||
CID string
|
||||
}
|
||||
|
||||
var cacheFile = flag.String("cache", "~/.taldl/cache.json", "cache file")
|
||||
var outputDir = flag.String("output", "~/TAL", "output directory")
|
||||
var tmpDir = flag.String("tmpdir", "~/.taldl", "tmp directory")
|
||||
|
||||
var formats = flag.String("formats", "zip,epub,pdf,a4.pdf,lt.pdf", "formats to download.")
|
||||
var fullUpdate = flag.Bool("full", false, "check everything for modifications")
|
||||
var verbose = flag.Bool("verbose", false, "verbose")
|
||||
var workers = flag.Int("workers", 1, "amount of workers")
|
||||
|
||||
var storeFile = flag.String("store", "~/.taldl/cache.json", "store file")
|
||||
var outputDir = flag.String("output", "~/TAL", "output directory")
|
||||
var tmpDir = flag.String("zipdir", "~/.taldl", "zip directory")
|
||||
|
||||
var ipfsEnabled = flag.Bool("ipfs", false, "pin to ipfs")
|
||||
var ipfsAPI = flag.String("ipfs-api", "localhost:5001", "ipfs api")
|
||||
var ipfsEnabled = flag.Bool("ipfs", false, "pin to ipfs")
|
||||
|
||||
var hrefs = []string{}
|
||||
var hrefsMutex sync.Mutex
|
||||
@ -48,14 +48,14 @@ var done bool
|
||||
|
||||
func main() {
|
||||
var wg sync.WaitGroup
|
||||
var store Store
|
||||
var cache Cache
|
||||
var last int
|
||||
|
||||
flag.Parse()
|
||||
|
||||
*storeFile = fixpath(*storeFile)
|
||||
storeData, _ := ioutil.ReadFile(*storeFile)
|
||||
_ = json.Unmarshal(storeData, &store)
|
||||
*cacheFile = fixpath(*cacheFile)
|
||||
cacheData, _ := ioutil.ReadFile(*cacheFile)
|
||||
_ = json.Unmarshal(cacheData, &cache)
|
||||
|
||||
*outputDir = fixpath(*outputDir)
|
||||
*tmpDir = fixpath(*tmpDir)
|
||||
@ -83,7 +83,7 @@ func main() {
|
||||
mostRecent = href
|
||||
}
|
||||
|
||||
if store.MostRecent == href && *fullUpdate == false {
|
||||
if cache.MostRecent == href && *fullUpdate == false {
|
||||
done = true
|
||||
} else {
|
||||
hrefs = append(hrefs, href)
|
||||
@ -102,7 +102,7 @@ func main() {
|
||||
if *fullUpdate {
|
||||
newPages = last - 1
|
||||
} else {
|
||||
newPages = last - store.Pages - 1
|
||||
newPages = last - cache.Pages - 1
|
||||
}
|
||||
|
||||
bar.ChangeMax(1 + newPages)
|
||||
@ -127,13 +127,13 @@ func main() {
|
||||
}
|
||||
wg.Wait()
|
||||
|
||||
store.Pages = last
|
||||
store.MostRecent = mostRecent
|
||||
cache.Pages = last
|
||||
cache.MostRecent = mostRecent
|
||||
|
||||
numJobs := len(hrefs)
|
||||
|
||||
if numJobs == 0 {
|
||||
save(store)
|
||||
save(cache)
|
||||
return
|
||||
}
|
||||
|
||||
@ -171,7 +171,7 @@ func main() {
|
||||
bar.Finish()
|
||||
|
||||
if downloadCount == 0 {
|
||||
save(store)
|
||||
save(cache)
|
||||
return
|
||||
}
|
||||
|
||||
@ -189,7 +189,7 @@ func main() {
|
||||
}
|
||||
close(downloadResults)
|
||||
bar.Finish()
|
||||
save(store)
|
||||
save(cache)
|
||||
|
||||
if buffer != "" {
|
||||
fmt.Fprintln(os.Stderr, buffer)
|
||||
@ -202,11 +202,11 @@ func main() {
|
||||
fmt.Fprintf(os.Stderr, "error: %s", err)
|
||||
os.Exit(1)
|
||||
}
|
||||
if store.CID != "" && store.CID != cid {
|
||||
sh.Unpin(store.CID)
|
||||
if cache.CID != "" && cache.CID != cid {
|
||||
sh.Unpin(cache.CID)
|
||||
}
|
||||
store.CID = cid
|
||||
save(store)
|
||||
cache.CID = cid
|
||||
save(cache)
|
||||
|
||||
fmt.Fprintln(os.Stderr, cid)
|
||||
}
|
||||
@ -477,7 +477,7 @@ func checker(id int, jobs <-chan string, results chan<- string) {
|
||||
}
|
||||
}
|
||||
|
||||
func save(store Store) {
|
||||
storeData, _ := json.Marshal(&store)
|
||||
_ = ioutil.WriteFile(*storeFile, storeData, 0644)
|
||||
func save(cache Cache) {
|
||||
cacheData, _ := json.Marshal(&cache)
|
||||
_ = ioutil.WriteFile(*cacheFile, cacheData, 0644)
|
||||
}
|
||||
|
Loading…
x
Reference in New Issue
Block a user