-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathconverters.go
156 lines (135 loc) · 3.6 KB
/
converters.go
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
package UniversalRepoFmt
import "github.com/asdfzxcvbn/UniversalRepoFmt/repos"
func ConvertToESign(uni *repos.Universal) *repos.ESign {
r := repos.ESign{
Name: uni.Name,
Identifier: uni.Identifier,
}
for _, app := range uni.Apps {
r.Apps = append(r.Apps, repos.ESignApp{
Name: app.Name,
BundleID: app.BundleID,
Description: app.Description,
DownloadURL: app.DownloadURL,
IconURL: app.IconURL,
Version: app.Version,
Date: app.Date,
Size: app.Size,
})
}
return &r
}
func ConvertToGBox(uni *repos.Universal) *repos.GBox {
r := repos.GBox{
Version: "1.0",
Name: uni.Name,
IconURL: uni.IconURL,
Description: uni.Description,
}
for _, app := range uni.Apps {
r.Apps = append(r.Apps, repos.GBoxApp{
Type: "SELF_SIGN", // wtf?
Date: app.Date,
Name: app.Name,
Version: app.Version,
Description: app.Description,
IconURL: app.IconURL,
DownloadURL: app.DownloadURL,
})
}
return &r
}
func ConvertToFeather(uni *repos.Universal) *repos.Feather {
r := repos.Feather{
Name: uni.Name,
Identifier: uni.Identifier,
}
for _, app := range uni.Apps {
r.Apps = append(r.Apps, repos.FeatherApp{
Name: app.Name,
BundleID: app.BundleID,
Caption: app.Caption,
Description: app.Description,
DownloadURL: app.DownloadURL,
IconURL: app.IconURL,
Version: app.Version,
Size: app.Size,
})
}
return &r
}
func ConvertToAltStore(uni *repos.Universal) *repos.AltStore {
r := repos.AltStore{
Name: uni.Name,
Identifier: uni.Identifier, // sidestore moment 1
IconURL: uni.IconURL,
Caption: uni.Caption,
Description: uni.Description,
}
// step 1: find indexes of all apps with same bundle id
bundleIdIdxs := make(map[string][]int, len(uni.Apps))
for idx, app := range uni.Apps {
_, ok := bundleIdIdxs[app.BundleID]
if !ok {
bundleIdIdxs[app.BundleID] = []int{idx}
} else {
bundleIdIdxs[app.BundleID] = append(bundleIdIdxs[app.BundleID], idx)
}
}
for bundle, idxs := range bundleIdIdxs {
orig := uni.Apps[idxs[0]]
app := repos.AltStoreApp{
Name: orig.Name,
DeveloperName: orig.DeveloperName,
BundleID: bundle,
IconURL: orig.IconURL,
}
// this wont be used for sidestore
if permissions, ok := uni.Permissions[bundle]; ok {
app.Permissions = permissions
}
for _, idx := range idxs {
origIdx := uni.Apps[idx]
app.Versions = append(app.Versions, repos.AltStoreAppVersion{
Version: origIdx.Version,
Date: origIdx.Date,
Description: origIdx.Description,
DownloadURL: origIdx.DownloadURL,
Size: origIdx.Size,
})
}
app.DownloadURL = app.Versions[0].DownloadURL // real sidestore moment 2
r.Apps = append(r.Apps, app)
}
return &r
}
func ConvertToScarlet(uni *repos.Universal) *repos.Scarlet {
r := repos.Scarlet{
Meta: repos.ScarletMeta{
RepoName: uni.Name,
RepoIcon: uni.IconURL,
},
}
for _, app := range uni.Apps {
r.Apps = append(r.Apps, repos.ScarletApp{
Name: app.Name,
DeveloperName: app.DeveloperName,
Version: app.Version,
Icon: app.IconURL,
Down: app.DownloadURL,
Description: app.Description,
BundleID: app.BundleID,
})
}
return &r
}
// a convenience function that returns all formatted repos.
func ConvertToAll(uni *repos.Universal) *repos.All {
return &repos.All{
ESign: ConvertToESign(uni),
GBox: ConvertToGBox(uni),
Feather: ConvertToFeather(uni),
AltStore: ConvertToAltStore(uni),
Scarlet: ConvertToScarlet(uni),
}
}