mirror of
https://github.com/advplyr/audiobookshelf-app.git
synced 2025-08-31 15:19:34 +02:00
Handle a documents directory that can change
Thanks iOS
This commit is contained in:
parent
8e2be4704e
commit
e9961f64a9
4 changed files with 137 additions and 53 deletions
|
@ -11,23 +11,87 @@ import Unrealm
|
|||
struct LocalLibraryItem: Realmable, Codable {
|
||||
var id: String = "local_\(UUID().uuidString)"
|
||||
var basePath: String = ""
|
||||
var absolutePath: String = ""
|
||||
var contentUrl: String = ""
|
||||
dynamic var _contentUrl: String?
|
||||
var isInvalid: Bool = false
|
||||
var mediaType: String = ""
|
||||
var media: MediaType?
|
||||
var localFiles: [LocalFile] = []
|
||||
var coverContentUrl: String?
|
||||
var coverAbsolutePath: String?
|
||||
dynamic var _coverContentUrl: String?
|
||||
var isLocal: Bool = true
|
||||
var serverConnectionConfigId: String?
|
||||
var serverAddress: String?
|
||||
var serverUserId: String?
|
||||
var libraryItemId: String?
|
||||
|
||||
var contentUrl: String? {
|
||||
set(url) {
|
||||
_contentUrl = url
|
||||
}
|
||||
get {
|
||||
if let path = _contentUrl {
|
||||
return AbsDownloader.downloadsDirectory.appendingPathComponent(path).absoluteString
|
||||
} else {
|
||||
return nil
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
var coverContentUrl: String? {
|
||||
set(url) {
|
||||
_coverContentUrl = url
|
||||
}
|
||||
get {
|
||||
if let path = self._coverContentUrl {
|
||||
return AbsDownloader.downloadsDirectory.appendingPathComponent(path).absoluteString
|
||||
} else {
|
||||
return nil
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
static func primaryKey() -> String? {
|
||||
return "id"
|
||||
}
|
||||
|
||||
private enum CodingKeys : String, CodingKey {
|
||||
case id, basePath, contentUrl, isInvalid, mediaType, media, localFiles, coverContentUrl, isLocal, serverConnectionConfigId, serverAddress, serverUserId, libraryItemId
|
||||
}
|
||||
|
||||
init() {}
|
||||
|
||||
init(from decoder: Decoder) throws {
|
||||
let values = try decoder.container(keyedBy: CodingKeys.self)
|
||||
id = try values.decode(String.self, forKey: .id)
|
||||
basePath = try values.decode(String.self, forKey: .basePath)
|
||||
contentUrl = try values.decode(String.self, forKey: .contentUrl)
|
||||
isInvalid = try values.decode(Bool.self, forKey: .isInvalid)
|
||||
mediaType = try values.decode(String.self, forKey: .mediaType)
|
||||
media = try values.decode(MediaType.self, forKey: .media)
|
||||
localFiles = try values.decode([LocalFile].self, forKey: .localFiles)
|
||||
coverContentUrl = try values.decode(String.self, forKey: .coverContentUrl)
|
||||
isLocal = try values.decode(Bool.self, forKey: .isLocal)
|
||||
serverConnectionConfigId = try values.decode(String.self, forKey: .serverConnectionConfigId)
|
||||
serverAddress = try values.decode(String.self, forKey: .serverAddress)
|
||||
serverUserId = try values.decode(String.self, forKey: .serverUserId)
|
||||
libraryItemId = try values.decode(String.self, forKey: .libraryItemId)
|
||||
}
|
||||
|
||||
func encode(to encoder: Encoder) throws {
|
||||
var container = encoder.container(keyedBy: CodingKeys.self)
|
||||
try container.encode(id, forKey: .id)
|
||||
try container.encode(basePath, forKey: .basePath)
|
||||
try container.encode(contentUrl, forKey: .contentUrl)
|
||||
try container.encode(isInvalid, forKey: .isInvalid)
|
||||
try container.encode(mediaType, forKey: .mediaType)
|
||||
try container.encode(media, forKey: .media)
|
||||
try container.encode(localFiles, forKey: .localFiles)
|
||||
try container.encode(coverContentUrl, forKey: .coverContentUrl)
|
||||
try container.encode(isLocal, forKey: .isLocal)
|
||||
try container.encode(serverConnectionConfigId, forKey: .serverConnectionConfigId)
|
||||
try container.encode(serverAddress, forKey: .serverAddress)
|
||||
try container.encode(serverUserId, forKey: .serverUserId)
|
||||
try container.encode(libraryItemId, forKey: .libraryItemId)
|
||||
}
|
||||
}
|
||||
|
||||
struct LocalPodcastEpisode: Realmable, Codable {
|
||||
|
@ -53,13 +117,40 @@ struct LocalFile: Realmable, Codable {
|
|||
var id: String = UUID().uuidString
|
||||
var filename: String?
|
||||
var contentUrl: String = ""
|
||||
var absolutePath: String = ""
|
||||
var absolutePath: String {
|
||||
return AbsDownloader.downloadsDirectory.appendingPathComponent(self.contentUrl).absoluteString
|
||||
}
|
||||
var mimeType: String?
|
||||
var size: Int = 0
|
||||
|
||||
static func primaryKey() -> String? {
|
||||
return "id"
|
||||
}
|
||||
|
||||
private enum CodingKeys : String, CodingKey {
|
||||
case id, filename, contentUrl, absolutePath, mimeType, size
|
||||
}
|
||||
|
||||
init() {}
|
||||
|
||||
init(from decoder: Decoder) throws {
|
||||
let values = try decoder.container(keyedBy: CodingKeys.self)
|
||||
id = try values.decode(String.self, forKey: .id)
|
||||
filename = try values.decode(String.self, forKey: .filename)
|
||||
contentUrl = try values.decode(String.self, forKey: .contentUrl)
|
||||
mimeType = try values.decode(String.self, forKey: .mimeType)
|
||||
size = try values.decode(Int.self, forKey: .size)
|
||||
}
|
||||
|
||||
func encode(to encoder: Encoder) throws {
|
||||
var container = encoder.container(keyedBy: CodingKeys.self)
|
||||
try container.encode(id, forKey: .id)
|
||||
try container.encode(filename, forKey: .filename)
|
||||
try container.encode(contentUrl, forKey: .contentUrl)
|
||||
try container.encode(absolutePath, forKey: .absolutePath)
|
||||
try container.encode(mimeType, forKey: .mimeType)
|
||||
try container.encode(size, forKey: .size)
|
||||
}
|
||||
}
|
||||
|
||||
struct LocalMediaProgress: Realmable, Codable {
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue