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{ history, err := s.db.SaveHistoryRecord(ent.History{
MediaID: media.ID, MediaID: media.ID,
EpisodeID: ep.ID, EpisodeID: ep.ID,
SourceTitle: media.NameCn, SourceTitle: in.Name,
TargetDir: "./", TargetDir: "./",
Status: history.StatusRunning, Status: history.StatusRunning,
Size: in.Size, Size: in.Size,

View File

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

View File

@@ -181,8 +181,8 @@ class MediaDetail {
} }
class SearchResult { class SearchResult {
SearchResult({ SearchResult(
required this.backdropPath, {required this.backdropPath,
required this.id, required this.id,
required this.name, required this.name,
required this.originalName, required this.originalName,
@@ -197,8 +197,7 @@ class SearchResult {
required this.voteAverage, required this.voteAverage,
required this.voteCount, required this.voteCount,
required this.originCountry, required this.originCountry,
this.inWatchlist this.inWatchlist});
});
final String? backdropPath; final String? backdropPath;
final int? id; final int? id;
@@ -258,10 +257,12 @@ class MovieTorrentResource
return (rsp.data as List).map((v) => TorrentResource.fromJson(v)).toList(); 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(); final dio = await APIs.getDio();
var resp = await dio.post(APIs.availableMoviesUrl, var resp = await dio.post(APIs.availableMoviesUrl, data: m);
data: {"media_id": int.parse(mediaId!), "link": link});
var rsp = ServerResponse.fromJson(resp.data); var rsp = ServerResponse.fromJson(resp.data);
if (rsp.code != 0) { if (rsp.code != 0) {
throw rsp.message; throw rsp.message;
@@ -286,4 +287,11 @@ class TorrentResource {
peers: json["peers"], peers: json["peers"],
link: json["link"]); 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;
}
} }