mirror of
https://github.com/zarzet/SpotiFLAC-Mobile.git
synced 2026-08-05 18:48:38 +02:00
Coordinated rename of the nine store-named bridge surfaces: Go exports (InitExtensionStoreJSON -> InitExtensionRepoJSON etc.), method-channel strings, the Kotlin and Swift handlers, and the Dart PlatformBridge methods. Channel strings verified 1:1 across Dart/Kotlin/Swift; gomobile bindings match the new export names. Android MediaStore APIs untouched. store_registry_url pref key kept for existing users. Local Android/iOS builds need the gobackend AAR/xcframework rebuilt; CI does this in the release workflow.
149 lines
3.1 KiB
Go
149 lines
3.1 KiB
Go
package gobackend
|
|
|
|
import (
|
|
"fmt"
|
|
"net/url"
|
|
"path/filepath"
|
|
"strings"
|
|
)
|
|
|
|
func InitExtensionRepoJSON(cacheDir string) error {
|
|
initExtensionRepo(cacheDir)
|
|
return nil
|
|
}
|
|
|
|
func SetRepoRegistryURLJSON(registryURL string) error {
|
|
repo := getExtensionRepo()
|
|
if repo == nil {
|
|
return fmt.Errorf("extension repo not initialized")
|
|
}
|
|
|
|
resolved, err := resolveRegistryURL(registryURL)
|
|
if err != nil {
|
|
return err
|
|
}
|
|
|
|
if err := requireHTTPSURL(resolved, "registry"); err != nil {
|
|
return err
|
|
}
|
|
|
|
repo.setRegistryURL(resolved)
|
|
return nil
|
|
}
|
|
|
|
func ClearRepoRegistryURLJSON() error {
|
|
repo := getExtensionRepo()
|
|
if repo == nil {
|
|
return fmt.Errorf("extension repo not initialized")
|
|
}
|
|
|
|
repo.setRegistryURL("")
|
|
repo.clearCache()
|
|
return nil
|
|
}
|
|
|
|
func GetRepoRegistryURLJSON() (string, error) {
|
|
repo := getExtensionRepo()
|
|
if repo == nil {
|
|
return "", fmt.Errorf("extension repo not initialized")
|
|
}
|
|
|
|
return repo.getRegistryURL(), nil
|
|
}
|
|
|
|
func GetRepoExtensionsJSON(forceRefresh bool) (string, error) {
|
|
repo := getExtensionRepo()
|
|
if repo == nil {
|
|
return "", fmt.Errorf("extension repo not initialized")
|
|
}
|
|
|
|
extensions, err := repo.getExtensionsWithStatus(forceRefresh)
|
|
if err != nil {
|
|
return "", err
|
|
}
|
|
|
|
return marshalJSONString(extensions)
|
|
}
|
|
|
|
func SearchRepoExtensionsJSON(query, category string) (string, error) {
|
|
repo := getExtensionRepo()
|
|
if repo == nil {
|
|
return "", fmt.Errorf("extension repo not initialized")
|
|
}
|
|
|
|
extensions, err := repo.searchExtensions(query, category)
|
|
if err != nil {
|
|
return "", err
|
|
}
|
|
|
|
return marshalJSONString(extensions)
|
|
}
|
|
|
|
func GetRepoCategoriesJSON() (string, error) {
|
|
repo := getExtensionRepo()
|
|
if repo == nil {
|
|
return "", fmt.Errorf("extension repo not initialized")
|
|
}
|
|
|
|
categories := repo.getCategories()
|
|
return marshalJSONString(categories)
|
|
}
|
|
|
|
func repoExtensionPackageSuffix(downloadURL string) string {
|
|
rawPath := downloadURL
|
|
if parsed, err := url.Parse(downloadURL); err == nil {
|
|
rawPath = parsed.Path
|
|
}
|
|
|
|
lowerPath := strings.ToLower(rawPath)
|
|
if strings.HasSuffix(lowerPath, ".sflx") {
|
|
return ".sflx"
|
|
}
|
|
if strings.HasSuffix(lowerPath, ".spotiflac-ext") {
|
|
return ".spotiflac-ext"
|
|
}
|
|
return ".spotiflac-ext"
|
|
}
|
|
|
|
func buildRepoExtensionDestPath(destDir, extensionID, downloadURL string) (string, error) {
|
|
if strings.TrimSpace(extensionID) == "" {
|
|
return "", fmt.Errorf("invalid extension id")
|
|
}
|
|
|
|
safeExtensionID := sanitizeFilename(extensionID)
|
|
return filepath.Join(destDir, safeExtensionID+repoExtensionPackageSuffix(downloadURL)), nil
|
|
}
|
|
|
|
func DownloadRepoExtensionJSON(extensionID, destDir string) (string, error) {
|
|
repo := getExtensionRepo()
|
|
if repo == nil {
|
|
return "", fmt.Errorf("extension repo not initialized")
|
|
}
|
|
|
|
ext, err := repo.findExtension(extensionID)
|
|
if err != nil {
|
|
return "", err
|
|
}
|
|
|
|
destPath, err := buildRepoExtensionDestPath(destDir, extensionID, ext.getDownloadURL())
|
|
if err != nil {
|
|
return "", err
|
|
}
|
|
err = repo.downloadExtension(extensionID, destPath)
|
|
if err != nil {
|
|
return "", err
|
|
}
|
|
|
|
return destPath, nil
|
|
}
|
|
|
|
func ClearRepoCacheJSON() error {
|
|
repo := getExtensionRepo()
|
|
if repo == nil {
|
|
return fmt.Errorf("extension repo not initialized")
|
|
}
|
|
|
|
repo.clearCache()
|
|
return nil
|
|
}
|