Skip to content

added JSON structure check for repos #455

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 2 commits into from
May 17, 2025
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
3 changes: 2 additions & 1 deletion lib/l10n/app_ar.arb
Original file line number Diff line number Diff line change
Expand Up @@ -463,5 +463,6 @@
"genre_search_library": "بحث النوع في المكتبة",
"genre_search_source": "تصفح في المصدر",
"source_not_added": "المصدر غير مثبت!",
"load_own_subtitles": "تحميل الترجمة الخاصة بك..."
"load_own_subtitles": "تحميل الترجمة الخاصة بك...",
"unsupported_repo": "لقد حاولت إضافة مستودع غير مدعوم. يرجى التحقق من خادم الخلاف للحصول على الدعم!"
}
3 changes: 2 additions & 1 deletion lib/l10n/app_de.arb
Original file line number Diff line number Diff line change
Expand Up @@ -465,5 +465,6 @@
"clear_all_sources_msg": "Dies wird alle Quellen der Anwendung vollständig löschen. Möchten Sie wirklich fortfahren?",
"sources_cleared": "Quellen gelöscht!",
"add_repo": "Repository hinzufügen?",
"extension_notes": "Hinweis: {notes}"
"extension_notes": "Hinweis: {notes}",
"unsupported_repo": "Du hast gerade versucht, ein ungültiges Repository hinzuzufügen. Bitte schau mal beim Discord Server vorbei!"
}
3 changes: 2 additions & 1 deletion lib/l10n/app_en.arb
Original file line number Diff line number Diff line change
Expand Up @@ -465,5 +465,6 @@
"genre_search_source": "Browse in source",
"source_not_added": "Source is not installed!",
"load_own_subtitles": "Load your own subtitles...",
"extension_notes": "Notes: {notes}"
"extension_notes": "Notes: {notes}",
"unsupported_repo": "You've tried to add an unsupported repository. Please check the discord server for support!"
}
3 changes: 2 additions & 1 deletion lib/l10n/app_es.arb
Original file line number Diff line number Diff line change
Expand Up @@ -463,5 +463,6 @@
"genre_search_library": "Buscar género en la biblioteca",
"genre_search_source": "Explorar en la fuente",
"source_not_added": "¡La fuente no está instalada!",
"load_own_subtitles": "Cargar tus propios subtítulos..."
"load_own_subtitles": "Cargar tus propios subtítulos...",
"unsupported_repo": "Has intentado añadir un repositorio no soportado. Por favor, ¡consulta el servidor discord para soporte!"
}
3 changes: 2 additions & 1 deletion lib/l10n/app_es_419.arb
Original file line number Diff line number Diff line change
Expand Up @@ -463,5 +463,6 @@
"genre_search_library": "Buscar género en la biblioteca",
"genre_search_source": "Explorar en la fuente",
"source_not_added": "¡La fuente no está instalada!",
"load_own_subtitles": "Cargar tus propios subtítulos..."
"load_own_subtitles": "Cargar tus propios subtítulos...",
"unsupported_repo": "Has intentado añadir un repositorio no soportado. Por favor, ¡consulta el servidor discord para soporte!"
}
3 changes: 2 additions & 1 deletion lib/l10n/app_fr.arb
Original file line number Diff line number Diff line change
Expand Up @@ -463,5 +463,6 @@
"genre_search_library": "Rechercher un genre dans la bibliothèque",
"genre_search_source": "Explorer dans la source",
"source_not_added": "La source n'est pas installée !",
"load_own_subtitles": "Charger vos propres sous-titres..."
"load_own_subtitles": "Charger vos propres sous-titres...",
"unsupported_repo": "Vous avez essayé d'ajouter un dépôt qui n'est pas pris en charge. Veuillez consulter le serveur discord pour obtenir de l'aide!"
}
3 changes: 2 additions & 1 deletion lib/l10n/app_id.arb
Original file line number Diff line number Diff line change
Expand Up @@ -463,5 +463,6 @@
"genre_search_library": "Cari genre di perpustakaan",
"genre_search_source": "Jelajahi di sumber",
"source_not_added": "Sumber tidak diinstal!",
"load_own_subtitles": "Muat subtitle Anda sendiri..."
"load_own_subtitles": "Muat subtitle Anda sendiri...",
"unsupported_repo": "Anda telah mencoba menambahkan repositori yang tidak didukung. Silakan periksa server discord untuk mendapatkan dukungan!"
}
3 changes: 2 additions & 1 deletion lib/l10n/app_it.arb
Original file line number Diff line number Diff line change
Expand Up @@ -463,5 +463,6 @@
"genre_search_library": "Cerca genere nella libreria",
"genre_search_source": "Esplora nella fonte",
"source_not_added": "La fonte non è installata!",
"load_own_subtitles": "Carica i tuoi sottotitoli..."
"load_own_subtitles": "Carica i tuoi sottotitoli...",
"unsupported_repo": "Hai provato ad aggiungere un repository non supportato. Controlla il server discord per ricevere supporto!"
}
3 changes: 2 additions & 1 deletion lib/l10n/app_pt.arb
Original file line number Diff line number Diff line change
Expand Up @@ -463,5 +463,6 @@
"genre_search_library": "Pesquisar gênero na biblioteca",
"genre_search_source": "Explorar na fonte",
"source_not_added": "A fonte não está instalada!",
"load_own_subtitles": "Carregar suas próprias legendas..."
"load_own_subtitles": "Carregar suas próprias legendas...",
"unsupported_repo": "Tentou adicionar um repositório não suportado. Por favor, verifique o servidor discord para obter suporte!"
}
3 changes: 2 additions & 1 deletion lib/l10n/app_pt_BR.arb
Original file line number Diff line number Diff line change
Expand Up @@ -463,5 +463,6 @@
"genre_search_library": "Pesquisar gênero na biblioteca",
"genre_search_source": "Explorar na fonte",
"source_not_added": "A fonte não está instalada!",
"load_own_subtitles": "Carregar suas próprias legendas..."
"load_own_subtitles": "Carregar suas próprias legendas...",
"unsupported_repo": "Você tentou adicionar um repositório sem suporte. Consulte o servidor do Discord para obter suporte!"
}
3 changes: 2 additions & 1 deletion lib/l10n/app_ru.arb
Original file line number Diff line number Diff line change
Expand Up @@ -463,5 +463,6 @@
"genre_search_library": "Поиск жанра в библиотеке",
"genre_search_source": "Просмотр в источнике",
"source_not_added": "Источник не установлен!",
"load_own_subtitles": "Загрузить свои собственные субтитры..."
"load_own_subtitles": "Загрузить свои собственные субтитры...",
"unsupported_repo": "Вы попытались добавить неподдерживаемый репозиторий. Пожалуйста, обратитесь за поддержкой на сервер discord!"
}
3 changes: 2 additions & 1 deletion lib/l10n/app_th.arb
Original file line number Diff line number Diff line change
Expand Up @@ -466,5 +466,6 @@
"genre_search_library": "ค้นหาประเภทในห้องสมุด",
"genre_search_source": "เรียกดูในแหล่งข้อมูล",
"source_not_added": "แหล่งข้อมูลไม่ได้ติดตั้ง!",
"load_own_subtitles": "โหลดคำบรรยายของคุณเอง..."
"load_own_subtitles": "โหลดคำบรรยายของคุณเอง...",
"unsupported_repo": "คุณพยายามเพิ่มที่เก็บข้อมูลที่ไม่รองรับ โปรดตรวจสอบเซิร์ฟเวอร์ Discord เพื่อรับการสนับสนุน!"
}
3 changes: 2 additions & 1 deletion lib/l10n/app_tr.arb
Original file line number Diff line number Diff line change
Expand Up @@ -463,5 +463,6 @@
"genre_search_library": "Kütüphanede tür ara",
"genre_search_source": "Kaynağı keşfet",
"source_not_added": "Kaynak yüklenmedi!",
"load_own_subtitles": "Kendi altyazılarınızı yükleyin..."
"load_own_subtitles": "Kendi altyazılarınızı yükleyin...",
"unsupported_repo": "Desteklenmeyen bir depo eklemeye çalıştınız. Lütfen destek için discord sunucusunu kontrol edin!"
}
3 changes: 2 additions & 1 deletion lib/l10n/app_zh.arb
Original file line number Diff line number Diff line change
Expand Up @@ -468,5 +468,6 @@
"genre_search_library": "按类别搜索图书馆",
"genre_search_source": "按类别搜索来源",
"source_not_added": "来源未添加",
"load_own_subtitles": "加载自定义字幕"
"load_own_subtitles": "加载自定义字幕",
"unsupported_repo": "您试图添加不支持的版本库。请查看 discord 服务器以获得支持!"
}
6 changes: 6 additions & 0 deletions lib/l10n/generated/app_localizations.dart
Original file line number Diff line number Diff line change
Expand Up @@ -2912,6 +2912,12 @@ abstract class AppLocalizations {
/// In en, this message translates to:
/// **'Notes: {notes}'**
String extension_notes(Object notes);

/// No description provided for @unsupported_repo.
///
/// In en, this message translates to:
/// **'You\'ve tried to add an unsupported repository. Please check the discord server for support!'**
String get unsupported_repo;
}

