Bots settings (WIP).

This commit is contained in:
John Livingston
2021-12-07 10:29:20 +01:00
parent 7bb444af2c
commit 62456aead1
7 changed files with 132 additions and 19 deletions

View File

@ -3,15 +3,28 @@ For internal API, we will generate an api Key that must be provided as
GET parameter for every API call.
*/
async function getAPIKey ({ storageManager }: RegisterServerOptions): Promise<string> {
let value: string = await storageManager.getData('APIKEY')
async function _getKey ({ storageManager }: RegisterServerOptions, key: string): Promise<string> {
let value: string = await storageManager.getData(key)
if (!value) {
value = Math.random().toString(36).slice(2, 12)
await storageManager.storeData('APIKEY', value)
await storageManager.storeData(key, value)
}
return value
}
export {
getAPIKey
async function getAPIKey (options: RegisterServerOptions): Promise<string> {
return _getKey(options, 'APIKEY')
}
async function getExternalComponentKey (options: RegisterServerOptions, componentName: string): Promise<string> {
if (!/^[A-Z]+$/.test(componentName)) {
throw new Error('Invalid component name: ' + componentName)
}
const key = 'EXTERNALCOMPONENTKEY_' + componentName
return _getKey(options, key)
}
export {
getAPIKey,
getExternalComponentKey
}