Initalier Commit

This commit is contained in:
2026-04-19 19:55:22 +02:00
commit 93e2c811b6
10 changed files with 318 additions and 0 deletions

31
Linkster/ApiClient.swift Normal file
View File

@@ -0,0 +1,31 @@
import Foundation
struct ApiClient {
static let shared = ApiClient()
private let base = URL(string: "https://linkster.langhei.de/api")!
func resolve(url: String) async throws -> SongResult? {
var components = URLComponents(url: base.appendingPathComponent("resolve"), resolvingAgainstBaseURL: false)!
components.queryItems = [URLQueryItem(name: "url", value: url)]
let (data, _) = try await URLSession.shared.data(from: components.url!)
let json = try JSONDecoder().decode(ResolveResponse.self, from: data)
guard json.found else { return nil }
return SongResult(
title: json.title ?? "",
artist: json.artist ?? "",
playlistName: json.playlist ?? "",
providers: json.providers ?? [:]
)
}
}
private struct ResolveResponse: Decodable {
let found: Bool
let title: String?
let artist: String?
let playlist: String?
let providers: [String: String]?
}