bulltrackers-module 1.0.532 → 1.0.534
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.
|
@@ -28,10 +28,25 @@ try {
|
|
|
28
28
|
function getRegistryFunctions(options = {}) {
|
|
29
29
|
// Try to get from options first (injected)
|
|
30
30
|
if (options.collectionRegistry) {
|
|
31
|
+
// Try to get getCollectionMetadata from injected registry, fallback to module-level if not available
|
|
32
|
+
let getMetadata = options.collectionRegistry.getCollectionMetadata;
|
|
33
|
+
if (!getMetadata && getCollectionMetadata) {
|
|
34
|
+
getMetadata = getCollectionMetadata;
|
|
35
|
+
}
|
|
36
|
+
// If still not available, try requiring the registry
|
|
37
|
+
if (!getMetadata) {
|
|
38
|
+
try {
|
|
39
|
+
const registryFallback = require('../../../../../../config/collection_registry');
|
|
40
|
+
getMetadata = registryFallback.getCollectionMetadata;
|
|
41
|
+
} catch (e) {
|
|
42
|
+
// getMetadata will be undefined, which is fine - we'll handle it gracefully
|
|
43
|
+
}
|
|
44
|
+
}
|
|
45
|
+
|
|
31
46
|
return {
|
|
32
47
|
getCollectionPath: options.collectionRegistry.getCollectionPath,
|
|
33
48
|
resolvePath: options.collectionRegistry.resolvePath || resolvePath,
|
|
34
|
-
getCollectionMetadata:
|
|
49
|
+
getCollectionMetadata: getMetadata
|
|
35
50
|
};
|
|
36
51
|
}
|
|
37
52
|
|
|
@@ -42,14 +57,19 @@ function getRegistryFunctions(options = {}) {
|
|
|
42
57
|
|
|
43
58
|
// Last resort: try to require again (in case it's available now)
|
|
44
59
|
try {
|
|
45
|
-
const
|
|
60
|
+
const registryLastResort = require('../../../../../../config/collection_registry');
|
|
46
61
|
return {
|
|
47
|
-
getCollectionPath:
|
|
48
|
-
resolvePath:
|
|
49
|
-
getCollectionMetadata:
|
|
62
|
+
getCollectionPath: registryLastResort.getCollectionPath,
|
|
63
|
+
resolvePath: registryLastResort.resolvePath,
|
|
64
|
+
getCollectionMetadata: registryLastResort.getCollectionMetadata
|
|
50
65
|
};
|
|
51
66
|
} catch (error) {
|
|
52
|
-
|
|
67
|
+
// Return functions that might be available, with getCollectionMetadata as undefined
|
|
68
|
+
return {
|
|
69
|
+
getCollectionPath: getCollectionPath || null,
|
|
70
|
+
resolvePath: resolvePath || null,
|
|
71
|
+
getCollectionMetadata: getCollectionMetadata || null
|
|
72
|
+
};
|
|
53
73
|
}
|
|
54
74
|
}
|
|
55
75
|
|
|
@@ -120,47 +140,49 @@ function getLegacyPath(dataType, userCid, config = {}, params = {}, category = n
|
|
|
120
140
|
const getMetadata = registryFuncs.getCollectionMetadata;
|
|
121
141
|
const resolve = registryFuncs.resolvePath;
|
|
122
142
|
|
|
123
|
-
// Check if getCollectionMetadata is available
|
|
124
|
-
if (
|
|
125
|
-
|
|
126
|
-
|
|
127
|
-
|
|
128
|
-
|
|
129
|
-
|
|
130
|
-
|
|
131
|
-
|
|
132
|
-
|
|
133
|
-
|
|
134
|
-
|
|
135
|
-
|
|
136
|
-
|
|
137
|
-
|
|
138
|
-
|
|
139
|
-
|
|
140
|
-
|
|
141
|
-
|
|
142
|
-
|
|
143
|
-
|
|
144
|
-
|
|
145
|
-
|
|
146
|
-
|
|
147
|
-
|
|
148
|
-
|
|
149
|
-
|
|
150
|
-
|
|
151
|
-
|
|
152
|
-
|
|
153
|
-
|
|
154
|
-
|
|
155
|
-
|
|
156
|
-
|
|
143
|
+
// Check if getCollectionMetadata is available - if not, fall through to hardcoded map
|
|
144
|
+
if (getMetadata && typeof getMetadata === 'function') {
|
|
145
|
+
const metadata = getMetadata(category, subcategory);
|
|
146
|
+
if (metadata && metadata.legacyPaths && metadata.legacyPaths.length > 0) {
|
|
147
|
+
// Use first legacy path from registry (can be enhanced to try multiple)
|
|
148
|
+
let legacyPathTemplate = metadata.legacyPaths[0];
|
|
149
|
+
|
|
150
|
+
// Resolve dynamic segments in the legacy path
|
|
151
|
+
const cid = String(userCid);
|
|
152
|
+
const resolvedParams = {
|
|
153
|
+
cid: cid,
|
|
154
|
+
userCid: cid,
|
|
155
|
+
firebaseUid: params.firebaseUid || '',
|
|
156
|
+
username: params.username || '',
|
|
157
|
+
date: params.date || '{date}',
|
|
158
|
+
requestId: params.requestId || '{requestId}',
|
|
159
|
+
piCid: params.piCid || cid,
|
|
160
|
+
reviewId: params.reviewId || `{piCid}_{userCid}`,
|
|
161
|
+
postId: params.postId || '{postId}',
|
|
162
|
+
viewId: params.viewId || `{piCid}_{viewerCid}_{timestamp}`,
|
|
163
|
+
watchlistId: params.watchlistId || '{watchlistId}',
|
|
164
|
+
version: params.version || '{version}',
|
|
165
|
+
...params // Allow params to override defaults
|
|
166
|
+
};
|
|
167
|
+
|
|
168
|
+
// Resolve path template
|
|
169
|
+
legacyPathTemplate = resolve(legacyPathTemplate, resolvedParams);
|
|
170
|
+
|
|
171
|
+
// Replace any remaining placeholders
|
|
172
|
+
for (const [key, value] of Object.entries(resolvedParams)) {
|
|
173
|
+
legacyPathTemplate = legacyPathTemplate.replace(`{${key}}`, String(value));
|
|
174
|
+
}
|
|
175
|
+
|
|
176
|
+
return legacyPathTemplate;
|
|
157
177
|
}
|
|
158
|
-
|
|
159
|
-
return legacyPathTemplate;
|
|
178
|
+
// If metadata exists but no legacyPaths, fall through to hardcoded map
|
|
160
179
|
}
|
|
161
180
|
} catch (error) {
|
|
162
181
|
// Fall through to hardcoded map if registry lookup fails
|
|
163
|
-
|
|
182
|
+
// Only log if it's not the expected "not available" error
|
|
183
|
+
if (error.message !== 'getCollectionMetadata is not available') {
|
|
184
|
+
console.warn(`[getLegacyPath] Could not get legacy path from registry for ${category}/${subcategory}:`, error.message);
|
|
185
|
+
}
|
|
164
186
|
}
|
|
165
187
|
}
|
|
166
188
|
|
|
@@ -257,7 +257,13 @@ async function handleRequest(message, context, configObj, dependencies) {
|
|
|
257
257
|
}
|
|
258
258
|
|
|
259
259
|
} catch (err) {
|
|
260
|
-
|
|
260
|
+
const errorMessage = err.message || String(err);
|
|
261
|
+
const errorStack = err.stack || '';
|
|
262
|
+
logger.log('ERROR', `[TaskEngine] Error processing task ${type}: ${errorMessage}`, {
|
|
263
|
+
error: errorMessage,
|
|
264
|
+
stack: errorStack,
|
|
265
|
+
taskType: type
|
|
266
|
+
});
|
|
261
267
|
}
|
|
262
268
|
}
|
|
263
269
|
|
|
@@ -235,15 +235,26 @@ async function handleGenericUserUpdate(taskData, config, dependencies, isPI) {
|
|
|
235
235
|
}
|
|
236
236
|
|
|
237
237
|
} catch (err) {
|
|
238
|
-
|
|
238
|
+
// Log error with full details
|
|
239
|
+
const errorMessage = err.message || String(err);
|
|
240
|
+
const errorStack = err.stack || '';
|
|
241
|
+
logger.log('ERROR', `[Update] Failed for ${username}: ${errorMessage}`, {
|
|
242
|
+
error: errorMessage,
|
|
243
|
+
stack: errorStack,
|
|
244
|
+
cid,
|
|
245
|
+
username,
|
|
246
|
+
requestId,
|
|
247
|
+
isPI
|
|
248
|
+
});
|
|
249
|
+
|
|
239
250
|
// Mark Failed
|
|
240
251
|
if (requestId && db) {
|
|
241
252
|
const reqRef = db.collection(source === 'on_demand_sync' ? 'user_sync_requests' : 'pi_fetch_requests')
|
|
242
253
|
.doc(String(cid)).collection('requests').doc(requestId);
|
|
243
|
-
await reqRef.update({ status: 'failed', error:
|
|
254
|
+
await reqRef.update({ status: 'failed', error: errorMessage, failedAt: FieldValue.serverTimestamp() });
|
|
244
255
|
|
|
245
256
|
if (metadata?.requestingUserCid) {
|
|
246
|
-
notifyTaskEngineComplete(db, logger, metadata.requestingUserCid, requestId, username, false,
|
|
257
|
+
notifyTaskEngineComplete(db, logger, metadata.requestingUserCid, requestId, username, false, errorMessage).catch(()=>{});
|
|
247
258
|
}
|
|
248
259
|
}
|
|
249
260
|
throw err;
|