e8c3e4644e
CI / lint-and-build (push) Has been cancelled
- Swift 6 + SwiftUI + SwiftData 直接调用阿里云 VOD API - 自实现 POP 签名,无需 Node 后端 - 视频列表、搜索、批量下载到用户选择目录 - 下载文件自动使用视频标题重命名 - 浏览器下载与下载工具(aria2/wget)两种方式 - Web 版标记为废弃,README/AGENTS/MEMORY 更新
50 lines
1.4 KiB
Swift
50 lines
1.4 KiB
Swift
import Foundation
|
|
import SwiftData
|
|
|
|
@MainActor
|
|
class AccountStore: ObservableObject {
|
|
static let shared = AccountStore()
|
|
|
|
@Published var accounts: [Account] = []
|
|
@Published var activeAccount: Account?
|
|
|
|
private init() {}
|
|
|
|
func load() async {
|
|
accounts = await DatabaseManager.shared.allAccounts()
|
|
activeAccount = await DatabaseManager.shared.activeAccount()
|
|
if let account = activeAccount {
|
|
await VODClient.shared.setActiveAccount(account)
|
|
}
|
|
}
|
|
|
|
func addAccount(_ account: Account) async {
|
|
await DatabaseManager.shared.save(account)
|
|
if account.isActive {
|
|
await DatabaseManager.shared.clearActiveAccounts()
|
|
account.isActive = true
|
|
await DatabaseManager.shared.save(account)
|
|
}
|
|
await load()
|
|
}
|
|
|
|
func updateAccount(_ account: Account) async {
|
|
await DatabaseManager.shared.save(account)
|
|
await load()
|
|
}
|
|
|
|
func deleteAccount(_ account: Account) async {
|
|
await DatabaseManager.shared.delete(account)
|
|
await load()
|
|
}
|
|
|
|
func switchActive(_ account: Account) async {
|
|
await DatabaseManager.shared.clearActiveAccounts()
|
|
account.isActive = true
|
|
account.updatedAt = Date()
|
|
await DatabaseManager.shared.save(account)
|
|
await VODClient.shared.setActiveAccount(account)
|
|
await load()
|
|
}
|
|
}
|