2022-01-04 22:28:18 +08:00
|
|
|
|
//
|
|
|
|
|
// PushDeerApi.swift
|
|
|
|
|
// PushDeer
|
|
|
|
|
//
|
|
|
|
|
// Created by HEXT on 2022/1/4.
|
|
|
|
|
//
|
|
|
|
|
|
|
|
|
|
import Foundation
|
|
|
|
|
import Moya
|
|
|
|
|
|
|
|
|
|
enum PushDeerApi {
|
|
|
|
|
|
|
|
|
|
case fake
|
2022-02-27 23:02:58 +08:00
|
|
|
|
/// 通过苹果 idToken 登入
|
2022-01-04 22:28:18 +08:00
|
|
|
|
case login(idToken: String)
|
2022-02-27 23:02:58 +08:00
|
|
|
|
/// 通过微信 oauth code 登入
|
|
|
|
|
case wechatLogin(code: String)
|
|
|
|
|
/// 合并用户并将旧用户删除
|
|
|
|
|
/// | 参数 | 说明 |
|
|
|
|
|
/// | - | - |
|
|
|
|
|
/// | token | 认证token |
|
|
|
|
|
/// | type | 字符串,必须为 apple 或者 wechat |
|
|
|
|
|
/// | tokenorcode | type 为 apple时此字段为 idToken,否则为 微信code |
|
|
|
|
|
case mergeUser(token: String, type: String, tokenorcode: String)
|
2022-01-10 00:26:29 +08:00
|
|
|
|
case getUserInfo(token: String)
|
2022-01-04 22:28:18 +08:00
|
|
|
|
|
|
|
|
|
case regDevice(token: String, name: String, device_id: String, is_clip: Int)
|
2022-01-15 22:13:23 +08:00
|
|
|
|
case renameDevice(token: String, id: Int, name: String)
|
2022-01-04 22:28:18 +08:00
|
|
|
|
case getDevices(token: String)
|
|
|
|
|
case rmDevice(token: String, id: Int)
|
|
|
|
|
|
|
|
|
|
case genKey(token: String)
|
|
|
|
|
case regenKey(token: String, id: Int)
|
|
|
|
|
case renameKey(token: String, id: Int, name: String)
|
|
|
|
|
case getKeys(token: String)
|
|
|
|
|
case rmKey(token: String, id: Int)
|
|
|
|
|
|
|
|
|
|
/// type: 文本=text,markdown,图片=image,默认为markdown
|
|
|
|
|
case push(pushkey: String, text: String, desp: String, type: String)
|
|
|
|
|
|
|
|
|
|
case getMessages(token: String, limit: Int)
|
|
|
|
|
case rmMessage(token: String, id: Int)
|
2022-04-19 00:35:56 +08:00
|
|
|
|
case rmAllMessage(token: String)
|
2022-01-04 22:28:18 +08:00
|
|
|
|
|
2022-09-14 00:14:19 +08:00
|
|
|
|
case stokenLogin(stoken: String)
|
|
|
|
|
case stokenRegen(token: String)
|
|
|
|
|
case stokenRemove(token: String)
|
2022-01-04 22:28:18 +08:00
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
extension PushDeerApi: TargetType {
|
2022-02-14 01:13:26 +08:00
|
|
|
|
var baseURL: URL {
|
|
|
|
|
var urlStr = Env.onlineApiEndpoint
|
|
|
|
|
if Env.isSelfHosted && !AppState.shared.api_endpoint.isEmpty {
|
|
|
|
|
urlStr = AppState.shared.api_endpoint
|
|
|
|
|
}
|
|
|
|
|
return URL(string: urlStr)!
|
|
|
|
|
}
|
2022-01-04 22:28:18 +08:00
|
|
|
|
var path: String {
|
|
|
|
|
switch self {
|
|
|
|
|
case .fake:
|
|
|
|
|
return "/login/fake"
|
|
|
|
|
case .login:
|
|
|
|
|
return "/login/idtoken"
|
2022-02-27 23:02:58 +08:00
|
|
|
|
case .wechatLogin:
|
|
|
|
|
return "/login/wecode"
|
|
|
|
|
case .mergeUser:
|
|
|
|
|
return "/user/merge"
|
2022-01-10 00:26:29 +08:00
|
|
|
|
case .getUserInfo:
|
|
|
|
|
return "/user/info"
|
2022-01-04 22:28:18 +08:00
|
|
|
|
|
|
|
|
|
case .regDevice:
|
|
|
|
|
return "/device/reg"
|
2022-01-15 22:13:23 +08:00
|
|
|
|
case .renameDevice:
|
|
|
|
|
return "/device/rename"
|
2022-01-04 22:28:18 +08:00
|
|
|
|
case .getDevices:
|
|
|
|
|
return "/device/list"
|
|
|
|
|
case .rmDevice:
|
|
|
|
|
return "/device/remove"
|
|
|
|
|
|
|
|
|
|
case .genKey:
|
|
|
|
|
return "/key/gen"
|
|
|
|
|
case .regenKey:
|
|
|
|
|
return "/key/regen"
|
|
|
|
|
case .renameKey:
|
|
|
|
|
return "/key/rename"
|
|
|
|
|
case .getKeys:
|
|
|
|
|
return "/key/list"
|
|
|
|
|
case .rmKey:
|
|
|
|
|
return "/key/remove"
|
|
|
|
|
|
|
|
|
|
case .push:
|
|
|
|
|
return "/message/push"
|
|
|
|
|
|
|
|
|
|
case .getMessages:
|
|
|
|
|
return "/message/list"
|
|
|
|
|
case .rmMessage:
|
|
|
|
|
return "/message/remove"
|
2022-04-19 00:35:56 +08:00
|
|
|
|
case .rmAllMessage:
|
|
|
|
|
return "/message/clean"
|
2022-09-14 00:14:19 +08:00
|
|
|
|
|
|
|
|
|
case .stokenLogin:
|
|
|
|
|
return "/login/simple_token"
|
|
|
|
|
case .stokenRegen:
|
|
|
|
|
return "/simple_token/regen"
|
|
|
|
|
case .stokenRemove:
|
|
|
|
|
return "/simple_token/remove"
|
2022-01-04 22:28:18 +08:00
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
var method: Moya.Method {
|
|
|
|
|
switch self {
|
|
|
|
|
default:
|
|
|
|
|
return .post
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
var task: Task {
|
|
|
|
|
switch self {
|
|
|
|
|
case .fake:
|
|
|
|
|
return .requestParameters(parameters: [:], encoding: URLEncoding.queryString)
|
|
|
|
|
case let .login(idToken):
|
|
|
|
|
return .requestParameters(parameters: ["idToken": idToken], encoding: URLEncoding.queryString)
|
2022-02-27 23:02:58 +08:00
|
|
|
|
case let .wechatLogin(code):
|
|
|
|
|
return .requestParameters(parameters: ["code": code], encoding: URLEncoding.queryString)
|
|
|
|
|
case let .mergeUser(token, type, tokenorcode):
|
|
|
|
|
return .requestParameters(parameters: ["token": token, "type": type, "tokenorcode": tokenorcode], encoding: URLEncoding.queryString)
|
2022-01-10 00:26:29 +08:00
|
|
|
|
case let .getUserInfo(token):
|
|
|
|
|
return .requestParameters(parameters: ["token": token], encoding: URLEncoding.queryString)
|
2022-01-04 22:28:18 +08:00
|
|
|
|
|
|
|
|
|
case let .regDevice(token, name, device_id, is_clip):
|
|
|
|
|
return .requestParameters(parameters: ["token": token,"name": name, "device_id": device_id,"is_clip": is_clip], encoding: URLEncoding.queryString)
|
2022-01-15 22:13:23 +08:00
|
|
|
|
case let .renameDevice(token, id, name):
|
|
|
|
|
return .requestParameters(parameters: ["token": token,"id": id,"name": name], encoding: URLEncoding.queryString)
|
2022-01-04 22:28:18 +08:00
|
|
|
|
case let .getDevices(token):
|
|
|
|
|
return .requestParameters(parameters: ["token": token], encoding: URLEncoding.queryString)
|
|
|
|
|
case let .rmDevice(token, id):
|
|
|
|
|
return .requestParameters(parameters: ["token": token,"id": id], encoding: URLEncoding.queryString)
|
|
|
|
|
|
|
|
|
|
case let .genKey(token):
|
|
|
|
|
return .requestParameters(parameters: ["token": token], encoding: URLEncoding.queryString)
|
|
|
|
|
case let .regenKey(token, id):
|
|
|
|
|
return .requestParameters(parameters: ["token": token,"id": id], encoding: URLEncoding.queryString)
|
|
|
|
|
case let .renameKey(token, id, name):
|
|
|
|
|
return .requestParameters(parameters: ["token": token,"id": id,"name": name], encoding: URLEncoding.queryString)
|
|
|
|
|
case let .getKeys(token):
|
|
|
|
|
return .requestParameters(parameters: ["token": token],encoding: URLEncoding.queryString)
|
|
|
|
|
case let .rmKey(token, id):
|
|
|
|
|
return .requestParameters(parameters: ["token": token, "id": id],encoding: URLEncoding.queryString)
|
|
|
|
|
|
|
|
|
|
case let .push(pushkey, text, desp, type):
|
|
|
|
|
return .requestParameters(parameters: ["pushkey": pushkey, "text": text, "desp": desp, "type": type],encoding: URLEncoding.queryString)
|
|
|
|
|
|
|
|
|
|
case let .getMessages(token, limit):
|
|
|
|
|
return .requestParameters(parameters: ["token": token, "limit": limit],encoding: URLEncoding.queryString)
|
|
|
|
|
case let .rmMessage(token, id):
|
|
|
|
|
return .requestParameters(parameters: ["token": token, "id": id],encoding: URLEncoding.queryString)
|
2022-04-19 00:35:56 +08:00
|
|
|
|
case let .rmAllMessage(token):
|
|
|
|
|
return .requestParameters(parameters: ["token": token],encoding: URLEncoding.queryString)
|
2022-01-04 22:28:18 +08:00
|
|
|
|
|
2022-09-14 00:14:19 +08:00
|
|
|
|
case let .stokenLogin(stoken):
|
|
|
|
|
return .requestParameters(parameters: ["stoken": stoken],encoding: URLEncoding.queryString)
|
|
|
|
|
case let .stokenRegen(token):
|
|
|
|
|
return .requestParameters(parameters: ["token": token],encoding: URLEncoding.queryString)
|
|
|
|
|
case let .stokenRemove(token):
|
|
|
|
|
return .requestParameters(parameters: ["token": token],encoding: URLEncoding.queryString)
|
2022-01-04 22:28:18 +08:00
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
var headers: [String: String]? {
|
|
|
|
|
return ["Content-type": "application/json"]
|
|
|
|
|
}
|
|
|
|
|
}
|