Simplify EzServer menu and serve original Web Console
This commit is contained in:
1 parent
ee7e18490f
commit
d748f7cc69
16 files changed
+290
-245
No files matched your search
@@ -6,7 +6,7 @@ struct ServerConfiguration {
|
||||
let token: String
|
||||
let port: UInt16
|
||||
|
||||
init(environment: [String: String] = ProcessInfo.processInfo.environment) throws {
|
||||
init(environment: [String: String] = ProcessInfo.processInfo.environment, imagesParent: URL? = nil) throws {
|
||||
let rawPort = environment["EZSERVER_PORT"] ?? "55005"
|
||||
guard let port = UInt16(rawPort), port > 0 else { throw Failure.invalidPort }
|
||||
self.port = port
|
||||
@@ -17,7 +17,20 @@ struct ServerConfiguration {
|
||||
} else {
|
||||
directory = URL.applicationSupportDirectory.appendingPathComponent("EzServerMac", isDirectory: true)
|
||||
}
|
||||
store = try ServerStore(directory: directory.resolvingSymlinksInPath())
|
||||
let imageStorage: URL?
|
||||
if let path = environment["EZSERVER_IMAGES_PARENT"] {
|
||||
guard path.hasPrefix("/") else { throw Failure.invalidImageDirectory }
|
||||
imageStorage = URL(fileURLWithPath: path, isDirectory: true)
|
||||
} else if let imagesParent {
|
||||
imageStorage = imagesParent
|
||||
} else if environment["EZSERVER_DATA"] == nil,
|
||||
let saved = UserDefaults.standard.string(forKey: "imagesParent") {
|
||||
imageStorage = URL(fileURLWithPath: saved, isDirectory: true)
|
||||
} else {
|
||||
imageStorage = nil
|
||||
}
|
||||
store = try ServerStore(directory: directory.resolvingSymlinksInPath(),
|
||||
imagesParent: imageStorage?.resolvingSymlinksInPath())
|
||||
|
||||
if let configured = environment["EZSERVER_TOKEN"] {
|
||||
guard Self.valid(configured) else { throw Failure.invalidToken }
|
||||
@@ -63,11 +76,12 @@ struct ServerConfiguration {
|
||||
}
|
||||
|
||||
private enum Failure: LocalizedError {
|
||||
case invalidPort, invalidDirectory, invalidToken
|
||||
case invalidPort, invalidDirectory, invalidImageDirectory, invalidToken
|
||||
var errorDescription: String? {
|
||||
switch self {
|
||||
case .invalidPort: return "EZSERVER_PORT должен быть числом от 1 до 65535."
|
||||
case .invalidDirectory: return "Укажите абсолютный путь в EZSERVER_DATA."
|
||||
case .invalidImageDirectory: return "Укажите абсолютный путь в EZSERVER_IMAGES_PARENT."
|
||||
case .invalidToken: return "Токен должен содержать от 32 до 1024 печатных ASCII-символов."
|
||||
}
|
||||
}
|
||||
|
||||
Reference in new issue
Block a user