mirror of
https://github.com/Xevion/paperless-mobile.git
synced 2025-12-11 21:10:38 -06:00
Fixed wrong encodings
This commit is contained in:
@@ -116,7 +116,7 @@ class TimeoutClient implements BaseClient {
|
|||||||
Response _handle400Error(Response response) {
|
Response _handle400Error(Response response) {
|
||||||
if (response.statusCode == 400) {
|
if (response.statusCode == 400) {
|
||||||
// try to parse contained error message, otherwise return response
|
// try to parse contained error message, otherwise return response
|
||||||
final JSON json = jsonDecode(response.body);
|
final JSON json = jsonDecode(utf8.decode(response.bodyBytes));
|
||||||
final Map<String, String> errorMessages = {};
|
final Map<String, String> errorMessages = {};
|
||||||
//TODO: This could be simplified, look at error message format of paperless-ngx
|
//TODO: This could be simplified, look at error message format of paperless-ngx
|
||||||
for (final entry in json.entries) {
|
for (final entry in json.entries) {
|
||||||
|
|||||||
@@ -133,7 +133,7 @@ class DocumentRepositoryImpl implements DocumentRepository {
|
|||||||
body: json.encode(doc.toJson()),
|
body: json.encode(doc.toJson()),
|
||||||
headers: {"Content-Type": "application/json"}).timeout(requestTimeout);
|
headers: {"Content-Type": "application/json"}).timeout(requestTimeout);
|
||||||
if (response.statusCode == 200) {
|
if (response.statusCode == 200) {
|
||||||
return DocumentModel.fromJson(jsonDecode(response.body));
|
return DocumentModel.fromJson(jsonDecode(utf8.decode(response.bodyBytes)));
|
||||||
} else {
|
} else {
|
||||||
throw const ErrorMessage(ErrorCode.documentUpdateFailed);
|
throw const ErrorMessage(ErrorCode.documentUpdateFailed);
|
||||||
}
|
}
|
||||||
@@ -147,7 +147,7 @@ class DocumentRepositoryImpl implements DocumentRepository {
|
|||||||
);
|
);
|
||||||
if (response.statusCode == 200) {
|
if (response.statusCode == 200) {
|
||||||
final searchResult = PagedSearchResult.fromJson(
|
final searchResult = PagedSearchResult.fromJson(
|
||||||
jsonDecode(const Utf8Decoder().convert(response.body.codeUnits)),
|
jsonDecode(utf8.decode(response.bodyBytes)),
|
||||||
DocumentModel.fromJson,
|
DocumentModel.fromJson,
|
||||||
);
|
);
|
||||||
return searchResult;
|
return searchResult;
|
||||||
@@ -249,7 +249,7 @@ class DocumentRepositoryImpl implements DocumentRepository {
|
|||||||
@override
|
@override
|
||||||
Future<DocumentMetaData> getMetaData(DocumentModel document) async {
|
Future<DocumentMetaData> getMetaData(DocumentModel document) async {
|
||||||
final response = await httpClient.get(Uri.parse("/api/documents/${document.id}/metadata/"));
|
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
|
@override
|
||||||
@@ -257,7 +257,7 @@ class DocumentRepositoryImpl implements DocumentRepository {
|
|||||||
final response =
|
final response =
|
||||||
await httpClient.get(Uri.parse("/api/search/autocomplete/?query=$query&limit=$limit}"));
|
await httpClient.get(Uri.parse("/api/search/autocomplete/?query=$query&limit=$limit}"));
|
||||||
if (response.statusCode == 200) {
|
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);
|
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"));
|
await httpClient.get(Uri.parse("/api/documents/?more_like=$docId&pageSize=10"));
|
||||||
if (response.statusCode == 200) {
|
if (response.statusCode == 200) {
|
||||||
return PagedSearchResult<SimilarDocumentModel>.fromJson(
|
return PagedSearchResult<SimilarDocumentModel>.fromJson(
|
||||||
json.decode(response.body),
|
jsonDecode(utf8.decode(response.bodyBytes)),
|
||||||
SimilarDocumentModel.fromJson,
|
SimilarDocumentModel.fromJson,
|
||||||
).results;
|
).results;
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -37,7 +37,7 @@ class SavedViewRepositoryImpl implements SavedViewsRepository {
|
|||||||
headers: {'Content-Type': 'application/json'},
|
headers: {'Content-Type': 'application/json'},
|
||||||
);
|
);
|
||||||
if (response.statusCode == 201) {
|
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);
|
throw ErrorMessage(ErrorCode.createSavedViewError, httpStatusCode: response.statusCode);
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -75,9 +75,10 @@ class LabelRepositoryImpl implements LabelRepository {
|
|||||||
Uri.parse('/api/correspondents/'),
|
Uri.parse('/api/correspondents/'),
|
||||||
body: json.encode(correspondent.toJson()),
|
body: json.encode(correspondent.toJson()),
|
||||||
headers: {"Content-Type": "application/json"},
|
headers: {"Content-Type": "application/json"},
|
||||||
|
encoding: Encoding.getByName("utf-8"),
|
||||||
);
|
);
|
||||||
if (response.statusCode == 201) {
|
if (response.statusCode == 201) {
|
||||||
return Correspondent.fromJson(json.decode(response.body));
|
return Correspondent.fromJson(jsonDecode(utf8.decode(response.bodyBytes)));
|
||||||
}
|
}
|
||||||
throw ErrorMessage(ErrorCode.correspondentCreateFailed, httpStatusCode: response.statusCode);
|
throw ErrorMessage(ErrorCode.correspondentCreateFailed, httpStatusCode: response.statusCode);
|
||||||
}
|
}
|
||||||
@@ -88,9 +89,10 @@ class LabelRepositoryImpl implements LabelRepository {
|
|||||||
Uri.parse('/api/document_types/'),
|
Uri.parse('/api/document_types/'),
|
||||||
body: json.encode(type.toJson()),
|
body: json.encode(type.toJson()),
|
||||||
headers: {"Content-Type": "application/json"},
|
headers: {"Content-Type": "application/json"},
|
||||||
|
encoding: Encoding.getByName("utf-8"),
|
||||||
);
|
);
|
||||||
if (response.statusCode == 201) {
|
if (response.statusCode == 201) {
|
||||||
return DocumentType.fromJson(json.decode(response.body));
|
return DocumentType.fromJson(jsonDecode(utf8.decode(response.bodyBytes)));
|
||||||
}
|
}
|
||||||
throw const ErrorMessage(ErrorCode.documentTypeCreateFailed);
|
throw const ErrorMessage(ErrorCode.documentTypeCreateFailed);
|
||||||
}
|
}
|
||||||
@@ -98,12 +100,17 @@ class LabelRepositoryImpl implements LabelRepository {
|
|||||||
@override
|
@override
|
||||||
Future<Tag> saveTag(Tag tag) async {
|
Future<Tag> saveTag(Tag tag) async {
|
||||||
final body = json.encode(tag.toJson());
|
final body = json.encode(tag.toJson());
|
||||||
final response = await httpClient.post(Uri.parse('/api/tags/'), body: body, headers: {
|
final response = await httpClient.post(
|
||||||
"Content-Type": "application/json",
|
Uri.parse('/api/tags/'),
|
||||||
"Accept": "application/json; version=2",
|
body: body,
|
||||||
});
|
headers: {
|
||||||
|
"Content-Type": "application/json",
|
||||||
|
"Accept": "application/json; version=2",
|
||||||
|
},
|
||||||
|
encoding: Encoding.getByName("utf-8"),
|
||||||
|
);
|
||||||
if (response.statusCode == 201) {
|
if (response.statusCode == 201) {
|
||||||
return Tag.fromJson(json.decode(response.body));
|
return Tag.fromJson(jsonDecode(utf8.decode(response.bodyBytes)));
|
||||||
}
|
}
|
||||||
throw const ErrorMessage(ErrorCode.tagCreateFailed);
|
throw const ErrorMessage(ErrorCode.tagCreateFailed);
|
||||||
}
|
}
|
||||||
@@ -112,7 +119,7 @@ class LabelRepositoryImpl implements LabelRepository {
|
|||||||
Future<int> getStatistics() async {
|
Future<int> getStatistics() async {
|
||||||
final response = await httpClient.get(Uri.parse('/api/statistics/'));
|
final response = await httpClient.get(Uri.parse('/api/statistics/'));
|
||||||
if (response.statusCode == 200) {
|
if (response.statusCode == 200) {
|
||||||
return json.decode(response.body)['documents_total'];
|
return jsonDecode(utf8.decode(response.bodyBytes))['documents_total'];
|
||||||
}
|
}
|
||||||
throw const ErrorMessage(ErrorCode.unknown);
|
throw const ErrorMessage(ErrorCode.unknown);
|
||||||
}
|
}
|
||||||
@@ -154,9 +161,10 @@ class LabelRepositoryImpl implements LabelRepository {
|
|||||||
Uri.parse('/api/correspondents/${correspondent.id}/'),
|
Uri.parse('/api/correspondents/${correspondent.id}/'),
|
||||||
headers: {"Content-Type": "application/json"},
|
headers: {"Content-Type": "application/json"},
|
||||||
body: json.encode(correspondent.toJson()),
|
body: json.encode(correspondent.toJson()),
|
||||||
|
encoding: Encoding.getByName("utf-8"),
|
||||||
);
|
);
|
||||||
if (response.statusCode == 200) {
|
if (response.statusCode == 200) {
|
||||||
return Correspondent.fromJson(json.decode(response.body));
|
return Correspondent.fromJson(jsonDecode(utf8.decode(response.bodyBytes)));
|
||||||
}
|
}
|
||||||
throw const ErrorMessage(ErrorCode.unknown);
|
throw const ErrorMessage(ErrorCode.unknown);
|
||||||
}
|
}
|
||||||
@@ -168,9 +176,10 @@ class LabelRepositoryImpl implements LabelRepository {
|
|||||||
Uri.parse('/api/document_types/${documentType.id}/'),
|
Uri.parse('/api/document_types/${documentType.id}/'),
|
||||||
headers: {"Content-Type": "application/json"},
|
headers: {"Content-Type": "application/json"},
|
||||||
body: json.encode(documentType.toJson()),
|
body: json.encode(documentType.toJson()),
|
||||||
|
encoding: Encoding.getByName("utf-8"),
|
||||||
);
|
);
|
||||||
if (response.statusCode == 200) {
|
if (response.statusCode == 200) {
|
||||||
return DocumentType.fromJson(json.decode(response.body));
|
return DocumentType.fromJson(jsonDecode(utf8.decode(response.bodyBytes)));
|
||||||
}
|
}
|
||||||
throw const ErrorMessage(ErrorCode.unknown);
|
throw const ErrorMessage(ErrorCode.unknown);
|
||||||
}
|
}
|
||||||
@@ -185,9 +194,10 @@ class LabelRepositoryImpl implements LabelRepository {
|
|||||||
"Content-Type": "application/json",
|
"Content-Type": "application/json",
|
||||||
},
|
},
|
||||||
body: json.encode(tag.toJson()),
|
body: json.encode(tag.toJson()),
|
||||||
|
encoding: Encoding.getByName("utf-8"),
|
||||||
);
|
);
|
||||||
if (response.statusCode == 200) {
|
if (response.statusCode == 200) {
|
||||||
return Tag.fromJson(json.decode(response.body));
|
return Tag.fromJson(jsonDecode(utf8.decode(response.bodyBytes)));
|
||||||
}
|
}
|
||||||
throw const ErrorMessage(ErrorCode.unknown);
|
throw const ErrorMessage(ErrorCode.unknown);
|
||||||
}
|
}
|
||||||
@@ -225,7 +235,7 @@ class LabelRepositoryImpl implements LabelRepository {
|
|||||||
headers: {"Content-Type": "application/json"},
|
headers: {"Content-Type": "application/json"},
|
||||||
);
|
);
|
||||||
if (response.statusCode == 201) {
|
if (response.statusCode == 201) {
|
||||||
return StoragePath.fromJson(json.decode(response.body));
|
return StoragePath.fromJson(jsonDecode(utf8.decode(response.bodyBytes)));
|
||||||
}
|
}
|
||||||
throw ErrorMessage(ErrorCode.storagePathCreateFailed, httpStatusCode: response.statusCode);
|
throw ErrorMessage(ErrorCode.storagePathCreateFailed, httpStatusCode: response.statusCode);
|
||||||
}
|
}
|
||||||
@@ -239,7 +249,7 @@ class LabelRepositoryImpl implements LabelRepository {
|
|||||||
body: json.encode(path.toJson()),
|
body: json.encode(path.toJson()),
|
||||||
);
|
);
|
||||||
if (response.statusCode == 200) {
|
if (response.statusCode == 200) {
|
||||||
return StoragePath.fromJson(json.decode(response.body));
|
return StoragePath.fromJson(jsonDecode(utf8.decode(response.bodyBytes)));
|
||||||
}
|
}
|
||||||
throw const ErrorMessage(ErrorCode.unknown);
|
throw const ErrorMessage(ErrorCode.unknown);
|
||||||
}
|
}
|
||||||
@@ -31,7 +31,7 @@ class AuthenticationService {
|
|||||||
body: {"username": username, "password": password},
|
body: {"username": username, "password": password},
|
||||||
);
|
);
|
||||||
if (response.statusCode == 200) {
|
if (response.statusCode == 200) {
|
||||||
final data = jsonDecode(response.body);
|
final data = jsonDecode(utf8.decode(response.bodyBytes));
|
||||||
return data['token'];
|
return data['token'];
|
||||||
} else if (response.statusCode == 400 &&
|
} else if (response.statusCode == 400 &&
|
||||||
response.body.toLowerCase().contains("no required certificate was sent")) {
|
response.body.toLowerCase().contains("no required certificate was sent")) {
|
||||||
|
|||||||
Reference in New Issue
Block a user