Added KawAnime secret to authenticate on analytics server

This commit is contained in:
Kylart 2019-06-25 15:29:39 +02:00
parent 6bb49934f3
commit 2caf50c4ef
2 changed files with 10 additions and 2 deletions

View File

@ -1,3 +1,5 @@
VUE_APP_KAWANIME_SECRET=
VUE_APP_ANILIST_CLIENT_ID= VUE_APP_ANILIST_CLIENT_ID=
VUE_APP_ANILIST_CLIENT_SECRET= VUE_APP_ANILIST_CLIENT_SECRET=

View File

@ -1,16 +1,22 @@
import { readFileSync } from 'fs'
import { eventsList } from '../../../../vendor' import { eventsList } from '../../../../vendor'
import { Logger, https } from '../../utils' import { Logger, https } from '../../utils'
import { localFiles } from '../../externals'
const events = eventsList.analytics const events = eventsList.analytics
const secretKey = process.env.VUE_APP_KAWANIME_SECRET
const ANALYTICS_URL = 'https://kawanime.com/api/v1/analytics' const ANALYTICS_URL = 'https://kawanime.com/api/v1/analytics'
const userToken = readFileSync(localFiles.getPath('_token'))
const logger = new Logger('Analytics') const logger = new Logger('Analytics')
async function send (event, { eventName, data }) { async function send (event, { eventName, data }) {
https.post(ANALYTICS_URL, { https.post(ANALYTICS_URL, {
eventName, eventName,
data data,
}) userToken
}, [], { Authorization: secretKey })
.catch(() => { .catch(() => {
// We ignore errors // We ignore errors
logger.error(`Could not send ${eventName} analytics event.`) logger.error(`Could not send ${eventName} analytics event.`)