Simplify EzServer menu and serve original Web Console

This commit is contained in:
SantaSpeen committed 2026-11-22 03:12:27 +03:00
1 parent ee7e18490f
commit d748f7cc69
16 files changed
+290 -245

No files matched your search

+21 -4
View File
@@ -5,17 +5,18 @@ import SQLite3
final class ServerStore {
let directory: URL
let database: URL
private let files: URL
let files: URL
private let pendingDeletes: URL
private let db: OpaquePointer
private let lock = NSRecursiveLock()
private static let transient = unsafeBitCast(-1, to: sqlite3_destructor_type.self)
init(directory: URL) throws {
init(directory: URL, imagesParent: URL? = nil) throws {
self.directory = directory
database = directory.appendingPathComponent("EzServer.sqlite3")
files = directory.appendingPathComponent("Files", isDirectory: true)
pendingDeletes = directory.appendingPathComponent("PendingDeletion", isDirectory: true)
let storage = imagesParent ?? directory
files = storage.appendingPathComponent("Files", isDirectory: true)
pendingDeletes = storage.appendingPathComponent("PendingDeletion", isDirectory: true)
try FileManager.default.createDirectory(at: directory, withIntermediateDirectories: true,
attributes: [.posixPermissions: 0o700])
try FileManager.default.createDirectory(at: files, withIntermediateDirectories: true,
@@ -60,6 +61,22 @@ final class ServerStore {
deinit { sqlite3_close(db) }
func copyImages(to parent: URL) throws {
lock.lock()
defer { lock.unlock() }
guard parent != files.deletingLastPathComponent() else { return }
let destination = parent.appendingPathComponent("Files", isDirectory: true)
let manager = FileManager.default
guard !manager.fileExists(atPath: destination.path),
!manager.fileExists(atPath: parent.appendingPathComponent("PendingDeletion").path) else {
throw CocoaError(.fileWriteFileExists, userInfo: [NSFilePathErrorKey: destination.path])
}
let stage = parent.appendingPathComponent(".EzServer-\(UUID().uuidString)", isDirectory: true)
defer { try? manager.removeItem(at: stage) }
try manager.copyItem(at: files, to: stage)
try manager.moveItem(at: stage, to: destination)
}
func patients() throws -> [PatientRecord] {
lock.lock()
defer { lock.unlock() }