Skip to content
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

Add Bookmark Import/Export to Git Repository with ssh key #312

Merged
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
2 changes: 2 additions & 0 deletions assets/locale/en.json
Original file line number Diff line number Diff line change
Expand Up @@ -152,6 +152,7 @@
"thisislatestbookmark": "Database is already up to date.",
"importingbookmark": "Import Bookmark",
"exportingbookmark": "Export Bookmark",
"exportingbookmarkgit": "Export Bookmark to Git Repository",
"noauth": "You do not have permission to run it.",
"noselectedb": "No database selected.",
"importbookmark": "Bookmark Imported!",
Expand Down Expand Up @@ -228,6 +229,7 @@
"movetoappbartobottom": "Move Buttons To Bottom",
"showslider": "Show Slider",
"importfromeh": "Import From E/Ex-Hentai",
"importfromgit": "Import From Git Repository",
"setcookiefirst": "Set Cookie First!",
"bookmarkisempty": "Bookmark is empty!",
"ensurecreatebookmark": "Would you like to add $1 item to your bookmarks? (Groups are created for each Favorite.)",
Expand Down
2 changes: 2 additions & 0 deletions assets/locale/eo.json
Original file line number Diff line number Diff line change
Expand Up @@ -152,6 +152,7 @@
"thisislatestbookmark": "Los datos ya están actualizados.",
"importingbookmark": "Importar Marcador",
"exportingbookmark": "Exportar Marcador",
"exportingbookmarkgit": "Export Bookmark to Git Repository",
"noauth": "No tienes permiso para iniciar.",
"noselectedb": "No se ha seleccionado ninguna base de datos.",
"importbookmark": "¡Marcador Importado!",
Expand Down Expand Up @@ -228,6 +229,7 @@
"movetoappbartobottom": "Move Buttons To Bottom",
"showslider": "Show Slider",
"importfromeh": "Import From E/Ex-Hentai",
"importfromgit": "Import From Git Repository",
"setcookiefirst": "Set Cookie First!",
"bookmarkisempty": "Bookmark is empty!",
"ensurecreatebookmark": "Would you like to add $1 item to your bookmarks? (Groups are created for each Favorite.)",
Expand Down
2 changes: 2 additions & 0 deletions assets/locale/it.json
Original file line number Diff line number Diff line change
Expand Up @@ -152,6 +152,7 @@
"thisislatestbookmark": "Il database è aggiornato.",
"importingbookmark": "Importa Segnalibri",
"exportingbookmark": "Esporta Segnalibri",
"exportingbookmarkgit": "Export Bookmark to Git Repository",
"noauth": "Non hai il permesso di avviarlo.",
"noselectedb": "Nessun database selezionato.",
"importbookmark": "Segnalibri Importati!",
Expand Down Expand Up @@ -228,6 +229,7 @@
"movetoappbartobottom": "Move Buttons To Bottom",
"showslider": "Show Slider",
"importfromeh": "Import From E/Ex-Hentai",
"importfromgit": "Import From Git Repository",
"setcookiefirst": "Set Cookie First!",
"bookmarkisempty": "Bookmark is empty!",
"ensurecreatebookmark": "Would you like to add $1 item to your bookmarks? (Groups are created for each Favorite.)",
Expand Down
2 changes: 2 additions & 0 deletions assets/locale/ja.json
Original file line number Diff line number Diff line change
Expand Up @@ -152,6 +152,7 @@
"thisislatestbookmark": "データベースがすでに最新の状態です。",
"importingbookmark": "ブックマークを読み込む",
"exportingbookmark": "ブックマークの書き出す",
"exportingbookmarkgit": "Export Bookmark to Git Repository",
"noauth": "権限がないため、実行できません。",
"noselectedb": "選択されたデータベースがありません。",
"importbookmark": "ブックマークを読み込みしました!",
Expand Down Expand Up @@ -228,6 +229,7 @@
"movetoappbartobottom": "ボタンを下に移動させる",
"showslider": "スライダー表示",
"importfromeh": "E/Ex-Hentaiから読み込む",
"importfromgit": "Import From Git Repository",
"setcookiefirst": "クッキーを設定してください!",
"bookmarkisempty": "ブックマークがありません!",
"ensurecreatebookmark": "$1個の項目をブックマークに追加しますか?(Favorite別のグループが作成されます。)",
Expand Down
2 changes: 2 additions & 0 deletions assets/locale/ko.json
Original file line number Diff line number Diff line change
Expand Up @@ -152,6 +152,7 @@
"thisislatestbookmark": "데이터베이스가 이미 최신상태입니다.",
"importingbookmark": "북마크 가져오기",
"exportingbookmark": "북마크 내보내기",
"exportingbookmarkgit": "Export Bookmark to Git Repository",
"noauth": "권한이 없어서 실행할 수 없습니다.",
"noselectedb": "선택된 데이터베이스가 없습니다.",
"importbookmark": "북마크를 가져왔습니다!",
Expand Down Expand Up @@ -228,6 +229,7 @@
"movetoappbartobottom": "버튼 밑으로 내리기",
"showslider": "슬라이더 보여주기",
"importfromeh": "이/익헨에서 불러오기",
"importfromgit": "Import From Git Repository",
"setcookiefirst": "쿠키를 먼저 설정하세요!",
"bookmarkisempty": "북마크가 비어있어요!",
"ensurecreatebookmark": "$1개 항목을 북마크에 추가할까요? (각 Favorite별로 그룹이 생성됩니다.)",
Expand Down
2 changes: 2 additions & 0 deletions assets/locale/pt.json
Original file line number Diff line number Diff line change
Expand Up @@ -152,6 +152,7 @@
"thisislatestbookmark": "O banco de dados já está atualizado.",
"importingbookmark": "Importar marcador",
"exportingbookmark": "Exportar marcador",
"exportingbookmarkgit": "Export Bookmark to Git Repository",
"noauth": "Você não tem permissão para executar isso.",
"noselectedb": "Nenhum banco de dados selecionado.",
"importbookmark": "Marcador importado!",
Expand Down Expand Up @@ -228,6 +229,7 @@
"movetoappbartobottom": "Mover botões para baixo",
"showslider": "Mostrar controle deslizante",
"importfromeh": "Importar de E/Ex-Hentai",
"importfromgit": "Import From Git Repository",
"setcookiefirst": "Defina o cookie primeiro!",
"bookmarkisempty": "O marcador está vazio!",
"ensurecreatebookmark": "Gostaria de adicionar $ 1 item aos seus marcadores? (Grupos são criados para cada Favorito.)",
Expand Down
2 changes: 2 additions & 0 deletions assets/locale/zh.json
Original file line number Diff line number Diff line change
Expand Up @@ -152,6 +152,7 @@
"thisislatestbookmark": "Database is already up to date.",
"importingbookmark": "Import Bookmark",
"exportingbookmark": "Export Bookmark",
"exportingbookmarkgit": "Export Bookmark to Git Repository",
"noauth": "You do not have permission to run it.",
"noselectedb": "No database selected.",
"importbookmark": "Bookmark Imported!",
Expand Down Expand Up @@ -228,6 +229,7 @@
"movetoappbartobottom": "Move Buttons To Bottom",
"showslider": "Show Slider",
"importfromeh": "Import From E/Ex-Hentai",
"importfromgit": "Import From Git Repository",
"setcookiefirst": "Set Cookie First!",
"bookmarkisempty": "Bookmark is empty!",
"ensurecreatebookmark": "Would you like to add $1 item to your bookmarks? (Groups are created for each Favorite.)",
Expand Down
2 changes: 2 additions & 0 deletions assets/locale/zh_Hans.json
Original file line number Diff line number Diff line change
Expand Up @@ -152,6 +152,7 @@
"thisislatestbookmark": "数据库已经是最新的.",
"importingbookmark": "导入书签",
"exportingbookmark": "导出书签",
"exportingbookmarkgit": "Export Bookmark to Git Repository",
"noauth": "你没有权限执行此操作.",
"noselectedb": "没有数据库被选中.",
"importbookmark": "书签导入成功!",
Expand Down Expand Up @@ -228,6 +229,7 @@
"movetoappbartobottom": "Move Buttons To Bottom",
"showslider": "Show Slider",
"importfromeh": "Import From E/Ex-Hentai",
"importfromgit": "Import From Git Repository",
"setcookiefirst": "Set Cookie First!",
"bookmarkisempty": "Bookmark is empty!",
"ensurecreatebookmark": "Would you like to add $1 item to your bookmarks? (Groups are created for each Favorite.)",
Expand Down
2 changes: 2 additions & 0 deletions assets/locale/zh_Hant.json
Original file line number Diff line number Diff line change
Expand Up @@ -152,6 +152,7 @@
"thisislatestbookmark": "Database is already up to date.",
"importingbookmark": "Import Bookmark",
"exportingbookmark": "Export Bookmark",
"exportingbookmarkgit": "Export Bookmark to Git Repository",
"noauth": "You do not have permission to run it.",
"noselectedb": "No database selected.",
"importbookmark": "Bookmark Imported!",
Expand Down Expand Up @@ -228,6 +229,7 @@
"movetoappbartobottom": "Move Buttons To Bottom",
"showslider": "Show Slider",
"importfromeh": "Import From E/Ex-Hentai",
"importfromgit": "Import From Git Repository",
"setcookiefirst": "Set Cookie First!",
"bookmarkisempty": "Bookmark is empty!",
"ensurecreatebookmark": "Would you like to add $1 item to your bookmarks? (Groups are created for each Favorite.)",
Expand Down
120 changes: 120 additions & 0 deletions lib/component/git/git_bookmark.dart
Original file line number Diff line number Diff line change
@@ -0,0 +1,120 @@
// This source code is a part of Project Violet.
// Copyright (C) 2020-2024. violet-team. Licensed under the Apache-2.0 License.

