Add provider tag suggestions and tag categories

This commit is contained in:
2026-05-23 15:41:23 +03:00
parent 1b763c4d62
commit b02c776628
30 changed files with 1119 additions and 77 deletions
+10
View File
@@ -14,6 +14,7 @@ class Post {
required this.createdAt,
required this.fileType,
required this.score,
this.tagGroups = const {},
});
final String id;
@@ -30,6 +31,7 @@ class Post {
final DateTime createdAt;
final String fileType;
final int score;
final Map<String, List<String>> tagGroups;
String get cacheKey => '$providerId:$id';
@@ -48,6 +50,7 @@ class Post {
'createdAt': createdAt.toIso8601String(),
'fileType': fileType,
'score': score,
'tagGroups': tagGroups,
};
factory Post.fromJson(Map<String, dynamic> json) => Post(
@@ -66,5 +69,12 @@ class Post {
DateTime.fromMillisecondsSinceEpoch(0),
fileType: (json['fileType'] as String?) ?? 'unknown',
score: (json['score'] as num?)?.toInt() ?? 0,
tagGroups: (json['tagGroups'] as Map?)?.map(
(key, value) => MapEntry(
key.toString(),
List<String>.from((value as List?) ?? const []),
),
) ??
const {},
);
}
+38
View File
@@ -0,0 +1,38 @@
enum TagCategory {
general,
artist,
copyright,
character,
meta,
species,
unknown,
}
class TagSuggestion {
const TagSuggestion({
required this.name,
required this.category,
required this.postCount,
required this.providerId,
});
final String name;
final TagCategory category;
final int postCount;
final String providerId;
String get categoryLabel => category.name;
}
TagCategory tagCategoryFromString(String? value) {
final normalized = (value ?? '').toLowerCase();
return switch (normalized) {
'0' || 'general' => TagCategory.general,
'1' || 'artist' => TagCategory.artist,
'3' || 'copyright' || 'circle' => TagCategory.copyright,
'4' || 'character' => TagCategory.character,
'5' || 'meta' || 'metadata' => TagCategory.meta,
'species' => TagCategory.species,
_ => TagCategory.unknown,
};
}