SPB Git

Repository Public License

MetadataView.swift 6.8 KB 160 lines swift

1// =============================================================================2//                  SP BOUCHER | SOFTWARE & RESEARCH3//             ARTIFICIAL INTELLIGENCE • FINANCE • ENGINEERING4// =============================================================================5//6// PROJECT METADATA7// -----------------------------------------------------------------------------8// Project          : ORIX Camera9// File             : App/Sources/Features/Library/MetadataView.swift10// Description      : Metadata inspector: what the file and the library really11//                    hold about an item, grouped, with a JSON report.12// Module           : Features13// Repository       : https://git.spboucher.ai/orix-camera14// Project Website  : https://www.orixlab.dev15// Created          : 2026-11-2116// Last Modified    : 2026-11-2117//18// =============================================================================19// AUTHOR & PROFESSIONAL AFFILIATION20// =============================================================================21//22// Author           : Simon-Pierre Boucher23// Position         : Professor of Finance24// Institution      : Université du Québec en Outaouais (UQO)25// Department       : Département des sciences administratives26// Organization     : SP Boucher27//28// Website          : https://spboucher.ai29// Git              : https://git.spboucher.ai30//31// =============================================================================32// OFFICIAL CONTACT DIRECTORY33// =============================================================================34//35// General          : info@spboucher.ai36// Professional     : contact@spboucher.ai37// Direct           : simon@spboucher.ai38// Research         : research@spboucher.ai39// Development      : dev@spboucher.ai40// Support          : support@spboucher.ai41// Security/Admin   : admin@spboucher.ai42// Notifications    : notifications@spboucher.ai43//44// Preferred Contact: support@spboucher.ai45//46// =============================================================================47// COPYRIGHT & INTELLECTUAL PROPERTY48// =============================================================================49//50// Copyright (c) 202651// Simon-Pierre Boucher52//53// All rights reserved where applicable.54//55// This file is governed by the applicable project license,56// copyright notices, institutional agreements and relevant law.57//58// Unless expressly authorized by the applicable license or59// rights holder, copying, redistribution, sublicensing,60// publication and commercial exploitation are not permitted.61//62// Existing third-party rights and notices remain unaffected.63//64// =============================================================================65// CONFIDENTIALITY & SECURITY66// =============================================================================67//68// Classification   : Public69// Distribution     : Public repository; use is governed by the project license70// Security Contact : admin@spboucher.ai71//72// Access to this source does not independently grant permission73// to redistribute or disclose confidential materials.74//75// Do not embed credentials, private keys, access tokens,76// certificates or confidential personal information.77//78// =============================================================================79// LICENSE & MAINTENANCE80// =============================================================================81//82// License          : Proprietary, all rights reserved (see license file)83// License File     : LICENSE84// Maintainer       : Simon-Pierre Boucher85// Technical Contact: dev@spboucher.ai86//87// =============================================================================88// END OF SP BOUCHER SOURCE HEADER89// =============================================================================9091import ORIXDesign92import ORIXImaging93import SwiftUI9495struct MetadataView: View {96    let item: ItemSnapshot97    let storage: CaptureStorage98    @Environment(\.dismiss) private var dismiss99    @State private var metadata: MediaMetadata?100    @State private var sections: [MetadataSection] = []101    @State private var loaded = false102    @State private var share: SharePayload?103    @State private var error: String?104105    var body: some View {106        NavigationStack {107            List {108                ForEach(sections) { section in109                    Section(section.title) {110                        ForEach(section.rows) { row in111                            LabeledContent(row.label) { Text(row.value).multilineTextAlignment(.trailing).textSelection(.enabled) }112                                .accessibilityElement(children: .combine)113                        }114                    }115                }116                if loaded {117                    Section {118                        Button { exportReport() } label: { Label("Export Metadata Report (JSON)", systemImage: "doc.text") }119                            .disabled(metadata == nil)120                            .accessibilityIdentifier("metadata.report")121                    } footer: {122                        Text(metadata?.hasLocation == true123                             ? "This file contains a location. The report includes it. Exports can remove it."124                             : "Only fields present in the file are listed. This file contains no location.")125                    }126                    if let error { Section { Text(error).foregroundStyle(ORIX.Palette.danger) } }127                } else {128                    ProgressView().frame(maxWidth: .infinity)129                }130            }131            .accessibilityIdentifier("metadata.list")132            .navigationTitle("Info")133            .navigationBarTitleDisplayMode(.inline)134            .toolbar { ToolbarItem(placement: .confirmationAction) { Button("Done") { dismiss() }.accessibilityIdentifier("metadata.done") } }135            .sheet(item: $share) { ShareSheet(items: $0.urls) }136            .task { await load() }137        }138        .presentationDetents([.medium, .large])139        .presentationBackground(Color(.systemGroupedBackground))140    }141142    private func load() async {143        let snapshot = item144        let result: (MediaMetadata?, MediaMetadata?) = await Task.detached(priority: .userInitiated) {145            let main = snapshot.isVideo ? await MetadataInspector.readVideo(url: snapshot.url) : MetadataInspector.readImage(url: snapshot.url)146            return (main, snapshot.companionURL.flatMap(MetadataInspector.readImage(url:)))147        }.value148        metadata = result.0149        sections = MetadataRows.sections(item: item, metadata: result.0, companion: result.1)150        loaded = true151    }152153    private func exportReport() {154        guard let metadata else { return }155        do { share = SharePayload(urls: [try MediaExport.metadataReport(metadata, name: item.baseName, directory: storage.exportDirectory)]) } catch {156            self.error = String(localized: "The report could not be written: \(error.localizedDescription)")157        }158    }159}160
Files main
Menu

Theme