Play images and video from Synology PhotoStation server

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576777879808182838485868788
  1. <?php
  2. require_once('rotate.inc.php');
  3. class RotateAPI extends WebAPI {
  4. function __construct()
  5. {
  6. parent::__construct(SZ_WEBAPI_API_DESCRIPTION_PATH);
  7. }
  8. protected function Process()
  9. {
  10. csSYNOPhotoDB::GetDBInstance()->SetSessionCache(true);
  11. csSYNOPhotoMisc::CheckSessionTimeOut(true);
  12. if (!strcasecmp($this->method, "set")) {
  13. $this->Set();
  14. }
  15. }
  16. private function GetParams_Set()
  17. {
  18. if (!isset($_REQUEST['id']) || !isset($_REQUEST['rotate'])) {
  19. return false;
  20. }
  21. if (!is_numeric($_REQUEST['rotate'])) {
  22. return false;
  23. }
  24. if (!in_array($_REQUEST['rotate'], array('90', '180', '270'))) {
  25. return false;
  26. }
  27. $params['rotate'] = (int)$_REQUEST['rotate'];
  28. $arr = explode(',', $_REQUEST['id']);
  29. $params['ids'] = array();
  30. foreach ($arr as $item) {
  31. unset($id);
  32. $split = explode('_', $item);
  33. if (3 !== count($split)) {
  34. return false;
  35. }
  36. if (!in_array($split[0], array('photo'))) {
  37. return false;
  38. }
  39. $dirName = @pack('H*', $split[1]);
  40. $fileName = @pack('H*', $split[2]);
  41. $filePath = SYNOPHOTO_SERVICE_REAL_DIR . "/" . ("/" === $dirName ? "" : $dirName . "/") . $fileName;
  42. if (!csSYNOPhotoMisc::CheckPathValid($filePath)) {
  43. return false;
  44. }
  45. $id['fullPath'] = $filePath;
  46. $id['albumName'] = $dirName;
  47. array_push($params['ids'], $id);
  48. }
  49. return $params;
  50. }
  51. private function Set()
  52. {
  53. if (false === ($params = $this->GetParams_Set())) {
  54. $this->SetError(WEBAPI_ERR_BAD_REQUEST);
  55. goto End;
  56. }
  57. // check album maganeable
  58. foreach ($params['ids'] as $item) {
  59. if (false === csSynoPhotoMisc::CheckAlbumManageable($item['albumName'])) {
  60. $this->SetError(PHOTOSTATION_ROTATE_ACCESS_DENY);
  61. goto End;
  62. }
  63. }
  64. // rotate
  65. foreach ($params['ids'] as $item) {
  66. $retJson = SYNOPHOTO_ROTATE_PIC_DoRotation($params['rotate'], $item['fullPath']);
  67. $ret = json_decode($retJson, true);
  68. if (false === $ret['success']) {
  69. $this->SetError(PHOTOSTATION_ROTATE_SET_FAIL);
  70. goto End;
  71. }
  72. }
  73. End:
  74. return;
  75. }
  76. }
  77. $api = new RotateAPI();
  78. $api->Run();
  79. ?>