feat: submit all torrent info to server

This commit is contained in:
Simon Ding
2024-07-24 21:24:36 +08:00
parent 1359df599b
commit e334acba32
3 changed files with 31 additions and 23 deletions

View File

@@ -309,7 +309,7 @@ func (s *Server) DownloadMovieTorrent(c *gin.Context) (interface{}, error) {
history, err := s.db.SaveHistoryRecord(ent.History{
MediaID: media.ID,
EpisodeID: ep.ID,
SourceTitle: media.NameCn,
SourceTitle: in.Name,
TargetDir: "./",
Status: history.StatusRunning,
Size: in.Size,

View File

@@ -252,7 +252,7 @@ class _NestedTabBarState extends ConsumerState<NestedTabBar>
ref
.read(movieTorrentsDataProvider(widget.id)
.notifier)
.download(torrent.link!)
.download(torrent)
.whenComplete(() =>
Utils.showSnakeBar("开始下载:${torrent.name}"))
.onError((error, trace) =>

View File

@@ -181,24 +181,23 @@ class MediaDetail {
}
class SearchResult {
SearchResult({
required this.backdropPath,
required this.id,
required this.name,
required this.originalName,
required this.overview,
required this.posterPath,
required this.mediaType,
required this.adult,
required this.originalLanguage,
required this.genreIds,
required this.popularity,
required this.firstAirDate,
required this.voteAverage,
required this.voteCount,
required this.originCountry,
this.inWatchlist
});
SearchResult(
{required this.backdropPath,
required this.id,
required this.name,
required this.originalName,
required this.overview,
required this.posterPath,
required this.mediaType,
required this.adult,
required this.originalLanguage,
required this.genreIds,
required this.popularity,
required this.firstAirDate,
required this.voteAverage,
required this.voteCount,
required this.originCountry,
this.inWatchlist});
final String? backdropPath;
final int? id;
@@ -258,10 +257,12 @@ class MovieTorrentResource
return (rsp.data as List).map((v) => TorrentResource.fromJson(v)).toList();
}
Future<void> download(String link) async {
Future<void> download(TorrentResource res) async {
var m = res.toJson();
m["media_id"] = int.parse(mediaId!);
final dio = await APIs.getDio();
var resp = await dio.post(APIs.availableMoviesUrl,
data: {"media_id": int.parse(mediaId!), "link": link});
var resp = await dio.post(APIs.availableMoviesUrl, data: m);
var rsp = ServerResponse.fromJson(resp.data);
if (rsp.code != 0) {
throw rsp.message;
@@ -286,4 +287,11 @@ class TorrentResource {
peers: json["peers"],
link: json["link"]);
}
Map<String, dynamic> toJson() {
final Map<String, dynamic> data = <String, dynamic>{};
data['name'] = name;
data['size'] = size;
data["link"] = link;
return data;
}
}