plugins: api.getCurrentUsername

Massimo Melina committed Dec 17, 2024 at 00:44 UTC b228e64ee93162683d36fe62c45501d7d7ea0c75
2 files changed +5
dev-plugins.md
+3
@@ -203,6 +203,8 @@ The `api` object you get as parameter of the `init` contains the following:
203
204 - `getConnections(): Connections[]` retrieve current list of active connections.
205
206 +- `getCurrentUsername(ctx: Context): string` an empty string if no user is logged in in the specified session, or its username otherwise.
207 +
208 - `storageDir: string` folder where a plugin is supposed to store run-time data. This folder is preserved during
209 an update of the plugin, while the rest could be deleted.
210
@@ -711,6 +713,7 @@ If you want to override a text regardless of the language, use the special langu
713 - frontend event: newListEntries
714 - HFS.fileShowComponents
715 - api.ctxBelongsTo
716 + - api.getCurrentUsername
717 - 9.6 (v0.54.0)
718 - frontend event: showPlay
719 - api.addBlock
src/plugins.ts
+2
@@ -30,6 +30,7 @@ import { addBlock } from './block'
30 import { getLangData } from './lang'
31 import { i18nFromTranslations } from './i18n'
32 import { ctxBelongsTo } from './perm'
33 +import { getCurrentUsername } from './auth'
34
35 export const PATH = 'plugins'
36 export const DISABLING_SUFFIX = '-disabled'
@@ -123,6 +124,7 @@ async function initPlugin<T>(pl: any, morePassedToInit?: T) {
124 addBlock,
125 misc,
126 ctxBelongsTo,
127 + getCurrentUsername,
128 ...morePassedToInit
129 })
130 return Object.assign(pl, typeof res === 'function' ? { unload: res } : res)