Skip to content

Commit

Permalink
fix(editor): fix emoji root url and restore retry when failed
Browse files Browse the repository at this point in the history
  • Loading branch information
realth000 committed Oct 7, 2024
1 parent 64fc6f5 commit 697c042
Show file tree
Hide file tree
Showing 2 changed files with 28 additions and 22 deletions.
1 change: 0 additions & 1 deletion CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -124,7 +124,6 @@ The format is based on [Keep a Changelog](https://keepachangelog.com/en/1.0.0/),
- 分区:某些情况下分区为空时显示登录按钮。
- 帖子:现在帖子的当前页码只会显示在右上角,随页面滚动而刷新。
- 帖子:优化帖子中各种卡片和按钮的样式。
- 帖子:现在下载表情时不再重试。
- 首页:迁移至官方轮播图,以修复一些问题。
- 网页:现在解析网页内容时,不再改变换行位置。
- 这会导致部分内容的换行位置与原始网页不同,但后续可以支持复制内容的功能。
Expand Down
49 changes: 28 additions & 21 deletions lib/features/editor/repository/editor_repository.dart
Original file line number Diff line number Diff line change
Expand Up @@ -52,12 +52,12 @@ final class EditorRepository with LoggerMixin {
/// Also formatted like "{:${GROUP_ID}_${EMOJI_ID}:}".
/// * FILE_NAME: the final file name in url when we fetch the emoji image. We
/// don't name cache with this value.
static const _emojiInfoUrl = '$baseUrl/data/cache/common_smilies_var.js?y1Z';
static const _emojiInfoUrl = '$baseUrl/data/cache/common_smilies_var.js';

/// Head of the image url.
///
/// Full url: [_emojiFileUrlHead]/${ROUTE_NAME}/${FILE_NAME}
static const _emojiFileUrlHead = 'https://img.mikudm.net/img02/smilies/';
static const _emojiFileUrlHead = 'https://img.tsdm39.com/img02/smilies/';

/// Expected to match data:
///
Expand Down Expand Up @@ -251,26 +251,33 @@ final class EditorRepository with LoggerMixin {
if (!force && cacheProvider.hasEmojiCacheFile(emojiGroup.id, emoji.id)) {
return true;
}
// No more retry here.
final respEither = await netClient.getImage(emoji.url).run();
if (_disposed) {
return false;
}
if (respEither.isLeft()) {
handle(respEither.unwrapErr());
error('failed to download emoji ${emojiGroup.id}_${emoji.id}: '
'exceed max retry times');
return false;
}
final resp = respEither.unwrap();
if (resp.statusCode != HttpStatus.ok) {
return false;
var retryTimes = 2;
while (retryTimes >= 0) {
retryTimes -= 1;
// No more retry here.
final respEither = await netClient.getImage(emoji.url).run();
if (_disposed) {
return false;
}
if (respEither.isLeft()) {
if (retryTimes < 0) {
handle(respEither.unwrapErr());
error('failed to download emoji ${emojiGroup.id}_${emoji.id}: '
'exceed max retry times');
return false;
}
continue;
}
final resp = respEither.unwrap();
if (resp.statusCode != HttpStatus.ok) {
return false;
}
await cacheProvider.updateEmojiCache(
emojiGroup.id,
emoji.id,
resp.data as List<int>,
);
}
await cacheProvider.updateEmojiCache(
emojiGroup.id,
emoji.id,
resp.data as List<int>,
);
return true;
}

Expand Down

0 comments on commit 697c042

Please sign in to comment.