Browse Source

fix parsing the bromite index

pull/70/head
Linus789 3 years ago
parent
commit
1908976143
  1. 65
      fdroid/index.go
  2. 6
      show.go

65
fdroid/index.go

@ -10,6 +10,7 @@ import (
"html" "html"
"io" "io"
"sort" "sort"
"strconv"
"strings" "strings"
"mvdan.cc/fdroidcl/adb" "mvdan.cc/fdroidcl/adb"
@ -193,21 +194,22 @@ func (a *App) TextDesc(w io.Writer) {
// Apk is an Android package // Apk is an Android package
type Apk struct { type Apk struct {
VersName string `json:"versionName"` VersName string `json:"versionName"`
VersCode int `json:"versionCode"` VersCode int `json:"versionCode"`
Size int64 `json:"size"` Size int64 `json:"size"`
MinSdk int `json:"minSdkVersion"` MinSdk StringInt `json:"minSdkVersion"`
MaxSdk int `json:"maxSdkVersion"` MaxSdk StringInt `json:"maxSdkVersion"`
ABIs []string `json:"nativecode"` TargetSdk StringInt `json:"targetSdkVersion"`
ApkName string `json:"apkName"` ABIs []string `json:"nativecode"`
SrcName string `json:"srcname"` ApkName string `json:"apkName"`
Sig HexVal `json:"sig"` SrcName string `json:"srcname"`
Signer HexVal `json:"signer"` Sig HexVal `json:"sig"`
Added UnixDate `json:"added"` Signer HexVal `json:"signer"`
Perms []Permission `json:"uses-permission"` Added UnixDate `json:"added"`
Feats []string `json:"features"` Perms []Permission `json:"uses-permission"`
Hash HexVal `json:"hash"` Feats []string `json:"features"`
HashType string `json:"hashType"` Hash HexVal `json:"hash"`
HashType string `json:"hashType"`
AppID string `json:"-"` AppID string `json:"-"`
RepoURL string `json:"-"` RepoURL string `json:"-"`
@ -233,6 +235,37 @@ func (p *Permission) UnmarshalJSON(data []byte) error {
return nil return nil
} }
// https://codesahara.com/blog/golang-cannot-unmarshal-string-into-go-value-of-type-int/
type StringInt struct {
Value int
}
func (st *StringInt) UnmarshalJSON(b []byte) error {
// convert the bytes into an interface
// this will help us check the type of our value
// if it is a string that can be converted into an int we convert it
// otherwise we return an error
var item interface{}
if err := json.Unmarshal(b, &item); err != nil {
return err
}
switch v := item.(type) {
case int:
*st = StringInt{Value: v}
case float64:
*st = StringInt{Value: int(v)}
case string:
// here convert the string into an integer
i, err := strconv.Atoi(v)
if err != nil {
// the string might not be of integer type, so return an error
return err
}
*st = StringInt{Value: i}
}
return nil
}
func (a *Apk) URL() string { func (a *Apk) URL() string {
return fmt.Sprintf("%s/%s", a.RepoURL, a.ApkName) return fmt.Sprintf("%s/%s", a.RepoURL, a.ApkName)
} }
@ -256,7 +289,7 @@ func (a *Apk) IsCompatibleABI(ABIs []string) bool {
} }
func (a *Apk) IsCompatibleAPILevel(sdk int) bool { func (a *Apk) IsCompatibleAPILevel(sdk int) bool {
return sdk >= a.MinSdk && (a.MaxSdk == 0 || sdk <= a.MaxSdk) return sdk >= a.MinSdk.Value && (a.MaxSdk.Value == 0 || sdk <= a.MaxSdk.Value)
} }
func (a *Apk) IsCompatible(device *adb.Device) bool { func (a *Apk) IsCompatible(device *adb.Device) bool {

6
show.go

@ -133,9 +133,9 @@ func printAppDetailed(app fdroid.App) {
fmt.Println() fmt.Println()
fmt.Printf(" Version : %s (%d)\n", apk.VersName, apk.VersCode) fmt.Printf(" Version : %s (%d)\n", apk.VersName, apk.VersCode)
fmt.Printf(" Size : %d\n", apk.Size) fmt.Printf(" Size : %d\n", apk.Size)
fmt.Printf(" MinSdk : %d\n", apk.MinSdk) fmt.Printf(" MinSdk : %d\n", apk.MinSdk.Value)
if apk.MaxSdk > 0 { if apk.MaxSdk.Value > 0 {
fmt.Printf(" MaxSdk : %d\n", apk.MaxSdk) fmt.Printf(" MaxSdk : %d\n", apk.MaxSdk.Value)
} }
if apk.ABIs != nil { if apk.ABIs != nil {
fmt.Printf(" ABIs : %s\n", strings.Join(apk.ABIs, ", ")) fmt.Printf(" ABIs : %s\n", strings.Join(apk.ABIs, ", "))

Loading…
Cancel
Save