FaceRecognizeAPI.swift 1.5 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768
  1. //
  2. // FaceRecognizeAPI.swift
  3. // O2Platform
  4. //
  5. // Created by FancyLou on 2018/10/17.
  6. // Copyright © 2018 zoneland. All rights reserved.
  7. //
  8. import Moya
  9. enum FaceRecognizeAPI {
  10. case search(UIImage, String)
  11. }
  12. extension FaceRecognizeAPI: OOAPIContextCapable {
  13. var apiContextKey: String {
  14. return "x_faceset_control"
  15. }
  16. }
  17. // MARK: - 是否需要加入x-token访问头
  18. extension FaceRecognizeAPI:OOAccessTokenAuthorizable {
  19. public var shouldAuthorize: Bool {
  20. return false
  21. }
  22. }
  23. extension FaceRecognizeAPI: TargetType {
  24. var baseURL: URL {
  25. let webhost = O2AuthSDK.shared.centerServerInfo()?.webServer?.host
  26. let baseURLString = "http://\(webhost ?? "dev.o2oa.net"):8888/\(apiContextKey)"
  27. return URL(string: baseURLString)!
  28. }
  29. var path: String {
  30. switch self {
  31. case .search(_, let faceSet):
  32. return "/search/\(faceSet)"
  33. }
  34. }
  35. var method: Moya.Method {
  36. switch self {
  37. case .search(_, _):
  38. return .post
  39. }
  40. }
  41. var sampleData: Data {
  42. return "".data(using: String.Encoding.utf8)!
  43. }
  44. var task: Task {
  45. switch self {
  46. case .search(let image, _):
  47. let data = image.pngData()
  48. let formData = MultipartFormData(provider: .data(data!), name: "file",
  49. fileName: "face.png", mimeType: "image/png")
  50. return .uploadMultipart([formData])
  51. }
  52. }
  53. var headers: [String : String]? {
  54. return nil
  55. }
  56. }