Add a Files tab to the project page
This commit is contained in:
@@ -3,7 +3,7 @@ import SwiftUI
|
||||
|
||||
enum ImageSource: Hashable {
|
||||
case blob(String)
|
||||
case worktree(taskId: String, path: String)
|
||||
case file(FileRoot, path: String)
|
||||
case data(Data)
|
||||
}
|
||||
|
||||
@@ -11,7 +11,7 @@ private let dataImage = Re(#"^data:image/(png|jpeg|gif|webp);"#, caseless: true)
|
||||
private let fileURL = Re(#"^file://"#, caseless: true)
|
||||
private let anyScheme = Re(#"^[a-z][a-z0-9+.-]*:"#, caseless: true)
|
||||
|
||||
func worktreeImageSource(_ path: String, _ taskId: String?, dir: String = "") -> ImageSource? {
|
||||
func worktreeImageSource(_ path: String, _ root: FileRoot?, dir: String = "") -> ImageSource? {
|
||||
if dataImage.test(path) {
|
||||
guard let comma = path.firstIndex(of: ","), path[..<comma].lowercased().hasSuffix(";base64"), let data = Data(base64Encoded: String(path[path.index(after: comma)...])) else {
|
||||
return nil
|
||||
@@ -29,10 +29,10 @@ func worktreeImageSource(_ path: String, _ taskId: String?, dir: String = "") ->
|
||||
} else if !dir.isEmpty && !file.hasPrefix("/") {
|
||||
file = "\(dir)/\(file)"
|
||||
}
|
||||
guard let taskId else {
|
||||
guard let root else {
|
||||
return nil
|
||||
}
|
||||
return .worktree(taskId: taskId, path: file)
|
||||
return .file(root, path: file)
|
||||
}
|
||||
|
||||
@MainActor
|
||||
@@ -76,11 +76,16 @@ final class ImageCache {
|
||||
case .png(let b), .jpeg(let b), .imageGif(let b), .imageWebp(let b): b
|
||||
}
|
||||
return try await Data(collecting: body, upTo: 32 << 20)
|
||||
case .worktree(let taskId, let path):
|
||||
case .file(.task(let taskId), let path):
|
||||
let body = switch try await api.client.getTaskImage(path: .init(taskId: taskId), query: .init(path: path)).ok.body {
|
||||
case .png(let b), .jpeg(let b), .imageGif(let b), .imageWebp(let b), .imageSvgXml(let b): b
|
||||
}
|
||||
return try await Data(collecting: body, upTo: 32 << 20)
|
||||
case .file(.project(let projectId), let path):
|
||||
let body = switch try await api.client.getProjectImage(path: .init(projectId: projectId), query: .init(path: path)).ok.body {
|
||||
case .png(let b), .jpeg(let b), .imageGif(let b), .imageWebp(let b), .imageSvgXml(let b): b
|
||||
}
|
||||
return try await Data(collecting: body, upTo: 32 << 20)
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user