增加注解

This commit is contained in:
JinJiangHuang
2026-03-01 22:23:38 +08:00
parent 99a8cc799b
commit ee8c71dcd4
23 changed files with 374 additions and 24 deletions
+24 -2
View File
@@ -5,18 +5,26 @@ import SwiftData
///
struct VodPlaybackState: Codable {
/// 线
var flag: String
///
var episodeIndex: Int
///
var progressSeconds: Double
}
///
@Model
final class VodCollect {
/// ID sourceKey
var vodId: String = ""
///
var vodName: String = ""
///
var vodPic: String = ""
/// key
var sourceKey: String = ""
/// /
var updateTime: Date = Date()
init(vodId: String, vodName: String, vodPic: String, sourceKey: String) {
@@ -31,12 +39,19 @@ final class VodCollect {
///
@Model
final class VodRecord {
/// ID
var vodId: String = ""
///
var vodName: String = ""
///
var vodPic: String = ""
/// key
var sourceKey: String = ""
var playNote: String = "" // "5 03:45"
var dataJson: String = "" // JSONVodPlaybackState
/// 5 03:45
var playNote: String = ""
/// JSON`VodPlaybackState`
var dataJson: String = ""
///
var updateTime: Date = Date()
init(vodId: String, vodName: String, vodPic: String, sourceKey: String, playNote: String = "") {
@@ -52,8 +67,11 @@ final class VodRecord {
///
@Model
final class CacheItem {
///
@Attribute(.unique) var key: String = ""
///
var value: String = ""
///
var updateTime: Date = Date()
init(key: String, value: String) {
@@ -95,6 +113,7 @@ actor CacheStore {
@MainActor
func removeCollect(vodId: String, sourceKey: String, context: ModelContext) {
// (vodId, sourceKey)
let predicate = #Predicate<VodCollect> { item in
item.vodId == vodId && item.sourceKey == sourceKey
}
@@ -151,6 +170,7 @@ actor CacheStore {
try? context.save()
}
/// JSON `nil`
@MainActor
func getPlaybackState(vodId: String, sourceKey: String, context: ModelContext) -> VodPlaybackState? {
guard let record = fetchRecord(vodId: vodId, sourceKey: sourceKey, context: context) else {
@@ -171,6 +191,7 @@ actor CacheStore {
@MainActor
private func fetchRecord(vodId: String, sourceKey: String, context: ModelContext) -> VodRecord? {
// (vodId, sourceKey)
let predicate = #Predicate<VodRecord> { item in
item.vodId == vodId && item.sourceKey == sourceKey
}
@@ -185,6 +206,7 @@ actor CacheStore {
return String(data: data, encoding: .utf8)
}
/// JSON
private nonisolated static func decodePlaybackState(_ json: String) -> VodPlaybackState? {
guard let data = json.data(using: .utf8) else { return nil }
return try? JSONDecoder().decode(VodPlaybackState.self, from: data)