From c257c74b59fdc1f9b8fafbad6fe7e0c10a5082fb Mon Sep 17 00:00:00 2001 From: Rongjian Zhang Date: Sun, 16 May 2021 12:09:27 +0800 Subject: [PATCH] refactor: fix http param type --- lib/models/auth.dart | 50 ++++++++++++++++++++-------------------- lib/screens/ge_repo.dart | 2 +- lib/screens/go_repo.dart | 2 +- lib/screens/gt_repo.dart | 2 +- 4 files changed, 28 insertions(+), 28 deletions(-) diff --git a/lib/models/auth.dart b/lib/models/auth.dart index e97a770..a3c3796 100644 --- a/lib/models/auth.dart +++ b/lib/models/auth.dart @@ -105,7 +105,7 @@ class AuthModel with ChangeNotifier { // Get token by code final res = await http.post( - 'https://git-touch-oauth.vercel.app/api/token', + Uri.parse('https://git-touch-oauth.vercel.app/api/token'), headers: { HttpHeaders.acceptHeader: 'application/json', HttpHeaders.contentTypeHeader: 'application/json', @@ -150,8 +150,8 @@ class AuthModel with ChangeNotifier { loading = true; notifyListeners(); try { - final res = await http - .get('$domain/api/v4/user', headers: {'Private-Token': token}); + final res = await http.get(Uri.parse('$domain/api/v4/user'), + headers: {'Private-Token': token}); final info = json.decode(res.body); if (info['message'] != null) { throw info['message']; @@ -179,7 +179,7 @@ class AuthModel with ChangeNotifier { } Future fetchWithGitlabToken(String p) async { - final res = await http.get(p, headers: {'Private-Token': token}); + final res = await http.get(Uri.parse(p), headers: {'Private-Token': token}); return res.body; } @@ -188,7 +188,7 @@ class AuthModel with ChangeNotifier { http.Response res; if (isPost) { res = await http.post( - '${activeAccount.domain}/api/v4$p', + Uri.parse('${activeAccount.domain}/api/v4$p'), headers: { 'Private-Token': token, HttpHeaders.contentTypeHeader: 'application/json' @@ -196,7 +196,7 @@ class AuthModel with ChangeNotifier { body: jsonEncode(body), ); } else { - res = await http.get('${activeAccount.domain}/api/v4$p', + res = await http.get(Uri.parse('${activeAccount.domain}/api/v4$p'), headers: {'Private-Token': token}); } final info = json.decode(utf8.decode(res.bodyBytes)); @@ -205,7 +205,7 @@ class AuthModel with ChangeNotifier { } Future fetchGitlabWithPage(String p) async { - final res = await http.get('${activeAccount.domain}/api/v4$p', + final res = await http.get(Uri.parse('${activeAccount.domain}/api/v4$p'), headers: {'Private-Token': token}); final next = int.tryParse( res.headers['X-Next-Pages'] ?? res.headers['x-next-page'] ?? ''); @@ -226,7 +226,7 @@ class AuthModel with ChangeNotifier { try { loading = true; notifyListeners(); - final res = await http.get('$domain/api/v1/user', + final res = await http.get(Uri.parse('$domain/api/v1/user'), headers: {'Authorization': 'token $token'}); final info = json.decode(res.body); if (info['message'] != null) { @@ -261,7 +261,7 @@ class AuthModel with ChangeNotifier { case 'DELETE': { await http.delete( - '${activeAccount.domain}/api/v1$p', + Uri.parse('${activeAccount.domain}/api/v1$p'), headers: headers, ); break; @@ -269,7 +269,7 @@ class AuthModel with ChangeNotifier { case 'POST': { res = await http.post( - '${activeAccount.domain}/api/v1$p', + Uri.parse('${activeAccount.domain}/api/v1$p'), headers: headers, body: jsonEncode(body), ); @@ -278,7 +278,7 @@ class AuthModel with ChangeNotifier { case 'PATCH': { res = await http.patch( - '${activeAccount.domain}/api/v1$p', + Uri.parse('${activeAccount.domain}/api/v1$p'), headers: headers, body: jsonEncode(body), ); @@ -286,7 +286,7 @@ class AuthModel with ChangeNotifier { } default: { - res = await http.get('${activeAccount.domain}/api/v1$p', + res = await http.get(Uri.parse('${activeAccount.domain}/api/v1$p'), headers: headers); break; } @@ -328,7 +328,7 @@ class AuthModel with ChangeNotifier { try { loading = true; notifyListeners(); - final res = await http.get('$domain/api/v1/user', + final res = await http.get(Uri.parse('$domain/api/v1/user'), headers: {'Authorization': 'token $token'}); final info = json.decode(res.body); if (info['message'] != null) { @@ -364,7 +364,7 @@ class AuthModel with ChangeNotifier { case 'DELETE': { await http.delete( - '${activeAccount.domain}/api/v1$p', + Uri.parse('${activeAccount.domain}/api/v1$p'), headers: headers, ); break; @@ -372,7 +372,7 @@ class AuthModel with ChangeNotifier { case 'POST': { res = await http.post( - '${activeAccount.domain}/api/v1$p', + Uri.parse('${activeAccount.domain}/api/v1$p'), headers: headers, body: jsonEncode(body), ); @@ -381,7 +381,7 @@ class AuthModel with ChangeNotifier { case 'PATCH': { res = await http.patch( - '${activeAccount.domain}/api/v1$p', + Uri.parse('${activeAccount.domain}/api/v1$p'), headers: headers, body: jsonEncode(body), ); @@ -389,7 +389,7 @@ class AuthModel with ChangeNotifier { } default: { - res = await http.get('${activeAccount.domain}/api/v1$p', + res = await http.get(Uri.parse('${activeAccount.domain}/api/v1$p'), headers: headers); break; } @@ -439,7 +439,7 @@ class AuthModel with ChangeNotifier { case 'DELETE': { await http.delete( - '${activeAccount.domain}/api/v5$p', + Uri.parse('${activeAccount.domain}/api/v5$p'), headers: headers, ); return; @@ -447,7 +447,7 @@ class AuthModel with ChangeNotifier { case 'PUT': { await http.put( - '${activeAccount.domain}/api/v5$p', + Uri.parse('${activeAccount.domain}/api/v5$p'), headers: headers, ); return; @@ -455,7 +455,7 @@ class AuthModel with ChangeNotifier { case 'POST': { res = await http.post( - '${activeAccount.domain}/api/v5$p', + Uri.parse('${activeAccount.domain}/api/v5$p'), headers: headers, body: jsonEncode(body), ); @@ -464,7 +464,7 @@ class AuthModel with ChangeNotifier { case 'PATCH': { res = await http.patch( - '${activeAccount.domain}/api/v5$p', + Uri.parse('${activeAccount.domain}/api/v5$p'), headers: headers, body: jsonEncode(body), ); @@ -472,13 +472,13 @@ class AuthModel with ChangeNotifier { } case 'NO CONTENT': { - res = await http.get('${activeAccount.domain}/api/v5$p', + res = await http.get(Uri.parse('${activeAccount.domain}/api/v5$p'), headers: headers); return res; } default: { - res = await http.get('${activeAccount.domain}/api/v5$p', + res = await http.get(Uri.parse('${activeAccount.domain}/api/v5$p'), headers: headers); break; } @@ -595,7 +595,7 @@ class AuthModel with ChangeNotifier { try { loading = true; notifyListeners(); - final res = await http.get('https://gitee.com/api/v5/user', + final res = await http.get(Uri.parse('https://gitee.com/api/v5/user'), headers: {'Authorization': 'token $token'}); final info = json.decode(res.body); if (info['message'] != null) { @@ -729,7 +729,7 @@ class AuthModel with ChangeNotifier { } final res = await http - .post(_apiPrefix + '/graphql', + .post(Uri.parse(_apiPrefix + '/graphql'), headers: { HttpHeaders.authorizationHeader: 'token $_token', HttpHeaders.contentTypeHeader: 'application/json' diff --git a/lib/screens/ge_repo.dart b/lib/screens/ge_repo.dart index 80ac06c..b402c15 100644 --- a/lib/screens/ge_repo.dart +++ b/lib/screens/ge_repo.dart @@ -46,7 +46,7 @@ class GeRepoScreen extends StatelessWidget { }); final html = () => md().then((v) async { final res = await http.post( - '${auth.activeAccount.domain}/api/v5/markdown', + Uri.parse('${auth.activeAccount.domain}/api/v5/markdown'), headers: {'Authorization': 'token ${auth.token}'}, body: {'text': v}, ); diff --git a/lib/screens/go_repo.dart b/lib/screens/go_repo.dart index 53d316f..f8ce5ce 100644 --- a/lib/screens/go_repo.dart +++ b/lib/screens/go_repo.dart @@ -38,7 +38,7 @@ class GoRepoScreen extends StatelessWidget { }); final html = () => md().then((v) async { final res = await http.post( - '${auth.activeAccount.domain}/api/v1/markdown/raw', + Uri.parse('${auth.activeAccount.domain}/api/v1/markdown/raw'), headers: {'Authorization': 'token ${auth.token}'}, body: v, ); diff --git a/lib/screens/gt_repo.dart b/lib/screens/gt_repo.dart index c1c68d8..f1c15b7 100644 --- a/lib/screens/gt_repo.dart +++ b/lib/screens/gt_repo.dart @@ -37,7 +37,7 @@ class GtRepoScreen extends StatelessWidget { }); final html = () => md().then((v) async { final res = await http.post( - '${auth.activeAccount.domain}/api/v1/markdown/raw', + Uri.parse('${auth.activeAccount.domain}/api/v1/markdown/raw'), headers: {'Authorization': 'token ${auth.token}'}, body: v, );