diff options
author | Vitaly Takmazov | 2023-03-07 13:04:37 +0300 |
---|---|---|
committer | Vitaly Takmazov | 2023-03-07 13:04:37 +0300 |
commit | 5d31fffc321717afb6c0cbb0f5dab9bd8f844eda (patch) | |
tree | 3bd96dc3ec6bb5e63a8442992c04f6c96ec35cff /vnext/server/hms.js | |
parent | b4ce703820264a7ed16b5b3efee973aadc43335d (diff) |
Conditional modules initialization
Diffstat (limited to 'vnext/server/hms.js')
-rw-r--r-- | vnext/server/hms.js | 33 |
1 files changed, 18 insertions, 15 deletions
diff --git a/vnext/server/hms.js b/vnext/server/hms.js index e9068c58..1f897cef 100644 --- a/vnext/server/hms.js +++ b/vnext/server/hms.js @@ -3,23 +3,26 @@ import config from 'config'; import debug from 'debug'; var log = debug('hms'); -const { client_id, client_secret } = config.get('service.hms'); +const { client_id, client_secret } = config.has('service.hms') ? config.get('service.hms') : {}; const refreshToken = async () => { - const params = new URLSearchParams(); - params.append('grant_type', 'client_credentials'); - params.append('client_id', client_id); - params.append('client_secret', client_secret); - const res = await axios.post('https://oauth-login.cloud.huawei.com/oauth2/v3/token', params).catch(console.log); - try { - log(`HMS response: ${JSON.stringify(res.data)}`); - const access = res.data; - log(`HMS access token: ${access.access_token}`); - return access.access_token; - } catch (error) { - log(error); - return ''; + if (client_id) { + const params = new URLSearchParams(); + params.append('grant_type', 'client_credentials'); + params.append('client_id', client_id); + params.append('client_secret', client_secret); + const res = await axios.post('https://oauth-login.cloud.huawei.com/oauth2/v3/token', params).catch(console.log); + try { + log(`HMS response: ${JSON.stringify(res.data)}`); + const access = res.data; + log(`HMS access token: ${access.access_token}`); + return access.access_token; + } catch (error) { + log(error); + return ''; + } } + return ''; }; export const send = async (msg, tokenList = []) => { @@ -36,7 +39,7 @@ export const send = async (msg, tokenList = []) => { 'android': { 'fast_app_target': 2 }, - 'data': { + 'data': { 'pushtype': 1, 'pushbody': { 'custom': { |