-
Notifications
You must be signed in to change notification settings - Fork 0
/
CollaboraRocketchatApp.ts
60 lines (55 loc) · 2.58 KB
/
CollaboraRocketchatApp.ts
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
import {
IAppAccessors,
IConfigurationExtend,
IConfigurationModify, IHttp,
ILogger, IRead,
} from '@rocket.chat/apps-engine/definition/accessors';
import { ApiSecurity, ApiVisibility } from '@rocket.chat/apps-engine/definition/api';
import { App } from '@rocket.chat/apps-engine/definition/App';
import { IAppInfo } from '@rocket.chat/apps-engine/definition/metadata';
import { ISetting, SettingType } from '@rocket.chat/apps-engine/definition/settings';
import { CheckFileInfoEndpoint } from './CheckFileInfoEndpoint';
import { GetCollaboraOnlineFileURL } from './GetCollaboraOnlineFileURL';
import { GetFileEndpoint } from './GetFileEndpoint';
import { UpdateWOPIFileMapEndpoint } from './UpdateWOPIFileMapEndpoint';
import { Utils } from './Utils';
export class CollaboraRocketchatApp extends App {
constructor(info: IAppInfo, logger: ILogger, accessors: IAppAccessors) {
super(info, logger, accessors);
}
public async extendConfiguration(configuration: IConfigurationExtend) {
// Register API endpoints
await configuration.api.provideApi({
visibility: ApiVisibility.PUBLIC,
security: ApiSecurity.UNSECURE,
endpoints: [
new CheckFileInfoEndpoint(this),
new GetFileEndpoint(this),
new GetCollaboraOnlineFileURL(this),
new UpdateWOPIFileMapEndpoint(this),
],
});
// Register Settings
await configuration.settings.provideSetting({
/** The id of this setting. */
id: 'OnlineServerUrl',
/** Type of setting this is. */
type: SettingType.STRING,
/** What is the default value (allows a reset button). */
packageValue: 'http://localhost',
/** Whether this setting is required or not. */
required: true,
/** Whether this setting is a public setting or not - administrators can see ones which are not public but users can't. */
public: false,
/** Name of the setting in the form of a i18n string. */
i18nLabel: 'Collabora_Online_Server',
});
}
public async onSettingUpdated(setting: ISetting, configurationModify: IConfigurationModify, read: IRead, http: IHttp): Promise<void> {
console.log(`CollaboraRocketchatApp.onSettingUpdated: ${ JSON.stringify(setting) }`);
if (setting.id === 'OnlineServerUrl') {
const wopiAddress = setting.value || setting.packageValue;
await Utils.updateWopiFileMap(this.getID(), read, http, wopiAddress);
}
}
}