( contents: ReadonlyArray<ScreenshotObject>, )
| 42 | return Number.isFinite(time) ? time : null; |
| 43 | }; |
| 44 | export 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 | }; |
| 74 | const getFileExtensionFromKey = (fileKey: string) => { |
| 75 | const fileName = fileKey.split("/").at(-1) ?? ""; |
| 76 | const extension = fileName.split(".").at(-1)?.toLowerCase(); |
no test coverage detected