Skip to content

Commit

Permalink
fix: videoshot images may be empty
Browse files Browse the repository at this point in the history
  • Loading branch information
magicdawn committed May 11, 2024
1 parent 238fb4a commit e6e1270
Show file tree
Hide file tree
Showing 2 changed files with 18 additions and 13 deletions.
12 changes: 8 additions & 4 deletions src/components/VideoCard/card.service.ts
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
import { HOST_APP } from '$common'
import { APP_NAME, HOST_APP } from '$common'
import type { AppRecItem, DmJson, PvideoJson } from '$define'
import { gmrequest, isWebApiSuccess, request } from '$request'
import { getCsrfToken } from '$utility'
import { AntdMessage, getCsrfToken } from '$utility'
import { toast } from '$utility/toast'
import QuickLRU from 'quick-lru'

Expand All @@ -15,7 +15,11 @@ export async function videoshot(bvid: string) {
})
const json = res.data as PvideoJson

// TODO: process errors
if (!isWebApiSuccess(json)) {
console.warn('[%s] videoshot error for %s: %o', APP_NAME, bvid, json)
const msg = `${bvid}: ${json?.message} 错误代码:${json?.code}`
AntdMessage.warning(msg)
}

return json.data
}
Expand Down Expand Up @@ -50,7 +54,7 @@ export async function fetchVideoData(bvid: string) {
cache.set(bvid, { videoshotData, dmData })

// load images
const imgs = videoshotData.image.slice(0, 3)
const imgs = (videoshotData?.image || []).slice(0, 3)
await Promise.all(
imgs.map((src) => {
return new Promise<boolean>((resolve) => {
Expand Down
19 changes: 10 additions & 9 deletions src/components/VideoCard/index.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -557,15 +557,16 @@ const VideoCardInner = memo(function VideoCardInner({

{/* preview */}
{/* follow-mouse or manual-control */}
{(isHoveringAfterDelay || typeof previewProgress === 'number') && (
<PreviewImage
videoDuration={duration}
pvideo={videoDataBox.state?.videoshotData}
mouseEnterRelativeX={mouseEnterRelativeX}
previewProgress={previewProgress}
previewT={previewT}
/>
)}
{(isHoveringAfterDelay || typeof previewProgress === 'number') &&
videoDataBox.state?.videoshotData?.image?.length && (
<PreviewImage
videoDuration={duration}
pvideo={videoDataBox.state?.videoshotData}
mouseEnterRelativeX={mouseEnterRelativeX}
previewProgress={previewProgress}
previewT={previewT}
/>
)}

{dislikeButtonEl && (
<div className='left-actions' css={VideoCardActionStyle.top('left')}>
Expand Down

0 comments on commit e6e1270

Please sign in to comment.