Skip to content

Recognize shared remote file if PDF #1143

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 1 commit into from
Jun 30, 2025
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
12 changes: 6 additions & 6 deletions ZShare/ViewModels/ExtensionViewModel.swift
Original file line number Diff line number Diff line change
Expand Up @@ -522,8 +522,9 @@ final class ExtensionViewModel {
.disposed(by: self.disposeBag)
}

private func process(fileUrl url: URL) {
private func process(fileUrl url: URL, expectedAttachmentFilename: String? = nil) {
let filename = url.lastPathComponent
let expectedAttachmentFilename = expectedAttachmentFilename ?? filename
let tmpFile = Files.temporaryFile(ext: url.pathExtension)

copyFile(from: url.path, to: tmpFile)
Expand All @@ -542,7 +543,7 @@ final class ExtensionViewModel {
func updateState(with attachmentState: State.AttachmentState) {
var state = self.state
state.processedAttachment = .file(file: tmpFile, filename: filename)
state.expectedAttachment = (filename, tmpFile)
state.expectedAttachment = (expectedAttachmentFilename, tmpFile)
state.attachmentState = attachmentState
self.state = state
}
Expand Down Expand Up @@ -596,20 +597,19 @@ final class ExtensionViewModel {
.subscribe(onSuccess: { [weak self] _ in
guard let self = self else { return }

var state = self.state
if self.fileStorage.isPdf(file: file) {
DDLogInfo("ExtensionViewModel: downloaded pdf")
state.processedAttachment = .file(file: file, filename: filename)
state.attachmentState = .processed
process(fileUrl: file.createUrl(), expectedAttachmentFilename: filename)
} else {
DDLogInfo("ExtensionViewModel: downloaded unsupported file")
var state = self.state
state.processedAttachment = nil
state.attachmentState = .failed(.downloadedFileNotPdf)
state.expectedAttachment = nil
// Remove downloaded file, it won't be used anymore
try? self.fileStorage.remove(file)
self.state = state
}
self.state = state
}, onFailure: { [weak self] error in
DDLogError("ExtensionViewModel: could not download shared file - \(url.absoluteString) - \(error)")
self?.state.attachmentState = .failed(.downloadFailed)
Expand Down