-
Notifications
You must be signed in to change notification settings - Fork 285
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge branch 'add/magic-link-auth' into lantean/1605-invalid-link-alert
- Loading branch information
Showing
15 changed files
with
293 additions
and
81 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,51 @@ | ||
import Foundation | ||
import UniformTypeIdentifiers | ||
import CoreData | ||
|
||
public class RecoveryUnarchiver { | ||
private let fileManager: FileManager | ||
private let simperium: Simperium | ||
|
||
public init(fileManager: FileManager = .default, simperium: Simperium) { | ||
self.fileManager = fileManager | ||
self.simperium = simperium | ||
} | ||
|
||
// MARK: Restore | ||
// | ||
public func insertNotesFromRecoveryFilesIfNeeded() { | ||
guard let recoveryURL = fileManager.recoveryDirectoryURL(), | ||
let recoveryFiles = try? fileManager.contentsOfDirectory(at: recoveryURL, includingPropertiesForKeys: nil), | ||
!recoveryFiles.isEmpty else { | ||
return | ||
} | ||
|
||
recoveryFiles.forEach { url in | ||
insertNote(from: url) | ||
try? fileManager.removeItem(at: url) | ||
} | ||
} | ||
|
||
private func insertNote(from url: URL) { | ||
guard let data = fileManager.contents(atPath: url.path), | ||
let recoveredContent = String(data: data, encoding: .utf8), | ||
let note = simperium.notesBucket.insertNewObject() as? Note else { | ||
return | ||
} | ||
|
||
var content = Constants.recoveredContentHeader | ||
content += "\n\n" | ||
content += recoveredContent | ||
note.content = content | ||
|
||
note.modificationDate = Date() | ||
note.creationDate = Date() | ||
note.markdown = UserDefaults.standard.bool(forKey: .markdown) | ||
|
||
simperium.save() | ||
} | ||
} | ||
|
||
private struct Constants { | ||
static let recoveredContentHeader = NSLocalizedString("Recovered Note Cotent - ", comment: "Header to put on any files that need to be recovered") | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.