F-Droid: Don't pull changelog text if it isn't a raw file from GitHub/GitLab (#1340)

This commit is contained in:
Imran Remtulla
2024-01-27 21:01:44 -05:00
parent d25895fa28
commit 5a8efa2388
2 changed files with 36 additions and 9 deletions

View File

@ -3,6 +3,8 @@ import 'dart:convert';
import 'package:easy_localization/easy_localization.dart'; import 'package:easy_localization/easy_localization.dart';
import 'package:html/parser.dart'; import 'package:html/parser.dart';
import 'package:http/http.dart'; import 'package:http/http.dart';
import 'package:obtainium/app_sources/github.dart';
import 'package:obtainium/app_sources/gitlab.dart';
import 'package:obtainium/components/generated_form.dart'; import 'package:obtainium/components/generated_form.dart';
import 'package:obtainium/custom_errors.dart'; import 'package:obtainium/custom_errors.dart';
import 'package:obtainium/providers/source_provider.dart'; import 'package:obtainium/providers/source_provider.dart';
@ -95,17 +97,32 @@ class FDroid extends AppSource {
details.names.author = details.names.author =
authorLines.first.split(': ').sublist(1).join(': '); authorLines.first.split(': ').sublist(1).join(': ');
} }
var changelogUrls = lines.where((l) => l.startsWith('Changelog: ')); var changelogUrls = lines
.where((l) => l.startsWith('Changelog: '))
.map((e) => e.split(' ').sublist(1).join(' '));
if (changelogUrls.isNotEmpty) { if (changelogUrls.isNotEmpty) {
details.changeLog = changelogUrls.first; details.changeLog = changelogUrls.first;
details.changeLog = (await sourceRequest( bool isGitHub = false;
details.changeLog! bool isGitLab = false;
.split(': ') try {
.sublist(1) GitHub().sourceSpecificStandardizeURL(details.changeLog!);
.join(': ') isGitHub = true;
.replaceFirst('/blob/', '/raw/'), } catch (e) {
additionalSettings)) //
.body; }
try {
GitLab().sourceSpecificStandardizeURL(details.changeLog!);
isGitLab = true;
} catch (e) {
//
}
if ((isGitHub || isGitLab) &&
(details.changeLog?.indexOf('/blob/') ?? -1) >= 0) {
details.changeLog = (await sourceRequest(
details.changeLog!.replaceFirst('/blob/', '/raw/'),
additionalSettings))
.body;
}
} }
} catch (e) { } catch (e) {
// Fail silently // Fail silently

View File

@ -358,6 +358,16 @@ class AppsPageState extends State<AppsPage> {
String? changesUrl = String? changesUrl =
appSource.changeLogPageFromStandardUrl(listedApps[appIndex].app.url); appSource.changeLogPageFromStandardUrl(listedApps[appIndex].app.url);
String? changeLog = listedApps[appIndex].app.changeLog; String? changeLog = listedApps[appIndex].app.changeLog;
if (changeLog?.split('\n').length == 1) {
if (RegExp(
'(http|ftp|https)://([\\w_-]+(?:(?:\\.[\\w_-]+)+))([\\w.,@?^=%&:/~+#-]*[\\w@?^=%&/~+#-])?')
.hasMatch(changeLog!)) {
if (changesUrl == null) {
changesUrl = changeLog;
changeLog = null;
}
}
}
return (changeLog == null && changesUrl == null) return (changeLog == null && changesUrl == null)
? null ? null
: () { : () {