Merge remote-tracking branch 'origin/master'

pull/1511/head
gedoor 3 years ago
commit 23d883a50b
  1. 7
      .github/workflows/release.yml
  2. 41
      .github/workflows/test.yml
  3. 2
      README.md
  4. 8
      app/src/main/java/io/legado/app/help/CacheManager.kt
  5. 15
      app/src/main/java/io/legado/app/help/JsExtensions.kt
  6. 4
      app/src/main/java/io/legado/app/utils/ACache.kt

@ -78,7 +78,9 @@ jobs:
files: ${{ github.workspace }}/apk/*.apk files: ${{ github.workspace }}/apk/*.apk
env: env:
GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }} GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }}
- name: Push Assets To "release" Branch - name: Push Assets To "release" Branch
if: ${{ github.actor == 'gedoor' }}
run: | run: |
cd $GITHUB_WORKSPACE/apk || exit 1 cd $GITHUB_WORKSPACE/apk || exit 1
git init git init
@ -87,11 +89,12 @@ jobs:
git checkout -b release git checkout -b release
git add *.apk git add *.apk
git commit -m "${{ env.RELEASE_VERSION }}" 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 git push -f -u origin release
- name: Purge Jsdelivr Cache - name: Purge Jsdelivr Cache
if: ${{ github.actor == 'gedoor' }}
run: | 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 if echo $result |grep -q 'success.*true'; then
echo "jsdelivr缓存更新成功" echo "jsdelivr缓存更新成功"
else else

@ -5,7 +5,7 @@ on:
branches: branches:
- master - master
workflow_dispatch: workflow_dispatch:
jobs: jobs:
prepare: prepare:
runs-on: ubuntu-latest runs-on: ubuntu-latest
@ -15,25 +15,25 @@ jobs:
lanzou: ${{ steps.check.outputs.lanzou }} lanzou: ${{ steps.check.outputs.lanzou }}
telegram: ${{ steps.check.outputs.telegram }} telegram: ${{ steps.check.outputs.telegram }}
steps: steps:
- id: set-ver - id: set-ver
run: | run: |
echo "::set-output name=version::$(date -d "8 hour" -u +3.%y.%m%d%H)" 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)" echo "::set-output name=versionL::$(date -d "8 hour" -u +3.%y.%m%d%H%M)"
- id: check - id: check
run: | run: |
if [ ${{ secrets.LANZOU_ID }} ]; then if [ ${{ secrets.LANZOU_ID }} ]; then
echo "::set-output name=lanzou::yes" echo "::set-output name=lanzou::yes"
fi fi
if [ ${{ secrets.BOT_TOKEN }} ]; then if [ ${{ secrets.BOT_TOKEN }} ]; then
echo "::set-output name=telegram::yes" echo "::set-output name=telegram::yes"
fi fi
build: build:
needs: prepare needs: prepare
strategy: strategy:
matrix: matrix:
product: [app, google] product: [ app, google ]
type: [release, releaseA] type: [ release, releaseA ]
fail-fast: false fail-fast: false
runs-on: ubuntu-latest runs-on: ubuntu-latest
env: env:
@ -91,7 +91,7 @@ jobs:
path: ${{ github.workspace }}/apk/*.apk path: ${{ github.workspace }}/apk/*.apk
lanzou: lanzou:
needs: [prepare, build] needs: [ prepare, build ]
if: ${{ needs.prepare.outputs.lanzou }} if: ${{ needs.prepare.outputs.lanzou }}
runs-on: ubuntu-latest runs-on: ubuntu-latest
env: env:
@ -115,8 +115,9 @@ jobs:
echo "[$(date -u -d '+8 hour' '+%Y.%m.%d %H:%M:%S')] 分享链接: https://kunfei.lanzoux.com/b0f810h4b" echo "[$(date -u -d '+8 hour' '+%Y.%m.%d %H:%M:%S')] 分享链接: https://kunfei.lanzoux.com/b0f810h4b"
test_Branch: test_Branch:
needs: [prepare, build] needs: [ prepare, build ]
runs-on: ubuntu-latest runs-on: ubuntu-latest
if: ${{ github.actor == 'gedoor' }}
steps: steps:
- uses: actions/checkout@v2 - uses: actions/checkout@v2
- uses: actions/download-artifact@v2 - uses: actions/download-artifact@v2
@ -133,11 +134,11 @@ jobs:
git checkout -b test git checkout -b test
git add *.apk git add *.apk
git commit -m "${{ needs.prepare.outputs.versionL }}" 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 git push -f -u origin test
telegram: telegram:
needs: [prepare, build] needs: [ prepare, build ]
if: ${{ needs.prepare.outputs.telegram }} if: ${{ needs.prepare.outputs.telegram }}
runs-on: ubuntu-latest runs-on: ubuntu-latest
env: env:

@ -52,7 +52,7 @@ Legado is a free and open source novel reader for Android.
* [Releases](https://github.com/gedoor/legado/releases/latest) * [Releases](https://github.com/gedoor/legado/releases/latest)
* [Google play - $1.99](https://play.google.com/store/apps/details?id=io.legado.play.release) * [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) * [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) * [\#Beta](https://kunfei.lanzoui.com/b0f810h4b)

@ -28,6 +28,10 @@ object CacheManager {
} }
} }
fun putString2File(key: String, value: String, saveTime: Int = 0) {
ACache.get(appCtx).put(key, value, saveTime)
}
fun get(key: String): String? { fun get(key: String): String? {
return appDb.cacheDao.get(key, System.currentTimeMillis()) return appDb.cacheDao.get(key, System.currentTimeMillis())
} }
@ -52,6 +56,10 @@ object CacheManager {
return ACache.get(appCtx).getAsBinary(key) return ACache.get(appCtx).getAsBinary(key)
} }
fun getString(key: String): String? {
return ACache.get(appCtx).getAsString(key)
}
fun getQueryTTF(key: String): QueryTTF? { fun getQueryTTF(key: String): QueryTTF? {
val cache = queryTTFMap[key] ?: return null val cache = queryTTFMap[key] ?: return null
if (cache.first == 0L || cache.first > System.currentTimeMillis()) { if (cache.first == 0L || cache.first > System.currentTimeMillis()) {

@ -138,15 +138,14 @@ interface JsExtensions {
* @param saveTime 缓存时间单位 * @param saveTime 缓存时间单位
* @return 返回缓存后的文件内容 * @return 返回缓存后的文件内容
*/ */
fun cacheFile(url: String, saveTime: Int = 0): String? { fun cacheFile(urlStr: String, saveTime: Int = 0): String? {
val key = md5Encode16(url) val key = md5Encode16(urlStr)
val cache = ACache.get(appCtx).getAsString(key) val cache = CacheManager.getString(key)
if(cache.isNullOrBlank()) { if(cache.isNullOrBlank()) {
log("首次下载${url}...") log("首次下载 ${urlStr}")
val value = ajax(url) ?: "" val value = ajax(urlStr) ?: return null
if (saveTime == 0) { CacheManager.putString2File(key, value, saveTime)
ACache.get(appCtx).put(key, value) return value
} else ACache.get(appCtx).put(key, value, saveTime)
} }
return cache return cache
} }

@ -109,7 +109,7 @@ class ACache private constructor(cacheDir: File, max_size: Long, max_count: Int)
* @param saveTime 保存的时间单位 * @param saveTime 保存的时间单位
*/ */
fun put(key: String, value: String, saveTime: Int) { 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 保存的时间单位 * @param saveTime 保存的时间单位
*/ */
fun put(key: String, value: ByteArray, saveTime: Int) { 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))
} }
/** /**

Loading…
Cancel
Save