class _AppLocalizationsDelegate extends LocalizationsDelegate<AppLocalizations> {
Expand Down
3 changes: 3 additions & 0 deletions lib/l10n/generated/app_localizations_ar.dart
Original file line number Diff line number Diff line change
Expand Up @@ -1455,4 +1455,7 @@ class AppLocalizationsAr extends AppLocalizations {
String extension_notes(Object notes) {
return 'Notes: $notes';
}

@override
String get unsupported_repo => 'لقد حاولت إضافة مستودع غير مدعوم. يرجى التحقق من خادم الخلاف للحصول على الدعم!';
}
3 changes: 3 additions & 0 deletions lib/l10n/generated/app_localizations_de.dart
Original file line number Diff line number Diff line change
Expand Up @@ -1455,4 +1455,7 @@ class AppLocalizationsDe extends AppLocalizations {
String extension_notes(Object notes) {
return 'Hinweis: $notes';
}

@override
String get unsupported_repo => 'Du hast gerade versucht, ein ungültiges Repository hinzuzufügen. Bitte schau mal beim Discord Server vorbei!';
}
3 changes: 3 additions & 0 deletions lib/l10n/generated/app_localizations_en.dart
Original file line number Diff line number Diff line change
Expand Up @@ -1455,4 +1455,7 @@ class AppLocalizationsEn extends AppLocalizations {
String extension_notes(Object notes) {
return 'Notes: $notes';
}

@override
String get unsupported_repo => 'You\'ve tried to add an unsupported repository. Please check the discord server for support!';
}
6 changes: 6 additions & 0 deletions lib/l10n/generated/app_localizations_es.dart
Original file line number Diff line number Diff line change
Expand Up @@ -1455,6 +1455,9 @@ class AppLocalizationsEs extends AppLocalizations {
String extension_notes(Object notes) {
return 'Notes: $notes';
}

@override
String get unsupported_repo => 'Has intentado añadir un repositorio no soportado. Por favor, ¡consulta el servidor discord para soporte!';
}

/// The translations for Spanish Castilian, as used in Latin America and the Caribbean (`es_419`).
Expand Down Expand Up @@ -2894,4 +2897,7 @@ class AppLocalizationsEs419 extends AppLocalizationsEs {

@override
String get load_own_subtitles => 'Cargar tus propios subtítulos...';

@override
String get unsupported_repo => 'Has intentado añadir un repositorio no soportado. Por favor, ¡consulta el servidor discord para soporte!';
}
3 changes: 3 additions & 0 deletions lib/l10n/generated/app_localizations_fr.dart
Original file line number Diff line number Diff line change
Expand Up @@ -1455,4 +1455,7 @@ class AppLocalizationsFr extends AppLocalizations {
String extension_notes(Object notes) {
return 'Notes: $notes';
}

@override
String get unsupported_repo => 'Vous avez essayé d\'ajouter un dépôt qui n\'est pas pris en charge. Veuillez consulter le serveur discord pour obtenir de l\'aide!';
}
3 changes: 3 additions & 0 deletions lib/l10n/generated/app_localizations_id.dart
Original file line number Diff line number Diff line change
Expand Up @@ -1455,4 +1455,7 @@ class AppLocalizationsId extends AppLocalizations {
String extension_notes(Object notes) {
return 'Notes: $notes';
}

@override
String get unsupported_repo => 'Anda telah mencoba menambahkan repositori yang tidak didukung. Silakan periksa server discord untuk mendapatkan dukungan!';
}
3 changes: 3 additions & 0 deletions lib/l10n/generated/app_localizations_it.dart
Original file line number Diff line number Diff line change
Expand Up @@ -1455,4 +1455,7 @@ class AppLocalizationsIt extends AppLocalizations {
String extension_notes(Object notes) {
return 'Notes: $notes';
}

@override
String get unsupported_repo => 'Hai provato ad aggiungere un repository non supportato. Controlla il server discord per ricevere supporto!';
}
6 changes: 6 additions & 0 deletions lib/l10n/generated/app_localizations_pt.dart
Original file line number Diff line number Diff line change
Expand Up @@ -1455,6 +1455,9 @@ class AppLocalizationsPt extends AppLocalizations {
String extension_notes(Object notes) {
return 'Notes: $notes';
}

@override
String get unsupported_repo => 'Tentou adicionar um repositório não suportado. Por favor, verifique o servidor discord para obter suporte!';
}

/// The translations for Portuguese, as used in Brazil (`pt_BR`).
Expand Down Expand Up @@ -2894,4 +2897,7 @@ class AppLocalizationsPtBr extends AppLocalizationsPt {

@override
String get load_own_subtitles => 'Carregar suas próprias legendas...';

@override
String get unsupported_repo => 'Você tentou adicionar um repositório sem suporte. Consulte o servidor do Discord para obter suporte!';
}
3 changes: 3 additions & 0 deletions lib/l10n/generated/app_localizations_ru.dart
Original file line number Diff line number Diff line change
Expand Up @@ -1455,4 +1455,7 @@ class AppLocalizationsRu extends AppLocalizations {
String extension_notes(Object notes) {
return 'Notes: $notes';
}

@override
String get unsupported_repo => 'Вы попытались добавить неподдерживаемый репозиторий. Пожалуйста, обратитесь за поддержкой на сервер discord!';
}
3 changes: 3 additions & 0 deletions lib/l10n/generated/app_localizations_th.dart
Original file line number Diff line number Diff line change
Expand Up @@ -1455,4 +1455,7 @@ class AppLocalizationsTh extends AppLocalizations {
String extension_notes(Object notes) {
return 'Notes: $notes';
}

@override
String get unsupported_repo => 'คุณพยายามเพิ่มที่เก็บข้อมูลที่ไม่รองรับ โปรดตรวจสอบเซิร์ฟเวอร์ Discord เพื่อรับการสนับสนุน!';
}
3 changes: 3 additions & 0 deletions lib/l10n/generated/app_localizations_tr.dart
Original file line number Diff line number Diff line change
Expand Up @@ -1455,4 +1455,7 @@ class AppLocalizationsTr extends AppLocalizations {
String extension_notes(Object notes) {
return 'Notes: $notes';
}

@override
String get unsupported_repo => 'Desteklenmeyen bir depo eklemeye çalıştınız. Lütfen destek için discord sunucusunu kontrol edin!';
}
3 changes: 3 additions & 0 deletions lib/l10n/generated/app_localizations_zh.dart
Original file line number Diff line number Diff line change
Expand Up @@ -1455,4 +1455,7 @@ class AppLocalizationsZh extends AppLocalizations {
String extension_notes(Object notes) {
return 'Notes: $notes';
}

@override
String get unsupported_repo => '您试图添加不支持的版本库。请查看 discord 服务器以获得支持!';
}
36 changes: 34 additions & 2 deletions lib/main.dart
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
import 'dart:async';
import 'dart:convert';
import 'dart:io';
import 'package:app_links/app_links.dart';
import 'package:bot_toast/bot_toast.dart';
Expand All @@ -12,13 +13,15 @@ import 'package:isar/isar.dart';
import 'package:mangayomi/eval/model/m_bridge.dart';
import 'package:mangayomi/models/manga.dart';
import 'package:mangayomi/models/settings.dart';
import 'package:mangayomi/models/source.dart';
import 'package:mangayomi/modules/more/data_and_storage/providers/storage_usage.dart';
import 'package:mangayomi/modules/more/settings/browse/providers/browse_state_provider.dart';
import 'package:mangayomi/providers/l10n_providers.dart';
import 'package:mangayomi/providers/storage_provider.dart';
import 'package:mangayomi/router/router.dart';
import 'package:mangayomi/modules/more/settings/appearance/providers/theme_mode_state_provider.dart';
import 'package:mangayomi/l10n/generated/app_localizations.dart';
import 'package:mangayomi/services/http/m_client.dart';
import 'package:mangayomi/src/rust/frb_generated.dart';
import 'package:mangayomi/utils/url_protocol/api.dart';
import 'package:mangayomi/modules/more/settings/appearance/providers/theme_provider.dart';
Expand Down Expand Up @@ -160,8 +163,19 @@ class _MyAppState extends ConsumerState<MyApp> {
),
FilledButton(
child: Text(l10n.add),
onPressed: () {
Navigator.of(context).pop();
onPressed: () async {
if (context.mounted) Navigator.of(context).pop();

final validUrls = await _checkValidUrls([
...mangaRepoUrls ?? [],
...animeRepoUrls ?? [],
...novelRepoUrls ?? [],
]);

if (!validUrls) {
botToast(l10n.unsupported_repo);
return;
}

void addRepos(ItemType type, List<String>? urls) {
if (urls == null) return;
Expand Down Expand Up @@ -198,4 +212,22 @@ class _MyAppState extends ConsumerState<MyApp> {
}
});
}

Future<bool> _checkValidUrls(List<String> urls) async {
final http = MClient.init(reqcopyWith: {'useDartHttpClient': true});
for (final url in urls) {
final req = await http.get(Uri.parse(url));
try {
final sourceList = (jsonDecode(req.body) as List).map(
(e) => Source.fromJson(e),
);
if (sourceList.firstOrNull?.name == null) {
return false;
}
} catch (err) {
return false;
}
}
return true;
}
}
9 changes: 4 additions & 5 deletions lib/modules/library/providers/file_scanner.g.dart

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

2 changes: 1 addition & 1 deletion lib/modules/more/data_and_storage/providers/restore.g.dart

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

Loading