Add provider tag suggestions and tag categories
This commit is contained in:
@@ -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 {},
|
||||
);
|
||||
}
|
||||
|
||||
@@ -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,
|
||||
};
|
||||
}
|
||||
Reference in New Issue
Block a user