1
1
mirror of https://github.com/qvacua/vimr.git synced 2024-11-28 11:35:35 +03:00
vimr/VimR/HttpServerService.swift

61 lines
1.2 KiB
Swift
Raw Normal View History

2017-01-25 00:39:19 +03:00
/**
* Tae Won Ha - http://taewon.de - @hataewon
* See LICENSE
*/
import Foundation
import Swifter
import RxSwift
protocol Service {
2017-02-03 00:39:05 +03:00
associatedtype Pair
2017-01-25 00:39:19 +03:00
2017-02-03 00:39:05 +03:00
func apply(_: Pair)
2017-01-25 00:39:19 +03:00
}
class HttpServerService: Service {
2017-02-03 00:39:05 +03:00
typealias Pair = StateActionPair<UuidState<MainWindow.State>, MainWindow.Action>
2017-01-25 00:39:19 +03:00
init(port: in_port_t) {
do {
try self.server.start(port)
NSLog("server started on http://localhost:\(port)")
self.server["/tools/preview/error"] = { r in .ok(.html("ERROR!")) }
self.server["/tools/preview/save-first"] = { r in .ok(.html("SAVE FIRST!")) }
self.server["/tools/preview/empty"] = { r in .ok(.html("NO PREVIEW!")) }
} catch {
NSLog("ERROR server could not be started on port \(port)")
}
}
2017-02-03 00:39:05 +03:00
func apply(_ pair: Pair) {
NSLog("!!!!!!!!!!!")
let uuid = pair.state.uuid
var state = pair.state.payload
switch pair.action {
case let .setCurrentBuffer(buffer):
guard let url = buffer.url else {
return
}
guard FileUtils.fileExists(at: url) else {
return
}
case .close:
return
default:
return
}
2017-01-25 00:39:19 +03:00
}
fileprivate let server = HttpServer()
}