Merge pull request #2447 from ar-lex/bugfix/rustore-charset

RuStore: fix charset detection (#2304)
This commit is contained in:
Imran
2025-08-06 18:38:25 -04:00
committed by GitHub

View File

@@ -36,13 +36,15 @@ class RuStore extends AppSource {
return Uri.parse(standardUrl).pathSegments.last; return Uri.parse(standardUrl).pathSegments.last;
} }
Future<String> decodeString(String str) async { Future<dynamic> decodeJsonBody(Uint8List bytes) async {
try { try {
return (await CharsetDetector.autoDecode( return jsonDecode((await CharsetDetector.autoDecode(bytes)).string);
Uint8List.fromList(str.codeUnits),
)).string;
} catch (e) { } catch (e) {
return str; try {
return jsonDecode(utf8.decode(bytes));
} catch (_) {
rethrow;
}
} }
} }
@@ -59,7 +61,7 @@ class RuStore extends AppSource {
if (res0.statusCode != 200) { if (res0.statusCode != 200) {
throw getObtainiumHttpError(res0); throw getObtainiumHttpError(res0);
} }
var appDetails = jsonDecode(res0.body)['body']; var appDetails = (await decodeJsonBody(res0.bodyBytes))['body'];
if (appDetails['appId'] == null) { if (appDetails['appId'] == null) {
throw NoReleasesError(); throw NoReleasesError();
} }
@@ -83,15 +85,11 @@ class RuStore extends AppSource {
followRedirects: false, followRedirects: false,
postBody: {"appId": appDetails['appId'], "firstInstall": true}, postBody: {"appId": appDetails['appId'], "firstInstall": true},
); );
var downloadDetails = jsonDecode(res1.body)['body']; var downloadDetails = (await decodeJsonBody(res1.bodyBytes))['body'];
if (res1.statusCode != 200 || downloadDetails['apkUrl'] == null) { if (res1.statusCode != 200 || downloadDetails['apkUrl'] == null) {
throw NoAPKError(); throw NoAPKError();
} }
appName = await decodeString(appName);
author = await decodeString(author);
changeLog = changeLog != null ? await decodeString(changeLog) : null;
return APKDetails( return APKDetails(
version, version,
getApkUrlsFromUrls([ getApkUrlsFromUrls([