4
0

api.php 2.4 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354
  1. <?php
  2. $app->get('/plugins/plexlibraries/settings', function ($request, $response, $args) {
  3. $plexLibrariesPlugin = new plexLibrariesPlugin();
  4. if ($plexLibrariesPlugin->checkRoute($request)) {
  5. if ($plexLibrariesPlugin->qualifyRequest(1, true)) {
  6. $GLOBALS['api']['response']['data'] = $plexLibrariesPlugin->_pluginGetSettings();
  7. }
  8. }
  9. $response->getBody()->write(jsonE($GLOBALS['api']));
  10. return $response
  11. ->withHeader('Content-Type', 'application/json;charset=UTF-8')
  12. ->withStatus($GLOBALS['responseCode']);
  13. });
  14. $app->get('/plugins/plexlibraries/launch', function ($request, $response, $args) {
  15. $plexLibrariesPlugin = new plexLibrariesPlugin();
  16. if ($plexLibrariesPlugin->checkRoute($request)) {
  17. if ($plexLibrariesPlugin->qualifyRequest($plexLibrariesPlugin->config['PLEXLIBRARIES-pluginAuth'], true)) {
  18. $plexLibrariesPlugin->_pluginLaunch();
  19. }
  20. }
  21. $response->getBody()->write(jsonE($GLOBALS['api']));
  22. return $response
  23. ->withHeader('Content-Type', 'application/json;charset=UTF-8')
  24. ->withStatus($GLOBALS['responseCode']);
  25. });
  26. $app->get('/plugins/plexlibraries/shares', function ($request, $response, $args) {
  27. $Organizr = ($request->getAttribute('Organizr')) ?? new Organizr();
  28. if ($Organizr->checkRoute($request)) {
  29. $plexLibrariesPlugin = new plexLibrariesPlugin;
  30. if ($plexLibrariesPlugin->qualifyRequest($plexLibrariesPlugin->config['PLEXLIBRARIES-pluginAuth'], true)) {
  31. $GLOBALS['api']['response']['data'] = $plexLibrariesPlugin->plexLibrariesPluginGetPlexShares();
  32. }
  33. }
  34. $response->getBody()->write(jsonE($GLOBALS['api']));
  35. return $response
  36. ->withHeader('Content-Type', 'application/json;charset=UTF-8')
  37. ->withStatus($GLOBALS['responseCode']);
  38. });
  39. $app->post('/plugins/plexlibraries/shares/{userId}/{action}/{shareId}', function ($request, $response, $args) {
  40. $Organizr = ($request->getAttribute('Organizr')) ?? new Organizr();
  41. if ($Organizr->checkRoute($request)) {
  42. $plexLibrariesPlugin = new plexLibrariesPlugin;
  43. if ($plexLibrariesPlugin->qualifyRequest($plexLibrariesPlugin->config['PLEXLIBRARIES-pluginAuth'], true)) {
  44. $userId = $args['userId'] ?? null;
  45. $action = $args['action'] ?? null;
  46. $shareId = $args['shareId'] ?? null;
  47. $plexLibrariesPlugin->plexLibrariesPluginUpdatePlexShares($userId, $action, $shareId);
  48. }
  49. }
  50. $response->getBody()->write(jsonE($GLOBALS['api']));
  51. return $response
  52. ->withHeader('Content-Type', 'application/json;charset=UTF-8')
  53. ->withStatus($GLOBALS['responseCode']);
  54. });