Skip to content

Commit

Permalink
import ban list init
Browse files Browse the repository at this point in the history
  • Loading branch information
Notsfsssf committed Nov 24, 2024
1 parent 9998b45 commit d1e3e7c
Show file tree
Hide file tree
Showing 4 changed files with 74 additions and 3 deletions.
11 changes: 11 additions & 0 deletions lib/models/ban_illust_id.dart
Original file line number Diff line number Diff line change
Expand Up @@ -62,6 +62,17 @@ create table $tableBanIllustId (
return todo;
}

Future<List<BanIllustIdPersist>> insertAll(
List<BanIllustIdPersist> todos) async {
await db.transaction((txn) async {
for (var todo in todos) {
todo.id = await txn.insert(tableBanIllustId, todo.toJson(),
conflictAlgorithm: ConflictAlgorithm.replace);
}
});
return todos;
}

Future<BanIllustIdPersist?> getAccount(int id) async {
List<Map<String, dynamic>> maps = await db.query(tableBanIllustId,
columns: [columnId, columnIllustId],
Expand Down
17 changes: 14 additions & 3 deletions lib/models/ban_tag.dart
Original file line number Diff line number Diff line change
Expand Up @@ -17,17 +17,18 @@ import 'package:json_annotation/json_annotation.dart';
import 'package:path/path.dart';
import 'package:sqflite_common_ffi/sqflite_ffi.dart';
part 'ban_tag.g.dart';

@JsonSerializable()
class BanTagPersist {
int? id;
String name;
@JsonKey(name: 'translate_name')
String translateName;

BanTagPersist(
{ this.id, required this.name, required this.translateName});
BanTagPersist({this.id, required this.name, required this.translateName});

factory BanTagPersist.fromJson(Map<String, dynamic> json) => _$BanTagPersistFromJson(json);
factory BanTagPersist.fromJson(Map<String, dynamic> json) =>
_$BanTagPersistFromJson(json);
Map<String, dynamic> toJson() => _$BanTagPersistToJson(this);
}

Expand Down Expand Up @@ -99,4 +100,14 @@ create table $tableBanTag (
}

Future close() async => db.close();

Future<List<BanTagPersist>> insertAll(List<BanTagPersist> list) async {
await db.transaction((txn) async {
for (var todo in list) {
todo.id = await txn.insert(tableBanTag, todo.toJson(),
conflictAlgorithm: ConflictAlgorithm.replace);
}
});
return list;
}
}
11 changes: 11 additions & 0 deletions lib/models/ban_user_id.dart
Original file line number Diff line number Diff line change
Expand Up @@ -106,4 +106,15 @@ create table $tableBanUserId (
}

Future close() async => db.close();

Future<List<BanUserIdPersist>> insertAll(
List<BanUserIdPersist> list) async {
await db.transaction((txn) async {
for (var todo in list) {
todo.id = await txn.insert(tableBanUserId, todo.toJson(),
conflictAlgorithm: ConflictAlgorithm.replace);
}
});
return list;
}
}
38 changes: 38 additions & 0 deletions lib/store/mute_store.dart
Original file line number Diff line number Diff line change
Expand Up @@ -15,6 +15,7 @@
*/

import 'dart:convert';
import 'dart:typed_data';

import 'package:mobx/mobx.dart';
import 'package:pixez/er/lprinter.dart';
Expand All @@ -23,6 +24,7 @@ import 'package:pixez/models/ban_illust_id.dart';
import 'package:pixez/models/ban_tag.dart';
import 'package:pixez/models/ban_user_id.dart';
import 'package:pixez/models/comment_response.dart';
import 'package:pixez/saf_plugin.dart';
import 'package:shared_preferences/shared_preferences.dart';

part 'mute_store.g.dart';
Expand Down Expand Up @@ -157,6 +159,42 @@ abstract class _MuteStoreBase with Store {
"bantag": banTag
};
final exportJson = jsonEncode(entity);
final uri = await SAFPlugin.createFile(
"pixez_mute_${DateTime.now().toIso8601String()}.json",
"application/json");
LPrinter.d("exportJson:$exportJson");
if (uri != null) {
await SAFPlugin.writeUri(
uri, Uint8List.fromList(utf8.encode(exportJson)));
}
}

importFile() async {
final uri = await SAFPlugin.openFile();
if (uri != null) {
final data = utf8.decode(uri);
final entity = jsonDecode(data);
final banIllust = entity["banillustid"];
final banUser = entity["banuserid"];
final banTag = entity["bantag"];
await banIllustIdProvider.open();
await banUserIdProvider.open();
await banTagProvider.open();
if (banIllust is List) {
await banIllustIdProvider.insertAll(
banIllust.map((e) => BanIllustIdPersist.fromJson(e)).toList());
}
if (banUser is List) {
await banUserIdProvider.insertAll(
banUser.map((e) => BanUserIdPersist.fromJson(e)).toList());
}
if (banTag is List) {
await banTagProvider
.insertAll(banTag.map((e) => BanTagPersist.fromJson(e)).toList());
}
await fetchBanIllusts();
await fetchBanUserIds();
await fetchBanTags();
}
}
}

0 comments on commit d1e3e7c

Please sign in to comment.