ReadKeep/readeck/Data/TokenProvider.swift
Ilyas Hallak c8368f0a70 feat: Implement bookmark filtering, enhanced UI, and API integration
- Add BookmarkState enum with unread, favorite, and archived states
- Extend API layer with query parameter filtering for bookmark states
- Update Bookmark domain model to match complete API response schema
- Implement BookmarkListView with card-based UI and preview images
- Add BookmarkListViewModel with state management and error handling
- Enhance BookmarkDetailView with meta information and WebView rendering
- Create comprehensive DTO mapping for all bookmark fields
- Add TabView with state-based bookmark filtering
- Implement date formatting utilities for ISO8601 timestamps
- Add progress indicators and pull-to-refresh functionality
2025-06-11 22:02:44 +02:00

59 lines
1.6 KiB
Swift

import Foundation
protocol TokenProvider {
func getToken() async -> String?
func getEndpoint() async -> String
func setToken(_ token: String) async
func clearToken() async
}
class CoreDataTokenProvider: TokenProvider {
private let settingsRepository = SettingsRepository()
private var cachedSettings: Settings?
private var isLoaded = false
private func loadSettingsIfNeeded() async {
guard !isLoaded else { return }
do {
cachedSettings = try await settingsRepository.loadSettings()
isLoaded = true
} catch {
print("Failed to load settings: \(error)")
cachedSettings = nil
}
}
func getToken() async -> String? {
await loadSettingsIfNeeded()
return cachedSettings?.token
}
func getEndpoint() async -> String {
await loadSettingsIfNeeded()
// Basis-URL ohne /api Suffix, da es in der API-Klasse hinzugefügt wird
return cachedSettings?.endpoint ?? "https://keep.mnk.any64.de"
}
func setToken(_ token: String) async {
await loadSettingsIfNeeded()
do {
try await settingsRepository.saveToken(token)
if cachedSettings != nil {
cachedSettings!.token = token
}
} catch {
print("Failed to save token: \(error)")
}
}
func clearToken() async {
do {
try await settingsRepository.clearSettings()
cachedSettings = nil
} catch {
print("Failed to clear settings: \(error)")
}
}
}