Skip to content

Commit bd02f50

Browse files
committed
修改http,增加拦截器
1 parent b2eb311 commit bd02f50

File tree

13 files changed

+291
-149
lines changed

13 files changed

+291
-149
lines changed

lib/common/dao/EventDao.dart

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -27,7 +27,7 @@ class EventDao {
2727
String userName = user.login;
2828
String url = Address.getEventReceived(userName) + Address.getPageParams("?", page);
2929

30-
var res = await HttpManager.netFetch(url, null, null, null);
30+
var res = await httpManager.netFetch(url, null, null, null);
3131
if (res != null && res.result) {
3232
List<Event> list = new List();
3333
var data = res.data;
@@ -58,7 +58,7 @@ class EventDao {
5858
UserEventDbProvider provider = new UserEventDbProvider();
5959
next() async {
6060
String url = Address.getEvent(userName) + Address.getPageParams("?", page);
61-
var res = await HttpManager.netFetch(url, null, null, null);
61+
var res = await httpManager.netFetch(url, null, null, null);
6262
if (res != null && res.result) {
6363
List<Event> list = new List();
6464
var data = res.data;

lib/common/dao/IssueDao.dart

Lines changed: 10 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -33,7 +33,7 @@ class IssueDao {
3333

3434
next() async {
3535
String url = Address.getReposIssue(userName, repository, state, sort, direction) + Address.getPageParams("&", page);
36-
var res = await HttpManager.netFetch(url, null, {"Accept": 'application/vnd.github.html,application/vnd.github.VERSION.raw'}, null);
36+
var res = await httpManager.netFetch(url, null, {"Accept": 'application/vnd.github.html,application/vnd.github.VERSION.raw'}, null);
3737
if (res != null && res.result) {
3838
List<Issue> list = new List();
3939
var data = res.data;
@@ -79,7 +79,7 @@ class IssueDao {
7979
qu = q + "+repo%3A${name}%2F${reposName}+state%3A${state}";
8080
}
8181
String url = Address.repositoryIssueSearch(qu) + Address.getPageParams("&", page);
82-
var res = await HttpManager.netFetch(url, null, null, null);
82+
var res = await httpManager.netFetch(url, null, null, null);
8383
if (res != null && res.result) {
8484
List<Issue> list = new List();
8585
var data = res.data["items"];
@@ -106,7 +106,7 @@ class IssueDao {
106106
next() async {
107107
String url = Address.getIssueInfo(userName, repository, number);
108108
//{"Accept": 'application/vnd.github.html,application/vnd.github.VERSION.raw'}
109-
var res = await HttpManager.netFetch(url, null, {"Accept": 'application/vnd.github.VERSION.raw'}, null);
109+
var res = await httpManager.netFetch(url, null, {"Accept": 'application/vnd.github.VERSION.raw'}, null);
110110
if (res != null && res.result) {
111111
if (needDb) {
112112
provider.insert(fullName, number, json.encode(res.data));
@@ -138,7 +138,7 @@ class IssueDao {
138138
next() async {
139139
String url = Address.getIssueComment(userName, repository, number) + Address.getPageParams("?", page);
140140
//{"Accept": 'application/vnd.github.html,application/vnd.github.VERSION.raw'}
141-
var res = await HttpManager.netFetch(url, null, {"Accept": 'application/vnd.github.VERSION.raw'}, null);
141+
var res = await httpManager.netFetch(url, null, {"Accept": 'application/vnd.github.VERSION.raw'}, null);
142142
if (res != null && res.result) {
143143
List<Issue> list = new List();
144144
var data = res.data;
@@ -173,7 +173,7 @@ class IssueDao {
173173
*/
174174
static addIssueCommentDao(userName, repository, number, comment) async {
175175
String url = Address.addIssueComment(userName, repository, number);
176-
var res = await HttpManager.netFetch(url, {"body": comment}, {"Accept": 'application/vnd.github.VERSION.full+json'}, new Options(method: 'POST'));
176+
var res = await httpManager.netFetch(url, {"body": comment}, {"Accept": 'application/vnd.github.VERSION.full+json'}, new Options(method: 'POST'));
177177
if (res != null && res.result) {
178178
return new DataResult(res.data, true);
179179
} else {
@@ -186,7 +186,7 @@ class IssueDao {
186186
*/
187187
static editIssueDao(userName, repository, number, issue) async {
188188
String url = Address.editIssue(userName, repository, number);
189-
var res = await HttpManager.netFetch(url, issue, {"Accept": 'application/vnd.github.VERSION.full+json'}, new Options(method: 'PATCH'));
189+
var res = await httpManager.netFetch(url, issue, {"Accept": 'application/vnd.github.VERSION.full+json'}, new Options(method: 'PATCH'));
190190
if (res != null && res.result) {
191191
return new DataResult(res.data, true);
192192
} else {
@@ -199,7 +199,7 @@ class IssueDao {
199199
*/
200200
static lockIssueDao(userName, repository, number, locked) async {
201201
String url = Address.lockIssue(userName, repository, number);
202-
var res = await HttpManager.netFetch(
202+
var res = await httpManager.netFetch(
203203
url, null, {"Accept": 'application/vnd.github.VERSION.full+json'}, new Options(method: locked ? "DELETE" : 'PUT', contentType: ContentType.text),
204204
noTip: true);
205205
if (res != null && res.result) {
@@ -214,7 +214,7 @@ class IssueDao {
214214
*/
215215
static createIssueDao(userName, repository, issue) async {
216216
String url = Address.createIssue(userName, repository);
217-
var res = await HttpManager.netFetch(url, issue, {"Accept": 'application/vnd.github.VERSION.full+json'}, new Options(method: 'POST'));
217+
var res = await httpManager.netFetch(url, issue, {"Accept": 'application/vnd.github.VERSION.full+json'}, new Options(method: 'POST'));
218218
if (res != null && res.result) {
219219
return new DataResult(res.data, true);
220220
} else {
@@ -227,7 +227,7 @@ class IssueDao {
227227
*/
228228
static editCommentDao(userName, repository, number, commentId, comment) async {
229229
String url = Address.editComment(userName, repository, commentId);
230-
var res = await HttpManager.netFetch(url, comment, {"Accept": 'application/vnd.github.VERSION.full+json'}, new Options(method: 'PATCH'));
230+
var res = await httpManager.netFetch(url, comment, {"Accept": 'application/vnd.github.VERSION.full+json'}, new Options(method: 'PATCH'));
231231
if (res != null && res.result) {
232232
return new DataResult(res.data, true);
233233
} else {
@@ -240,7 +240,7 @@ class IssueDao {
240240
*/
241241
static deleteCommentDao(userName, repository, number, commentId) async {
242242
String url = Address.editComment(userName, repository, commentId);
243-
var res = await HttpManager.netFetch(url, null, null, new Options(method: 'DELETE'), noTip: true);
243+
var res = await httpManager.netFetch(url, null, null, new Options(method: 'DELETE'), noTip: true);
244244
if (res != null && res.result) {
245245
return new DataResult(res.data, true);
246246
} else {

lib/common/dao/ReposDao.dart

Lines changed: 23 additions & 23 deletions
Original file line numberDiff line numberDiff line change
@@ -85,7 +85,7 @@ class ReposDao {
8585

8686
next() async {
8787
String url = Address.getReposDetail(userName, reposName) + "?ref=" + branch;
88-
var res = await HttpManager.netFetch(url, null, {"Accept": 'application/vnd.github.mercy-preview+json'}, null);
88+
var res = await httpManager.netFetch(url, null, {"Accept": 'application/vnd.github.mercy-preview+json'}, null);
8989
if (res != null && res.result && res.data.length > 0) {
9090
var data = res.data;
9191
if (data == null || data.length == 0) {
@@ -126,7 +126,7 @@ class ReposDao {
126126

127127
next() async {
128128
String url = Address.getReposEvent(userName, reposName) + Address.getPageParams("?", page);
129-
var res = await HttpManager.netFetch(url, null, null, null);
129+
var res = await httpManager.netFetch(url, null, null, null);
130130
if (res != null && res.result) {
131131
List<Event> list = new List();
132132
var data = res.data;
@@ -162,8 +162,8 @@ class ReposDao {
162162
static getRepositoryStatusDao(userName, reposName) async {
163163
String urls = Address.resolveStarRepos(userName, reposName);
164164
String urlw = Address.resolveWatcherRepos(userName, reposName);
165-
var resS = await HttpManager.netFetch(urls, null, null, new Options(contentType: ContentType.text), noTip: true);
166-
var resW = await HttpManager.netFetch(urlw, null, null, new Options(contentType: ContentType.text), noTip: true);
165+
var resS = await httpManager.netFetch(urls, null, null, new Options(contentType: ContentType.text), noTip: true);
166+
var resW = await httpManager.netFetch(urlw, null, null, new Options(contentType: ContentType.text), noTip: true);
167167
var data = {"star": resS.result, "watch": resW.result};
168168
return new DataResult(data, true);
169169
}
@@ -178,7 +178,7 @@ class ReposDao {
178178

179179
next() async {
180180
String url = Address.getReposCommits(userName, reposName) + Address.getPageParams("?", page) + "&sha=" + branch;
181-
var res = await HttpManager.netFetch(url, null, null, null);
181+
var res = await httpManager.netFetch(url, null, null, null);
182182
if (res != null && res.result) {
183183
List<RepoCommit> list = new List();
184184
var data = res.data;
@@ -213,7 +213,7 @@ class ReposDao {
213213
*/
214214
static getReposFileDirDao(userName, reposName, {path = '', branch, text = false, isHtml = false}) async {
215215
String url = Address.reposDataDir(userName, reposName, path, branch);
216-
var res = await HttpManager.netFetch(
216+
var res = await httpManager.netFetch(
217217
url,
218218
null,
219219
//text ? {"Accept": 'application/vnd.github.VERSION.raw'} : {"Accept": 'application/vnd.github.html'},
@@ -252,7 +252,7 @@ class ReposDao {
252252
*/
253253
static Future<DataResult> doRepositoryStarDao(userName, reposName, star) async {
254254
String url = Address.resolveStarRepos(userName, reposName);
255-
var res = await HttpManager.netFetch(url, null, null, new Options(method: !star ? 'PUT' : 'DELETE', contentType: ContentType.text));
255+
var res = await httpManager.netFetch(url, null, null, new Options(method: !star ? 'PUT' : 'DELETE', contentType: ContentType.text));
256256
return Future<DataResult>(() {
257257
return new DataResult(null, res.result);
258258
});
@@ -263,7 +263,7 @@ class ReposDao {
263263
*/
264264
static doRepositoryWatchDao(userName, reposName, watch) async {
265265
String url = Address.resolveWatcherRepos(userName, reposName);
266-
var res = await HttpManager.netFetch(url, null, null, new Options(method: !watch ? 'PUT' : 'DELETE', contentType: ContentType.text));
266+
var res = await httpManager.netFetch(url, null, null, new Options(method: !watch ? 'PUT' : 'DELETE', contentType: ContentType.text));
267267
return new DataResult(null, res.result);
268268
}
269269

@@ -276,7 +276,7 @@ class ReposDao {
276276

277277
next() async {
278278
String url = Address.getReposWatcher(userName, reposName) + Address.getPageParams("?", page);
279-
var res = await HttpManager.netFetch(url, null, null, null);
279+
var res = await httpManager.netFetch(url, null, null, null);
280280
if (res != null && res.result) {
281281
List<User> list = new List();
282282
var data = res.data;
@@ -314,7 +314,7 @@ class ReposDao {
314314
RepositoryStarDbProvider provider = new RepositoryStarDbProvider();
315315
next() async {
316316
String url = Address.getReposStar(userName, reposName) + Address.getPageParams("?", page);
317-
var res = await HttpManager.netFetch(url, null, null, null);
317+
var res = await httpManager.netFetch(url, null, null, null);
318318
if (res != null && res.result) {
319319
List<User> list = new List();
320320
var data = res.data;
@@ -352,7 +352,7 @@ class ReposDao {
352352
RepositoryForkDbProvider provider = new RepositoryForkDbProvider();
353353
next() async {
354354
String url = Address.getReposForks(userName, reposName) + Address.getPageParams("?", page);
355-
var res = await HttpManager.netFetch(url, null, null, null);
355+
var res = await httpManager.netFetch(url, null, null, null);
356356
if (res != null && res.result && res.data.length > 0) {
357357
List<Repository> list = new List();
358358
var dataList = res.data;
@@ -390,7 +390,7 @@ class ReposDao {
390390
UserStaredDbProvider provider = new UserStaredDbProvider();
391391
next() async {
392392
String url = Address.userStar(userName, sort) + Address.getPageParams("&", page);
393-
var res = await HttpManager.netFetch(url, null, null, null);
393+
var res = await httpManager.netFetch(url, null, null, null);
394394
if (res != null && res.result && res.data.length > 0) {
395395
List<Repository> list = new List();
396396
var dataList = res.data;
@@ -428,7 +428,7 @@ class ReposDao {
428428
UserReposDbProvider provider = new UserReposDbProvider();
429429
next() async {
430430
String url = Address.userRepos(userName, sort) + Address.getPageParams("&", page);
431-
var res = await HttpManager.netFetch(url, null, null, null);
431+
var res = await httpManager.netFetch(url, null, null, null);
432432
if (res != null && res.result && res.data.length > 0) {
433433
List<Repository> list = new List();
434434
var dataList = res.data;
@@ -464,7 +464,7 @@ class ReposDao {
464464
*/
465465
static createForkDao(userName, reposName) async {
466466
String url = Address.createFork(userName, reposName);
467-
var res = await HttpManager.netFetch(url, null, null, new Options(method: "POST", contentType: ContentType.text));
467+
var res = await httpManager.netFetch(url, null, null, new Options(method: "POST", contentType: ContentType.text));
468468
return new DataResult(null, res.result);
469469
}
470470

@@ -473,7 +473,7 @@ class ReposDao {
473473
*/
474474
static getBranchesDao(userName, reposName) async {
475475
String url = Address.getbranches(userName, reposName);
476-
var res = await HttpManager.netFetch(url, null, null, null);
476+
var res = await httpManager.netFetch(url, null, null, null);
477477
if (res != null && res.result && res.data.length > 0) {
478478
List<String> list = new List();
479479
var dataList = res.data;
@@ -495,7 +495,7 @@ class ReposDao {
495495
*/
496496
static getUserRepository100StatusDao(userName) async {
497497
String url = Address.userRepos(userName, 'pushed') + "&page=1&per_page=100";
498-
var res = await HttpManager.netFetch(url, null, null, null);
498+
var res = await httpManager.netFetch(url, null, null, null);
499499
if (res != null && res.result && res.data.length > 0) {
500500
int stared = 0;
501501
for (int i = 0; i < res.data.length; i++) {
@@ -516,8 +516,8 @@ class ReposDao {
516516

517517
next() async {
518518
String url = Address.readmeFile(userName + '/' + reposName, branch);
519-
var res = await HttpManager.netFetch(url, null, {"Accept": 'application/vnd.github.VERSION.raw'}, new Options(contentType: ContentType.text));
520-
//var res = await HttpManager.netFetch(url, null, {"Accept": 'application/vnd.github.html'}, new Options(contentType: ContentType.text));
519+
var res = await httpManager.netFetch(url, null, {"Accept": 'application/vnd.github.VERSION.raw'}, new Options(contentType: ContentType.text));
520+
//var res = await httpManager.netFetch(url, null, {"Accept": 'application/vnd.github.html'}, new Options(contentType: ContentType.text));
521521
if (res != null && res.result) {
522522
if (needDb) {
523523
provider.insert(fullName, branch, res.data);
@@ -552,7 +552,7 @@ class ReposDao {
552552
q = q + "%2Blanguage%3A$language";
553553
}
554554
String url = Address.search(q, sort, order, type, page, pageSize);
555-
var res = await HttpManager.netFetch(url, null, null, null);
555+
var res = await httpManager.netFetch(url, null, null, null);
556556
if (type == null) {
557557
if (res != null && res.result && res.data["items"] != null) {
558558
List<Repository> list = new List();
@@ -590,7 +590,7 @@ class ReposDao {
590590
*/
591591
static getReposCommitsInfoDao(userName, reposName, sha) async {
592592
String url = Address.getReposCommitsInfo(userName, reposName, sha);
593-
var res = await HttpManager.netFetch(url, null, null, null);
593+
var res = await httpManager.netFetch(url, null, null, null);
594594
if (res != null && res.result) {
595595
PushCommit pushCommit = PushCommit.fromJson(res.data);
596596
return new DataResult(pushCommit, true);
@@ -607,7 +607,7 @@ class ReposDao {
607607
? Address.getReposRelease(userName, reposName) + Address.getPageParams("?", page)
608608
: Address.getReposTag(userName, reposName) + Address.getPageParams("?", page);
609609

610-
var res = await HttpManager.netFetch(
610+
var res = await httpManager.netFetch(
611611
url,
612612
null,
613613
{"Accept": (needHtml ? 'application/vnd.github.html,application/vnd.github.VERSION.raw' : "")},
@@ -675,7 +675,7 @@ class ReposDao {
675675
*/
676676
static getRepositoryIssueStatusDao(userName, repository) async {
677677
String url = Address.getReposIssue(userName, repository, null, null, null) + "&per_page=1";
678-
var res = await HttpManager.netFetch(url, null, null, null);
678+
var res = await httpManager.netFetch(url, null, null, null);
679679
if (res != null && res.result && res.headers != null) {
680680
try {
681681
List<String> link = res.headers['link'];
@@ -699,7 +699,7 @@ class ReposDao {
699699
*/
700700
static searchTopicRepositoryDao(searchTopic, {page = 0}) async {
701701
String url = Address.searchTopic(searchTopic) + Address.getPageParams("&", page);
702-
var res = await HttpManager.netFetch(url, null, null, null);
702+
var res = await httpManager.netFetch(url, null, null, null);
703703
var data = (res.data != null && res.data["items"] != null) ? res.data["items"] : res.data;
704704
if (res != null && res.result && data != null && data.length > 0) {
705705
List<Repository> list = new List();

0 commit comments

Comments
 (0)