-
Notifications
You must be signed in to change notification settings - Fork 5
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
feat: 한 번 불러오기 실패한 사진은 다시 요청하지 않기 (#421)
* test: mock data 변경 * feat: 실패한 이미지 url은 재요청하지 않음
- Loading branch information
1 parent
1f5fbe2
commit ef0e1aa
Showing
3 changed files
with
42 additions
and
13 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,37 @@ | ||
import { getResizedImageUrl, isServerStaticData } from 'utils/image'; | ||
import sadpiumiPng from 'assets/sadpiumi-imageFail.png'; | ||
|
||
const failedImageUrls = new Set<string>(); | ||
|
||
class ImageSourceList { | ||
private fallbackImages: string[] = [sadpiumiPng]; | ||
/** | ||
* @param src img src | ||
* @param imageSize 사용할 크기 (픽셀, px) | ||
*/ | ||
constructor(src: string, imageSize: number) { | ||
if (!failedImageUrls.has(src)) this.fallbackImages.push(src); | ||
|
||
if (isServerStaticData(src)) { | ||
const pngUrl = getResizedImageUrl(src, imageSize, 'png'); | ||
const webpUrl = getResizedImageUrl(src, imageSize, 'webp'); | ||
|
||
if (!failedImageUrls.has(pngUrl)) this.fallbackImages.push(pngUrl); | ||
if (!failedImageUrls.has(webpUrl)) this.fallbackImages.push(webpUrl); | ||
} | ||
} | ||
|
||
getCurrent() { | ||
return this.fallbackImages[this.fallbackImages.length - 1]; | ||
} | ||
|
||
getNext() { | ||
if (this.fallbackImages.length > 1) { | ||
const failed = this.fallbackImages.pop(); | ||
if (failed) failedImageUrls.add(failed); | ||
} | ||
return this.getCurrent(); | ||
} | ||
} | ||
|
||
export default ImageSourceList; |