Reverting work on DemoBot (it is now an external package).

This commit is contained in:
John Livingston
2021-12-11 17:12:04 +01:00
parent d01d13a69e
commit 2e7cec04d9
23 changed files with 89 additions and 1221 deletions

View File

@ -3,28 +3,15 @@ For internal API, we will generate an api Key that must be provided as
GET parameter for every API call.
*/
async function _getKey ({ storageManager }: RegisterServerOptions, key: string): Promise<string> {
let value: string = await storageManager.getData(key)
async function getAPIKey ({ storageManager }: RegisterServerOptions): Promise<string> {
let value: string = await storageManager.getData('APIKEY')
if (!value) {
value = Math.random().toString(36).slice(2, 12)
await storageManager.storeData(key, value)
await storageManager.storeData('APIKEY', value)
}
return value
}
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
getAPIKey
}