From 1ae74fdcd4ae358bbd201ae52f3be7660a70473d Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Jurij=20Podgor=C5=A1ek?= Date: Fri, 15 Dec 2023 17:08:37 +0100 Subject: [PATCH] etherpad prefix v drupal modul, dokumentacija APIja, WIP izboljsave --- doc/api.org | 15 +++++++ nuxt/.env.dist | 1 - .../custom/etherpad_api/src/Client.php | 15 ++++--- .../Controller/#EtherpadApiController.php# | 42 ------------------- .../src/Controller/EtherpadApiController.php | 9 +++- 5 files changed, 30 insertions(+), 52 deletions(-) create mode 100644 doc/api.org delete mode 100644 web/modules/custom/etherpad_api/src/Controller/#EtherpadApiController.php# diff --git a/doc/api.org b/doc/api.org new file mode 100644 index 0000000..cf1142e --- /dev/null +++ b/doc/api.org @@ -0,0 +1,15 @@ +# -*- restclient -*- + +########################## +# YUFU API dokumentacija # +########################## + +# Poganjamo z restclient major mode-om v emacsu + +# Ustvari nov pad +POST https://yufu-manifest.ddev.site/etherpad-api/createPad?padID=d2d479bf-b3cb-455a-b7db-5d53c31d1fa2 +Content-Type: application/x-www-form-urlencoded +text=While post-communist, post-socialist and post-Yugoslav discourses merely reinforce the appearance of an unchanging and unstable present with a more or less accurate expression of the situation, Yugofuturism follows the example of other ethnofuturist movements such as Afrofuturism, Sinofuturism, Baltic Ethnofuturism and Hungarofuturism, which tactically empower peripheral identities and subversively affirm individual cultural curiosities. + +# Brisi vsebino pada +GET https://yufu-manifest.ddev.site/etherpad-api/deletePad?padID=d2d479bf-b3cb-455a-b7db-5d53c31d1fa2 \ No newline at end of file diff --git a/nuxt/.env.dist b/nuxt/.env.dist index c505f6f..cb0e6c1 100644 --- a/nuxt/.env.dist +++ b/nuxt/.env.dist @@ -3,4 +3,3 @@ JSONAPI_PATH="/jsonapi" FILE_PATH="/sites/default/files" ETHERPAD_URL="https://pisi.kompot.si" ETHERPAD_API_URL="https://yufu-manifest.ddev.site/etherpad-api" -ETHERPAD_PREFIX="yufu-" diff --git a/web/modules/custom/etherpad_api/src/Client.php b/web/modules/custom/etherpad_api/src/Client.php index 1f54f02..a476179 100644 --- a/web/modules/custom/etherpad_api/src/Client.php +++ b/web/modules/custom/etherpad_api/src/Client.php @@ -52,15 +52,14 @@ class Client { /** * Method description. */ - public function request($method, $url) { - $uri = "{$this->baseUrl}/" . self::API_VERSION . '/' . $url; - - if (str_contains($uri, '?')) { - $uri .= "&apikey={$this->apiKey}"; - } else { - $uri .= "?apikey={$this->apiKey}"; + public function request($method, $url, $opts = []) { + $uri = "{$this->baseUrl}/" . self::API_VERSION . '/' . explode('?', $url)[0]; + if (!isset($opts['form_params'])) { + $opts['form_params'] = []; } + $opts['form_params']['apikey'] = $this->apiKey; + $opts['verify'] = false; - return $this->httpClient->request($method, $uri); + return $this->httpClient->post($uri, $opts); } } diff --git a/web/modules/custom/etherpad_api/src/Controller/#EtherpadApiController.php# b/web/modules/custom/etherpad_api/src/Controller/#EtherpadApiController.php# deleted file mode 100644 index acd81b5..0000000 --- a/web/modules/custom/etherpad_api/src/Controller/#EtherpadApiController.php# +++ /dev/null @@ -1,42 +0,0 @@ -client = $client; - } - - public static function create(ContainerInterface $container) { - return new static($container->get('etherpad_api.client')); - } - - /** - * Builds the response. - */ - public function build($components, Request $request) { - $uri = str_replace(':', '/', $components); - if ($params = $request->getQueryString()) { - $uri .= "?$params"; - } - - try { - return $this->client->request($request->getMethod(), $uri); - } catch (ClientException $exception) { - return new Response($exception->getMessage(), $exception->getCode()); - } - } -} diff --git a/web/modules/custom/etherpad_api/src/Controller/EtherpadApiController.php b/web/modules/custom/etherpad_api/src/Controller/EtherpadApiController.php index acd81b5..8d6ba1c 100644 --- a/web/modules/custom/etherpad_api/src/Controller/EtherpadApiController.php +++ b/web/modules/custom/etherpad_api/src/Controller/EtherpadApiController.php @@ -33,8 +33,15 @@ class EtherpadApiController extends ControllerBase { $uri .= "?$params"; } + $data = array_merge($request->query->all(), $request->request->all()); + if ($data['padID']) { + // @TODO prefix v config! + $data['padID'] = 'yufu-' . $data['padID']; + } + $opts = ['form_params' => $data]; + try { - return $this->client->request($request->getMethod(), $uri); + return $this->client->request($request->getMethod(), $uri, $opts); } catch (ClientException $exception) { return new Response($exception->getMessage(), $exception->getCode()); }