Rework content commands, add audio player

This commit is contained in:
Christoph Hagen
2024-12-14 16:31:40 +01:00
parent b3b8c9a610
commit be2aab2ea8
52 changed files with 1758 additions and 767 deletions

View File

@ -1,9 +1,7 @@
import Foundation
import SwiftUI
final class FileResource: ObservableObject {
unowned let content: Content
final class FileResource: Item {
let type: FileType
@ -24,24 +22,24 @@ final class FileResource: ObservableObject {
var size: CGSize = .zero
init(content: Content, id: String, isExternallyStored: Bool, en: String, de: String) {
self.content = content
self.id = id
self.type = FileType(fileExtension: id.fileExtension)
self.englishDescription = en
self.germanDescription = de
self.isExternallyStored = isExternallyStored
super.init(content: content)
}
/**
Only for bundle images
*/
init(resourceImage: String, type: ImageFileType) {
self.content = .mock // TODO: Add images to mock
self.type = .image(type)
self.id = resourceImage
self.englishDescription = "A test image included in the bundle"
self.germanDescription = "Ein Testbild aus dem Bundle"
self.isExternallyStored = true
super.init(content: .mock) // TODO: Add images to mock
}
func getDescription(for language: ContentLanguage) -> String {
@ -62,6 +60,10 @@ final class FileResource: ObservableObject {
}
}
func dataContent() throws -> Data {
try content.storage.fileData(for: id)
}
// MARK: Images
var aspectRatio: CGFloat {
@ -94,6 +96,26 @@ final class FileResource: ObservableObject {
private var failureImage: Image {
Image(systemSymbol: .exclamationmarkTriangle)
}
// MARK: Paths
/**
Get the url path to a file in the output folder.
The result is an absolute path from the output folder for use in HTML.
*/
var absoluteUrl: String {
let path = pathPrefix + "/" + id
return makeCleanAbsolutePath(path)
}
private var pathPrefix: String {
switch type {
case .image: return content.settings.paths.imagesOutputFolderPath
case .video: return content.settings.paths.videosOutputFolderPath
default: return content.settings.paths.filesOutputFolderPath
}
}
}
extension FileResource: Identifiable {