pushdeer/ios/PushDeer-iOS/PushDeer/Service/PushDeerApi.swift
hext d3050e154f 添加自建服务配置, 优化交互, 修复bug.
修改配置为pushdeer官方配置(包名,团队标识,api域名);
补充新添加的文字的英文翻译 (国际化);
设备和key是空列表时,加一个提示,让用户知道可以新增;
尝试解决列表删除项后UI偶尔没刷新的bug;
首次打开提示注册设备;
首次自动生成一个 key;
消息列表放到第一个位置;
推送测试时自动生成一个key;
后台进入前台后, 刷新本地消息列表;
键盘上方添加完成按钮, 用于收键盘;
发送推送测试后 自动收键盘;
及时清角标, 拯救强迫症;
为了保持一致, 设置页也改为可滑动;
添加SelfHosted配置, 可以直接一套代码跑出两种版本;
支持服务自建;
添加Env统一管理环境变量.
2022-02-14 01:13:26 +08:00

131 lines
4.2 KiB
Swift
Raw Blame History

This file contains ambiguous Unicode characters

This file contains Unicode characters that might be confused with other characters. If you think that this is intentional, you can safely ignore this warning. Use the Escape button to reveal them.

//
// PushDeerApi.swift
// PushDeer
//
// Created by HEXT on 2022/1/4.
//
import Foundation
import Moya
enum PushDeerApi {
case fake
case login(idToken: String)
case getUserInfo(token: String)
case regDevice(token: String, name: String, device_id: String, is_clip: Int)
case renameDevice(token: String, id: Int, name: String)
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: =textmarkdown=imagemarkdown
case push(pushkey: String, text: String, desp: String, type: String)
case getMessages(token: String, limit: Int)
case rmMessage(token: String, id: Int)
}
extension PushDeerApi: TargetType {
var baseURL: URL {
var urlStr = Env.onlineApiEndpoint
if Env.isSelfHosted && !AppState.shared.api_endpoint.isEmpty {
urlStr = AppState.shared.api_endpoint
}
return URL(string: urlStr)!
}
var path: String {
switch self {
case .fake:
return "/login/fake"
case .login:
return "/login/idtoken"
case .getUserInfo:
return "/user/info"
case .regDevice:
return "/device/reg"
case .renameDevice:
return "/device/rename"
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"
}
}
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)
case let .getUserInfo(token):
return .requestParameters(parameters: ["token": token], encoding: URLEncoding.queryString)
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)
case let .renameDevice(token, id, name):
return .requestParameters(parameters: ["token": token,"id": id,"name": name], encoding: URLEncoding.queryString)
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)
}
}
var headers: [String: String]? {
return ["Content-type": "application/json"]
}
}