This commit is contained in:
61
lib/models/media_item.dart
Normal file
61
lib/models/media_item.dart
Normal file
@ -0,0 +1,61 @@
|
||||
class MediaItem {
|
||||
final int id;
|
||||
final String mime;
|
||||
final int size;
|
||||
final int stamp;
|
||||
final String dest;
|
||||
final int mode;
|
||||
final List<Tag> tags;
|
||||
|
||||
MediaItem({
|
||||
required this.id,
|
||||
required this.mime,
|
||||
required this.size,
|
||||
required this.stamp,
|
||||
required this.dest,
|
||||
required this.mode,
|
||||
required this.tags,
|
||||
});
|
||||
|
||||
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 = [];
|
||||
}
|
||||
|
||||
return MediaItem(
|
||||
id: json['id'],
|
||||
mime: json['mime'],
|
||||
size: json['size'],
|
||||
stamp: json['stamp'],
|
||||
dest: json['dest'],
|
||||
mode: json['mode'],
|
||||
tags: parsedTags,
|
||||
);
|
||||
}
|
||||
|
||||
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'],
|
||||
);
|
||||
}
|
||||
}
|
Reference in New Issue
Block a user