fix: add to watchlist

This commit is contained in:
Simon Ding
2024-07-12 14:36:32 +08:00
parent fc35850426
commit 55966b8115
5 changed files with 40 additions and 10 deletions

7
server/activity.go Normal file
View File

@@ -0,0 +1,7 @@
package server
import "github.com/gin-gonic/gin"
func (s *Server) GetRunningActivities(c *gin.Context) (interface{}, error) {
return nil, nil
}

View File

@@ -57,6 +57,7 @@ func (s *Server) Serve() error {
tv.POST("/watchlist", HttpHandler(s.AddWatchlist))
tv.GET("/watchlist", HttpHandler(s.GetWatchlist))
tv.GET("/series/:id", HttpHandler(s.GetTvDetails))
tv.GET("/resolutions", HttpHandler(s.GetAvailableResolutions))
}
indexer := api.Group("/indexer")
{

View File

@@ -28,8 +28,9 @@ func (s *Server) SearchTvSeries(c *gin.Context) (interface{}, error) {
}
type addWatchlistIn struct {
TmdbID int `json:"id" binding:"required"`
StorageID int `json:"storage_id"`
TmdbID int `json:"tmdb_id" binding:"required"`
StorageID int `json:"storage_id" binding:"required"`
Resolution db.ResolutionType `json:"resolution" binding:"required"`
}
func (s *Server) AddWatchlist(c *gin.Context) (interface{}, error) {
@@ -99,3 +100,11 @@ func (s *Server) GetTvDetails(c *gin.Context) (interface{}, error) {
detail := s.db.GetSeriesDetails(id)
return detail, nil
}
func (s *Server) GetAvailableResolutions(c *gin.Context) (interface{}, error) {
return []db.ResolutionType{
db.R720p,
db.R1080p,
db.R4k,
}, nil
}

View File

@@ -28,10 +28,14 @@ class SearchPageData extends AutoDisposeAsyncNotifier<List<SearchResult>> {
return list;
}
Future<void> submit2Watchlist(int id) async {
Future<void> submit2Watchlist(int tmdbId, int storageId, String resolution) async {
final dio = await APIs.getDio();
var resp = await dio
.post(APIs.watchlistUrl, data: {"id": id, "folder": "/downloads"});
.post(APIs.watchlistUrl, data: {
"tmdb_id": tmdbId,
"storage_id": storageId,
"resolution": resolution
});
var sp = ServerResponse.fromJson(resp.data);
if (sp.code != 0) {
throw sp.message;

View File

@@ -90,9 +90,8 @@ class _SearchPageState extends ConsumerState<SearchPage> {
}
Future<void> _showSubmitDialog(BuildContext context, SearchResult item) {
TextEditingController resolutionController =
TextEditingController(text: "1080p");
TextEditingController storageController = TextEditingController();
String _resSelected = "1080p";
int _storageSelected = 0;
var storage = ref.watch(storageSettingProvider);
return showDialog<void>(
context: context,
@@ -104,22 +103,32 @@ class _SearchPageState extends ConsumerState<SearchPage> {
children: [
DropdownMenu(
label: const Text("清晰度"),
controller: resolutionController,
initialSelection: _resSelected,
dropdownMenuEntries: const [
DropdownMenuEntry(value: "720p", label: "720p"),
DropdownMenuEntry(value: "1080p", label: "1080p"),
DropdownMenuEntry(value: "4k", label: "4k"),
],
onSelected: (value) {
setState(() {
_resSelected = value!;
});
},
),
storage.when(
data: (v) {
return DropdownMenu(
label: const Text("存储位置"),
controller: storageController,
initialSelection: _storageSelected,
dropdownMenuEntries: v
.map((s) =>
DropdownMenuEntry(label: s.name!, value: s.id))
.toList(),
onSelected: (value) {
setState(() {
_storageSelected = value!;
});
},
);
},
error: (err, trace) => Text("$err"),
@@ -144,7 +153,7 @@ class _SearchPageState extends ConsumerState<SearchPage> {
onPressed: () {
ref
.read(searchPageDataProvider.notifier)
.submit2Watchlist(item.id!);
.submit2Watchlist(item.id!, _storageSelected, _resSelected);
Navigator.of(context).pop();
},
),