MCPcopy
hub / github.com/CapSoftware/Cap / findScreenshotObjectKey

Function findScreenshotObjectKey

packages/web-backend/src/Videos/index.ts:44–73  ·  view source on GitHub ↗
(
	contents: ReadonlyArray<ScreenshotObject>,
)

Source from the content-addressed store, hash-verified

42 return Number.isFinite(time) ? time : null;
43};
44export const findScreenshotObjectKey = (
45 contents: ReadonlyArray<ScreenshotObject>,
46) => {
47 const candidates = contents
48 .map((item): ScreenshotCandidate | null => {
49 const key = item.Key;
50 if (!key) return null;
51 const suffixIndex = SCREENSHOT_OBJECT_KEY_SUFFIXES.findIndex((suffix) =>
52 key.endsWith(suffix),
53 );
54 if (suffixIndex < 0) return null;
55 return {
56 key,
57 suffixIndex,
58 lastModified: getScreenshotObjectTime(item.LastModified),
59 };
60 })
61 .filter((item): item is ScreenshotCandidate => item !== null)
62 .sort((a, b) => {
63 if (a.lastModified !== null || b.lastModified !== null) {
64 const timeDiff =
65 (b.lastModified ?? Number.NEGATIVE_INFINITY) -
66 (a.lastModified ?? Number.NEGATIVE_INFINITY);
67 if (timeDiff !== 0) return timeDiff;
68 }
69 return a.suffixIndex - b.suffixIndex;
70 });
71
72 return candidates[0]?.key ?? null;
73};
74const getFileExtensionFromKey = (fileKey: string) => {
75 const fileName = fileKey.split("/").at(-1) ?? "";
76 const extension = fileName.split(".").at(-1)?.toLowerCase();

Callers 4

generateVideoOgImageFunction · 0.90
GETFunction · 0.90
VideosClass · 0.85

Calls 1

getScreenshotObjectTimeFunction · 0.85

Tested by

no test coverage detected