import 'dart:collection';
import 'dart:io';

import 'package:path_provider/path_provider.dart';
import 'package:sqflite/sqflite.dart';
import 'package:violet/util/git.dart';

class BookmarkGroupKeyVal {
int? id;
String? name;
String? dateTime;
String? description;
int? color;
int? gorder;
}

class BookmarkArticleKeyVal {
int? id;
int? article;
String? dateTime;
int? groupId;
}

class GitBookmark {
static Map<BookmarkGroupKeyVal, List<BookmarkArticleKeyVal>>? bookmarkInfo;
static Future<Map<BookmarkGroupKeyVal, List<BookmarkArticleKeyVal>>?>
process() async {
// https://e-hentai.org/favorites.php?page=0&favcat=0
// https://exhentai.org/favorites.php?page=0&favcat=0

Map<BookmarkGroupKeyVal, List<BookmarkArticleKeyVal>> result =
<BookmarkGroupKeyVal, List<BookmarkArticleKeyVal>>{};

final gitPath =
'${(await getTemporaryDirectory()).path}/_tmp_bookmark_from_git';
if (await Directory(gitPath).exists()) {
await Directory(gitPath).delete(recursive: true);
}
BookmarkGit git = BookmarkGit();
await git.clone(gitPath);
String getRelatedPath(String absolutePath) {
return absolutePath
.replaceAll(gitPath, '')
.split('/')
.where((p) => p.isNotEmpty)
.join('/');
}

List<FileSystemEntity> getList() {
return Directory(gitPath)
.listSync(recursive: true, followLinks: false)
.where((absolutePath) =>
getRelatedPath(absolutePath.path)
.split('/')
.firstOrNull
?.isNotEmpty ??
false)
.where((absolutePath) =>
getRelatedPath(absolutePath.path).split('/').firstOrNull !=
'.git')
.toList();
}

if (await Directory(gitPath).exists()) {
final listInPath = getList();
print(listInPath);
await Future.forEach(listInPath, (absolutePath) async {
final relativePath = getRelatedPath(absolutePath.path);
if (relativePath.split('/').isNotEmpty) {
if (relativePath.split('/').firstOrNull != '.git') {
if (relativePath.split('/').lastOrNull?.endsWith('.db') ?? false) {
Database db = await openDatabase(absolutePath.path);
final bookmarkGroups = await db.query('BookmarkGroup');
for (var bookmarkGroup in bookmarkGroups) {
BookmarkGroupKeyVal group = BookmarkGroupKeyVal();
// "Id", "Name", "DateTime", "Description", "Color", "Gorder"
// Int, String, String , String , Int , Int
bookmarkGroup.forEach((key, value) {
if (key == 'Id') group.id = int.tryParse(value.toString());
if (key == 'Name') group.name = value.toString();
if (key == 'DataTime') group.dateTime = value.toString();
if (key == 'Description')
group.description = value.toString();
if (key == 'Color')
group.color = int.tryParse(value.toString());
if (key == 'Gorder')
group.gorder = int.tryParse(value.toString());
});
final bookmarkArticles = await db.query('BookmarkArticle');
// "Id", "Article", "DateTime", "GroupId"
// Int, Int , String , Int
for (final bookmarkArticle in bookmarkArticles) {
BookmarkArticleKeyVal article = BookmarkArticleKeyVal();
bookmarkArticle.forEach((key, value) {
if (key == 'Id')
article.id = int.tryParse(value.toString());
if (key == 'Article')
article.article = int.tryParse(value.toString());
if (key == 'DateTime') article.dateTime = value.toString();
if (key == 'GroupId')
article.groupId = int.tryParse(value.toString());
});
if (group.gorder == article.groupId) {
result[group] ??= <BookmarkArticleKeyVal>[];
result[group]!.add(article);
}
}
}
await db.close();
}
}
}
});
}
return bookmarkInfo = result;
}
}
104 changes: 104 additions & 0 deletions lib/pages/settings/import_from_git.dart
Original file line number Diff line number Diff line change
@@ -0,0 +1,104 @@
// This source code is a part of Project Violet.
// Copyright (C) 2020-2024. violet-team. Licensed under the Apache-2.0 License.

