@samitouri / QOSami-HFS / commits / 5fc4e0e9

plugins: HFS.userBelongsTo now supports array of usernames

Massimo Melina committed Oct 24, 2025 at 19:24 UTC 5fc4e0e97fdbd7e2d4b27001c6d7c8df58ac9bd0
2 files changed +8 -6
dev-plugins.md
+6 -4
@@ -312,7 +312,8 @@ The `api` object you get as parameter of the `init` contains the following:
312 - `i18n(ctx: Context): Promise<{ t }>` if you need to translate messages inside http body, without the GUI, use this function
313 to instantiate translation for the language of the browser. You can then use the `t` function as documented in [dedicated section](Internationalization-i18n).
314
315 -- `ctxBelongsTo(ctx: Context, accounts: strings[]): boolean` check if the current username, or any group it belongs to, matches the provided accounts list.
315 +- `ctxBelongsTo(ctx: Context, accounts: strings[]): boolean` check if the current username, or any group it belongs to,
316 + matches the provided accounts list. Backend counterpart of `HFS.userBelongsTo`.
317
318 - `setError(error: string)` set an error message that will be displayed in the admin-panel. Use an empty string to clear it.
319
@@ -432,8 +433,8 @@ In frontend you will have access to the `HFS` object of the global scope, which
433 For details please refer to `src/debounceAsync.ts`.
434 - `loadScript(uri: string): Promise` load a js file. If uri is relative, it is based on the plugin's public folder.
435 - `customRestCall(name: string, parameters?: object): Promise<any>` call backend functions exported with `customRest`.
435 -- `userBelongsTo(groupOrUsername: string): boolean` returns true if logged in account belongs to the specified group name.
436 - Returns true if the specified name is the one of the logged in account.
436 +- `userBelongsTo(groupOrUsername: string | string[]): boolean` returns true if the current account is or belongs to the name(s) specified.
437 + Frontend counterpart of `api.ctxBelongsTo`.
438 - `DirEntry: class_constructor(n :string, otherProps?: DirEntry)` this is the class of the objects inside `HFS.state.list`;
439 in case you need to add to the list, do it by instantiating this class. E.g. `new HFS.DirEntry(name)`
440 - `fileShow(entry: DirEntry, options?: { startPlaying: true ): boolean` open file-show on the specified entry.
@@ -1077,4 +1078,5 @@ If you want to override a text regardless of the language, use the special langu
1078 - uploadStart now gets fullPath, tempName, resume, fullSize
1079 - ctx.disconnect(logMessage)
1080 - 12.94 (v0.57.24)
1080 - - HFS.onEvent now supports :after
\ No newline at end of file
1081 + - HFS.onEvent now supports :after
1082 + - HFS.userBelongsTo now supports array of usernames
\ No newline at end of file
shared/index.ts
+2 -2
@@ -2,7 +2,7 @@
2
3 import _ from 'lodash'
4 import { apiCall } from './api'
5 -import { DAY, Dict, formatBytes, HOUR, MINUTE, objSameKeys, typedEntries } from '../src/cross'
5 +import { DAY, Dict, formatBytes, HOUR, MINUTE, objSameKeys, typedEntries, wantArray } from '../src/cross'
6 export * from './react'
7 export * from './dialogs'
8 export * from './md'
@@ -32,7 +32,7 @@ Object.assign(HFS, {
32 getPluginPublic: () => getScriptAttr('src')?.match(/^.*\//)?.[0],
33 getPluginConfig: () => HFS.plugins[HFS.getPluginKey()] || {},
34 loadScript: (uri: string) => loadScript(uri.includes('//') || uri.startsWith('/') ? uri : HFS.getPluginPublic() + uri),
35 - userBelongsTo: (groupOrUser: string) => HFS.state.expandedUsername.includes(groupOrUser),
35 + userBelongsTo: (username: string | string[]) => wantArray(username).some(x => HFS.state.expandedUsername.includes(x)),
36 cpuSpeedIndex,
37 copyTextToClipboard,
38 urlParams,