chore: send api token to heartbeat end point
This commit is contained in:
@@ -52,7 +52,7 @@ class WakaTimeCore {
|
|||||||
* Depending on various factors detects the current active tab URL or domain,
|
* Depending on various factors detects the current active tab URL or domain,
|
||||||
* and sends it to WakaTime for logging.
|
* and sends it to WakaTime for logging.
|
||||||
*/
|
*/
|
||||||
async recordHeartbeat(): Promise<void> {
|
async recordHeartbeat(apiKey: string): Promise<void> {
|
||||||
const items = await browser.storage.sync.get({
|
const items = await browser.storage.sync.get({
|
||||||
blacklist: '',
|
blacklist: '',
|
||||||
loggingEnabled: config.loggingEnabled,
|
loggingEnabled: config.loggingEnabled,
|
||||||
@@ -90,6 +90,7 @@ class WakaTimeCore {
|
|||||||
url: currentActiveTab.url as string,
|
url: currentActiveTab.url as string,
|
||||||
},
|
},
|
||||||
debug,
|
debug,
|
||||||
|
apiKey,
|
||||||
);
|
);
|
||||||
} else {
|
} else {
|
||||||
await changeExtensionState('blacklisted');
|
await changeExtensionState('blacklisted');
|
||||||
@@ -103,7 +104,7 @@ class WakaTimeCore {
|
|||||||
items.whitelist as string,
|
items.whitelist as string,
|
||||||
);
|
);
|
||||||
if (heartbeat.url) {
|
if (heartbeat.url) {
|
||||||
await this.sendHeartbeat(heartbeat, debug);
|
await this.sendHeartbeat(heartbeat, debug, apiKey);
|
||||||
} else {
|
} else {
|
||||||
await changeExtensionState('whitelisted');
|
await changeExtensionState('whitelisted');
|
||||||
console.log(`${currentActiveTab.url} is not on a whitelist.`);
|
console.log(`${currentActiveTab.url} is not on a whitelist.`);
|
||||||
@@ -182,8 +183,8 @@ class WakaTimeCore {
|
|||||||
* @param heartbeat
|
* @param heartbeat
|
||||||
* @param debug
|
* @param debug
|
||||||
*/
|
*/
|
||||||
async sendHeartbeat(heartbeat: SendHeartbeat, debug: boolean): Promise<void> {
|
async sendHeartbeat(heartbeat: SendHeartbeat, debug: boolean, apiKey: string): Promise<void> {
|
||||||
let payload = null;
|
let payload;
|
||||||
|
|
||||||
const loggingType = await this.getLoggingType();
|
const loggingType = await this.getLoggingType();
|
||||||
// Get only the domain from the entity.
|
// Get only the domain from the entity.
|
||||||
@@ -191,14 +192,12 @@ class WakaTimeCore {
|
|||||||
if (loggingType == 'domain') {
|
if (loggingType == 'domain') {
|
||||||
heartbeat.url = getDomainFromUrl(heartbeat.url);
|
heartbeat.url = getDomainFromUrl(heartbeat.url);
|
||||||
payload = this.preparePayload(heartbeat, 'domain', debug);
|
payload = this.preparePayload(heartbeat, 'domain', debug);
|
||||||
console.log(payload);
|
await this.sendPostRequestToApi(payload, apiKey);
|
||||||
await this.sendAjaxRequestToApi(payload);
|
|
||||||
}
|
}
|
||||||
// Send entity in heartbeat
|
// Send entity in heartbeat
|
||||||
else if (loggingType == 'url') {
|
else if (loggingType == 'url') {
|
||||||
payload = this.preparePayload(heartbeat, 'url', debug);
|
payload = this.preparePayload(heartbeat, 'url', debug);
|
||||||
console.log(payload);
|
await this.sendPostRequestToApi(payload, apiKey);
|
||||||
await this.sendAjaxRequestToApi(payload);
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -243,7 +242,7 @@ class WakaTimeCore {
|
|||||||
* @param method
|
* @param method
|
||||||
* @returns {*}
|
* @returns {*}
|
||||||
*/
|
*/
|
||||||
async sendAjaxRequestToApi(payload: Record<string, unknown>, api_key = '') {
|
async sendPostRequestToApi(payload: Record<string, unknown>, api_key = '') {
|
||||||
try {
|
try {
|
||||||
const response = await axios.post(config.heartbeatApiUrl, payload, {
|
const response = await axios.post(config.heartbeatApiUrl, payload, {
|
||||||
params: {
|
params: {
|
||||||
|
|||||||
@@ -38,7 +38,7 @@ export const fetchUserData = async (
|
|||||||
dispatch(setLoggingEnabled(items.loggingEnabled as boolean));
|
dispatch(setLoggingEnabled(items.loggingEnabled as boolean));
|
||||||
dispatch(setTotalTimeLoggedToday(totalTimeLoggedTodayResponse.text));
|
dispatch(setTotalTimeLoggedToday(totalTimeLoggedTodayResponse.text));
|
||||||
|
|
||||||
await WakaTimeCore.recordHeartbeat();
|
await WakaTimeCore.recordHeartbeat(apiKey);
|
||||||
} catch (err: unknown) {
|
} catch (err: unknown) {
|
||||||
await changeExtensionState('notSignedIn');
|
await changeExtensionState('notSignedIn');
|
||||||
}
|
}
|
||||||
|
|||||||
Reference in New Issue
Block a user