import 'package:flutter/material.dart';
import 'package:violet/component/git/git_bookmark.dart';
import 'package:violet/settings/settings.dart';
import 'package:violet/style/palette.dart';

class ImportFromGitPage extends StatefulWidget {
const ImportFromGitPage({super.key});

@override
State<ImportFromGitPage> createState() => _ImportFromGitState();
}

class _ImportFromGitState extends State<ImportFromGitPage> {
@override
void initState() {
super.initState();

Future.delayed(const Duration(milliseconds: 100)).then((value) async {
await GitBookmark.process();

Navigator.pop(context);
});
}

@override
Widget build(BuildContext context) {
return PopScope(
canPop: false,
child: Container(
decoration: BoxDecoration(
borderRadius: const BorderRadius.all(Radius.circular(1)),
boxShadow: [
BoxShadow(
color: Settings.themeWhat
? Colors.black.withOpacity(0.4)
: Colors.grey.withOpacity(0.2),
spreadRadius: 1,
blurRadius: 1,
offset: const Offset(0, 3), // changes position of shadow
),
],
),
child: Column(
mainAxisAlignment: MainAxisAlignment.center,
crossAxisAlignment: CrossAxisAlignment.center,
children: <Widget>[
Card(
color: Settings.themeWhat
? Palette.darkThemeBackground
: Palette.lightThemeBackground,
elevation: 100,
child: SizedBox(
child: SizedBox(
width: 280,
height: (56 * 4 + 16).toDouble(),
child: const Padding(
padding: EdgeInsets.fromLTRB(0, 8, 0, 8),
// child: Column(
// mainAxisAlignment: MainAxisAlignment.center,
// children: <Widget>[
// CircularProgressIndicator(),
// Expanded(
// child: Container(child: Text('초기화 중...')),
// )
// ],
// ),
child: Stack(
children: [
Center(
child: CircularProgressIndicator(),
),
Align(
alignment: Alignment.bottomCenter,
child: Padding(
padding: EdgeInsets.only(bottom: 33),
child: Text(
'가져오는 중',
),
),
),
Align(
alignment: Alignment.bottomCenter,
child: Padding(
padding: EdgeInsets.only(bottom: 15),
child: Text(
'잠시만 기다려주세요...',
),
),
),
],
),
),
),
),
),
],
),
),
);
}
}
Loading
Loading