Files
ultimate-ban-tracker/frontend/dist-electron/services/backend.js

193 lines
6.3 KiB
JavaScript

"use strict";
var __importDefault = (this && this.__importDefault) || function (mod) {
return (mod && mod.__esModule) ? mod : { "default": mod };
};
Object.defineProperty(exports, "__esModule", { value: true });
exports.BackendService = void 0;
const axios_1 = __importDefault(require("axios"));
class BackendService {
url;
token;
constructor(url, token) {
this.url = url;
this.token = token;
}
get headers() {
return {
Authorization: `Bearer ${this.token}`,
'Content-Type': 'application/json'
};
}
async getSharedAccounts() {
if (!this.token)
return [];
try {
const response = await axios_1.default.get(`${this.url}/api/sync`, { headers: this.headers });
return response.data;
}
catch (e) {
console.error('[Backend] Failed to fetch shared accounts');
return [];
}
}
async getCommunityAccounts() {
if (!this.token)
return [];
try {
const response = await axios_1.default.get(`${this.url}/api/sync/community`, { headers: this.headers });
return response.data;
}
catch (e) {
console.error('[Backend] Failed to fetch community accounts');
return [];
}
}
async getServerUsers() {
if (!this.token)
return [];
try {
const response = await axios_1.default.get(`${this.url}/api/sync/users`, { headers: this.headers });
return response.data;
}
catch (e) {
console.error('[Backend] Failed to fetch server users');
return [];
}
}
async shareAccount(account) {
if (!this.token)
return;
try {
await axios_1.default.post(`${this.url}/api/sync`, {
steamId: account.steamId,
personaName: account.personaName,
avatar: account.avatar,
profileUrl: account.profileUrl,
vacBanned: account.vacBanned,
gameBans: account.gameBans,
loginName: account.loginName,
steamLoginSecure: account.steamLoginSecure,
loginConfig: account.loginConfig,
sessionUpdatedAt: account.sessionUpdatedAt,
lastMetadataCheck: account.lastBanCheck,
lastScrapeTime: account.lastScrapeTime,
cooldownExpiresAt: account.cooldownExpiresAt
}, { headers: this.headers });
}
catch (e) {
console.error('[Backend] Failed to share account');
}
}
async pushCooldown(steamId, cooldownExpiresAt, lastScrapeTime) {
if (!this.token)
return;
try {
await axios_1.default.patch(`${this.url}/api/sync/${steamId}/cooldown`, {
cooldownExpiresAt,
lastScrapeTime
}, { headers: this.headers });
}
catch (e) {
console.error(`[Backend] Failed to push cooldown for ${steamId}`);
}
}
async shareWithUser(steamId, targetSteamId) {
if (!this.token)
return;
try {
const response = await axios_1.default.post(`${this.url}/api/sync/${steamId}/share`, {
targetSteamId
}, { headers: this.headers });
return response.data;
}
catch (e) {
console.error(`[Backend] Failed to share account ${steamId} with ${targetSteamId}`);
throw new Error(e.response?.data?.message || 'Failed to share account');
}
}
async revokeAccess(steamId, targetSteamId) {
if (!this.token)
return;
try {
const response = await axios_1.default.delete(`${this.url}/api/sync/${steamId}/share`, {
headers: this.headers,
data: { targetSteamId }
});
return response.data;
}
catch (e) {
console.error(`[Backend] Failed to revoke access for ${steamId} from ${targetSteamId}`);
throw new Error(e.response?.data?.message || 'Failed to revoke access');
}
}
async revokeAllAccess(steamId) {
if (!this.token)
return;
try {
const response = await axios_1.default.delete(`${this.url}/api/sync/${steamId}/share/all`, {
headers: this.headers
});
return response.data;
}
catch (e) {
console.error(`[Backend] Failed to revoke all access for ${steamId}`);
throw new Error(e.response?.data?.message || 'Failed to revoke all access');
}
}
// --- Admin API ---
async getAdminStats() {
if (!this.token)
return null;
try {
const response = await axios_1.default.get(`${this.url}/api/admin/stats`, { headers: this.headers });
return response.data;
}
catch (e) {
return null;
}
}
async getAdminUsers() {
if (!this.token)
return [];
try {
const response = await axios_1.default.get(`${this.url}/api/admin/users`, { headers: this.headers });
return response.data;
}
catch (e) {
return [];
}
}
async deleteUser(userId) {
if (!this.token)
return;
try {
await axios_1.default.delete(`${this.url}/api/admin/users/${userId}`, { headers: this.headers });
}
catch (e) {
throw new Error(e.response?.data?.message || 'Failed to delete user');
}
}
async getAdminAccounts() {
if (!this.token)
return [];
try {
const response = await axios_1.default.get(`${this.url}/api/admin/accounts`, { headers: this.headers });
return response.data;
}
catch (e) {
return [];
}
}
async forceRemoveAccount(steamId) {
if (!this.token)
return;
try {
await axios_1.default.delete(`${this.url}/api/admin/accounts/${steamId}`, { headers: this.headers });
}
catch (e) {
throw new Error(e.response?.data?.message || 'Failed to remove account');
}
}
}
exports.BackendService = BackendService;