From c8d5e899f7704a60f6d777ef53d338be45ade938 Mon Sep 17 00:00:00 2001 From: Michel Roux Date: Fri, 3 Jan 2025 22:50:29 +0100 Subject: [PATCH] feat: :seedling: include script ok --- appinfo/info.xml | 9 ------- lib/Controller/PageController.php | 27 ++++++++++++------- .../LoadAdditionalScriptsListener.php | 2 +- psalm.xml | 2 +- src/init.ts | 12 ++++----- vite.config.ts | 1 + 6 files changed, 27 insertions(+), 26 deletions(-) diff --git a/appinfo/info.xml b/appinfo/info.xml index 0f8e3d9..228d805 100644 --- a/appinfo/info.xml +++ b/appinfo/info.xml @@ -16,13 +16,4 @@ - - - retro - Games - retro.page.index - app.svg - link - - diff --git a/lib/Controller/PageController.php b/lib/Controller/PageController.php index 0a3b240..df09b8d 100644 --- a/lib/Controller/PageController.php +++ b/lib/Controller/PageController.php @@ -10,26 +10,35 @@ use OCP\AppFramework\Http\Attribute\FrontpageRoute; use OCP\AppFramework\Http\Attribute\NoAdminRequired; use OCP\AppFramework\Http\Attribute\NoCSRFRequired; use OCP\AppFramework\Http\TemplateResponse; -use OCP\AppFramework\Services\IInitialState; +use OCP\Files\IRootFolder; use OCP\IRequest; +use OCP\IUserSession; use OCP\Util; class PageController extends Controller { - public function __construct(IRequest $request, private IInitialState $initialState) - { + public function __construct( + IRequest $request, + private readonly IRootFolder $rootFolder, + private readonly IUserSession $userSession + ) { parent::__construct(Application::APP_ID, $request); } #[NoCSRFRequired] #[NoAdminRequired] - #[FrontpageRoute(verb: 'GET', url: '/{path}')] - public function index(): TemplateResponse - { - Util::addStyle(Application::APP_ID, Application::APP_ID . '-main'); - Util::addScript(Application::APP_ID, Application::APP_ID . '-main'); + #[FrontpageRoute(verb: 'GET', url: '/{path}', requirements: ['path' => '.+'])] + public function run(string $path): TemplateResponse { + $user = $this->userSession->getUser(); - $this->initialState->provideInitialState(); + if (!$user) { + throw new \Exception('User not logged in'); + } + + $folder = $this->rootFolder->getUserFolder($user->getUID()); + $folder->get($path); + + Util::addScript(Application::APP_ID, Application::APP_ID.'-main'); return new TemplateResponse( Application::APP_ID, diff --git a/lib/Listener/LoadAdditionalScriptsListener.php b/lib/Listener/LoadAdditionalScriptsListener.php index a6389a7..ad0267e 100644 --- a/lib/Listener/LoadAdditionalScriptsListener.php +++ b/lib/Listener/LoadAdditionalScriptsListener.php @@ -17,7 +17,7 @@ class LoadAdditionalScriptsListener implements IEventListener { public function handle(Event $event): void { if ($event instanceof LoadAdditionalScriptsEvent) { - Util::addInitScript(Application::APP_ID, 'init'); + Util::addInitScript(Application::APP_ID, Application::APP_ID.'-init'); } } } diff --git a/psalm.xml b/psalm.xml index 09d70a8..79832b0 100644 --- a/psalm.xml +++ b/psalm.xml @@ -7,7 +7,7 @@ xsi:schemaLocation="https://getpsalm.org/schema/config vendor/vimeo/psalm/config.xsd" findUnusedBaselineEntry="true" findUnusedCode="false" - phpVersion="8.1" + phpVersion="8.2" > diff --git a/src/init.ts b/src/init.ts index 24aba70..40f22cf 100644 --- a/src/init.ts +++ b/src/init.ts @@ -1,25 +1,25 @@ import { FileAction, FileType, Node, registerFileAction } from '@nextcloud/files' import cores from './mime.json' import { generateUrl } from '@nextcloud/router' -import icon from '../img/' import { t } from '@nextcloud/l10n' const action = new FileAction({ id: 'retro', displayName: () => t('repod', 'Play'), - iconSvgInline: () => icon, + iconSvgInline: () => '', enabled: (files: Node[]) => { if (files.length !== 1) return false const file = files[0] - if (file.type !== FileType.File) return false + if (!file.fileid || file.type !== FileType.File) return false + const extension = file.extension?.substring(1) for (const core in cores) { - if (cores[core].types === file.mime) return true - if (cores[core].extensions.includes(file.extension)) return true + if (cores[core].types.includes(file.mime)) return true + if (cores[core].extensions.includes(extension)) return true } return false }, exec: async (file: Node) => { - location.href = generateUrl('/apps/retro/' + file.path) + location.href = generateUrl(`/apps/retro/${file.path}`) return true }, }) diff --git a/vite.config.ts b/vite.config.ts index 0b5a65d..e3e43a5 100644 --- a/vite.config.ts +++ b/vite.config.ts @@ -11,6 +11,7 @@ const config = defineConfig({ export default createAppConfig( { main: resolve(join('src', 'main.ts')), + init: resolve(join('src', 'init.ts')), }, { config,