mirror of
https://github.com/yattee/yattee.git
synced 2024-11-10 00:08:21 +00:00
24 lines
687 B
Swift
24 lines
687 B
Swift
import Foundation
|
|
import Logging
|
|
import SwiftyJSON
|
|
|
|
struct VideoCacheModel {
|
|
static let shared = VideoCacheModel()
|
|
var logger = Logger(label: "stream.yattee.video-cache")
|
|
|
|
func saveVideo(id: Video.ID, app: VideosApp, json: JSON) {
|
|
guard !json.isEmpty else { return }
|
|
var jsonWithApp = json
|
|
jsonWithApp["app"].string = app.rawValue
|
|
try! CacheModel.shared.videoStorage!.setObject(jsonWithApp, forKey: id)
|
|
logger.info("saving video \(id)")
|
|
}
|
|
|
|
func loadVideo(id: Video.ID) -> JSON? {
|
|
logger.info("loading video \(id)")
|
|
|
|
let json = try? CacheModel.shared.videoStorage?.object(forKey: id)
|
|
return json
|
|
}
|
|
}
|