Skip to content

Commit 8596ddf

Browse files
committed
开发者部分替换完成
1 parent baffd88 commit 8596ddf

File tree

7 files changed

+153
-74
lines changed

7 files changed

+153
-74
lines changed

SwiftPamphletApp.xcodeproj/project.pbxproj

+12-4
Original file line numberDiff line numberDiff line change
@@ -199,8 +199,10 @@
199199
0896FB9027BA39B100676B7F /* PlayButtonView.swift in Sources */ = {isa = PBXBuildFile; fileRef = 0896FB8F27BA39B100676B7F /* PlayButtonView.swift */; };
200200
0896FB9227BA486900676B7F /* 145.md in Resources */ = {isa = PBXBuildFile; fileRef = 0896FB9127BA486900676B7F /* 145.md */; };
201201
08A4FDC227B25A140068E5BC /* 141.md in Resources */ = {isa = PBXBuildFile; fileRef = 08A4FDC127B25A140068E5BC /* 141.md */; };
202-
08A9E19F2BC18EF400A73764 /* APIVM.swift in Sources */ = {isa = PBXBuildFile; fileRef = 08A9E19E2BC18EF400A73764 /* APIVM.swift */; };
202+
08A9E19F2BC18EF400A73764 /* APIRepoVM.swift in Sources */ = {isa = PBXBuildFile; fileRef = 08A9E19E2BC18EF400A73764 /* APIRepoVM.swift */; };
203203
08A9E1A22BC25D0700A73764 /* ViewComponetMarkdown.swift in Sources */ = {isa = PBXBuildFile; fileRef = 08A9E1A12BC25D0700A73764 /* ViewComponetMarkdown.swift */; };
204+
08A9E1A42BC2837500A73764 /* APIUserVM.swift in Sources */ = {isa = PBXBuildFile; fileRef = 08A9E1A32BC2837500A73764 /* APIUserVM.swift */; };
205+
08A9E1A62BC2861100A73764 /* GitHubReq.swift in Sources */ = {isa = PBXBuildFile; fileRef = 08A9E1A52BC2861100A73764 /* GitHubReq.swift */; };
204206
08AEAEDD277EA64900B969E2 /* DBDevNoti.swift in Sources */ = {isa = PBXBuildFile; fileRef = 08AEAEDC277EA64900B969E2 /* DBDevNoti.swift */; };
205207
08AEAEE1277EA70500B969E2 /* DBRepoStore.swift in Sources */ = {isa = PBXBuildFile; fileRef = 08AEAEE0277EA70500B969E2 /* DBRepoStore.swift */; };
206208
08AEAEF1277F09D000B969E2 /* IntroView.swift in Sources */ = {isa = PBXBuildFile; fileRef = 08AEAEF0277F09D000B969E2 /* IntroView.swift */; };
@@ -475,8 +477,10 @@
475477
0896FB8F27BA39B100676B7F /* PlayButtonView.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = PlayButtonView.swift; sourceTree = "<group>"; };
476478
0896FB9127BA486900676B7F /* 145.md */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = net.daringfireball.markdown; path = 145.md; sourceTree = "<group>"; };
477479
08A4FDC127B25A140068E5BC /* 141.md */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = net.daringfireball.markdown; path = 141.md; sourceTree = "<group>"; };
478-
08A9E19E2BC18EF400A73764 /* APIVM.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = APIVM.swift; sourceTree = "<group>"; };
480+
08A9E19E2BC18EF400A73764 /* APIRepoVM.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = APIRepoVM.swift; sourceTree = "<group>"; };
479481
08A9E1A12BC25D0700A73764 /* ViewComponetMarkdown.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = ViewComponetMarkdown.swift; sourceTree = "<group>"; };
482+
08A9E1A32BC2837500A73764 /* APIUserVM.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = APIUserVM.swift; sourceTree = "<group>"; };
483+
08A9E1A52BC2861100A73764 /* GitHubReq.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = GitHubReq.swift; sourceTree = "<group>"; };
480484
08AEAEDC277EA64900B969E2 /* DBDevNoti.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = DBDevNoti.swift; sourceTree = "<group>"; };
481485
08AEAEE0277EA70500B969E2 /* DBRepoStore.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = DBRepoStore.swift; sourceTree = "<group>"; };
482486
08AEAEF0277F09D000B969E2 /* IntroView.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = IntroView.swift; sourceTree = "<group>"; };
@@ -1263,7 +1267,9 @@
12631267
08A9E1A02BC1919C00A73764 /* APIVM */ = {
12641268
isa = PBXGroup;
12651269
children = (
1266-
08A9E19E2BC18EF400A73764 /* APIVM.swift */,
1270+
08A9E19E2BC18EF400A73764 /* APIRepoVM.swift */,
1271+
08A9E1A32BC2837500A73764 /* APIUserVM.swift */,
1272+
08A9E1A52BC2861100A73764 /* GitHubReq.swift */,
12671273
);
12681274
path = APIVM;
12691275
sourceTree = "<group>";
@@ -1738,6 +1744,7 @@
17381744
08448F0D2799035600B61353 /* PlaySecurity.swift in Sources */,
17391745
0871C6192BA040E5000B620D /* InfoRowView.swift in Sources */,
17401746
086A5F442744EE2800FECE02 /* SwiftPamphletAppConfig.swift in Sources */,
1747+
08A9E1A62BC2861100A73764 /* GitHubReq.swift in Sources */,
17411748
08C411F427951181006FC340 /* PlaySyntax.swift in Sources */,
17421749
083554E12756503B0095E0EE /* AnimateLayout.swift in Sources */,
17431750
08BF26DA276B65160064DDAC /* CCYGitHubAPI.swift in Sources */,
@@ -1761,6 +1768,7 @@
17611768
08BE637D27CDDA47002BC6A8 /* DataListView.swift in Sources */,
17621769
08AEAEF1277F09D000B969E2 /* IntroView.swift in Sources */,
17631770
086A5F412744EDCE00FECE02 /* UserVM.swift in Sources */,
1771+
08A9E1A42BC2837500A73764 /* APIUserVM.swift in Sources */,
17641772
08BE633527BF54A0002BC6A8 /* PlayTextEditorView.swift in Sources */,
17651773
08AEAEF5277F0A1E00B969E2 /* SPSidebar.swift in Sources */,
17661774
086A5F642754C14F00FECE02 /* PlayTextView.swift in Sources */,
@@ -1776,7 +1784,7 @@
17761784
08BE637927CDCFD9002BC6A8 /* DataSortingListView.swift in Sources */,
17771785
08BE636E27C8D6FD002BC6A8 /* PlayLazyVGridAndLazyHGridView.swift in Sources */,
17781786
08522BE227CF52ED005FF059 /* PlayColor.swift in Sources */,
1779-
08A9E19F2BC18EF400A73764 /* APIVM.swift in Sources */,
1787+
08A9E19F2BC18EF400A73764 /* APIRepoVM.swift in Sources */,
17801788
08BE636A27C8C409002BC6A8 /* PlayImageView.swift in Sources */,
17811789
08CD61FF27758B8A008C0935 /* Token.swift in Sources */,
17821790
3AE0D59E2BAB183100D6D925 /* EditDeveloper.swift in Sources */,

SwiftPamphletApp/GitHubAPI/APIVM/APIVM.swift SwiftPamphletApp/GitHubAPI/APIVM/APIRepoVM.swift

+23-20
Original file line numberDiff line numberDiff line change
@@ -6,14 +6,15 @@
66
//
77

88
import Foundation
9-
import SwiftUI
109

1110
@Observable
1211
final class APIRepoVM {
1312
var name: String = ""
1413
var repo: RepoModel = RepoModel()
1514
var commits: [CommitModel] = [CommitModel]()
1615
var issues: [IssueModel] = [IssueModel]()
16+
var issuesEvents: [IssueEventModel] = [IssueEventModel]()
17+
var readme: RepoContent = RepoContent()
1718

1819
init(name: String) {
1920
self.name = name
@@ -23,6 +24,8 @@ final class APIRepoVM {
2324
await obtainRepos()
2425
await obtainCommits()
2526
await obtainIssues()
27+
await obtainIssuesEvents()
28+
await obtainReadme()
2629
}
2730

2831
// https://docs.github.com/en/rest/repos/repos?apiVersion=2022-11-28
@@ -52,27 +55,27 @@ final class APIRepoVM {
5255
} catch { print("问题是:\(error)") }
5356
}
5457

55-
}
56-
57-
// github api 入口 https://api.github.com
58-
class GitHubReq {
59-
static func jsonDecoder() -> JSONDecoder {
60-
let de = JSONDecoder()
61-
de.keyDecodingStrategy = .convertFromSnakeCase
62-
return de
58+
// https://docs.github.com/en/rest/issues/events?apiVersion=2022-11-28#about-events
59+
@MainActor
60+
func obtainIssuesEvents() async {
61+
do {
62+
let (data, _) = try await URLSession.shared.data(for: GitHubReq.req("repos/\(name)/issues/events"))
63+
issuesEvents = try GitHubReq.jsonDecoder().decode([IssueEventModel].self, from: data)
64+
} catch { print("问题是:\(error)") }
6365
}
64-
static func req(_ path: String) -> URLRequest {
65-
let req = URLRequest(url: URL(string: "https://api.github.com/\(path)")!)
66-
// var githubat = ""
67-
// if SPC.gitHubAccessToken.isEmpty == true {
68-
// githubat = SPC.githubAccessToken()
69-
// } else {
70-
// githubat = SPC.gitHubAccessToken
71-
// }
72-
//
73-
// req.addValue("token \(githubat)", forHTTPHeaderField: "Authorization")
74-
return req
66+
67+
// https://docs.github.com/en/rest/repos/contents?apiVersion=2022-11-28
68+
@MainActor
69+
func obtainReadme() async {
70+
do {
71+
let (data, _) = try await URLSession.shared.data(for: GitHubReq.req("repos/\(name)/readme"))
72+
readme = try GitHubReq.jsonDecoder().decode(RepoContent.self, from: data)
73+
} catch { print("问题是:\(error)") }
7574
}
75+
76+
// TODO: 下载内容
7677
}
7778

7879

80+
81+
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,54 @@
1+
//
2+
// APIUserVM.swift
3+
// SwiftPamphletApp
4+
//
5+
// Created by Ming Dai on 2024/4/7.
6+
//
7+
8+
import Foundation
9+
10+
@Observable
11+
final class APIUserVM {
12+
var name: String = ""
13+
var user: UserModel = UserModel()
14+
var events: [EventModel] = [EventModel]()
15+
var receivedEvents: [EventModel] = [EventModel]()
16+
17+
init(name: String) {
18+
self.name = name
19+
}
20+
21+
func updateAllData() async {
22+
await obtainUser()
23+
await obtainEvents()
24+
await obtainReceivedEvents()
25+
}
26+
27+
// https://docs.github.com/en/rest/users/users?apiVersion=2022-11-28
28+
@MainActor
29+
func obtainUser() async {
30+
do {
31+
let (data, _) = try await URLSession.shared.data(for: GitHubReq.req("users/\(name)"))
32+
user = try GitHubReq.jsonDecoder().decode(UserModel.self, from: data)
33+
} catch { print("问题是:\(error)") }
34+
}
35+
36+
// https://docs.github.com/en/rest/activity/events?apiVersion=2022-11-28
37+
@MainActor
38+
func obtainEvents() async {
39+
do {
40+
let (data, _) = try await URLSession.shared.data(for: GitHubReq.req("users/\(name)/events"))
41+
events = try GitHubReq.jsonDecoder().decode([EventModel].self, from: data)
42+
} catch { print("问题是:\(error)") }
43+
}
44+
45+
// https://docs.github.com/en/rest/activity/events?apiVersion=2022-11-28#list-events-received-by-the-authenticated-user
46+
@MainActor
47+
func obtainReceivedEvents() async {
48+
do {
49+
let (data, _) = try await URLSession.shared.data(for: GitHubReq.req("users/\(name)/received_events"))
50+
receivedEvents = try GitHubReq.jsonDecoder().decode([EventModel].self, from: data)
51+
} catch { print("问题是:\(error)") }
52+
}
53+
54+
}
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,29 @@
1+
//
2+
// GitHubReq.swift
3+
// SwiftPamphletApp
4+
//
5+
// Created by Ming Dai on 2024/4/7.
6+
//
7+
8+
import Foundation
9+
10+
// github api 入口 https://api.github.com
11+
class GitHubReq {
12+
static func jsonDecoder() -> JSONDecoder {
13+
let de = JSONDecoder()
14+
de.keyDecodingStrategy = .convertFromSnakeCase
15+
return de
16+
}
17+
static func req(_ path: String) -> URLRequest {
18+
let req = URLRequest(url: URL(string: "https://api.github.com/\(path)")!)
19+
// var githubat = ""
20+
// if SPC.gitHubAccessToken.isEmpty == true {
21+
// githubat = SPC.githubAccessToken()
22+
// } else {
23+
// githubat = SPC.gitHubAccessToken
24+
// }
25+
//
26+
// req.addValue("token \(githubat)", forHTTPHeaderField: "Authorization")
27+
return req
28+
}
29+
}

SwiftPamphletApp/GitHubAPI/DetailView/RepoView.swift

+2
Original file line numberDiff line numberDiff line change
@@ -129,12 +129,14 @@ struct RepoView: View {
129129
}
130130

131131
struct ReadmeView: View {
132+
@Environment(\.colorScheme) private var colorScheme
132133
var content: String
133134
var body: some View {
134135
ScrollView {
135136
MarkdownView(s: content.base64Decoded() ?? "failed")
136137
.padding(10)
137138
}
139+
.background(colorScheme == .light ? Color.white : Color.black)
138140
}
139141
}
140142

0 commit comments

Comments
 (0)