From 697c042db1f1579816d49e59bddf01a8d31daef4 Mon Sep 17 00:00:00 2001 From: realth000 Date: Mon, 7 Oct 2024 21:51:13 +0800 Subject: [PATCH] fix(editor): fix emoji root url and restore retry when failed --- CHANGELOG.md | 1 - .../editor/repository/editor_repository.dart | 49 +++++++++++-------- 2 files changed, 28 insertions(+), 22 deletions(-) diff --git a/CHANGELOG.md b/CHANGELOG.md index 8a92a7a..d66d305 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -124,7 +124,6 @@ The format is based on [Keep a Changelog](https://keepachangelog.com/en/1.0.0/), - 分区:某些情况下分区为空时显示登录按钮。 - 帖子:现在帖子的当前页码只会显示在右上角,随页面滚动而刷新。 - 帖子:优化帖子中各种卡片和按钮的样式。 -- 帖子:现在下载表情时不再重试。 - 首页:迁移至官方轮播图,以修复一些问题。 - 网页:现在解析网页内容时,不再改变换行位置。 - 这会导致部分内容的换行位置与原始网页不同,但后续可以支持复制内容的功能。 diff --git a/lib/features/editor/repository/editor_repository.dart b/lib/features/editor/repository/editor_repository.dart index bb261f0..0e44ef6 100644 --- a/lib/features/editor/repository/editor_repository.dart +++ b/lib/features/editor/repository/editor_repository.dart @@ -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: /// @@ -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, + ); } - await cacheProvider.updateEmojiCache( - emojiGroup.id, - emoji.id, - resp.data as List, - ); return true; }