Consider it done. The open-source AI agent that works out of the box · 想到,就能做到。开源、开箱即用的 AI Agent。
TypeScript agentai-agentai-assistantandroidclaude-codecodexelectroniosllmmacosreact-nativetypescriptwindows
fix(mobile): decode shared file URL data and raw image types
Chris64155643b514
diff --git a/apps/mobile/docs/incoming-sharing.md b/apps/mobile/docs/incoming-sharing.mdindex bf64be7b53..9d86f3b2a6 100644--- a/apps/mobile/docs/incoming-sharing.md+++ b/apps/mobile/docs/incoming-sharing.md@@ -43,7 +43,9 @@ new sending privileges: normal conversation hydration and authorization still apformats need no extension allowlist.File-URL classification uses the original file's UTI or image header, never aprovider-wide thumbnail. Unknown extensionless documents remain original files;- actual extensionless raster images retain image processing.+ actual extensionless raster images retain image processing. File URLs exported+ as UTF-8 data are decoded and copied within the provider callback. Unnamed+ abstract image data uses its actual image header for extension and MIME.- `plugins/with-incoming-share-formats.js`: generated Expo controller integration.Checked patch anchors fail prebuild if the upstream template changes.- `fingerprint.config.cjs`: explicitly hashes the share extension's Swift, stringsdiff --git a/apps/mobile/plugins/incoming-share-formats.swift b/apps/mobile/plugins/incoming-share-formats.swiftindex 829f67d38a..274f887905 100644--- a/apps/mobile/plugins/incoming-share-formats.swift+++ b/apps/mobile/plugins/incoming-share-formats.swift@@ -88,7 +88,11 @@await withCheckedContinuation { continuation inprovider.loadItem(forTypeIdentifier: identifier, options: nil) { value, _ in// URL lifetime belongs to this callback, including loadItem fallbacks.- if let url = value as? URL {+ // Only an explicitly advertised file-URL representation grants a data+ // value URL semantics; ordinary file/image bytes are never paths.+ let encodedURL = identifier == UTType.fileURL.identifier+ ? (value as? Data).flatMap { String(data: $0, encoding: .utf8) }.flatMap(URL.init(string:)) : nil+ if let url = (value as? URL) ?? encodedURL {continuation.resume(returning: self.copyAndProcessFile(url: url, type: kind ?? self.fileShareType(url)))return}@@ -97,7 +101,13 @@return}let isRenderedImage = value is UIImage- let type = isRenderedImage ? UTType.png : UTType(identifier)+ var type = isRenderedImage ? UTType.png : UTType(identifier)+ if !isRenderedImage, identifier == UTType.image.identifier,+ let source = CGImageSourceCreateWithData(data as CFData, [kCGImageSourceShouldCache: false] as CFDictionary),+ let identifier = CGImageSourceGetType(source),+ let imageType = UTType(identifier as String), imageType.conforms(to: .image) {+ type = imageType+ }let ext = type?.preferredFilenameExtension ?? "bin"let suggested = provider.suggestedName.map { URL(fileURLWithPath: $0).lastPathComponent } ?? UUID().uuidStringlet name = suggested.isEmpty || suggested == "." || suggested == ".." ? UUID().uuidString : suggesteddiff --git a/apps/mobile/scripts/test-incoming-share-formats.mjs b/apps/mobile/scripts/test-incoming-share-formats.mjsindex fb51c65bbf..fa7797a8e9 100644--- a/apps/mobile/scripts/test-incoming-share-formats.mjs+++ b/apps/mobile/scripts/test-incoming-share-formats.mjs@@ -20,9 +20,11 @@ let NSExtensionJavaScriptPreprocessingResultsKey = "NSExtensionJavaScriptPreprocclass UIImage: NSObject { func pngData() -> Data? { nil } }final class EphemeralProvider: NSItemProvider {var url: URL!+ var encodedURL = falseoverride func loadItem(forTypeIdentifier identifier: String, options: [AnyHashable: Any]? = nil, completionHandler: NSItemProvider.CompletionHandler? = nil) {Thread.current.threadDictionary["owning-provider-callback"] = true- completionHandler?(url as NSURL, nil)+ let value: NSSecureCoding = encodedURL ? NSData(data: Data(url.absoluteString.utf8)) : url as NSURL+ completionHandler?(value, nil)Thread.current.threadDictionary.removeObject(forKey: "owning-provider-callback")try? FileManager.default.removeItem(at: url)}@@ -52,9 +54,47 @@ final class Adapter {try! FileManager.default.createDirectory(at: root, withIntermediateDirectories: true)defer { try? FileManager.default.removeItem(at: root) }let adapter = Adapter()+ let selected = CommandLine.arguments[2]// The file URL owns the bytes; a separate image representation may be only// its thumbnail. Extensionless originals must not inherit that preview type.let png = Data(base64Encoded: "iVBORw0KGgoAAAANSUhEUgAAAAEAAAABCAQAAAC1HAwCAAAAC0lEQVR42mP8/x8AAwMCAO+jRZkAAAAASUVORK5CYII=")!+ if selected != "raw-image" {+ let url = root.appendingPathComponent("data encoded document.pdf")+ let bytes = Data("original file URL document".utf8)+ try! bytes.write(to: url)+ let provider = NSItemProvider()+ provider.registerDataRepresentation(forTypeIdentifier: UTType.fileURL.identifier, visibility: .all) { done in+ done(Data(url.absoluteString.utf8), nil); return nil+ }+ guard let payload = await adapter.parse(provider), payload.type == .file,+ let result = URL(string: payload.value) else { fatalError("Missing Data-encoded file URL") }+ precondition(result.lastPathComponent == url.lastPathComponent && (try! Data(contentsOf: result)) == bytes)+ let ephemeral = EphemeralProvider()+ ephemeral.url = url; ephemeral.encodedURL = true+ ephemeral.registerItem(forTypeIdentifier: UTType.fileURL.identifier, loadHandler: { _, _, _ in })+ adapter.requireProviderCallback = true+ guard let copied = await adapter.parse(ephemeral), let copy = URL(string: copied.value) else { fatalError("Missing temporary Data-encoded file URL") }+ precondition(try! Data(contentsOf: copy) == bytes)+ precondition(!FileManager.default.fileExists(atPath: url.path))+ adapter.requireProviderCallback = false+ print("PASS: Data-encoded file URLs preserve originals within provider callbacks")+ }+ if selected != "data-file-url" {+ let gif = Data(base64Encoded: "R0lGODlhAQABAIAAAAAAAP///yH5BAEAAAAALAAAAAABAAEAAAIBRAA7")!+ for (bytes, type) in [(png, UTType.png), (gif, UTType.gif)] {+ let provider = NSItemProvider()+ provider.registerDataRepresentation(forTypeIdentifier: UTType.image.identifier, visibility: .all) { done in+ done(bytes, nil); return nil+ }+ precondition(provider.suggestedName == nil)+ guard let payload = await adapter.parse(provider), payload.type == .image,+ let result = URL(string: payload.value) else { fatalError("Missing abstract image data") }+ precondition(result.pathExtension == type.preferredFilenameExtension && payload.mimeType == type.preferredMIMEType,+ "Abstract image bytes lost their concrete format")+ precondition(try! Data(contentsOf: result) == bytes)+ }+ print("PASS: unnamed abstract image bytes preserve concrete extensions and MIME")+ }for (name, bytes, kind) in [("extensionless-document", Data("original document bytes".utf8), ShareType.file),("extensionless-image", png, ShareType.image)] {let url = root.appendingPathComponent(name)@@ -142,7 +182,6 @@ final class Adapter {precondition(try! Data(contentsOf: result) == bytes)}print("PASS: concrete images beat source URLs; abstract thumbnails remain previews")- let selected = CommandLine.arguments[2]let link = NSItemProvider()let sharedURL = URL(string: "https://example.com/shared-page?source=provider")!link.registerDataRepresentation(forTypeIdentifier: UTType.image.identifier, visibility: .all) { done indiff --git a/apps/mobile/src/__tests__/incomingShareNativePlugin.test.ts b/apps/mobile/src/__tests__/incomingShareNativePlugin.test.tsindex 28bc5c4c27..4ac0b267de 100644--- a/apps/mobile/src/__tests__/incomingShareNativePlugin.test.ts+++ b/apps/mobile/src/__tests__/incomingShareNativePlugin.test.ts@@ -159,6 +159,8 @@ it("preserves original exports ahead of previews and copies temporary URLs withiexpect(result.stdout).toContain("PASS: concrete images beat source URLs; abstract thumbnails remain previews");expect(result.stdout).toContain("PASS: unreadable account-boundary fence survives process restart and recovery");expect(result.stdout).toContain("PASS: failed rejection removal retains retry state until durable recovery");+ expect(result.stdout).toContain("PASS: Data-encoded file URLs preserve originals within provider callbacks");+ expect(result.stdout).toContain("PASS: unnamed abstract image bytes preserve concrete extensions and MIME");expect(result.stdout).toContain("PASS: temporary file URL copied inside provider callback");expect(result.stdout).toContain("PASS: durable exact-snapshot rejection, retry and replacement");}, 180_000);