From dbb789b5fa11f9808177e7f778f71fb53a23a46a Mon Sep 17 00:00:00 2001 From: Ferdinand Thiessen Date: Sun, 21 Apr 2024 15:50:26 +0200 Subject: [PATCH] fix: Resolved linter issues Signed-off-by: Ferdinand Thiessen --- lib/requesttoken.ts | 12 +++++----- lib/user.ts | 25 ++++++++++++------- rollup.config.mjs | 58 ++++++++++++++++++++++----------------------- 3 files changed, 52 insertions(+), 43 deletions(-) diff --git a/lib/requesttoken.ts b/lib/requesttoken.ts index 0d7bb9c2..cacf88b1 100644 --- a/lib/requesttoken.ts +++ b/lib/requesttoken.ts @@ -4,7 +4,7 @@ export interface CsrfTokenObserver { (token: string): void; } -let token: string | null | undefined = undefined +let token: string | null | undefined const observers: CsrfTokenObserver[] = [] /** @@ -24,19 +24,19 @@ export function getRequestToken(): string | null { /** * Add an observer which is called when the CSRF token changes * - * @param observer The observer + * @param observer The observer */ export function onRequestTokenUpdate(observer: CsrfTokenObserver): void { observers.push(observer) } // Listen to server event and keep token in sync -subscribe('csrf-token-update', e => { - token = e.token +subscribe('csrf-token-update', (e: unknown) => { + token = (e as { token: string }).token - observers.forEach(observer => { + observers.forEach((observer) => { try { - observer(e.token) + observer(token!) } catch (e) { console.error('error updating CSRF token observer', e) } diff --git a/lib/user.ts b/lib/user.ts index 64f76be7..27116235 100644 --- a/lib/user.ts +++ b/lib/user.ts @@ -1,19 +1,28 @@ -const getAttribute = (el: HTMLHeadElement | undefined, attribute: string): string | null => { - if (el) { - return el.getAttribute(attribute) +declare global { + interface Window { + _oc_isadmin?: boolean } - - return null } -let currentUser: NextcloudUser | null | undefined = undefined - export interface NextcloudUser { uid: string, displayName: string | null, isAdmin: boolean, } +let currentUser: NextcloudUser | null | undefined + +const getAttribute = (el: HTMLHeadElement | undefined, attribute: string): string | null => { + if (el) { + return el.getAttribute(attribute) + } + + return null +} + +/** + * Get the currently logged in Nextcloud user or null if not logged in + */ export function getCurrentUser(): NextcloudUser | null { if (currentUser !== undefined) { return currentUser @@ -34,7 +43,7 @@ export function getCurrentUser(): NextcloudUser | null { currentUser = { uid, displayName: getAttribute(head, 'data-user-displayname'), - isAdmin: !!(window as any)._oc_isadmin, + isAdmin: !!window._oc_isadmin, } as NextcloudUser return currentUser diff --git a/rollup.config.mjs b/rollup.config.mjs index 10826516..dd8bc32c 100644 --- a/rollup.config.mjs +++ b/rollup.config.mjs @@ -3,33 +3,33 @@ import typescript from '@rollup/plugin-typescript' const external = ['@nextcloud/event-bus'] export default [ - { - input: './lib/index.ts', - external, - plugins: [ - typescript({ - tsconfig: './tsconfig.json', - compilerOptions: { target: 'es5' }, - }), - ], - output: [ - { - dir: 'dist', - format: 'cjs', - sourcemap: true, - }, - ], - }, - { - input: 'lib/index.ts', - external, - plugins: [typescript()], - output: [ - { - file: 'dist/index.es.mjs', - format: 'esm', - sourcemap: true, - }, - ], - }, + { + input: './lib/index.ts', + external, + plugins: [ + typescript({ + tsconfig: './tsconfig.json', + compilerOptions: { target: 'es5' }, + }), + ], + output: [ + { + dir: 'dist', + format: 'cjs', + sourcemap: true, + }, + ], + }, + { + input: 'lib/index.ts', + external, + plugins: [typescript()], + output: [ + { + file: 'dist/index.es.mjs', + format: 'esm', + sourcemap: true, + }, + ], + }, ]