chore: 更新CI

This commit is contained in:
maotoumao
2025-06-24 16:37:36 +08:00
parent dbb7365391
commit 9cbb52ad80
4 changed files with 928 additions and 35 deletions

143
.github/workflows/artifact-upload.yml vendored Normal file
View File

@@ -0,0 +1,143 @@
name: 发布到飞书
on:
workflow_dispatch:
inputs:
run_id:
description: 'GitHub Action Run ID to download artifacts from'
required: true
type: string
jobs:
download-and-upload:
runs-on: ubuntu-latest
steps:
- name: Checkout repository
uses: actions/checkout@v4
- name: Setup Node.js
uses: actions/setup-node@v4
with:
node-version: '18'
- name: Install dependencies for upload script
run: |
npm install @larksuiteoapi/node-sdk
- name: Download artifacts from specified run
id: download
env:
GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }}
RUN_ID: ${{ github.event.inputs.run_id }}
run: |
echo "Checking artifacts for run ID: $RUN_ID"
# Get artifacts list for the specified run
artifacts_response=$(curl -s -H "Authorization: token $GITHUB_TOKEN" \
"https://api.github.com/repos/${{ github.repository }}/actions/runs/$RUN_ID/artifacts")
# Check if there are any artifacts
artifacts_count=$(echo "$artifacts_response" | jq '.total_count')
if [ "$artifacts_count" -eq 0 ]; then
echo "No artifacts found for run ID: $RUN_ID"
echo "has_artifacts=false" >> $GITHUB_OUTPUT
exit 0
fi
echo "Found $artifacts_count artifact(s)"
echo "has_artifacts=true" >> $GITHUB_OUTPUT
# Create downloads directory
mkdir -p ./downloads
# Download all artifacts
echo "$artifacts_response" | jq -r '.artifacts[] | "\(.id) \(.name)"' | while read artifact_id artifact_name; do
echo "Downloading artifact: $artifact_name (ID: $artifact_id)"
# Download artifact
curl -L -H "Authorization: token $GITHUB_TOKEN" \
"https://api.github.com/repos/${{ github.repository }}/actions/artifacts/$artifact_id/zip" \
-o "./downloads/${artifact_name}.zip"
echo "Downloaded: ${artifact_name}.zip"
done
- name: Process and upload artifacts
if: steps.download.outputs.has_artifacts == 'true'
env:
FEISHU_APP_ID: ${{ secrets.FEISHU_APP_ID }}
FEISHU_APP_SECRET: ${{ secrets.FEISHU_APP_SECRET }}
FEISHU_PARENT_NODE: E438flrKhlBJvfdmT57cMpOunlE
run: |
cd ./downloads
for zip_file in *.zip; do
if [ ! -f "$zip_file" ]; then
continue
fi
echo "Processing: $zip_file"
# Create a directory for this artifact
artifact_dir="${zip_file%.zip}"
mkdir -p "$artifact_dir"
# Extract the artifact zip
unzip -q "$zip_file" -d "$artifact_dir"
# Process files in the extracted directory
for file in "$artifact_dir"/*; do
if [ -f "$file" ]; then
filename=$(basename "$file")
echo "Processing file: $filename"
# Check if filename contains "portable"
if [[ "$filename" == *"portable"* ]]; then
echo "File contains 'portable', uploading directly: $filename"
# Upload file directly without extraction
node ../scripts/feishu-upload.js "$file" "$filename"
else
echo "File does not contain 'portable', checking if it's a zip/archive: $filename"
# Check if it's a zip file and extract it
if [[ "$filename" == *.zip ]]; then
echo "Extracting and uploading contents of: $filename"
extract_dir="${filename%.zip}_extracted"
mkdir -p "$extract_dir"
unzip -q "$file" -d "$extract_dir"
# Upload all extracted files
for extracted_file in "$extract_dir"/*; do
if [ -f "$extracted_file" ]; then
extracted_filename=$(basename "$extracted_file")
echo "Uploading extracted file: $extracted_filename"
node ../scripts/feishu-upload.js "$extracted_file" "$extracted_filename"
fi
done
else
echo "Uploading file directly: $filename"
# Upload non-zip files directly
node ../scripts/feishu-upload.js "$file" "$filename"
fi
fi
fi
done
# Clean up extracted directory
rm -rf "$artifact_dir"
done
- name: Cleanup
if: always()
run: |
rm -rf ./downloads
- name: Summary
run: |
if [ "${{ steps.download.outputs.has_artifacts }}" == "true" ]; then
echo "✅ Artifacts processed and uploaded successfully"
else
echo " No artifacts found for the specified run ID"
fi

426
package-lock.json generated
View File

@@ -1,12 +1,12 @@
{
"name": "musicfree-desktop",
"version": "0.0.7-alpha.1",
"version": "0.0.7",
"lockfileVersion": 3,
"requires": true,
"packages": {
"": {
"name": "musicfree-desktop",
"version": "0.0.7-alpha.1",
"version": "0.0.7",
"license": "GPL",
"dependencies": {
"@headlessui/react": "^1.7.15",
@@ -66,6 +66,7 @@
"@electron-forge/maker-squirrel": "6.4.1",
"@electron-forge/maker-zip": "6.4.1",
"@electron-forge/plugin-webpack": "6.4.1",
"@larksuiteoapi/node-sdk": "^1.50.1",
"@svgr/webpack": "^8.1.0",
"@timfish/forge-externals-plugin": "^0.2.1",
"@types/better-sqlite3": "^7.6.10",
@@ -82,6 +83,7 @@
"@typescript-eslint/parser": "^5.59.7",
"@vercel/webpack-asset-relocator-loader": "^1.7.3",
"babel-loader": "^9.1.3",
"cross-env": "^7.0.3",
"css-loader": "^6.11.0",
"electron": "^25.3.0",
"eslint": "^8.41.0",
@@ -3212,6 +3214,55 @@
"@jridgewell/sourcemap-codec": "^1.4.14"
}
},
"node_modules/@larksuiteoapi/node-sdk": {
"version": "1.50.1",
"resolved": "https://registry.npmmirror.com/@larksuiteoapi/node-sdk/-/node-sdk-1.50.1.tgz",
"integrity": "sha512-hhB+HpTNl4HED9WGzL+2EhU4zQBYVtbTxVHBagohIm5iryNx1g0y7S3l6uAB54vbsnLKRireiH/r+bkV8ViXRg==",
"dev": true,
"license": "MIT",
"dependencies": {
"axios": "0.27.2",
"lodash.identity": "^3.0.0",
"lodash.merge": "^4.6.2",
"lodash.pickby": "^4.6.0",
"protobufjs": "^7.2.6",
"qs": "^6.13.0",
"ws": "^8.16.0"
}
},
"node_modules/@larksuiteoapi/node-sdk/node_modules/axios": {
"version": "0.27.2",
"resolved": "https://registry.npmmirror.com/axios/-/axios-0.27.2.tgz",
"integrity": "sha512-t+yRIyySRTp/wua5xEr+z1q60QmLq8ABsS5O9Me1AsE5dfKqgnCFzwiCZZ/cGNd1lq4/7akDWMxdhVlucjmnOQ==",
"dev": true,
"license": "MIT",
"dependencies": {
"follow-redirects": "^1.14.9",
"form-data": "^4.0.0"
}
},
"node_modules/@larksuiteoapi/node-sdk/node_modules/ws": {
"version": "8.18.2",
"resolved": "https://registry.npmmirror.com/ws/-/ws-8.18.2.tgz",
"integrity": "sha512-DMricUmwGZUVr++AEAe2uiVM7UoO9MAVZMDu05UQOaUII0lp+zOzLLU4Xqh/JvTqklB1T4uELaaPBKyjE1r4fQ==",
"dev": true,
"license": "MIT",
"engines": {
"node": ">=10.0.0"
},
"peerDependencies": {
"bufferutil": "^4.0.1",
"utf-8-validate": ">=5.0.2"
},
"peerDependenciesMeta": {
"bufferutil": {
"optional": true
},
"utf-8-validate": {
"optional": true
}
}
},
"node_modules/@leichtgewicht/ip-codec": {
"version": "2.0.4",
"resolved": "https://registry.npmmirror.com/@leichtgewicht/ip-codec/-/ip-codec-2.0.4.tgz",
@@ -3657,6 +3708,80 @@
"node": ">=14"
}
},
"node_modules/@protobufjs/aspromise": {
"version": "1.1.2",
"resolved": "https://registry.npmmirror.com/@protobufjs/aspromise/-/aspromise-1.1.2.tgz",
"integrity": "sha512-j+gKExEuLmKwvz3OgROXtrJ2UG2x8Ch2YZUxahh+s1F2HZ+wAceUNLkvy6zKCPVRkU++ZWQrdxsUeQXmcg4uoQ==",
"dev": true,
"license": "BSD-3-Clause"
},
"node_modules/@protobufjs/base64": {
"version": "1.1.2",
"resolved": "https://registry.npmmirror.com/@protobufjs/base64/-/base64-1.1.2.tgz",
"integrity": "sha512-AZkcAA5vnN/v4PDqKyMR5lx7hZttPDgClv83E//FMNhR2TMcLUhfRUBHCmSl0oi9zMgDDqRUJkSxO3wm85+XLg==",
"dev": true,
"license": "BSD-3-Clause"
},
"node_modules/@protobufjs/codegen": {
"version": "2.0.4",
"resolved": "https://registry.npmmirror.com/@protobufjs/codegen/-/codegen-2.0.4.tgz",
"integrity": "sha512-YyFaikqM5sH0ziFZCN3xDC7zeGaB/d0IUb9CATugHWbd1FRFwWwt4ld4OYMPWu5a3Xe01mGAULCdqhMlPl29Jg==",
"dev": true,
"license": "BSD-3-Clause"
},
"node_modules/@protobufjs/eventemitter": {
"version": "1.1.0",
"resolved": "https://registry.npmmirror.com/@protobufjs/eventemitter/-/eventemitter-1.1.0.tgz",
"integrity": "sha512-j9ednRT81vYJ9OfVuXG6ERSTdEL1xVsNgqpkxMsbIabzSo3goCjDIveeGv5d03om39ML71RdmrGNjG5SReBP/Q==",
"dev": true,
"license": "BSD-3-Clause"
},
"node_modules/@protobufjs/fetch": {
"version": "1.1.0",
"resolved": "https://registry.npmmirror.com/@protobufjs/fetch/-/fetch-1.1.0.tgz",
"integrity": "sha512-lljVXpqXebpsijW71PZaCYeIcE5on1w5DlQy5WH6GLbFryLUrBD4932W/E2BSpfRJWseIL4v/KPgBFxDOIdKpQ==",
"dev": true,
"license": "BSD-3-Clause",
"dependencies": {
"@protobufjs/aspromise": "^1.1.1",
"@protobufjs/inquire": "^1.1.0"
}
},
"node_modules/@protobufjs/float": {
"version": "1.0.2",
"resolved": "https://registry.npmmirror.com/@protobufjs/float/-/float-1.0.2.tgz",
"integrity": "sha512-Ddb+kVXlXst9d+R9PfTIxh1EdNkgoRe5tOX6t01f1lYWOvJnSPDBlG241QLzcyPdoNTsblLUdujGSE4RzrTZGQ==",
"dev": true,
"license": "BSD-3-Clause"
},
"node_modules/@protobufjs/inquire": {
"version": "1.1.0",
"resolved": "https://registry.npmmirror.com/@protobufjs/inquire/-/inquire-1.1.0.tgz",
"integrity": "sha512-kdSefcPdruJiFMVSbn801t4vFK7KB/5gd2fYvrxhuJYg8ILrmn9SKSX2tZdV6V+ksulWqS7aXjBcRXl3wHoD9Q==",
"dev": true,
"license": "BSD-3-Clause"
},
"node_modules/@protobufjs/path": {
"version": "1.1.2",
"resolved": "https://registry.npmmirror.com/@protobufjs/path/-/path-1.1.2.tgz",
"integrity": "sha512-6JOcJ5Tm08dOHAbdR3GrvP+yUUfkjG5ePsHYczMFLq3ZmMkAD98cDgcT2iA1lJ9NVwFd4tH/iSSoe44YWkltEA==",
"dev": true,
"license": "BSD-3-Clause"
},
"node_modules/@protobufjs/pool": {
"version": "1.1.0",
"resolved": "https://registry.npmmirror.com/@protobufjs/pool/-/pool-1.1.0.tgz",
"integrity": "sha512-0kELaGSIDBKvcgS4zkjz1PeddatrjYcmMWOlAuAPwAeccUrPHdUqo/J6LiymHHEiJT5NrF1UVwxY14f+fy4WQw==",
"dev": true,
"license": "BSD-3-Clause"
},
"node_modules/@protobufjs/utf8": {
"version": "1.1.0",
"resolved": "https://registry.npmmirror.com/@protobufjs/utf8/-/utf8-1.1.0.tgz",
"integrity": "sha512-Vvn3zZrhQZkkBE8LSuW3em98c0FwgO4nxzv6OdSxPKJIEKY2bGbHn+mhGIPerzI4twdxaP8/0+06HBpwf345Lw==",
"dev": true,
"license": "BSD-3-Clause"
},
"node_modules/@remix-run/router": {
"version": "1.16.1",
"resolved": "https://registry.npmmirror.com/@remix-run/router/-/router-1.16.1.tgz",
@@ -5918,6 +6043,7 @@
"version": "1.0.7",
"resolved": "https://registry.npmmirror.com/call-bind/-/call-bind-1.0.7.tgz",
"integrity": "sha512-GHTSNSYICQ7scH7sZ+M2rFopRoLh8t2bLSW6BbgrtLsahOIB5iyAVJf9GjWK3cYTDaMj4XdBpM1cA6pIS0Kv2w==",
"dev": true,
"dependencies": {
"es-define-property": "^1.0.0",
"es-errors": "^1.3.0",
@@ -5929,6 +6055,35 @@
"node": ">= 0.4"
}
},
"node_modules/call-bind-apply-helpers": {
"version": "1.0.2",
"resolved": "https://registry.npmmirror.com/call-bind-apply-helpers/-/call-bind-apply-helpers-1.0.2.tgz",
"integrity": "sha512-Sp1ablJ0ivDkSzjcaJdxEunN5/XvksFJ2sMBFfq6x0ryhQV/2b/KwFe21cMpmHtPOSij8K99/wSfoEuTObmuMQ==",
"license": "MIT",
"dependencies": {
"es-errors": "^1.3.0",
"function-bind": "^1.1.2"
},
"engines": {
"node": ">= 0.4"
}
},
"node_modules/call-bound": {
"version": "1.0.4",
"resolved": "https://registry.npmmirror.com/call-bound/-/call-bound-1.0.4.tgz",
"integrity": "sha512-+ys997U96po4Kx/ABpBCqhA9EuxJaQWDQg7295H4hBphv3IZg0boBKuwYpt4YXp6MZ5AmZQnU/tyMTlRpaSejg==",
"license": "MIT",
"dependencies": {
"call-bind-apply-helpers": "^1.0.2",
"get-intrinsic": "^1.3.0"
},
"engines": {
"node": ">= 0.4"
},
"funding": {
"url": "https://github.com/sponsors/ljharb"
}
},
"node_modules/callsites": {
"version": "3.1.0",
"resolved": "https://registry.npmmirror.com/callsites/-/callsites-3.1.0.tgz",
@@ -6556,6 +6711,25 @@
"dev": true,
"optional": true
},
"node_modules/cross-env": {
"version": "7.0.3",
"resolved": "https://registry.npmmirror.com/cross-env/-/cross-env-7.0.3.tgz",
"integrity": "sha512-+/HKd6EgcQCJGh2PSjZuUitQBQynKor4wrFbRg4DtAgS1aWO+gU52xpH7M9ScGgXSYmAVS9bIJ8EzuaGw0oNAw==",
"dev": true,
"license": "MIT",
"dependencies": {
"cross-spawn": "^7.0.1"
},
"bin": {
"cross-env": "src/bin/cross-env.js",
"cross-env-shell": "src/bin/cross-env-shell.js"
},
"engines": {
"node": ">=10.14",
"npm": ">=6",
"yarn": ">=1"
}
},
"node_modules/cross-spawn": {
"version": "7.0.3",
"resolved": "https://registry.npmmirror.com/cross-spawn/-/cross-spawn-7.0.3.tgz",
@@ -6957,6 +7131,7 @@
"version": "1.1.4",
"resolved": "https://registry.npmmirror.com/define-data-property/-/define-data-property-1.1.4.tgz",
"integrity": "sha512-rBMvIzlpA8v6E+SJZoo++HAYqsLrkg7MSfIinMPFhmkorw7X+dOXVJQs+QT69zGkzMyfDnIMN2Wid1+NbL3T+A==",
"dev": true,
"dependencies": {
"es-define-property": "^1.0.0",
"es-errors": "^1.3.0",
@@ -7171,6 +7346,20 @@
"tn1150": "^0.1.0"
}
},
"node_modules/dunder-proto": {
"version": "1.0.1",
"resolved": "https://registry.npmmirror.com/dunder-proto/-/dunder-proto-1.0.1.tgz",
"integrity": "sha512-KIN/nDJBQRcXw0MLVhZE9iQHmG68qAVIBg9CqmUYjmQIhgij9U5MFvrqkUL5FbtyyzZuOeOt0zdeRe4UY7ct+A==",
"license": "MIT",
"dependencies": {
"call-bind-apply-helpers": "^1.0.1",
"es-errors": "^1.3.0",
"gopd": "^1.2.0"
},
"engines": {
"node": ">= 0.4"
}
},
"node_modules/duplexer2": {
"version": "0.1.4",
"resolved": "https://registry.npmjs.org/duplexer2/-/duplexer2-0.1.4.tgz",
@@ -7879,12 +8068,10 @@
}
},
"node_modules/es-define-property": {
"version": "1.0.0",
"resolved": "https://registry.npmmirror.com/es-define-property/-/es-define-property-1.0.0.tgz",
"integrity": "sha512-jxayLKShrEqqzJ0eumQbVhTYQM27CfT1T35+gCgDFoL82JLsXqTJ76zv6A0YLOgEnLUMvLzsDsGIrl8NFpT2gQ==",
"dependencies": {
"get-intrinsic": "^1.2.4"
},
"version": "1.0.1",
"resolved": "https://registry.npmmirror.com/es-define-property/-/es-define-property-1.0.1.tgz",
"integrity": "sha512-e3nRfgfUZ4rNGL232gUgX06QNyyez04KdjFrF+LTRoOXmrOgFKDg4BCdsjW8EnT69eqdYGmRpJwiPVYNrCaW3g==",
"license": "MIT",
"engines": {
"node": ">= 0.4"
}
@@ -7903,6 +8090,18 @@
"integrity": "sha512-vZK7T0N2CBmBOixhmjdqx2gWVbFZ4DXZ/NyRMZVlJXPa7CyFS+/a4QQsDGDQy9ZfEzxFuNEsMLeQJnKP2p5/JA==",
"dev": true
},
"node_modules/es-object-atoms": {
"version": "1.1.1",
"resolved": "https://registry.npmmirror.com/es-object-atoms/-/es-object-atoms-1.1.1.tgz",
"integrity": "sha512-FGgH2h8zKNim9ljj7dankFPcICIK9Cp5bm+c2gQSYePhpaG5+esrLODihIorn+Pe6FGJzWhXQotPv73jTaldXA==",
"license": "MIT",
"dependencies": {
"es-errors": "^1.3.0"
},
"engines": {
"node": ">= 0.4"
}
},
"node_modules/es-set-tostringtag": {
"version": "2.0.1",
"resolved": "https://registry.npmmirror.com/es-set-tostringtag/-/es-set-tostringtag-2.0.1.tgz",
@@ -9449,18 +9648,27 @@
}
},
"node_modules/get-intrinsic": {
"version": "1.2.4",
"resolved": "https://registry.npmmirror.com/get-intrinsic/-/get-intrinsic-1.2.4.tgz",
"integrity": "sha512-5uYhsJH8VJBTv7oslg4BznJYhDoRI6waYCxMmCdnTrcCrHA/fCFKoTFz2JKKE0HdDFUF7/oQuhzumXJK7paBRQ==",
"version": "1.3.0",
"resolved": "https://registry.npmmirror.com/get-intrinsic/-/get-intrinsic-1.3.0.tgz",
"integrity": "sha512-9fSjSaos/fRIVIp+xSJlE6lfwhES7LNtKaCBIamHsjr2na1BiABJPo0mOjjz8GJDURarmCPGqaiVg5mfjb98CQ==",
"license": "MIT",
"dependencies": {
"call-bind-apply-helpers": "^1.0.2",
"es-define-property": "^1.0.1",
"es-errors": "^1.3.0",
"es-object-atoms": "^1.1.1",
"function-bind": "^1.1.2",
"has-proto": "^1.0.1",
"has-symbols": "^1.0.3",
"hasown": "^2.0.0"
"get-proto": "^1.0.1",
"gopd": "^1.2.0",
"has-symbols": "^1.1.0",
"hasown": "^2.0.2",
"math-intrinsics": "^1.1.0"
},
"engines": {
"node": ">= 0.4"
},
"funding": {
"url": "https://github.com/sponsors/ljharb"
}
},
"node_modules/get-package-info": {
@@ -9493,6 +9701,19 @@
"integrity": "sha512-Tpp60P6IUJDTuOq/5Z8cdskzJujfwqfOTkrwIwj7IRISpnkJnT6SyJ4PCPnGMoFjC9ddhal5KVIYtAt97ix05A==",
"dev": true
},
"node_modules/get-proto": {
"version": "1.0.1",
"resolved": "https://registry.npmmirror.com/get-proto/-/get-proto-1.0.1.tgz",
"integrity": "sha512-sTSfBjoXBp89JvIKIefqw7U2CCebsc74kiY6awiGogKtoSGbgjYE/G/+l9sF3MWFPNc9IcoOC4ODfKHfxFmp0g==",
"license": "MIT",
"dependencies": {
"dunder-proto": "^1.0.1",
"es-object-atoms": "^1.0.0"
},
"engines": {
"node": ">= 0.4"
}
},
"node_modules/get-stdin": {
"version": "4.0.1",
"resolved": "https://registry.npmmirror.com/get-stdin/-/get-stdin-4.0.1.tgz",
@@ -9751,11 +9972,15 @@
}
},
"node_modules/gopd": {
"version": "1.0.1",
"resolved": "https://registry.npmmirror.com/gopd/-/gopd-1.0.1.tgz",
"integrity": "sha512-d65bNlIadxvpb/A2abVdlqKqV563juRnZ1Wtk6s1sIR8uNsXR70xqIzVqxVf1eTqDunwT2MkczEeaezCKTZhwA==",
"dependencies": {
"get-intrinsic": "^1.1.3"
"version": "1.2.0",
"resolved": "https://registry.npmmirror.com/gopd/-/gopd-1.2.0.tgz",
"integrity": "sha512-ZUKRh6/kUFoAiTAtTYPZJ3hw9wNxx+BIBOijnlG9PnrJsCcSjs1wyyD6vJpaYtgnzDrKYRSqf3OO6Rfa93xsRg==",
"license": "MIT",
"engines": {
"node": ">= 0.4"
},
"funding": {
"url": "https://github.com/sponsors/ljharb"
}
},
"node_modules/got": {
@@ -9839,6 +10064,7 @@
"version": "1.0.2",
"resolved": "https://registry.npmmirror.com/has-property-descriptors/-/has-property-descriptors-1.0.2.tgz",
"integrity": "sha512-55JNKuIW+vq4Ke1BjOTjM2YctQIvCT7GFzHwmfZPGo5wnrgkid0YQtnAleFSqumZm4az3n2BS+erby5ipJdgrg==",
"dev": true,
"dependencies": {
"es-define-property": "^1.0.0"
}
@@ -9847,16 +10073,21 @@
"version": "1.0.1",
"resolved": "https://registry.npmmirror.com/has-proto/-/has-proto-1.0.1.tgz",
"integrity": "sha512-7qE+iP+O+bgF9clE5+UoBFzE65mlBiVj3tKCrlNQ0Ogwm0BjpT/gK4SlLYDMybDh5I3TCTKnPPa0oMG7JDYrhg==",
"dev": true,
"engines": {
"node": ">= 0.4"
}
},
"node_modules/has-symbols": {
"version": "1.0.3",
"resolved": "https://registry.npmmirror.com/has-symbols/-/has-symbols-1.0.3.tgz",
"integrity": "sha512-l3LCuF6MgDNwTDKkdYGEihYjt5pRPbEg46rtlmnSPlUbgmB8LOIrKJbYYFBSbnPaJexMKtiPO8hmeRjRz2Td+A==",
"version": "1.1.0",
"resolved": "https://registry.npmmirror.com/has-symbols/-/has-symbols-1.1.0.tgz",
"integrity": "sha512-1cDNdwJ2Jaohmb3sg4OmKaMBwuC48sYni5HUw2DvsC8LjGTLK9h+eb1X6RyuOHe4hT0ULCW68iomhjUoKUqlPQ==",
"license": "MIT",
"engines": {
"node": ">= 0.4"
},
"funding": {
"url": "https://github.com/sponsors/ljharb"
}
},
"node_modules/has-tostringtag": {
@@ -11466,12 +11697,26 @@
"integrity": "sha512-z+Uw/vLuy6gQe8cfaFWD7p0wVv8fJl3mbzXh33RS+0oW2wvUqiRXiQ69gLWSLpgB5/6sU+r6BlQR0MBILadqTQ==",
"dev": true
},
"node_modules/lodash.identity": {
"version": "3.0.0",
"resolved": "https://registry.npmmirror.com/lodash.identity/-/lodash.identity-3.0.0.tgz",
"integrity": "sha512-AupTIzdLQxJS5wIYUQlgGyk2XRTfGXA+MCghDHqZk0pzUNYvd3EESS6dkChNauNYVIutcb0dfHw1ri9Q1yPV8Q==",
"dev": true,
"license": "MIT"
},
"node_modules/lodash.merge": {
"version": "4.6.2",
"resolved": "https://registry.npmmirror.com/lodash.merge/-/lodash.merge-4.6.2.tgz",
"integrity": "sha512-0KpjqXRVvrYyCsX1swR/XTK0va6VQkQM6MNo7PqW77ByjAhoARA8EfrP1N4+KlKj8YS0ZUCtRT/YUuhyYDujIQ==",
"dev": true
},
"node_modules/lodash.pickby": {
"version": "4.6.0",
"resolved": "https://registry.npmmirror.com/lodash.pickby/-/lodash.pickby-4.6.0.tgz",
"integrity": "sha512-AZV+GsS/6ckvPOVQPXSiFFacKvKB4kOQu6ynt9wz0F3LO4R9Ij4K1ddYsIytDpSgLz88JHd9P+oaLeej5/Sl7Q==",
"dev": true,
"license": "MIT"
},
"node_modules/lodash.shuffle": {
"version": "4.2.0",
"resolved": "https://registry.npmmirror.com/lodash.shuffle/-/lodash.shuffle-4.2.0.tgz",
@@ -11632,6 +11877,13 @@
"node": ">=8"
}
},
"node_modules/long": {
"version": "5.3.2",
"resolved": "https://registry.npmmirror.com/long/-/long-5.3.2.tgz",
"integrity": "sha512-mNAgZ1GmyNhD7AuqnTG3/VQ26o760+ZYBPKjPvugO8+nLbYfX6TVpJPseBvopbdY+qpZ/lKUnmEc1LeZYS3QAA==",
"dev": true,
"license": "Apache-2.0"
},
"node_modules/loose-envify": {
"version": "1.4.0",
"resolved": "https://registry.npmmirror.com/loose-envify/-/loose-envify-1.4.0.tgz",
@@ -11802,6 +12054,15 @@
"node": ">=10"
}
},
"node_modules/math-intrinsics": {
"version": "1.1.0",
"resolved": "https://registry.npmmirror.com/math-intrinsics/-/math-intrinsics-1.1.0.tgz",
"integrity": "sha512-/IXtbwEk5HTPyEwyKX6hGkYXxM9nbj64B+ilVJnC/R6B0pH5G4V3b0pVbL7DBj4tkhBAppbQUlf6F6Xl9LHu1g==",
"license": "MIT",
"engines": {
"node": ">= 0.4"
}
},
"node_modules/md5": {
"version": "2.3.0",
"resolved": "https://registry.npmjs.org/md5/-/md5-2.3.0.tgz",
@@ -13270,9 +13531,16 @@
}
},
"node_modules/object-inspect": {
"version": "1.13.1",
"resolved": "https://registry.npmmirror.com/object-inspect/-/object-inspect-1.13.1.tgz",
"integrity": "sha512-5qoj1RUiKOMsCCNLV1CBiPYE10sziTsnmNxkAI/rZhiD63CF7IqdFGC/XzjWjpSgLf0LxXX3bDFIh0E18f6UhQ=="
"version": "1.13.4",
"resolved": "https://registry.npmmirror.com/object-inspect/-/object-inspect-1.13.4.tgz",
"integrity": "sha512-W67iLl4J2EXEGTbfeHCffrjDfitvLANg0UlX3wFUUSTx92KXRFegMHUVgSqE+wvhAbi4WqjGg9czysTV2Epbew==",
"license": "MIT",
"engines": {
"node": ">= 0.4"
},
"funding": {
"url": "https://github.com/sponsors/ljharb"
}
},
"node_modules/object-keys": {
"version": "1.1.1",
@@ -14185,6 +14453,31 @@
"node": ">=10"
}
},
"node_modules/protobufjs": {
"version": "7.5.3",
"resolved": "https://registry.npmmirror.com/protobufjs/-/protobufjs-7.5.3.tgz",
"integrity": "sha512-sildjKwVqOI2kmFDiXQ6aEB0fjYTafpEvIBs8tOR8qI4spuL9OPROLVu2qZqi/xgCfsHIwVqlaF8JBjWFHnKbw==",
"dev": true,
"hasInstallScript": true,
"license": "BSD-3-Clause",
"dependencies": {
"@protobufjs/aspromise": "^1.1.2",
"@protobufjs/base64": "^1.1.2",
"@protobufjs/codegen": "^2.0.4",
"@protobufjs/eventemitter": "^1.1.0",
"@protobufjs/fetch": "^1.1.0",
"@protobufjs/float": "^1.0.2",
"@protobufjs/inquire": "^1.1.0",
"@protobufjs/path": "^1.1.2",
"@protobufjs/pool": "^1.1.0",
"@protobufjs/utf8": "^1.1.0",
"@types/node": ">=13.7.0",
"long": "^5.0.0"
},
"engines": {
"node": ">=12.0.0"
}
},
"node_modules/proxy-addr": {
"version": "2.0.7",
"resolved": "https://registry.npmmirror.com/proxy-addr/-/proxy-addr-2.0.7.tgz",
@@ -14223,14 +14516,18 @@
}
},
"node_modules/qs": {
"version": "6.12.1",
"resolved": "https://registry.npmmirror.com/qs/-/qs-6.12.1.tgz",
"integrity": "sha512-zWmv4RSuB9r2mYQw3zxQuHWeU+42aKi1wWig/j4ele4ygELZ7PEO6MM7rim9oAQH2A5MWfsAVf/jPvTPgCbvUQ==",
"version": "6.14.0",
"resolved": "https://registry.npmmirror.com/qs/-/qs-6.14.0.tgz",
"integrity": "sha512-YWWTjgABSKcvs/nWBi9PycY/JiPJqOD4JA6o9Sej2AtvSGarXxKC3OQSk4pAarbdQlKAh5D4FCQkJNkW+GAn3w==",
"license": "BSD-3-Clause",
"dependencies": {
"side-channel": "^1.0.6"
"side-channel": "^1.1.0"
},
"engines": {
"node": ">=0.6"
},
"funding": {
"url": "https://github.com/sponsors/ljharb"
}
},
"node_modules/querystringify": {
@@ -15549,6 +15846,7 @@
"version": "1.2.2",
"resolved": "https://registry.npmmirror.com/set-function-length/-/set-function-length-1.2.2.tgz",
"integrity": "sha512-pgRc4hJ4/sNjWCSS9AmnS40x3bNMDTknHgL5UaMBTMyJnU90EgWh1Rz+MC9eFu4BuN/UwZjKQuY/1v3rM7HMfg==",
"dev": true,
"dependencies": {
"define-data-property": "^1.1.4",
"es-errors": "^1.3.0",
@@ -15635,17 +15933,75 @@
"dev": true
},
"node_modules/side-channel": {
"version": "1.0.6",
"resolved": "https://registry.npmmirror.com/side-channel/-/side-channel-1.0.6.tgz",
"integrity": "sha512-fDW/EZ6Q9RiO8eFG8Hj+7u/oW+XrPTIChwCOM2+th2A6OblDtYYIpve9m+KvI9Z4C9qSEXlaGR6bTEYHReuglA==",
"version": "1.1.0",
"resolved": "https://registry.npmmirror.com/side-channel/-/side-channel-1.1.0.tgz",
"integrity": "sha512-ZX99e6tRweoUXqR+VBrslhda51Nh5MTQwou5tnUDgbtyM0dBgmhEDtWGP/xbKn6hqfPRHujUNwz5fy/wbbhnpw==",
"license": "MIT",
"dependencies": {
"call-bind": "^1.0.7",
"es-errors": "^1.3.0",
"get-intrinsic": "^1.2.4",
"object-inspect": "^1.13.1"
"object-inspect": "^1.13.3",
"side-channel-list": "^1.0.0",
"side-channel-map": "^1.0.1",
"side-channel-weakmap": "^1.0.2"
},
"engines": {
"node": ">= 0.4"
},
"funding": {
"url": "https://github.com/sponsors/ljharb"
}
},
"node_modules/side-channel-list": {
"version": "1.0.0",
"resolved": "https://registry.npmmirror.com/side-channel-list/-/side-channel-list-1.0.0.tgz",
"integrity": "sha512-FCLHtRD/gnpCiCHEiJLOwdmFP+wzCmDEkc9y7NsYxeF4u7Btsn1ZuwgwJGxImImHicJArLP4R0yX4c2KCrMrTA==",
"license": "MIT",
"dependencies": {
"es-errors": "^1.3.0",
"object-inspect": "^1.13.3"
},
"engines": {
"node": ">= 0.4"
},
"funding": {
"url": "https://github.com/sponsors/ljharb"
}
},
"node_modules/side-channel-map": {
"version": "1.0.1",
"resolved": "https://registry.npmmirror.com/side-channel-map/-/side-channel-map-1.0.1.tgz",
"integrity": "sha512-VCjCNfgMsby3tTdo02nbjtM/ewra6jPHmpThenkTYh8pG9ucZ/1P8So4u4FGBek/BjpOVsDCMoLA/iuBKIFXRA==",
"license": "MIT",
"dependencies": {
"call-bound": "^1.0.2",
"es-errors": "^1.3.0",
"get-intrinsic": "^1.2.5",
"object-inspect": "^1.13.3"
},
"engines": {
"node": ">= 0.4"
},
"funding": {
"url": "https://github.com/sponsors/ljharb"
}
},
"node_modules/side-channel-weakmap": {
"version": "1.0.2",
"resolved": "https://registry.npmmirror.com/side-channel-weakmap/-/side-channel-weakmap-1.0.2.tgz",
"integrity": "sha512-WPS/HvHQTYnHisLo9McqBHOJk2FkHO/tlpvldyrnem4aeQp4hai3gythswg6p01oSoTl58rcpiFAjF2br2Ak2A==",
"license": "MIT",
"dependencies": {
"call-bound": "^1.0.2",
"es-errors": "^1.3.0",
"get-intrinsic": "^1.2.5",
"object-inspect": "^1.13.3",
"side-channel-map": "^1.0.1"
},
"engines": {
"node": ">= 0.4"
},
"funding": {
"url": "https://github.com/sponsors/ljharb"
}
},
"node_modules/signal-exit": {

View File

@@ -36,6 +36,7 @@
"@electron-forge/maker-squirrel": "6.4.1",
"@electron-forge/maker-zip": "6.4.1",
"@electron-forge/plugin-webpack": "6.4.1",
"@larksuiteoapi/node-sdk": "^1.50.1",
"@svgr/webpack": "^8.1.0",
"@timfish/forge-externals-plugin": "^0.2.1",
"@types/better-sqlite3": "^7.6.10",
@@ -52,6 +53,7 @@
"@typescript-eslint/parser": "^5.59.7",
"@vercel/webpack-asset-relocator-loader": "^1.7.3",
"babel-loader": "^9.1.3",
"cross-env": "^7.0.3",
"css-loader": "^6.11.0",
"electron": "^25.3.0",
"eslint": "^8.41.0",

392
scripts/feishu-upload.js Normal file
View File

@@ -0,0 +1,392 @@
const fs = require('fs');
const path = require('path');
const { Readable } = require('stream');
const { Client } = require('@larksuiteoapi/node-sdk');
/**
* 飞书云空间文件上传工具
* 支持小文件直接上传和大文件分片上传
* 包含重试机制和错误处理
*/
class FeishuFileUploader {
constructor(appId, appSecret, tenantAccessToken = null) {
this.client = new Client({
appId: appId,
appSecret: appSecret,
disableTokenCache: true
});
this.appId = appId;
this.appSecret = appSecret;
this.tenantAccessToken = tenantAccessToken;
this.tokenExpireTime = null;
this.maxRetries = 5; // 最大重试次数
this.retryDelay = 1000; // 重试延迟(毫秒)
this.maxFileSize = 20 * 1024 * 1024; // 20MB - 小文件直接上传的阈值
this.chunkSize = 4 * 1024 * 1024; // 4MB - 分片大小
}
/**
* 获取tenant_access_token
*/
async getTenantAccessToken() {
// 如果token存在且未过期剩余时间超过5分钟直接返回
if (this.tenantAccessToken && this.tokenExpireTime) {
const now = Date.now();
const remainingTime = this.tokenExpireTime - now;
if (remainingTime > 5 * 60 * 1000) { // 5分钟
return this.tenantAccessToken;
}
}
console.log('正在获取 tenant_access_token...');
try {
const response = await fetch('https://open.feishu.cn/open-apis/auth/v3/tenant_access_token/internal', {
method: 'POST',
headers: {
'Content-Type': 'application/json; charset=utf-8'
},
body: JSON.stringify({
app_id: this.appId,
app_secret: this.appSecret
})
});
const data = await response.json();
if (data.code !== 0) {
throw new Error(`获取 tenant_access_token 失败: ${data.msg}`);
}
this.tenantAccessToken = data.tenant_access_token;
this.tokenExpireTime = Date.now() + (data.expire * 1000);
console.log('tenant_access_token 获取成功');
return this.tenantAccessToken;
} catch (error) {
console.error('获取 tenant_access_token 失败:', error.message);
throw error;
}
} /**
* 计算Adler-32校验和
*/
calculateAdler32(buffer) {
const MOD = 65521;
let s1 = 1; // 初始低位累加和
let s2 = 0; // 初始高位累加和
// 遍历缓冲区中的每个字节
for (let i = 0; i < buffer.length; i++) {
// 获取无符号字节值 (0-255)
const byte = buffer[i];
// 更新累加值,使用模数防止溢出
s1 = (s1 + byte) % MOD;
s2 = (s2 + s1) % MOD;
}
// 组合结果: (s2 << 16) | s1
const combinedValue = (s2 << 16) | s1;
// 确保结果是32位无符号整数
// 注意JavaScript 的位操作符返回的是32位有符号整数所以需要转换
const result = combinedValue >>> 0;
// 返回十进制格式的字符串
return result.toString(10);
}
/**
* 延迟函数
*/
delay(ms) {
return new Promise(resolve => setTimeout(resolve, ms));
}
/**
* 重试包装器
*/
async withRetry(operation, operationName) {
let lastError;
for (let attempt = 1; attempt <= this.maxRetries; attempt++) {
try {
return await operation();
} catch (error) {
lastError = error;
// 检查是否是可重试的错误
const isRetryableError = this.isRetryableError(error);
if (!isRetryableError || attempt === this.maxRetries) {
console.error(`${operationName} 失败 (尝试 ${attempt}/${this.maxRetries}):`, error.message);
throw error;
}
const delayTime = this.retryDelay * Math.pow(2, attempt - 1); // 指数退避
console.log(`${operationName} 失败 (尝试 ${attempt}/${this.maxRetries}), ${delayTime}ms 后重试...`);
await this.delay(delayTime);
}
}
throw lastError;
}
/**
* 判断是否为可重试的错误
*/
isRetryableError(error) {
if (error.response && error.response.data) {
const code = error.response.data.code;
// 1061045: 频率限制错误,可重试
// 1061001: 内部错误,可重试
// 1064230: 数据迁移中,可重试
return [1061045, 1061001, 1064230].includes(code);
}
// 网络错误等也可以重试
return error.code === 'ECONNRESET' ||
error.code === 'ETIMEDOUT' ||
error.code === 'ENOTFOUND';
} /**
* 直接上传小文件
*/
async uploadSmallFile(filePath, fileName, parentNode) {
const fileBuffer = fs.readFileSync(filePath);
const token = await this.getTenantAccessToken();
return await this.withRetry(async () => {
const response = await this.client.drive.v1.file.upload({
data: {
file_name: fileName,
parent_type: 'explorer',
parent_node: parentNode,
size: fileBuffer.length,
file: fileBuffer
}
}, {
headers: {
'Authorization': `Bearer ${token}`
}
});
return response.data;
}, '小文件上传');
} /**
* 分片上传预处理
*/
async uploadPrepare(fileName, parentNode, fileSize) {
const token = await this.getTenantAccessToken();
return await this.withRetry(async () => {
const response = await this.client.drive.v1.file.uploadPrepare({
data: {
file_name: fileName,
parent_type: 'explorer',
parent_node: parentNode,
size: fileSize
}
}, {
headers: {
'Authorization': `Bearer ${token}`
}
});
return response.data;
}, '预上传');
}/**
* 上传单个分片
*/
async uploadPart(uploadId, seq, chunkBuffer) {
const checksum = this.calculateAdler32(chunkBuffer);
const token = await this.getTenantAccessToken();
// 创建一个真正的可读流
const chunkStream = new Readable({
read() { }
});
chunkStream.push(chunkBuffer);
chunkStream.push(null); // 标记流结束
return await this.withRetry(async () => {
const response = await this.client.drive.v1.file.uploadPart({
data: {
upload_id: uploadId,
seq: seq,
size: chunkBuffer.length,
checksum: checksum,
file: chunkStream
}
}, {
headers: {
'Authorization': `Bearer ${token}`
}
});
return response?.data;
}, `分片上传 (${seq})`);
}
/**
* 完成分片上传
*/
async uploadFinish(uploadId, blockNum) {
const token = await this.getTenantAccessToken();
return await this.withRetry(async () => {
const response = await this.client.drive.v1.file.uploadFinish({
data: {
upload_id: uploadId,
block_num: blockNum
}
}, {
headers: {
'Authorization': `Bearer ${token}`
}
});
return response.data;
}, '完成上传');
}
/**
* 分片上传大文件
*/
async uploadLargeFile(filePath, fileName, parentNode) {
const fileStats = fs.statSync(filePath);
const fileSize = fileStats.size;
console.log(`开始分片上传文件: ${fileName} (${fileSize} bytes)`);
// 1. 预上传
const prepareResult = await this.uploadPrepare(fileName, parentNode, fileSize);
const { upload_id, block_size, block_num } = prepareResult;
console.log(`预上传成功, upload_id: ${upload_id}, 分片数量: ${block_num}`);
// 2. 分片上传
const fileHandle = fs.openSync(filePath, 'r');
try {
for (let i = 0; i < block_num; i++) {
const start = i * block_size;
const end = Math.min(start + block_size, fileSize);
const chunkSize = end - start;
const chunkBuffer = Buffer.alloc(chunkSize);
fs.readSync(fileHandle, chunkBuffer, 0, chunkSize, start);
console.log(`上传分片 ${i + 1}/${block_num} (${chunkSize} bytes)`);
await this.uploadPart(upload_id, i, chunkBuffer);
// 避免频率限制,分片之间稍微延迟
if (i < block_num - 1) {
await this.delay(200);
}
}
} finally {
fs.closeSync(fileHandle);
}
// 3. 完成上传
console.log('完成分片上传...');
const finishResult = await this.uploadFinish(upload_id, block_num);
return finishResult;
}
/**
* 主上传函数 - 自动选择上传方式
*/
async uploadFile(filePath, fileName, parentNode) {
if (!fs.existsSync(filePath)) {
throw new Error(`文件不存在: ${filePath}`);
}
const fileStats = fs.statSync(filePath);
const fileSize = fileStats.size;
console.log(`准备上传文件: ${fileName}`);
console.log(`文件大小: ${fileSize} bytes`);
console.log(`目标文件夹: ${parentNode}`);
try {
let result;
if (fileSize <= this.maxFileSize) {
console.log('使用直接上传方式');
result = await this.uploadSmallFile(filePath, fileName, parentNode);
} else {
console.log('使用分片上传方式');
result = await this.uploadLargeFile(filePath, fileName, parentNode);
}
console.log('文件上传成功!');
return result;
} catch (error) {
console.error('文件上传失败:', error.message);
if (error.response && error.response.data) {
console.error('错误详情:', error.response.data);
}
throw error;
}
}
}
/**
* 主函数 - 从环境变量和命令行参数获取配置
*/
async function main() {
try {
// 从环境变量获取配置
const appId = process.env.FEISHU_APP_ID;
const appSecret = process.env.FEISHU_APP_SECRET;
const parentNode = process.env.FEISHU_PARENT_NODE;
// 从命令行参数获取文件路径和文件名
const args = process.argv.slice(2);
if (args.length < 1) {
console.error('用法: node feishu-upload.js <文件路径> [上传文件名]');
console.error('');
console.error('环境变量:');
console.error(' FEISHU_APP_ID - 飞书应用ID');
console.error(' FEISHU_APP_SECRET - 飞书应用密钥');
console.error(' FEISHU_PARENT_NODE - 云空间文件夹token');
process.exit(1);
}
const filePath = path.resolve(args[0]);
const fileName = args[1] || path.basename(filePath);
// 验证环境变量
if (!appId || !appSecret || !parentNode) {
console.error('错误: 缺少必要的环境变量');
console.error('请设置: FEISHU_APP_ID, FEISHU_APP_SECRET, FEISHU_PARENT_NODE');
process.exit(1);
}
// 创建上传器实例
const uploader = new FeishuFileUploader(appId, appSecret);
// 执行上传
const result = await uploader.uploadFile(filePath, fileName, parentNode);
console.log('上传结果:', result);
if (result.file_token) {
console.log(`文件上传成功! file_token: ${result.file_token}`);
}
} catch (error) {
console.error('上传失败:', error.message);
process.exit(1);
}
}
// 如果直接运行此脚本,则执行主函数
if (require.main === module) {
main();
}
// 导出类以供其他模块使用
module.exports = { FeishuFileUploader };