From 586b1573286b52319eac2239047c6cf758caa419 Mon Sep 17 00:00:00 2001 From: Xwite <1797350009@qq.com> Date: Fri, 7 Jan 2022 09:35:39 +0800 Subject: [PATCH 1/4] =?UTF-8?q?cacheFile:=E9=A6=96=E6=AC=A1=E4=B8=8B?= =?UTF-8?q?=E6=B2=A1=E6=9C=89=E8=BF=94=E5=9B=9E=E4=B8=8B=E8=BD=BD=E5=86=85?= =?UTF-8?q?=E5=AE=B9;=E6=AD=A3=E7=A1=AE=E5=A4=84=E7=90=86saveTime=3D0?= =?UTF-8?q?=E7=9A=84=E6=83=85=E5=86=B5?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../main/java/io/legado/app/help/CacheManager.kt | 11 +++++++++++ .../main/java/io/legado/app/help/JsExtensions.kt | 15 +++++++-------- 2 files changed, 18 insertions(+), 8 deletions(-) diff --git a/app/src/main/java/io/legado/app/help/CacheManager.kt b/app/src/main/java/io/legado/app/help/CacheManager.kt index 60627ee35..cc1ce71f1 100644 --- a/app/src/main/java/io/legado/app/help/CacheManager.kt +++ b/app/src/main/java/io/legado/app/help/CacheManager.kt @@ -28,6 +28,13 @@ object CacheManager { } } + fun putString2File(key: String, value: String, saveTime: Int = 0) { + if (saveTime == 0) { + //不设置过期时间 + ACache.get(appCtx).put(key, value) + } else ACache.get(appCtx).put(key, value, saveTime) + } + fun get(key: String): String? { return appDb.cacheDao.get(key, System.currentTimeMillis()) } @@ -52,6 +59,10 @@ object CacheManager { return ACache.get(appCtx).getAsBinary(key) } + fun getString(key: String): String? { + return ACache.get(appCtx).getAsString(key) + } + fun getQueryTTF(key: String): QueryTTF? { val cache = queryTTFMap[key] ?: return null if (cache.first == 0L || cache.first > System.currentTimeMillis()) { diff --git a/app/src/main/java/io/legado/app/help/JsExtensions.kt b/app/src/main/java/io/legado/app/help/JsExtensions.kt index adde0e962..69a21ae79 100644 --- a/app/src/main/java/io/legado/app/help/JsExtensions.kt +++ b/app/src/main/java/io/legado/app/help/JsExtensions.kt @@ -138,15 +138,14 @@ interface JsExtensions { * @param saveTime 缓存时间,单位:秒 * @return 返回缓存后的文件内容 */ - fun cacheFile(url: String, saveTime: Int = 0): String? { - val key = md5Encode16(url) - val cache = ACache.get(appCtx).getAsString(key) + fun cacheFile(urlStr: String, saveTime: Int = 0): String? { + val key = md5Encode16(urlStr) + val cache = CacheManager.getString(key) if(cache.isNullOrBlank()) { - log("首次下载${url}...") - val value = ajax(url) ?: "" - if (saveTime == 0) { - ACache.get(appCtx).put(key, value) - } else ACache.get(appCtx).put(key, value, saveTime) + log("首次下载 ${urlStr}") + val value = ajax(urlStr) ?: return null + CacheManager.putString2File(key, value, saveTime) + return value } return cache } From 8211f73b4300898aba915d0205c3f76f2a1ab07e Mon Sep 17 00:00:00 2001 From: Xwite <1797350009@qq.com> Date: Fri, 7 Jan 2022 10:13:20 +0800 Subject: [PATCH 2/4] =?UTF-8?q?cacheFile:=E9=A6=96=E6=AC=A1=E4=B8=8B?= =?UTF-8?q?=E6=B2=A1=E6=9C=89=E8=BF=94=E5=9B=9E=E4=B8=8B=E8=BD=BD=E5=86=85?= =?UTF-8?q?=E5=AE=B9;ACache:saveTime=3D0=E8=A7=86=E4=B8=BA=E6=B0=B8?= =?UTF-8?q?=E4=B9=85=E4=BF=9D=E5=AD=98?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- app/src/main/java/io/legado/app/help/CacheManager.kt | 5 +---- app/src/main/java/io/legado/app/utils/ACache.kt | 4 ++-- 2 files changed, 3 insertions(+), 6 deletions(-) diff --git a/app/src/main/java/io/legado/app/help/CacheManager.kt b/app/src/main/java/io/legado/app/help/CacheManager.kt index cc1ce71f1..3b5d89bdb 100644 --- a/app/src/main/java/io/legado/app/help/CacheManager.kt +++ b/app/src/main/java/io/legado/app/help/CacheManager.kt @@ -29,10 +29,7 @@ object CacheManager { } fun putString2File(key: String, value: String, saveTime: Int = 0) { - if (saveTime == 0) { - //不设置过期时间 - ACache.get(appCtx).put(key, value) - } else ACache.get(appCtx).put(key, value, saveTime) + ACache.get(appCtx).put(key, value, saveTime) } fun get(key: String): String? { diff --git a/app/src/main/java/io/legado/app/utils/ACache.kt b/app/src/main/java/io/legado/app/utils/ACache.kt index 11b448aa6..b900095c3 100644 --- a/app/src/main/java/io/legado/app/utils/ACache.kt +++ b/app/src/main/java/io/legado/app/utils/ACache.kt @@ -109,7 +109,7 @@ class ACache private constructor(cacheDir: File, max_size: Long, max_count: Int) * @param saveTime 保存的时间,单位:秒 */ fun put(key: String, value: String, saveTime: Int) { - put(key, Utils.newStringWithDateInfo(saveTime, value)) + if (saveTime == 0) put(key, value) else put(key, Utils.newStringWithDateInfo(saveTime, value)) } /** @@ -245,7 +245,7 @@ class ACache private constructor(cacheDir: File, max_size: Long, max_count: Int) * @param saveTime 保存的时间,单位:秒 */ fun put(key: String, value: ByteArray, saveTime: Int) { - put(key, Utils.newByteArrayWithDateInfo(saveTime, value)) + if (saveTime == 0) put(key, value) else put(key, Utils.newByteArrayWithDateInfo(saveTime, value)) } /** From 66eaa6195a343473d0f13b8f22e46d041849e9aa Mon Sep 17 00:00:00 2001 From: celetor Date: Fri, 7 Jan 2022 10:18:05 +0800 Subject: [PATCH 3/4] =?UTF-8?q?=E6=8A=8A=E5=AE=89=E8=A3=85=E5=8C=85?= =?UTF-8?q?=E6=94=BE=E5=88=B0=E4=BA=86https://github.com/gedoor/release?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .github/workflows/release.yml | 7 ++++-- .github/workflows/test.yml | 41 ++++++++++++++++++----------------- 2 files changed, 26 insertions(+), 22 deletions(-) diff --git a/.github/workflows/release.yml b/.github/workflows/release.yml index 04be02dfb..7ba1b54ce 100644 --- a/.github/workflows/release.yml +++ b/.github/workflows/release.yml @@ -78,7 +78,9 @@ jobs: files: ${{ github.workspace }}/apk/*.apk env: GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }} + - name: Push Assets To "release" Branch + if: ${{ github.actor == 'gedoor' }} run: | cd $GITHUB_WORKSPACE/apk || exit 1 git init @@ -87,11 +89,12 @@ jobs: git checkout -b release git add *.apk git commit -m "${{ env.RELEASE_VERSION }}" - git remote add origin "https://${{ github.actor }}:${{ secrets.GITHUB_TOKEN }}@github.com/${{ github.repository }}" + git remote add origin "https://${{ github.actor }}:${{ secrets.GITHUB_TOKEN }}@github.com/${{ github.actor }}/release" git push -f -u origin release - name: Purge Jsdelivr Cache + if: ${{ github.actor == 'gedoor' }} run: | - result=$(curl -s https://purge.jsdelivr.net/gh/${{ github.repository }}@release/) + result=$(curl -s https://purge.jsdelivr.net/gh/${{ github.actor }}/release@release/) if echo $result |grep -q 'success.*true'; then echo "jsdelivr缓存更新成功" else diff --git a/.github/workflows/test.yml b/.github/workflows/test.yml index 3f6441b98..c7738b502 100644 --- a/.github/workflows/test.yml +++ b/.github/workflows/test.yml @@ -5,7 +5,7 @@ on: branches: - master workflow_dispatch: - + jobs: prepare: runs-on: ubuntu-latest @@ -15,25 +15,25 @@ jobs: lanzou: ${{ steps.check.outputs.lanzou }} telegram: ${{ steps.check.outputs.telegram }} steps: - - id: set-ver - run: | - echo "::set-output name=version::$(date -d "8 hour" -u +3.%y.%m%d%H)" - echo "::set-output name=versionL::$(date -d "8 hour" -u +3.%y.%m%d%H%M)" - - id: check - run: | - if [ ${{ secrets.LANZOU_ID }} ]; then - echo "::set-output name=lanzou::yes" - fi - if [ ${{ secrets.BOT_TOKEN }} ]; then - echo "::set-output name=telegram::yes" - fi - + - id: set-ver + run: | + echo "::set-output name=version::$(date -d "8 hour" -u +3.%y.%m%d%H)" + echo "::set-output name=versionL::$(date -d "8 hour" -u +3.%y.%m%d%H%M)" + - id: check + run: | + if [ ${{ secrets.LANZOU_ID }} ]; then + echo "::set-output name=lanzou::yes" + fi + if [ ${{ secrets.BOT_TOKEN }} ]; then + echo "::set-output name=telegram::yes" + fi + build: needs: prepare strategy: matrix: - product: [app, google] - type: [release, releaseA] + product: [ app, google ] + type: [ release, releaseA ] fail-fast: false runs-on: ubuntu-latest env: @@ -91,7 +91,7 @@ jobs: path: ${{ github.workspace }}/apk/*.apk lanzou: - needs: [prepare, build] + needs: [ prepare, build ] if: ${{ needs.prepare.outputs.lanzou }} runs-on: ubuntu-latest env: @@ -115,8 +115,9 @@ jobs: echo "[$(date -u -d '+8 hour' '+%Y.%m.%d %H:%M:%S')] 分享链接: https://kunfei.lanzoux.com/b0f810h4b" test_Branch: - needs: [prepare, build] + needs: [ prepare, build ] runs-on: ubuntu-latest + if: ${{ github.actor == 'gedoor' }} steps: - uses: actions/checkout@v2 - uses: actions/download-artifact@v2 @@ -133,11 +134,11 @@ jobs: git checkout -b test git add *.apk git commit -m "${{ needs.prepare.outputs.versionL }}" - git remote add origin "https://${{ github.actor }}:${{ secrets.GITHUB_TOKEN }}@github.com/${{ github.repository }}" + git remote add origin "https://${{ github.actor }}:${{ secrets.GITHUB_TOKEN }}@github.com/${{ github.actor }}/release" git push -f -u origin test telegram: - needs: [prepare, build] + needs: [ prepare, build ] if: ${{ needs.prepare.outputs.telegram }} runs-on: ubuntu-latest env: From 76a4c705e9cb9c039c303bfdb5747aab72c5d4a8 Mon Sep 17 00:00:00 2001 From: celetor Date: Fri, 7 Jan 2022 10:25:28 +0800 Subject: [PATCH 4/4] =?UTF-8?q?=E6=9B=B4=E6=96=B0?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- README.md | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/README.md b/README.md index 4b0e204cf..5190451ab 100644 --- a/README.md +++ b/README.md @@ -52,7 +52,7 @@ Legado is a free and open source novel reader for Android. * [Releases](https://github.com/gedoor/legado/releases/latest) * [Google play - $1.99](https://play.google.com/store/apps/details?id=io.legado.play.release) * [Coolapk](https://www.coolapk.com/apk/io.legado.app.release) -* [Jsdelivr](https://cdn.jsdelivr.net/gh/gedoor/legado@release/) +* [Jsdelivr](https://cdn.jsdelivr.net/gh/gedoor/release@release/) * [\#Beta](https://kunfei.lanzoui.com/b0f810h4b)