Jul 14 - Using CDN - update

This commit is contained in:
Nguyen Ngo
2026-07-14 15:40:16 -04:00
parent 6fbd3d1437
commit 2a0b264a5c
8 changed files with 162 additions and 49 deletions
+13 -4
View File
@@ -497,9 +497,13 @@ struct IssueDetailView: View {
// Resolution Photos (server-side, read display)
if !issue.resultPhotoServerPaths.isEmpty {
Section("Resolution Photos (\(issue.resultPhotoServerPaths.count))") {
ForEach(issue.resultPhotoServerPaths, id: \.self) { relativePath in
let paths = issue.resultPhotoServerPaths
let urls = issue.resultPhotoServerUrls
ForEach(paths.indices, id: \.self) { idx in
RetryablePhotoView(
url: URL(string: ServerConfig.current + "/static/" + relativePath)
url: ServerConfig.mediaURL(
absolute: idx < urls.count ? urls[idx] : nil,
path: paths[idx])
)
}
}
@@ -571,9 +575,13 @@ struct IssueDetailView: View {
// Synced: show server photos only
if !issue.photoServerPaths.isEmpty {
Section("Photos (\(issue.photoServerPaths.count))") {
ForEach(issue.photoServerPaths, id: \.self) { relativePath in
let paths = issue.photoServerPaths
let urls = issue.photoServerUrls
ForEach(paths.indices, id: \.self) { idx in
RetryablePhotoView(
url: URL(string: ServerConfig.current + "/static/" + relativePath)
url: ServerConfig.mediaURL(
absolute: idx < urls.count ? urls[idx] : nil,
path: paths[idx])
)
}
}
@@ -748,6 +756,7 @@ struct IssueDetailView: View {
// Refresh resolution photos from server
if !detail.resultPhotos.isEmpty {
issue.resultPhotoServerPaths = detail.resultPhotos
issue.resultPhotoServerUrls = detail.resultPhotoUrls
}
try? context.save()
} catch {
@@ -452,6 +452,7 @@ struct HistoryDetailView: View {
schema: formSchema,
formValues: savedValues
)
.environment(\.mediaURLByPath, inspection.mediaURLByPath)
.padding(.horizontal, 24)
}
}
@@ -928,6 +929,7 @@ struct ReadOnlyCellView: View {
struct PhotoThumbnailView: View {
let value: String
@Environment(\.mediaURLByPath) private var mediaURLByPath
@State private var showLightbox = false
var body: some View {
@@ -954,7 +956,7 @@ struct PhotoThumbnailView: View {
.font(.system(size: 11)).foregroundStyle(.secondary)
}
} else if value.hasPrefix("uploads/") {
let url = URL(string: "\(ServerConfig.current)/static/\(value)")
let url = ServerConfig.mediaURL(absolute: mediaURLByPath[value], path: value)
thumbnailButton {
AsyncImage(url: url) { phase in
switch phase {
@@ -1042,3 +1044,19 @@ struct MailComposeView: UIViewControllerRepresentable {
}
}
}
// MARK: - Media URL environment
// Injects a {relative_path: absolute_url} map (from APIInspectionSummary.mediaURLByPath)
// so image cells deep inside the read-only grid can resolve presigned R2 URLs
// without threading field IDs through every layer. Empty map the resolver
// falls back to building a /static/ URL from the relative path.
private struct MediaURLByPathKey: EnvironmentKey {
static let defaultValue: [String: String] = [:]
}
extension EnvironmentValues {
var mediaURLByPath: [String: String] {
get { self[MediaURLByPathKey.self] }
set { self[MediaURLByPathKey.self] = newValue }
}
}