remove backward compatibility and also move v2 api endpoint to root
lineageos-ota-server / build (push) Successful in 32s

This commit is contained in:
2026-07-04 11:31:21 -06:00
parent f06ccb4781
commit 282ac863c4
+47 -6
View File
@@ -272,22 +272,63 @@ func updateROMCache() {
} }
// http - GET / // http - GET /
// The LineageOS updater app needs a JSON array of type LineageOSROM // The LineageOS updater app needs a JSON array of v2 builds
// Marshals romCache.ROMs to JSON to serve as the response body // Marshals romCache.ROMs to V2 JSON format to serve as the response body
func lineageOSROMListHandler(w http.ResponseWriter, r *http.Request) { func lineageOSROMListHandler(w http.ResponseWriter, r *http.Request) {
checkNewBuilds() checkNewBuilds()
romCache.RLock() romCache.RLock()
httpResponseJSON := &HTTPResponseJSON{Response: romCache.ROMs} defer romCache.RUnlock()
romCache.RUnlock()
b, err := json.Marshal(httpResponseJSON) var builds []V2BuildResponse
for _, rom := range romCache.ROMs {
relPath := rom.Filename
if strings.Contains(rom.URL, "/public/") {
parts := strings.SplitN(rom.URL, "/public/", 2)
if len(parts) == 2 {
relPath = parts[1]
}
}
file := V2BuildFile{
Date: rom.Date,
Datetime: int64(rom.Datetime),
Filename: rom.Filename,
Filepath: "/public/" + relPath,
OSPatchLevel: rom.OSPatchLevel,
OSSDKLevel: rom.OSSDKLevel,
OTAPropertyFiles: rom.OTAPropertyFiles,
SHA1: rom.SHA1,
SHA256: rom.SHA256,
Size: int64(rom.Size),
Type: strings.ToLower(rom.Romtype),
URL: rom.URL,
}
build := V2BuildResponse{
Date: rom.Date,
Datetime: int64(rom.Datetime),
Files: []V2BuildFile{file},
Type: strings.ToLower(rom.Romtype),
Version: rom.Version,
}
builds = append(builds, build)
}
if builds == nil {
builds = []V2BuildResponse{}
}
b, err := json.Marshal(builds)
if err != nil { if err != nil {
w.WriteHeader(http.StatusInternalServerError) w.WriteHeader(http.StatusInternalServerError)
log.Printf("failed to marshal lineageOSROMs to json: %v", err) log.Printf("failed to marshal v2 builds to json: %v", err)
return return
} }
w.Header().Set("Content-Type", "application/json")
w.Write(b) w.Write(b)
} }