Honestly, some of this formatting seems a little weird, but it appears to thread the needle between the competing requirements of swiftformat's wrapMultilineStatementBraces rule and SwiftLint's opening_brace rule.
Three main changes here:
- If a PDF isn't a local file, dont try to download and then
upload it to the backend. Just treat it as a URL.
- If we are passed PDF data by an app like Files, upload it.
- Wrap the whole operation in a Background task so its not
killed if the user taps dismiss during the upload of larger
documents.
This fixes issues where we'd incorrectly identify a PDF as HTML.
Safari will use our preprocess javascript file even if the
file is PDF, so we rely on JS to detect the content type here.