mirror of
https://github.com/yattee/yattee.git
synced 2024-12-13 05:40:32 +05:30
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
|
|
}
|
|
}
|