@rmdes/indiekit-endpoint-youtube 1.1.0 → 1.1.1
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/lib/controllers/dashboard.js +35 -6
- package/package.json +1 -1
|
@@ -1,5 +1,26 @@
|
|
|
1
1
|
import { YouTubeClient } from "../youtube-client.js";
|
|
2
2
|
|
|
3
|
+
/**
|
|
4
|
+
* Get primary channel from config (for backward compatibility)
|
|
5
|
+
* Multi-channel mode uses first channel for dashboard
|
|
6
|
+
*/
|
|
7
|
+
function getPrimaryChannel(config) {
|
|
8
|
+
const { channelId, channelHandle, channels } = config;
|
|
9
|
+
|
|
10
|
+
// Multi-channel mode: use first channel
|
|
11
|
+
if (channels && Array.isArray(channels) && channels.length > 0) {
|
|
12
|
+
const first = channels[0];
|
|
13
|
+
return { id: first.id, handle: first.handle };
|
|
14
|
+
}
|
|
15
|
+
|
|
16
|
+
// Single channel mode (backward compatible)
|
|
17
|
+
if (channelId || channelHandle) {
|
|
18
|
+
return { id: channelId, handle: channelHandle };
|
|
19
|
+
}
|
|
20
|
+
|
|
21
|
+
return null;
|
|
22
|
+
}
|
|
23
|
+
|
|
3
24
|
/**
|
|
4
25
|
* Dashboard controller
|
|
5
26
|
*/
|
|
@@ -19,7 +40,7 @@ export const dashboardController = {
|
|
|
19
40
|
});
|
|
20
41
|
}
|
|
21
42
|
|
|
22
|
-
const { apiKey,
|
|
43
|
+
const { apiKey, cacheTtl, limits } = youtubeConfig;
|
|
23
44
|
|
|
24
45
|
if (!apiKey) {
|
|
25
46
|
return response.render("youtube", {
|
|
@@ -28,7 +49,9 @@ export const dashboardController = {
|
|
|
28
49
|
});
|
|
29
50
|
}
|
|
30
51
|
|
|
31
|
-
|
|
52
|
+
const primaryChannel = getPrimaryChannel(youtubeConfig);
|
|
53
|
+
|
|
54
|
+
if (!primaryChannel) {
|
|
32
55
|
return response.render("youtube", {
|
|
33
56
|
title: response.locals.__("youtube.title"),
|
|
34
57
|
error: { message: response.locals.__("youtube.error.noChannel") },
|
|
@@ -37,8 +60,8 @@ export const dashboardController = {
|
|
|
37
60
|
|
|
38
61
|
const client = new YouTubeClient({
|
|
39
62
|
apiKey,
|
|
40
|
-
channelId,
|
|
41
|
-
channelHandle,
|
|
63
|
+
channelId: primaryChannel.id,
|
|
64
|
+
channelHandle: primaryChannel.handle,
|
|
42
65
|
cacheTtl,
|
|
43
66
|
});
|
|
44
67
|
|
|
@@ -93,10 +116,16 @@ export const dashboardController = {
|
|
|
93
116
|
return response.status(500).json({ error: "Not configured" });
|
|
94
117
|
}
|
|
95
118
|
|
|
119
|
+
const primaryChannel = getPrimaryChannel(youtubeConfig);
|
|
120
|
+
|
|
121
|
+
if (!primaryChannel) {
|
|
122
|
+
return response.status(500).json({ error: "No channel configured" });
|
|
123
|
+
}
|
|
124
|
+
|
|
96
125
|
const client = new YouTubeClient({
|
|
97
126
|
apiKey: youtubeConfig.apiKey,
|
|
98
|
-
channelId:
|
|
99
|
-
channelHandle:
|
|
127
|
+
channelId: primaryChannel.id,
|
|
128
|
+
channelHandle: primaryChannel.handle,
|
|
100
129
|
});
|
|
101
130
|
|
|
102
131
|
// Clear cache and refetch
|
package/package.json
CHANGED