Files
fApp/lib/models/item.dart
Flummi 405d388db0
All checks were successful
Flutter Schmutter / build (push) Successful in 3m46s
v1.4.6+67
2025-06-23 02:51:49 +02:00

123 lines
2.8 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;
final String? username;
final String? userchannel;
final String? usernetwork;
MediaItem({
required this.id,
required this.mime,
required this.size,
required this.stamp,
required this.dest,
required this.mode,
this.tags = const [],
this.favorites = const [],
this.username,
this.userchannel,
this.usernetwork,
});
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';
MediaItem copyWith({
int? id,
String? mime,
int? size,
int? stamp,
String? dest,
int? mode,
List<Tag>? tags,
List<Favorite>? favorites,
String? username,
String? userchannel,
String? usernetwork,
}) {
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,
username: username ?? this.username,
userchannel: userchannel ?? this.userchannel,
usernetwork: usernetwork ?? this.usernetwork,
);
}
factory MediaItem.fromJson(Map<String, dynamic> json) {
return MediaItem(
id: json['id'],
mime: json['mime'],
size: json['size'],
stamp: json['stamp'],
dest: json['dest'],
mode: json['mode'],
tags:
(json['tags'] as List<dynamic>?)
?.map((e) => Tag.fromJson(e))
.toList() ??
[],
favorites:
(json['favorites'] as List<dynamic>?)
?.map((e) => Favorite.fromJson(e))
.toList() ??
[],
username: json['username'],
userchannel: json['userchannel'],
usernetwork: json['usernetwork'],
);
}
}
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 username;
final int avatar;
Favorite({
required this.userId,
required this.username,
required this.avatar,
});
factory Favorite.fromJson(Map<String, dynamic> json) {
return Favorite(
userId: json['userId'],
username: json['username'],
avatar: json['avatar'],
);
}
String get avatarUrl => 'https://f0ck.me/t/$avatar.webp';
}