mirror of
https://github.com/permissionlesstech/bitchat.git
synced 2026-07-25 05:25:19 +00:00
Copy imported files before sending to preserve access
This commit is contained in:
@@ -2055,8 +2055,20 @@ private extension ContentView {
|
||||
}
|
||||
|
||||
func handleImportedFile(url: URL) async {
|
||||
await MainActor.run {
|
||||
viewModel.sendFileAttachment(from: url)
|
||||
do {
|
||||
let fileManager = FileManager.default
|
||||
let tempDir = fileManager.temporaryDirectory
|
||||
let fileName = url.lastPathComponent.isEmpty ? "attachment" : url.lastPathComponent
|
||||
let destination = tempDir.appendingPathComponent(UUID().uuidString + "_" + fileName)
|
||||
if fileManager.fileExists(atPath: destination.path) {
|
||||
try fileManager.removeItem(at: destination)
|
||||
}
|
||||
try fileManager.copyItem(at: url, to: destination)
|
||||
await MainActor.run {
|
||||
viewModel.sendFileAttachment(from: destination)
|
||||
}
|
||||
} catch {
|
||||
SecureLogger.error("File copy failed before send: \(error)", category: .session)
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
Reference in New Issue
Block a user