diff options
Diffstat (limited to 'packages/meshbay-hub/src/meshbay_hub/static/transport.js')
| -rw-r--r-- | packages/meshbay-hub/src/meshbay_hub/static/transport.js | 78 |
1 files changed, 78 insertions, 0 deletions
diff --git a/packages/meshbay-hub/src/meshbay_hub/static/transport.js b/packages/meshbay-hub/src/meshbay_hub/static/transport.js index 8df7700..785b926 100644 --- a/packages/meshbay-hub/src/meshbay_hub/static/transport.js +++ b/packages/meshbay-hub/src/meshbay_hub/static/transport.js @@ -85,6 +85,7 @@ const ADMIN_OP_TYPES = new Set([ 'musicbrainz_enabled', 'file_delete', 'dir_delete', 'apps_enabled', 'set_scan_settings', 'member_revoke', 'root_add', 'root_remove', 'root_update', 'root_eject', 'root_plug', + 'app_directories', 'chat_directory', 'chat_link_preview', 'member_unpin', 'gek_rotate', 'group_attach', 'group_detach', 'invite_create', ]); @@ -335,6 +336,9 @@ class MeshBayTransport { set onUploadPolicy(fn) { this._onUploadPolicy = fn; } set onRootsChanged(fn) { this._onRootsChanged = fn; } set onAppsEnabled(fn) { this._onAppsEnabled = fn; } + set onAppDirectories(fn) { this._onAppDirectories = fn; } + set onChatDirectory(fn) { this._onChatDirectory = fn; } + set onChatLinkPreview(fn) { this._onChatLinkPreview = fn; } set onTmdbConfig(fn) { this._onTmdbConfig = fn; } set onTmdbEnabled(fn) { this._onTmdbEnabled = fn; } set onVideoRoot(fn) { this._onVideoRoot = fn; } @@ -1178,6 +1182,68 @@ class MeshBayTransport { } /** + * Point an application at folder(s) inside the group's shared directories. + * + * One method for every app, keyed by the app's registry name — the same + * generic op the node grew for the same reason (docs/refactor-groups.md + * §1.6). `setVideoRoot`, `setAudioRoot` and `setPhotoRoots` are still here + * and still work; nothing new should call them. + * + * The subject names the app as well as the paths, because an operator shown + * "Media/Films" alone cannot tell which application is about to be pointed + * at it, and two apps' challenges would otherwise be indistinguishable. + * Cleaned and sorted the same way the node does, so both sides build the + * same bytes to sign. + */ + async setAppDirectories(appKey, directories, signFn) { + const clean = [...new Set( + (directories || []).map((d) => (d || '').replace(/^\/+|\/+$/g, '')).filter(Boolean), + )].sort(); + const msg = await this._sendAndWait({ + type: 'app_directories', v: '1.1', app: appKey, directories: clean, + }); + if (msg.type === 'error') throw new Error(msg.detail); + if (msg.type === 'admin_challenge') { + return this._authorizeAdminOp( + msg, 'app_directories', `${appKey}:${clean.join(',')}`, signFn); + } + return msg; + } + + /** + * Where chat attachments are written. + * + * Its own message rather than `setAppDirectories('chat', ...)`: this one is + * a destination, and the node refuses a read-only root for it. A caller + * reaching for the generic form would get a refusal it has no reason to + * expect, so the difference is in the name. + */ + async setChatDirectory(path, signFn) { + const clean = (path || '').replace(/^\/+|\/+$/g, ''); + const msg = await this._sendAndWait({ + type: 'chat_directory', v: '1.1', path: clean, + }); + if (msg.type === 'error') throw new Error(msg.detail); + if (msg.type === 'admin_challenge') { + return this._authorizeAdminOp(msg, 'chat_directory', clean, signFn); + } + return msg; + } + + /** Whether the node unfurls links members post in this group's chat. */ + async setChatLinkPreview(enabled, signFn) { + const msg = await this._sendAndWait({ + type: 'chat_link_preview', v: '1.1', enabled: Boolean(enabled), + }); + if (msg.type === 'error') throw new Error(msg.detail); + if (msg.type === 'admin_challenge') { + return this._authorizeAdminOp( + msg, 'chat_link_preview', enabled ? 'on' : 'off', signFn); + } + return msg; + } + + /** * MusicBrainz metadata for one track (Music app, docs/musicbay.md §4.3) * — same shape as fetchMediaMeta, minus a season/episode concept: * album-level (release), resolved from the track's own artist/album @@ -2291,6 +2357,18 @@ class MeshBayTransport { this._onAppsEnabled(msg.apps || []); } + // An application was pointed at different folders. One handler for every + // app — the callback is given the app's name and decides. + if (msg.type === 'app_directories_ack' && this._onAppDirectories) { + this._onAppDirectories(msg.app, msg.directories || []); + } + if (msg.type === 'chat_directory_ack' && this._onChatDirectory) { + this._onChatDirectory(msg.path || ''); + } + if (msg.type === 'chat_link_preview_ack' && this._onChatLinkPreview) { + this._onChatLinkPreview(Boolean(msg.enabled)); + } + // Node-wide (not per-group) — the operator supplied/cleared a custom // token, or changed the query language. `token_customized` only says // whether one is set, never the token itself. |