summaryrefslogtreecommitdiff
path: root/src/utils/video-poster.ts
diff options
context:
space:
mode:
authorrxliuli <rxliuli@gmail.com>2025-11-04 05:03:50 +0800
committerrxliuli <rxliuli@gmail.com>2025-11-04 05:03:50 +0800
commitbce557cc2dc767628bed6aac87301a1be7c5431b (patch)
treeb51a051228d01fe3306cd7626d4a96768aadb944 /src/utils/video-poster.ts
init commit
Diffstat (limited to 'src/utils/video-poster.ts')
-rw-r--r--src/utils/video-poster.ts27
1 files changed, 27 insertions, 0 deletions
diff --git a/src/utils/video-poster.ts b/src/utils/video-poster.ts
new file mode 100644
index 0000000..e2e32ed
--- /dev/null
+++ b/src/utils/video-poster.ts
@@ -0,0 +1,27 @@
+import type { Artwork } from '@jet-app/app-store/api/models';
+import type { Profile } from '@amp/web-app-components/src/components/Artwork/types';
+import type { Size } from '@amp/web-app-components/src/types';
+import type { NamedProfile } from 'src/config/components/artwork';
+import { buildSrc } from '@amp/web-app-components/src/components/Artwork/utils/srcset';
+import { getDataFromProfile } from '@amp/web-app-components/src/components/Artwork/utils/artProfile';
+
+export const buildPoster = (
+ preview: Artwork,
+ profile: NamedProfile | Profile,
+ mediaQuery: string,
+): ReturnType<typeof buildSrc> => {
+ const profileData = getDataFromProfile(profile);
+ const imageAttributes = profileData[mediaQuery as Size] || preview;
+ const dpr = typeof window !== 'undefined' ? window.devicePixelRatio : 2;
+
+ return buildSrc(
+ preview.template,
+ {
+ crop: 'sr',
+ width: imageAttributes.width * dpr,
+ height: imageAttributes.height * dpr,
+ fileType: 'webp',
+ },
+ {},
+ );
+};