Fixed wrong encodings

This commit is contained in:
Anton Stubenbord
2022-11-01 23:42:43 +01:00
parent b3cb64cad1
commit 2a1b90cc42
5 changed files with 31 additions and 21 deletions

View File

@@ -133,7 +133,7 @@ class DocumentRepositoryImpl implements DocumentRepository {
body: json.encode(doc.toJson()),
headers: {"Content-Type": "application/json"}).timeout(requestTimeout);
if (response.statusCode == 200) {
return DocumentModel.fromJson(jsonDecode(response.body));
return DocumentModel.fromJson(jsonDecode(utf8.decode(response.bodyBytes)));
} else {
throw const ErrorMessage(ErrorCode.documentUpdateFailed);
}
@@ -147,7 +147,7 @@ class DocumentRepositoryImpl implements DocumentRepository {
);
if (response.statusCode == 200) {
final searchResult = PagedSearchResult.fromJson(
jsonDecode(const Utf8Decoder().convert(response.body.codeUnits)),
jsonDecode(utf8.decode(response.bodyBytes)),
DocumentModel.fromJson,
);
return searchResult;
@@ -249,7 +249,7 @@ class DocumentRepositoryImpl implements DocumentRepository {
@override
Future<DocumentMetaData> getMetaData(DocumentModel document) async {
final response = await httpClient.get(Uri.parse("/api/documents/${document.id}/metadata/"));
return DocumentMetaData.fromJson(jsonDecode(response.body));
return DocumentMetaData.fromJson(jsonDecode(utf8.decode(response.bodyBytes)));
}
@override
@@ -257,7 +257,7 @@ class DocumentRepositoryImpl implements DocumentRepository {
final response =
await httpClient.get(Uri.parse("/api/search/autocomplete/?query=$query&limit=$limit}"));
if (response.statusCode == 200) {
return json.decode(response.body) as List<String>;
return jsonDecode(utf8.decode(response.bodyBytes)) as List<String>;
}
throw const ErrorMessage(ErrorCode.autocompleteQueryError);
}
@@ -268,7 +268,7 @@ class DocumentRepositoryImpl implements DocumentRepository {
await httpClient.get(Uri.parse("/api/documents/?more_like=$docId&pageSize=10"));
if (response.statusCode == 200) {
return PagedSearchResult<SimilarDocumentModel>.fromJson(
json.decode(response.body),
jsonDecode(utf8.decode(response.bodyBytes)),
SimilarDocumentModel.fromJson,
).results;
}

View File

@@ -37,7 +37,7 @@ class SavedViewRepositoryImpl implements SavedViewsRepository {
headers: {'Content-Type': 'application/json'},
);
if (response.statusCode == 201) {
return SavedView.fromJson(jsonDecode(response.body));
return SavedView.fromJson(jsonDecode(utf8.decode(response.bodyBytes)));
}
throw ErrorMessage(ErrorCode.createSavedViewError, httpStatusCode: response.statusCode);
}