From 76eecb298bc2cf51d9933f3de4303a55f116b1b1 Mon Sep 17 00:00:00 2001 From: SrS2225a Date: Sun, 17 Dec 2023 13:44:29 -0800 Subject: [PATCH] added support for kde intergration --- app/Controllers/ClientController.php | 31 +++++++++++ app/routes.php | 1 + .../scripts/xbackbone_kde_uploader.sh.twig | 52 +++++++++++++++++++ resources/templates/user/edit.twig | 6 ++- 4 files changed, 89 insertions(+), 1 deletion(-) create mode 100644 resources/templates/scripts/xbackbone_kde_uploader.sh.twig diff --git a/app/Controllers/ClientController.php b/app/Controllers/ClientController.php index d373cec..e0a4013 100644 --- a/app/Controllers/ClientController.php +++ b/app/Controllers/ClientController.php @@ -114,4 +114,35 @@ class ClientController extends Controller ] ); } + + /** + * @param Request $request + * @param Response $response + * @param int $id + * + * @return Response + * @throws \Twig\Error\LoaderError + * @throws \Twig\Error\RuntimeError + * @throws \Twig\Error\SyntaxError + */ + public function getKDEScript(Request $request, Response $response, int $id): Response + { + $user = make(UserRepository::class)->get($request, $id, true); + + if (!$user->token) { + $this->session->alert(lang('no_upload_token'), 'danger'); + + return redirect($response, $request->getHeaderLine('Referer')); + } + + return view()->render( + $response->withHeader('Content-Disposition', 'attachment;filename="xbackbone_uploader_'.$user->username.'.sh"'), + 'scripts/xbackbone_kde_uploader.sh.twig', + [ + 'username' => $user->username, + 'upload_url' => route('upload'), + 'token' => $user->token, + ] + ); + } } diff --git a/app/routes.php b/app/routes.php index 9aca211..348e6e3 100755 --- a/app/routes.php +++ b/app/routes.php @@ -57,6 +57,7 @@ $app->group('', function (RouteCollectorProxy $group) { $group->post('/user/{id}/refreshToken', [UserController::class, 'refreshToken'])->setName('refreshToken'); $group->get('/user/{id}/config/sharex', [ClientController::class, 'getShareXConfig'])->setName('config.sharex'); $group->get('/user/{id}/config/script', [ClientController::class, 'getBashScript'])->setName('config.script'); + $group->get('/user/{id}/config/kde_script', [ClientController::class, 'getKDEScript'])->setName('kde_config.script'); $group->get('/user/{id}/export', [ExportController::class, 'downloadData'])->setName('export.data'); diff --git a/resources/templates/scripts/xbackbone_kde_uploader.sh.twig b/resources/templates/scripts/xbackbone_kde_uploader.sh.twig new file mode 100644 index 0000000..b2a3371 --- /dev/null +++ b/resources/templates/scripts/xbackbone_kde_uploader.sh.twig @@ -0,0 +1,52 @@ +#!/bin/bash + +create_desktop_entry() { +cat << "EOF" > "$HOME/.local/share/kio/servicemenus/xbackbone-uploader.desktop" +[Desktop Entry] +Type=Service +ServiceTypes=KonqPopupMenu/Plugin +Icon=imaga +X-KDE-StartupNotify=false +X-KDE-Priority=TopLevel +MimeType=image/*; +Actions=xbackbone_upload + +[Desktop Action xbackbone_upload] +Name=Upload with XBackBone +Exec=sh -c 'RESPONSE="$(curl -s -F "token={{ token }}" -F "upload=@%u" {{ upload_url }})"; if [ "$(echo "${RESPONSE}" | jq -r ".message")" = "OK" ]; then URL="$(echo "${RESPONSE}" | jq -r ".url")"; if [ "${DESKTOP_SESSION}" != "" ]; then echo "${URL}" | xclip -selection c; notify-send "Upload completed!" "${URL}"; else echo "${URL}"; fi; exit 0; else MESSAGE="$(echo "${RESPONSE}" | jq -r ".message")"; if [ $? -ne 0 ]; then echo "Unexpected response:"; echo "${RESPONSE}"; exit 1; fi; if [ "${DESKTOP_SESSION}" != "" ]; then notify-send "Error!" "${MESSAGE}"; else echo "Error! ${MESSAGE}"; fi; exit 1; fi' +Icon=image +EOF + + echo "Service menu created!"; +} + +check() { + ERRORS=0; + + if [ ! -x "$(command -v jq)" ]; then + echo "jq command not found."; + ERRORS=1; + fi + + if [ ! -x "$(command -v curl)" ]; then + echo "curl command not found."; + ERRORS=1; + fi + + if [ ! -x "$(command -v xclip)" ] && [ "${DESKTOP_SESSION}" != "" ]; then + echo "xclip command not found."; + ERRORS=1; + fi + + if [ ! -x "$(command -v notify-send)" ] && [ "${DESKTOP_SESSION}" != "" ]; then + echo "notify-send command not found."; + ERRORS=1; + fi + + if [ "${ERRORS}" -eq 1 ]; then + exit 1; + fi +} + +check +create_desktop_entry diff --git a/resources/templates/user/edit.twig b/resources/templates/user/edit.twig index 605ac56..4a56f1a 100644 --- a/resources/templates/user/edit.twig +++ b/resources/templates/user/edit.twig @@ -66,7 +66,11 @@
ShareX Screencloud - Linux Script + Linux Script + +