fix api bugs

This commit is contained in:
factory-droid[bot]
2025-10-02 21:40:20 +00:00
parent c30b1b2464
commit fd296d800f
4 changed files with 39 additions and 10 deletions

View File

@@ -31,11 +31,12 @@ class Favorite {
}
String get fullPosterUrl {
final baseUrl = dotenv.env['API_URL']!;
if (posterPath.isEmpty) {
return '$baseUrl/images/w500/placeholder.jpg';
return 'https://via.placeholder.com/500x750.png?text=No+Poster';
}
// TMDB CDN base URL
const tmdbBaseUrl = 'https://image.tmdb.org/t/p';
final cleanPath = posterPath.startsWith('/') ? posterPath.substring(1) : posterPath;
return '$baseUrl/images/w500/$cleanPath';
return '$tmdbBaseUrl/w500/$cleanPath';
}
}

View File

@@ -16,6 +16,8 @@ class Movie extends HiveObject {
@HiveField(2)
final String? posterPath;
final String? backdropPath;
@HiveField(3)
final String? overview;
@@ -51,6 +53,7 @@ class Movie extends HiveObject {
required this.id,
required this.title,
this.posterPath,
this.backdropPath,
this.overview,
this.releaseDate,
this.genres,
@@ -68,6 +71,7 @@ class Movie extends HiveObject {
id: (json['id'] as num).toString(), // Ensure id is a string
title: (json['title'] ?? json['name'] ?? '') as String,
posterPath: json['poster_path'] as String?,
backdropPath: json['backdrop_path'] as String?,
overview: json['overview'] as String?,
releaseDate: json['release_date'] != null && json['release_date'].isNotEmpty
? DateTime.tryParse(json['release_date'] as String)
@@ -92,13 +96,24 @@ class Movie extends HiveObject {
Map<String, dynamic> toJson() => _$MovieToJson(this);
String get fullPosterUrl {
final baseUrl = dotenv.env['API_URL']!;
if (posterPath == null || posterPath!.isEmpty) {
// Use the placeholder from our own backend
return '$baseUrl/images/w500/placeholder.jpg';
// Use a generic placeholder
return 'https://via.placeholder.com/500x750.png?text=No+Poster';
}
// Null check is already performed above, so we can use `!`
// TMDB CDN base URL
const tmdbBaseUrl = 'https://image.tmdb.org/t/p';
final cleanPath = posterPath!.startsWith('/') ? posterPath!.substring(1) : posterPath!;
return '$baseUrl/images/w500/$cleanPath';
return '$tmdbBaseUrl/w500/$cleanPath';
}
String get fullBackdropUrl {
if (backdropPath == null || backdropPath!.isEmpty) {
// Use a generic placeholder
return 'https://via.placeholder.com/1280x720.png?text=No+Backdrop';
}
// TMDB CDN base URL
const tmdbBaseUrl = 'https://image.tmdb.org/t/p';
final cleanPath = backdropPath!.startsWith('/') ? backdropPath!.substring(1) : backdropPath!;
return '$tmdbBaseUrl/w780/$cleanPath';
}
}

View File

@@ -81,6 +81,7 @@ Movie _$MovieFromJson(Map<String, dynamic> json) => Movie(
id: json['id'] as String,
title: json['title'] as String,
posterPath: json['posterPath'] as String?,
backdropPath: json['backdropPath'] as String?,
overview: json['overview'] as String?,
releaseDate: json['releaseDate'] == null
? null
@@ -100,6 +101,7 @@ Map<String, dynamic> _$MovieToJson(Movie instance) => <String, dynamic>{
'id': instance.id,
'title': instance.title,
'posterPath': instance.posterPath,
'backdropPath': instance.backdropPath,
'overview': instance.overview,
'releaseDate': instance.releaseDate?.toIso8601String(),
'genres': instance.genres,