add version and ID (filehash)
continuous-integration/drone/push Build is passing Details

This commit is contained in:
Steven Polley 2023-06-04 09:32:23 -06:00
parent 62722871e7
commit f9a0a1df8f
1 changed files with 24 additions and 2 deletions

26
main.go
View File

@ -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
}