mirror of
https://github.com/advplyr/audiobookshelf-app.git
synced 2025-07-30 23:54:30 +02:00
Add:iOS offline ebooks
This commit is contained in:
parent
8b39ba9c92
commit
147f89f870
13 changed files with 157 additions and 26 deletions
78
ios/App/Shared/models/server/EBookFile.swift
Normal file
78
ios/App/Shared/models/server/EBookFile.swift
Normal file
|
@ -0,0 +1,78 @@
|
|||
//
|
||||
// EBookFile.swift
|
||||
// Audiobookshelf
|
||||
//
|
||||
// Created by Advplyr on 6/19/23.
|
||||
//
|
||||
|
||||
import Foundation
|
||||
import RealmSwift
|
||||
|
||||
class EBookFile: EmbeddedObject, Codable {
|
||||
@Persisted var ino: String = ""
|
||||
@Persisted var metadata: FileMetadata?
|
||||
@Persisted var ebookFormat: String
|
||||
@Persisted var contentUrl: String?
|
||||
@Persisted var localFileId: String?
|
||||
|
||||
private enum CodingKeys : String, CodingKey {
|
||||
case ino, metadata, ebookFormat, contentUrl, localFileId
|
||||
}
|
||||
|
||||
override init() {
|
||||
super.init()
|
||||
}
|
||||
|
||||
required init(from decoder: Decoder) throws {
|
||||
super.init()
|
||||
let values = try decoder.container(keyedBy: CodingKeys.self)
|
||||
ino = try values.decode(String.self, forKey: .ino)
|
||||
metadata = try values.decode(FileMetadata.self, forKey: .metadata)
|
||||
ebookFormat = try values.decode(String.self, forKey: .ebookFormat)
|
||||
contentUrl = try? values.decode(String.self, forKey: .contentUrl)
|
||||
localFileId = try? values.decodeIfPresent(String.self, forKey: .localFileId)
|
||||
}
|
||||
|
||||
func encode(to encoder: Encoder) throws {
|
||||
var container = encoder.container(keyedBy: CodingKeys.self)
|
||||
try container.encode(ino, forKey: .ino)
|
||||
try container.encode(metadata, forKey: .metadata)
|
||||
try container.encode(ebookFormat, forKey: .ebookFormat)
|
||||
try container.encode(contentUrl, forKey: .contentUrl)
|
||||
try container.encode(localFileId, forKey: .localFileId)
|
||||
}
|
||||
}
|
||||
|
||||
extension EBookFile {
|
||||
func setLocalInfo(localFile: LocalFile) -> Bool {
|
||||
self.localFileId = localFile.id
|
||||
self.contentUrl = localFile.contentUrl
|
||||
return false
|
||||
}
|
||||
|
||||
func getLocalFile() -> LocalFile? {
|
||||
guard let localFileId = self.localFileId else { return nil }
|
||||
return Database.shared.getLocalFile(localFileId: localFileId)
|
||||
}
|
||||
|
||||
func mimeType() -> String? {
|
||||
var mimeType = ""
|
||||
switch ebookFormat {
|
||||
case "epub":
|
||||
mimeType = "application/epub+zip"
|
||||
case "pdf":
|
||||
mimeType = "application/pdf"
|
||||
case "mobi":
|
||||
mimeType = "application/x-mobipocket-ebook"
|
||||
case "azw3":
|
||||
mimeType = "application/vnd.amazon.mobi8-ebook"
|
||||
case "cbr":
|
||||
mimeType = "application/vnd.comicbook-rar"
|
||||
case "cbz":
|
||||
mimeType = "application/vnd.comicbook+zip"
|
||||
default:
|
||||
mimeType = "application/epub+zip"
|
||||
}
|
||||
return mimeType
|
||||
}
|
||||
}
|
Loading…
Add table
Add a link
Reference in a new issue