added revalidate cache feature
This commit is contained in:
31
internal/hasher.go
Normal file
31
internal/hasher.go
Normal file
@@ -0,0 +1,31 @@
|
||||
package steamimmich
|
||||
|
||||
import (
|
||||
"crypto/sha1"
|
||||
"fmt"
|
||||
"io"
|
||||
"os"
|
||||
)
|
||||
|
||||
func hashFiles(assets []AssetState) (map[int]string, error) {
|
||||
results := make(map[int]string)
|
||||
|
||||
for i, p := range assets {
|
||||
f, err := os.Open(p.FilePath)
|
||||
if err != nil {
|
||||
results[i] = ""
|
||||
continue
|
||||
}
|
||||
|
||||
h := sha1.New()
|
||||
if _, err := io.Copy(h, f); err != nil {
|
||||
f.Close()
|
||||
return nil, err
|
||||
}
|
||||
f.Close()
|
||||
|
||||
results[i] = fmt.Sprintf("%x", h.Sum(nil))
|
||||
}
|
||||
|
||||
return results, nil
|
||||
}
|
||||
Reference in New Issue
Block a user