cs2-inspect-lib
Version:
Enhanced CS2 Inspect URL library with full protobuf support, validation, and error handling
197 lines • 6.44 kB
JavaScript
"use strict";
/**
* Steam client manager for CS2 inspect URL library
* Provides high-level interface for Steam client operations
*/
Object.defineProperty(exports, "__esModule", { value: true });
exports.SteamClientManager = void 0;
const steam_client_1 = require("./steam-client");
const types_1 = require("./types");
const errors_1 = require("./errors");
/**
* Manager class for Steam client operations
*/
class SteamClientManager {
constructor(config = {}) {
this.client = null;
this.initialized = false;
this.config = config;
}
/**
* Initialize Steam client if enabled and credentials are provided
*/
async initialize() {
if (this.initialized) {
return;
}
if (!this.config.enabled) {
console.log('[Steam Manager] Steam client disabled in configuration');
return;
}
if (!this.config.username || !this.config.password) {
console.warn('[Steam Manager] Steam credentials not provided - unmasked URL support disabled');
return;
}
try {
this.client = steam_client_1.SteamClient.getInstance(this.config);
await this.client.connect();
this.initialized = true;
console.log('[Steam Manager] Steam client initialized successfully');
}
catch (error) {
console.error('[Steam Manager] Failed to initialize Steam client:', error);
throw error;
}
}
/**
* Check if Steam client is available and ready
*/
isAvailable() {
return this.initialized && this.client !== null && this.client.isReady();
}
/**
* Get current Steam client status
*/
getStatus() {
if (!this.client) {
return types_1.SteamClientStatus.DISCONNECTED;
}
return this.client.getStatus();
}
/**
* Get current queue length
*/
getQueueLength() {
if (!this.client) {
return 0;
}
return this.client.getQueueLength();
}
/**
* Inspect an unmasked URL using Steam client
*/
async inspectUnmaskedUrl(urlInfo) {
if (!this.isAvailable()) {
throw new errors_1.SteamNotReadyError('Steam client is not available or not ready', {
status: this.getStatus(),
initialized: this.initialized
});
}
if (urlInfo.url_type !== 'unmasked') {
throw new errors_1.SteamInspectionError('URL is not an unmasked inspect URL', {
urlType: urlInfo.url_type,
url: urlInfo.original_url
});
}
if (!this.client) {
throw new errors_1.SteamNotReadyError('Steam client not initialized');
}
const startTime = Date.now();
try {
const steamData = await this.client.inspectItem(urlInfo);
const fetchTime = Date.now() - startTime;
// Convert Steam data to EconItem format
const econItem = this.convertSteamDataToEconItem(steamData);
const result = {
...econItem,
inspectUrl: urlInfo.original_url,
queueStatus: {
length: this.client.getQueueLength()
},
steamMetadata: {
fetchTime
}
};
return result;
}
catch (error) {
console.error('[Steam Manager] Failed to inspect item:', error);
throw error;
}
}
/**
* Convert Steam API data to EconItem format
*/
convertSteamDataToEconItem(steamData) {
// This is a basic conversion - you may need to adjust based on actual Steam API response
const econItem = {
defindex: steamData.defindex || 0,
paintindex: steamData.paintindex || 0,
paintseed: steamData.paintseed || 0,
paintwear: steamData.paintwear || 0,
rarity: steamData.rarity || 0,
quality: steamData.quality || 0
};
// Add optional fields if present
if (steamData.killeaterscoretype !== undefined) {
econItem.killeaterscoretype = steamData.killeaterscoretype;
}
if (steamData.killeatervalue !== undefined) {
econItem.killeatervalue = steamData.killeatervalue;
}
if (steamData.customname) {
econItem.customname = steamData.customname;
}
if (steamData.stickers && Array.isArray(steamData.stickers)) {
econItem.stickers = steamData.stickers;
}
if (steamData.keychains && Array.isArray(steamData.keychains)) {
econItem.keychains = steamData.keychains;
}
if (steamData.style !== undefined) {
econItem.style = steamData.style;
}
if (steamData.upgrade_level !== undefined) {
econItem.upgrade_level = steamData.upgrade_level;
}
return econItem;
}
/**
* Update Steam client configuration
*/
updateConfig(config) {
this.config = { ...this.config, ...config };
if (this.client) {
this.client.updateConfig(config);
}
}
/**
* Disconnect and cleanup Steam client
*/
async disconnect() {
if (this.client) {
await this.client.disconnect();
this.client = null;
}
this.initialized = false;
console.log('[Steam Manager] Steam client disconnected');
}
/**
* Check if unmasked URL support is enabled
*/
isUnmaskedUrlSupportEnabled() {
return this.config.enabled === true &&
Boolean(this.config.username) &&
Boolean(this.config.password);
}
/**
* Get configuration information (without sensitive data)
*/
getConfigInfo() {
const { username, password, apiKey, ...safeConfig } = this.config;
return safeConfig;
}
/**
* Get Steam client statistics
*/
getStats() {
return {
status: this.getStatus(),
queueLength: this.getQueueLength(),
isAvailable: this.isAvailable(),
unmaskedSupport: this.isUnmaskedUrlSupportEnabled()
};
}
}
exports.SteamClientManager = SteamClientManager;
//# sourceMappingURL=steam-client-manager.js.map