fix(bb): utf8 decode text

This commit is contained in:
Rongjian Zhang 2020-02-02 23:06:54 +08:00
parent f9fa142702
commit 8f9ed5469d
3 changed files with 7 additions and 9 deletions

View File

@ -287,12 +287,6 @@ class AuthModel with ChangeNotifier {
);
}
Future<String> fetchBbReadme(String p) async {
final res = await fetchBb(p);
if (res.statusCode >= 400) return null;
return res.body;
}
Future<void> init() async {
// Listen scheme
_sub = getUriLinksStream().listen(_onSchemeDetected, onError: (err) {

View File

@ -28,9 +28,10 @@ class BbObjectScreen extends StatelessWidget {
final res = await auth
.fetchBb('/repositories/$owner/$name/src/$ref/${path ?? ''}');
if (res.headers[HttpHeaders.contentTypeHeader] == 'text/plain') {
return res.body;
return utf8.decode(res.bodyBytes);
} else {
return BbPagination.fromJson(json.decode(res.body)).values;
return BbPagination.fromJson(json.decode(utf8.decode(res.bodyBytes)))
.values;
}
},
actionBuilder: (p, _) {

View File

@ -1,3 +1,5 @@
import 'dart:convert';
import 'package:filesize/filesize.dart';
import 'package:flutter/material.dart';
import 'package:git_touch/models/auth.dart';
@ -27,7 +29,8 @@ class BbRepoScreen extends StatelessWidget {
final repo = BbRepo.fromJson(r);
final res = await auth.fetchBb(
'/repositories/$owner/$name/src/${repo.mainbranch.name}/README.md');
final readme = res.statusCode >= 400 ? null : res.body;
final readme =
res.statusCode >= 400 ? null : utf8.decode(res.bodyBytes);
return Tuple2(repo, readme);
},
bodyBuilder: (t, setState) {