all repos — artbound-go @ d98670b07f40b6c4a1e88f4c62d2f0be6c39b8ac

The official administration panel for ArtBound, by EarthBound Café.

minor code  cleanup
Marco Andronaco andronacomarco@gmail.com
Fri, 22 Dec 2023 13:37:11 +0100
commit

d98670b07f40b6c4a1e88f4c62d2f0be6c39b8ac

parent

1ad157ca5408d2c73f0caf2401b7814aa63f421f

1 files changed, 17 insertions(+), 12 deletions(-)

jump to
M cache/cache.gocache/cache.go

@@ -78,6 +78,21 @@ }

return false, "" } +func handleEntry(entry *Entry, db *DB) string { + isFileCached, ext := isCached(db.cachedEntries, entry.FileID) + + if isFileCached { + log.Println(entry.FileID, "is cached.") + return ext + } + log.Println(entry.FileID, "is not cached. Downloading.") + ext, err := getFile(&db.googleApi, entry.FileID, cachePath) + if err != nil { + log.Fatal("Could not download file", entry.FileID) + } + return ext +} + func InitDB(spreadsheetId string, spreadsheetRange string) *DB { files, err := listCachedEntries(cachePath) if err != nil {

@@ -120,18 +135,8 @@ }

for i := range res { e := &res[i] - isFileCached, ext := isCached(db.cachedEntries, e.FileID) - if isFileCached { - log.Println(e.FileID, "is cached.") - e.FilePath = filepath.Join(cachePath, e.FileID+ext) - } else { - log.Println(e.FileID, "is not cached. Downloading.") - ext, err := getFile(&db.googleApi, e.FileID, cachePath) - if err != nil { - log.Fatal("Could not download file", e.FileID) - } - e.FilePath = filepath.Join(cachePath, e.FileID+ext) - } + ext := handleEntry(e, db) + e.FilePath = filepath.Join(cachePath, e.FileID+ext) } return res, nil