Skip to content

Commit

Permalink
fix: Resolved linter issues
Browse files Browse the repository at this point in the history
Signed-off-by: Ferdinand Thiessen <[email protected]>
  • Loading branch information
susnux committed Apr 21, 2024
1 parent 81c8f78 commit dbb789b
Show file tree
Hide file tree
Showing 3 changed files with 52 additions and 43 deletions.
12 changes: 6 additions & 6 deletions lib/requesttoken.ts
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@ export interface CsrfTokenObserver {
(token: string): void;
}

let token: string | null | undefined = undefined
let token: string | null | undefined
const observers: CsrfTokenObserver[] = []

/**
Expand All @@ -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)
}
Expand Down
25 changes: 17 additions & 8 deletions lib/user.ts
Original file line number Diff line number Diff line change
@@ -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
Expand All @@ -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
Expand Down
58 changes: 29 additions & 29 deletions rollup.config.mjs
Original file line number Diff line number Diff line change
Expand Up @@ -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,
},
],
},
]

0 comments on commit dbb789b

Please sign in to comment.