mirror of
https://github.com/advplyr/audiobookshelf-app.git
synced 2025-08-05 10:35:42 +02:00
Refactor to use extensions for objects
This commit is contained in:
parent
b7725c455b
commit
52d0890032
4 changed files with 63 additions and 36 deletions
|
@ -25,34 +25,6 @@ class LocalLibraryItem: Object, Encodable {
|
|||
@Persisted var serverAddress: String? = nil
|
||||
@Persisted var serverUserId: String? = nil
|
||||
@Persisted var libraryItemId: String? = nil
|
||||
|
||||
override init() {
|
||||
super.init()
|
||||
}
|
||||
|
||||
init(item: LibraryItem, localUrl: URL, server: ServerConnectionConfig, files: [LocalFile]) {
|
||||
super.init()
|
||||
self.id = item.id
|
||||
self.contentUrl = localUrl.absoluteString
|
||||
self.mediaType = item.mediaType
|
||||
self.media = LocalMediaType(mediaType: item.media)
|
||||
self.localFiles.append(objectsIn: files)
|
||||
// TODO: self.coverContentURL
|
||||
// TODO: self.converAbsolutePath
|
||||
self.libraryItemId = item.id
|
||||
self.serverConnectionConfigId = server.id
|
||||
self.serverAddress = server.address
|
||||
self.serverUserId = server.userId
|
||||
}
|
||||
|
||||
enum CodingKeys: CodingKey {
|
||||
case id
|
||||
}
|
||||
|
||||
func encode(to encoder: Encoder) throws {
|
||||
var container = encoder.container(keyedBy: CodingKeys.self)
|
||||
try container.encode(id, forKey: .id)
|
||||
}
|
||||
}
|
||||
|
||||
class LocalMediaType: Object {
|
||||
|
@ -113,13 +85,10 @@ class LocalMetadata: Object {
|
|||
@Persisted var narratorName: String? = ""
|
||||
@Persisted var seriesName: String? = ""
|
||||
@Persisted var feedUrl: String? = ""
|
||||
|
||||
override init() {
|
||||
super.init()
|
||||
}
|
||||
|
||||
init(metadata: Metadata) {
|
||||
super.init()
|
||||
}
|
||||
|
||||
extension LocalMetadata {
|
||||
convenience init(metadata: Metadata) {
|
||||
self.title = metadata.title
|
||||
self.subtitle = metadata.subtitle
|
||||
self.narrators.append(objectsIn: metadata.narrators ?? [])
|
||||
|
|
54
ios/App/Shared/models/LocalLibraryExtensions.swift
Normal file
54
ios/App/Shared/models/LocalLibraryExtensions.swift
Normal file
|
@ -0,0 +1,54 @@
|
|||
//
|
||||
// LocalLibraryExtensions.swift
|
||||
// App
|
||||
//
|
||||
// Created by Ron Heft on 7/16/22.
|
||||
//
|
||||
|
||||
import Foundation
|
||||
|
||||
extension LocalLibraryItem {
|
||||
enum CodingKeys: CodingKey {
|
||||
case id
|
||||
case basePath
|
||||
case absolutePath
|
||||
case contentUrl
|
||||
case isInvalid
|
||||
case mediaType
|
||||
case media
|
||||
case localFiles
|
||||
case coverContentUrl
|
||||
case coverAbsolutePath
|
||||
case isLocal
|
||||
case serverConnectionConfigId
|
||||
case serverAddress
|
||||
case serverUserId
|
||||
case 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(absolutePath, forKey: .absolutePath)
|
||||
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)
|
||||
}
|
||||
|
||||
convenience init(_ item: LibraryItem, localUrl: URL, server: ServerConnectionConfig, files: [LocalFile]) {
|
||||
self.init()
|
||||
self.contentUrl = localUrl.absoluteString
|
||||
self.mediaType = item.mediaType
|
||||
self.media = LocalMediaType(mediaType: item.media)
|
||||
self.localFiles.append(objectsIn: files)
|
||||
// TODO: self.coverContentURL
|
||||
// TODO: self.converAbsolutePath
|
||||
self.libraryItemId = item.id
|
||||
self.serverConnectionConfigId = server.id
|
||||
self.serverAddress = server.address
|
||||
self.serverUserId = server.userId
|
||||
}
|
||||
}
|
Loading…
Add table
Add a link
Reference in a new issue