api.php 10 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382
  1. <?php
  2. /**
  3. * @OA\Tag(
  4. * name="plugins-invites",
  5. * description="Media Invite Plugin"
  6. * )
  7. */
  8. /**
  9. * @OA\Schema(
  10. * schema="getInvites",
  11. * type="object",
  12. * @OA\Property(
  13. * property="response",
  14. * type="object",
  15. * @OA\Property(
  16. * property="result",
  17. * description="success or error",
  18. * type="string",
  19. * example="success",
  20. * ),
  21. * @OA\Property(
  22. * property="message",
  23. * description="success or error message",
  24. * type="string",
  25. * example=null,
  26. * ),
  27. * @OA\Property(
  28. * property="data",
  29. * description="data from api",
  30. * type="array",
  31. * @OA\Items({
  32. * @OA\Property(
  33. * property="id",
  34. * type="number",
  35. * example=1,
  36. * ),
  37. * @OA\Property(
  38. * property="code",
  39. * type="string",
  40. * example="NN9JH9",
  41. * ),
  42. * @OA\Property(
  43. * property="date",
  44. * type="string",
  45. * example="2018-09-01 02:02:24",
  46. * ),
  47. * @OA\Property(
  48. * property="email",
  49. * type="string",
  50. * example="causefX@organizr.app",
  51. * ),
  52. * @OA\Property(
  53. * property="username",
  54. * type="string",
  55. * example="causefx",
  56. * ),
  57. * @OA\Property(
  58. * property="dateused",
  59. * type="string",
  60. * example="2018-09-01 02:02:24",
  61. * ),
  62. * @OA\Property(
  63. * property="usedby",
  64. * type="string",
  65. * example="causefx",
  66. * ),
  67. * @OA\Property(
  68. * property="ip",
  69. * type="string",
  70. * example="10.0.0.0",
  71. * ),
  72. * @OA\Property(
  73. * property="valid",
  74. * type="string",
  75. * example="No",
  76. * ),
  77. * @OA\Property(
  78. * property="type",
  79. * type="string",
  80. * example="Plex",
  81. * )
  82. * })
  83. * ),
  84. * ),
  85. * )
  86. */
  87. /**
  88. * @OA\Schema(
  89. * schema="createInviteCode",
  90. * type="object",
  91. * @OA\Property(
  92. * property="response",
  93. * type="object",
  94. * @OA\Property(
  95. * property="result",
  96. * description="success or error",
  97. * type="string",
  98. * example="success",
  99. * ),
  100. * @OA\Property(
  101. * property="message",
  102. * description="success or error message",
  103. * type="string",
  104. * example="Invite Code: XYXYXY has been created",
  105. * ),
  106. * @OA\Property(
  107. * property="data",
  108. * description="data from api",
  109. * type="string",
  110. * example=null,
  111. * ),
  112. * ),
  113. * )
  114. */
  115. /**
  116. * @OA\Schema(
  117. * schema="verifyInviteCode",
  118. * type="object",
  119. * @OA\Property(
  120. * property="response",
  121. * type="object",
  122. * @OA\Property(
  123. * property="result",
  124. * description="success or error",
  125. * type="string",
  126. * example="success",
  127. * ),
  128. * @OA\Property(
  129. * property="message",
  130. * description="success or error message",
  131. * type="string",
  132. * example="Code has been verified",
  133. * ),
  134. * @OA\Property(
  135. * property="data",
  136. * description="data from api",
  137. * type="string",
  138. * example=null,
  139. * ),
  140. * ),
  141. * )
  142. */
  143. /**
  144. * @OA\Schema(
  145. * schema="useInviteCode",
  146. * type="object",
  147. * @OA\Property(
  148. * property="response",
  149. * type="object",
  150. * @OA\Property(
  151. * property="result",
  152. * description="success or error",
  153. * type="string",
  154. * example="success",
  155. * ),
  156. * @OA\Property(
  157. * property="message",
  158. * description="success or error message",
  159. * type="string",
  160. * example="Plex/Emby User now has access to system",
  161. * ),
  162. * @OA\Property(
  163. * property="data",
  164. * description="data from api",
  165. * type="string",
  166. * example=null,
  167. * ),
  168. * ),
  169. * )
  170. */
  171. /**
  172. * @OA\Schema(
  173. * schema="deleteInviteCode",
  174. * type="object",
  175. * @OA\Property(
  176. * property="response",
  177. * type="object",
  178. * @OA\Property(
  179. * property="result",
  180. * description="success or error",
  181. * type="string",
  182. * example="success",
  183. * ),
  184. * @OA\Property(
  185. * property="message",
  186. * description="success or error message",
  187. * type="string",
  188. * example="Code has been deleted",
  189. * ),
  190. * @OA\Property(
  191. * property="data",
  192. * description="data from api",
  193. * type="string",
  194. * example=null,
  195. * ),
  196. * ),
  197. * )
  198. */
  199. $app->get('/plugins/invites/settings', function ($request, $response, $args) {
  200. /**
  201. * @OA\Get(
  202. * tags={"plugins-invites"},
  203. * path="/api/v2/plugins/invites/settings",
  204. * summary="Get settings",
  205. * @OA\Response(
  206. * response="200",
  207. * description="Success",
  208. * @OA\JsonContent(ref="#/components/schemas/pluginSettingsPage"),
  209. * ),
  210. * @OA\Response(response="401",description="Unauthorized"),
  211. * security={{ "api_key":{} }}
  212. * )
  213. */
  214. $Invites = new Invites();
  215. if ($Invites->checkRoute($request)) {
  216. if ($Invites->qualifyRequest(1, true)) {
  217. $GLOBALS['api']['response']['data'] = $Invites->_invitesPluginGetSettings();
  218. }
  219. }
  220. $response->getBody()->write(jsonE($GLOBALS['api']));
  221. return $response
  222. ->withHeader('Content-Type', 'application/json;charset=UTF-8')
  223. ->withStatus($GLOBALS['responseCode']);
  224. });
  225. $app->get('/plugins/invites', function ($request, $response, $args) {
  226. /**
  227. * @OA\Get(
  228. * tags={"plugins-invites"},
  229. * path="/api/v2/plugins/invites",
  230. * summary="Get All Invites",
  231. * @OA\Response(
  232. * response="200",
  233. * description="Success",
  234. * @OA\JsonContent(ref="#/components/schemas/getInvites"),
  235. * ),
  236. * @OA\Response(response="401",description="Unauthorized"),
  237. * security={{ "api_key":{} }}
  238. * )
  239. */
  240. $Invites = new Invites();
  241. if ($Invites->checkRoute($request)) {
  242. if ($Invites->qualifyRequest($Invites->config['INVITES-Auth-include'], true)) {
  243. $GLOBALS['api']['response']['data'] = $Invites->_invitesPluginGetCodes();
  244. }
  245. }
  246. $response->getBody()->write(jsonE($GLOBALS['api']));
  247. return $response
  248. ->withHeader('Content-Type', 'application/json;charset=UTF-8')
  249. ->withStatus($GLOBALS['responseCode']);
  250. });
  251. $app->post('/plugins/invites', function ($request, $response, $args) {
  252. /**
  253. * @OA\Post(
  254. * tags={"plugins-invites"},
  255. * path="/api/v2/plugins/invites",
  256. * summary="Create Invite Code",
  257. * @OA\Response(
  258. * response="200",
  259. * description="Success",
  260. * @OA\JsonContent(ref="#/components/schemas/createInviteCode"),
  261. * ),
  262. * @OA\Response(response="401",description="Unauthorized"),
  263. * security={{ "api_key":{} }}
  264. * )
  265. */
  266. $Invites = new Invites();
  267. if ($Invites->checkRoute($request)) {
  268. if ($Invites->qualifyRequest($Invites->config['INVITES-Auth-include'], true)) {
  269. $Invites->_invitesPluginCreateCode($Invites->apiData($request));
  270. }
  271. }
  272. $response->getBody()->write(jsonE($GLOBALS['api']));
  273. return $response
  274. ->withHeader('Content-Type', 'application/json;charset=UTF-8')
  275. ->withStatus($GLOBALS['responseCode']);
  276. });
  277. $app->get('/plugins/invites/{code}', function ($request, $response, $args) {
  278. /**
  279. * @OA\Get(
  280. * tags={"plugins-invites"},
  281. * path="/api/v2/plugins/invites/{code}",
  282. * summary="Verify Invite Code",
  283. * @OA\Parameter(
  284. * name="code",
  285. * description="The Invite Code",
  286. * @OA\Schema(
  287. * type="integer",
  288. * format="int64",
  289. * ),
  290. * in="path",
  291. * required=true
  292. * ),
  293. * @OA\Response(
  294. * response="200",
  295. * description="Success",
  296. * @OA\JsonContent(ref="#/components/schemas/verifyInviteCode"),
  297. * ),
  298. * @OA\Response(response="401",description="Unauthorized")
  299. * )
  300. */
  301. $Invites = new Invites();
  302. if ($Invites->checkRoute($request)) {
  303. if ($Invites->qualifyRequest(999, true)) {
  304. $Invites->_invitesPluginVerifyCode($args['code']);
  305. }
  306. }
  307. $response->getBody()->write(jsonE($GLOBALS['api']));
  308. return $response
  309. ->withHeader('Content-Type', 'application/json;charset=UTF-8')
  310. ->withStatus($GLOBALS['responseCode']);
  311. });
  312. $app->post('/plugins/invites/{code}', function ($request, $response, $args) {
  313. /**
  314. * @OA\Post(
  315. * tags={"plugins-invites"},
  316. * path="/api/v2/plugins/invites/{code}",
  317. * summary="Use Invite Code",
  318. * @OA\Parameter(
  319. * name="code",
  320. * description="The Invite Code",
  321. * @OA\Schema(
  322. * type="integer",
  323. * format="int64",
  324. * ),
  325. * in="path",
  326. * required=true
  327. * ),
  328. * @OA\Response(
  329. * response="200",
  330. * description="Success",
  331. * @OA\JsonContent(ref="#/components/schemas/useInviteCode"),
  332. * ),
  333. * @OA\Response(response="401",description="Unauthorized")
  334. * )
  335. */
  336. $Invites = new Invites();
  337. if ($Invites->checkRoute($request)) {
  338. if ($Invites->qualifyRequest(999, true)) {
  339. $Invites->_invitesPluginUseCode($args['code'], $Invites->apiData($request));
  340. }
  341. }
  342. $response->getBody()->write(jsonE($GLOBALS['api']));
  343. return $response
  344. ->withHeader('Content-Type', 'application/json;charset=UTF-8')
  345. ->withStatus($GLOBALS['responseCode']);
  346. });
  347. $app->delete('/plugins/invites/{code}', function ($request, $response, $args) {
  348. /**
  349. * @OA\Delete(
  350. * tags={"plugins-invites"},
  351. * path="/api/v2/plugins/invites/{code}",
  352. * summary="Delete Invite Code",
  353. * @OA\Parameter(
  354. * name="code",
  355. * description="The Invite Code",
  356. * @OA\Schema(
  357. * type="integer",
  358. * format="int64",
  359. * ),
  360. * in="path",
  361. * required=true
  362. * ),
  363. * @OA\Response(
  364. * response="200",
  365. * description="Success",
  366. * @OA\JsonContent(ref="#/components/schemas/deleteInviteCode"),
  367. * ),
  368. * @OA\Response(response="401",description="Unauthorized"),
  369. * security={{ "api_key":{} }}
  370. * )
  371. */
  372. $Invites = new Invites();
  373. if ($Invites->checkRoute($request)) {
  374. if ($Invites->qualifyRequest($Invites->config['INVITES-Auth-include'], true)) {
  375. $Invites->_invitesPluginDeleteCode($args['code']);
  376. }
  377. }
  378. $response->getBody()->write(jsonE($GLOBALS['api']));
  379. return $response
  380. ->withHeader('Content-Type', 'application/json;charset=UTF-8')
  381. ->withStatus($GLOBALS['responseCode']);
  382. });