- Swift 6 + SwiftUI + SwiftData 直接调用阿里云 VOD API - 自实现 POP 签名,无需 Node 后端 - 视频列表、搜索、批量下载到用户选择目录 - 下载文件自动使用视频标题重命名 - 浏览器下载与下载工具(aria2/wget)两种方式 - Web 版标记为废弃,README/AGENTS/MEMORY 更新
This commit is contained in:
@@ -0,0 +1,49 @@
|
||||
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()
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user