add version and ID (filehash)
All checks were successful
continuous-integration/drone/push Build is passing
All checks were successful
continuous-integration/drone/push Build is passing
This commit is contained in:
parent
62722871e7
commit
f9a0a1df8f
26
main.go
26
main.go
@ -1,8 +1,10 @@
|
||||
package main
|
||||
|
||||
import (
|
||||
"crypto/sha256"
|
||||
"encoding/json"
|
||||
"fmt"
|
||||
"io"
|
||||
"io/fs"
|
||||
"log"
|
||||
"net/http"
|
||||
@ -72,14 +74,19 @@ func getLineageOSROMs(romDirectory string) ([]LineageOSROM, error) {
|
||||
return nil
|
||||
}
|
||||
|
||||
fileHash, err := hashFile(d.Name())
|
||||
if err != nil {
|
||||
log.Printf("ingore zip file '%s', failed to get sha256 hash: %v", d.Name(), err)
|
||||
}
|
||||
|
||||
lineageOSROM := LineageOSROM{
|
||||
Datetime: int(fInfo.ModTime().Unix()),
|
||||
Filename: d.Name(),
|
||||
ID: "TBD",
|
||||
ID: fileHash,
|
||||
Romtype: "nightly",
|
||||
Size: int(fInfo.Size()),
|
||||
URL: fmt.Sprintf("https://lineageos-ota.deadbeef.codes/public/%s", d.Name()),
|
||||
Version: "TBD",
|
||||
Version: splitName[1],
|
||||
}
|
||||
|
||||
lineageOSROMs = append(lineageOSROMs, lineageOSROM)
|
||||
@ -114,3 +121,18 @@ func lineageOSROMListHandler(w http.ResponseWriter, r *http.Request) {
|
||||
|
||||
w.Write(b)
|
||||
}
|
||||
|
||||
func hashFile(filename string) (string, error) {
|
||||
f, err := os.Open(filename)
|
||||
if err != nil {
|
||||
return "", fmt.Errorf("failed to open file '%s': %v: ", filename, err)
|
||||
}
|
||||
defer f.Close()
|
||||
|
||||
h := sha256.New()
|
||||
if _, err := io.Copy(h, f); err != nil {
|
||||
return "", fmt.Errorf("failed to copy data from file to hash function: %v", err)
|
||||
}
|
||||
|
||||
return string(h.Sum(nil)), nil
|
||||
}
|
||||
|
Loading…
Reference in New Issue
Block a user