@epic-web/workshop-utils 6.55.0 → 6.55.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/dist/epic-api.server.js
CHANGED
|
@@ -1,6 +1,7 @@
|
|
|
1
1
|
import { invariant } from '@epic-web/invariant';
|
|
2
2
|
import * as cookie from 'cookie';
|
|
3
3
|
import md5 from 'md5-hex';
|
|
4
|
+
import PQueue from 'p-queue';
|
|
4
5
|
import { z } from 'zod';
|
|
5
6
|
import { getExerciseApp, getExercises, getWorkshopFinished, getWorkshopInstructions, } from "./apps.server.js";
|
|
6
7
|
import { cachified, epicApiCache } from "./cache.server.js";
|
|
@@ -84,6 +85,7 @@ const CachedEpicVideoInfoSchema = z
|
|
|
84
85
|
}))
|
|
85
86
|
.or(z.null());
|
|
86
87
|
const videoInfoLog = log.logger('video-info');
|
|
88
|
+
const EPIC_VIDEO_INFO_CONCURRENCY = 6;
|
|
87
89
|
export async function getEpicVideoInfos(epicWebUrls, { request, timings } = {}) {
|
|
88
90
|
if (!epicWebUrls) {
|
|
89
91
|
videoInfoLog.warn('no epic web URLs provided, returning empty object');
|
|
@@ -92,18 +94,23 @@ export async function getEpicVideoInfos(epicWebUrls, { request, timings } = {})
|
|
|
92
94
|
const authInfo = await getAuthInfo();
|
|
93
95
|
if (getEnv().EPICSHOP_DEPLOYED)
|
|
94
96
|
return {};
|
|
95
|
-
|
|
97
|
+
const uniqueUrls = Array.from(new Set(epicWebUrls));
|
|
98
|
+
videoInfoLog(`fetching epic video infos for ${uniqueUrls.length} URLs`);
|
|
96
99
|
const epicVideoInfos = {};
|
|
97
|
-
|
|
98
|
-
|
|
100
|
+
const queue = new PQueue({ concurrency: EPIC_VIDEO_INFO_CONCURRENCY });
|
|
101
|
+
const results = await Promise.all(uniqueUrls.map((epicVideoEmbed) => queue.add(async () => ({
|
|
102
|
+
epicVideoEmbed,
|
|
103
|
+
info: await getEpicVideoInfo({
|
|
99
104
|
epicVideoEmbed,
|
|
100
105
|
accessToken: authInfo?.tokenSet.access_token,
|
|
101
106
|
request,
|
|
102
107
|
timings,
|
|
103
|
-
})
|
|
104
|
-
|
|
105
|
-
|
|
106
|
-
|
|
108
|
+
}),
|
|
109
|
+
}))));
|
|
110
|
+
for (const result of results) {
|
|
111
|
+
if (!result.info)
|
|
112
|
+
continue;
|
|
113
|
+
epicVideoInfos[result.epicVideoEmbed] = result.info;
|
|
107
114
|
}
|
|
108
115
|
videoInfoLog(`successfully fetched ${Object.keys(epicVideoInfos).length} epic video infos`);
|
|
109
116
|
return epicVideoInfos;
|
|
@@ -62,6 +62,7 @@ export declare function getOfflineVideoDownloadState(): OfflineVideoDownloadStat
|
|
|
62
62
|
export declare function getOfflineVideoSummary({ request, }?: {
|
|
63
63
|
request?: Request;
|
|
64
64
|
}): Promise<OfflineVideoSummary>;
|
|
65
|
+
export declare function warmOfflineVideoSummary(): Promise<void>;
|
|
65
66
|
export declare function startOfflineVideoDownload({ request, }?: {
|
|
66
67
|
request?: Request;
|
|
67
68
|
}): Promise<OfflineVideoStartResult>;
|
|
@@ -422,6 +422,9 @@ export async function getOfflineVideoSummary({ request, } = {}) {
|
|
|
422
422
|
downloadState,
|
|
423
423
|
};
|
|
424
424
|
}
|
|
425
|
+
export async function warmOfflineVideoSummary() {
|
|
426
|
+
await getWorkshopVideoCollection();
|
|
427
|
+
}
|
|
425
428
|
export async function startOfflineVideoDownload({ request, } = {}) {
|
|
426
429
|
if (getEnv().EPICSHOP_DEPLOYED) {
|
|
427
430
|
return {
|