Skip to content

Commit d927c99

Browse files
committed
Format all code for 4 spaces(Tab)
1 parent dcccedc commit d927c99

File tree

13 files changed

+737
-741
lines changed

13 files changed

+737
-741
lines changed

V2exOS/User/CurrentUserStore.swift

Lines changed: 70 additions & 70 deletions
Original file line numberDiff line numberDiff line change
@@ -11,82 +11,82 @@ import V2exAPI
1111
import KeychainAccess
1212

1313
public class CurrentUserStore: ObservableObject {
14-
15-
public static let shared = CurrentUserStore()
16-
17-
@Published public private(set) var user: V2Member?
18-
@Published public private(set) var accessToken: String? {
19-
didSet {
20-
v2ex.accessToken = accessToken
14+
15+
public static let shared = CurrentUserStore()
16+
17+
@Published public private(set) var user: V2Member?
18+
@Published public private(set) var accessToken: String? {
19+
didSet {
20+
v2ex.accessToken = accessToken
21+
}
2122
}
22-
}
23-
24-
let keychain = Keychain(service: "com.isaced.v2exos")
25-
let KeychainTokenKey = "AccessToken"
26-
27-
28-
29-
public init() {
30-
if let token = readToken(){
31-
accessToken = token
32-
33-
fetchUser()
23+
24+
let keychain = Keychain(service: "com.isaced.v2exos")
25+
let KeychainTokenKey = "AccessToken"
26+
27+
28+
29+
public init() {
30+
if let token = readToken(){
31+
accessToken = token
32+
33+
fetchUser()
34+
}
3435
}
35-
}
36-
37-
public func readToken() -> String? {
38-
return keychain[KeychainTokenKey]
39-
}
40-
41-
public func saveToken(token: String) {
42-
accessToken = token
43-
keychain[KeychainTokenKey] = token
4436

45-
fetchUser()
46-
}
47-
48-
func clearToken() {
49-
do {
50-
try keychain.remove(KeychainTokenKey)
51-
}catch {
52-
print(error)
37+
public func readToken() -> String? {
38+
return keychain[KeychainTokenKey]
5339
}
54-
}
55-
56-
public func logout(){
57-
accessToken = nil
58-
user = nil
59-
clearToken()
60-
}
61-
62-
public func checkToken(token: String) async -> Bool {
63-
do {
64-
v2ex.accessToken = token
65-
let res = try await v2ex.token()
66-
if let tokenObj = res?.result {
67-
print(tokenObj)
68-
if let _ = tokenObj.token {
69-
return true
40+
41+
public func saveToken(token: String) {
42+
accessToken = token
43+
keychain[KeychainTokenKey] = token
44+
45+
fetchUser()
46+
}
47+
48+
func clearToken() {
49+
do {
50+
try keychain.remove(KeychainTokenKey)
51+
}catch {
52+
print(error)
53+
}
54+
}
55+
56+
public func logout(){
57+
accessToken = nil
58+
user = nil
59+
clearToken()
60+
}
61+
62+
public func checkToken(token: String) async -> Bool {
63+
do {
64+
v2ex.accessToken = token
65+
let res = try await v2ex.token()
66+
if let tokenObj = res?.result {
67+
print(tokenObj)
68+
if let _ = tokenObj.token {
69+
return true
70+
}
71+
}
72+
}catch{
73+
print(error)
7074
}
71-
}
72-
}catch{
73-
print(error)
75+
v2ex.accessToken = nil
76+
return false
7477
}
75-
v2ex.accessToken = nil
76-
return false
77-
}
78-
79-
func fetchUser() {
80-
Task {
81-
do {
82-
if let res = try await v2ex.member(){
83-
if res.success {
84-
user = res.result;
85-
}
78+
79+
func fetchUser() {
80+
Task {
81+
do {
82+
if let res = try await v2ex.member(){
83+
if res.success {
84+
user = res.result;
85+
}
86+
}
87+
}catch{
88+
return
89+
}
8690
}
87-
}catch{
88-
return
89-
}
9091
}
91-
}
9292
}

V2exOS/Utils/PreviewData.swift

Lines changed: 28 additions & 31 deletions
Original file line numberDiff line numberDiff line change
@@ -8,36 +8,33 @@
88
import Foundation
99
import V2exAPI
1010

11-
12-
13-
1411
struct PreviewData {
15-
static let member = V2Member(id: 79764,
16-
username: "ljsh093",
17-
url: "https://www.v2ex.com/u/ljsh093",
18-
avatarMini: "https://cdn.v2ex.com/avatar/ff10/6e6c/79764_mini.png?m=1657684598",
19-
avatarNormal: "https://cdn.v2ex.com/avatar/ff10/6e6c/79764_normal.png?m=1657684598",
20-
avatarLarge: "https://cdn.v2ex.com/avatar/ff10/6e6c/79764_large.png?m=1657684598",
21-
created: 1414903742,
22-
lastModified: 1657684598)
23-
24-
static let topic = V2Topic(id: 1,
25-
node: nil,
26-
member: PreviewData.member,
27-
lastReplyBy: "ljsh093",
28-
lastTouched: 1658649862,
29-
title: "万行原生 Javascript 该如何维护?",
30-
url: "https://www.v2ex.com/t/868366",
31-
created: 1658649797,
32-
deleted: 0,
33-
content: "想拆成 Typescript 模块化,有没有什么指路手册?",
34-
contentRendered: "<p>想拆成 Typescript 模块化,有没有什么指路手册?</p>\n",
35-
lastModified: 1658649797,
36-
replies: 1111)
37-
38-
static let comment = V2Comment(id: 1,
39-
content: "Testtt",
40-
contentRendered: "Testtt",
41-
created: 1272220126,
42-
member: member)
12+
static let member = V2Member(id: 79764,
13+
username: "ljsh093",
14+
url: "https://www.v2ex.com/u/ljsh093",
15+
avatarMini: "https://cdn.v2ex.com/avatar/ff10/6e6c/79764_mini.png?m=1657684598",
16+
avatarNormal: "https://cdn.v2ex.com/avatar/ff10/6e6c/79764_normal.png?m=1657684598",
17+
avatarLarge: "https://cdn.v2ex.com/avatar/ff10/6e6c/79764_large.png?m=1657684598",
18+
created: 1414903742,
19+
lastModified: 1657684598)
20+
21+
static let topic = V2Topic(id: 1,
22+
node: nil,
23+
member: PreviewData.member,
24+
lastReplyBy: "ljsh093",
25+
lastTouched: 1658649862,
26+
title: "万行原生 Javascript 该如何维护?",
27+
url: "https://www.v2ex.com/t/868366",
28+
created: 1658649797,
29+
deleted: 0,
30+
content: "想拆成 Typescript 模块化,有没有什么指路手册?",
31+
contentRendered: "<p>想拆成 Typescript 模块化,有没有什么指路手册?</p>\n",
32+
lastModified: 1658649797,
33+
replies: 1111)
34+
35+
static let comment = V2Comment(id: 1,
36+
content: "Testtt",
37+
contentRendered: "Testtt",
38+
created: 1272220126,
39+
member: member)
4340
}

V2exOS/Utils/ProxyHelper.swift

Lines changed: 67 additions & 67 deletions
Original file line numberDiff line numberDiff line change
@@ -9,85 +9,85 @@ import Foundation
99
import Kingfisher
1010

1111
enum ProxyType : Int , Codable {
12-
case http
13-
case socks
12+
case http
13+
case socks
1414
}
1515

1616
struct ProxyInfo : Codable {
17-
var enabled: Bool
18-
var type: ProxyType = .http
19-
var host: String?
20-
var port: Int?
21-
var username: String?
22-
var password: String?
17+
var enabled: Bool
18+
var type: ProxyType = .http
19+
var host: String?
20+
var port: Int?
21+
var username: String?
22+
var password: String?
2323
}
2424

2525
struct ProxyHelper {
26-
27-
static let ProxyCacheKey = "ProxyInfo"
28-
29-
/**
30-
Load proxy
31-
*/
32-
static func loadProxy() {
33-
guard let proxyInfo = loadProxyInfo(), proxyInfo.enabled else {
34-
clearProxy()
35-
return
36-
}
3726

38-
let sessionConfiguration = URLSessionConfiguration.default
27+
static let ProxyCacheKey = "ProxyInfo"
3928

40-
if proxyInfo.type == .http {
41-
sessionConfiguration.connectionProxyDictionary = [
42-
kCFNetworkProxiesHTTPEnable: true,
43-
kCFNetworkProxiesHTTPProxy: proxyInfo.host ?? "",
44-
kCFNetworkProxiesHTTPPort: proxyInfo.port ?? 0,
45-
kCFNetworkProxiesHTTPSEnable: true,
46-
kCFNetworkProxiesHTTPSProxy: proxyInfo.host ?? "",
47-
kCFNetworkProxiesHTTPSPort: proxyInfo.port ?? 0,
48-
]
49-
} else if proxyInfo.type == .socks {
50-
sessionConfiguration.connectionProxyDictionary = [
51-
kCFNetworkProxiesSOCKSEnable: true,
52-
kCFNetworkProxiesSOCKSProxy: proxyInfo.host ?? "",
53-
kCFNetworkProxiesSOCKSPort: proxyInfo.port ?? 0,
54-
]
29+
/**
30+
Load proxy
31+
*/
32+
static func loadProxy() {
33+
guard let proxyInfo = loadProxyInfo(), proxyInfo.enabled else {
34+
clearProxy()
35+
return
36+
}
37+
38+
let sessionConfiguration = URLSessionConfiguration.default
39+
40+
if proxyInfo.type == .http {
41+
sessionConfiguration.connectionProxyDictionary = [
42+
kCFNetworkProxiesHTTPEnable: true,
43+
kCFNetworkProxiesHTTPProxy: proxyInfo.host ?? "",
44+
kCFNetworkProxiesHTTPPort: proxyInfo.port ?? 0,
45+
kCFNetworkProxiesHTTPSEnable: true,
46+
kCFNetworkProxiesHTTPSProxy: proxyInfo.host ?? "",
47+
kCFNetworkProxiesHTTPSPort: proxyInfo.port ?? 0,
48+
]
49+
} else if proxyInfo.type == .socks {
50+
sessionConfiguration.connectionProxyDictionary = [
51+
kCFNetworkProxiesSOCKSEnable: true,
52+
kCFNetworkProxiesSOCKSProxy: proxyInfo.host ?? "",
53+
kCFNetworkProxiesSOCKSPort: proxyInfo.port ?? 0,
54+
]
55+
}
56+
57+
if let username = proxyInfo.username, username.count > 0 {
58+
sessionConfiguration.connectionProxyDictionary?[kCFProxyUsernameKey] = username
59+
}
60+
if let password = proxyInfo.password, password.count > 0 {
61+
sessionConfiguration.connectionProxyDictionary?[kCFProxyPasswordKey] = password
62+
}
63+
64+
v2ex.session = URLSession(configuration: sessionConfiguration)
65+
ImageDownloader.default.sessionConfiguration = sessionConfiguration
5566
}
5667

57-
if let username = proxyInfo.username, username.count > 0 {
58-
sessionConfiguration.connectionProxyDictionary?[kCFProxyUsernameKey] = username
59-
}
60-
if let password = proxyInfo.password, password.count > 0 {
61-
sessionConfiguration.connectionProxyDictionary?[kCFProxyPasswordKey] = password
68+
static func clearProxy() {
69+
v2ex.session = URLSession.shared
70+
ImageDownloader.default.sessionConfiguration = URLSessionConfiguration.ephemeral
6271
}
6372

64-
v2ex.session = URLSession(configuration: sessionConfiguration)
65-
ImageDownloader.default.sessionConfiguration = sessionConfiguration
66-
}
67-
68-
static func clearProxy() {
69-
v2ex.session = URLSession.shared
70-
ImageDownloader.default.sessionConfiguration = URLSessionConfiguration.ephemeral
71-
}
72-
73-
/**
74-
Load proxy info from UserDefaults
75-
*/
76-
static func loadProxyInfo() -> ProxyInfo? {
77-
if let data = UserDefaults.standard.object(forKey: ProxyCacheKey) as? Data {
78-
let decoder = JSONDecoder()
79-
return try? decoder.decode(ProxyInfo.self, from: data)
73+
/**
74+
Load proxy info from UserDefaults
75+
*/
76+
static func loadProxyInfo() -> ProxyInfo? {
77+
if let data = UserDefaults.standard.object(forKey: ProxyCacheKey) as? Data {
78+
let decoder = JSONDecoder()
79+
return try? decoder.decode(ProxyInfo.self, from: data)
80+
}
81+
return nil
8082
}
81-
return nil
82-
}
83-
84-
/**
85-
Save proxy info to UserDefaults
86-
*/
87-
static func saveProxyInfo(proxyInfo: ProxyInfo) {
88-
let encoder = JSONEncoder()
89-
if let encoded = try? encoder.encode(proxyInfo) {
90-
UserDefaults.standard.set(encoded, forKey: ProxyCacheKey)
83+
84+
/**
85+
Save proxy info to UserDefaults
86+
*/
87+
static func saveProxyInfo(proxyInfo: ProxyInfo) {
88+
let encoder = JSONEncoder()
89+
if let encoded = try? encoder.encode(proxyInfo) {
90+
UserDefaults.standard.set(encoded, forKey: ProxyCacheKey)
91+
}
9192
}
92-
}
9393
}

V2exOS/Utils/StringExt.swift

Lines changed: 11 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -8,16 +8,16 @@
88
import Foundation
99

1010
extension String {
11-
func htmlToString() -> String? {
12-
do {
13-
14-
let text = try NSAttributedString(data: self.data(using: .unicode)!,
15-
options: [.documentType: NSAttributedString.DocumentType.html],
16-
documentAttributes: nil).string
17-
return text
18-
} catch {
19-
print("htmlToString fail: ", self)
11+
func htmlToString() -> String? {
12+
do {
13+
14+
let text = try NSAttributedString(data: self.data(using: .unicode)!,
15+
options: [.documentType: NSAttributedString.DocumentType.html],
16+
documentAttributes: nil).string
17+
return text
18+
} catch {
19+
print("htmlToString fail: ", self)
20+
}
21+
return nil
2022
}
21-
return nil
22-
}
2323
}

0 commit comments

Comments
 (0)