117 lines
2.6 KiB
Dart
117 lines
2.6 KiB
Dart
class MediaItem {
|
|
final int id;
|
|
final String mime;
|
|
final int size;
|
|
final int stamp;
|
|
final String dest;
|
|
final int mode;
|
|
final List<Tag> tags;
|
|
final List<Favorite>? favorites;
|
|
|
|
MediaItem({
|
|
required this.id,
|
|
required this.mime,
|
|
required this.size,
|
|
required this.stamp,
|
|
required this.dest,
|
|
required this.mode,
|
|
required this.tags,
|
|
required this.favorites,
|
|
});
|
|
|
|
MediaItem copyWith({
|
|
int? id,
|
|
String? mime,
|
|
int? size,
|
|
int? stamp,
|
|
String? dest,
|
|
int? mode,
|
|
List<Tag>? tags,
|
|
List<Favorite>? favorites,
|
|
}) {
|
|
return MediaItem(
|
|
id: id ?? this.id,
|
|
mime: mime ?? this.mime,
|
|
size: size ?? this.size,
|
|
stamp: stamp ?? this.stamp,
|
|
dest: dest ?? this.dest,
|
|
mode: mode ?? this.mode,
|
|
tags: tags ?? this.tags,
|
|
favorites: favorites ?? this.favorites,
|
|
);
|
|
}
|
|
|
|
factory MediaItem.fromJson(Map<String, dynamic> json) {
|
|
List<Tag> parsedTags = [];
|
|
if (json['tags'] is List) {
|
|
parsedTags = (json['tags'] as List<dynamic>)
|
|
.map((tagJson) => Tag.fromJson(tagJson as Map<String, dynamic>))
|
|
.toList();
|
|
} else {
|
|
parsedTags = [];
|
|
}
|
|
|
|
List<Favorite> parsedFavorites = [];
|
|
if (json['favorites'] is List) {
|
|
parsedFavorites = (json['favorites'] as List<dynamic>)
|
|
.map(
|
|
(favoritesJson) =>
|
|
Favorite.fromJson(favoritesJson as Map<String, dynamic>),
|
|
)
|
|
.toList();
|
|
} else {
|
|
parsedFavorites = [];
|
|
}
|
|
|
|
return MediaItem(
|
|
id: json['id'],
|
|
mime: json['mime'],
|
|
size: json['size'],
|
|
stamp: json['stamp'],
|
|
dest: json['dest'],
|
|
mode: json['mode'],
|
|
tags: parsedTags,
|
|
favorites: parsedFavorites,
|
|
);
|
|
}
|
|
|
|
String get thumbnailUrl => 'https://f0ck.me/t/$id.webp';
|
|
String get mediaUrl => 'https://f0ck.me/b/$dest';
|
|
String get coverUrl => 'https://f0ck.me/ca/$id.webp';
|
|
String get postUrl => 'https://f0ck.me/$id';
|
|
}
|
|
|
|
class Tag {
|
|
final int id;
|
|
final String tag;
|
|
final String normalized;
|
|
|
|
Tag({required this.id, required this.tag, required this.normalized});
|
|
|
|
factory Tag.fromJson(Map<String, dynamic> json) {
|
|
return Tag(
|
|
id: json['id'],
|
|
tag: json['tag'],
|
|
normalized: json['normalized'],
|
|
);
|
|
}
|
|
}
|
|
|
|
class Favorite {
|
|
final int userId;
|
|
final String user;
|
|
final int avatar;
|
|
|
|
Favorite({required this.userId, required this.user, required this.avatar});
|
|
|
|
factory Favorite.fromJson(Map<String, dynamic> json) {
|
|
return Favorite(
|
|
userId: json['user_id'],
|
|
user: json['user'],
|
|
avatar: json['avatar'],
|
|
);
|
|
}
|
|
|
|
String get avatarUrl => 'https://f0ck.me/t/$avatar.webp';
|
|
}
|