bulltrackers-module 1.0.36 → 1.0.37
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
|
@@ -38,6 +38,21 @@ class IntelligentHeaderManager {
|
|
|
38
38
|
this.headers = [];
|
|
39
39
|
this.lastFetched = null;
|
|
40
40
|
this.performanceUpdates = {};
|
|
41
|
+
|
|
42
|
+
// Initialize with fallback to ensure we always have at least one header
|
|
43
|
+
this._setFallbackHeader();
|
|
44
|
+
}
|
|
45
|
+
|
|
46
|
+
/**
|
|
47
|
+
* Sets the fallback header as the only available header.
|
|
48
|
+
* @private
|
|
49
|
+
*/
|
|
50
|
+
_setFallbackHeader() {
|
|
51
|
+
this.headers = [{
|
|
52
|
+
id: 'fallback',
|
|
53
|
+
data: { 'User-Agent': this.fallbackUserAgent },
|
|
54
|
+
performance: { total: 1, success: 1 }
|
|
55
|
+
}];
|
|
41
56
|
}
|
|
42
57
|
|
|
43
58
|
/**
|
|
@@ -56,37 +71,48 @@ class IntelligentHeaderManager {
|
|
|
56
71
|
const snapshot = await this.firestore.collection(this.collectionName).get();
|
|
57
72
|
|
|
58
73
|
if (snapshot.empty) {
|
|
59
|
-
|
|
74
|
+
this.logger.log('WARN', `[HeaderManager] No documents found in headers collection: ${this.collectionName}. Using fallback.`);
|
|
75
|
+
this._setFallbackHeader();
|
|
76
|
+
this.lastFetched = new Date();
|
|
77
|
+
return;
|
|
60
78
|
}
|
|
61
79
|
|
|
62
|
-
|
|
63
|
-
|
|
64
|
-
|
|
65
|
-
|
|
66
|
-
|
|
67
|
-
|
|
80
|
+
const loadedHeaders = snapshot.docs.map(doc => {
|
|
81
|
+
const docData = doc.data();
|
|
82
|
+
|
|
83
|
+
// Validate that the document has the required 'headers' field
|
|
84
|
+
if (!docData.headers) {
|
|
85
|
+
this.logger.log('WARN', `[HeaderManager] Document ${doc.id} is missing 'headers' field. Skipping.`);
|
|
86
|
+
return null;
|
|
68
87
|
}
|
|
69
|
-
|
|
70
|
-
|
|
71
|
-
|
|
72
|
-
|
|
88
|
+
|
|
89
|
+
return {
|
|
90
|
+
id: doc.id,
|
|
91
|
+
data: docData.headers, // Changed from 'header' to 'headers'
|
|
92
|
+
performance: {
|
|
93
|
+
total: docData.totalRequests || 0,
|
|
94
|
+
success: docData.successfulRequests || 0
|
|
95
|
+
}
|
|
96
|
+
};
|
|
97
|
+
}).filter(Boolean); // Remove null entries
|
|
98
|
+
|
|
99
|
+
if (loadedHeaders.length === 0) {
|
|
100
|
+
this.logger.log('WARN', "[HeaderManager] No valid headers found in collection. Using fallback.");
|
|
101
|
+
this._setFallbackHeader();
|
|
102
|
+
} else {
|
|
103
|
+
this.headers = loadedHeaders;
|
|
104
|
+
this.logger.log('INFO', `[HeaderManager] Successfully loaded ${this.headers.length} headers.`);
|
|
73
105
|
}
|
|
74
106
|
|
|
75
107
|
this.lastFetched = new Date();
|
|
76
|
-
|
|
108
|
+
|
|
77
109
|
} catch (error) {
|
|
78
110
|
this.logger.log('ERROR', '[HeaderManager] Failed to load headers from Firestore. Using fallback.', {
|
|
79
111
|
errorMessage: error.message,
|
|
112
|
+
errorStack: error.stack,
|
|
80
113
|
collection: this.collectionName
|
|
81
114
|
});
|
|
82
|
-
|
|
83
|
-
if (this.headers.length === 0) {
|
|
84
|
-
this.headers = [{
|
|
85
|
-
id: 'fallback',
|
|
86
|
-
data: { 'User-Agent': this.fallbackUserAgent },
|
|
87
|
-
performance: { total: 1, success: 1 }
|
|
88
|
-
}];
|
|
89
|
-
}
|
|
115
|
+
this._setFallbackHeader();
|
|
90
116
|
}
|
|
91
117
|
}
|
|
92
118
|
|
|
@@ -98,8 +124,9 @@ class IntelligentHeaderManager {
|
|
|
98
124
|
async selectHeader() {
|
|
99
125
|
await this._loadHeaders();
|
|
100
126
|
|
|
127
|
+
// This should never happen now because we always have fallback, but keep as safety check
|
|
101
128
|
if (!this.headers || this.headers.length === 0) {
|
|
102
|
-
this.logger.log('
|
|
129
|
+
this.logger.log('ERROR', '[HeaderManager] No headers available after load attempt. Returning fallback.');
|
|
103
130
|
return { id: 'fallback', header: { 'User-Agent': this.fallbackUserAgent } };
|
|
104
131
|
}
|
|
105
132
|
|