diff --git a/.github/scripts/check_alist.sh b/.github/scripts/check_alist.sh new file mode 100644 index 0000000..03e07bf --- /dev/null +++ b/.github/scripts/check_alist.sh @@ -0,0 +1,53 @@ +#!/bin/bash + +function to_int() { + echo $(echo "$1" | grep -oE '[0-9]+' | tr -d '\n') +} + +function get_latest_version() { + echo $(curl -s https://api.github.com/repos/alist-org/alist/releases/latest | grep -o '"tag_name": ".*"' | cut -d'"' -f4) +} + +LATEST_VER="" +for index in $(seq 5) +do + echo "Try to get latest version, index=$index" + LATEST_VER=$(get_latest_version) + if [ -z "$LATEST_VER" ]; then + if [ "$index" -ge 5 ]; then + echo "Failed to get latest version, exit" + exit 1 + fi + echo "Failed to get latest version, sleep 15s and retry" + sleep 15 + else + break + fi + +done + +LATEST_VER_INT=$(to_int "$LATEST_VER") +echo "Latest AList version $LATEST_VER ${LATEST_VER_INT}" + +echo "alist_version=$LATEST_VER" >> "$GITHUB_ENV" +# VERSION_FILE="$GITHUB_WORKSPACE/alist_version.txt" + +VER=$(cat "$VERSION_FILE") + +if [ -z "$VER" ]; then + VER="v3.25.1" + echo "No version file, use default version ${VER}" +fi + +VER_INT=$(to_int $VER) + +echo "Current AList version: $VER ${VER_INT}" + + +if [ "$VER_INT" -ge "$LATEST_VER_INT" ]; then + echo "Current >= Latest" + echo "alist_update=0" >> "$GITHUB_ENV" +else + echo "Current < Latest" + echo "alist_update=1" >> "$GITHUB_ENV" +fi diff --git a/.github/scripts/lzy_web.py b/.github/scripts/lzy_web.py new file mode 100644 index 0000000..5ce7b30 --- /dev/null +++ b/.github/scripts/lzy_web.py @@ -0,0 +1,98 @@ +import requests, os, datetime, sys + +# Cookie 中 phpdisk_info 的值 +cookie_phpdisk_info = os.environ.get('phpdisk_info') +# Cookie 中 ylogin 的值 +cookie_ylogin = os.environ.get('ylogin') + +# 请求头 +headers = { + 'User-Agent': 'Mozilla/5.0 (Windows NT 10.0; Win64; x64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/89.0.4389.72 Safari/537.36 Edg/89.0.774.45', + 'Accept-Language': 'zh-CN,zh;q=0.9', + 'Referer': 'https://pc.woozooo.com/account.php?action=login' +} + +# 小饼干 +cookie = { + 'ylogin': cookie_ylogin, + 'phpdisk_info': cookie_phpdisk_info +} + + +# 日志打印 +def log(msg): + utc_time = datetime.datetime.utcnow() + china_time = utc_time + datetime.timedelta(hours=8) + print(f"[{china_time.strftime('%Y.%m.%d %H:%M:%S')}] {msg}") + + +# 检查是否已登录 +def login_by_cookie(): + url_account = "https://pc.woozooo.com/account.php" + if cookie['phpdisk_info'] is None: + log('ERROR: 请指定 Cookie 中 phpdisk_info 的值!') + return False + if cookie['ylogin'] is None: + log('ERROR: 请指定 Cookie 中 ylogin 的值!') + return False + res = requests.get(url_account, headers=headers, cookies=cookie, verify=True) + if '网盘用户登录' in res.text: + log('ERROR: 登录失败,请更新Cookie') + return False + else: + log('登录成功') + return True + + +# 上传文件 +def upload_file(file_dir, folder_id): + file_name = os.path.basename(file_dir) + url_upload = "https://up.woozooo.com/fileup.php" + headers['Referer'] = f'https://up.woozooo.com/mydisk.php?item=files&action=index&u={cookie_ylogin}' + post_data = { + "task": "1", + "folder_id": folder_id, + "id": "WU_FILE_0", + "name": file_name, + } + files = {'upload_file': (file_name, open(file_dir, "rb"), 'application/octet-stream')} + res = requests.post(url_upload, data=post_data, files=files, headers=headers, cookies=cookie, timeout=120).json() + log(f"{file_dir} -> {res['info']}") + return res['zt'] == 1 + + +# 上传文件夹内的文件 +def upload_folder(folder_dir, folder_id): + file_list = sorted(os.listdir(folder_dir), reverse=True) + for file in file_list: + path = os.path.join(folder_dir, file) + if os.path.isfile(path): + upload_file(path, folder_id) + else: + upload_folder(path, folder_id) + + +# 上传 +def upload(dir, folder_id): + if dir is None: + log('ERROR: 请指定上传的文件路径') + return + if folder_id is None: + log('ERROR: 请指定蓝奏云的文件夹id') + return + if os.path.isfile(dir): + upload_file(dir, str(folder_id)) + else: + upload_folder(dir, str(folder_id)) + + +if __name__ == '__main__': + argv = sys.argv[1:] + if len(argv) != 2: + log('ERROR: 参数错误,请以这种格式重新尝试\npython lzy_web.py 需上传的路径 蓝奏云文件夹id') + # 需上传的路径 + upload_path = argv[0] + # 蓝奏云文件夹id + lzy_folder_id = argv[1] + if login_by_cookie(): + upload(upload_path, lzy_folder_id) \ No newline at end of file diff --git a/.github/workflows/build.yaml b/.github/workflows/build.yaml new file mode 100644 index 0000000..cf3469b --- /dev/null +++ b/.github/workflows/build.yaml @@ -0,0 +1,126 @@ +name: Build + +on: + push: + branches: + - "master" + paths-ignore: + - "*.md" + - "*.sh" + - "release.yaml" +# - "sync_frp.yaml" + + workflow_dispatch: + +jobs: + go: + runs-on: ubuntu-latest + strategy: + matrix: + GO_ARCH: [ "386", amd64, arm, arm64 ] + steps: + - uses: actions/checkout@v3 + + - name: Download AList Source Code + run: | + cd $GITHUB_WORKSPACE/alist-lib/scripts + chmod +x *.sh + ./init_alist_core.sh + ./init_alist_web.sh + + - uses: actions/setup-go@v4 + with: + go-version: 1.21.5 + cache-dependency-path: ${{ github.workspace }}/alist-lib/go.sum + + - name: Build + run: | + cd $GITHUB_WORKSPACE/alist-lib + + GOARCH=${{ matrix.GO_ARCH }} + + declare -A goarch2cc=( ["arm64"]="aarch64-linux-android32-clang" ["arm"]="armv7a-linux-androideabi32-clang" ["amd64"]="x86_64-linux-android32-clang" ["386"]="i686-linux-android32-clang") + export CC="$ANDROID_NDK_LATEST_HOME/toolchains/llvm/prebuilt/linux-x86_64/bin/${goarch2cc[$GOARCH]}" + + declare -A arch2lib=( ["arm64"]="arm64-v8a" ["arm"]="armeabi-v7a" ["amd64"]="x86_64" ["386"]="x86") + export LIB="${arch2lib[$GOARCH]}" + + ./scripts/install_alist.sh $GOARCH $LIB + + - name: Upload to Artifact + uses: actions/upload-artifact@v3 + with: + name: "app_libs" + path: "${{ github.workspace }}/android/app/libs" + + android: + runs-on: ubuntu-latest + needs: [ go ] + env: + output: "${{ github.workspace }}/build/app/outputs/apk/release" + steps: + - uses: actions/checkout@v3 + with: + fetch-depth: 0 + + - uses: actions/setup-java@v3 + with: + distribution: temurin + java-version: 17 + + - name: Setup Gradle + uses: gradle/gradle-build-action@v2.4.2 + + - name: Download Artifact + uses: actions/download-artifact@v3 + with: + name: "app_libs" + path: "${{ github.workspace }}/android/app/libs" + + - name: Init Signature + run: | + cd android + touch local.properties + echo ALIAS_NAME='${{ secrets.ALIAS_NAME }}' >> local.properties + echo ALIAS_PASSWORD='${{ secrets.ALIAS_PASSWORD }}' >> local.properties + echo KEY_PASSWORD='${{ secrets.KEY_PASSWORD }}' >> local.properties + echo KEY_PATH='./key.jks' >> local.properties + # 从Secrets读取无换行符Base64解码, 然后保存到到app/key.jks + echo ${{ secrets.KEY_STORE }} | base64 --decode > $GITHUB_WORKSPACE/app/key.jks + + - uses: subosito/flutter-action@v2 + with: + flutter-version: '3.16.7' + - run: flutter build apk --split-per-abi --release + + - name: Upload missing_rules.txt + if: failure() && steps.gradle.outcome != 'success' + uses: actions/upload-artifact@v3 + with: + name: "missing_rules" + path: "${{ github.workspace }}/build/app/outputs/mapping/release/missing_rules.txt" + + - name: Init APP Version Name + run: | + echo "ver_name=$(grep -m 1 'versionName' ${{ env.output }}/output-metadata.json | cut -d\" -f4)" >> $GITHUB_ENV + + - name: Upload App To Artifact arm64-v8a + if: success () || failure () + uses: actions/upload-artifact@v3 + with: + name: "AListAndroid-v${{ env.ver_name }}_arm64-v8a" + path: "${{ env.output }}/*-v8a.apk" + + - name: Upload App To Artifact arm-v7a + if: success () || failure () + uses: actions/upload-artifact@v3 + with: + name: "AListAndroid-v${{ env.ver_name }}_arm-v7a" + path: "${{ env.output }}/*-v7a.apk" + + - name: Upload App To Artifact x86 + if: success () || failure () + uses: actions/upload-artifact@v3 + with: + name: "AListAndroid-v${{ env.ver_name }}_x86" + path: "${{ env.output }}/*_x86.apk" \ No newline at end of file diff --git a/.github/workflows/release.yaml b/.github/workflows/release.yaml new file mode 100644 index 0000000..09b25ed --- /dev/null +++ b/.github/workflows/release.yaml @@ -0,0 +1,134 @@ +name: Release + +on: + push: + branches: + - "master" + paths: + - "CHANGELOG.md" + workflow_dispatch: + +jobs: + go: + runs-on: ubuntu-latest + strategy: + matrix: + GO_ARCH: [ "386", amd64, arm, arm64 ] + steps: + - uses: actions/checkout@v3 + + - name: Download AList Source Code + run: | + cd $GITHUB_WORKSPACE/alist-lib/scripts + chmod +x *.sh + ./init_alist_core.sh + ./init_alist_web.sh + + - uses: actions/setup-go@v4 + with: + go-version: 1.21.5 + cache-dependency-path: ${{ github.workspace }}/alist-lib/go.sum + + - name: Build + run: | + cd $GITHUB_WORKSPACE/alist-lib + + GOARCH=${{ matrix.GO_ARCH }} + + declare -A goarch2cc=( ["arm64"]="aarch64-linux-android32-clang" ["arm"]="armv7a-linux-androideabi32-clang" ["amd64"]="x86_64-linux-android32-clang" ["386"]="i686-linux-android32-clang") + export CC="$ANDROID_NDK_LATEST_HOME/toolchains/llvm/prebuilt/linux-x86_64/bin/${goarch2cc[$GOARCH]}" + + declare -A arch2lib=( ["arm64"]="arm64-v8a" ["arm"]="armeabi-v7a" ["amd64"]="x86_64" ["386"]="x86") + export LIB="${arch2lib[$GOARCH]}" + + ./scripts/install_alist.sh $GOARCH $LIB + + - name: Upload to Artifact + uses: actions/upload-artifact@v3 + with: + name: "app_libs" + path: "${{ github.workspace }}/android/app/libs" + + android: + runs-on: ubuntu-latest + needs: [ go ] + env: + output: "${{ github.workspace }}/build/app/outputs/apk/release" + steps: + - uses: actions/checkout@v3 + with: + fetch-depth: 0 + + - uses: actions/setup-java@v3 + with: + distribution: temurin + java-version: 17 + + - name: Setup Gradle + uses: gradle/gradle-build-action@v2.4.2 + + - name: Download Artifact + uses: actions/download-artifact@v3 + with: + name: "app_libs" + path: "${{ github.workspace }}/android/app/libs" + + - name: Init Signature + run: | + touch local.properties + cd android + echo ALIAS_NAME='${{ secrets.ALIAS_NAME }}' >> local.properties + echo ALIAS_PASSWORD='${{ secrets.ALIAS_PASSWORD }}' >> local.properties + echo KEY_PASSWORD='${{ secrets.KEY_PASSWORD }}' >> local.properties + echo KEY_PATH='./key.jks' >> local.properties + # 从Secrets读取无换行符Base64解码, 然后保存到到app/key.jks + echo ${{ secrets.KEY_STORE }} | base64 --decode > $GITHUB_WORKSPACE/app/key.jks + + - name: Grant execute permission for gradlew + run: chmod +x gradlew + - name: Build with Gradle + id: gradle + run: ./gradlew assembleRelease -build-cache --parallel --daemon --warning-mode all + + - name: Upload missing_rules.txt + if: failure() && steps.gradle.outcome != 'success' + uses: actions/upload-artifact@v3 + with: + name: "missing_rules" + path: "${{ github.workspace }}/build/app/outputs/mapping/release/missing_rules.txt" + + - name: Init APP Version Name + run: | + echo "ver_name=$(grep -m 1 'versionName' ${{ env.output }}/output-metadata.json | cut -d\" -f4)" >> $GITHUB_ENV + + - name: Upload App To Artifact arm64-v8a + if: success () || failure () + uses: actions/upload-artifact@v3 + with: + name: "AListAndroid-v${{ env.ver_name }}_arm64-v8a" + path: "${{ env.output }}/*-v8a.apk" + + - name: Upload App To Artifact arm-v7a + if: success () || failure () + uses: actions/upload-artifact@v3 + with: + name: "AListAndroid-v${{ env.ver_name }}_arm-v7a" + path: "${{ env.output }}/*-v7a.apk" + + - name: Upload App To Artifact x86 + if: success () || failure () + uses: actions/upload-artifact@v3 + with: + name: "AListAndroid-v${{ env.ver_name }}_x86" + path: "${{ env.output }}/*_x86.apk" + + - uses: softprops/action-gh-release@v0.1.15 + with: + name: ${{ env.ver_name }} + tag_name: ${{ env.ver_name }} + body_path: ${{ github.workspace }}/CHANGELOG.md + draft: false + prerelease: false + files: ${{ env.output }}/*.apk + env: + GITHUB_TOKEN: ${{ secrets.TOKEN }} diff --git a/.github/workflows/sync_alist.yaml b/.github/workflows/sync_alist.yaml new file mode 100644 index 0000000..e6f345e --- /dev/null +++ b/.github/workflows/sync_alist.yaml @@ -0,0 +1,54 @@ +name: CheckAList + +on: + schedule: + - cron: "0 * * * *" # 每小时执行一次 + workflow_dispatch: + push: + branches: + - "master" + paths: + - "sync_alist.yaml" + +jobs: + build: + runs-on: ubuntu-latest + env: + VERSION_FILE: ${{ github.workspace }}/alist_version + steps: + - uses: actions/checkout@v3 + - run: | + cd $GITHUB_WORKSPACE/.github/scripts + chmod +x ./*.sh + + touch ${{ env.VERSION_FILE }} + ./check_alist.sh + + - name: Shell + run: | + echo "alist_version=${{ env.alist_version }}" + echo "alist_update=${{ env.alist_update }}" + + # 用于测试 + # echo "alist_update=1" >> $GITHUB_ENV + + if [ ${{ env.alist_update }} -eq 0 ] + then + echo "无更新" + else + echo -e "[自动同步AList] ${{ env.alist_version }}" > $GITHUB_WORKSPACE/CHANGELOG.md + echo -e "${{ env.alist_version }}" > ${{ env.VERSION_FILE }} + + git config user.name "github-actions" + git config user.email "42014615+jing332@users.noreply.github.com" + git add . + git commit -m "[bot] Update alist to ${{ env.alist_version }}" + git push + fi + + - name: Run workflow release + if: env.alist_update == 1 && ( success() || failure() ) + run: | + gh workflow run release.yaml -R jing332/AlistAndroid + env: + GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }} diff --git a/.gitignore b/.gitignore index 916dcfa..0bbf3c5 100644 --- a/.gitignore +++ b/.gitignore @@ -42,7 +42,17 @@ app.*.map.json /android/app/profile /android/app/release - - local.properties +/alist-lib/* +alist-main +!../alist-lib/alistlib +!../alist-lib/scripts + +*.aar +*.exe +*.tgz +*.jar +*.zip +*.so + diff --git a/android/alist-lib/scripts/clear.sh b/alist-lib/scripts/clear.sh similarity index 100% rename from android/alist-lib/scripts/clear.sh rename to alist-lib/scripts/clear.sh diff --git a/android/alist-lib/scripts/init_alist_core.sh b/alist-lib/scripts/init_alist_core.sh similarity index 65% rename from android/alist-lib/scripts/init_alist_core.sh rename to alist-lib/scripts/init_alist_core.sh index 71e1a04..9344e60 100644 --- a/android/alist-lib/scripts/init_alist_core.sh +++ b/alist-lib/scripts/init_alist_core.sh @@ -6,8 +6,8 @@ echo "Downloading alist ${TAG_NAME} from ${URL}" curl -L -o "alist.tgz" $URL tar xf "alist.tgz" --strip-components 1 -C ../ -echo "Write version to local.properties" -cd ../../ -touch local.properties -sed -i '/ALIST_VERSION/d' local.properties -echo "ALIST_VERSION=${TAG_NAME}" >> local.properties +#echo "Write version to local.properties" +#cd ../../ +#touch local.properties +#sed -i '/ALIST_VERSION/d' local.properties +#echo "ALIST_VERSION=${TAG_NAME}" >> local.properties diff --git a/android/alist-lib/scripts/init_alist_web.sh b/alist-lib/scripts/init_alist_web.sh similarity index 100% rename from android/alist-lib/scripts/init_alist_web.sh rename to alist-lib/scripts/init_alist_web.sh diff --git a/android/alist-lib/scripts/install_alist.sh b/alist-lib/scripts/install_alist.sh similarity index 86% rename from android/alist-lib/scripts/install_alist.sh rename to alist-lib/scripts/install_alist.sh index a76af06..5261ad4 100644 --- a/android/alist-lib/scripts/install_alist.sh +++ b/alist-lib/scripts/install_alist.sh @@ -13,8 +13,8 @@ function build() { go build -ldflags "-s -w" -o ${FN} - mkdir -p ${dir}/../app/libs/$2 - cp -f ${FN} ${dir}/../app/libs/$2 + mkdir -p ${dir}/../android/app/libs/$2 + cp -f ${FN} ${dir}/../android/app/libs/$2 } #cp -f ./frp-*/conf/* ../app/src/main/assets/defaultData diff --git a/android/.gitignore b/android/.gitignore index 2f81e04..4eb1fc2 100644 --- a/android/.gitignore +++ b/android/.gitignore @@ -14,8 +14,8 @@ key.properties /alist-lib/* alist-main -!alist-lib/alistlib -!alist-lib/scripts +!../alist-lib/alistlib +!../alist-lib/scripts *.aar *.exe diff --git a/android/app/build.gradle b/android/app/build.gradle index ef8ed5f..b3337ec 100644 --- a/android/app/build.gradle +++ b/android/app/build.gradle @@ -73,6 +73,26 @@ android { } } + splits { + abi { + enable gradle.startParameter.taskNames.any { it.contains("Release") } + reset() + include 'armeabi-v7a', 'arm64-v8a', 'x86', 'x86_64' + universalApk true + } + } + + android.applicationVariants.all { variant -> + variant.outputs.all { output -> + //noinspection GrDeprecatedAPIUsage + def abiName = output.getFilter(com.android.build.OutputFile.ABI) + if (abiName == null) + output.outputFileName = "AListF-v${variant.versionName}.apk" + else + output.outputFileName = "AListF-v${variant.versionName}_${abiName}.apk" + } + } + // kotlin { // jvmToolchain = 17 // }