Skip to content

Commit

Permalink
Rename class.
Browse files Browse the repository at this point in the history
  • Loading branch information
yangziy committed Sep 27, 2018
1 parent ab83f45 commit cfe134f
Showing 1 changed file with 22 additions and 22 deletions.
44 changes: 22 additions & 22 deletions ShadowsocksX-NG/HTTPUserProxy.swift
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,7 @@ import GCDWebServer
class HTTPUserProxy{
static let shard = HTTPUserProxy()

let adapter = APIAdapter()
let app = AppFacade()

let server = GCDWebServer()
let api_port:UInt = 9528
Expand Down Expand Up @@ -55,20 +55,20 @@ class HTTPUserProxy{

func addHandler_getStatus() {
server.addHandler(forMethod: "GET", path: "/status", request: GCDWebServerRequest.self, processBlock: {request in
return GCDWebServerDataResponse(jsonObject: ["Enable":self.adapter.getStatus()], contentType: "json")
return GCDWebServerDataResponse(jsonObject: ["Enable":self.app.getStatus()], contentType: "json")
})
}

func addHandler_setStatus() {
server.addHandler(forMethod: "PUT", path: "/status", request: GCDWebServerURLEncodedFormRequest.self, processBlock: {request in
if let targetStatus_str = (request as? GCDWebServerURLEncodedFormRequest)?.arguments["Enable"] as? String{
if let targetStatus = Bool(targetStatus_str) {
self.adapter.setStatus(status: targetStatus)
self.app.setStatus(status: targetStatus)
return GCDWebServerResponse()
}
}
else {
self.adapter.toggleStatus()
self.app.toggleStatus()
return GCDWebServerResponse()
}
return GCDWebServerResponse(statusCode: 400)
Expand All @@ -77,14 +77,14 @@ class HTTPUserProxy{

func addHandler_getServerList() {
server.addHandler(forMethod: "GET", path: "/servers", request: GCDWebServerRequest.self, processBlock: {request in
return GCDWebServerDataResponse(jsonObject: self.adapter.getServerList(), contentType: "json")
return GCDWebServerDataResponse(jsonObject: self.app.getServerList(), contentType: "json")
})
}

func addHandler_getCurrentServer() {
server.addHandler(forMethod: "GET", path: "/current", request: GCDWebServerRequest.self, processBlock: {request in
if let activeId = self.adapter.getCurrentServerId() {
return GCDWebServerDataResponse(jsonObject: self.adapter.getServer(uuid: activeId)!, contentType: "json")
if let activeId = self.app.getCurrentServerId() {
return GCDWebServerDataResponse(jsonObject: self.app.getServer(uuid: activeId)!, contentType: "json")
}
else {
return GCDWebServerResponse(statusCode: 404);
Expand All @@ -96,8 +96,8 @@ class HTTPUserProxy{
server.addHandler(forMethod: "PUT", path: "/current", request: GCDWebServerURLEncodedFormRequest.self, processBlock: {request in

if let targetId = (request as? GCDWebServerURLEncodedFormRequest)?.arguments["Id"] as? String{
if self.adapter.getServer(uuid: targetId) != nil {
self.adapter.setCurrentServer(uuid: targetId);
if self.app.getServer(uuid: targetId) != nil {
self.app.setCurrentServer(uuid: targetId);
return GCDWebServerResponse()
}
}
Expand All @@ -111,7 +111,7 @@ class HTTPUserProxy{
if (server["ServerPort"] != nil) {
server["ServerPort"] = UInt16(server["ServerPort"] as! String)
if (Validator.profile(server)) { // validate
self.adapter.addServer(server: server)
self.app.addServer(server: server)
return GCDWebServerResponse();
}
}
Expand All @@ -127,10 +127,10 @@ class HTTPUserProxy{
if (server["ServerPort"] != nil) {
server["ServerPort"] = UInt16(server["ServerPort"] as! String)
}
if (self.adapter.getServer(uuid: id) != nil) {
if (self.app.getServer(uuid: id) != nil) {
if (Validator.existAttributes(server)) {
if (self.adapter.getCurrentServerId() != id) {
self.adapter.modifyServer(uuid: id, server: server)
if (self.app.getCurrentServerId() != id) {
self.app.modifyServer(uuid: id, server: server)
return GCDWebServerResponse()
}
else {
Expand All @@ -149,9 +149,9 @@ class HTTPUserProxy{
server.addHandler(forMethod: "DELETE", pathRegex: "/servers/"+self.UUID_REGEX, request: GCDWebServerRequest.self
, processBlock: {request in
let id = String(request.path.dropFirst("/servers/".count))
if((self.adapter.getServer(uuid: id)) != nil) {
if (self.adapter.getCurrentServerId() != id) {
self.adapter.deleteServer(uuid: id)
if((self.app.getServer(uuid: id)) != nil) {
if (self.app.getCurrentServerId() != id) {
self.app.deleteServer(uuid: id)
return GCDWebServerResponse()
} else {
return GCDWebServerResponse(statusCode: 400)
Expand All @@ -165,15 +165,15 @@ class HTTPUserProxy{

func addHandler_getMode() {
server.addHandler(forMethod: "GET", path: "/mode", request: GCDWebServerRequest.self, processBlock: {request in
return GCDWebServerDataResponse(jsonObject: ["Mode":self.adapter.getMode().rawValue], contentType: "json")
return GCDWebServerDataResponse(jsonObject: ["Mode":self.app.getMode().rawValue], contentType: "json")
})
}

func addHandler_setMode() {
server.addHandler(forMethod: "PUT", path: "/mode", request: GCDWebServerURLEncodedFormRequest.self, processBlock: {request in
if let mode_str = (request as? GCDWebServerURLEncodedFormRequest)?.arguments["Mode"] as? String{
if let mode = ProxyType(rawValue: mode_str) {
self.adapter.setMode(mode: mode);
self.app.setMode(mode: mode);

return GCDWebServerResponse()
}
Expand All @@ -183,10 +183,10 @@ class HTTPUserProxy{
}
}

class APIAdapter {
let SerMgr = ServerProfileManager.instance
let defaults = UserDefaults.standard
let appdeleget = NSApplication.shared.delegate as! AppDelegate
class AppFacade {
private let SerMgr = ServerProfileManager.instance
private let defaults = UserDefaults.standard
private let appdeleget = NSApplication.shared.delegate as! AppDelegate

func getStatus()->Bool {
return self.defaults.bool(forKey: "ShadowsocksOn");
Expand Down

0 comments on commit cfe134f

Please sign in to comment.