-
Notifications
You must be signed in to change notification settings - Fork 41
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge pull request #312 from TaYaKi71751/dev-bookmark-export-to-git
Add Bookmark Import/Export to Git Repository with ssh key
- Loading branch information
Showing
16 changed files
with
767 additions
and
1 deletion.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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; | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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( | ||
'잠시만 기다려주세요...', | ||
), | ||
), | ||
), | ||
], | ||
), | ||
), | ||
), | ||
), | ||
), | ||
], | ||
), | ||
), | ||
); | ||
} | ||
} |
Oops, something went wrong.