@rmdes/indiekit-endpoint-funkwhale 1.0.4 → 1.0.6
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.
- package/index.js +3 -0
- package/lib/controllers/dashboard.js +17 -2
- package/lib/sync.js +19 -0
- package/package.json +1 -1
package/index.js
CHANGED
|
@@ -100,6 +100,9 @@ export default class FunkwhaleEndpoint {
|
|
|
100
100
|
Indiekit.config.application.funkwhaleConfig = this.options;
|
|
101
101
|
Indiekit.config.application.funkwhaleEndpoint = this.mountPath;
|
|
102
102
|
|
|
103
|
+
// Store database getter for controller access
|
|
104
|
+
Indiekit.config.application.getFunkwhaleDb = () => Indiekit.database;
|
|
105
|
+
|
|
103
106
|
// Start background sync if database is available
|
|
104
107
|
if (Indiekit.config.application.mongodbUrl) {
|
|
105
108
|
startSync(Indiekit, this.options);
|
|
@@ -1,5 +1,5 @@
|
|
|
1
1
|
import { FunkwhaleClient } from "../funkwhale-client.js";
|
|
2
|
-
import { runSync, getCachedStats } from "../sync.js";
|
|
2
|
+
import { runSync, getCachedStats, refreshStatsCache } from "../sync.js";
|
|
3
3
|
import * as utils from "../utils.js";
|
|
4
4
|
|
|
5
5
|
/**
|
|
@@ -64,8 +64,23 @@ export const dashboardController = {
|
|
|
64
64
|
}
|
|
65
65
|
|
|
66
66
|
// Get stats from cache (same source as public API)
|
|
67
|
-
|
|
67
|
+
// If cache is empty, try to refresh it from database
|
|
68
|
+
let cachedStats = getCachedStats();
|
|
69
|
+
console.log("[Funkwhale Dashboard] cachedStats:", cachedStats ? "exists" : "null");
|
|
70
|
+
if (!cachedStats) {
|
|
71
|
+
const getDb = request.app.locals.application.getFunkwhaleDb;
|
|
72
|
+
console.log("[Funkwhale Dashboard] getFunkwhaleDb:", getDb ? "exists" : "null");
|
|
73
|
+
if (getDb) {
|
|
74
|
+
const db = getDb();
|
|
75
|
+
console.log("[Funkwhale Dashboard] db:", db ? "exists" : "null");
|
|
76
|
+
if (db) {
|
|
77
|
+
cachedStats = await refreshStatsCache(db, limits);
|
|
78
|
+
console.log("[Funkwhale Dashboard] after refresh:", cachedStats ? "exists" : "null");
|
|
79
|
+
}
|
|
80
|
+
}
|
|
81
|
+
}
|
|
68
82
|
const summary = cachedStats?.summary?.all || null;
|
|
83
|
+
console.log("[Funkwhale Dashboard] summary:", JSON.stringify(summary));
|
|
69
84
|
|
|
70
85
|
// Determine public frontend URL (strip 'api' from mount path)
|
|
71
86
|
// e.g., /funkwhaleapi -> /funkwhale
|
package/lib/sync.js
CHANGED
|
@@ -30,6 +30,25 @@ export function setCachedStats(stats) {
|
|
|
30
30
|
cachedStatsTime = Date.now();
|
|
31
31
|
}
|
|
32
32
|
|
|
33
|
+
/**
|
|
34
|
+
* Refresh stats cache from database (for when cache is empty)
|
|
35
|
+
* @param {object} db - MongoDB database instance
|
|
36
|
+
* @param {object} limits - Limits for top lists
|
|
37
|
+
* @returns {Promise<object|null>} - Stats or null if failed
|
|
38
|
+
*/
|
|
39
|
+
export async function refreshStatsCache(db, limits = {}) {
|
|
40
|
+
if (!db) return null;
|
|
41
|
+
try {
|
|
42
|
+
const stats = await getAllStats(db, limits);
|
|
43
|
+
setCachedStats(stats);
|
|
44
|
+
console.log("[Funkwhale] Stats cache refreshed on-demand");
|
|
45
|
+
return stats;
|
|
46
|
+
} catch (err) {
|
|
47
|
+
console.error("[Funkwhale] Failed to refresh stats cache:", err.message);
|
|
48
|
+
return null;
|
|
49
|
+
}
|
|
50
|
+
}
|
|
51
|
+
|
|
33
52
|
/**
|
|
34
53
|
* Start background sync process
|
|
35
54
|
* @param {object} Indiekit - Indiekit instance
|
package/package.json
CHANGED