Add global _apiAddress var + reformat

This commit is contained in:
Szymon Parafiński 2023-02-01 01:10:34 +01:00
parent e163d25776
commit b3724c49f4

View File

@ -9,8 +9,10 @@ import Foundation
import Alamofire import Alamofire
import SwiftUI import SwiftUI
private let _apiAddress_ = "http://127.0.0.1:5000"
let evaluators:[String:ServerTrustEvaluating]=[ let evaluators:[String:ServerTrustEvaluating]=[
"http://192.168.5.129:8080":DisabledTrustEvaluator() _apiAddress_:DisabledTrustEvaluator()
] ]
let manager=ServerTrustManager(evaluators: evaluators) let manager=ServerTrustManager(evaluators: evaluators)
let session=Session.init(serverTrustManager:manager) let session=Session.init(serverTrustManager:manager)
@ -18,7 +20,8 @@ let session=Session.init(serverTrustManager:manager)
class Api { class Api {
func getResponse(completion: @escaping(Bool?) -> Void) { func getResponse(completion: @escaping(Bool?) -> Void) {
session.request("http://192.168.5.129:8080/test",method:.get, encoding: JSONEncoding.default).response { response in let endpointAddress = _apiAddress_ + "/test"
session.request(endpointAddress, method:.get, encoding: JSONEncoding.default).response { response in
switch response.result { switch response.result {
case.success: case.success:
if response.response?.statusCode == 200 { if response.response?.statusCode == 200 {
@ -40,9 +43,10 @@ class Api {
} }
func getImageResponse(image: String, completion: @escaping(Bool?) -> Void) { func getImageResponse(image: String, completion: @escaping(Bool?) -> Void) {
let endpointAddress = _apiAddress_ + "/detectLicense"
let parameters = ["imageFile": image] as [String : Any] let parameters = ["imageFile": image] as [String : Any]
session.request("http://192.168.5.129:8080/detectLicense", method: .post, parameters: parameters as Parameters, encoding: JSONEncoding.default, headers: nil) session.request(endpointAddress, method: .post, parameters: parameters as Parameters, encoding: JSONEncoding.default, headers: nil)
.response { response in .response { response in
switch response.result { switch response.result {
case.success: case.success:
@ -89,9 +93,10 @@ class Api {
} }
func getPlatsNumberResponse(image: String, completion: @escaping(Bool?) -> Void) { func getPlatsNumberResponse(image: String, completion: @escaping(Bool?) -> Void) {
let endpointAddress = _apiAddress_ + "/getPlatesNumber"
let parameters = ["imageFile": image] as [String : Any] let parameters = ["imageFile": image] as [String : Any]
session.request("http://192.168.5.129:8080/getPlatesNumber", method: .post, parameters: parameters as Parameters, encoding: JSONEncoding.default, headers: nil) session.request(endpointAddress, method: .post, parameters: parameters as Parameters, encoding: JSONEncoding.default, headers: nil)
.response { response in .response { response in
switch response.result { switch response.result {
case.success: case.success:
@ -130,9 +135,9 @@ class Api {
} }
extension String { extension String {
var fixedBase64Format: Self { var fixedBase64Format: Self {
let offset = count % 4 let offset = count % 4
guard offset != 0 else { return self } guard offset != 0 else { return self }
return padding(toLength: count + 4 - offset, withPad: "=", startingAt: 0) return padding(toLength: count + 4 - offset, withPad: "=", startingAt: 0)
} }
} }