bulltrackers-module 1.0.532 → 1.0.533
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
|
|