remove id and set time to number when not using official api

This commit is contained in:
Alan Hamlett
2024-10-14 09:39:48 +02:00
parent 77d0963d93
commit 1031ad0279
2 changed files with 24 additions and 2 deletions

View File

@@ -12,7 +12,12 @@ import { getSettings, Settings } from '../utils/settings';
import { getApiUrl } from '../utils/user'; import { getApiUrl } from '../utils/user';
import config, { ExtensionStatus } from '../config/config'; import config, { ExtensionStatus } from '../config/config';
import { EntityType, Heartbeat, HeartbeatsBulkResponse } from '../types/heartbeats'; import {
EntityType,
Heartbeat,
HeartbeatsBulkResponse,
HeartbeatThirdParty,
} from '../types/heartbeats';
class WakaTimeCore { class WakaTimeCore {
tabsWithDevtoolsOpen: Tabs.Tab[]; tabsWithDevtoolsOpen: Tabs.Tab[];
@@ -179,11 +184,25 @@ class WakaTimeCore {
if (heartbeats.length === 0) return; if (heartbeats.length === 0) return;
const userAgent = await this.getUserAgent(); const userAgent = await this.getUserAgent();
const apiUrl = await getApiUrl();
try { try {
const request: RequestInit = { const request: RequestInit = {
body: JSON.stringify( body: JSON.stringify(
heartbeats.map((heartbeat) => { heartbeats.map((heartbeat) => {
if (!apiUrl.includes('wakatime.com')) {
const hb = {
branch: heartbeat.branch,
category: heartbeat.category,
entity: heartbeat.entity,
language: heartbeat.language,
plugin: heartbeat.plugin,
project: heartbeat.project,
time: parseFloat(heartbeat.time),
type: heartbeat.type,
} as HeartbeatThirdParty;
return { ...hb, userAgent };
}
return { ...heartbeat, userAgent }; return { ...heartbeat, userAgent };
}), }),
), ),
@@ -196,7 +215,6 @@ class WakaTimeCore {
}; };
} }
const apiUrl = await getApiUrl();
const url = `${apiUrl}${settings.heartbeatApiEndPoint}?api_key=${settings.apiKey}`; const url = `${apiUrl}${settings.heartbeatApiEndPoint}?api_key=${settings.apiKey}`;
const response = await fetch(url, request); const response = await fetch(url, request);
if (response.status === 401) { if (response.status === 401) {

View File

@@ -10,6 +10,10 @@ export interface Heartbeat {
type: EntityType; type: EntityType;
} }
export interface HeartbeatThirdParty extends Omit<Heartbeat, 'id' | 'time'> {
time: number;
}
export enum Category { export enum Category {
browsing = 'browsing', browsing = 'browsing',
code_reviewing = 'code reviewing', code_reviewing = 'code reviewing',