Add a Files tab to the project page

This commit is contained in:
Ian Gulliver
2026-10-22 19:17:08 -07:00
parent 2aba745531
commit d8ce1cee41
12 changed files with 769 additions and 437 deletions
+10 -5
View File
@@ -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)
}
}
}