mirror of
https://github.com/git-touch/git-touch
synced 2025-01-31 16:14:49 +01:00
refactor(github): fetch raw markdown
This commit is contained in:
parent
14c6944481
commit
0a83206071
@ -287,14 +287,9 @@ class AuthModel with ChangeNotifier {
|
|||||||
return data['data'];
|
return data['data'];
|
||||||
}
|
}
|
||||||
|
|
||||||
Future<dynamic> getWithCredentials(String url, {String contentType}) async {
|
Future<dynamic> getWithCredentials(String url) async {
|
||||||
var headers = _headers;
|
|
||||||
if (contentType != null) {
|
|
||||||
// https://developer.github.com/v3/repos/contents/#custom-media-types
|
|
||||||
headers[HttpHeaders.contentTypeHeader] = contentType;
|
|
||||||
}
|
|
||||||
final res = await http
|
final res = await http
|
||||||
.get(_apiPrefix + url, headers: headers)
|
.get(_apiPrefix + url, headers: _headers)
|
||||||
.timeout(_timeoutDuration);
|
.timeout(_timeoutDuration);
|
||||||
final data = json.decode(res.body);
|
final data = json.decode(res.body);
|
||||||
if (res.statusCode >= 400) {
|
if (res.statusCode >= 400) {
|
||||||
@ -303,6 +298,15 @@ class AuthModel with ChangeNotifier {
|
|||||||
return data;
|
return data;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
Future<String> getRaw(String url) async {
|
||||||
|
final res = await http.get(_apiPrefix + url, headers: {
|
||||||
|
..._headers,
|
||||||
|
// https://developer.github.com/v3/repos/contents/#custom-media-types
|
||||||
|
HttpHeaders.acceptHeader: 'application/vnd.github.v3.raw'
|
||||||
|
}).timeout(_timeoutDuration);
|
||||||
|
return res.body;
|
||||||
|
}
|
||||||
|
|
||||||
Future<void> patchWithCredentials(String url) async {
|
Future<void> patchWithCredentials(String url) async {
|
||||||
await http
|
await http
|
||||||
.patch(_apiPrefix + url, headers: _headers)
|
.patch(_apiPrefix + url, headers: _headers)
|
||||||
|
@ -1,4 +1,3 @@
|
|||||||
import 'dart:convert';
|
|
||||||
import 'package:filesize/filesize.dart';
|
import 'package:filesize/filesize.dart';
|
||||||
import 'package:flutter/material.dart';
|
import 'package:flutter/material.dart';
|
||||||
import 'package:flutter/cupertino.dart';
|
import 'package:flutter/cupertino.dart';
|
||||||
@ -46,12 +45,6 @@ class RepositoryScreen extends StatelessWidget {
|
|||||||
return res.data.repository;
|
return res.data.repository;
|
||||||
}
|
}
|
||||||
|
|
||||||
Future<String> _fetchReadme(BuildContext context) async {
|
|
||||||
final data = await Provider.of<AuthModel>(context)
|
|
||||||
.getWithCredentials('/repos/$owner/$name/readme');
|
|
||||||
return (data['content'] as String)?.dropLineBreak?.base64ToUtf8;
|
|
||||||
}
|
|
||||||
|
|
||||||
Widget _buildLanguages(BuildContext context, GhRepoRepository repo) {
|
Widget _buildLanguages(BuildContext context, GhRepoRepository repo) {
|
||||||
final theme = Provider.of<ThemeModel>(context);
|
final theme = Provider.of<ThemeModel>(context);
|
||||||
return Container(
|
return Container(
|
||||||
@ -106,7 +99,7 @@ class RepositoryScreen extends StatelessWidget {
|
|||||||
fetchData: () async {
|
fetchData: () async {
|
||||||
final rs = await Future.wait([
|
final rs = await Future.wait([
|
||||||
_query(context),
|
_query(context),
|
||||||
_fetchReadme(context),
|
Provider.of<AuthModel>(context).getRaw('/repos/$owner/$name/readme'),
|
||||||
]);
|
]);
|
||||||
return Tuple2(rs[0] as GhRepoRepository, rs[1] as String);
|
return Tuple2(rs[0] as GhRepoRepository, rs[1] as String);
|
||||||
},
|
},
|
||||||
|
Loading…
x
Reference in New Issue
Block a user