Compare commits
51 Commits
| Author | SHA1 | Date | |
|---|---|---|---|
|
|
87f69fc782 | ||
|
|
59d3b0c65c | ||
|
|
e861ea8f78 | ||
|
|
6692751c62 | ||
|
|
65e876a2e9 | ||
|
|
496c88a629 | ||
|
|
2086bd1663 | ||
|
|
d6f8d0e63c | ||
|
|
cc4dd8284f | ||
|
|
6f688cbbb3 | ||
|
|
e0a1e0af39 | ||
|
|
c1d3a61f9f | ||
|
|
d6d806c96e | ||
|
|
089406464b | ||
|
|
c28d5d6ad0 | ||
|
|
471147ac82 | ||
|
|
7558a67df3 | ||
|
|
4a3f0ee124 | ||
|
|
5fe6d93d5e | ||
|
|
30fd2ebb9f | ||
|
|
0f78f117d0 | ||
|
|
c79b6951d6 | ||
|
|
5118874712 | ||
|
|
7e5baba969 | ||
|
|
a7af89e35d | ||
|
|
d511efdfce | ||
|
|
9b6050be7a | ||
|
|
57736e60f3 | ||
|
|
6165a2619e | ||
|
|
c933b6e0b4 | ||
|
|
e0e01cbdca | ||
|
|
9b34ecbed9 | ||
|
|
1dda213013 | ||
|
|
94c2dc740f | ||
|
|
61f062455e | ||
|
|
79827f14f7 | ||
|
|
394bdd573c | ||
|
|
d03d62c8d4 | ||
|
|
be0b0b0390 | ||
|
|
c1d2f3dc8d | ||
|
|
e590c33c66 | ||
|
|
604ac7b553 | ||
|
|
18e233ae10 | ||
|
|
61699c4853 | ||
|
|
6e69920a5d | ||
|
|
a767b008a0 | ||
|
|
41b104e96d | ||
|
|
8562b7c954 | ||
|
|
b61e88b7d9 | ||
|
|
cc1dbcaf3f | ||
|
|
941af10830 |
10
.eslintrc.backup.json
Normal file
@@ -0,0 +1,10 @@
|
|||||||
|
{
|
||||||
|
"extends": ["@electron-toolkit/eslint-config-ts", "@electron-toolkit/eslint-config-prettier"],
|
||||||
|
"rules": {
|
||||||
|
"vue/require-default-prop": "off",
|
||||||
|
"vue/multi-word-component-names": "off",
|
||||||
|
"@typescript-eslint/explicit-function-return-type": "off",
|
||||||
|
"@typescript-eslint/no-explicit-any": "warn",
|
||||||
|
"no-console": "warn"
|
||||||
|
}
|
||||||
|
}
|
||||||
158
.github/workflows/auto-sync-release.yml
vendored
Normal file
@@ -0,0 +1,158 @@
|
|||||||
|
name: Auto Sync New Release to WebDAV
|
||||||
|
|
||||||
|
on:
|
||||||
|
release:
|
||||||
|
types: [published]
|
||||||
|
|
||||||
|
permissions:
|
||||||
|
contents: read
|
||||||
|
|
||||||
|
jobs:
|
||||||
|
auto-sync-to-webdav:
|
||||||
|
runs-on: ubuntu-latest
|
||||||
|
steps:
|
||||||
|
- name: Install dependencies
|
||||||
|
run: |
|
||||||
|
sudo apt-get update
|
||||||
|
sudo apt-get install -y curl jq
|
||||||
|
|
||||||
|
- name: Get release info
|
||||||
|
id: release-info
|
||||||
|
run: |
|
||||||
|
echo "tag_name=${{ github.event.release.tag_name }}" >> $GITHUB_OUTPUT
|
||||||
|
echo "release_id=${{ github.event.release.id }}" >> $GITHUB_OUTPUT
|
||||||
|
echo "release_name=${{ github.event.release.name }}" >> $GITHUB_OUTPUT
|
||||||
|
|
||||||
|
- name: Sync new release to WebDAV
|
||||||
|
run: |
|
||||||
|
TAG_NAME="${{ steps.release-info.outputs.tag_name }}"
|
||||||
|
RELEASE_ID="${{ steps.release-info.outputs.release_id }}"
|
||||||
|
RELEASE_NAME="${{ steps.release-info.outputs.release_name }}"
|
||||||
|
|
||||||
|
echo "🚀 开始同步新发布的版本到 WebDAV..."
|
||||||
|
echo "版本标签: $TAG_NAME"
|
||||||
|
echo "版本名称: $RELEASE_NAME"
|
||||||
|
echo "Release ID: $RELEASE_ID"
|
||||||
|
echo "WebDAV 根路径: ${{ secrets.WEBDAV_BASE_URL }}/yd/ceru"
|
||||||
|
|
||||||
|
# 获取该release的所有资源文件
|
||||||
|
assets_json=$(curl -s \
|
||||||
|
-H "Authorization: token ${{ secrets.GITHUB_TOKEN }}" \
|
||||||
|
-H "Accept: application/vnd.github.v3+json" \
|
||||||
|
"https://api.github.com/repos/${{ github.repository }}/releases/$RELEASE_ID/assets")
|
||||||
|
|
||||||
|
assets_count=$(echo "$assets_json" | jq '. | length')
|
||||||
|
echo "找到 $assets_count 个资源文件"
|
||||||
|
|
||||||
|
if [ "$assets_count" -eq 0 ]; then
|
||||||
|
echo "⚠️ 该版本没有资源文件,跳过同步"
|
||||||
|
exit 0
|
||||||
|
fi
|
||||||
|
|
||||||
|
# 先创建版本目录
|
||||||
|
dir_path="/yd/ceru/$TAG_NAME"
|
||||||
|
dir_url="${{ secrets.WEBDAV_BASE_URL }}$dir_path"
|
||||||
|
|
||||||
|
echo "创建版本目录: $dir_path"
|
||||||
|
if curl -s -f -X MKCOL \
|
||||||
|
-u "${{ secrets.WEBDAV_USERNAME }}:${{ secrets.WEBDAV_PASSWORD }}" \
|
||||||
|
"$dir_url"; then
|
||||||
|
echo "✅ 目录创建成功"
|
||||||
|
else
|
||||||
|
echo "ℹ️ 目录可能已存在或创建失败,继续执行"
|
||||||
|
fi
|
||||||
|
|
||||||
|
# 处理每个asset
|
||||||
|
success_count=0
|
||||||
|
failed_count=0
|
||||||
|
|
||||||
|
for i in $(seq 0 $(($assets_count - 1))); do
|
||||||
|
asset=$(echo "$assets_json" | jq -c ".[$i]")
|
||||||
|
asset_name=$(echo "$asset" | jq -r '.name')
|
||||||
|
asset_url=$(echo "$asset" | jq -r '.url')
|
||||||
|
asset_size=$(echo "$asset" | jq -r '.size')
|
||||||
|
|
||||||
|
echo "📦 处理资源: $asset_name (大小: $asset_size bytes)"
|
||||||
|
|
||||||
|
# 下载资源文件
|
||||||
|
safe_filename="./temp_${TAG_NAME}_$(date +%s)_$i"
|
||||||
|
|
||||||
|
if ! curl -sL -o "$safe_filename" \
|
||||||
|
-H "Authorization: token ${{ secrets.GITHUB_TOKEN }}" \
|
||||||
|
-H "Accept: application/octet-stream" \
|
||||||
|
"$asset_url"; then
|
||||||
|
echo "❌ 下载失败: $asset_name"
|
||||||
|
failed_count=$((failed_count + 1))
|
||||||
|
continue
|
||||||
|
fi
|
||||||
|
|
||||||
|
if [ -f "$safe_filename" ]; then
|
||||||
|
actual_size=$(wc -c < "$safe_filename")
|
||||||
|
if [ "$actual_size" -ne "$asset_size" ]; then
|
||||||
|
echo "❌ 文件大小不匹配: $asset_name (期望: $asset_size, 实际: $actual_size)"
|
||||||
|
rm -f "$safe_filename"
|
||||||
|
failed_count=$((failed_count + 1))
|
||||||
|
continue
|
||||||
|
fi
|
||||||
|
|
||||||
|
echo "⬆️ 上传到 WebDAV: $asset_name"
|
||||||
|
|
||||||
|
# 构建远程路径
|
||||||
|
remote_path="/yd/ceru/$TAG_NAME/$asset_name"
|
||||||
|
full_url="${{ secrets.WEBDAV_BASE_URL }}$remote_path"
|
||||||
|
|
||||||
|
# 使用 WebDAV PUT 方法上传文件
|
||||||
|
if curl -s -f -X PUT \
|
||||||
|
-u "${{ secrets.WEBDAV_USERNAME }}:${{ secrets.WEBDAV_PASSWORD }}" \
|
||||||
|
-T "$safe_filename" \
|
||||||
|
"$full_url"; then
|
||||||
|
|
||||||
|
echo "✅ 上传成功: $asset_name"
|
||||||
|
success_count=$((success_count + 1))
|
||||||
|
|
||||||
|
# 验证文件是否存在
|
||||||
|
sleep 1
|
||||||
|
if curl -s -f -u "${{ secrets.WEBDAV_USERNAME }}:${{ secrets.WEBDAV_PASSWORD }}" \
|
||||||
|
-X PROPFIND \
|
||||||
|
-H "Depth: 0" \
|
||||||
|
"$full_url" > /dev/null 2>&1; then
|
||||||
|
echo "✅ 文件验证成功: $asset_name"
|
||||||
|
else
|
||||||
|
echo "⚠️ 文件验证失败,但上传可能成功: $asset_name"
|
||||||
|
fi
|
||||||
|
|
||||||
|
else
|
||||||
|
echo "❌ 上传失败: $asset_name"
|
||||||
|
failed_count=$((failed_count + 1))
|
||||||
|
fi
|
||||||
|
|
||||||
|
# 清理临时文件
|
||||||
|
rm -f "$safe_filename"
|
||||||
|
echo "----------------------------------------"
|
||||||
|
else
|
||||||
|
echo "❌ 临时文件不存在: $safe_filename"
|
||||||
|
failed_count=$((failed_count + 1))
|
||||||
|
fi
|
||||||
|
done
|
||||||
|
|
||||||
|
echo "========================================"
|
||||||
|
echo "🎉 同步完成!"
|
||||||
|
echo "成功: $success_count 个文件"
|
||||||
|
echo "失败: $failed_count 个文件"
|
||||||
|
echo "总计: $assets_count 个文件"
|
||||||
|
|
||||||
|
if [ "$failed_count" -gt 0 ]; then
|
||||||
|
echo "⚠️ 有文件同步失败,请检查日志"
|
||||||
|
exit 1
|
||||||
|
else
|
||||||
|
echo "✅ 所有文件同步成功!"
|
||||||
|
fi
|
||||||
|
|
||||||
|
- name: Notify completion
|
||||||
|
if: always()
|
||||||
|
run: |
|
||||||
|
if [ "${{ job.status }}" == "success" ]; then
|
||||||
|
echo "✅ 版本 ${{ steps.release-info.outputs.tag_name }} 已成功同步到 alist"
|
||||||
|
else
|
||||||
|
echo "❌ 版本 ${{ steps.release-info.outputs.tag_name }} 同步失败"
|
||||||
|
fi
|
||||||
143
.github/workflows/main.yml
vendored
@@ -70,3 +70,146 @@ jobs:
|
|||||||
uses: softprops/action-gh-release@v1
|
uses: softprops/action-gh-release@v1
|
||||||
with:
|
with:
|
||||||
files: 'dist/**' # 将dist目录下所有文件添加到release
|
files: 'dist/**' # 将dist目录下所有文件添加到release
|
||||||
|
|
||||||
|
# 新增:自动同步到 WebDAV
|
||||||
|
sync-to-webdav:
|
||||||
|
name: Sync to WebDAV
|
||||||
|
needs: release # 等待 release 任务完成
|
||||||
|
runs-on: ubuntu-latest
|
||||||
|
if: startsWith(github.ref, 'refs/tags/v') # 只在标签推送时执行
|
||||||
|
steps:
|
||||||
|
- name: Wait for release to be ready
|
||||||
|
run: |
|
||||||
|
echo "等待 Release 准备就绪..."
|
||||||
|
sleep 30 # 等待30秒确保 release 完全创建
|
||||||
|
|
||||||
|
- name: Install dependencies
|
||||||
|
run: |
|
||||||
|
sudo apt-get update
|
||||||
|
sudo apt-get install -y curl jq
|
||||||
|
|
||||||
|
- name: Get latest release info
|
||||||
|
id: get-release
|
||||||
|
run: |
|
||||||
|
# 获取当前标签对应的 release 信息
|
||||||
|
TAG_NAME=${GITHUB_REF#refs/tags/}
|
||||||
|
echo "tag_name=$TAG_NAME" >> $GITHUB_OUTPUT
|
||||||
|
|
||||||
|
# 获取 release 详细信息
|
||||||
|
response=$(curl -s \
|
||||||
|
-H "Authorization: token ${{ secrets.GITHUB_TOKEN }}" \
|
||||||
|
-H "Accept: application/vnd.github.v3+json" \
|
||||||
|
"https://api.github.com/repos/${{ github.repository }}/releases/tags/$TAG_NAME")
|
||||||
|
|
||||||
|
release_id=$(echo "$response" | jq -r '.id')
|
||||||
|
echo "release_id=$release_id" >> $GITHUB_OUTPUT
|
||||||
|
echo "找到 Release ID: $release_id"
|
||||||
|
|
||||||
|
- name: Sync release to WebDAV
|
||||||
|
run: |
|
||||||
|
TAG_NAME="${{ steps.get-release.outputs.tag_name }}"
|
||||||
|
RELEASE_ID="${{ steps.get-release.outputs.release_id }}"
|
||||||
|
|
||||||
|
echo "🚀 开始同步版本 $TAG_NAME 到 WebDAV..."
|
||||||
|
echo "Release ID: $RELEASE_ID"
|
||||||
|
echo "WebDAV 根路径: ${{ secrets.WEBDAV_BASE_URL }}/yd/ceru"
|
||||||
|
|
||||||
|
# 获取该release的所有资源文件
|
||||||
|
assets_json=$(curl -s \
|
||||||
|
-H "Authorization: token ${{ secrets.GITHUB_TOKEN }}" \
|
||||||
|
-H "Accept: application/vnd.github.v3+json" \
|
||||||
|
"https://api.github.com/repos/${{ github.repository }}/releases/$RELEASE_ID/assets")
|
||||||
|
|
||||||
|
assets_count=$(echo "$assets_json" | jq '. | length')
|
||||||
|
echo "找到 $assets_count 个资源文件"
|
||||||
|
|
||||||
|
if [ "$assets_count" -eq 0 ]; then
|
||||||
|
echo "⚠️ 该版本没有资源文件,跳过同步"
|
||||||
|
exit 0
|
||||||
|
fi
|
||||||
|
|
||||||
|
# 先创建版本目录
|
||||||
|
dir_path="/yd/ceru/$TAG_NAME"
|
||||||
|
dir_url="${{ secrets.WEBDAV_BASE_URL }}$dir_path"
|
||||||
|
|
||||||
|
echo "创建版本目录: $dir_path"
|
||||||
|
curl -s -X MKCOL \
|
||||||
|
-u "${{ secrets.WEBDAV_USERNAME }}:${{ secrets.WEBDAV_PASSWORD }}" \
|
||||||
|
"$dir_url" || echo "目录可能已存在"
|
||||||
|
|
||||||
|
# 处理每个asset
|
||||||
|
success_count=0
|
||||||
|
failed_count=0
|
||||||
|
|
||||||
|
for i in $(seq 0 $(($assets_count - 1))); do
|
||||||
|
asset=$(echo "$assets_json" | jq -c ".[$i]")
|
||||||
|
asset_name=$(echo "$asset" | jq -r '.name')
|
||||||
|
asset_url=$(echo "$asset" | jq -r '.url')
|
||||||
|
asset_size=$(echo "$asset" | jq -r '.size')
|
||||||
|
|
||||||
|
echo "📦 处理资源: $asset_name (大小: $asset_size bytes)"
|
||||||
|
|
||||||
|
# 下载资源文件
|
||||||
|
safe_filename="./temp_${TAG_NAME}_$(date +%s)_$i"
|
||||||
|
|
||||||
|
if ! curl -sL -o "$safe_filename" \
|
||||||
|
-H "Authorization: token ${{ secrets.GITHUB_TOKEN }}" \
|
||||||
|
-H "Accept: application/octet-stream" \
|
||||||
|
"$asset_url"; then
|
||||||
|
echo "❌ 下载失败: $asset_name"
|
||||||
|
failed_count=$((failed_count + 1))
|
||||||
|
continue
|
||||||
|
fi
|
||||||
|
|
||||||
|
if [ -f "$safe_filename" ]; then
|
||||||
|
actual_size=$(wc -c < "$safe_filename")
|
||||||
|
if [ "$actual_size" -ne "$asset_size" ]; then
|
||||||
|
echo "❌ 文件大小不匹配: $asset_name (期望: $asset_size, 实际: $actual_size)"
|
||||||
|
rm -f "$safe_filename"
|
||||||
|
failed_count=$((failed_count + 1))
|
||||||
|
continue
|
||||||
|
fi
|
||||||
|
|
||||||
|
echo "⬆️ 上传到 WebDAV: $asset_name"
|
||||||
|
|
||||||
|
# 构建远程路径
|
||||||
|
remote_path="/yd/ceru/$TAG_NAME/$asset_name"
|
||||||
|
full_url="${{ secrets.WEBDAV_BASE_URL }}$remote_path"
|
||||||
|
|
||||||
|
# 使用 WebDAV PUT 方法上传文件
|
||||||
|
if curl -s -f -X PUT \
|
||||||
|
-u "${{ secrets.WEBDAV_USERNAME }}:${{ secrets.WEBDAV_PASSWORD }}" \
|
||||||
|
-T "$safe_filename" \
|
||||||
|
"$full_url"; then
|
||||||
|
|
||||||
|
echo "✅ 上传成功: $asset_name"
|
||||||
|
success_count=$((success_count + 1))
|
||||||
|
|
||||||
|
else
|
||||||
|
echo "❌ 上传失败: $asset_name"
|
||||||
|
failed_count=$((failed_count + 1))
|
||||||
|
fi
|
||||||
|
|
||||||
|
# 清理临时文件
|
||||||
|
rm -f "$safe_filename"
|
||||||
|
echo "----------------------------------------"
|
||||||
|
else
|
||||||
|
echo "❌ 临时文件不存在: $safe_filename"
|
||||||
|
failed_count=$((failed_count + 1))
|
||||||
|
fi
|
||||||
|
done
|
||||||
|
|
||||||
|
echo "========================================"
|
||||||
|
echo "🎉 同步完成!"
|
||||||
|
echo "成功: $success_count 个文件"
|
||||||
|
echo "失败: $failed_count 个文件"
|
||||||
|
echo "总计: $assets_count 个文件"
|
||||||
|
|
||||||
|
- name: Notify completion
|
||||||
|
if: always()
|
||||||
|
run: |
|
||||||
|
if [ "${{ job.status }}" == "success" ]; then
|
||||||
|
echo "✅ 版本 ${{ steps.get-release.outputs.tag_name }} 已成功同步到 alist"
|
||||||
|
else
|
||||||
|
echo "❌ 版本 ${{ steps.get-release.outputs.tag_name }} 同步失败"
|
||||||
|
fi
|
||||||
|
|||||||
154
.github/workflows/sync-releases-to-webdav.yml
vendored
Normal file
@@ -0,0 +1,154 @@
|
|||||||
|
name: Sync Existing Releases to Alist
|
||||||
|
|
||||||
|
on:
|
||||||
|
workflow_dispatch:
|
||||||
|
inputs:
|
||||||
|
tag_name:
|
||||||
|
description: '要同步的特定标签(如 v1.0.0),留空则同步所有版本'
|
||||||
|
required: false
|
||||||
|
default: ''
|
||||||
|
|
||||||
|
permissions:
|
||||||
|
contents: read
|
||||||
|
|
||||||
|
jobs:
|
||||||
|
sync-releases-to-alist:
|
||||||
|
runs-on: ubuntu-latest
|
||||||
|
steps:
|
||||||
|
- name: Install dependencies
|
||||||
|
run: |
|
||||||
|
sudo apt-get update
|
||||||
|
sudo apt-get install -y curl jq
|
||||||
|
|
||||||
|
- name: Get all releases
|
||||||
|
id: get-releases
|
||||||
|
run: |
|
||||||
|
response=$(curl -s \
|
||||||
|
-H "Authorization: token ${{ secrets.GITHUB_TOKEN }}" \
|
||||||
|
-H "Accept: application/vnd.github.v3+json" \
|
||||||
|
"https://api.github.com/repos/${{ github.repository }}/releases")
|
||||||
|
echo "releases_json=$(echo "$response" | jq -c '.')" >> $GITHUB_OUTPUT
|
||||||
|
|
||||||
|
- name: Sync releases to Alist(自动登录 & 上传)
|
||||||
|
run: |
|
||||||
|
# ========== 1. 读取输入参数 ==========
|
||||||
|
SPECIFIC_TAG="${{ github.event.inputs.tag_name }}"
|
||||||
|
RELEASES_JSON='${{ steps.get-releases.outputs.releases_json }}'
|
||||||
|
|
||||||
|
# ========== 2. Alist 连接信息 ==========
|
||||||
|
ALIST_URL="https://alist.shiqianjiang.cn" # https://pan.example.com
|
||||||
|
ALIST_USER="${{ secrets.WEBDAV_USERNAME }}" # Alist 登录账号
|
||||||
|
ALIST_PASS="${{ secrets.WEBDAV_PASSWORD }}" # Alist 登录密码
|
||||||
|
ALIST_DIR="/yd/ceru" # 目标根目录
|
||||||
|
|
||||||
|
# ========== 3. 登录拿 token ==========
|
||||||
|
echo "正在登录 Alist ..."
|
||||||
|
login_resp=$(curl -s -X POST "$ALIST_URL/api/auth/login" \
|
||||||
|
-H "Content-Type: application/json" \
|
||||||
|
-d "{
|
||||||
|
\"username\": \"$ALIST_USER\",
|
||||||
|
\"password\": \"$ALIST_PASS\"
|
||||||
|
}")
|
||||||
|
echo "$login_resp"
|
||||||
|
token=$(echo "$login_resp" | jq -r '.data.token // empty')
|
||||||
|
|
||||||
|
if [ -z "$token" ]; then
|
||||||
|
echo "❌ 登录失败,返回:$login_resp"
|
||||||
|
exit 1
|
||||||
|
fi
|
||||||
|
echo "✅ 登录成功,token 已获取"
|
||||||
|
|
||||||
|
# ========== 4. 循环处理 release ==========
|
||||||
|
releases_count=$(echo "$RELEASES_JSON" | jq '. | length')
|
||||||
|
echo "找到 $releases_count 个 releases"
|
||||||
|
for i in $(seq 0 $(($releases_count - 1))); do
|
||||||
|
release=$(echo "$RELEASES_JSON" | jq -c ".[$i]")
|
||||||
|
tag_name=$(echo "$release" | jq -r '.tag_name')
|
||||||
|
release_id=$(echo "$release" | jq -r '.id')
|
||||||
|
|
||||||
|
[ -n "$SPECIFIC_TAG" ] && [ "$tag_name" != "$SPECIFIC_TAG" ] && {
|
||||||
|
echo "跳过 $tag_name,不是指定标签"
|
||||||
|
continue
|
||||||
|
}
|
||||||
|
|
||||||
|
echo "处理版本: $tag_name (ID: $release_id)"
|
||||||
|
assets_json=$(curl -s \
|
||||||
|
-H "Authorization: token ${{ secrets.GITHUB_TOKEN }}" \
|
||||||
|
-H "Accept: application/vnd.github.v3+json" \
|
||||||
|
"https://api.github.com/repos/${{ github.repository }}/releases/$release_id/assets")
|
||||||
|
assets_count=$(echo "$assets_json" | jq '. | length')
|
||||||
|
echo "找到 $assets_count 个资源文件"
|
||||||
|
|
||||||
|
for j in $(seq 0 $(($assets_count - 1))); do
|
||||||
|
asset=$(echo "$assets_json" | jq -c ".[$j]")
|
||||||
|
asset_name=$(echo "$asset" | jq -r '.name')
|
||||||
|
asset_url=$(echo "$asset" | jq -r '.url')
|
||||||
|
asset_size=$(echo "$asset" | jq -r '.size')
|
||||||
|
|
||||||
|
echo "下载资源: $asset_name (大小: $asset_size bytes)"
|
||||||
|
safe_filename="./temp_download_$(date +%s)_$j"
|
||||||
|
|
||||||
|
# 下载
|
||||||
|
curl -sL -o "$safe_filename" \
|
||||||
|
-H "Authorization: token ${{ secrets.GITHUB_TOKEN }}" \
|
||||||
|
-H "Accept: application/octet-stream" \
|
||||||
|
"$asset_url" || {
|
||||||
|
echo "❌ 下载失败: $asset_name"
|
||||||
|
continue
|
||||||
|
}
|
||||||
|
|
||||||
|
# 大小校验
|
||||||
|
actual_size=$(wc -c < "$safe_filename")
|
||||||
|
[ "$actual_size" -ne "$asset_size" ] && {
|
||||||
|
echo "❌ 文件大小不匹配: $asset_name"
|
||||||
|
rm -f "$safe_filename"
|
||||||
|
continue
|
||||||
|
}
|
||||||
|
|
||||||
|
# 组装远程路径(URL 编码)
|
||||||
|
remote_path="$ALIST_DIR/$tag_name/$asset_name"
|
||||||
|
file_path_encoded=$(printf %s "$remote_path" | jq -sRr @uri)
|
||||||
|
echo "上传到 Alist: $remote_path"
|
||||||
|
|
||||||
|
# 调用 /api/fs/put 上传(带 As-Task 异步)
|
||||||
|
response=$(
|
||||||
|
curl -s -X PUT "$ALIST_URL/api/fs/put" \
|
||||||
|
-H "Authorization: $token" \
|
||||||
|
-H "File-Path: $file_path_encoded" \
|
||||||
|
-H "Content-Type: application/octet-stream" \
|
||||||
|
-H "Content-Length: $actual_size" \
|
||||||
|
-H "As-Task: true" \
|
||||||
|
--data-binary @"$safe_filename"
|
||||||
|
)
|
||||||
|
echo "==== 上传接口原始返回 ===="
|
||||||
|
echo "$response"
|
||||||
|
code=$(echo "$response" | jq -r '.code // empty')
|
||||||
|
if [ "$code" = "200" ]; then
|
||||||
|
echo "✅ Alist 上传任务创建成功: $asset_name"
|
||||||
|
else
|
||||||
|
echo "❌ Alist 上传失败: $asset_name"
|
||||||
|
fi
|
||||||
|
|
||||||
|
rm -f "$safe_filename"
|
||||||
|
echo "----------------------------------------"
|
||||||
|
done
|
||||||
|
echo "版本 $tag_name 处理完成"
|
||||||
|
echo "========================================"
|
||||||
|
done
|
||||||
|
|
||||||
|
# ========== 5. 退出登录 ==========
|
||||||
|
echo "退出登录 ..."
|
||||||
|
curl -s -X POST "$ALIST_URL/api/auth/logout" \
|
||||||
|
-H "Authorization: $token" > /dev/null || true
|
||||||
|
|
||||||
|
echo "🎉 Alist 同步完成"
|
||||||
|
|
||||||
|
- name: Summary
|
||||||
|
run: |
|
||||||
|
echo "同步任务已完成!"
|
||||||
|
echo "请检查 Alist 中的文件是否正确上传。"
|
||||||
|
echo "如果遇到问题,请检查以下配置:"
|
||||||
|
echo "1. ALIST_URL - Alist 服务器地址"
|
||||||
|
echo "2. ALIST_USERNAME - Alist 登录账号"
|
||||||
|
echo "3. ALIST_PASSWORD - Alist 登录密码"
|
||||||
|
echo "4. GITHUB_TOKEN - GitHub 访问令牌"
|
||||||
160
.github/workflows/uploadpan.yml
vendored
Normal file
@@ -0,0 +1,160 @@
|
|||||||
|
name: Sync Existing Releases to WebDAV
|
||||||
|
|
||||||
|
on:
|
||||||
|
workflow_dispatch:
|
||||||
|
inputs:
|
||||||
|
tag_name:
|
||||||
|
description: '要同步的特定标签(如 v1.0.0),留空则同步所有版本'
|
||||||
|
required: false
|
||||||
|
default: ''
|
||||||
|
|
||||||
|
permissions:
|
||||||
|
contents: read
|
||||||
|
|
||||||
|
jobs:
|
||||||
|
sync-releases-to-webdav:
|
||||||
|
runs-on: ubuntu-latest
|
||||||
|
steps:
|
||||||
|
- name: Install dependencies
|
||||||
|
run: |
|
||||||
|
sudo apt-get update
|
||||||
|
sudo apt-get install -y curl
|
||||||
|
|
||||||
|
- name: Get all releases
|
||||||
|
id: get-releases
|
||||||
|
run: |
|
||||||
|
response=$(curl -s \
|
||||||
|
-H "Authorization: token ${{ secrets.GITHUB_TOKEN }}" \
|
||||||
|
-H "Accept: application/vnd.github.v3+json" \
|
||||||
|
"https://api.github.com/repos/${{ github.repository }}/releases")
|
||||||
|
echo "releases_json=$(echo "$response" | jq -c '.')" >> $GITHUB_OUTPUT
|
||||||
|
|
||||||
|
- name: Sync releases to WebDAV
|
||||||
|
run: |
|
||||||
|
# 读取输入参数
|
||||||
|
SPECIFIC_TAG="${{ github.event.inputs.tag_name }}"
|
||||||
|
RELEASES_JSON='${{ steps.get-releases.outputs.releases_json }}'
|
||||||
|
|
||||||
|
echo "开始同步 releases..."
|
||||||
|
echo "特定标签: ${SPECIFIC_TAG:-所有版本}"
|
||||||
|
echo "WebDAV 根路径: ${{ secrets.WEBDAV_BASE_URL }}/yd/ceru"
|
||||||
|
|
||||||
|
# 处理每个 release
|
||||||
|
releases_count=$(echo "$RELEASES_JSON" | jq '. | length')
|
||||||
|
echo "找到 $releases_count 个 releases"
|
||||||
|
|
||||||
|
for i in $(seq 0 $(($releases_count - 1))); do
|
||||||
|
release=$(echo "$RELEASES_JSON" | jq -c ".[$i]")
|
||||||
|
tag_name=$(echo "$release" | jq -r '.tag_name')
|
||||||
|
release_id=$(echo "$release" | jq -r '.id')
|
||||||
|
|
||||||
|
if [ -n "$SPECIFIC_TAG" ] && [ "$tag_name" != "$SPECIFIC_TAG" ]; then
|
||||||
|
echo "跳过 $tag_name,不是指定的标签 $SPECIFIC_TAG"
|
||||||
|
continue
|
||||||
|
fi
|
||||||
|
|
||||||
|
echo "正在处理版本: $tag_name (ID: $release_id)"
|
||||||
|
|
||||||
|
# 获取该release的所有资源文件
|
||||||
|
assets_json=$(curl -s \
|
||||||
|
-H "Authorization: token ${{ secrets.GITHUB_TOKEN }}" \
|
||||||
|
-H "Accept: application/vnd.github.v3+json" \
|
||||||
|
"https://api.github.com/repos/${{ github.repository }}/releases/$release_id/assets")
|
||||||
|
|
||||||
|
assets_count=$(echo "$assets_json" | jq '. | length')
|
||||||
|
echo "找到 $assets_count 个资源文件"
|
||||||
|
|
||||||
|
# 处理每个asset
|
||||||
|
for j in $(seq 0 $(($assets_count - 1))); do
|
||||||
|
asset=$(echo "$assets_json" | jq -c ".[$j]")
|
||||||
|
asset_name=$(echo "$asset" | jq -r '.name')
|
||||||
|
asset_url=$(echo "$asset" | jq -r '.url')
|
||||||
|
asset_size=$(echo "$asset" | jq -r '.size')
|
||||||
|
|
||||||
|
echo "下载资源: $asset_name (大小: $asset_size bytes)"
|
||||||
|
|
||||||
|
# 下载资源文件
|
||||||
|
safe_filename="./temp_download"
|
||||||
|
|
||||||
|
if ! curl -sL -o "$safe_filename" \
|
||||||
|
-H "Authorization: token ${{ secrets.GITHUB_TOKEN }}" \
|
||||||
|
-H "Accept: application/octet-stream" \
|
||||||
|
"$asset_url"; then
|
||||||
|
echo "❌ 下载失败: $asset_name"
|
||||||
|
continue
|
||||||
|
fi
|
||||||
|
|
||||||
|
if [ -f "$safe_filename" ]; then
|
||||||
|
actual_size=$(wc -c < "$safe_filename")
|
||||||
|
if [ "$actual_size" -ne "$asset_size" ]; then
|
||||||
|
echo "❌ 文件大小不匹配: $asset_name (期望: $asset_size, 实际: $actual_size)"
|
||||||
|
rm -f "$safe_filename"
|
||||||
|
continue
|
||||||
|
fi
|
||||||
|
|
||||||
|
echo "上传到 WebDAV: $asset_name"
|
||||||
|
|
||||||
|
# 构建远程路径
|
||||||
|
remote_path="/yd/ceru/$tag_name/$asset_name"
|
||||||
|
full_url="${{ secrets.WEBDAV_BASE_URL }}$remote_path"
|
||||||
|
|
||||||
|
echo "完整路径: $full_url"
|
||||||
|
|
||||||
|
# 使用 WebDAV PUT 方法上传文件
|
||||||
|
if curl -s -f -X PUT \
|
||||||
|
-u "${{ secrets.WEBDAV_USERNAME }}:${{ secrets.WEBDAV_PASSWORD }}" \
|
||||||
|
-T "$safe_filename" \
|
||||||
|
"$full_url"; then
|
||||||
|
|
||||||
|
echo "✅ WebDAV 上传成功: $asset_name"
|
||||||
|
|
||||||
|
# 验证文件是否存在
|
||||||
|
echo "验证文件是否存在..."
|
||||||
|
sleep 2
|
||||||
|
|
||||||
|
if curl -s -f -u "${{ secrets.WEBDAV_USERNAME }}:${{ secrets.WEBDAV_PASSWORD }}" \
|
||||||
|
-X PROPFIND \
|
||||||
|
-H "Depth: 0" \
|
||||||
|
"$full_url" > /dev/null 2>&1; then
|
||||||
|
echo "✅ 文件确认存在: $asset_name"
|
||||||
|
else
|
||||||
|
echo "⚠️ 文件验证失败,但上传可能成功"
|
||||||
|
fi
|
||||||
|
|
||||||
|
else
|
||||||
|
echo "❌ WebDAV 上传失败: $asset_name"
|
||||||
|
echo "尝试创建目录后重新上传..."
|
||||||
|
|
||||||
|
# 尝试先创建目录
|
||||||
|
dir_path="/yd/ceru/$tag_name"
|
||||||
|
dir_url="${{ secrets.WEBDAV_BASE_URL }}$dir_path"
|
||||||
|
|
||||||
|
if curl -s -f -X MKCOL \
|
||||||
|
-u "${{ secrets.WEBDAV_USERNAME }}:${{ secrets.WEBDAV_PASSWORD }}" \
|
||||||
|
"$dir_url"; then
|
||||||
|
echo "✅ 目录创建成功: $dir_path"
|
||||||
|
|
||||||
|
# 重新尝试上传文件
|
||||||
|
if curl -s -f -X PUT \
|
||||||
|
-u "${{ secrets.WEBDAV_USERNAME }}:${{ secrets.WEBDAV_PASSWORD }}" \
|
||||||
|
-T "$safe_filename" \
|
||||||
|
"$full_url"; then
|
||||||
|
echo "✅ 重新上传成功: $asset_name"
|
||||||
|
else
|
||||||
|
echo "❌ 重新上传失败: $asset_name"
|
||||||
|
fi
|
||||||
|
else
|
||||||
|
echo "❌ 目录创建失败: $dir_path"
|
||||||
|
fi
|
||||||
|
fi
|
||||||
|
|
||||||
|
# 安全删除临时文件
|
||||||
|
rm -f "$safe_filename"
|
||||||
|
echo "----------------------------------------"
|
||||||
|
else
|
||||||
|
echo "❌ 文件不存在: $safe_filename"
|
||||||
|
fi
|
||||||
|
done
|
||||||
|
done
|
||||||
|
|
||||||
|
echo "🎉 WebDAV 同步完成"
|
||||||
12
README.md
@@ -1,7 +1,5 @@
|
|||||||
# Ceru Music(澜音)
|
# Ceru Music(澜音)
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
一个跨平台的音乐播放器应用,支持基于合规插件获取公开音乐信息与播放功能。
|
一个跨平台的音乐播放器应用,支持基于合规插件获取公开音乐信息与播放功能。
|
||||||
|
|
||||||
## 项目简介
|
## 项目简介
|
||||||
@@ -22,8 +20,6 @@ Ceru Music 是基于 Electron 和 Vue 开发的跨平台桌面音乐播放器工
|
|||||||
|
|
||||||
## 主要功能
|
## 主要功能
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
- 提供插件加载与管理功能,支持通过合规插件获取公开音乐信息
|
- 提供插件加载与管理功能,支持通过合规插件获取公开音乐信息
|
||||||
- 支持通过插件获取歌词、专辑封面等公开元数据
|
- 支持通过插件获取歌词、专辑封面等公开元数据
|
||||||
- 支持虚拟滚动列表,优化大量数据渲染性能
|
- 支持虚拟滚动列表,优化大量数据渲染性能
|
||||||
@@ -36,16 +32,12 @@ Ceru Music 是基于 Electron 和 Vue 开发的跨平台桌面音乐播放器工
|
|||||||
|
|
||||||
### 推荐开发环境
|
### 推荐开发环境
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
- **IDE**: VS Code 或 WebStorm
|
- **IDE**: VS Code 或 WebStorm
|
||||||
- **Node.js 版本**: 22 及以上
|
- **Node.js 版本**: 22 及以上
|
||||||
- **包管理器**: **yarn**
|
- **包管理器**: **yarn**
|
||||||
|
|
||||||
### 项目设置
|
### 项目设置
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
1. 安装依赖:
|
1. 安装依赖:
|
||||||
|
|
||||||
```bash
|
```bash
|
||||||
@@ -66,8 +58,6 @@ Ceru Music 是基于 Electron 和 Vue 开发的跨平台桌面音乐播放器工
|
|||||||
|
|
||||||
### 平台构建指令
|
### 平台构建指令
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
- Windows
|
- Windows
|
||||||
|
|
||||||
```bash
|
```bash
|
||||||
@@ -86,8 +76,6 @@ Ceru Music 是基于 Electron 和 Vue 开发的跨平台桌面音乐播放器工
|
|||||||
yarn build:linux
|
yarn build:linux
|
||||||
```
|
```
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
> 提示:构建后的应用仅包含播放器框架,需用户自行配置合规插件方可获取音乐数据。
|
> 提示:构建后的应用仅包含播放器框架,需用户自行配置合规插件方可获取音乐数据。
|
||||||
|
|
||||||
## 文档与资源
|
## 文档与资源
|
||||||
|
|||||||
@@ -1,3 +0,0 @@
|
|||||||
provider: generic
|
|
||||||
url: https://update.ceru.shiqianjiang.cn
|
|
||||||
updaterCacheDirName: ceru-music-updater
|
|
||||||
@@ -1,12 +1,19 @@
|
|||||||
import { defineConfig } from 'vitepress'
|
import { defineConfig } from 'vitepress'
|
||||||
|
import note from 'markdown-it-footnote'
|
||||||
|
|
||||||
// https://vitepress.dev/reference/site-config
|
|
||||||
export default defineConfig({
|
export default defineConfig({
|
||||||
lang: 'zh-CN',
|
lang: 'zh-CN',
|
||||||
title: "Ceru Music",
|
title: 'Ceru Music',
|
||||||
base: process.env.BASE_URL ?? '/CeruMusic/',
|
base: '/',
|
||||||
description: "Ceru Music 是基于 Electron 和 Vue 开发的跨平台桌面音乐播放器工具,一个跨平台的音乐播放器应用,支持基于合规插件获取公开音乐信息与播放功能。",
|
description:
|
||||||
|
'Ceru Music 是基于 Electron 和 Vue 开发的跨平台桌面音乐播放器工具,一个跨平台的音乐播放器应用,支持基于合规插件获取公开音乐信息与播放功能。',
|
||||||
|
markdown:{
|
||||||
|
config(md){
|
||||||
|
md.use(note)
|
||||||
|
}
|
||||||
|
},
|
||||||
themeConfig: {
|
themeConfig: {
|
||||||
|
returnToTopLabel: '返回顶部',
|
||||||
// https://vitepress.dev/reference/default-theme-config
|
// https://vitepress.dev/reference/default-theme-config
|
||||||
logo: '/logo.svg',
|
logo: '/logo.svg',
|
||||||
nav: [
|
nav: [
|
||||||
@@ -18,8 +25,15 @@ export default defineConfig({
|
|||||||
{
|
{
|
||||||
text: 'CeruMusic',
|
text: 'CeruMusic',
|
||||||
items: [
|
items: [
|
||||||
{ text: '使用教程', link: '/guide/' },
|
{ text: '安装教程', link: '/guide/' },
|
||||||
{ text: '软件设计文档', link: '/guide/design' }
|
{
|
||||||
|
text: '使用教程',
|
||||||
|
items: [
|
||||||
|
{ text: '音乐播放列表', link: '/guide/used/playList' },
|
||||||
|
]
|
||||||
|
},
|
||||||
|
{ text: '软件设计文档', link: '/guide/design' },
|
||||||
|
{ text: '更新日志', link: '/guide/updateLog' }
|
||||||
]
|
]
|
||||||
},
|
},
|
||||||
{
|
{
|
||||||
@@ -37,7 +51,6 @@ export default defineConfig({
|
|||||||
{ icon: 'qq', link: 'https://qm.qq.com/q/IDpQnbGd06' },
|
{ icon: 'qq', link: 'https://qm.qq.com/q/IDpQnbGd06' },
|
||||||
{ icon: 'beatsbydre', link: 'https://shiqianjiang.cn' },
|
{ icon: 'beatsbydre', link: 'https://shiqianjiang.cn' },
|
||||||
{ icon: 'bilibili', link: 'https://space.bilibili.com/696709986' }
|
{ icon: 'bilibili', link: 'https://space.bilibili.com/696709986' }
|
||||||
|
|
||||||
],
|
],
|
||||||
footer: {
|
footer: {
|
||||||
message: 'Released under the Apache License 2.0 License.',
|
message: 'Released under the Apache License 2.0 License.',
|
||||||
@@ -48,9 +61,21 @@ export default defineConfig({
|
|||||||
},
|
},
|
||||||
search: {
|
search: {
|
||||||
provider: 'local'
|
provider: 'local'
|
||||||
}
|
|
||||||
},
|
},
|
||||||
|
outline: {
|
||||||
|
level: [2,4],
|
||||||
|
label: '文章导航'
|
||||||
|
},
|
||||||
|
docFooter: {
|
||||||
|
next: '下一篇',
|
||||||
|
prev: '上一篇'
|
||||||
|
},
|
||||||
|
lastUpdatedText: '上次更新',
|
||||||
|
|
||||||
|
},
|
||||||
|
|
||||||
lastUpdated: true,
|
lastUpdated: true,
|
||||||
head: [['link', { rel: 'icon', href: (process.env.BASE_URL ?? '/CeruMusic/') + 'logo.svg' }]]
|
head: [['link', { rel: 'icon', href: '/logo.svg' }]],
|
||||||
})
|
})
|
||||||
|
console.log(process.env.BASE_URL_DOCS)
|
||||||
// Smooth scrolling functions
|
// Smooth scrolling functions
|
||||||
|
|||||||
@@ -3,7 +3,7 @@
|
|||||||
}
|
}
|
||||||
|
|
||||||
::view-transition-new(*) {
|
::view-transition-new(*) {
|
||||||
animation: globalDark .5s ease-in;
|
animation: globalDark 0.5s ease-in;
|
||||||
}
|
}
|
||||||
|
|
||||||
@keyframes globalDark {
|
@keyframes globalDark {
|
||||||
|
|||||||
@@ -1,7 +1,10 @@
|
|||||||
import { nextTick, provide } from 'vue'
|
import { nextTick, provide } from 'vue'
|
||||||
// 判断是否能使用 startViewTransition
|
// 判断是否能使用 startViewTransition
|
||||||
const enableTransitions = () => {
|
const enableTransitions = () => {
|
||||||
return 'startViewTransition' in document && window.matchMedia('(prefers-reduced-motion: no-preference)').matches
|
return (
|
||||||
|
'startViewTransition' in document &&
|
||||||
|
window.matchMedia('(prefers-reduced-motion: no-preference)').matches
|
||||||
|
)
|
||||||
}
|
}
|
||||||
// 切换动画
|
// 切换动画
|
||||||
export const toggleDark = (isDark: any) => {
|
export const toggleDark = (isDark: any) => {
|
||||||
|
|||||||
@@ -1,7 +1,7 @@
|
|||||||
import DefaultTheme from 'vitepress/theme'
|
import DefaultTheme from 'vitepress/theme'
|
||||||
import './style.css'
|
import './style.scss'
|
||||||
import './dark.css'
|
import './dark.css'
|
||||||
import MyLayout from './MyLayout.vue';
|
import MyLayout from './MyLayout.vue'
|
||||||
// history.scrollRestoration = 'manual'
|
// history.scrollRestoration = 'manual'
|
||||||
|
|
||||||
export default {
|
export default {
|
||||||
@@ -11,6 +11,3 @@ export default {
|
|||||||
// ...
|
// ...
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
|||||||
@@ -157,26 +157,26 @@ html.dark #app {
|
|||||||
no-repeat center;
|
no-repeat center;
|
||||||
|
|
||||||
/* 是否开启网格背景?1 是;0 否 */
|
/* 是否开启网格背景?1 是;0 否 */
|
||||||
--bg-grid: 0;
|
--bg-grid: 1;
|
||||||
|
|
||||||
/* 已完成的代办事项是否显示删除线?1 是;0 否 */
|
/* 已完成的代办事项是否显示删除线?1 是;0 否 */
|
||||||
--check-line: 1;
|
--check-line: 1;
|
||||||
|
|
||||||
/* 自动编号格式设置 无需自动编号可全部注释掉或部分注释掉*/
|
/* 自动编号格式设置 无需自动编号可全部注释掉或部分注释掉*/
|
||||||
/* --autonum-h1: counter(h1) ". ";
|
// --autonum-h1: counter(h1) ". ";
|
||||||
--autonum-h2: counter(h1) "." counter(h2) ". ";
|
// --autonum-h2: counter(h1) "." counter(h2) ". ";
|
||||||
--autonum-h3: counter(h1) "." counter(h2) "." counter(h3) ". ";
|
// --autonum-h3: counter(h1) "." counter(h2) "." counter(h3) ". ";
|
||||||
--autonum-h4: counter(h1) "." counter(h2) "." counter(h3) "." counter(h4) ". ";
|
// --autonum-h4: counter(h1) "." counter(h2) "." counter(h3) "." counter(h4) ". ";
|
||||||
--autonum-h5: counter(h1) "." counter(h2) "." counter(h3) "." counter(h4) "." counter(h5) ". ";
|
// --autonum-h5: counter(h1) "." counter(h2) "." counter(h3) "." counter(h4) "." counter(h5) ". ";
|
||||||
--autonum-h6: counter(h1) "." counter(h2) "." counter(h3) "." counter(h4) "." counter(h5) "." counter(h6) ". "; */
|
// --autonum-h6: counter(h1) "." counter(h2) "." counter(h3) "." counter(h4) "." counter(h5) "." counter(h6) ". ";
|
||||||
|
|
||||||
/* 下面是文章内Toc目录自动编号,与上面一样即可 */
|
/* 下面是文章内Toc目录自动编号,与上面一样即可 */
|
||||||
/* --autonum-h1toc: counter(h1toc) ". ";
|
// --autonum-h1toc: counter(h1toc) ". ";
|
||||||
--autonum-h2toc: counter(h1toc) "." counter(h2toc) ". ";
|
// --autonum-h2toc: counter(h1toc) "." counter(h2toc) ". ";
|
||||||
--autonum-h3toc: counter(h1toc) "." counter(h2toc) "." counter(h3toc) ". ";
|
// --autonum-h3toc: counter(h1toc) "." counter(h2toc) "." counter(h3toc) ". ";
|
||||||
--autonum-h4toc: counter(h1toc) "." counter(h2toc) "." counter(h3toc) "." counter(h4toc) ". ";
|
// --autonum-h4toc: counter(h1toc) "." counter(h2toc) "." counter(h3toc) "." counter(h4toc) ". ";
|
||||||
--autonum-h5toc: counter(h1toc) "." counter(h2toc) "." counter(h3toc) "." counter(h4toc) "." counter(h5toc) ". ";
|
// --autonum-h5toc: counter(h1toc) "." counter(h2toc) "." counter(h3toc) "." counter(h4toc) "." counter(h5toc) ". ";
|
||||||
--autonum-h6toc: counter(h1toc) "." counter(h2toc) "." counter(h3toc) "." counter(h4toc) "." counter(h5toc) "." counter(h6toc) ". "; */
|
// --autonum-h6toc: counter(h1toc) "." counter(h2toc) "." counter(h3toc) "." counter(h4toc) "." counter(h5toc) "." counter(h6toc) ". ";
|
||||||
|
|
||||||
/* 主题颜色 */
|
/* 主题颜色 */
|
||||||
|
|
||||||
@@ -218,36 +218,34 @@ html.dark #app {
|
|||||||
* 黑暗模式切换动画
|
* 黑暗模式切换动画
|
||||||
* -------------------------------------------------------------------------- */
|
* -------------------------------------------------------------------------- */
|
||||||
|
|
||||||
#VPContent .vp-doc > div {
|
// #VPContent .vp-doc > div {
|
||||||
animation:
|
// animation:
|
||||||
rises 1s,
|
// rises 1s,
|
||||||
looming 1s;
|
// looming 1s;
|
||||||
}
|
// }
|
||||||
|
|
||||||
@keyframes rises {
|
// @keyframes rises {
|
||||||
0% {
|
// 0% {
|
||||||
transform: translateY(50px);
|
// transform: translateY(50px);
|
||||||
}
|
// }
|
||||||
|
|
||||||
100% {
|
// 100% {
|
||||||
transform: translateY(0);
|
// transform: translateY(0);
|
||||||
}
|
// }
|
||||||
}
|
// }
|
||||||
|
|
||||||
|
// @keyframes looming {
|
||||||
|
// 0% {
|
||||||
|
// opacity: 0;
|
||||||
|
// }
|
||||||
|
// 50% {
|
||||||
|
// opacity: 0.3;
|
||||||
|
// }
|
||||||
|
// 100% {
|
||||||
|
// opacity: 1;
|
||||||
|
// }
|
||||||
|
// }
|
||||||
|
|
||||||
@keyframes looming {
|
|
||||||
0% {
|
|
||||||
opacity: 0;
|
|
||||||
}
|
|
||||||
50% {
|
|
||||||
opacity: 0.3;
|
|
||||||
}
|
|
||||||
100% {
|
|
||||||
opacity: 1;
|
|
||||||
}
|
|
||||||
}
|
|
||||||
li {
|
|
||||||
position: relative;
|
|
||||||
}
|
|
||||||
.vp-doc li div[class*='language-'] {
|
.vp-doc li div[class*='language-'] {
|
||||||
margin: 12px;
|
margin: 12px;
|
||||||
}
|
}
|
||||||
@@ -264,3 +262,29 @@ html .vp-doc div[class*='language-'] pre {
|
|||||||
overflow: hidden;
|
overflow: hidden;
|
||||||
padding: 0.4em;
|
padding: 0.4em;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
.vp-doc {
|
||||||
|
h1,
|
||||||
|
h2,
|
||||||
|
h3,
|
||||||
|
h4,
|
||||||
|
h5,
|
||||||
|
h6,
|
||||||
|
p {
|
||||||
|
margin-top: 1rem;
|
||||||
|
margin-bottom: 1rem;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
// .VPDoc,
|
||||||
|
// .VPDoc .container > .content {
|
||||||
|
// padding: 0 !important;
|
||||||
|
// }
|
||||||
|
.vp-doc li {
|
||||||
|
position: relative;
|
||||||
|
}
|
||||||
|
.VPDoc.has-aside .content-container {
|
||||||
|
max-width: none !important;
|
||||||
|
}
|
||||||
|
.vp-doc{
|
||||||
|
// padding: min(3vw, 64px) !important;
|
||||||
|
}
|
||||||
15
docs/guide/updateLog.md
Normal file
@@ -0,0 +1,15 @@
|
|||||||
|
# 澜音版本更新日志
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
## 日志
|
||||||
|
|
||||||
|
- 2025-9-17 **(V1.3.1)**
|
||||||
|
1. **设置功能页**
|
||||||
|
- 缓存路径支持自定义
|
||||||
|
- 下载路径支持自定义
|
||||||
|
2. **debug**
|
||||||
|
- 播放页面唱针可以拖动问题
|
||||||
|
- 播放按钮加载中 因为自动下一曲 导致动画变形问题
|
||||||
|
- **SMTC** 功能 系统显示**未知应用**问题
|
||||||
|
- 播放页歌词**字体粗细**偶现丢失问题
|
||||||
BIN
docs/guide/used/assets/image-20250916132204465.png
Normal file
|
After Width: | Height: | Size: 9.5 KiB |
BIN
docs/guide/used/assets/image-20250916132248046.png
Normal file
|
After Width: | Height: | Size: 9.5 KiB |
BIN
docs/guide/used/assets/image-20250916133531421.png
Normal file
|
After Width: | Height: | Size: 88 KiB |
BIN
docs/guide/used/assets/image-20250916134406714.png
Normal file
|
After Width: | Height: | Size: 249 KiB |
BIN
docs/guide/used/assets/image-20250916134511291.png
Normal file
|
After Width: | Height: | Size: 255 KiB |
BIN
docs/guide/used/assets/image-20250916134615679.png
Normal file
|
After Width: | Height: | Size: 41 KiB |
BIN
docs/guide/used/assets/image-20250916134820742.png
Normal file
|
After Width: | Height: | Size: 449 KiB |
28
docs/guide/used/playList.md
Normal file
@@ -0,0 +1,28 @@
|
|||||||
|
# 音乐播放列表-机制分析
|
||||||
|
|
||||||
|
## 基础使用
|
||||||
|
|
||||||
|
1. 默认情况下,播放 **「搜索」「歌单」** 双击中的歌曲时,会自动将该歌曲添加到 **「列表」** 中的末尾后并不会播放,这与手动将歌曲添加到 **「列表」** 等价,亦或是通过点击歌曲前面小三角播放<img src="./assets/image-20250916132248046.png" alt="image-20250916132248046" style="float:right" />可以添加到歌曲开头也可进行该歌曲添加到 **「列表」** 中的开头并播放。歌曲会按照你选择的播放顺序进行播放。
|
||||||
|
2. 对于 **「列表」** 歌曲的顺序可通过展开长按 **1.5s** 后可以进行拖拽排序,歌曲排序实时保存到本地 **LocalStorage**<img src="./assets/image-20250916133531421.png" alt="image-20250916133531421" style="zoom: 20%;" />
|
||||||
|
|
||||||
|
## 歌曲列表的导出和分享
|
||||||
|
|
||||||
|
3. 可进入设置
|
||||||
|
|
||||||
|

|
||||||
|
|
||||||
|
点击 **[播放列表]** =>
|
||||||
|
|
||||||
|

|
||||||
|
|
||||||
|
即可操作你想要的功能
|
||||||
|
|
||||||
|
4. 播放列表还可以导出为歌单
|
||||||
|
|
||||||
|

|
||||||
|
|
||||||
|
歌单将自动选取第一首 **有效封面**[^1] 为歌单
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
[^1]: url正确的歌曲封面
|
||||||
444
docs/songlist-api.md
Normal file
@@ -0,0 +1,444 @@
|
|||||||
|
# 歌单管理 API 文档
|
||||||
|
|
||||||
|
本文档介绍了 CeruMusic 中歌单管理功能的使用方法,包括后端服务类和前端 API 接口。
|
||||||
|
|
||||||
|
## 概述
|
||||||
|
|
||||||
|
歌单管理系统提供了完整的歌单和歌曲管理功能,包括:
|
||||||
|
|
||||||
|
- 📁 **歌单管理**:创建、删除、编辑、搜索歌单
|
||||||
|
- 🎵 **歌曲管理**:添加、移除、搜索歌单中的歌曲
|
||||||
|
- 📊 **统计分析**:获取歌单和歌曲的统计信息
|
||||||
|
- 🔧 **数据维护**:验证和修复歌单数据完整性
|
||||||
|
- ⚡ **批量操作**:支持批量删除和批量移除操作
|
||||||
|
|
||||||
|
## 架构设计
|
||||||
|
|
||||||
|
```
|
||||||
|
前端 (Renderer Process)
|
||||||
|
├── src/renderer/src/api/songList.ts # 前端 API 封装
|
||||||
|
├── src/renderer/src/examples/songListUsage.ts # 使用示例
|
||||||
|
└── src/types/songList.ts # TypeScript 类型定义
|
||||||
|
|
||||||
|
主进程 (Main Process)
|
||||||
|
├── src/main/events/songList.ts # IPC 事件处理
|
||||||
|
├── src/main/services/songList/ManageSongList.ts # 歌单管理服务
|
||||||
|
└── src/main/services/songList/PlayListSongs.ts # 歌曲管理基类
|
||||||
|
```
|
||||||
|
|
||||||
|
## 快速开始
|
||||||
|
|
||||||
|
### 1. 前端使用
|
||||||
|
|
||||||
|
```typescript
|
||||||
|
import songListAPI from '@/api/songList'
|
||||||
|
|
||||||
|
// 创建歌单
|
||||||
|
const result = await songListAPI.create('我的收藏', '我最喜欢的歌曲')
|
||||||
|
if (result.success) {
|
||||||
|
console.log('歌单创建成功,ID:', result.data?.id)
|
||||||
|
}
|
||||||
|
|
||||||
|
// 获取所有歌单
|
||||||
|
const playlists = await songListAPI.getAll()
|
||||||
|
if (playlists.success) {
|
||||||
|
console.log('歌单列表:', playlists.data)
|
||||||
|
}
|
||||||
|
|
||||||
|
// 添加歌曲到歌单
|
||||||
|
const songs = [
|
||||||
|
/* 歌曲数据 */
|
||||||
|
]
|
||||||
|
await songListAPI.addSongs(playlistId, songs)
|
||||||
|
```
|
||||||
|
|
||||||
|
### 2. 类型安全
|
||||||
|
|
||||||
|
所有 API 都提供了完整的 TypeScript 类型支持:
|
||||||
|
|
||||||
|
```typescript
|
||||||
|
import type { IPCResponse, SongListStatistics } from '@/types/songList'
|
||||||
|
|
||||||
|
const stats: IPCResponse<SongListStatistics> = await songListAPI.getStatistics()
|
||||||
|
```
|
||||||
|
|
||||||
|
## API 参考
|
||||||
|
|
||||||
|
### 歌单管理
|
||||||
|
|
||||||
|
#### `create(name, description?, source?)`
|
||||||
|
|
||||||
|
创建新歌单
|
||||||
|
|
||||||
|
```typescript
|
||||||
|
const result = await songListAPI.create('我的收藏', '描述', 'local')
|
||||||
|
// 返回: { success: boolean, data?: { id: string }, error?: string }
|
||||||
|
```
|
||||||
|
|
||||||
|
#### `getAll()`
|
||||||
|
|
||||||
|
获取所有歌单
|
||||||
|
|
||||||
|
```typescript
|
||||||
|
const result = await songListAPI.getAll()
|
||||||
|
// 返回: { success: boolean, data?: SongList[], error?: string }
|
||||||
|
```
|
||||||
|
|
||||||
|
#### `getById(hashId)`
|
||||||
|
|
||||||
|
根据ID获取歌单
|
||||||
|
|
||||||
|
```typescript
|
||||||
|
const result = await songListAPI.getById('playlist-id')
|
||||||
|
// 返回: { success: boolean, data?: SongList | null, error?: string }
|
||||||
|
```
|
||||||
|
|
||||||
|
#### `delete(hashId)`
|
||||||
|
|
||||||
|
删除歌单
|
||||||
|
|
||||||
|
```typescript
|
||||||
|
const result = await songListAPI.delete('playlist-id')
|
||||||
|
// 返回: { success: boolean, error?: string }
|
||||||
|
```
|
||||||
|
|
||||||
|
#### `batchDelete(hashIds)`
|
||||||
|
|
||||||
|
批量删除歌单
|
||||||
|
|
||||||
|
```typescript
|
||||||
|
const result = await songListAPI.batchDelete(['id1', 'id2'])
|
||||||
|
// 返回: { success: boolean, data?: { success: string[], failed: string[] } }
|
||||||
|
```
|
||||||
|
|
||||||
|
#### `edit(hashId, updates)`
|
||||||
|
|
||||||
|
编辑歌单信息
|
||||||
|
|
||||||
|
```typescript
|
||||||
|
const result = await songListAPI.edit('playlist-id', {
|
||||||
|
name: '新名称',
|
||||||
|
description: '新描述'
|
||||||
|
})
|
||||||
|
```
|
||||||
|
|
||||||
|
#### `search(keyword, source?)`
|
||||||
|
|
||||||
|
搜索歌单
|
||||||
|
|
||||||
|
```typescript
|
||||||
|
const result = await songListAPI.search('关键词', 'local')
|
||||||
|
// 返回: { success: boolean, data?: SongList[], error?: string }
|
||||||
|
```
|
||||||
|
|
||||||
|
### 歌曲管理
|
||||||
|
|
||||||
|
#### `addSongs(hashId, songs)`
|
||||||
|
|
||||||
|
添加歌曲到歌单
|
||||||
|
|
||||||
|
```typescript
|
||||||
|
const songs: Songs[] = [
|
||||||
|
/* 歌曲数据 */
|
||||||
|
]
|
||||||
|
const result = await songListAPI.addSongs('playlist-id', songs)
|
||||||
|
```
|
||||||
|
|
||||||
|
#### `removeSong(hashId, songmid)`
|
||||||
|
|
||||||
|
移除单首歌曲
|
||||||
|
|
||||||
|
```typescript
|
||||||
|
const result = await songListAPI.removeSong('playlist-id', 'song-id')
|
||||||
|
// 返回: { success: boolean, data?: boolean, error?: string }
|
||||||
|
```
|
||||||
|
|
||||||
|
#### `removeSongs(hashId, songmids)`
|
||||||
|
|
||||||
|
批量移除歌曲
|
||||||
|
|
||||||
|
```typescript
|
||||||
|
const result = await songListAPI.removeSongs('playlist-id', ['song1', 'song2'])
|
||||||
|
// 返回: { success: boolean, data?: { removed: number, notFound: number } }
|
||||||
|
```
|
||||||
|
|
||||||
|
#### `getSongs(hashId)`
|
||||||
|
|
||||||
|
获取歌单中的歌曲
|
||||||
|
|
||||||
|
```typescript
|
||||||
|
const result = await songListAPI.getSongs('playlist-id')
|
||||||
|
// 返回: { success: boolean, data?: readonly Songs[], error?: string }
|
||||||
|
```
|
||||||
|
|
||||||
|
#### `searchSongs(hashId, keyword)`
|
||||||
|
|
||||||
|
搜索歌单中的歌曲
|
||||||
|
|
||||||
|
```typescript
|
||||||
|
const result = await songListAPI.searchSongs('playlist-id', '关键词')
|
||||||
|
// 返回: { success: boolean, data?: Songs[], error?: string }
|
||||||
|
```
|
||||||
|
|
||||||
|
### 统计信息
|
||||||
|
|
||||||
|
#### `getStatistics()`
|
||||||
|
|
||||||
|
获取歌单统计信息
|
||||||
|
|
||||||
|
```typescript
|
||||||
|
const result = await songListAPI.getStatistics()
|
||||||
|
// 返回: {
|
||||||
|
// success: boolean,
|
||||||
|
// data?: {
|
||||||
|
// total: number,
|
||||||
|
// bySource: Record<string, number>,
|
||||||
|
// lastUpdated: string
|
||||||
|
// }
|
||||||
|
// }
|
||||||
|
```
|
||||||
|
|
||||||
|
#### `getSongStatistics(hashId)`
|
||||||
|
|
||||||
|
获取歌单歌曲统计信息
|
||||||
|
|
||||||
|
```typescript
|
||||||
|
const result = await songListAPI.getSongStatistics('playlist-id')
|
||||||
|
// 返回: {
|
||||||
|
// success: boolean,
|
||||||
|
// data?: {
|
||||||
|
// total: number,
|
||||||
|
// bySinger: Record<string, number>,
|
||||||
|
// byAlbum: Record<string, number>,
|
||||||
|
// lastModified: string
|
||||||
|
// }
|
||||||
|
// }
|
||||||
|
```
|
||||||
|
|
||||||
|
### 数据维护
|
||||||
|
|
||||||
|
#### `validateIntegrity(hashId)`
|
||||||
|
|
||||||
|
验证歌单数据完整性
|
||||||
|
|
||||||
|
```typescript
|
||||||
|
const result = await songListAPI.validateIntegrity('playlist-id')
|
||||||
|
// 返回: { success: boolean, data?: { isValid: boolean, issues: string[] } }
|
||||||
|
```
|
||||||
|
|
||||||
|
#### `repairData(hashId)`
|
||||||
|
|
||||||
|
修复歌单数据
|
||||||
|
|
||||||
|
```typescript
|
||||||
|
const result = await songListAPI.repairData('playlist-id')
|
||||||
|
// 返回: { success: boolean, data?: { fixed: boolean, changes: string[] } }
|
||||||
|
```
|
||||||
|
|
||||||
|
### 便捷方法
|
||||||
|
|
||||||
|
#### `getPlaylistDetail(hashId)`
|
||||||
|
|
||||||
|
获取歌单详细信息(包含歌曲列表)
|
||||||
|
|
||||||
|
```typescript
|
||||||
|
const result = await songListAPI.getPlaylistDetail('playlist-id')
|
||||||
|
// 返回: {
|
||||||
|
// playlist: SongList | null,
|
||||||
|
// songs: readonly Songs[],
|
||||||
|
// success: boolean,
|
||||||
|
// error?: string
|
||||||
|
// }
|
||||||
|
```
|
||||||
|
|
||||||
|
#### `checkAndRepair(hashId)`
|
||||||
|
|
||||||
|
检查并修复歌单数据
|
||||||
|
|
||||||
|
```typescript
|
||||||
|
const result = await songListAPI.checkAndRepair('playlist-id')
|
||||||
|
// 返回: {
|
||||||
|
// needsRepair: boolean,
|
||||||
|
// repairResult?: RepairResult,
|
||||||
|
// success: boolean,
|
||||||
|
// error?: string
|
||||||
|
// }
|
||||||
|
```
|
||||||
|
|
||||||
|
## 错误处理
|
||||||
|
|
||||||
|
所有 API 都返回统一的响应格式:
|
||||||
|
|
||||||
|
```typescript
|
||||||
|
interface IPCResponse<T = any> {
|
||||||
|
success: boolean // 操作是否成功
|
||||||
|
data?: T // 返回的数据
|
||||||
|
error?: string // 错误信息
|
||||||
|
message?: string // 附加消息
|
||||||
|
code?: string // 错误码
|
||||||
|
}
|
||||||
|
```
|
||||||
|
|
||||||
|
### 错误码说明
|
||||||
|
|
||||||
|
| 错误码 | 说明 |
|
||||||
|
| -------------------- | ------------ |
|
||||||
|
| `INVALID_HASH_ID` | 无效的歌单ID |
|
||||||
|
| `PLAYLIST_NOT_FOUND` | 歌单不存在 |
|
||||||
|
| `EMPTY_NAME` | 歌单名称为空 |
|
||||||
|
| `CREATE_FAILED` | 创建失败 |
|
||||||
|
| `DELETE_FAILED` | 删除失败 |
|
||||||
|
| `EDIT_FAILED` | 编辑失败 |
|
||||||
|
| `READ_FAILED` | 读取失败 |
|
||||||
|
| `WRITE_FAILED` | 写入失败 |
|
||||||
|
|
||||||
|
## 使用示例
|
||||||
|
|
||||||
|
### 完整的歌单管理流程
|
||||||
|
|
||||||
|
```typescript
|
||||||
|
import songListAPI from '@/api/songList'
|
||||||
|
|
||||||
|
async function managePlaylist() {
|
||||||
|
try {
|
||||||
|
// 1. 创建歌单
|
||||||
|
const createResult = await songListAPI.create('我的收藏', '我最喜欢的歌曲')
|
||||||
|
if (!createResult.success) {
|
||||||
|
throw new Error(createResult.error)
|
||||||
|
}
|
||||||
|
|
||||||
|
const playlistId = createResult.data!.id
|
||||||
|
|
||||||
|
// 2. 添加歌曲
|
||||||
|
const songs = [
|
||||||
|
{
|
||||||
|
songmid: 'song1',
|
||||||
|
name: '歌曲1',
|
||||||
|
singer: '歌手1',
|
||||||
|
albumName: '专辑1',
|
||||||
|
albumId: 'album1',
|
||||||
|
duration: 240,
|
||||||
|
source: 'local'
|
||||||
|
}
|
||||||
|
]
|
||||||
|
|
||||||
|
await songListAPI.addSongs(playlistId, songs)
|
||||||
|
|
||||||
|
// 3. 获取歌单详情
|
||||||
|
const detail = await songListAPI.getPlaylistDetail(playlistId)
|
||||||
|
console.log('歌单信息:', detail.playlist)
|
||||||
|
console.log('歌曲列表:', detail.songs)
|
||||||
|
|
||||||
|
// 4. 搜索歌曲
|
||||||
|
const searchResult = await songListAPI.searchSongs(playlistId, '歌曲')
|
||||||
|
console.log('搜索结果:', searchResult.data)
|
||||||
|
|
||||||
|
// 5. 获取统计信息
|
||||||
|
const stats = await songListAPI.getSongStatistics(playlistId)
|
||||||
|
console.log('统计信息:', stats.data)
|
||||||
|
} catch (error) {
|
||||||
|
console.error('操作失败:', error)
|
||||||
|
}
|
||||||
|
}
|
||||||
|
```
|
||||||
|
|
||||||
|
### React 组件中的使用
|
||||||
|
|
||||||
|
```typescript
|
||||||
|
import React, { useState, useEffect } from 'react'
|
||||||
|
import songListAPI from '@/api/songList'
|
||||||
|
import type { SongList } from '@common/types/songList'
|
||||||
|
|
||||||
|
const PlaylistManager: React.FC = () => {
|
||||||
|
const [playlists, setPlaylists] = useState<SongList[]>([])
|
||||||
|
const [loading, setLoading] = useState(false)
|
||||||
|
|
||||||
|
// 加载歌单列表
|
||||||
|
const loadPlaylists = async () => {
|
||||||
|
setLoading(true)
|
||||||
|
try {
|
||||||
|
const result = await songListAPI.getAll()
|
||||||
|
if (result.success) {
|
||||||
|
setPlaylists(result.data || [])
|
||||||
|
}
|
||||||
|
} catch (error) {
|
||||||
|
console.error('加载歌单失败:', error)
|
||||||
|
} finally {
|
||||||
|
setLoading(false)
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
// 创建新歌单
|
||||||
|
const createPlaylist = async (name: string) => {
|
||||||
|
const result = await songListAPI.create(name)
|
||||||
|
if (result.success) {
|
||||||
|
await loadPlaylists() // 重新加载列表
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
// 删除歌单
|
||||||
|
const deletePlaylist = async (id: string) => {
|
||||||
|
const result = await songListAPI.safeDelete(id, async () => {
|
||||||
|
return confirm('确定要删除这个歌单吗?')
|
||||||
|
})
|
||||||
|
|
||||||
|
if (result.success) {
|
||||||
|
await loadPlaylists() // 重新加载列表
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
useEffect(() => {
|
||||||
|
loadPlaylists()
|
||||||
|
}, [])
|
||||||
|
|
||||||
|
return (
|
||||||
|
<div>
|
||||||
|
{loading ? (
|
||||||
|
<div>加载中...</div>
|
||||||
|
) : (
|
||||||
|
<div>
|
||||||
|
{playlists.map(playlist => (
|
||||||
|
<div key={playlist.id}>
|
||||||
|
<h3>{playlist.name}</h3>
|
||||||
|
<p>{playlist.description}</p>
|
||||||
|
<button onClick={() => deletePlaylist(playlist.id)}>
|
||||||
|
删除
|
||||||
|
</button>
|
||||||
|
</div>
|
||||||
|
))}
|
||||||
|
</div>
|
||||||
|
)}
|
||||||
|
</div>
|
||||||
|
)
|
||||||
|
}
|
||||||
|
```
|
||||||
|
|
||||||
|
## 性能优化建议
|
||||||
|
|
||||||
|
1. **批量操作**:使用 `batchDelete` 和 `removeSongs` 进行批量操作
|
||||||
|
2. **数据缓存**:在前端适当缓存歌单列表,避免频繁请求
|
||||||
|
3. **懒加载**:歌曲列表可以按需加载,不必一次性加载所有数据
|
||||||
|
4. **错误恢复**:使用 `checkAndRepair` 定期检查数据完整性
|
||||||
|
|
||||||
|
## 注意事项
|
||||||
|
|
||||||
|
1. 所有 API 都是异步的,需要使用 `await` 或 `.then()`
|
||||||
|
2. 歌单 ID (`hashId`) 是唯一标识符,不要与数组索引混淆
|
||||||
|
3. 歌曲 ID (`songmid`) 可能是字符串或数字类型
|
||||||
|
4. 删除操作是不可逆的,建议使用 `safeDelete` 方法
|
||||||
|
5. 大量数据操作时注意性能影响
|
||||||
|
|
||||||
|
## 更新日志
|
||||||
|
|
||||||
|
### v1.0.0 (2024-01-10)
|
||||||
|
|
||||||
|
- ✨ 初始版本发布
|
||||||
|
- ✨ 完整的歌单管理功能
|
||||||
|
- ✨ 批量操作支持
|
||||||
|
- ✨ 数据完整性检查
|
||||||
|
- ✨ TypeScript 类型支持
|
||||||
|
- ✨ 详细的使用文档和示例
|
||||||
|
|
||||||
|
---
|
||||||
|
|
||||||
|
如有问题或建议,请提交 Issue 或 Pull Request。
|
||||||
@@ -19,6 +19,7 @@ win:
|
|||||||
- target: nsis
|
- target: nsis
|
||||||
arch:
|
arch:
|
||||||
- x64
|
- x64
|
||||||
|
- ia32
|
||||||
# 简化版本信息设置,避免rcedit错误
|
# 简化版本信息设置,避免rcedit错误
|
||||||
fileAssociations:
|
fileAssociations:
|
||||||
- ext: cerumusic
|
- ext: cerumusic
|
||||||
@@ -30,7 +31,7 @@ win:
|
|||||||
# 或者使用证书存储
|
# 或者使用证书存储
|
||||||
# certificateSubjectName: "Your Company Name"
|
# certificateSubjectName: "Your Company Name"
|
||||||
nsis:
|
nsis:
|
||||||
artifactName: ${name}-${version}-setup.${ext}
|
artifactName: ${name}-${version}-${arch}-setup.${ext}
|
||||||
shortcutName: ${productName}
|
shortcutName: ${productName}
|
||||||
uninstallDisplayName: ${productName}
|
uninstallDisplayName: ${productName}
|
||||||
createDesktopShortcut: always
|
createDesktopShortcut: always
|
||||||
@@ -40,16 +41,17 @@ nsis:
|
|||||||
allowToChangeInstallationDirectory: true
|
allowToChangeInstallationDirectory: true
|
||||||
allowElevation: true
|
allowElevation: true
|
||||||
mac:
|
mac:
|
||||||
|
icon: 'resources/icons/icon.icns'
|
||||||
entitlementsInherit: build/entitlements.mac.plist
|
entitlementsInherit: build/entitlements.mac.plist
|
||||||
extendInfo:
|
extendInfo:
|
||||||
- NSCameraUsageDescription: Application requests access to the device's camera.
|
- NSDocumentsFolderUsageDescription: 需要访问文档文件夹来保存和打开您创建的文件。
|
||||||
- NSMicrophoneUsageDescription: Application requests access to the device's microphone.
|
- NSDownloadsFolderUsageDescription: 需要访问下载文件夹来管理您下载的内容。
|
||||||
- NSDocumentsFolderUsageDescription: Application requests access to the user's Documents folder.
|
|
||||||
- NSDownloadsFolderUsageDescription: Application requests access to the user's Downloads folder.
|
|
||||||
notarize: false
|
notarize: false
|
||||||
dmg:
|
dmg:
|
||||||
artifactName: ${name}-${version}.${ext}
|
artifactName: ${name}-${version}.${ext}
|
||||||
|
title: ${productName}
|
||||||
linux:
|
linux:
|
||||||
|
icon: 'resources/icons'
|
||||||
target:
|
target:
|
||||||
- AppImage
|
- AppImage
|
||||||
- snap
|
- snap
|
||||||
|
|||||||
235
eslint.config.js
Normal file
@@ -0,0 +1,235 @@
|
|||||||
|
import js from '@eslint/js'
|
||||||
|
import tseslint from 'typescript-eslint'
|
||||||
|
import vue from 'eslint-plugin-vue'
|
||||||
|
import prettier from '@electron-toolkit/eslint-config-prettier'
|
||||||
|
|
||||||
|
export default [
|
||||||
|
// 基础 JavaScript 推荐配置
|
||||||
|
js.configs.recommended,
|
||||||
|
|
||||||
|
// TypeScript 推荐配置
|
||||||
|
...tseslint.configs.recommended,
|
||||||
|
|
||||||
|
// Vue 3 推荐配置
|
||||||
|
...vue.configs['flat/recommended'],
|
||||||
|
|
||||||
|
// 忽略的文件和目录
|
||||||
|
{
|
||||||
|
ignores: [
|
||||||
|
'**/node_modules/**',
|
||||||
|
'**/dist/**',
|
||||||
|
'**/out/**',
|
||||||
|
'**/build/**',
|
||||||
|
'**/.vitepress/**',
|
||||||
|
'**/docs/**',
|
||||||
|
'**/website/**',
|
||||||
|
'**/coverage/**',
|
||||||
|
'**/*.min.js',
|
||||||
|
'**/auto-imports.d.ts',
|
||||||
|
'**/components.d.ts',
|
||||||
|
'src/preload/index.d.ts', // 忽略类型定义文件
|
||||||
|
'src/renderer/src/assets/icon_font/**', // 忽略第三方图标字体文件
|
||||||
|
'src/main/utils/musicSdk/**', // 忽略第三方音乐 SDK
|
||||||
|
'src/main/utils/request.js', // 忽略第三方请求库
|
||||||
|
'scripts/**', // 忽略脚本文件
|
||||||
|
'src/common/utils/lyricUtils/**' // 忽略第三方歌词工具
|
||||||
|
]
|
||||||
|
},
|
||||||
|
|
||||||
|
// 全局配置
|
||||||
|
{
|
||||||
|
files: ['**/*.{js,ts,vue}'],
|
||||||
|
languageOptions: {
|
||||||
|
ecmaVersion: 'latest',
|
||||||
|
sourceType: 'module'
|
||||||
|
},
|
||||||
|
rules: {
|
||||||
|
// 代码质量 (放宽规则)
|
||||||
|
'no-unused-vars': 'off', // 由 TypeScript 处理
|
||||||
|
'no-undef': 'off', // 由 TypeScript 处理
|
||||||
|
'prefer-const': 'warn', // 降级为警告
|
||||||
|
'no-var': 'warn', // 降级为警告
|
||||||
|
'no-duplicate-imports': 'off', // 允许重复导入
|
||||||
|
'no-useless-return': 'off',
|
||||||
|
'no-useless-concat': 'off',
|
||||||
|
'no-useless-escape': 'off',
|
||||||
|
'no-unreachable': 'warn',
|
||||||
|
'no-debugger': 'off',
|
||||||
|
|
||||||
|
// 代码风格 (大幅放宽)
|
||||||
|
eqeqeq: 'off', // 允许 == 和 ===
|
||||||
|
curly: 'off', // 允许不使用大括号
|
||||||
|
'brace-style': 'off',
|
||||||
|
'comma-dangle': 'off',
|
||||||
|
quotes: 'off',
|
||||||
|
semi: 'off',
|
||||||
|
indent: 'off',
|
||||||
|
'object-curly-spacing': 'off',
|
||||||
|
'array-bracket-spacing': 'off',
|
||||||
|
'space-before-function-paren': 'off',
|
||||||
|
|
||||||
|
// 最佳实践 (放宽)
|
||||||
|
'no-eval': 'warn',
|
||||||
|
'no-implied-eval': 'warn',
|
||||||
|
'no-new-func': 'warn',
|
||||||
|
'no-alert': 'off',
|
||||||
|
'no-empty': 'off', // 允许空块
|
||||||
|
'no-extra-boolean-cast': 'off',
|
||||||
|
'no-extra-semi': 'off',
|
||||||
|
'no-irregular-whitespace': 'off',
|
||||||
|
'no-multiple-empty-lines': 'off',
|
||||||
|
'no-trailing-spaces': 'off',
|
||||||
|
'eol-last': 'off',
|
||||||
|
'no-fallthrough': 'off', // 允许 switch case 穿透
|
||||||
|
'no-case-declarations': 'off', // 允许 case 中声明变量
|
||||||
|
'no-empty-pattern': 'off', // 允许空对象模式
|
||||||
|
'no-prototype-builtins': 'off', // 允许直接调用 hasOwnProperty
|
||||||
|
'no-self-assign': 'off', // 允许自赋值
|
||||||
|
'no-async-promise-executor': 'off' // 允许异步 Promise 执行器
|
||||||
|
}
|
||||||
|
},
|
||||||
|
|
||||||
|
// 主进程 TypeScript 配置
|
||||||
|
{
|
||||||
|
files: ['src/main/**/*.ts', 'src/preload/**/*.ts', 'src/common/**/*.ts', 'src/types/**/*.ts'],
|
||||||
|
languageOptions: {
|
||||||
|
parserOptions: {
|
||||||
|
project: './tsconfig.node.json',
|
||||||
|
tsconfigRootDir: process.cwd()
|
||||||
|
}
|
||||||
|
},
|
||||||
|
rules: {
|
||||||
|
// TypeScript 特定规则 (大幅放宽)
|
||||||
|
'@typescript-eslint/no-unused-vars': 'off', // 完全关闭未使用变量检查
|
||||||
|
'@typescript-eslint/no-explicit-any': 'off',
|
||||||
|
'@typescript-eslint/explicit-function-return-type': 'off',
|
||||||
|
'@typescript-eslint/explicit-module-boundary-types': 'off',
|
||||||
|
'@typescript-eslint/no-non-null-assertion': 'off',
|
||||||
|
'@typescript-eslint/no-var-requires': 'off', // 允许 require
|
||||||
|
'@typescript-eslint/ban-ts-comment': 'off', // 允许 @ts-ignore
|
||||||
|
'@typescript-eslint/no-empty-function': 'off', // 允许空函数
|
||||||
|
'@typescript-eslint/no-inferrable-types': 'off',
|
||||||
|
'@typescript-eslint/no-unused-expressions': 'off', // 允许未使用的表达式
|
||||||
|
'@typescript-eslint/no-require-imports': 'off', // 允许 require 导入
|
||||||
|
'@typescript-eslint/no-unsafe-function-type': 'off', // 允许 Function 类型
|
||||||
|
'@typescript-eslint/prefer-as-const': 'off' // 允许字面量类型
|
||||||
|
}
|
||||||
|
},
|
||||||
|
|
||||||
|
// 渲染进程 TypeScript 配置
|
||||||
|
{
|
||||||
|
files: ['src/renderer/**/*.ts'],
|
||||||
|
languageOptions: {
|
||||||
|
parserOptions: {
|
||||||
|
project: './tsconfig.web.json',
|
||||||
|
tsconfigRootDir: process.cwd()
|
||||||
|
}
|
||||||
|
},
|
||||||
|
rules: {
|
||||||
|
// TypeScript 特定规则 (大幅放宽)
|
||||||
|
'@typescript-eslint/no-unused-vars': 'off',
|
||||||
|
'@typescript-eslint/no-explicit-any': 'off',
|
||||||
|
'@typescript-eslint/explicit-function-return-type': 'off',
|
||||||
|
'@typescript-eslint/explicit-module-boundary-types': 'off',
|
||||||
|
'@typescript-eslint/no-non-null-assertion': 'off',
|
||||||
|
'@typescript-eslint/no-var-requires': 'off',
|
||||||
|
'@typescript-eslint/ban-ts-comment': 'off',
|
||||||
|
'@typescript-eslint/no-empty-function': 'off',
|
||||||
|
'@typescript-eslint/no-inferrable-types': 'off',
|
||||||
|
'@typescript-eslint/no-unused-expressions': 'off',
|
||||||
|
'@typescript-eslint/no-require-imports': 'off',
|
||||||
|
'@typescript-eslint/no-unsafe-function-type': 'off',
|
||||||
|
'@typescript-eslint/prefer-as-const': 'off'
|
||||||
|
}
|
||||||
|
},
|
||||||
|
|
||||||
|
// Vue 特定配置
|
||||||
|
{
|
||||||
|
files: ['src/renderer/**/*.vue'],
|
||||||
|
languageOptions: {
|
||||||
|
parserOptions: {
|
||||||
|
parser: '@typescript-eslint/parser',
|
||||||
|
extraFileExtensions: ['.vue']
|
||||||
|
}
|
||||||
|
},
|
||||||
|
rules: {
|
||||||
|
// Vue 特定规则 (大幅放宽)
|
||||||
|
'vue/multi-word-component-names': 'off',
|
||||||
|
'vue/no-v-html': 'off', // 允许 v-html
|
||||||
|
'vue/require-default-prop': 'off',
|
||||||
|
'vue/require-explicit-emits': 'off', // 不强制显式 emits
|
||||||
|
'vue/component-definition-name-casing': 'off',
|
||||||
|
'vue/component-name-in-template-casing': 'off',
|
||||||
|
'vue/custom-event-name-casing': 'off', // 允许任意事件命名
|
||||||
|
'vue/define-macros-order': 'off',
|
||||||
|
'vue/html-self-closing': 'off',
|
||||||
|
'vue/max-attributes-per-line': 'off',
|
||||||
|
'vue/singleline-html-element-content-newline': 'off',
|
||||||
|
'vue/multiline-html-element-content-newline': 'off',
|
||||||
|
'vue/no-side-effects-in-computed-properties': 'off', // 允许计算属性中的副作用
|
||||||
|
'vue/no-required-prop-with-default': 'off', // 允许带默认值的必需属性
|
||||||
|
|
||||||
|
// TypeScript 在 Vue 中的规则 (放宽)
|
||||||
|
'@typescript-eslint/no-unused-vars': 'off',
|
||||||
|
'@typescript-eslint/no-explicit-any': 'off',
|
||||||
|
'@typescript-eslint/no-unsafe-function-type': 'off'
|
||||||
|
}
|
||||||
|
},
|
||||||
|
|
||||||
|
// 主进程文件配置 (Node.js 环境)
|
||||||
|
{
|
||||||
|
files: [
|
||||||
|
'src/main/**/*.{ts,js}',
|
||||||
|
'src/preload/**/*.{ts,js}',
|
||||||
|
'electron.vite.config.*',
|
||||||
|
'scripts/**/*.{js,ts}'
|
||||||
|
],
|
||||||
|
languageOptions: {
|
||||||
|
globals: {
|
||||||
|
__dirname: 'readonly',
|
||||||
|
__filename: 'readonly',
|
||||||
|
Buffer: 'readonly',
|
||||||
|
process: 'readonly',
|
||||||
|
global: 'readonly'
|
||||||
|
}
|
||||||
|
},
|
||||||
|
rules: {
|
||||||
|
// Node.js 特定规则 (放宽)
|
||||||
|
'no-console': 'off',
|
||||||
|
'no-process-exit': 'off' // 允许 process.exit()
|
||||||
|
}
|
||||||
|
},
|
||||||
|
|
||||||
|
// 渲染进程文件配置 (浏览器环境)
|
||||||
|
{
|
||||||
|
files: ['src/renderer/**/*.{ts,js,vue}'],
|
||||||
|
languageOptions: {
|
||||||
|
globals: {
|
||||||
|
window: 'readonly',
|
||||||
|
document: 'readonly',
|
||||||
|
navigator: 'readonly',
|
||||||
|
console: 'readonly',
|
||||||
|
setTimeout: 'readonly',
|
||||||
|
clearTimeout: 'readonly',
|
||||||
|
setInterval: 'readonly',
|
||||||
|
clearInterval: 'readonly'
|
||||||
|
}
|
||||||
|
},
|
||||||
|
rules: {
|
||||||
|
// 浏览器环境特定规则
|
||||||
|
'no-console': 'off'
|
||||||
|
}
|
||||||
|
},
|
||||||
|
|
||||||
|
// 配置文件特殊规则
|
||||||
|
{
|
||||||
|
files: ['*.config.{js,ts}', 'vite.config.*', 'electron.vite.config.*'],
|
||||||
|
rules: {
|
||||||
|
'no-console': 'off',
|
||||||
|
'@typescript-eslint/no-var-requires': 'off'
|
||||||
|
}
|
||||||
|
},
|
||||||
|
|
||||||
|
// Prettier 配置 (必须放在最后)
|
||||||
|
prettier
|
||||||
|
]
|
||||||
@@ -1,102 +0,0 @@
|
|||||||
const baseRule = {
|
|
||||||
'no-new': 'off',
|
|
||||||
camelcase: 'off',
|
|
||||||
'no-return-assign': 'off',
|
|
||||||
'space-before-function-paren': ['error', 'never'],
|
|
||||||
'no-var': 'error',
|
|
||||||
'no-fallthrough': 'off',
|
|
||||||
eqeqeq: 'off',
|
|
||||||
'require-atomic-updates': ['error', { allowProperties: true }],
|
|
||||||
'no-multiple-empty-lines': [1, { max: 2 }],
|
|
||||||
'comma-dangle': [2, 'always-multiline'],
|
|
||||||
'standard/no-callback-literal': 'off',
|
|
||||||
'prefer-const': 'off',
|
|
||||||
'no-labels': 'off',
|
|
||||||
'node/no-callback-literal': 'off',
|
|
||||||
'multiline-ternary': 'off'
|
|
||||||
}
|
|
||||||
const typescriptRule = {
|
|
||||||
...baseRule,
|
|
||||||
'@typescript-eslint/strict-boolean-expressions': 'off',
|
|
||||||
'@typescript-eslint/explicit-function-return-type': 'off',
|
|
||||||
'@typescript-eslint/space-before-function-paren': 'off',
|
|
||||||
'@typescript-eslint/no-non-null-assertion': 'off',
|
|
||||||
'@typescript-eslint/restrict-template-expressions': [
|
|
||||||
1,
|
|
||||||
{
|
|
||||||
allowBoolean: true,
|
|
||||||
allowAny: true
|
|
||||||
}
|
|
||||||
],
|
|
||||||
'@typescript-eslint/restrict-plus-operands': [
|
|
||||||
1,
|
|
||||||
{
|
|
||||||
allowBoolean: true,
|
|
||||||
allowAny: true
|
|
||||||
}
|
|
||||||
],
|
|
||||||
'@typescript-eslint/no-misused-promises': [
|
|
||||||
'error',
|
|
||||||
{
|
|
||||||
checksVoidReturn: {
|
|
||||||
arguments: false,
|
|
||||||
attributes: false
|
|
||||||
}
|
|
||||||
}
|
|
||||||
],
|
|
||||||
'@typescript-eslint/naming-convention': 'off',
|
|
||||||
'@typescript-eslint/return-await': 'off',
|
|
||||||
'@typescript-eslint/ban-ts-comment': 'off',
|
|
||||||
'@typescript-eslint/comma-dangle': 'off',
|
|
||||||
'@typescript-eslint/no-unsafe-argument': 'off'
|
|
||||||
}
|
|
||||||
const vueRule = {
|
|
||||||
...typescriptRule,
|
|
||||||
'vue/multi-word-component-names': 'off',
|
|
||||||
'vue/max-attributes-per-line': 'off',
|
|
||||||
'vue/singleline-html-element-content-newline': 'off',
|
|
||||||
'vue/use-v-on-exact': 'off'
|
|
||||||
}
|
|
||||||
|
|
||||||
export const base = {
|
|
||||||
extends: ['standard'],
|
|
||||||
rules: baseRule,
|
|
||||||
parser: '@babel/eslint-parser'
|
|
||||||
}
|
|
||||||
|
|
||||||
export const html = {
|
|
||||||
files: ['*.html'],
|
|
||||||
plugins: ['html']
|
|
||||||
}
|
|
||||||
|
|
||||||
export const typescript = {
|
|
||||||
files: ['*.ts'],
|
|
||||||
rules: typescriptRule,
|
|
||||||
parser: '@typescript-eslint/parser',
|
|
||||||
extends: ['standard-with-typescript']
|
|
||||||
}
|
|
||||||
|
|
||||||
export const vue = {
|
|
||||||
files: ['*.vue'],
|
|
||||||
rules: vueRule,
|
|
||||||
parser: 'vue-eslint-parser',
|
|
||||||
extends: [
|
|
||||||
// 'plugin:vue/vue3-essential',
|
|
||||||
'plugin:vue/base',
|
|
||||||
'plugin:vue/vue3-recommended',
|
|
||||||
'plugin:vue-pug/vue3-recommended',
|
|
||||||
// "plugin:vue/strongly-recommended"
|
|
||||||
'standard-with-typescript'
|
|
||||||
],
|
|
||||||
parserOptions: {
|
|
||||||
sourceType: 'module',
|
|
||||||
parser: {
|
|
||||||
// Script parser for `<script>`
|
|
||||||
js: '@typescript-eslint/parser',
|
|
||||||
|
|
||||||
// Script parser for `<script lang="ts">`
|
|
||||||
ts: '@typescript-eslint/parser'
|
|
||||||
},
|
|
||||||
extraFileExtensions: ['.vue']
|
|
||||||
}
|
|
||||||
}
|
|
||||||
5224
package-lock.json
generated
12
package.json
@@ -1,6 +1,6 @@
|
|||||||
{
|
{
|
||||||
"name": "ceru-music",
|
"name": "ceru-music",
|
||||||
"version": "1.1.10",
|
"version": "1.3.1",
|
||||||
"description": "一款简洁优雅的音乐播放器",
|
"description": "一款简洁优雅的音乐播放器",
|
||||||
"main": "./out/main/index.js",
|
"main": "./out/main/index.js",
|
||||||
"author": "sqj,wldss,star",
|
"author": "sqj,wldss,star",
|
||||||
@@ -18,7 +18,8 @@
|
|||||||
"onlybuild": "electron-vite build && electron-builder --win --x64",
|
"onlybuild": "electron-vite build && electron-builder --win --x64",
|
||||||
"postinstall": "electron-builder install-app-deps",
|
"postinstall": "electron-builder install-app-deps",
|
||||||
"build:unpack": "yarn run build && electron-builder --dir",
|
"build:unpack": "yarn run build && electron-builder --dir",
|
||||||
"build:win": "yarn run build && electron-builder --win --x64 --config --publish never",
|
"build:win": "yarn run build && electron-builder --win --config --publish never",
|
||||||
|
"build:win32": "yarn run build && electron-builder --win --ia32 --config --publish never",
|
||||||
"build:mac": "yarn run build && electron-builder --mac --config --publish never",
|
"build:mac": "yarn run build && electron-builder --mac --config --publish never",
|
||||||
"build:linux": "yarn run build && electron-builder --linux --config --publish never",
|
"build:linux": "yarn run build && electron-builder --linux --config --publish never",
|
||||||
"build:deps": "electron-builder install-app-deps && yarn run build && electron-builder --win --x64 --config",
|
"build:deps": "electron-builder install-app-deps && yarn run build && electron-builder --win --x64 --config",
|
||||||
@@ -57,6 +58,7 @@
|
|||||||
"jss": "^10.10.0",
|
"jss": "^10.10.0",
|
||||||
"jss-preset-default": "^10.10.0",
|
"jss-preset-default": "^10.10.0",
|
||||||
"lodash": "^4.17.21",
|
"lodash": "^4.17.21",
|
||||||
|
"markdown-it-footnote": "^4.0.0",
|
||||||
"marked": "^16.1.2",
|
"marked": "^16.1.2",
|
||||||
"mitt": "^3.0.1",
|
"mitt": "^3.0.1",
|
||||||
"needle": "^3.3.1",
|
"needle": "^3.3.1",
|
||||||
@@ -74,10 +76,11 @@
|
|||||||
"@electron-toolkit/tsconfig": "^1.0.1",
|
"@electron-toolkit/tsconfig": "^1.0.1",
|
||||||
"@tdesign-vue-next/auto-import-resolver": "^0.1.1",
|
"@tdesign-vue-next/auto-import-resolver": "^0.1.1",
|
||||||
"@types/crypto-js": "^4.2.2",
|
"@types/crypto-js": "^4.2.2",
|
||||||
|
"@types/markdown-it-footnote": "^3.0.4",
|
||||||
"@types/node": "^22.16.5",
|
"@types/node": "^22.16.5",
|
||||||
"@types/node-fetch": "^2.6.13",
|
"@types/node-fetch": "^2.6.13",
|
||||||
"@vitejs/plugin-vue": "^6.0.0",
|
"@vitejs/plugin-vue": "^6.0.0",
|
||||||
"electron": "^37.3.1",
|
"electron": "^38.1.0",
|
||||||
"electron-builder": "^25.1.8",
|
"electron-builder": "^25.1.8",
|
||||||
"electron-icon-builder": "^2.0.1",
|
"electron-icon-builder": "^2.0.1",
|
||||||
"electron-vite": "^4.0.0",
|
"electron-vite": "^4.0.0",
|
||||||
@@ -94,7 +97,8 @@
|
|||||||
"vite-plugin-top-level-await": "^1.6.0",
|
"vite-plugin-top-level-await": "^1.6.0",
|
||||||
"vite-plugin-vue-devtools": "^8.0.0",
|
"vite-plugin-vue-devtools": "^8.0.0",
|
||||||
"vite-plugin-wasm": "^3.5.0",
|
"vite-plugin-wasm": "^3.5.0",
|
||||||
"vue": "^3.5.17",
|
"vitepress": "^1.6.4",
|
||||||
|
"vue": "^3.5.21",
|
||||||
"vue-eslint-parser": "^10.2.0",
|
"vue-eslint-parser": "^10.2.0",
|
||||||
"vue-tsc": "^3.0.3"
|
"vue-tsc": "^3.0.3"
|
||||||
}
|
}
|
||||||
|
|||||||
10491
pnpm-lock.yaml
generated
BIN
resources/default-cover.png
Normal file
|
After Width: | Height: | Size: 824 KiB |
66
scripts/auth-test.js
Normal file
@@ -0,0 +1,66 @@
|
|||||||
|
const axios = require('axios')
|
||||||
|
|
||||||
|
const ALIST_BASE_URL = 'http://47.96.72.224:5244'
|
||||||
|
const ALIST_USERNAME = 'ceruupdate'
|
||||||
|
const ALIST_PASSWORD = '123456'
|
||||||
|
|
||||||
|
async function test() {
|
||||||
|
// 认证
|
||||||
|
const auth = await axios.post(`${ALIST_BASE_URL}/api/auth/login`, {
|
||||||
|
username: ALIST_USERNAME,
|
||||||
|
password: ALIST_PASSWORD
|
||||||
|
})
|
||||||
|
|
||||||
|
const token = auth.data.data.token
|
||||||
|
console.log('Token received')
|
||||||
|
|
||||||
|
// 测试直接 token 格式
|
||||||
|
try {
|
||||||
|
const list = await axios.post(
|
||||||
|
`${ALIST_BASE_URL}/api/fs/list`,
|
||||||
|
{
|
||||||
|
path: '/',
|
||||||
|
password: '',
|
||||||
|
page: 1,
|
||||||
|
per_page: 30,
|
||||||
|
refresh: false
|
||||||
|
},
|
||||||
|
{
|
||||||
|
headers: { Authorization: token }
|
||||||
|
}
|
||||||
|
)
|
||||||
|
|
||||||
|
console.log('Direct token works:', list.data.code === 200)
|
||||||
|
if (list.data.code === 200) {
|
||||||
|
console.log(
|
||||||
|
'Files:',
|
||||||
|
list.data.data.content.map((f) => f.name)
|
||||||
|
)
|
||||||
|
}
|
||||||
|
} catch (e) {
|
||||||
|
console.log('Direct token failed')
|
||||||
|
}
|
||||||
|
|
||||||
|
// 测试 Bearer 格式
|
||||||
|
try {
|
||||||
|
const list2 = await axios.post(
|
||||||
|
`${ALIST_BASE_URL}/api/fs/list`,
|
||||||
|
{
|
||||||
|
path: '/',
|
||||||
|
password: '',
|
||||||
|
page: 1,
|
||||||
|
per_page: 30,
|
||||||
|
refresh: false
|
||||||
|
},
|
||||||
|
{
|
||||||
|
headers: { Authorization: `Bearer ${token}` }
|
||||||
|
}
|
||||||
|
)
|
||||||
|
|
||||||
|
console.log('Bearer format works:', list2.data.code === 200)
|
||||||
|
} catch (e) {
|
||||||
|
console.log('Bearer format failed')
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
test().catch(console.error)
|
||||||
148
scripts/test-alist.js
Normal file
@@ -0,0 +1,148 @@
|
|||||||
|
const axios = require('axios')
|
||||||
|
|
||||||
|
// Alist API 配置
|
||||||
|
const ALIST_BASE_URL = 'http://47.96.72.224:5244'
|
||||||
|
const ALIST_USERNAME = 'ceruupdate'
|
||||||
|
const ALIST_PASSWORD = '123456'
|
||||||
|
|
||||||
|
async function testAlistConnection() {
|
||||||
|
console.log('Testing Alist connection...')
|
||||||
|
|
||||||
|
try {
|
||||||
|
// 0. 首先测试服务器是否可访问
|
||||||
|
console.log('0. Testing server accessibility...')
|
||||||
|
const pingResponse = await axios.get(`${ALIST_BASE_URL}/ping`, {
|
||||||
|
timeout: 5000
|
||||||
|
})
|
||||||
|
console.log('Server ping successful:', pingResponse.status)
|
||||||
|
|
||||||
|
// 1. 测试认证
|
||||||
|
console.log('1. Testing authentication...')
|
||||||
|
console.log(`Trying to authenticate with username: ${ALIST_USERNAME}`)
|
||||||
|
|
||||||
|
const authResponse = await axios.post(
|
||||||
|
`${ALIST_BASE_URL}/api/auth/login`,
|
||||||
|
{
|
||||||
|
username: ALIST_USERNAME,
|
||||||
|
password: ALIST_PASSWORD
|
||||||
|
},
|
||||||
|
{
|
||||||
|
timeout: 10000,
|
||||||
|
headers: {
|
||||||
|
'Content-Type': 'application/json'
|
||||||
|
}
|
||||||
|
}
|
||||||
|
)
|
||||||
|
|
||||||
|
console.log('Auth response:', authResponse.data)
|
||||||
|
|
||||||
|
if (authResponse.data.code !== 200) {
|
||||||
|
// 尝试获取公共访问权限
|
||||||
|
console.log('Authentication failed, trying public access...')
|
||||||
|
|
||||||
|
// 尝试不使用认证直接访问文件列表
|
||||||
|
const publicListResponse = await axios.post(
|
||||||
|
`${ALIST_BASE_URL}/api/fs/list`,
|
||||||
|
{
|
||||||
|
path: '/',
|
||||||
|
password: '',
|
||||||
|
page: 1,
|
||||||
|
per_page: 30,
|
||||||
|
refresh: false
|
||||||
|
},
|
||||||
|
{
|
||||||
|
timeout: 10000,
|
||||||
|
headers: {
|
||||||
|
'Content-Type': 'application/json'
|
||||||
|
}
|
||||||
|
}
|
||||||
|
)
|
||||||
|
|
||||||
|
console.log('Public access response:', publicListResponse.data)
|
||||||
|
|
||||||
|
if (publicListResponse.data.code === 200) {
|
||||||
|
console.log('✓ Public access successful')
|
||||||
|
return // 如果公共访问成功,就不需要认证
|
||||||
|
}
|
||||||
|
|
||||||
|
throw new Error(`Authentication failed: ${authResponse.data.message}`)
|
||||||
|
}
|
||||||
|
|
||||||
|
const token = authResponse.data.data.token
|
||||||
|
console.log('✓ Authentication successful')
|
||||||
|
|
||||||
|
// 2. 测试文件列表
|
||||||
|
console.log('2. Testing file listing...')
|
||||||
|
const listResponse = await axios.post(
|
||||||
|
`${ALIST_BASE_URL}/api/fs/list`,
|
||||||
|
{
|
||||||
|
path: '/',
|
||||||
|
password: '',
|
||||||
|
page: 1,
|
||||||
|
per_page: 30,
|
||||||
|
refresh: false
|
||||||
|
},
|
||||||
|
{
|
||||||
|
timeout: 10000,
|
||||||
|
headers: {
|
||||||
|
Authorization: `Bearer ${token}`,
|
||||||
|
'Content-Type': 'application/json'
|
||||||
|
}
|
||||||
|
}
|
||||||
|
)
|
||||||
|
|
||||||
|
console.log('List response:', listResponse.data)
|
||||||
|
|
||||||
|
if (listResponse.data.code === 200) {
|
||||||
|
console.log('✓ File listing successful')
|
||||||
|
console.log('Available directories/files:')
|
||||||
|
listResponse.data.data.content.forEach((item) => {
|
||||||
|
console.log(` - ${item.name} (${item.is_dir ? 'directory' : 'file'})`)
|
||||||
|
})
|
||||||
|
}
|
||||||
|
|
||||||
|
// 3. 测试获取特定文件信息(如果存在版本目录)
|
||||||
|
console.log('3. Testing file info retrieval...')
|
||||||
|
try {
|
||||||
|
const fileInfoResponse = await axios.post(
|
||||||
|
`${ALIST_BASE_URL}/api/fs/get`,
|
||||||
|
{
|
||||||
|
path: '/v1.0.0' // 测试版本目录
|
||||||
|
},
|
||||||
|
{
|
||||||
|
timeout: 10000,
|
||||||
|
headers: {
|
||||||
|
Authorization: token,
|
||||||
|
'Content-Type': 'application/json'
|
||||||
|
}
|
||||||
|
}
|
||||||
|
)
|
||||||
|
|
||||||
|
console.log('File info response:', fileInfoResponse.data)
|
||||||
|
|
||||||
|
if (fileInfoResponse.data.code === 200) {
|
||||||
|
console.log('✓ File info retrieval successful')
|
||||||
|
}
|
||||||
|
} catch (error) {
|
||||||
|
console.log(
|
||||||
|
'ℹ Version directory /v1.0.0 not found (this is expected if no updates are available)'
|
||||||
|
)
|
||||||
|
}
|
||||||
|
|
||||||
|
console.log('\n✅ Alist connection test completed successfully!')
|
||||||
|
} catch (error) {
|
||||||
|
console.error('❌ Alist connection test failed:', error.message)
|
||||||
|
|
||||||
|
if (error.response) {
|
||||||
|
console.error('Response status:', error.response.status)
|
||||||
|
console.error('Response data:', error.response.data)
|
||||||
|
} else if (error.request) {
|
||||||
|
console.error('No response received. Check if the Alist server is running and accessible.')
|
||||||
|
}
|
||||||
|
|
||||||
|
process.exit(1)
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
// 运行测试
|
||||||
|
testAlistConnection()
|
||||||
@@ -26,7 +26,7 @@ export function compareVer(currentVer: string, targetVer: string): -1 | 0 | 1 {
|
|||||||
.replace(/[^0-9.]/g, fix)
|
.replace(/[^0-9.]/g, fix)
|
||||||
.split('.')
|
.split('.')
|
||||||
const targetVerArr: Array<string | number> = ('' + targetVer).replace(/[^0-9.]/g, fix).split('.')
|
const targetVerArr: Array<string | number> = ('' + targetVer).replace(/[^0-9.]/g, fix).split('.')
|
||||||
let c = Math.max(currentVerArr.length, targetVerArr.length)
|
const c = Math.max(currentVerArr.length, targetVerArr.length)
|
||||||
for (let i = 0; i < c; i++) {
|
for (let i = 0; i < c; i++) {
|
||||||
// convert to integer the most efficient way
|
// convert to integer the most efficient way
|
||||||
currentVerArr[i] = ~~currentVerArr[i]
|
currentVerArr[i] = ~~currentVerArr[i]
|
||||||
|
|||||||
15
src/common/types/playList.ts
Normal file
@@ -0,0 +1,15 @@
|
|||||||
|
export default interface PlayList {
|
||||||
|
songmid: string | number
|
||||||
|
hash?: string
|
||||||
|
singer: string
|
||||||
|
name: string
|
||||||
|
albumName: string
|
||||||
|
albumId: string | number
|
||||||
|
source: string
|
||||||
|
interval: string
|
||||||
|
img: string
|
||||||
|
lrc: null | string
|
||||||
|
types: string[]
|
||||||
|
_types: Record<string, any>
|
||||||
|
typeUrl: Record<string, any>
|
||||||
|
}
|
||||||
12
src/common/types/songList.ts
Normal file
@@ -0,0 +1,12 @@
|
|||||||
|
import PlayList from './playList'
|
||||||
|
export type Songs = PlayList
|
||||||
|
|
||||||
|
export type SongList = {
|
||||||
|
id: string //hashId 对应歌单文件名.json
|
||||||
|
name: string // 歌单名
|
||||||
|
createTime: string
|
||||||
|
updateTime: string
|
||||||
|
description: string // 歌单描述
|
||||||
|
coverImgUrl: string //歌单封面 默认第一首歌的图片
|
||||||
|
source: 'local' | 'wy' | 'tx' | 'mg' | 'kg' | 'kw' // 来源
|
||||||
|
}
|
||||||
@@ -27,10 +27,10 @@ export const toDateObj = (date: any): Date | '' => {
|
|||||||
switch (typeof date) {
|
switch (typeof date) {
|
||||||
case 'string':
|
case 'string':
|
||||||
if (!date.includes('T')) date = date.split('.')[0].replace(/-/g, '/')
|
if (!date.includes('T')) date = date.split('.')[0].replace(/-/g, '/')
|
||||||
// eslint-disable-next-line no-fallthrough
|
|
||||||
case 'number':
|
case 'number':
|
||||||
date = new Date(date)
|
date = new Date(date)
|
||||||
// eslint-disable-next-line no-fallthrough
|
|
||||||
case 'object':
|
case 'object':
|
||||||
break
|
break
|
||||||
default:
|
default:
|
||||||
|
|||||||
@@ -24,13 +24,13 @@ const headExp = /^.*\[id:\$\w+\]\n/
|
|||||||
const parseLyric = (str) => {
|
const parseLyric = (str) => {
|
||||||
str = str.replace(/\r/g, '')
|
str = str.replace(/\r/g, '')
|
||||||
if (headExp.test(str)) str = str.replace(headExp, '')
|
if (headExp.test(str)) str = str.replace(headExp, '')
|
||||||
let trans = str.match(/\[language:([\w=\\/+]+)\]/)
|
const trans = str.match(/\[language:([\w=\\/+]+)\]/)
|
||||||
let lyric
|
let lyric
|
||||||
let rlyric
|
let rlyric
|
||||||
let tlyric
|
let tlyric
|
||||||
if (trans) {
|
if (trans) {
|
||||||
str = str.replace(/\[language:[\w=\\/+]+\]\n/, '')
|
str = str.replace(/\[language:[\w=\\/+]+\]\n/, '')
|
||||||
let json = JSON.parse(Buffer.from(trans[1], 'base64').toString())
|
const json = JSON.parse(Buffer.from(trans[1], 'base64').toString())
|
||||||
for (const item of json.content) {
|
for (const item of json.content) {
|
||||||
switch (item.type) {
|
switch (item.type) {
|
||||||
case 0:
|
case 0:
|
||||||
@@ -44,23 +44,23 @@ const parseLyric = (str) => {
|
|||||||
}
|
}
|
||||||
let i = 0
|
let i = 0
|
||||||
let crlyric = str.replace(/\[((\d+),\d+)\].*/g, (str) => {
|
let crlyric = str.replace(/\[((\d+),\d+)\].*/g, (str) => {
|
||||||
let result = str.match(/\[((\d+),\d+)\].*/)
|
const result = str.match(/\[((\d+),\d+)\].*/)
|
||||||
let lineStartTime = parseInt(result[2]) // 行开始时间
|
const lineStartTime = parseInt(result[2]) // 行开始时间
|
||||||
let time = lineStartTime
|
let time = lineStartTime
|
||||||
let ms = time % 1000
|
const ms = time % 1000
|
||||||
time /= 1000
|
time /= 1000
|
||||||
let m = parseInt(time / 60)
|
const m = parseInt(time / 60)
|
||||||
.toString()
|
.toString()
|
||||||
.padStart(2, '0')
|
.padStart(2, '0')
|
||||||
time %= 60
|
time %= 60
|
||||||
let s = parseInt(time).toString().padStart(2, '0')
|
const s = parseInt(time).toString().padStart(2, '0')
|
||||||
time = `${m}:${s}.${ms}`
|
time = `${m}:${s}.${ms}`
|
||||||
if (rlyric) rlyric[i] = `[${time}]${rlyric[i]?.join('') ?? ''}`
|
if (rlyric) rlyric[i] = `[${time}]${rlyric[i]?.join('') ?? ''}`
|
||||||
if (tlyric) tlyric[i] = `[${time}]${tlyric[i]?.join('') ?? ''}`
|
if (tlyric) tlyric[i] = `[${time}]${tlyric[i]?.join('') ?? ''}`
|
||||||
i++
|
i++
|
||||||
|
|
||||||
// 保持原始的 [start,duration] 格式,将相对时间戳转换为绝对时间戳
|
// 保持原始的 [start,duration] 格式,将相对时间戳转换为绝对时间戳
|
||||||
let processedStr = str.replace(/<(\d+),(\d+),(\d+)>/g, (match, start, duration, param) => {
|
const processedStr = str.replace(/<(\d+),(\d+),(\d+)>/g, (match, start, duration, param) => {
|
||||||
const absoluteStart = lineStartTime + parseInt(start)
|
const absoluteStart = lineStartTime + parseInt(start)
|
||||||
return `(${absoluteStart},${duration},${param})`
|
return `(${absoluteStart},${duration},${param})`
|
||||||
})
|
})
|
||||||
|
|||||||
@@ -38,7 +38,7 @@ const handleScrollY = (
|
|||||||
// @ts-expect-error
|
// @ts-expect-error
|
||||||
const start = element.scrollTop ?? element.scrollY ?? 0
|
const start = element.scrollTop ?? element.scrollY ?? 0
|
||||||
if (to > start) {
|
if (to > start) {
|
||||||
let maxScrollTop = element.scrollHeight - element.clientHeight
|
const maxScrollTop = element.scrollHeight - element.clientHeight
|
||||||
if (to > maxScrollTop) to = maxScrollTop
|
if (to > maxScrollTop) to = maxScrollTop
|
||||||
} else if (to < start) {
|
} else if (to < start) {
|
||||||
if (to < 0) to = 0
|
if (to < 0) to = 0
|
||||||
@@ -55,7 +55,7 @@ const handleScrollY = (
|
|||||||
|
|
||||||
let currentTime = 0
|
let currentTime = 0
|
||||||
let val: number
|
let val: number
|
||||||
let key = Math.random()
|
const key = Math.random()
|
||||||
|
|
||||||
const animateScroll = () => {
|
const animateScroll = () => {
|
||||||
element.lx_scrollTimeout = undefined
|
element.lx_scrollTimeout = undefined
|
||||||
@@ -156,7 +156,7 @@ const handleScrollX = (
|
|||||||
// @ts-expect-error
|
// @ts-expect-error
|
||||||
const start = element.scrollLeft || element.scrollX || 0
|
const start = element.scrollLeft || element.scrollX || 0
|
||||||
if (to > start) {
|
if (to > start) {
|
||||||
let maxScrollLeft = element.scrollWidth - element.clientWidth
|
const maxScrollLeft = element.scrollWidth - element.clientWidth
|
||||||
if (to > maxScrollLeft) to = maxScrollLeft
|
if (to > maxScrollLeft) to = maxScrollLeft
|
||||||
} else if (to < start) {
|
} else if (to < start) {
|
||||||
if (to < 0) to = 0
|
if (to < 0) to = 0
|
||||||
@@ -173,7 +173,7 @@ const handleScrollX = (
|
|||||||
|
|
||||||
let currentTime = 0
|
let currentTime = 0
|
||||||
let val: number
|
let val: number
|
||||||
let key = Math.random()
|
const key = Math.random()
|
||||||
|
|
||||||
const animateScroll = () => {
|
const animateScroll = () => {
|
||||||
element.lx_scrollTimeout = undefined
|
element.lx_scrollTimeout = undefined
|
||||||
@@ -272,7 +272,7 @@ const handleScrollXR = (
|
|||||||
// @ts-expect-error
|
// @ts-expect-error
|
||||||
const start = element.scrollLeft || (element.scrollX as number) || 0
|
const start = element.scrollLeft || (element.scrollX as number) || 0
|
||||||
if (to < start) {
|
if (to < start) {
|
||||||
let maxScrollLeft = -element.scrollWidth + element.clientWidth
|
const maxScrollLeft = -element.scrollWidth + element.clientWidth
|
||||||
if (to < maxScrollLeft) to = maxScrollLeft
|
if (to < maxScrollLeft) to = maxScrollLeft
|
||||||
} else if (to > start) {
|
} else if (to > start) {
|
||||||
if (to > 0) to = 0
|
if (to > 0) to = 0
|
||||||
@@ -290,7 +290,7 @@ const handleScrollXR = (
|
|||||||
|
|
||||||
let currentTime = 0
|
let currentTime = 0
|
||||||
let val: number
|
let val: number
|
||||||
let key = Math.random()
|
const key = Math.random()
|
||||||
|
|
||||||
const animateScroll = () => {
|
const animateScroll = () => {
|
||||||
element.lx_scrollTimeout = undefined
|
element.lx_scrollTimeout = undefined
|
||||||
@@ -371,7 +371,7 @@ export const scrollXRTo = (
|
|||||||
/**
|
/**
|
||||||
* 设置标题
|
* 设置标题
|
||||||
*/
|
*/
|
||||||
let dom_title = document.getElementsByTagName('title')[0]
|
const dom_title = document.getElementsByTagName('title')[0]
|
||||||
export const setTitle = (title: string | null) => {
|
export const setTitle = (title: string | null) => {
|
||||||
title ||= 'LX Music'
|
title ||= 'LX Music'
|
||||||
dom_title.innerText = title
|
dom_title.innerText = title
|
||||||
|
|||||||
@@ -1,6 +1,6 @@
|
|||||||
// 业务工具方法
|
// 业务工具方法
|
||||||
|
|
||||||
import { LX } from "../../types/global"
|
import { LX } from '../../types/global'
|
||||||
|
|
||||||
export const toNewMusicInfo = (oldMusicInfo: any): LX.Music.MusicInfo => {
|
export const toNewMusicInfo = (oldMusicInfo: any): LX.Music.MusicInfo => {
|
||||||
const meta: Record<string, any> = {
|
const meta: Record<string, any> = {
|
||||||
|
|||||||
@@ -1,54 +1,160 @@
|
|||||||
import { BrowserWindow, app, shell } from 'electron';
|
import { BrowserWindow, app, shell } from 'electron'
|
||||||
import axios from 'axios';
|
import axios from 'axios'
|
||||||
import fs from 'fs';
|
import fs from 'fs'
|
||||||
import path from 'node:path';
|
import path from 'node:path'
|
||||||
|
|
||||||
|
let mainWindow: BrowserWindow | null = null
|
||||||
let mainWindow: BrowserWindow | null = null;
|
let currentUpdateInfo: UpdateInfo | null = null
|
||||||
let currentUpdateInfo: UpdateInfo | null = null;
|
let downloadProgress = { percent: 0, transferred: 0, total: 0 }
|
||||||
let downloadProgress = { percent: 0, transferred: 0, total: 0 };
|
|
||||||
|
|
||||||
// 更新信息接口
|
// 更新信息接口
|
||||||
interface UpdateInfo {
|
interface UpdateInfo {
|
||||||
url: string;
|
url: string
|
||||||
name: string;
|
name: string
|
||||||
notes: string;
|
notes: string
|
||||||
pub_date: string;
|
pub_date: string
|
||||||
}
|
}
|
||||||
|
|
||||||
// 更新服务器配置
|
// 更新服务器配置
|
||||||
const UPDATE_SERVER = 'https://update.ceru.shiqianjiang.cn';
|
const UPDATE_SERVER = 'https://update.ceru.shiqianjiang.cn'
|
||||||
const UPDATE_API_URL = `${UPDATE_SERVER}/update/${process.platform}/${app.getVersion()}`;
|
const UPDATE_API_URL = `${UPDATE_SERVER}/update/${process.platform}/${app.getVersion()}`
|
||||||
|
|
||||||
|
// Alist API 配置
|
||||||
|
const ALIST_BASE_URL = 'https://alist.shiqianjiang.cn' // 请替换为实际的 alist 域名
|
||||||
|
const ALIST_USERNAME = 'ceruupdate'
|
||||||
|
const ALIST_PASSWORD = '123456'
|
||||||
|
|
||||||
|
// Alist 认证 token
|
||||||
|
let alistToken: string | null = null
|
||||||
|
|
||||||
|
// 获取 Alist 认证 token
|
||||||
|
async function getAlistToken(): Promise<string> {
|
||||||
|
if (alistToken) {
|
||||||
|
return alistToken
|
||||||
|
}
|
||||||
|
|
||||||
|
try {
|
||||||
|
console.log('Authenticating with Alist...')
|
||||||
|
const response = await axios.post(
|
||||||
|
`${ALIST_BASE_URL}/api/auth/login`,
|
||||||
|
{
|
||||||
|
username: ALIST_USERNAME,
|
||||||
|
password: ALIST_PASSWORD
|
||||||
|
},
|
||||||
|
{
|
||||||
|
timeout: 10000,
|
||||||
|
headers: {
|
||||||
|
'Content-Type': 'application/json'
|
||||||
|
}
|
||||||
|
}
|
||||||
|
)
|
||||||
|
|
||||||
|
console.log('Alist auth response:', response.data)
|
||||||
|
|
||||||
|
if (response.data.code === 200) {
|
||||||
|
alistToken = response.data.data.token
|
||||||
|
console.log('Alist authentication successful')
|
||||||
|
return alistToken! // 我们已经确认 token 存在
|
||||||
|
} else {
|
||||||
|
throw new Error(`Alist authentication failed: ${response.data.message || 'Unknown error'}`)
|
||||||
|
}
|
||||||
|
} catch (error: any) {
|
||||||
|
console.error('Alist authentication error:', error)
|
||||||
|
if (error.response) {
|
||||||
|
throw new Error(
|
||||||
|
`Failed to authenticate with Alist: HTTP ${error.response.status} - ${error.response.data?.message || error.response.statusText}`
|
||||||
|
)
|
||||||
|
} else {
|
||||||
|
throw new Error(`Failed to authenticate with Alist: ${error.message}`)
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
// 获取 Alist 文件下载链接
|
||||||
|
async function getAlistDownloadUrl(version: string, fileName: string): Promise<string> {
|
||||||
|
const token = await getAlistToken()
|
||||||
|
const filePath = `/${version}/${fileName}`
|
||||||
|
|
||||||
|
try {
|
||||||
|
console.log(`Getting file info for: ${filePath}`)
|
||||||
|
const response = await axios.post(
|
||||||
|
`${ALIST_BASE_URL}/api/fs/get`,
|
||||||
|
{
|
||||||
|
path: filePath
|
||||||
|
},
|
||||||
|
{
|
||||||
|
timeout: 10000,
|
||||||
|
headers: {
|
||||||
|
Authorization: token,
|
||||||
|
'Content-Type': 'application/json'
|
||||||
|
}
|
||||||
|
}
|
||||||
|
)
|
||||||
|
|
||||||
|
console.log('Alist file info response:', response.data)
|
||||||
|
|
||||||
|
if (response.data.code === 200) {
|
||||||
|
const fileInfo = response.data.data
|
||||||
|
|
||||||
|
// 检查文件是否存在且有下载链接
|
||||||
|
if (fileInfo && fileInfo.raw_url) {
|
||||||
|
console.log('Using raw_url for download:', fileInfo.raw_url)
|
||||||
|
return fileInfo.raw_url
|
||||||
|
} else if (fileInfo && fileInfo.sign) {
|
||||||
|
// 使用签名构建下载链接
|
||||||
|
const downloadUrl = `${ALIST_BASE_URL}/d${filePath}?sign=${fileInfo.sign}`
|
||||||
|
console.log('Using signed download URL:', downloadUrl)
|
||||||
|
return downloadUrl
|
||||||
|
} else {
|
||||||
|
// 尝试直接下载链接(无签名)
|
||||||
|
const directUrl = `${ALIST_BASE_URL}/d${filePath}`
|
||||||
|
console.log('Using direct download URL:', directUrl)
|
||||||
|
return directUrl
|
||||||
|
}
|
||||||
|
} else {
|
||||||
|
throw new Error(`Failed to get file info: ${response.data.message || 'Unknown error'}`)
|
||||||
|
}
|
||||||
|
} catch (error: any) {
|
||||||
|
console.error('Alist file info error:', error)
|
||||||
|
if (error.response) {
|
||||||
|
throw new Error(
|
||||||
|
`Failed to get download URL from Alist: HTTP ${error.response.status} - ${error.response.data?.message || error.response.statusText}`
|
||||||
|
)
|
||||||
|
} else {
|
||||||
|
throw new Error(`Failed to get download URL from Alist: ${error.message}`)
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
// 初始化自动更新器
|
// 初始化自动更新器
|
||||||
export function initAutoUpdater(window: BrowserWindow) {
|
export function initAutoUpdater(window: BrowserWindow) {
|
||||||
mainWindow = window;
|
mainWindow = window
|
||||||
console.log('Auto updater initialized');
|
console.log('Auto updater initialized')
|
||||||
}
|
}
|
||||||
|
|
||||||
// 检查更新
|
// 检查更新
|
||||||
export async function checkForUpdates(window?: BrowserWindow) {
|
export async function checkForUpdates(window?: BrowserWindow) {
|
||||||
if (window) {
|
if (window) {
|
||||||
mainWindow = window;
|
mainWindow = window
|
||||||
}
|
}
|
||||||
|
|
||||||
try {
|
try {
|
||||||
console.log('Checking for updates...');
|
console.log('Checking for updates...')
|
||||||
mainWindow?.webContents.send('auto-updater:checking-for-update');
|
mainWindow?.webContents.send('auto-updater:checking-for-update')
|
||||||
|
|
||||||
const updateInfo = await fetchUpdateInfo();
|
const updateInfo = await fetchUpdateInfo()
|
||||||
|
|
||||||
if (updateInfo && isNewerVersion(updateInfo.name, app.getVersion())) {
|
if (updateInfo && isNewerVersion(updateInfo.name, app.getVersion())) {
|
||||||
console.log('Update available:', updateInfo);
|
console.log('Update available:', updateInfo)
|
||||||
currentUpdateInfo = updateInfo;
|
currentUpdateInfo = updateInfo
|
||||||
mainWindow?.webContents.send('auto-updater:update-available', updateInfo);
|
mainWindow?.webContents.send('auto-updater:update-available', updateInfo)
|
||||||
} else {
|
} else {
|
||||||
console.log('No update available');
|
console.log('No update available')
|
||||||
mainWindow?.webContents.send('auto-updater:update-not-available');
|
mainWindow?.webContents.send('auto-updater:update-not-available')
|
||||||
}
|
}
|
||||||
} catch (error) {
|
} catch (error) {
|
||||||
console.error('Error checking for updates:', error);
|
console.error('Error checking for updates:', error)
|
||||||
mainWindow?.webContents.send('auto-updater:error', (error as Error).message);
|
mainWindow?.webContents.send('auto-updater:error', (error as Error).message)
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -58,26 +164,26 @@ async function fetchUpdateInfo(): Promise<UpdateInfo | null> {
|
|||||||
const response = await axios.get(UPDATE_API_URL, {
|
const response = await axios.get(UPDATE_API_URL, {
|
||||||
timeout: 10000, // 10秒超时
|
timeout: 10000, // 10秒超时
|
||||||
validateStatus: (status) => status === 200 || status === 204 // 允许 200 和 204 状态码
|
validateStatus: (status) => status === 200 || status === 204 // 允许 200 和 204 状态码
|
||||||
});
|
})
|
||||||
|
|
||||||
if (response.status === 200) {
|
if (response.status === 200) {
|
||||||
return response.data as UpdateInfo;
|
return response.data as UpdateInfo
|
||||||
} else if (response.status === 204) {
|
} else if (response.status === 204) {
|
||||||
// 204 表示没有更新
|
// 204 表示没有更新
|
||||||
return null;
|
return null
|
||||||
}
|
}
|
||||||
|
|
||||||
return null;
|
return null
|
||||||
} catch (error: any) {
|
} catch (error: any) {
|
||||||
if (error.response) {
|
if (error.response) {
|
||||||
// 服务器响应了错误状态码
|
// 服务器响应了错误状态码
|
||||||
throw new Error(`HTTP ${error.response.status}: ${error.response.statusText}`);
|
throw new Error(`HTTP ${error.response.status}: ${error.response.statusText}`)
|
||||||
} else if (error.request) {
|
} else if (error.request) {
|
||||||
// 请求已发出但没有收到响应
|
// 请求已发出但没有收到响应
|
||||||
throw new Error('Network error: No response received');
|
throw new Error('Network error: No response received')
|
||||||
} else {
|
} else {
|
||||||
// 其他错误
|
// 其他错误
|
||||||
throw new Error(`Request failed: ${error.message}`);
|
throw new Error(`Request failed: ${error.message}`)
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
@@ -85,101 +191,119 @@ async function fetchUpdateInfo(): Promise<UpdateInfo | null> {
|
|||||||
// 比较版本号
|
// 比较版本号
|
||||||
function isNewerVersion(remoteVersion: string, currentVersion: string): boolean {
|
function isNewerVersion(remoteVersion: string, currentVersion: string): boolean {
|
||||||
const parseVersion = (version: string) => {
|
const parseVersion = (version: string) => {
|
||||||
return version.replace(/^v/, '').split('.').map(num => parseInt(num, 10));
|
return version
|
||||||
};
|
.replace(/^v/, '')
|
||||||
|
.split('.')
|
||||||
const remote = parseVersion(remoteVersion);
|
.map((num) => parseInt(num, 10))
|
||||||
const current = parseVersion(currentVersion);
|
|
||||||
|
|
||||||
for (let i = 0; i < Math.max(remote.length, current.length); i++) {
|
|
||||||
const r = remote[i] || 0;
|
|
||||||
const c = current[i] || 0;
|
|
||||||
|
|
||||||
if (r > c) return true;
|
|
||||||
if (r < c) return false;
|
|
||||||
}
|
}
|
||||||
|
|
||||||
return false;
|
const remote = parseVersion(remoteVersion)
|
||||||
|
const current = parseVersion(currentVersion)
|
||||||
|
|
||||||
|
for (let i = 0; i < Math.max(remote.length, current.length); i++) {
|
||||||
|
const r = remote[i] || 0
|
||||||
|
const c = current[i] || 0
|
||||||
|
|
||||||
|
if (r > c) return true
|
||||||
|
if (r < c) return false
|
||||||
|
}
|
||||||
|
|
||||||
|
return false
|
||||||
}
|
}
|
||||||
|
|
||||||
// 下载更新
|
// 下载更新
|
||||||
export async function downloadUpdate() {
|
export async function downloadUpdate() {
|
||||||
if (!currentUpdateInfo) {
|
if (!currentUpdateInfo) {
|
||||||
throw new Error('No update info available');
|
throw new Error('No update info available')
|
||||||
}
|
}
|
||||||
|
|
||||||
try {
|
try {
|
||||||
console.log('Starting download:', currentUpdateInfo.url);
|
console.log('Starting download:', currentUpdateInfo.url)
|
||||||
|
|
||||||
// 通知渲染进程开始下载
|
// 通知渲染进程开始下载
|
||||||
mainWindow?.webContents.send('auto-updater:download-started', currentUpdateInfo);
|
mainWindow?.webContents.send('auto-updater:download-started', currentUpdateInfo)
|
||||||
|
|
||||||
const downloadPath = await downloadFile(currentUpdateInfo.url);
|
const downloadPath = await downloadFile(currentUpdateInfo.url)
|
||||||
console.log('Download completed:', downloadPath);
|
console.log('Download completed:', downloadPath)
|
||||||
|
|
||||||
mainWindow?.webContents.send('auto-updater:update-downloaded', {
|
mainWindow?.webContents.send('auto-updater:update-downloaded', {
|
||||||
downloadPath,
|
downloadPath,
|
||||||
updateInfo: currentUpdateInfo
|
updateInfo: currentUpdateInfo
|
||||||
});
|
})
|
||||||
} catch (error) {
|
} catch (error) {
|
||||||
console.error('Download failed:', error);
|
console.error('Download failed:', error)
|
||||||
mainWindow?.webContents.send('auto-updater:error', (error as Error).message);
|
mainWindow?.webContents.send('auto-updater:error', (error as Error).message)
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
// 下载文件
|
// 下载文件
|
||||||
async function downloadFile(url: string): Promise<string> {
|
async function downloadFile(originalUrl: string): Promise<string> {
|
||||||
const fileName = path.basename(url);
|
const fileName = path.basename(originalUrl)
|
||||||
const downloadPath = path.join(app.getPath('temp'), fileName);
|
const downloadPath = path.join(app.getPath('temp'), fileName)
|
||||||
|
|
||||||
// 进度节流变量
|
// 进度节流变量
|
||||||
let lastProgressSent = 0;
|
let lastProgressSent = 0
|
||||||
let lastProgressTime = 0;
|
let lastProgressTime = 0
|
||||||
const PROGRESS_THROTTLE_INTERVAL = 500; // 500ms 发送一次进度
|
const PROGRESS_THROTTLE_INTERVAL = 500 // 500ms 发送一次进度
|
||||||
const PROGRESS_THRESHOLD = 1; // 进度变化超过1%才发送
|
const PROGRESS_THRESHOLD = 1 // 进度变化超过1%才发送
|
||||||
|
|
||||||
try {
|
try {
|
||||||
|
let downloadUrl = originalUrl
|
||||||
|
|
||||||
|
try {
|
||||||
|
// 从当前更新信息中提取版本号
|
||||||
|
const version = currentUpdateInfo?.name || app.getVersion()
|
||||||
|
|
||||||
|
// 尝试使用 alist API 获取下载链接
|
||||||
|
downloadUrl = await getAlistDownloadUrl(version, fileName)
|
||||||
|
console.log('Using Alist download URL:', downloadUrl)
|
||||||
|
} catch (alistError) {
|
||||||
|
console.warn('Alist download failed, falling back to original URL:', alistError)
|
||||||
|
console.log('Using original download URL:', originalUrl)
|
||||||
|
downloadUrl = originalUrl
|
||||||
|
}
|
||||||
|
|
||||||
const response = await axios({
|
const response = await axios({
|
||||||
method: 'GET',
|
method: 'GET',
|
||||||
url: url,
|
url: downloadUrl,
|
||||||
responseType: 'stream',
|
responseType: 'stream',
|
||||||
timeout: 30000, // 30秒超时
|
timeout: 30000, // 30秒超时
|
||||||
onDownloadProgress: (progressEvent) => {
|
onDownloadProgress: (progressEvent) => {
|
||||||
const { loaded, total } = progressEvent;
|
const { loaded, total } = progressEvent
|
||||||
const percent = total ? (loaded / total) * 100 : 0;
|
const percent = total ? (loaded / total) * 100 : 0
|
||||||
const currentTime = Date.now();
|
const currentTime = Date.now()
|
||||||
|
|
||||||
// 节流逻辑:只在进度变化显著或时间间隔足够时发送
|
// 节流逻辑:只在进度变化显著或时间间隔足够时发送
|
||||||
const progressDiff = Math.abs(percent - lastProgressSent);
|
const progressDiff = Math.abs(percent - lastProgressSent)
|
||||||
const timeDiff = currentTime - lastProgressTime;
|
const timeDiff = currentTime - lastProgressTime
|
||||||
|
|
||||||
if (progressDiff >= PROGRESS_THRESHOLD || timeDiff >= PROGRESS_THROTTLE_INTERVAL) {
|
if (progressDiff >= PROGRESS_THRESHOLD || timeDiff >= PROGRESS_THROTTLE_INTERVAL) {
|
||||||
downloadProgress = {
|
downloadProgress = {
|
||||||
percent,
|
percent,
|
||||||
transferred: loaded,
|
transferred: loaded,
|
||||||
total: total || 0
|
total: total || 0
|
||||||
};
|
}
|
||||||
|
|
||||||
mainWindow?.webContents.send('auto-updater:download-progress', downloadProgress);
|
mainWindow?.webContents.send('auto-updater:download-progress', downloadProgress)
|
||||||
lastProgressSent = percent;
|
lastProgressSent = percent
|
||||||
lastProgressTime = currentTime;
|
lastProgressTime = currentTime
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
});
|
})
|
||||||
|
|
||||||
// 发送初始进度
|
// 发送初始进度
|
||||||
const totalSize = parseInt(response.headers['content-length'] || '0', 10);
|
const totalSize = parseInt(response.headers['content-length'] || '0', 10)
|
||||||
mainWindow?.webContents.send('auto-updater:download-progress', {
|
mainWindow?.webContents.send('auto-updater:download-progress', {
|
||||||
percent: 0,
|
percent: 0,
|
||||||
transferred: 0,
|
transferred: 0,
|
||||||
total: totalSize
|
total: totalSize
|
||||||
});
|
})
|
||||||
|
|
||||||
// 创建写入流
|
// 创建写入流
|
||||||
const writer = fs.createWriteStream(downloadPath);
|
const writer = fs.createWriteStream(downloadPath)
|
||||||
|
|
||||||
// 将响应数据流写入文件
|
// 将响应数据流写入文件
|
||||||
response.data.pipe(writer);
|
response.data.pipe(writer)
|
||||||
|
|
||||||
return new Promise((resolve, reject) => {
|
return new Promise((resolve, reject) => {
|
||||||
writer.on('finish', () => {
|
writer.on('finish', () => {
|
||||||
@@ -188,37 +312,36 @@ async function downloadFile(url: string): Promise<string> {
|
|||||||
percent: 100,
|
percent: 100,
|
||||||
transferred: totalSize,
|
transferred: totalSize,
|
||||||
total: totalSize
|
total: totalSize
|
||||||
});
|
})
|
||||||
|
|
||||||
console.log('File download completed:', downloadPath);
|
console.log('File download completed:', downloadPath)
|
||||||
resolve(downloadPath);
|
resolve(downloadPath)
|
||||||
});
|
})
|
||||||
|
|
||||||
writer.on('error', (error) => {
|
writer.on('error', (error) => {
|
||||||
// 删除部分下载的文件
|
// 删除部分下载的文件
|
||||||
fs.unlink(downloadPath, () => {});
|
fs.unlink(downloadPath, () => {})
|
||||||
reject(error);
|
reject(error)
|
||||||
});
|
})
|
||||||
|
|
||||||
response.data.on('error', (error: Error) => {
|
response.data.on('error', (error: Error) => {
|
||||||
writer.destroy();
|
writer.destroy()
|
||||||
fs.unlink(downloadPath, () => {});
|
fs.unlink(downloadPath, () => {})
|
||||||
reject(error);
|
reject(error)
|
||||||
});
|
})
|
||||||
});
|
})
|
||||||
|
|
||||||
} catch (error: any) {
|
} catch (error: any) {
|
||||||
// 删除可能创建的文件
|
// 删除可能创建的文件
|
||||||
if (fs.existsSync(downloadPath)) {
|
if (fs.existsSync(downloadPath)) {
|
||||||
fs.unlink(downloadPath, () => {});
|
fs.unlink(downloadPath, () => {})
|
||||||
}
|
}
|
||||||
|
|
||||||
if (error.response) {
|
if (error.response) {
|
||||||
throw new Error(`Download failed: HTTP ${error.response.status} ${error.response.statusText}`);
|
throw new Error(`Download failed: HTTP ${error.response.status} ${error.response.statusText}`)
|
||||||
} else if (error.request) {
|
} else if (error.request) {
|
||||||
throw new Error('Download failed: Network error');
|
throw new Error('Download failed: Network error')
|
||||||
} else {
|
} else {
|
||||||
throw new Error(`Download failed: ${error.message}`);
|
throw new Error(`Download failed: ${error.message}`)
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
@@ -226,37 +349,37 @@ async function downloadFile(url: string): Promise<string> {
|
|||||||
// 退出并安装
|
// 退出并安装
|
||||||
export function quitAndInstall() {
|
export function quitAndInstall() {
|
||||||
if (!currentUpdateInfo) {
|
if (!currentUpdateInfo) {
|
||||||
console.error('No update info available for installation');
|
console.error('No update info available for installation')
|
||||||
return;
|
return
|
||||||
}
|
}
|
||||||
|
|
||||||
// 对于不同平台,处理方式不同
|
// 对于不同平台,处理方式不同
|
||||||
if (process.platform === 'win32') {
|
if (process.platform === 'win32') {
|
||||||
// Windows: 打开安装程序
|
// Windows: 打开安装程序
|
||||||
const fileName = path.basename(currentUpdateInfo.url);
|
const fileName = path.basename(currentUpdateInfo.url)
|
||||||
const downloadPath = path.join(app.getPath('temp'), fileName);
|
const downloadPath = path.join(app.getPath('temp'), fileName)
|
||||||
|
|
||||||
if (fs.existsSync(downloadPath)) {
|
if (fs.existsSync(downloadPath)) {
|
||||||
shell.openPath(downloadPath).then(() => {
|
shell.openPath(downloadPath).then(() => {
|
||||||
app.quit();
|
app.quit()
|
||||||
});
|
})
|
||||||
} else {
|
} else {
|
||||||
console.error('Downloaded file not found:', downloadPath);
|
console.error('Downloaded file not found:', downloadPath)
|
||||||
}
|
}
|
||||||
} else if (process.platform === 'darwin') {
|
} else if (process.platform === 'darwin') {
|
||||||
// macOS: 打开 dmg 或 zip 文件
|
// macOS: 打开 dmg 或 zip 文件
|
||||||
const fileName = path.basename(currentUpdateInfo.url);
|
const fileName = path.basename(currentUpdateInfo.url)
|
||||||
const downloadPath = path.join(app.getPath('temp'), fileName);
|
const downloadPath = path.join(app.getPath('temp'), fileName)
|
||||||
|
|
||||||
if (fs.existsSync(downloadPath)) {
|
if (fs.existsSync(downloadPath)) {
|
||||||
shell.openPath(downloadPath).then(() => {
|
shell.openPath(downloadPath).then(() => {
|
||||||
app.quit();
|
app.quit()
|
||||||
});
|
})
|
||||||
} else {
|
} else {
|
||||||
console.error('Downloaded file not found:', downloadPath);
|
console.error('Downloaded file not found:', downloadPath)
|
||||||
}
|
}
|
||||||
} else {
|
} else {
|
||||||
// Linux: 打开下载文件夹
|
// Linux: 打开下载文件夹
|
||||||
shell.showItemInFolder(path.join(app.getPath('temp'), path.basename(currentUpdateInfo.url)));
|
shell.showItemInFolder(path.join(app.getPath('temp'), path.basename(currentUpdateInfo.url)))
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -1,28 +1,28 @@
|
|||||||
import { ipcMain, BrowserWindow } from 'electron';
|
import { ipcMain, BrowserWindow } from 'electron'
|
||||||
import { initAutoUpdater, checkForUpdates, downloadUpdate, quitAndInstall } from '../autoUpdate';
|
import { initAutoUpdater, checkForUpdates, downloadUpdate, quitAndInstall } from '../autoUpdate'
|
||||||
|
|
||||||
// 注册自动更新相关的IPC事件
|
// 注册自动更新相关的IPC事件
|
||||||
export function registerAutoUpdateEvents() {
|
export function registerAutoUpdateEvents() {
|
||||||
// 检查更新
|
// 检查更新
|
||||||
ipcMain.handle('auto-updater:check-for-updates', (event) => {
|
ipcMain.handle('auto-updater:check-for-updates', (event) => {
|
||||||
const window = BrowserWindow.fromWebContents(event.sender);
|
const window = BrowserWindow.fromWebContents(event.sender)
|
||||||
if (window) {
|
if (window) {
|
||||||
checkForUpdates(window);
|
checkForUpdates(window)
|
||||||
}
|
}
|
||||||
});
|
})
|
||||||
|
|
||||||
// 下载更新
|
// 下载更新
|
||||||
ipcMain.handle('auto-updater:download-update', () => {
|
ipcMain.handle('auto-updater:download-update', () => {
|
||||||
downloadUpdate();
|
downloadUpdate()
|
||||||
});
|
})
|
||||||
|
|
||||||
// 安装更新
|
// 安装更新
|
||||||
ipcMain.handle('auto-updater:quit-and-install', () => {
|
ipcMain.handle('auto-updater:quit-and-install', () => {
|
||||||
quitAndInstall();
|
quitAndInstall()
|
||||||
});
|
})
|
||||||
}
|
}
|
||||||
|
|
||||||
// 初始化自动更新(在主窗口创建后调用)
|
// 初始化自动更新(在主窗口创建后调用)
|
||||||
export function initAutoUpdateForWindow(window: BrowserWindow) {
|
export function initAutoUpdateForWindow(window: BrowserWindow) {
|
||||||
initAutoUpdater(window);
|
initAutoUpdater(window)
|
||||||
}
|
}
|
||||||
206
src/main/events/directorySettings.ts
Normal file
@@ -0,0 +1,206 @@
|
|||||||
|
import { ipcMain, dialog, app } from 'electron'
|
||||||
|
import { join } from 'path'
|
||||||
|
import fs from 'fs'
|
||||||
|
import { promisify } from 'util'
|
||||||
|
|
||||||
|
const mkdir = promisify(fs.mkdir)
|
||||||
|
const access = promisify(fs.access)
|
||||||
|
|
||||||
|
export const CONFIG_NAME = 'sqj_config.json'
|
||||||
|
|
||||||
|
// 默认目录配置
|
||||||
|
const getDefaultDirectories = () => {
|
||||||
|
const userDataPath = app.getPath('userData')
|
||||||
|
return {
|
||||||
|
cacheDir: join(userDataPath, 'music-cache'),
|
||||||
|
downloadDir: join(app.getPath('music'), 'CeruMusic/songs')
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
// 确保目录存在
|
||||||
|
const ensureDirectoryExists = async (dirPath: string) => {
|
||||||
|
try {
|
||||||
|
await access(dirPath)
|
||||||
|
} catch {
|
||||||
|
await mkdir(dirPath, { recursive: true })
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
// 获取当前目录配置
|
||||||
|
ipcMain.handle('directory-settings:get-directories', async () => {
|
||||||
|
try {
|
||||||
|
const defaults = getDefaultDirectories()
|
||||||
|
|
||||||
|
// 从配置文件读取用户设置的目录
|
||||||
|
const configPath = join(app.getPath('userData'), CONFIG_NAME)
|
||||||
|
let userConfig: any = {}
|
||||||
|
|
||||||
|
try {
|
||||||
|
const configData = fs.readFileSync(configPath, 'utf-8')
|
||||||
|
userConfig = JSON.parse(configData)
|
||||||
|
} catch {
|
||||||
|
// 配置文件不存在或读取失败,使用默认配置
|
||||||
|
}
|
||||||
|
|
||||||
|
const directories = {
|
||||||
|
cacheDir: userConfig.cacheDir || defaults.cacheDir,
|
||||||
|
downloadDir: userConfig.downloadDir || defaults.downloadDir
|
||||||
|
}
|
||||||
|
|
||||||
|
// 确保目录存在
|
||||||
|
await ensureDirectoryExists(directories.cacheDir)
|
||||||
|
await ensureDirectoryExists(directories.downloadDir)
|
||||||
|
|
||||||
|
return directories
|
||||||
|
} catch (error) {
|
||||||
|
console.error('获取目录配置失败:', error)
|
||||||
|
const defaults = getDefaultDirectories()
|
||||||
|
return defaults
|
||||||
|
}
|
||||||
|
})
|
||||||
|
|
||||||
|
// 选择缓存目录
|
||||||
|
ipcMain.handle('directory-settings:select-cache-dir', async () => {
|
||||||
|
try {
|
||||||
|
const result = await dialog.showOpenDialog({
|
||||||
|
title: '选择缓存目录',
|
||||||
|
properties: ['openDirectory', 'createDirectory'],
|
||||||
|
buttonLabel: '选择目录'
|
||||||
|
})
|
||||||
|
|
||||||
|
if (!result.canceled && result.filePaths.length > 0) {
|
||||||
|
const selectedPath = result.filePaths[0]
|
||||||
|
await ensureDirectoryExists(selectedPath)
|
||||||
|
return { success: true, path: selectedPath }
|
||||||
|
}
|
||||||
|
|
||||||
|
return { success: false, message: '用户取消选择' }
|
||||||
|
} catch (error) {
|
||||||
|
console.error('选择缓存目录失败:', error)
|
||||||
|
return { success: false, message: '选择目录失败' }
|
||||||
|
}
|
||||||
|
})
|
||||||
|
|
||||||
|
// 选择下载目录
|
||||||
|
ipcMain.handle('directory-settings:select-download-dir', async () => {
|
||||||
|
try {
|
||||||
|
const result = await dialog.showOpenDialog({
|
||||||
|
title: '选择下载目录',
|
||||||
|
properties: ['openDirectory', 'createDirectory'],
|
||||||
|
buttonLabel: '选择目录'
|
||||||
|
})
|
||||||
|
|
||||||
|
if (!result.canceled && result.filePaths.length > 0) {
|
||||||
|
const selectedPath = result.filePaths[0]
|
||||||
|
await ensureDirectoryExists(selectedPath)
|
||||||
|
return { success: true, path: selectedPath }
|
||||||
|
}
|
||||||
|
|
||||||
|
return { success: false, message: '用户取消选择' }
|
||||||
|
} catch (error) {
|
||||||
|
console.error('选择下载目录失败:', error)
|
||||||
|
return { success: false, message: '选择目录失败' }
|
||||||
|
}
|
||||||
|
})
|
||||||
|
|
||||||
|
// 保存目录配置
|
||||||
|
ipcMain.handle('directory-settings:save-directories', async (_, directories) => {
|
||||||
|
try {
|
||||||
|
const configPath = join(app.getPath('userData'), CONFIG_NAME)
|
||||||
|
|
||||||
|
// 确保目录存在
|
||||||
|
await ensureDirectoryExists(directories.cacheDir)
|
||||||
|
await ensureDirectoryExists(directories.downloadDir)
|
||||||
|
|
||||||
|
// 保存配置
|
||||||
|
fs.writeFileSync(configPath, JSON.stringify(directories, null, 2))
|
||||||
|
|
||||||
|
return { success: true, message: '目录配置已保存' }
|
||||||
|
} catch (error) {
|
||||||
|
console.error('保存目录配置失败:', error)
|
||||||
|
return { success: false, message: '保存配置失败' }
|
||||||
|
}
|
||||||
|
})
|
||||||
|
|
||||||
|
// 重置为默认目录
|
||||||
|
ipcMain.handle('directory-settings:reset-directories', async () => {
|
||||||
|
try {
|
||||||
|
const defaults = getDefaultDirectories()
|
||||||
|
const configPath = join(app.getPath('userData'), CONFIG_NAME)
|
||||||
|
|
||||||
|
// 删除配置文件
|
||||||
|
try {
|
||||||
|
fs.unlinkSync(configPath)
|
||||||
|
} catch {
|
||||||
|
// 文件不存在,忽略错误
|
||||||
|
}
|
||||||
|
|
||||||
|
// 确保默认目录存在
|
||||||
|
await ensureDirectoryExists(defaults.cacheDir)
|
||||||
|
await ensureDirectoryExists(defaults.downloadDir)
|
||||||
|
|
||||||
|
return { success: true, directories: defaults }
|
||||||
|
} catch (error) {
|
||||||
|
console.error('重置目录配置失败:', error)
|
||||||
|
return { success: false, message: '重置配置失败' }
|
||||||
|
}
|
||||||
|
})
|
||||||
|
|
||||||
|
// 打开目录
|
||||||
|
ipcMain.handle('directory-settings:open-directory', async (_, dirPath) => {
|
||||||
|
try {
|
||||||
|
const { shell } = require('electron')
|
||||||
|
await shell.openPath(dirPath)
|
||||||
|
return { success: true }
|
||||||
|
} catch (error) {
|
||||||
|
console.error('打开目录失败:', error)
|
||||||
|
return { success: false, message: '打开目录失败' }
|
||||||
|
}
|
||||||
|
})
|
||||||
|
|
||||||
|
// 获取目录大小
|
||||||
|
ipcMain.handle('directory-settings:get-directory-size', async (_, dirPath) => {
|
||||||
|
try {
|
||||||
|
const getDirectorySize = (dirPath: string): number => {
|
||||||
|
let totalSize = 0
|
||||||
|
|
||||||
|
try {
|
||||||
|
const items = fs.readdirSync(dirPath)
|
||||||
|
|
||||||
|
for (const item of items) {
|
||||||
|
const itemPath = join(dirPath, item)
|
||||||
|
const stats = fs.statSync(itemPath)
|
||||||
|
|
||||||
|
if (stats.isDirectory()) {
|
||||||
|
totalSize += getDirectorySize(itemPath)
|
||||||
|
} else {
|
||||||
|
totalSize += stats.size
|
||||||
|
}
|
||||||
|
}
|
||||||
|
} catch {
|
||||||
|
// 忽略无法访问的文件/目录
|
||||||
|
}
|
||||||
|
|
||||||
|
return totalSize
|
||||||
|
}
|
||||||
|
|
||||||
|
const size = getDirectorySize(dirPath)
|
||||||
|
|
||||||
|
// 格式化大小
|
||||||
|
const formatSize = (bytes: number): string => {
|
||||||
|
if (bytes === 0) return '0 B'
|
||||||
|
const k = 1024
|
||||||
|
const sizes = ['B', 'KB', 'MB', 'GB', 'TB']
|
||||||
|
const i = Math.floor(Math.log(bytes) / Math.log(k))
|
||||||
|
return parseFloat((bytes / Math.pow(k, i)).toFixed(2)) + ' ' + sizes[i]
|
||||||
|
}
|
||||||
|
|
||||||
|
return {
|
||||||
|
size,
|
||||||
|
formatted: formatSize(size)
|
||||||
|
}
|
||||||
|
} catch (error) {
|
||||||
|
console.error('获取目录大小失败:', error)
|
||||||
|
return { size: 0, formatted: '0 B' }
|
||||||
|
}
|
||||||
|
})
|
||||||
@@ -14,18 +14,21 @@ ipcMain.handle('music-cache:get-info', async () => {
|
|||||||
// 清空缓存
|
// 清空缓存
|
||||||
ipcMain.handle('music-cache:clear', async () => {
|
ipcMain.handle('music-cache:clear', async () => {
|
||||||
try {
|
try {
|
||||||
|
console.log('收到清空缓存请求')
|
||||||
await musicCacheService.clearCache()
|
await musicCacheService.clearCache()
|
||||||
|
console.log('缓存清空完成')
|
||||||
return { success: true, message: '缓存已清空' }
|
return { success: true, message: '缓存已清空' }
|
||||||
} catch (error) {
|
} catch (error: any) {
|
||||||
console.error('清空缓存失败:', error)
|
console.error('清空缓存失败:', error)
|
||||||
return { success: false, message: '清空缓存失败' }
|
return { success: false, message: `清空缓存失败: ${error.message}` }
|
||||||
}
|
}
|
||||||
})
|
})
|
||||||
|
|
||||||
// 获取缓存大小
|
// 获取缓存大小
|
||||||
ipcMain.handle('music-cache:get-size', async () => {
|
ipcMain.handle('music-cache:get-size', async () => {
|
||||||
try {
|
try {
|
||||||
return await musicCacheService.getCacheSize()
|
const info = await musicCacheService.getCacheInfo()
|
||||||
|
return info.size
|
||||||
} catch (error) {
|
} catch (error) {
|
||||||
console.error('获取缓存大小失败:', error)
|
console.error('获取缓存大小失败:', error)
|
||||||
return 0
|
return 0
|
||||||
|
|||||||
361
src/main/events/songList.ts
Normal file
@@ -0,0 +1,361 @@
|
|||||||
|
import { ipcMain } from 'electron'
|
||||||
|
import ManageSongList, { SongListError } from '../services/songList/ManageSongList'
|
||||||
|
import type { SongList, Songs } from '@common/types/songList'
|
||||||
|
|
||||||
|
// 创建新歌单
|
||||||
|
ipcMain.handle(
|
||||||
|
'songlist:create',
|
||||||
|
async (_, name: string, description: string = '', source: SongList['source']) => {
|
||||||
|
try {
|
||||||
|
const result = ManageSongList.createPlaylist(name, description, source)
|
||||||
|
return { success: true, data: result, message: '歌单创建成功' }
|
||||||
|
} catch (error) {
|
||||||
|
console.error('创建歌单失败:', error)
|
||||||
|
const message = error instanceof SongListError ? error.message : '创建歌单失败'
|
||||||
|
return {
|
||||||
|
success: false,
|
||||||
|
error: message,
|
||||||
|
code: error instanceof SongListError ? error.code : 'UNKNOWN_ERROR'
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
)
|
||||||
|
|
||||||
|
// 获取所有歌单
|
||||||
|
ipcMain.handle('songlist:get-all', async () => {
|
||||||
|
try {
|
||||||
|
const songLists = ManageSongList.Read()
|
||||||
|
return { success: true, data: songLists }
|
||||||
|
} catch (error) {
|
||||||
|
console.error('获取歌单列表失败:', error)
|
||||||
|
const message = error instanceof SongListError ? error.message : '获取歌单列表失败'
|
||||||
|
return {
|
||||||
|
success: false,
|
||||||
|
error: message,
|
||||||
|
code: error instanceof SongListError ? error.code : 'UNKNOWN_ERROR'
|
||||||
|
}
|
||||||
|
}
|
||||||
|
})
|
||||||
|
|
||||||
|
// 根据ID获取歌单信息
|
||||||
|
ipcMain.handle('songlist:get-by-id', async (_, hashId: string) => {
|
||||||
|
try {
|
||||||
|
const songList = ManageSongList.getById(hashId)
|
||||||
|
return { success: true, data: songList }
|
||||||
|
} catch (error) {
|
||||||
|
console.error('获取歌单信息失败:', error)
|
||||||
|
return { success: false, error: '获取歌单信息失败' }
|
||||||
|
}
|
||||||
|
})
|
||||||
|
|
||||||
|
// 删除歌单
|
||||||
|
ipcMain.handle('songlist:delete', async (_, hashId: string) => {
|
||||||
|
try {
|
||||||
|
ManageSongList.deleteById(hashId)
|
||||||
|
return { success: true, message: '歌单删除成功' }
|
||||||
|
} catch (error) {
|
||||||
|
console.error('删除歌单失败:', error)
|
||||||
|
const message = error instanceof SongListError ? error.message : '删除歌单失败'
|
||||||
|
return {
|
||||||
|
success: false,
|
||||||
|
error: message,
|
||||||
|
code: error instanceof SongListError ? error.code : 'UNKNOWN_ERROR'
|
||||||
|
}
|
||||||
|
}
|
||||||
|
})
|
||||||
|
|
||||||
|
// 批量删除歌单
|
||||||
|
ipcMain.handle('songlist:batch-delete', async (_, hashIds: string[]) => {
|
||||||
|
try {
|
||||||
|
const result = ManageSongList.batchDelete(hashIds)
|
||||||
|
return {
|
||||||
|
success: true,
|
||||||
|
data: result,
|
||||||
|
message: `成功删除 ${result.success.length} 个歌单,失败 ${result.failed.length} 个`
|
||||||
|
}
|
||||||
|
} catch (error) {
|
||||||
|
console.error('批量删除歌单失败:', error)
|
||||||
|
return { success: false, error: '批量删除歌单失败' }
|
||||||
|
}
|
||||||
|
})
|
||||||
|
|
||||||
|
// 编辑歌单信息
|
||||||
|
ipcMain.handle(
|
||||||
|
'songlist:edit',
|
||||||
|
async (_, hashId: string, updates: Partial<Omit<SongList, 'id' | 'createTime'>>) => {
|
||||||
|
try {
|
||||||
|
ManageSongList.editById(hashId, updates)
|
||||||
|
return { success: true, message: '歌单信息更新成功' }
|
||||||
|
} catch (error) {
|
||||||
|
console.error('编辑歌单失败:', error)
|
||||||
|
const message = error instanceof SongListError ? error.message : '编辑歌单失败'
|
||||||
|
return {
|
||||||
|
success: false,
|
||||||
|
error: message,
|
||||||
|
code: error instanceof SongListError ? error.code : 'UNKNOWN_ERROR'
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
)
|
||||||
|
|
||||||
|
// 更新歌单封面
|
||||||
|
ipcMain.handle('songlist:update-cover', async (_, hashId: string, coverImgUrl: string) => {
|
||||||
|
try {
|
||||||
|
ManageSongList.updateCoverImgById(hashId, coverImgUrl)
|
||||||
|
return { success: true, message: '封面更新成功' }
|
||||||
|
} catch (error) {
|
||||||
|
console.error('更新封面失败:', error)
|
||||||
|
const message = error instanceof SongListError ? error.message : '更新封面失败'
|
||||||
|
return {
|
||||||
|
success: false,
|
||||||
|
error: message,
|
||||||
|
code: error instanceof SongListError ? error.code : 'UNKNOWN_ERROR'
|
||||||
|
}
|
||||||
|
}
|
||||||
|
})
|
||||||
|
|
||||||
|
// 搜索歌单
|
||||||
|
ipcMain.handle('songlist:search', async (_, keyword: string, source?: SongList['source']) => {
|
||||||
|
try {
|
||||||
|
const results = ManageSongList.search(keyword, source)
|
||||||
|
return { success: true, data: results }
|
||||||
|
} catch (error) {
|
||||||
|
console.error('搜索歌单失败:', error)
|
||||||
|
return { success: false, error: '搜索歌单失败', data: [] }
|
||||||
|
}
|
||||||
|
})
|
||||||
|
|
||||||
|
// 获取歌单统计信息
|
||||||
|
ipcMain.handle('songlist:get-statistics', async () => {
|
||||||
|
try {
|
||||||
|
const statistics = ManageSongList.getStatistics()
|
||||||
|
return { success: true, data: statistics }
|
||||||
|
} catch (error) {
|
||||||
|
console.error('获取统计信息失败:', error)
|
||||||
|
return { success: false, error: '获取统计信息失败' }
|
||||||
|
}
|
||||||
|
})
|
||||||
|
|
||||||
|
// 检查歌单是否存在
|
||||||
|
ipcMain.handle('songlist:exists', async (_, hashId: string) => {
|
||||||
|
try {
|
||||||
|
const exists = ManageSongList.exists(hashId)
|
||||||
|
return { success: true, data: exists }
|
||||||
|
} catch (error) {
|
||||||
|
console.error('检查歌单存在性失败:', error)
|
||||||
|
return { success: false, error: '检查歌单存在性失败', data: false }
|
||||||
|
}
|
||||||
|
})
|
||||||
|
|
||||||
|
// === 歌曲管理相关 IPC 事件 ===
|
||||||
|
|
||||||
|
// 添加歌曲到歌单
|
||||||
|
ipcMain.handle('songlist:add-songs', async (_, hashId: string, songs: Songs[]) => {
|
||||||
|
try {
|
||||||
|
const instance = new ManageSongList(hashId)
|
||||||
|
instance.addSongs(songs)
|
||||||
|
return { success: true, message: `成功添加 ${songs.length} 首歌曲` }
|
||||||
|
} catch (error) {
|
||||||
|
console.error('添加歌曲失败:', error)
|
||||||
|
const message = error instanceof SongListError ? error.message : '添加歌曲失败'
|
||||||
|
return {
|
||||||
|
success: false,
|
||||||
|
error: message,
|
||||||
|
code: error instanceof SongListError ? error.code : 'UNKNOWN_ERROR'
|
||||||
|
}
|
||||||
|
}
|
||||||
|
})
|
||||||
|
|
||||||
|
// 从歌单移除歌曲
|
||||||
|
ipcMain.handle('songlist:remove-song', async (_, hashId: string, songmid: string | number) => {
|
||||||
|
try {
|
||||||
|
const instance = new ManageSongList(hashId)
|
||||||
|
const removed = instance.removeSong(songmid)
|
||||||
|
return {
|
||||||
|
success: true,
|
||||||
|
data: removed,
|
||||||
|
message: removed ? '歌曲移除成功' : '歌曲不存在'
|
||||||
|
}
|
||||||
|
} catch (error) {
|
||||||
|
console.error('移除歌曲失败:', error)
|
||||||
|
const message = error instanceof SongListError ? error.message : '移除歌曲失败'
|
||||||
|
return {
|
||||||
|
success: false,
|
||||||
|
error: message,
|
||||||
|
code: error instanceof SongListError ? error.code : 'UNKNOWN_ERROR'
|
||||||
|
}
|
||||||
|
}
|
||||||
|
})
|
||||||
|
|
||||||
|
// 批量移除歌曲
|
||||||
|
ipcMain.handle(
|
||||||
|
'songlist:remove-songs',
|
||||||
|
async (_, hashId: string, songmids: (string | number)[]) => {
|
||||||
|
try {
|
||||||
|
const instance = new ManageSongList(hashId)
|
||||||
|
const result = instance.removeSongs(songmids)
|
||||||
|
return {
|
||||||
|
success: true,
|
||||||
|
data: result,
|
||||||
|
message: `成功移除 ${result.removed} 首歌曲,${result.notFound} 首未找到`
|
||||||
|
}
|
||||||
|
} catch (error) {
|
||||||
|
console.error('批量移除歌曲失败:', error)
|
||||||
|
const message = error instanceof SongListError ? error.message : '批量移除歌曲失败'
|
||||||
|
return {
|
||||||
|
success: false,
|
||||||
|
error: message,
|
||||||
|
code: error instanceof SongListError ? error.code : 'UNKNOWN_ERROR'
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
)
|
||||||
|
|
||||||
|
// 清空歌单
|
||||||
|
ipcMain.handle('songlist:clear-songs', async (_, hashId: string) => {
|
||||||
|
try {
|
||||||
|
const instance = new ManageSongList(hashId)
|
||||||
|
instance.clearSongs()
|
||||||
|
return { success: true, message: '歌单已清空' }
|
||||||
|
} catch (error) {
|
||||||
|
console.error('清空歌单失败:', error)
|
||||||
|
const message = error instanceof SongListError ? error.message : '清空歌单失败'
|
||||||
|
return {
|
||||||
|
success: false,
|
||||||
|
error: message,
|
||||||
|
code: error instanceof SongListError ? error.code : 'UNKNOWN_ERROR'
|
||||||
|
}
|
||||||
|
}
|
||||||
|
})
|
||||||
|
|
||||||
|
// 获取歌单中的歌曲列表
|
||||||
|
ipcMain.handle('songlist:get-songs', async (_, hashId: string) => {
|
||||||
|
try {
|
||||||
|
const instance = new ManageSongList(hashId)
|
||||||
|
const songs = instance.getSongs()
|
||||||
|
return { success: true, data: songs }
|
||||||
|
} catch (error) {
|
||||||
|
console.error('获取歌曲列表失败:', error)
|
||||||
|
const message = error instanceof SongListError ? error.message : '获取歌曲列表失败'
|
||||||
|
return {
|
||||||
|
success: false,
|
||||||
|
error: message,
|
||||||
|
code: error instanceof SongListError ? error.code : 'UNKNOWN_ERROR'
|
||||||
|
}
|
||||||
|
}
|
||||||
|
})
|
||||||
|
|
||||||
|
// 获取歌单歌曲数量
|
||||||
|
ipcMain.handle('songlist:get-song-count', async (_, hashId: string) => {
|
||||||
|
try {
|
||||||
|
const instance = new ManageSongList(hashId)
|
||||||
|
const count = instance.getCount()
|
||||||
|
return { success: true, data: count }
|
||||||
|
} catch (error) {
|
||||||
|
console.error('获取歌曲数量失败:', error)
|
||||||
|
const message = error instanceof SongListError ? error.message : '获取歌曲数量失败'
|
||||||
|
return {
|
||||||
|
success: false,
|
||||||
|
error: message,
|
||||||
|
code: error instanceof SongListError ? error.code : 'UNKNOWN_ERROR'
|
||||||
|
}
|
||||||
|
}
|
||||||
|
})
|
||||||
|
|
||||||
|
// 检查歌曲是否在歌单中
|
||||||
|
ipcMain.handle('songlist:has-song', async (_, hashId: string, songmid: string | number) => {
|
||||||
|
try {
|
||||||
|
const instance = new ManageSongList(hashId)
|
||||||
|
const hasSong = instance.hasSong(songmid)
|
||||||
|
return { success: true, data: hasSong }
|
||||||
|
} catch (error) {
|
||||||
|
console.error('检查歌曲存在性失败:', error)
|
||||||
|
return { success: false, error: '检查歌曲存在性失败', data: false }
|
||||||
|
}
|
||||||
|
})
|
||||||
|
|
||||||
|
// 根据ID获取歌曲
|
||||||
|
ipcMain.handle('songlist:get-song', async (_, hashId: string, songmid: string | number) => {
|
||||||
|
try {
|
||||||
|
const instance = new ManageSongList(hashId)
|
||||||
|
const song = instance.getSong(songmid)
|
||||||
|
return { success: true, data: song }
|
||||||
|
} catch (error) {
|
||||||
|
console.error('获取歌曲失败:', error)
|
||||||
|
return { success: false, error: '获取歌曲失败', data: null }
|
||||||
|
}
|
||||||
|
})
|
||||||
|
|
||||||
|
// 搜索歌单中的歌曲
|
||||||
|
ipcMain.handle('songlist:search-songs', async (_, hashId: string, keyword: string) => {
|
||||||
|
try {
|
||||||
|
const instance = new ManageSongList(hashId)
|
||||||
|
const results = instance.searchSongs(keyword)
|
||||||
|
return { success: true, data: results }
|
||||||
|
} catch (error) {
|
||||||
|
console.error('搜索歌曲失败:', error)
|
||||||
|
return { success: false, error: '搜索歌曲失败', data: [] }
|
||||||
|
}
|
||||||
|
})
|
||||||
|
|
||||||
|
// 获取歌单歌曲统计信息
|
||||||
|
ipcMain.handle('songlist:get-song-statistics', async (_, hashId: string) => {
|
||||||
|
try {
|
||||||
|
const instance = new ManageSongList(hashId)
|
||||||
|
const statistics = instance.getStatistics()
|
||||||
|
return { success: true, data: statistics }
|
||||||
|
} catch (error) {
|
||||||
|
console.error('获取歌曲统计信息失败:', error)
|
||||||
|
return { success: false, error: '获取歌曲统计信息失败' }
|
||||||
|
}
|
||||||
|
})
|
||||||
|
|
||||||
|
// 验证歌单完整性
|
||||||
|
ipcMain.handle('songlist:validate-integrity', async (_, hashId: string) => {
|
||||||
|
try {
|
||||||
|
const instance = new ManageSongList(hashId)
|
||||||
|
const result = instance.validateIntegrity()
|
||||||
|
return { success: true, data: result }
|
||||||
|
} catch (error) {
|
||||||
|
console.error('验证歌单完整性失败:', error)
|
||||||
|
return { success: false, error: '验证歌单完整性失败' }
|
||||||
|
}
|
||||||
|
})
|
||||||
|
|
||||||
|
// 修复歌单数据
|
||||||
|
ipcMain.handle('songlist:repair-data', async (_, hashId: string) => {
|
||||||
|
try {
|
||||||
|
const instance = new ManageSongList(hashId)
|
||||||
|
const result = instance.repairData()
|
||||||
|
return {
|
||||||
|
success: true,
|
||||||
|
data: result,
|
||||||
|
message: result.fixed ? `数据修复完成: ${result.changes.join(', ')}` : '数据无需修复'
|
||||||
|
}
|
||||||
|
} catch (error) {
|
||||||
|
console.error('修复歌单数据失败:', error)
|
||||||
|
const message = error instanceof SongListError ? error.message : '修复歌单数据失败'
|
||||||
|
return {
|
||||||
|
success: false,
|
||||||
|
error: message,
|
||||||
|
code: error instanceof SongListError ? error.code : 'UNKNOWN_ERROR'
|
||||||
|
}
|
||||||
|
}
|
||||||
|
})
|
||||||
|
|
||||||
|
// 强制保存歌单
|
||||||
|
ipcMain.handle('songlist:force-save', async (_, hashId: string) => {
|
||||||
|
try {
|
||||||
|
const instance = new ManageSongList(hashId)
|
||||||
|
instance.forceSave()
|
||||||
|
return { success: true, message: '歌单保存成功' }
|
||||||
|
} catch (error) {
|
||||||
|
console.error('强制保存歌单失败:', error)
|
||||||
|
const message = error instanceof SongListError ? error.message : '强制保存歌单失败'
|
||||||
|
return {
|
||||||
|
success: false,
|
||||||
|
error: message,
|
||||||
|
code: error instanceof SongListError ? error.code : 'UNKNOWN_ERROR'
|
||||||
|
}
|
||||||
|
}
|
||||||
|
})
|
||||||
@@ -7,6 +7,23 @@ import musicService from './services/music'
|
|||||||
import pluginService from './services/plugin'
|
import pluginService from './services/plugin'
|
||||||
import aiEvents from './events/ai'
|
import aiEvents from './events/ai'
|
||||||
import './services/musicSdk/index'
|
import './services/musicSdk/index'
|
||||||
|
// 获取单实例锁
|
||||||
|
const gotTheLock = app.requestSingleInstanceLock()
|
||||||
|
|
||||||
|
if (!gotTheLock) {
|
||||||
|
// 如果没有获得锁,说明已经有实例在运行,退出当前实例
|
||||||
|
app.quit()
|
||||||
|
} else {
|
||||||
|
// 当第二个实例尝试启动时,聚焦到第一个实例的窗口
|
||||||
|
app.on('second-instance', () => {
|
||||||
|
// 如果有窗口存在,聚焦到该窗口
|
||||||
|
if (mainWindow) {
|
||||||
|
if (mainWindow.isMinimized()) mainWindow.restore()
|
||||||
|
if (!mainWindow.isVisible()) mainWindow.show()
|
||||||
|
mainWindow.focus()
|
||||||
|
}
|
||||||
|
})
|
||||||
|
}
|
||||||
|
|
||||||
// import wy from './utils/musicSdk/wy/index'
|
// import wy from './utils/musicSdk/wy/index'
|
||||||
// import kg from './utils/musicSdk/kg/index'
|
// import kg from './utils/musicSdk/kg/index'
|
||||||
@@ -76,7 +93,7 @@ function createWindow(): void {
|
|||||||
mainWindow = new BrowserWindow({
|
mainWindow = new BrowserWindow({
|
||||||
width: 1100,
|
width: 1100,
|
||||||
height: 750,
|
height: 750,
|
||||||
minWidth: 970,
|
minWidth: 1100,
|
||||||
minHeight: 670,
|
minHeight: 670,
|
||||||
show: false,
|
show: false,
|
||||||
center: true,
|
center: true,
|
||||||
@@ -95,7 +112,6 @@ function createWindow(): void {
|
|||||||
contextIsolation: false,
|
contextIsolation: false,
|
||||||
backgroundThrottling: false
|
backgroundThrottling: false
|
||||||
}
|
}
|
||||||
|
|
||||||
})
|
})
|
||||||
if (process.platform == 'darwin') mainWindow.setWindowButtonVisibility(false)
|
if (process.platform == 'darwin') mainWindow.setWindowButtonVisibility(false)
|
||||||
|
|
||||||
@@ -200,15 +216,23 @@ ipcMain.handle('get-app-version', () => {
|
|||||||
|
|
||||||
aiEvents(mainWindow)
|
aiEvents(mainWindow)
|
||||||
import './events/musicCache'
|
import './events/musicCache'
|
||||||
|
import './events/songList'
|
||||||
|
import './events/directorySettings'
|
||||||
import { registerAutoUpdateEvents, initAutoUpdateForWindow } from './events/autoUpdate'
|
import { registerAutoUpdateEvents, initAutoUpdateForWindow } from './events/autoUpdate'
|
||||||
|
|
||||||
// This method will be called when Electron has finished
|
// This method will be called when Electron has finished
|
||||||
// initialization and is ready to create browser windows.
|
// initialization and is ready to create browser windows.
|
||||||
// Some APIs can only be used after this event occurs.
|
// Some APIs can only be used after this event occurs.
|
||||||
app.whenReady().then(() => {
|
app.whenReady().then(() => {
|
||||||
// Set app user model id for windows
|
// Set app user model id for windows - 确保与 electron-builder.yml 中的 appId 一致
|
||||||
|
electronApp.setAppUserModelId('com.cerumusic.app')
|
||||||
|
|
||||||
electronApp.setAppUserModelId('com.cerulean.music')
|
// 在 Windows 上设置应用程序名称,帮助 SMTC 识别
|
||||||
|
if (process.platform === 'win32') {
|
||||||
|
app.setAppUserModelId('com.cerumusic.app')
|
||||||
|
// 设置应用程序名称
|
||||||
|
app.setName('澜音')
|
||||||
|
}
|
||||||
|
|
||||||
setTimeout(async () => {
|
setTimeout(async () => {
|
||||||
// 初始化插件系统
|
// 初始化插件系统
|
||||||
@@ -218,7 +242,7 @@ app.whenReady().then(() => {
|
|||||||
} catch (error) {
|
} catch (error) {
|
||||||
console.error('插件系统初始化失败:', error)
|
console.error('插件系统初始化失败:', error)
|
||||||
}
|
}
|
||||||
},1000)
|
}, 1000)
|
||||||
|
|
||||||
// Default open or close DevTools by F12 in development
|
// Default open or close DevTools by F12 in development
|
||||||
// and ignore CommandOrControl + R in production.
|
// and ignore CommandOrControl + R in production.
|
||||||
|
|||||||
@@ -3,19 +3,43 @@ import * as path from 'path'
|
|||||||
import * as fs from 'fs/promises'
|
import * as fs from 'fs/promises'
|
||||||
import * as crypto from 'crypto'
|
import * as crypto from 'crypto'
|
||||||
import axios from 'axios'
|
import axios from 'axios'
|
||||||
|
import { CONFIG_NAME } from '../../events/directorySettings'
|
||||||
|
|
||||||
export class MusicCacheService {
|
export class MusicCacheService {
|
||||||
private cacheDir: string
|
|
||||||
private cacheIndex: Map<string, string> = new Map()
|
private cacheIndex: Map<string, string> = new Map()
|
||||||
private indexFilePath: string
|
|
||||||
|
|
||||||
constructor() {
|
constructor() {
|
||||||
this.cacheDir = path.join(app.getPath('userData'), 'music-cache')
|
|
||||||
this.indexFilePath = path.join(this.cacheDir, 'cache-index.json')
|
|
||||||
this.initCache()
|
this.initCache()
|
||||||
}
|
}
|
||||||
|
|
||||||
|
private getCacheDirectory(): string {
|
||||||
|
try {
|
||||||
|
// 尝试从配置文件读取自定义缓存目录
|
||||||
|
const configPath = path.join(app.getPath('userData'), CONFIG_NAME)
|
||||||
|
const configData = require('fs').readFileSync(configPath, 'utf-8')
|
||||||
|
const config = JSON.parse(configData)
|
||||||
|
|
||||||
|
if (config.cacheDir && typeof config.cacheDir === 'string') {
|
||||||
|
return config.cacheDir
|
||||||
|
}
|
||||||
|
} catch {
|
||||||
|
// 配置文件不存在或读取失败,使用默认目录
|
||||||
|
}
|
||||||
|
|
||||||
|
// 默认缓存目录
|
||||||
|
return path.join(app.getPath('userData'), 'music-cache')
|
||||||
|
}
|
||||||
|
|
||||||
|
// 动态获取缓存目录
|
||||||
|
public get cacheDir(): string {
|
||||||
|
return this.getCacheDirectory()
|
||||||
|
}
|
||||||
|
|
||||||
|
// 动态获取索引文件路径
|
||||||
|
public get indexFilePath(): string {
|
||||||
|
return path.join(this.cacheDir, 'cache-index.json')
|
||||||
|
}
|
||||||
|
|
||||||
private async initCache() {
|
private async initCache() {
|
||||||
try {
|
try {
|
||||||
// 确保缓存目录存在
|
// 确保缓存目录存在
|
||||||
@@ -60,7 +84,7 @@ export class MusicCacheService {
|
|||||||
|
|
||||||
async getCachedMusicUrl(songId: string, originalUrlPromise: Promise<string>): Promise<string> {
|
async getCachedMusicUrl(songId: string, originalUrlPromise: Promise<string>): Promise<string> {
|
||||||
const cacheKey = this.generateCacheKey(songId)
|
const cacheKey = this.generateCacheKey(songId)
|
||||||
console.log('hash',cacheKey)
|
console.log('hash', cacheKey)
|
||||||
|
|
||||||
// 检查是否已缓存
|
// 检查是否已缓存
|
||||||
if (this.cacheIndex.has(cacheKey)) {
|
if (this.cacheIndex.has(cacheKey)) {
|
||||||
@@ -131,43 +155,117 @@ export class MusicCacheService {
|
|||||||
|
|
||||||
async clearCache(): Promise<void> {
|
async clearCache(): Promise<void> {
|
||||||
try {
|
try {
|
||||||
// 删除所有缓存文件
|
console.log('开始清空缓存目录:', this.cacheDir)
|
||||||
|
|
||||||
|
// 先重新加载缓存索引,确保获取最新的文件列表
|
||||||
|
await this.loadCacheIndex()
|
||||||
|
|
||||||
|
// 删除索引中记录的所有缓存文件
|
||||||
|
let deletedFromIndex = 0
|
||||||
for (const filePath of this.cacheIndex.values()) {
|
for (const filePath of this.cacheIndex.values()) {
|
||||||
try {
|
try {
|
||||||
await fs.unlink(filePath)
|
await fs.unlink(filePath)
|
||||||
} catch (error) {
|
deletedFromIndex++
|
||||||
// 忽略文件不存在的错误
|
console.log('删除缓存文件:', filePath)
|
||||||
|
} catch (error: any) {
|
||||||
|
console.warn('删除文件失败:', filePath, error.message)
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
// 删除缓存目录中的所有其他文件(包括可能遗漏的文件)
|
||||||
|
let deletedFromDir = 0
|
||||||
|
try {
|
||||||
|
const files = await fs.readdir(this.cacheDir)
|
||||||
|
for (const file of files) {
|
||||||
|
const filePath = path.join(this.cacheDir, file)
|
||||||
|
try {
|
||||||
|
const stats = await fs.stat(filePath)
|
||||||
|
if (stats.isFile() && file !== 'cache-index.json') {
|
||||||
|
await fs.unlink(filePath)
|
||||||
|
deletedFromDir++
|
||||||
|
console.log('删除目录文件:', filePath)
|
||||||
|
}
|
||||||
|
} catch (error: any) {
|
||||||
|
console.warn('删除目录文件失败:', filePath, error.message)
|
||||||
|
}
|
||||||
|
}
|
||||||
|
} catch (error: any) {
|
||||||
|
console.warn('读取缓存目录失败:', error.message)
|
||||||
|
}
|
||||||
|
|
||||||
// 清空缓存索引
|
// 清空缓存索引
|
||||||
this.cacheIndex.clear()
|
this.cacheIndex.clear()
|
||||||
await this.saveCacheIndex()
|
await this.saveCacheIndex()
|
||||||
|
|
||||||
console.log('音乐缓存已清空')
|
console.log(
|
||||||
|
`音乐缓存已清空 - 从索引删除: ${deletedFromIndex}个文件, 从目录删除: ${deletedFromDir}个文件`
|
||||||
|
)
|
||||||
} catch (error) {
|
} catch (error) {
|
||||||
console.error('清空缓存失败:', error)
|
console.error('清空缓存失败:', error)
|
||||||
|
throw error
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
async getCacheSize(): Promise<number> {
|
getDirectorySize = async (dirPath: string): Promise<number> => {
|
||||||
let totalSize = 0
|
let totalSize = 0
|
||||||
|
|
||||||
for (const filePath of this.cacheIndex.values()) {
|
|
||||||
try {
|
try {
|
||||||
const stats = await fs.stat(filePath)
|
const items = await fs.readdir(dirPath)
|
||||||
|
|
||||||
|
for (const item of items) {
|
||||||
|
const itemPath = path.join(dirPath, item)
|
||||||
|
const stats = await fs.stat(itemPath)
|
||||||
|
|
||||||
|
if (stats.isDirectory()) {
|
||||||
|
totalSize += await this.getDirectorySize(itemPath)
|
||||||
|
} else {
|
||||||
totalSize += stats.size
|
totalSize += stats.size
|
||||||
} catch (error) {
|
|
||||||
// 文件不存在,忽略
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
} catch {
|
||||||
|
// 忽略无法访问的文件/目录
|
||||||
|
}
|
||||||
|
|
||||||
return totalSize
|
return totalSize
|
||||||
}
|
}
|
||||||
|
|
||||||
async getCacheInfo(): Promise<{ count: number; size: number; sizeFormatted: string }> {
|
async getCacheInfo(): Promise<{ count: number; size: number; sizeFormatted: string }> {
|
||||||
const size = await this.getCacheSize()
|
// 重新加载缓存索引以确保数据准确
|
||||||
const count = this.cacheIndex.size
|
await this.loadCacheIndex()
|
||||||
|
|
||||||
|
// 统计实际的缓存文件数量和大小
|
||||||
|
let actualCount = 0
|
||||||
|
let totalSize = 0
|
||||||
|
|
||||||
|
try {
|
||||||
|
const items = await fs.readdir(this.cacheDir)
|
||||||
|
|
||||||
|
for (const item of items) {
|
||||||
|
const itemPath = path.join(this.cacheDir, item)
|
||||||
|
try {
|
||||||
|
const stats = await fs.stat(itemPath)
|
||||||
|
|
||||||
|
if (stats.isFile() && item !== 'cache-index.json') {
|
||||||
|
// 检查是否是音频文件
|
||||||
|
const ext = path.extname(item).toLowerCase()
|
||||||
|
const audioExts = ['.mp3', '.flac', '.wav', '.aac', '.ogg', '.m4a', '.wma']
|
||||||
|
|
||||||
|
if (audioExts.includes(ext)) {
|
||||||
|
actualCount++
|
||||||
|
totalSize += stats.size
|
||||||
|
}
|
||||||
|
}
|
||||||
|
} catch (error: any) {
|
||||||
|
// 忽略无法访问的文件
|
||||||
|
console.warn('无法访问文件:', itemPath, error.message)
|
||||||
|
}
|
||||||
|
}
|
||||||
|
} catch (error: any) {
|
||||||
|
console.warn('读取缓存目录失败:', error.message)
|
||||||
|
// 如果无法读取目录,使用索引数据作为备选
|
||||||
|
totalSize = await this.getDirectorySize(this.cacheDir)
|
||||||
|
actualCount = this.cacheIndex.size
|
||||||
|
}
|
||||||
|
|
||||||
const formatSize = (bytes: number): string => {
|
const formatSize = (bytes: number): string => {
|
||||||
if (bytes === 0) return '0 B'
|
if (bytes === 0) return '0 B'
|
||||||
@@ -177,10 +275,12 @@ export class MusicCacheService {
|
|||||||
return parseFloat((bytes / Math.pow(k, i)).toFixed(2)) + ' ' + sizes[i]
|
return parseFloat((bytes / Math.pow(k, i)).toFixed(2)) + ' ' + sizes[i]
|
||||||
}
|
}
|
||||||
|
|
||||||
|
console.log(`缓存信息 - 文件数量: ${actualCount}, 总大小: ${totalSize} bytes`)
|
||||||
|
|
||||||
return {
|
return {
|
||||||
count,
|
count: actualCount,
|
||||||
size,
|
size: totalSize,
|
||||||
sizeFormatted: formatSize(size)
|
sizeFormatted: formatSize(totalSize)
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -19,7 +19,7 @@ export function request<T extends keyof MainApi>(
|
|||||||
return (Api[method] as (args: any) => any)(args)
|
return (Api[method] as (args: any) => any)(args)
|
||||||
}
|
}
|
||||||
throw new Error(`未知的方法: ${method}`)
|
throw new Error(`未知的方法: ${method}`)
|
||||||
}catch (error:any){
|
} catch (error: any) {
|
||||||
throw new Error(error.message)
|
throw new Error(error.message)
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -11,7 +11,6 @@ import {
|
|||||||
} from './type'
|
} from './type'
|
||||||
import pluginService from '../plugin/index'
|
import pluginService from '../plugin/index'
|
||||||
import musicSdk from '../../utils/musicSdk/index'
|
import musicSdk from '../../utils/musicSdk/index'
|
||||||
import { getAppDirPath } from '../../utils/path'
|
|
||||||
import { musicCacheService } from '../musicCache'
|
import { musicCacheService } from '../musicCache'
|
||||||
import path from 'node:path'
|
import path from 'node:path'
|
||||||
import fs from 'fs'
|
import fs from 'fs'
|
||||||
@@ -19,10 +18,11 @@ import fsPromise from 'fs/promises'
|
|||||||
import axios from 'axios'
|
import axios from 'axios'
|
||||||
import { pipeline } from 'node:stream/promises'
|
import { pipeline } from 'node:stream/promises'
|
||||||
import { fileURLToPath } from 'url'
|
import { fileURLToPath } from 'url'
|
||||||
|
import { app } from 'electron'
|
||||||
|
import { CONFIG_NAME } from '../../events/directorySettings'
|
||||||
|
|
||||||
const fileLock: Record<string, boolean> = {}
|
const fileLock: Record<string, boolean> = {}
|
||||||
|
|
||||||
|
|
||||||
function main(source: string) {
|
function main(source: string) {
|
||||||
const Api = musicSdk[source]
|
const Api = musicSdk[source]
|
||||||
return {
|
return {
|
||||||
@@ -38,7 +38,6 @@ function main(source: string) {
|
|||||||
// 获取原始URL
|
// 获取原始URL
|
||||||
const originalUrlPromise = usePlugin.getMusicUrl(source, songInfo, quality)
|
const originalUrlPromise = usePlugin.getMusicUrl(source, songInfo, quality)
|
||||||
|
|
||||||
|
|
||||||
// 生成歌曲唯一标识
|
// 生成歌曲唯一标识
|
||||||
const songId = `${songInfo.name}-${songInfo.singer}-${source}-${quality}`
|
const songId = `${songInfo.name}-${songInfo.singer}-${source}-${quality}`
|
||||||
|
|
||||||
@@ -91,6 +90,24 @@ function main(source: string) {
|
|||||||
const url = await this.getMusicUrl({ pluginId, songInfo, quality })
|
const url = await this.getMusicUrl({ pluginId, songInfo, quality })
|
||||||
if (typeof url === 'object') throw new Error('无法获取歌曲链接')
|
if (typeof url === 'object') throw new Error('无法获取歌曲链接')
|
||||||
|
|
||||||
|
// 获取自定义下载目录
|
||||||
|
const getDownloadDirectory = (): string => {
|
||||||
|
try {
|
||||||
|
const configPath = path.join(app.getPath('userData'), CONFIG_NAME)
|
||||||
|
const configData = fs.readFileSync(configPath, 'utf-8')
|
||||||
|
const config = JSON.parse(configData)
|
||||||
|
|
||||||
|
if (config.downloadDir && typeof config.downloadDir === 'string') {
|
||||||
|
return config.downloadDir
|
||||||
|
}
|
||||||
|
} catch {
|
||||||
|
// 配置文件不存在或读取失败,使用默认目录
|
||||||
|
}
|
||||||
|
|
||||||
|
// 默认下载目录
|
||||||
|
return path.join(app.getPath('music'), 'CeruMusic/songs')
|
||||||
|
}
|
||||||
|
|
||||||
// 从URL中提取文件扩展名,如果没有则默认为mp3
|
// 从URL中提取文件扩展名,如果没有则默认为mp3
|
||||||
const getFileExtension = (url: string): string => {
|
const getFileExtension = (url: string): string => {
|
||||||
try {
|
try {
|
||||||
@@ -112,11 +129,10 @@ function main(source: string) {
|
|||||||
}
|
}
|
||||||
|
|
||||||
const fileExtension = getFileExtension(url)
|
const fileExtension = getFileExtension(url)
|
||||||
|
const downloadDir = getDownloadDirectory()
|
||||||
const songPath = path.join(
|
const songPath = path.join(
|
||||||
getAppDirPath('music'),
|
downloadDir,
|
||||||
'CeruMusic',
|
`${songInfo.name}-${songInfo.singer}-${songInfo.source}.${fileExtension}`
|
||||||
'songs',
|
|
||||||
`${songInfo.name}-${songInfo.singer}-${source}.${fileExtension}`
|
|
||||||
.replace(/[/\\:*?"<>|]/g, '')
|
.replace(/[/\\:*?"<>|]/g, '')
|
||||||
.replace(/^\.+/, '')
|
.replace(/^\.+/, '')
|
||||||
.replace(/\.+$/, '')
|
.replace(/\.+$/, '')
|
||||||
@@ -161,6 +177,26 @@ function main(source: string) {
|
|||||||
message: '下载成功',
|
message: '下载成功',
|
||||||
path: songPath
|
path: songPath
|
||||||
}
|
}
|
||||||
|
},
|
||||||
|
|
||||||
|
async parsePlaylistId({ url }: { url: string }) {
|
||||||
|
try {
|
||||||
|
return await Api.songList.handleParseId(url)
|
||||||
|
} catch (e: any) {
|
||||||
|
return {
|
||||||
|
error: '解析歌单链接失败 ' + (e.error || e.message || e)
|
||||||
|
}
|
||||||
|
}
|
||||||
|
},
|
||||||
|
|
||||||
|
async getPlaylistDetailById(id: string, page: number = 1) {
|
||||||
|
try {
|
||||||
|
return await Api.songList.getListDetail(id, page)
|
||||||
|
} catch (e: any) {
|
||||||
|
return {
|
||||||
|
error: '获取歌单详情失败 ' + (e.error || e.message || e)
|
||||||
|
}
|
||||||
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
755
src/main/services/songList/ManageSongList.ts
Normal file
@@ -0,0 +1,755 @@
|
|||||||
|
import type { SongList, Songs } from '@common/types/songList'
|
||||||
|
import PlayListSongs from './PlayListSongs'
|
||||||
|
import fs from 'fs'
|
||||||
|
import path from 'path'
|
||||||
|
import crypto from 'crypto'
|
||||||
|
import { getAppDirPath } from '../../utils/path'
|
||||||
|
|
||||||
|
// 常量定义
|
||||||
|
const DEFAULT_COVER_IDENTIFIER = 'default-cover'
|
||||||
|
const SONGLIST_DIR = 'songList'
|
||||||
|
const INDEX_FILE = 'index.json'
|
||||||
|
|
||||||
|
// 错误类型定义
|
||||||
|
class SongListError extends Error {
|
||||||
|
constructor(
|
||||||
|
message: string,
|
||||||
|
public code?: string
|
||||||
|
) {
|
||||||
|
super(message)
|
||||||
|
this.name = 'SongListError'
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
// 工具函数类
|
||||||
|
class SongListUtils {
|
||||||
|
/**
|
||||||
|
* 获取默认封面标识符
|
||||||
|
*/
|
||||||
|
static getDefaultCoverUrl(): string {
|
||||||
|
return DEFAULT_COVER_IDENTIFIER
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* 获取歌单管理入口文件路径
|
||||||
|
*/
|
||||||
|
static getSongListIndexPath(): string {
|
||||||
|
return path.join(getAppDirPath('userData'), SONGLIST_DIR, INDEX_FILE)
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* 获取歌单文件路径
|
||||||
|
*/
|
||||||
|
static getSongListFilePath(hashId: string): string {
|
||||||
|
return path.join(getAppDirPath('userData'), SONGLIST_DIR, `${hashId}.json`)
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* 确保目录存在
|
||||||
|
*/
|
||||||
|
static ensureDirectoryExists(dirPath: string): void {
|
||||||
|
if (!fs.existsSync(dirPath)) {
|
||||||
|
fs.mkdirSync(dirPath, { recursive: true })
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* 生成唯一hashId
|
||||||
|
*/
|
||||||
|
static generateUniqueId(name: string): string {
|
||||||
|
return crypto.createHash('md5').update(`${name}_${Date.now()}_${Math.random()}`).digest('hex')
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* 验证歌曲封面URL是否有效
|
||||||
|
*/
|
||||||
|
static isValidCoverUrl(url: string | undefined | null): boolean {
|
||||||
|
return Boolean(url && url.trim() !== '' && url !== DEFAULT_COVER_IDENTIFIER)
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* 验证hashId格式
|
||||||
|
*/
|
||||||
|
static isValidHashId(hashId: string): boolean {
|
||||||
|
return Boolean(hashId && typeof hashId === 'string' && hashId.trim().length > 0)
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* 安全的JSON解析
|
||||||
|
*/
|
||||||
|
static safeJsonParse<T>(content: string, defaultValue: T): T {
|
||||||
|
try {
|
||||||
|
return JSON.parse(content) as T
|
||||||
|
} catch {
|
||||||
|
return defaultValue
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
export default class ManageSongList extends PlayListSongs {
|
||||||
|
private readonly hashId: string
|
||||||
|
|
||||||
|
constructor(hashId: string) {
|
||||||
|
if (!SongListUtils.isValidHashId(hashId)) {
|
||||||
|
throw new SongListError('无效的歌单ID', 'INVALID_HASH_ID')
|
||||||
|
}
|
||||||
|
|
||||||
|
super(hashId)
|
||||||
|
this.hashId = hashId.trim()
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* 静态方法:创建新歌单
|
||||||
|
* @param name 歌单名称
|
||||||
|
* @param description 歌单描述
|
||||||
|
* @param source 歌单来源
|
||||||
|
* @returns 包含hashId的对象 (id字段就是hashId)
|
||||||
|
*/
|
||||||
|
static createPlaylist(
|
||||||
|
name: string,
|
||||||
|
description: string = '',
|
||||||
|
source: SongList['source']
|
||||||
|
): { id: string } {
|
||||||
|
// 参数验证
|
||||||
|
if (!name?.trim()) {
|
||||||
|
throw new SongListError('歌单名称不能为空', 'EMPTY_NAME')
|
||||||
|
}
|
||||||
|
|
||||||
|
if (!source) {
|
||||||
|
throw new SongListError('歌单来源不能为空', 'EMPTY_SOURCE')
|
||||||
|
}
|
||||||
|
|
||||||
|
try {
|
||||||
|
const id = SongListUtils.generateUniqueId(name)
|
||||||
|
const now = new Date().toISOString()
|
||||||
|
|
||||||
|
const songListInfo: SongList = {
|
||||||
|
id,
|
||||||
|
name: name.trim(),
|
||||||
|
createTime: now,
|
||||||
|
updateTime: now,
|
||||||
|
description: description?.trim() || '',
|
||||||
|
coverImgUrl: SongListUtils.getDefaultCoverUrl(),
|
||||||
|
source
|
||||||
|
}
|
||||||
|
|
||||||
|
// 创建歌单文件
|
||||||
|
ManageSongList.createSongListFile(id)
|
||||||
|
|
||||||
|
// 更新入口文件
|
||||||
|
ManageSongList.updateIndexFile(songListInfo, 'add')
|
||||||
|
|
||||||
|
// 验证歌单可以正常实例化
|
||||||
|
try {
|
||||||
|
new ManageSongList(id)
|
||||||
|
// 如果能成功创建实例,说明文件创建成功
|
||||||
|
} catch (verifyError) {
|
||||||
|
console.error('歌单创建验证失败:', verifyError)
|
||||||
|
// 清理已创建的文件
|
||||||
|
try {
|
||||||
|
const filePath = SongListUtils.getSongListFilePath(id)
|
||||||
|
if (fs.existsSync(filePath)) {
|
||||||
|
fs.unlinkSync(filePath)
|
||||||
|
}
|
||||||
|
} catch (cleanupError) {
|
||||||
|
console.error('清理失败的歌单文件时出错:', cleanupError)
|
||||||
|
}
|
||||||
|
throw new SongListError('歌单创建后验证失败', 'CREATION_VERIFICATION_FAILED')
|
||||||
|
}
|
||||||
|
|
||||||
|
return { id }
|
||||||
|
} catch (error) {
|
||||||
|
console.error('创建歌单失败:', error)
|
||||||
|
if (error instanceof SongListError) {
|
||||||
|
throw error
|
||||||
|
}
|
||||||
|
throw new SongListError(
|
||||||
|
`创建歌单失败: ${error instanceof Error ? error.message : '未知错误'}`,
|
||||||
|
'CREATE_FAILED'
|
||||||
|
)
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* 创建歌单文件
|
||||||
|
* @param hashId 歌单hashId
|
||||||
|
*/
|
||||||
|
private static createSongListFile(hashId: string): void {
|
||||||
|
const songListFilePath = SongListUtils.getSongListFilePath(hashId)
|
||||||
|
const dir = path.dirname(songListFilePath)
|
||||||
|
|
||||||
|
SongListUtils.ensureDirectoryExists(dir)
|
||||||
|
|
||||||
|
try {
|
||||||
|
// 使用原子性写入确保文件完整性
|
||||||
|
const tempPath = `${songListFilePath}.tmp`
|
||||||
|
const content = JSON.stringify([], null, 2)
|
||||||
|
|
||||||
|
fs.writeFileSync(tempPath, content)
|
||||||
|
fs.renameSync(tempPath, songListFilePath)
|
||||||
|
|
||||||
|
// 确保文件确实存在且可读
|
||||||
|
if (!fs.existsSync(songListFilePath)) {
|
||||||
|
throw new Error('文件创建后验证失败')
|
||||||
|
}
|
||||||
|
|
||||||
|
// 验证文件内容
|
||||||
|
const verifyContent = fs.readFileSync(songListFilePath, 'utf-8')
|
||||||
|
JSON.parse(verifyContent) // 确保内容是有效的JSON
|
||||||
|
} catch (error) {
|
||||||
|
throw new SongListError(
|
||||||
|
`创建歌单文件失败: ${error instanceof Error ? error.message : '未知错误'}`,
|
||||||
|
'FILE_CREATE_FAILED'
|
||||||
|
)
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* 删除当前歌单
|
||||||
|
*/
|
||||||
|
delete(): void {
|
||||||
|
const hashId = this.getHashId()
|
||||||
|
|
||||||
|
try {
|
||||||
|
// 检查歌单是否存在
|
||||||
|
if (!ManageSongList.exists(hashId)) {
|
||||||
|
throw new SongListError('歌单不存在', 'PLAYLIST_NOT_FOUND')
|
||||||
|
}
|
||||||
|
|
||||||
|
// 删除歌单文件
|
||||||
|
const filePath = SongListUtils.getSongListFilePath(hashId)
|
||||||
|
if (fs.existsSync(filePath)) {
|
||||||
|
fs.unlinkSync(filePath)
|
||||||
|
}
|
||||||
|
|
||||||
|
// 从入口文件中移除
|
||||||
|
ManageSongList.updateIndexFile({ id: hashId } as SongList, 'remove')
|
||||||
|
} catch (error) {
|
||||||
|
console.error('删除歌单失败:', error)
|
||||||
|
if (error instanceof SongListError) {
|
||||||
|
throw error
|
||||||
|
}
|
||||||
|
throw new SongListError(
|
||||||
|
`删除歌单失败: ${error instanceof Error ? error.message : '未知错误'}`,
|
||||||
|
'DELETE_FAILED'
|
||||||
|
)
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* 修改当前歌单信息
|
||||||
|
* @param updates 要更新的字段
|
||||||
|
*/
|
||||||
|
edit(updates: Partial<Omit<SongList, 'id' | 'createTime'>>): void {
|
||||||
|
if (!updates || Object.keys(updates).length === 0) {
|
||||||
|
throw new SongListError('更新内容不能为空', 'EMPTY_UPDATES')
|
||||||
|
}
|
||||||
|
|
||||||
|
const hashId = this.getHashId()
|
||||||
|
|
||||||
|
try {
|
||||||
|
const songLists = ManageSongList.readIndexFile()
|
||||||
|
const index = songLists.findIndex((item) => item.id === hashId)
|
||||||
|
|
||||||
|
if (index === -1) {
|
||||||
|
throw new SongListError('歌单不存在', 'PLAYLIST_NOT_FOUND')
|
||||||
|
}
|
||||||
|
|
||||||
|
// 验证和清理更新数据
|
||||||
|
const cleanUpdates = ManageSongList.validateAndCleanUpdates(updates)
|
||||||
|
|
||||||
|
// 更新歌单信息
|
||||||
|
songLists[index] = {
|
||||||
|
...songLists[index],
|
||||||
|
...cleanUpdates,
|
||||||
|
updateTime: new Date().toISOString()
|
||||||
|
}
|
||||||
|
|
||||||
|
// 保存到入口文件
|
||||||
|
ManageSongList.writeIndexFile(songLists)
|
||||||
|
} catch (error) {
|
||||||
|
console.error('修改歌单失败:', error)
|
||||||
|
if (error instanceof SongListError) {
|
||||||
|
throw error
|
||||||
|
}
|
||||||
|
throw new SongListError(
|
||||||
|
`修改歌单失败: ${error instanceof Error ? error.message : '未知错误'}`,
|
||||||
|
'EDIT_FAILED'
|
||||||
|
)
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* 获取当前歌单的hashId
|
||||||
|
* @returns hashId
|
||||||
|
*/
|
||||||
|
private getHashId(): string {
|
||||||
|
return this.hashId
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* 验证和清理更新数据
|
||||||
|
* @param updates 原始更新数据
|
||||||
|
* @returns 清理后的更新数据
|
||||||
|
*/
|
||||||
|
private static validateAndCleanUpdates(
|
||||||
|
updates: Partial<Omit<SongList, 'id' | 'createTime'>>
|
||||||
|
): Partial<Omit<SongList, 'id' | 'createTime'>> {
|
||||||
|
const cleanUpdates: Partial<Omit<SongList, 'id' | 'createTime'>> = {}
|
||||||
|
|
||||||
|
// 验证歌单名称
|
||||||
|
if (updates.name !== undefined) {
|
||||||
|
const trimmedName = updates.name.trim()
|
||||||
|
if (!trimmedName) {
|
||||||
|
throw new SongListError('歌单名称不能为空', 'EMPTY_NAME')
|
||||||
|
}
|
||||||
|
cleanUpdates.name = trimmedName
|
||||||
|
}
|
||||||
|
|
||||||
|
// 处理描述
|
||||||
|
if (updates.description !== undefined) {
|
||||||
|
cleanUpdates.description = updates.description?.trim() || ''
|
||||||
|
}
|
||||||
|
|
||||||
|
// 处理封面URL
|
||||||
|
if (updates.coverImgUrl !== undefined) {
|
||||||
|
cleanUpdates.coverImgUrl = updates.coverImgUrl || SongListUtils.getDefaultCoverUrl()
|
||||||
|
}
|
||||||
|
|
||||||
|
// 处理来源
|
||||||
|
if (updates.source !== undefined) {
|
||||||
|
if (!updates.source) {
|
||||||
|
throw new SongListError('歌单来源不能为空', 'EMPTY_SOURCE')
|
||||||
|
}
|
||||||
|
cleanUpdates.source = updates.source
|
||||||
|
}
|
||||||
|
|
||||||
|
return cleanUpdates
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* 读取歌单列表
|
||||||
|
* @returns 歌单列表数组
|
||||||
|
*/
|
||||||
|
static Read(): SongList[] {
|
||||||
|
try {
|
||||||
|
return ManageSongList.readIndexFile()
|
||||||
|
} catch (error) {
|
||||||
|
console.error('读取歌单列表失败:', error)
|
||||||
|
if (error instanceof SongListError) {
|
||||||
|
throw error
|
||||||
|
}
|
||||||
|
throw new SongListError(
|
||||||
|
`读取歌单列表失败: ${error instanceof Error ? error.message : '未知错误'}`,
|
||||||
|
'READ_FAILED'
|
||||||
|
)
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* 根据hashId获取单个歌单信息
|
||||||
|
* @param hashId 歌单hashId
|
||||||
|
* @returns 歌单信息或null
|
||||||
|
*/
|
||||||
|
static getById(hashId: string): SongList | null {
|
||||||
|
if (!SongListUtils.isValidHashId(hashId)) {
|
||||||
|
return null
|
||||||
|
}
|
||||||
|
|
||||||
|
try {
|
||||||
|
const songLists = ManageSongList.readIndexFile()
|
||||||
|
return songLists.find((item) => item.id === hashId) || null
|
||||||
|
} catch (error) {
|
||||||
|
console.error('获取歌单信息失败:', error)
|
||||||
|
return null
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* 读取入口文件
|
||||||
|
* @returns 歌单列表数组
|
||||||
|
*/
|
||||||
|
private static readIndexFile(): SongList[] {
|
||||||
|
const indexPath = SongListUtils.getSongListIndexPath()
|
||||||
|
|
||||||
|
if (!fs.existsSync(indexPath)) {
|
||||||
|
ManageSongList.initializeIndexFile()
|
||||||
|
return []
|
||||||
|
}
|
||||||
|
|
||||||
|
try {
|
||||||
|
const content = fs.readFileSync(indexPath, 'utf-8')
|
||||||
|
const parsed = SongListUtils.safeJsonParse<unknown>(content, [])
|
||||||
|
|
||||||
|
// 验证数据格式
|
||||||
|
if (!Array.isArray(parsed)) {
|
||||||
|
console.warn('入口文件格式错误,重新初始化')
|
||||||
|
ManageSongList.initializeIndexFile()
|
||||||
|
return []
|
||||||
|
}
|
||||||
|
|
||||||
|
return parsed as SongList[]
|
||||||
|
} catch (error) {
|
||||||
|
console.error('解析入口文件失败:', error)
|
||||||
|
// 备份损坏的文件并重新初始化
|
||||||
|
ManageSongList.backupCorruptedFile(indexPath)
|
||||||
|
ManageSongList.initializeIndexFile()
|
||||||
|
return []
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* 备份损坏的文件
|
||||||
|
* @param filePath 文件路径
|
||||||
|
*/
|
||||||
|
private static backupCorruptedFile(filePath: string): void {
|
||||||
|
try {
|
||||||
|
const backupPath = `${filePath}.backup.${Date.now()}`
|
||||||
|
fs.copyFileSync(filePath, backupPath)
|
||||||
|
console.log(`已备份损坏的文件到: ${backupPath}`)
|
||||||
|
} catch (error) {
|
||||||
|
console.error('备份损坏文件失败:', error)
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* 初始化入口文件
|
||||||
|
*/
|
||||||
|
private static initializeIndexFile(): void {
|
||||||
|
const indexPath = SongListUtils.getSongListIndexPath()
|
||||||
|
const dir = path.dirname(indexPath)
|
||||||
|
|
||||||
|
SongListUtils.ensureDirectoryExists(dir)
|
||||||
|
|
||||||
|
try {
|
||||||
|
fs.writeFileSync(indexPath, JSON.stringify([], null, 2))
|
||||||
|
} catch (error) {
|
||||||
|
throw new SongListError(
|
||||||
|
`初始化入口文件失败: ${error instanceof Error ? error.message : '未知错误'}`,
|
||||||
|
'INIT_FAILED'
|
||||||
|
)
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* 写入入口文件
|
||||||
|
* @param songLists 歌单列表
|
||||||
|
*/
|
||||||
|
private static writeIndexFile(songLists: SongList[]): void {
|
||||||
|
if (!Array.isArray(songLists)) {
|
||||||
|
throw new SongListError('歌单列表必须是数组格式', 'INVALID_DATA_FORMAT')
|
||||||
|
}
|
||||||
|
|
||||||
|
const indexPath = SongListUtils.getSongListIndexPath()
|
||||||
|
const dir = path.dirname(indexPath)
|
||||||
|
|
||||||
|
SongListUtils.ensureDirectoryExists(dir)
|
||||||
|
|
||||||
|
try {
|
||||||
|
// 先写入临时文件,再重命名,确保原子性操作
|
||||||
|
const tempPath = `${indexPath}.tmp`
|
||||||
|
fs.writeFileSync(tempPath, JSON.stringify(songLists, null, 2))
|
||||||
|
fs.renameSync(tempPath, indexPath)
|
||||||
|
} catch (error) {
|
||||||
|
console.error('写入入口文件失败:', error)
|
||||||
|
throw new SongListError(
|
||||||
|
`写入入口文件失败: ${error instanceof Error ? error.message : '未知错误'}`,
|
||||||
|
'WRITE_FAILED'
|
||||||
|
)
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* 更新入口文件
|
||||||
|
* @param songListInfo 歌单信息
|
||||||
|
* @param action 操作类型
|
||||||
|
*/
|
||||||
|
private static updateIndexFile(songListInfo: SongList, action: 'add' | 'remove'): void {
|
||||||
|
const songLists = ManageSongList.readIndexFile()
|
||||||
|
|
||||||
|
switch (action) {
|
||||||
|
case 'add':
|
||||||
|
// 检查是否已存在,避免重复添加
|
||||||
|
if (!songLists.some((item) => item.id === songListInfo.id)) {
|
||||||
|
songLists.push(songListInfo)
|
||||||
|
}
|
||||||
|
break
|
||||||
|
|
||||||
|
case 'remove':
|
||||||
|
const index = songLists.findIndex((item) => item.id === songListInfo.id)
|
||||||
|
if (index !== -1) {
|
||||||
|
songLists.splice(index, 1)
|
||||||
|
}
|
||||||
|
break
|
||||||
|
|
||||||
|
default:
|
||||||
|
throw new SongListError(`不支持的操作类型: ${action}`, 'INVALID_ACTION')
|
||||||
|
}
|
||||||
|
|
||||||
|
ManageSongList.writeIndexFile(songLists)
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* 更新当前歌单封面图片URL
|
||||||
|
* @param coverImgUrl 封面图片URL
|
||||||
|
*/
|
||||||
|
updateCoverImg(coverImgUrl: string): void {
|
||||||
|
try {
|
||||||
|
const finalCoverUrl = coverImgUrl || SongListUtils.getDefaultCoverUrl()
|
||||||
|
this.edit({ coverImgUrl: finalCoverUrl })
|
||||||
|
} catch (error) {
|
||||||
|
console.error('更新封面失败:', error)
|
||||||
|
if (error instanceof SongListError) {
|
||||||
|
throw error
|
||||||
|
}
|
||||||
|
throw new SongListError(
|
||||||
|
`更新封面失败: ${error instanceof Error ? error.message : '未知错误'}`,
|
||||||
|
'UPDATE_COVER_FAILED'
|
||||||
|
)
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* 重写父类的addSongs方法,添加自动设置封面功能
|
||||||
|
* @param songs 要添加的歌曲列表
|
||||||
|
*/
|
||||||
|
addSongs(songs: Songs[]): void {
|
||||||
|
if (!Array.isArray(songs) || songs.length === 0) {
|
||||||
|
return
|
||||||
|
}
|
||||||
|
|
||||||
|
// 调用父类方法添加歌曲
|
||||||
|
super.addSongs(songs)
|
||||||
|
|
||||||
|
// 异步更新封面,不阻塞主要功能
|
||||||
|
setImmediate(() => {
|
||||||
|
this.updateCoverIfNeeded(songs)
|
||||||
|
})
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* 检查并更新封面图片
|
||||||
|
* @param newSongs 新添加的歌曲列表
|
||||||
|
*/
|
||||||
|
private updateCoverIfNeeded(newSongs: Songs[]): void {
|
||||||
|
try {
|
||||||
|
const currentPlaylist = ManageSongList.getById(this.hashId)
|
||||||
|
|
||||||
|
if (!currentPlaylist) {
|
||||||
|
console.warn(`歌单 ${this.hashId} 不存在,跳过封面更新`)
|
||||||
|
return
|
||||||
|
}
|
||||||
|
|
||||||
|
const shouldUpdateCover = this.shouldUpdateCover(currentPlaylist.coverImgUrl)
|
||||||
|
|
||||||
|
if (shouldUpdateCover) {
|
||||||
|
const validCoverUrl = this.findValidCoverFromSongs(newSongs)
|
||||||
|
|
||||||
|
if (validCoverUrl) {
|
||||||
|
this.updateCoverImg(validCoverUrl)
|
||||||
|
} else if (
|
||||||
|
!currentPlaylist.coverImgUrl ||
|
||||||
|
currentPlaylist.coverImgUrl === SongListUtils.getDefaultCoverUrl()
|
||||||
|
) {
|
||||||
|
// 如果没有找到有效封面且当前也没有封面,设置默认封面
|
||||||
|
this.updateCoverImg(SongListUtils.getDefaultCoverUrl())
|
||||||
|
}
|
||||||
|
}
|
||||||
|
} catch (error) {
|
||||||
|
console.error('更新封面失败:', error)
|
||||||
|
// 不抛出错误,避免影响添加歌曲的主要功能
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* 判断是否应该更新封面
|
||||||
|
* @param currentCoverUrl 当前封面URL
|
||||||
|
* @returns 是否应该更新
|
||||||
|
*/
|
||||||
|
private shouldUpdateCover(currentCoverUrl: string): boolean {
|
||||||
|
return !currentCoverUrl || currentCoverUrl === SongListUtils.getDefaultCoverUrl()
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* 从歌曲列表中查找有效的封面图片
|
||||||
|
* @param songs 歌曲列表
|
||||||
|
* @returns 有效的封面URL或null
|
||||||
|
*/
|
||||||
|
private findValidCoverFromSongs(songs: Songs[]): string | null {
|
||||||
|
// 优先检查新添加的歌曲
|
||||||
|
for (const song of songs) {
|
||||||
|
if (SongListUtils.isValidCoverUrl(song.img)) {
|
||||||
|
return song.img
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
// 如果新添加的歌曲都没有封面,检查当前歌单中的所有歌曲
|
||||||
|
try {
|
||||||
|
for (const song of this.list) {
|
||||||
|
if (SongListUtils.isValidCoverUrl(song.img)) {
|
||||||
|
return song.img
|
||||||
|
}
|
||||||
|
}
|
||||||
|
} catch (error) {
|
||||||
|
console.error('获取歌单歌曲列表失败:', error)
|
||||||
|
}
|
||||||
|
|
||||||
|
return null
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* 检查歌单是否存在
|
||||||
|
* @param hashId 歌单hashId
|
||||||
|
* @returns 是否存在
|
||||||
|
*/
|
||||||
|
static exists(hashId: string): boolean {
|
||||||
|
if (!SongListUtils.isValidHashId(hashId)) {
|
||||||
|
return false
|
||||||
|
}
|
||||||
|
|
||||||
|
try {
|
||||||
|
const songLists = ManageSongList.readIndexFile()
|
||||||
|
return songLists.some((item) => item.id === hashId)
|
||||||
|
} catch (error) {
|
||||||
|
console.error('检查歌单存在性失败:', error)
|
||||||
|
return false
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* 获取歌单统计信息
|
||||||
|
* @returns 统计信息
|
||||||
|
*/
|
||||||
|
static getStatistics(): { total: number; bySource: Record<string, number>; lastUpdated: string } {
|
||||||
|
try {
|
||||||
|
const songLists = ManageSongList.readIndexFile()
|
||||||
|
const bySource: Record<string, number> = {}
|
||||||
|
|
||||||
|
songLists.forEach((playlist) => {
|
||||||
|
const source = playlist.source || 'unknown'
|
||||||
|
bySource[source] = (bySource[source] || 0) + 1
|
||||||
|
})
|
||||||
|
|
||||||
|
return {
|
||||||
|
total: songLists.length,
|
||||||
|
bySource,
|
||||||
|
lastUpdated: new Date().toISOString()
|
||||||
|
}
|
||||||
|
} catch (error) {
|
||||||
|
console.error('获取统计信息失败:', error)
|
||||||
|
return {
|
||||||
|
total: 0,
|
||||||
|
bySource: {},
|
||||||
|
lastUpdated: new Date().toISOString()
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* 获取当前歌单信息
|
||||||
|
* @returns 歌单信息或null
|
||||||
|
*/
|
||||||
|
getPlaylistInfo(): SongList | null {
|
||||||
|
return ManageSongList.getById(this.hashId)
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* 批量操作:删除多个歌单
|
||||||
|
* @param hashIds 歌单ID数组
|
||||||
|
* @returns 操作结果
|
||||||
|
*/
|
||||||
|
static batchDelete(hashIds: string[]): { success: string[]; failed: string[] } {
|
||||||
|
const result = { success: [] as string[], failed: [] as string[] }
|
||||||
|
|
||||||
|
for (const hashId of hashIds) {
|
||||||
|
try {
|
||||||
|
ManageSongList.deleteById(hashId)
|
||||||
|
result.success.push(hashId)
|
||||||
|
} catch (error) {
|
||||||
|
console.error(`删除歌单 ${hashId} 失败:`, error)
|
||||||
|
result.failed.push(hashId)
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
return result
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* 搜索歌单
|
||||||
|
* @param keyword 搜索关键词
|
||||||
|
* @param source 可选的来源筛选
|
||||||
|
* @returns 匹配的歌单列表
|
||||||
|
*/
|
||||||
|
static search(keyword: string, source?: SongList['source']): SongList[] {
|
||||||
|
if (!keyword?.trim()) {
|
||||||
|
return []
|
||||||
|
}
|
||||||
|
|
||||||
|
try {
|
||||||
|
const songLists = ManageSongList.readIndexFile()
|
||||||
|
const lowerKeyword = keyword.toLowerCase()
|
||||||
|
|
||||||
|
return songLists.filter((playlist) => {
|
||||||
|
const matchesKeyword =
|
||||||
|
playlist.name.toLowerCase().includes(lowerKeyword) ||
|
||||||
|
playlist.description.toLowerCase().includes(lowerKeyword)
|
||||||
|
const matchesSource = !source || playlist.source === source
|
||||||
|
|
||||||
|
return matchesKeyword && matchesSource
|
||||||
|
})
|
||||||
|
} catch (error) {
|
||||||
|
console.error('搜索歌单失败:', error)
|
||||||
|
return []
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
// 静态方法别名,用于删除和编辑指定hashId的歌单
|
||||||
|
/**
|
||||||
|
* 静态方法:删除指定歌单
|
||||||
|
* @param hashId 歌单hashId
|
||||||
|
*/
|
||||||
|
static deleteById(hashId: string): void {
|
||||||
|
if (!SongListUtils.isValidHashId(hashId)) {
|
||||||
|
throw new SongListError('无效的歌单ID', 'INVALID_HASH_ID')
|
||||||
|
}
|
||||||
|
|
||||||
|
const instance = new ManageSongList(hashId)
|
||||||
|
instance.delete()
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* 静态方法:编辑指定歌单
|
||||||
|
* @param hashId 歌单hashId
|
||||||
|
* @param updates 要更新的字段
|
||||||
|
*/
|
||||||
|
static editById(hashId: string, updates: Partial<Omit<SongList, 'id' | 'createTime'>>): void {
|
||||||
|
if (!SongListUtils.isValidHashId(hashId)) {
|
||||||
|
throw new SongListError('无效的歌单ID', 'INVALID_HASH_ID')
|
||||||
|
}
|
||||||
|
|
||||||
|
const instance = new ManageSongList(hashId)
|
||||||
|
instance.edit(updates)
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* 静态方法:更新指定歌单封面
|
||||||
|
* @param hashId 歌单hashId
|
||||||
|
* @param coverImgUrl 封面图片URL
|
||||||
|
*/
|
||||||
|
static updateCoverImgById(hashId: string, coverImgUrl: string): void {
|
||||||
|
if (!SongListUtils.isValidHashId(hashId)) {
|
||||||
|
throw new SongListError('无效的歌单ID', 'INVALID_HASH_ID')
|
||||||
|
}
|
||||||
|
|
||||||
|
const instance = new ManageSongList(hashId)
|
||||||
|
instance.updateCoverImg(coverImgUrl)
|
||||||
|
}
|
||||||
|
|
||||||
|
// 保持向后兼容的别名方法
|
||||||
|
static Delete = ManageSongList.deleteById
|
||||||
|
static Edit = ManageSongList.editById
|
||||||
|
static read = ManageSongList.Read
|
||||||
|
}
|
||||||
|
|
||||||
|
// 导出错误类供外部使用
|
||||||
|
export { SongListError }
|
||||||
452
src/main/services/songList/PlayListSongs.ts
Normal file
@@ -0,0 +1,452 @@
|
|||||||
|
import type { Songs as SongItem } from '@common/types/songList'
|
||||||
|
import fs from 'fs'
|
||||||
|
import path from 'path'
|
||||||
|
import { getAppDirPath } from '../../utils/path'
|
||||||
|
|
||||||
|
// 错误类定义
|
||||||
|
class PlayListError extends Error {
|
||||||
|
constructor(
|
||||||
|
message: string,
|
||||||
|
public code?: string
|
||||||
|
) {
|
||||||
|
super(message)
|
||||||
|
this.name = 'PlayListError'
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
// 工具函数类
|
||||||
|
class PlayListUtils {
|
||||||
|
/**
|
||||||
|
* 获取歌单文件路径
|
||||||
|
*/
|
||||||
|
static getFilePath(hashId: string): string {
|
||||||
|
if (!hashId || typeof hashId !== 'string' || !hashId.trim()) {
|
||||||
|
throw new PlayListError('无效的歌单ID', 'INVALID_HASH_ID')
|
||||||
|
}
|
||||||
|
return path.join(getAppDirPath('userData'), 'songList', `${hashId.trim()}.json`)
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* 确保目录存在
|
||||||
|
*/
|
||||||
|
static ensureDirectoryExists(dirPath: string): void {
|
||||||
|
if (!fs.existsSync(dirPath)) {
|
||||||
|
fs.mkdirSync(dirPath, { recursive: true })
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* 安全的JSON解析
|
||||||
|
*/
|
||||||
|
static safeJsonParse<T>(content: string, defaultValue: T): T {
|
||||||
|
try {
|
||||||
|
const parsed = JSON.parse(content)
|
||||||
|
return parsed as T
|
||||||
|
} catch {
|
||||||
|
return defaultValue
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* 安全的JSON解析(专门用于数组)
|
||||||
|
*/
|
||||||
|
static safeJsonParseArray<T>(content: string, defaultValue: T[]): T[] {
|
||||||
|
try {
|
||||||
|
const parsed = JSON.parse(content)
|
||||||
|
return Array.isArray(parsed) ? parsed : defaultValue
|
||||||
|
} catch {
|
||||||
|
return defaultValue
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* 验证歌曲对象
|
||||||
|
*/
|
||||||
|
static isValidSong(song: any): song is SongItem {
|
||||||
|
return (
|
||||||
|
song &&
|
||||||
|
typeof song === 'object' &&
|
||||||
|
(typeof song.songmid === 'string' || typeof song.songmid === 'number') &&
|
||||||
|
String(song.songmid).trim().length > 0
|
||||||
|
)
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* 去重歌曲列表
|
||||||
|
*/
|
||||||
|
static deduplicateSongs(songs: SongItem[]): SongItem[] {
|
||||||
|
const seen = new Set<string>()
|
||||||
|
return songs.filter((song) => {
|
||||||
|
const songmidStr = String(song.songmid)
|
||||||
|
if (seen.has(songmidStr)) {
|
||||||
|
return false
|
||||||
|
}
|
||||||
|
seen.add(songmidStr)
|
||||||
|
return true
|
||||||
|
})
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
export default class PlayListSongs {
|
||||||
|
protected readonly filePath: string
|
||||||
|
protected list: SongItem[]
|
||||||
|
private isDirty: boolean = false
|
||||||
|
|
||||||
|
constructor(hashId: string) {
|
||||||
|
this.filePath = PlayListUtils.getFilePath(hashId)
|
||||||
|
this.list = []
|
||||||
|
this.initList()
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* 初始化歌单列表
|
||||||
|
*/
|
||||||
|
private initList(): void {
|
||||||
|
// 增加重试机制,处理文件创建的时序问题
|
||||||
|
const maxRetries = 3
|
||||||
|
const retryDelay = 100 // 100ms
|
||||||
|
|
||||||
|
for (let attempt = 0; attempt < maxRetries; attempt++) {
|
||||||
|
try {
|
||||||
|
if (!fs.existsSync(this.filePath)) {
|
||||||
|
if (attempt < maxRetries - 1) {
|
||||||
|
// 等待一段时间后重试
|
||||||
|
const start = Date.now()
|
||||||
|
while (Date.now() - start < retryDelay) {
|
||||||
|
// 简单的同步等待
|
||||||
|
}
|
||||||
|
continue
|
||||||
|
}
|
||||||
|
throw new PlayListError('歌单文件不存在', 'FILE_NOT_FOUND')
|
||||||
|
}
|
||||||
|
|
||||||
|
const content = fs.readFileSync(this.filePath, 'utf-8')
|
||||||
|
const parsed = PlayListUtils.safeJsonParseArray<SongItem>(content, [])
|
||||||
|
|
||||||
|
// 验证和清理数据
|
||||||
|
this.list = parsed.filter(PlayListUtils.isValidSong)
|
||||||
|
|
||||||
|
// 如果数据被清理过,标记为需要保存
|
||||||
|
if (this.list.length !== parsed.length) {
|
||||||
|
this.isDirty = true
|
||||||
|
console.warn(
|
||||||
|
`歌单文件包含无效数据,已自动清理 ${parsed.length - this.list.length} 条无效记录`
|
||||||
|
)
|
||||||
|
}
|
||||||
|
|
||||||
|
// 成功读取,退出重试循环
|
||||||
|
return
|
||||||
|
} catch (error) {
|
||||||
|
if (attempt < maxRetries - 1) {
|
||||||
|
console.warn(`读取歌单文件失败,第 ${attempt + 1} 次重试:`, error)
|
||||||
|
// 等待一段时间后重试
|
||||||
|
const start = Date.now()
|
||||||
|
while (Date.now() - start < retryDelay) {
|
||||||
|
// 简单的同步等待
|
||||||
|
}
|
||||||
|
continue
|
||||||
|
}
|
||||||
|
|
||||||
|
console.error('读取歌单文件失败:', error)
|
||||||
|
throw new PlayListError(
|
||||||
|
`读取歌单失败: ${error instanceof Error ? error.message : '未知错误'}`,
|
||||||
|
'READ_FAILED'
|
||||||
|
)
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* 检查歌单文件是否存在
|
||||||
|
*/
|
||||||
|
static hasListFile(hashId: string): boolean {
|
||||||
|
try {
|
||||||
|
const filePath = PlayListUtils.getFilePath(hashId)
|
||||||
|
return fs.existsSync(filePath)
|
||||||
|
} catch {
|
||||||
|
return false
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* 添加歌曲到歌单
|
||||||
|
*/
|
||||||
|
addSongs(songs: SongItem[]): void {
|
||||||
|
if (!Array.isArray(songs) || songs.length === 0) {
|
||||||
|
return
|
||||||
|
}
|
||||||
|
|
||||||
|
// 验证和过滤有效歌曲
|
||||||
|
const validSongs = songs.filter(PlayListUtils.isValidSong)
|
||||||
|
if (validSongs.length === 0) {
|
||||||
|
console.warn('没有有效的歌曲可添加')
|
||||||
|
return
|
||||||
|
}
|
||||||
|
|
||||||
|
// 使用 Set 提高查重性能,统一转换为字符串进行比较
|
||||||
|
const existingSongMids = new Set(this.list.map((song) => String(song.songmid)))
|
||||||
|
|
||||||
|
// 添加不重复的歌曲
|
||||||
|
const newSongs = validSongs.filter((song) => !existingSongMids.has(String(song.songmid)))
|
||||||
|
|
||||||
|
if (newSongs.length > 0) {
|
||||||
|
this.list.push(...newSongs)
|
||||||
|
this.isDirty = true
|
||||||
|
this.saveToFile()
|
||||||
|
|
||||||
|
console.log(
|
||||||
|
`成功添加 ${newSongs.length} 首歌曲,跳过 ${validSongs.length - newSongs.length} 首重复歌曲`
|
||||||
|
)
|
||||||
|
} else {
|
||||||
|
console.log('所有歌曲都已存在,未添加任何歌曲')
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* 从歌单中移除歌曲
|
||||||
|
*/
|
||||||
|
removeSong(songmid: string | number): boolean {
|
||||||
|
if (!songmid && songmid !== 0) {
|
||||||
|
throw new PlayListError('无效的歌曲ID', 'INVALID_SONG_ID')
|
||||||
|
}
|
||||||
|
|
||||||
|
const songmidStr = String(songmid)
|
||||||
|
const index = this.list.findIndex((item) => String(item.songmid) === songmidStr)
|
||||||
|
if (index !== -1) {
|
||||||
|
this.list.splice(index, 1)
|
||||||
|
this.isDirty = true
|
||||||
|
this.saveToFile()
|
||||||
|
return true
|
||||||
|
}
|
||||||
|
return false
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* 批量移除歌曲
|
||||||
|
*/
|
||||||
|
removeSongs(songmids: (string | number)[]): { removed: number; notFound: number } {
|
||||||
|
if (!Array.isArray(songmids) || songmids.length === 0) {
|
||||||
|
return { removed: 0, notFound: 0 }
|
||||||
|
}
|
||||||
|
|
||||||
|
const validSongMids = songmids.filter(
|
||||||
|
(id) => (id || id === 0) && (typeof id === 'string' || typeof id === 'number')
|
||||||
|
)
|
||||||
|
const songMidSet = new Set(validSongMids.map((id) => String(id)))
|
||||||
|
|
||||||
|
const initialLength = this.list.length
|
||||||
|
this.list = this.list.filter((song) => !songMidSet.has(String(song.songmid)))
|
||||||
|
|
||||||
|
const removedCount = initialLength - this.list.length
|
||||||
|
const notFoundCount = validSongMids.length - removedCount
|
||||||
|
|
||||||
|
if (removedCount > 0) {
|
||||||
|
this.isDirty = true
|
||||||
|
this.saveToFile()
|
||||||
|
}
|
||||||
|
|
||||||
|
return { removed: removedCount, notFound: notFoundCount }
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* 清空歌单
|
||||||
|
*/
|
||||||
|
clearSongs(): void {
|
||||||
|
if (this.list.length > 0) {
|
||||||
|
this.list = []
|
||||||
|
this.isDirty = true
|
||||||
|
this.saveToFile()
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* 保存到文件
|
||||||
|
*/
|
||||||
|
private saveToFile(): void {
|
||||||
|
if (!this.isDirty) {
|
||||||
|
return
|
||||||
|
}
|
||||||
|
|
||||||
|
try {
|
||||||
|
const dir = path.dirname(this.filePath)
|
||||||
|
PlayListUtils.ensureDirectoryExists(dir)
|
||||||
|
|
||||||
|
// 原子性写入:先写临时文件,再重命名
|
||||||
|
const tempPath = `${this.filePath}.tmp`
|
||||||
|
const content = JSON.stringify(this.list, null, 2)
|
||||||
|
|
||||||
|
fs.writeFileSync(tempPath, content)
|
||||||
|
fs.renameSync(tempPath, this.filePath)
|
||||||
|
|
||||||
|
this.isDirty = false
|
||||||
|
} catch (error) {
|
||||||
|
console.error('保存歌单文件失败:', error)
|
||||||
|
throw new PlayListError(
|
||||||
|
`保存歌单失败: ${error instanceof Error ? error.message : '未知错误'}`,
|
||||||
|
'SAVE_FAILED'
|
||||||
|
)
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* 强制保存到文件
|
||||||
|
*/
|
||||||
|
forceSave(): void {
|
||||||
|
this.isDirty = true
|
||||||
|
this.saveToFile()
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* 获取歌曲列表
|
||||||
|
*/
|
||||||
|
getSongs(): readonly SongItem[] {
|
||||||
|
return Object.freeze([...this.list])
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* 获取歌曲数量
|
||||||
|
*/
|
||||||
|
getCount(): number {
|
||||||
|
return this.list.length
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* 检查歌曲是否存在
|
||||||
|
*/
|
||||||
|
hasSong(songmid: string | number): boolean {
|
||||||
|
if (!songmid && songmid !== 0) {
|
||||||
|
return false
|
||||||
|
}
|
||||||
|
const songmidStr = String(songmid)
|
||||||
|
return this.list.some((song) => String(song.songmid) === songmidStr)
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* 根据songmid获取歌曲
|
||||||
|
*/
|
||||||
|
getSong(songmid: string | number): SongItem | null {
|
||||||
|
if (!songmid && songmid !== 0) {
|
||||||
|
return null
|
||||||
|
}
|
||||||
|
const songmidStr = String(songmid)
|
||||||
|
return this.list.find((song) => String(song.songmid) === songmidStr) || null
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* 搜索歌曲
|
||||||
|
*/
|
||||||
|
searchSongs(keyword: string): SongItem[] {
|
||||||
|
if (!keyword || typeof keyword !== 'string') {
|
||||||
|
return []
|
||||||
|
}
|
||||||
|
|
||||||
|
const lowerKeyword = keyword.toLowerCase()
|
||||||
|
return this.list.filter(
|
||||||
|
(song) =>
|
||||||
|
song.name?.toLowerCase().includes(lowerKeyword) ||
|
||||||
|
song.singer?.toLowerCase().includes(lowerKeyword) ||
|
||||||
|
song.albumName?.toLowerCase().includes(lowerKeyword)
|
||||||
|
)
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* 获取歌单统计信息
|
||||||
|
*/
|
||||||
|
getStatistics(): {
|
||||||
|
total: number
|
||||||
|
bySinger: Record<string, number>
|
||||||
|
byAlbum: Record<string, number>
|
||||||
|
lastModified: string
|
||||||
|
} {
|
||||||
|
const bySinger: Record<string, number> = {}
|
||||||
|
const byAlbum: Record<string, number> = {}
|
||||||
|
|
||||||
|
this.list.forEach((song) => {
|
||||||
|
// 统计歌手
|
||||||
|
if (song.singer) {
|
||||||
|
const singerName = String(song.singer)
|
||||||
|
bySinger[singerName] = (bySinger[singerName] || 0) + 1
|
||||||
|
}
|
||||||
|
|
||||||
|
// 统计专辑
|
||||||
|
if (song.albumName) {
|
||||||
|
const albumName = String(song.albumName)
|
||||||
|
byAlbum[albumName] = (byAlbum[albumName] || 0) + 1
|
||||||
|
}
|
||||||
|
})
|
||||||
|
|
||||||
|
return {
|
||||||
|
total: this.list.length,
|
||||||
|
bySinger,
|
||||||
|
byAlbum,
|
||||||
|
lastModified: new Date().toISOString()
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* 验证歌单完整性
|
||||||
|
*/
|
||||||
|
validateIntegrity(): { isValid: boolean; issues: string[] } {
|
||||||
|
const issues: string[] = []
|
||||||
|
|
||||||
|
// 检查文件是否存在
|
||||||
|
if (!fs.existsSync(this.filePath)) {
|
||||||
|
issues.push('歌单文件不存在')
|
||||||
|
}
|
||||||
|
|
||||||
|
// 检查数据完整性
|
||||||
|
const invalidSongs = this.list.filter((song) => !PlayListUtils.isValidSong(song))
|
||||||
|
if (invalidSongs.length > 0) {
|
||||||
|
issues.push(`发现 ${invalidSongs.length} 首无效歌曲`)
|
||||||
|
}
|
||||||
|
|
||||||
|
// 检查重复歌曲
|
||||||
|
const songMids = this.list.map((song) => String(song.songmid))
|
||||||
|
const uniqueSongMids = new Set(songMids)
|
||||||
|
if (songMids.length !== uniqueSongMids.size) {
|
||||||
|
issues.push(`发现 ${songMids.length - uniqueSongMids.size} 首重复歌曲`)
|
||||||
|
}
|
||||||
|
|
||||||
|
return {
|
||||||
|
isValid: issues.length === 0,
|
||||||
|
issues
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* 修复歌单数据
|
||||||
|
*/
|
||||||
|
repairData(): { fixed: boolean; changes: string[] } {
|
||||||
|
const changes: string[] = []
|
||||||
|
let hasChanges = false
|
||||||
|
|
||||||
|
// 移除无效歌曲
|
||||||
|
const validSongs = this.list.filter(PlayListUtils.isValidSong)
|
||||||
|
if (validSongs.length !== this.list.length) {
|
||||||
|
changes.push(`移除了 ${this.list.length - validSongs.length} 首无效歌曲`)
|
||||||
|
this.list = validSongs
|
||||||
|
hasChanges = true
|
||||||
|
}
|
||||||
|
|
||||||
|
// 去重
|
||||||
|
const deduplicatedSongs = PlayListUtils.deduplicateSongs(this.list)
|
||||||
|
if (deduplicatedSongs.length !== this.list.length) {
|
||||||
|
changes.push(`移除了 ${this.list.length - deduplicatedSongs.length} 首重复歌曲`)
|
||||||
|
this.list = deduplicatedSongs
|
||||||
|
hasChanges = true
|
||||||
|
}
|
||||||
|
|
||||||
|
if (hasChanges) {
|
||||||
|
this.isDirty = true
|
||||||
|
this.saveToFile()
|
||||||
|
}
|
||||||
|
|
||||||
|
return {
|
||||||
|
fixed: hasChanges,
|
||||||
|
changes
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
// 导出错误类供外部使用
|
||||||
|
export { PlayListError }
|
||||||
@@ -51,14 +51,14 @@ export default {
|
|||||||
...sources,
|
...sources,
|
||||||
init() {
|
init() {
|
||||||
const tasks = []
|
const tasks = []
|
||||||
for (let source of sources.sources) {
|
for (const source of sources.sources) {
|
||||||
let sm = sources[source.id]
|
const sm = sources[source.id]
|
||||||
sm && sm.init && tasks.push(sm.init())
|
sm && sm.init && tasks.push(sm.init())
|
||||||
}
|
}
|
||||||
return Promise.all(tasks)
|
return Promise.all(tasks)
|
||||||
},
|
},
|
||||||
async searchMusic({ name, singer, source: s, limit = 25 }) {
|
async searchMusic({ name, singer, source: s, limit = 25 }) {
|
||||||
const trimStr = (str) => (typeof str == 'string' ? str.trim() : str)
|
const trimStr = (str) => (typeof str === 'string' ? str.trim() : str)
|
||||||
const musicName = trimStr(name)
|
const musicName = trimStr(name)
|
||||||
const tasks = []
|
const tasks = []
|
||||||
const excludeSource = ['xm']
|
const excludeSource = ['xm']
|
||||||
@@ -106,7 +106,7 @@ export default {
|
|||||||
const getIntv = (interval) => {
|
const getIntv = (interval) => {
|
||||||
if (!interval) return 0
|
if (!interval) return 0
|
||||||
// if (musicInfo._interval) return musicInfo._interval
|
// if (musicInfo._interval) return musicInfo._interval
|
||||||
let intvArr = interval.split(':')
|
const intvArr = interval.split(':')
|
||||||
let intv = 0
|
let intv = 0
|
||||||
let unit = 1
|
let unit = 1
|
||||||
while (intvArr.length) {
|
while (intvArr.length) {
|
||||||
@@ -115,9 +115,9 @@ export default {
|
|||||||
}
|
}
|
||||||
return intv
|
return intv
|
||||||
}
|
}
|
||||||
const trimStr = (str) => (typeof str == 'string' ? str.trim() : str || '')
|
const trimStr = (str) => (typeof str === 'string' ? str.trim() : str || '')
|
||||||
const filterStr = (str) =>
|
const filterStr = (str) =>
|
||||||
typeof str == 'string'
|
typeof str === 'string'
|
||||||
? str.replace(/\s|'|\.|,|,|&|"|、|\(|\)|(|)|`|~|-|<|>|\||\/|\]|\[|!|!/g, '')
|
? str.replace(/\s|'|\.|,|,|&|"|、|\(|\)|(|)|`|~|-|<|>|\||\/|\]|\[|!|!/g, '')
|
||||||
: String(str || '')
|
: String(str || '')
|
||||||
const fMusicName = filterStr(name).toLowerCase()
|
const fMusicName = filterStr(name).toLowerCase()
|
||||||
|
|||||||
@@ -47,7 +47,7 @@ export default {
|
|||||||
)
|
)
|
||||||
if (!albumList.info) return Promise.reject(new Error('Get album list failed.'))
|
if (!albumList.info) return Promise.reject(new Error('Get album list failed.'))
|
||||||
|
|
||||||
let result = await getMusicInfosByList(albumList.info)
|
const result = await getMusicInfosByList(albumList.info)
|
||||||
|
|
||||||
const info = await this.getAlbumInfo(id)
|
const info = await this.getAlbumInfo(id)
|
||||||
|
|
||||||
|
|||||||
@@ -12,7 +12,7 @@ export default {
|
|||||||
// const res_id = (await getMusicInfoRaw(hash)).classification?.[0]?.res_id
|
// const res_id = (await getMusicInfoRaw(hash)).classification?.[0]?.res_id
|
||||||
// if (!res_id) throw new Error('获取评论失败')
|
// if (!res_id) throw new Error('获取评论失败')
|
||||||
|
|
||||||
let timestamp = Date.now()
|
const timestamp = Date.now()
|
||||||
const params = `dfid=0&mid=16249512204336365674023395779019&clienttime=${timestamp}&uuid=0&extdata=${hash}&appid=1005&code=fc4be23b4e972707f36b8a828a93ba8a&schash=${hash}&clientver=11409&p=${page}&clienttoken=&pagesize=${limit}&ver=10&kugouid=0`
|
const params = `dfid=0&mid=16249512204336365674023395779019&clienttime=${timestamp}&uuid=0&extdata=${hash}&appid=1005&code=fc4be23b4e972707f36b8a828a93ba8a&schash=${hash}&clientver=11409&p=${page}&clienttoken=&pagesize=${limit}&ver=10&kugouid=0`
|
||||||
// const params = `appid=1005&clienttime=${timestamp}&clienttoken=0&clientver=11409&code=fc4be23b4e972707f36b8a828a93ba8a&dfid=0&extdata=${hash}&kugouid=0&mid=16249512204336365674023395779019&mixsongid=${res_id}&p=${page}&pagesize=${limit}&uuid=0&ver=10`
|
// const params = `appid=1005&clienttime=${timestamp}&clienttoken=0&clientver=11409&code=fc4be23b4e972707f36b8a828a93ba8a&dfid=0&extdata=${hash}&kugouid=0&mid=16249512204336365674023395779019&mixsongid=${res_id}&p=${page}&pagesize=${limit}&uuid=0&ver=10`
|
||||||
const _requestObj = httpFetch(
|
const _requestObj = httpFetch(
|
||||||
@@ -40,7 +40,7 @@ export default {
|
|||||||
async getHotComment({ hash }, page = 1, limit = 20) {
|
async getHotComment({ hash }, page = 1, limit = 20) {
|
||||||
// console.log(songmid)
|
// console.log(songmid)
|
||||||
if (this._requestObj2) this._requestObj2.cancelHttp()
|
if (this._requestObj2) this._requestObj2.cancelHttp()
|
||||||
let timestamp = Date.now()
|
const timestamp = Date.now()
|
||||||
const params = `dfid=0&mid=16249512204336365674023395779019&clienttime=${timestamp}&uuid=0&extdata=${hash}&appid=1005&code=fc4be23b4e972707f36b8a828a93ba8a&schash=${hash}&clientver=11409&p=${page}&clienttoken=&pagesize=${limit}&ver=10&kugouid=0`
|
const params = `dfid=0&mid=16249512204336365674023395779019&clienttime=${timestamp}&uuid=0&extdata=${hash}&appid=1005&code=fc4be23b4e972707f36b8a828a93ba8a&schash=${hash}&clientver=11409&p=${page}&clienttoken=&pagesize=${limit}&ver=10&kugouid=0`
|
||||||
// https://github.com/GitHub-ZC/wp_MusicApi/blob/bf9307dd138dc8ac6c4f7de29361209d4f5b665f/routes/v1/kugou/comment.js#L53
|
// https://github.com/GitHub-ZC/wp_MusicApi/blob/bf9307dd138dc8ac6c4f7de29361209d4f5b665f/routes/v1/kugou/comment.js#L53
|
||||||
const _requestObj2 = httpFetch(
|
const _requestObj2 = httpFetch(
|
||||||
@@ -94,7 +94,7 @@ export default {
|
|||||||
},
|
},
|
||||||
filterComment(rawList) {
|
filterComment(rawList) {
|
||||||
return rawList.map((item) => {
|
return rawList.map((item) => {
|
||||||
let data = {
|
const data = {
|
||||||
id: item.id,
|
id: item.id,
|
||||||
text: decodeName(
|
text: decodeName(
|
||||||
(item.atlist ? this.replaceAt(item.content, item.atlist) : item.content) || ''
|
(item.atlist ? this.replaceAt(item.content, item.atlist) : item.content) || ''
|
||||||
|
|||||||
@@ -2,7 +2,7 @@ import { httpFetch } from '../../request'
|
|||||||
import { decodeName, formatPlayTime, sizeFormate } from '../index'
|
import { decodeName, formatPlayTime, sizeFormate } from '../index'
|
||||||
import { formatSingerName } from '../utils'
|
import { formatSingerName } from '../utils'
|
||||||
|
|
||||||
let boardList = [
|
const boardList = [
|
||||||
{ id: 'kg__8888', name: 'TOP500', bangid: '8888' },
|
{ id: 'kg__8888', name: 'TOP500', bangid: '8888' },
|
||||||
{ id: 'kg__6666', name: '飙升榜', bangid: '6666' },
|
{ id: 'kg__6666', name: '飙升榜', bangid: '6666' },
|
||||||
{ id: 'kg__59703', name: '蜂鸟流行音乐榜', bangid: '59703' },
|
{ id: 'kg__59703', name: '蜂鸟流行音乐榜', bangid: '59703' },
|
||||||
@@ -137,7 +137,7 @@ export default {
|
|||||||
return requestDataObj.promise
|
return requestDataObj.promise
|
||||||
},
|
},
|
||||||
getSinger(singers) {
|
getSinger(singers) {
|
||||||
let arr = []
|
const arr = []
|
||||||
singers.forEach((singer) => {
|
singers.forEach((singer) => {
|
||||||
arr.push(singer.author_name)
|
arr.push(singer.author_name)
|
||||||
})
|
})
|
||||||
@@ -149,7 +149,7 @@ export default {
|
|||||||
const types = []
|
const types = []
|
||||||
const _types = {}
|
const _types = {}
|
||||||
if (item.filesize !== 0) {
|
if (item.filesize !== 0) {
|
||||||
let size = sizeFormate(item.filesize)
|
const size = sizeFormate(item.filesize)
|
||||||
types.push({ type: '128k', size, hash: item.hash })
|
types.push({ type: '128k', size, hash: item.hash })
|
||||||
_types['128k'] = {
|
_types['128k'] = {
|
||||||
size,
|
size,
|
||||||
@@ -157,7 +157,7 @@ export default {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
if (item['320filesize'] !== 0) {
|
if (item['320filesize'] !== 0) {
|
||||||
let size = sizeFormate(item['320filesize'])
|
const size = sizeFormate(item['320filesize'])
|
||||||
types.push({ type: '320k', size, hash: item['320hash'] })
|
types.push({ type: '320k', size, hash: item['320hash'] })
|
||||||
_types['320k'] = {
|
_types['320k'] = {
|
||||||
size,
|
size,
|
||||||
@@ -165,7 +165,7 @@ export default {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
if (item.sqfilesize !== 0) {
|
if (item.sqfilesize !== 0) {
|
||||||
let size = sizeFormate(item.sqfilesize)
|
const size = sizeFormate(item.sqfilesize)
|
||||||
types.push({ type: 'flac', size, hash: item.sqhash })
|
types.push({ type: 'flac', size, hash: item.sqhash })
|
||||||
_types.flac = {
|
_types.flac = {
|
||||||
size,
|
size,
|
||||||
@@ -173,7 +173,7 @@ export default {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
if (item.filesize_high !== 0) {
|
if (item.filesize_high !== 0) {
|
||||||
let size = sizeFormate(item.filesize_high)
|
const size = sizeFormate(item.filesize_high)
|
||||||
types.push({ type: 'flac24bit', size, hash: item.hash_high })
|
types.push({ type: 'flac24bit', size, hash: item.hash_high })
|
||||||
_types.flac24bit = {
|
_types.flac24bit = {
|
||||||
size,
|
size,
|
||||||
@@ -201,7 +201,7 @@ export default {
|
|||||||
|
|
||||||
filterBoardsData(rawList) {
|
filterBoardsData(rawList) {
|
||||||
// console.log(rawList)
|
// console.log(rawList)
|
||||||
let list = []
|
const list = []
|
||||||
for (const board of rawList) {
|
for (const board of rawList) {
|
||||||
if (board.isvol != 1) continue
|
if (board.isvol != 1) continue
|
||||||
list.push({
|
list.push({
|
||||||
@@ -243,9 +243,9 @@ export default {
|
|||||||
if (body.errcode != 0) return this.getList(bangid, page, retryNum)
|
if (body.errcode != 0) return this.getList(bangid, page, retryNum)
|
||||||
|
|
||||||
// console.log(body)
|
// console.log(body)
|
||||||
let total = body.data.total
|
const total = body.data.total
|
||||||
let limit = 100
|
const limit = 100
|
||||||
let listData = this.filterData(body.data.info)
|
const listData = this.filterData(body.data.info)
|
||||||
// console.log(listData)
|
// console.log(listData)
|
||||||
return {
|
return {
|
||||||
total,
|
total,
|
||||||
@@ -256,7 +256,7 @@ export default {
|
|||||||
}
|
}
|
||||||
},
|
},
|
||||||
getDetailPageUrl(id) {
|
getDetailPageUrl(id) {
|
||||||
if (typeof id == 'string') id = id.replace('kg__', '')
|
if (typeof id === 'string') id = id.replace('kg__', '')
|
||||||
return `https://www.kugou.com/yy/rank/home/1-${id}.html`
|
return `https://www.kugou.com/yy/rank/home/1-${id}.html`
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -4,7 +4,7 @@ import { decodeKrc } from '../../../../common/utils/lyricUtils/kg'
|
|||||||
export default {
|
export default {
|
||||||
getIntv(interval) {
|
getIntv(interval) {
|
||||||
if (!interval) return 0
|
if (!interval) return 0
|
||||||
let intvArr = interval.split(':')
|
const intvArr = interval.split(':')
|
||||||
let intv = 0
|
let intv = 0
|
||||||
let unit = 1
|
let unit = 1
|
||||||
while (intvArr.length) {
|
while (intvArr.length) {
|
||||||
@@ -36,7 +36,7 @@ export default {
|
|||||||
// return requestObj
|
// return requestObj
|
||||||
// },
|
// },
|
||||||
searchLyric(name, hash, time, tryNum = 0) {
|
searchLyric(name, hash, time, tryNum = 0) {
|
||||||
let requestObj = httpFetch(
|
const requestObj = httpFetch(
|
||||||
`http://lyrics.kugou.com/search?ver=1&man=yes&client=pc&keyword=${encodeURIComponent(name)}&hash=${hash}&timelength=${time}&lrctxt=1`,
|
`http://lyrics.kugou.com/search?ver=1&man=yes&client=pc&keyword=${encodeURIComponent(name)}&hash=${hash}&timelength=${time}&lrctxt=1`,
|
||||||
{
|
{
|
||||||
headers: {
|
headers: {
|
||||||
@@ -49,12 +49,12 @@ export default {
|
|||||||
requestObj.promise = requestObj.promise.then(({ body, statusCode }) => {
|
requestObj.promise = requestObj.promise.then(({ body, statusCode }) => {
|
||||||
if (statusCode !== 200) {
|
if (statusCode !== 200) {
|
||||||
if (tryNum > 5) return Promise.reject(new Error('歌词获取失败'))
|
if (tryNum > 5) return Promise.reject(new Error('歌词获取失败'))
|
||||||
let tryRequestObj = this.searchLyric(name, hash, time, ++tryNum)
|
const tryRequestObj = this.searchLyric(name, hash, time, ++tryNum)
|
||||||
requestObj.cancelHttp = tryRequestObj.cancelHttp.bind(tryRequestObj)
|
requestObj.cancelHttp = tryRequestObj.cancelHttp.bind(tryRequestObj)
|
||||||
return tryRequestObj.promise
|
return tryRequestObj.promise
|
||||||
}
|
}
|
||||||
if (body.candidates.length) {
|
if (body.candidates.length) {
|
||||||
let info = body.candidates[0]
|
const info = body.candidates[0]
|
||||||
return {
|
return {
|
||||||
id: info.id,
|
id: info.id,
|
||||||
accessKey: info.accesskey,
|
accessKey: info.accesskey,
|
||||||
@@ -66,7 +66,7 @@ export default {
|
|||||||
return requestObj
|
return requestObj
|
||||||
},
|
},
|
||||||
getLyricDownload(id, accessKey, fmt, tryNum = 0) {
|
getLyricDownload(id, accessKey, fmt, tryNum = 0) {
|
||||||
let requestObj = httpFetch(
|
const requestObj = httpFetch(
|
||||||
`http://lyrics.kugou.com/download?ver=1&client=pc&id=${id}&accesskey=${accessKey}&fmt=${fmt}&charset=utf8`,
|
`http://lyrics.kugou.com/download?ver=1&client=pc&id=${id}&accesskey=${accessKey}&fmt=${fmt}&charset=utf8`,
|
||||||
{
|
{
|
||||||
headers: {
|
headers: {
|
||||||
@@ -79,7 +79,7 @@ export default {
|
|||||||
requestObj.promise = requestObj.promise.then(({ body, statusCode }) => {
|
requestObj.promise = requestObj.promise.then(({ body, statusCode }) => {
|
||||||
if (statusCode !== 200) {
|
if (statusCode !== 200) {
|
||||||
if (tryNum > 5) return Promise.reject(new Error('歌词获取失败'))
|
if (tryNum > 5) return Promise.reject(new Error('歌词获取失败'))
|
||||||
let tryRequestObj = this.getLyric(id, accessKey, fmt, ++tryNum)
|
const tryRequestObj = this.getLyric(id, accessKey, fmt, ++tryNum)
|
||||||
requestObj.cancelHttp = tryRequestObj.cancelHttp.bind(tryRequestObj)
|
requestObj.cancelHttp = tryRequestObj.cancelHttp.bind(tryRequestObj)
|
||||||
return tryRequestObj.promise
|
return tryRequestObj.promise
|
||||||
}
|
}
|
||||||
@@ -102,7 +102,7 @@ export default {
|
|||||||
return requestObj
|
return requestObj
|
||||||
},
|
},
|
||||||
getLyric(songInfo, tryNum = 0) {
|
getLyric(songInfo, tryNum = 0) {
|
||||||
let requestObj = this.searchLyric(
|
const requestObj = this.searchLyric(
|
||||||
songInfo.name,
|
songInfo.name,
|
||||||
songInfo.hash,
|
songInfo.hash,
|
||||||
songInfo._interval || this.getIntv(songInfo.interval)
|
songInfo._interval || this.getIntv(songInfo.interval)
|
||||||
@@ -111,7 +111,7 @@ export default {
|
|||||||
requestObj.promise = requestObj.promise.then((result) => {
|
requestObj.promise = requestObj.promise.then((result) => {
|
||||||
if (!result) return Promise.reject(new Error('Get lyric failed'))
|
if (!result) return Promise.reject(new Error('Get lyric failed'))
|
||||||
|
|
||||||
let requestObj2 = this.getLyricDownload(result.id, result.accessKey, result.fmt)
|
const requestObj2 = this.getLyricDownload(result.id, result.accessKey, result.fmt)
|
||||||
|
|
||||||
requestObj.cancelHttp = requestObj2.cancelHttp.bind(requestObj2)
|
requestObj.cancelHttp = requestObj2.cancelHttp.bind(requestObj2)
|
||||||
|
|
||||||
|
|||||||
@@ -2,7 +2,7 @@ import { decodeName, formatPlayTime, sizeFormate } from '../../index'
|
|||||||
import { createHttpFetch } from './util'
|
import { createHttpFetch } from './util'
|
||||||
|
|
||||||
const createGetMusicInfosTask = (hashs) => {
|
const createGetMusicInfosTask = (hashs) => {
|
||||||
let data = {
|
const data = {
|
||||||
area_code: '1',
|
area_code: '1',
|
||||||
show_privilege: 1,
|
show_privilege: 1,
|
||||||
show_album_info: '1',
|
show_album_info: '1',
|
||||||
@@ -16,13 +16,13 @@ const createGetMusicInfosTask = (hashs) => {
|
|||||||
fields: 'album_info,author_name,audio_info,ori_audio_name,base,songname,classification'
|
fields: 'album_info,author_name,audio_info,ori_audio_name,base,songname,classification'
|
||||||
}
|
}
|
||||||
let list = hashs
|
let list = hashs
|
||||||
let tasks = []
|
const tasks = []
|
||||||
while (list.length) {
|
while (list.length) {
|
||||||
tasks.push(Object.assign({ data: list.slice(0, 100) }, data))
|
tasks.push(Object.assign({ data: list.slice(0, 100) }, data))
|
||||||
if (list.length < 100) break
|
if (list.length < 100) break
|
||||||
list = list.slice(100)
|
list = list.slice(100)
|
||||||
}
|
}
|
||||||
let url = 'http://gateway.kugou.com/v3/album_audio/audio'
|
const url = 'http://gateway.kugou.com/v3/album_audio/audio'
|
||||||
return tasks.map((task) =>
|
return tasks.map((task) =>
|
||||||
createHttpFetch(url, {
|
createHttpFetch(url, {
|
||||||
method: 'POST',
|
method: 'POST',
|
||||||
@@ -41,8 +41,8 @@ const createGetMusicInfosTask = (hashs) => {
|
|||||||
|
|
||||||
export const filterMusicInfoList = (rawList) => {
|
export const filterMusicInfoList = (rawList) => {
|
||||||
// console.log(rawList)
|
// console.log(rawList)
|
||||||
let ids = new Set()
|
const ids = new Set()
|
||||||
let list = []
|
const list = []
|
||||||
rawList.forEach((item) => {
|
rawList.forEach((item) => {
|
||||||
if (!item) return
|
if (!item) return
|
||||||
if (ids.has(item.audio_info.audio_id)) return
|
if (ids.has(item.audio_info.audio_id)) return
|
||||||
@@ -50,7 +50,7 @@ export const filterMusicInfoList = (rawList) => {
|
|||||||
const types = []
|
const types = []
|
||||||
const _types = {}
|
const _types = {}
|
||||||
if (item.audio_info.filesize !== '0') {
|
if (item.audio_info.filesize !== '0') {
|
||||||
let size = sizeFormate(parseInt(item.audio_info.filesize))
|
const size = sizeFormate(parseInt(item.audio_info.filesize))
|
||||||
types.push({ type: '128k', size, hash: item.audio_info.hash })
|
types.push({ type: '128k', size, hash: item.audio_info.hash })
|
||||||
_types['128k'] = {
|
_types['128k'] = {
|
||||||
size,
|
size,
|
||||||
@@ -58,7 +58,7 @@ export const filterMusicInfoList = (rawList) => {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
if (item.audio_info.filesize_320 !== '0') {
|
if (item.audio_info.filesize_320 !== '0') {
|
||||||
let size = sizeFormate(parseInt(item.audio_info.filesize_320))
|
const size = sizeFormate(parseInt(item.audio_info.filesize_320))
|
||||||
types.push({ type: '320k', size, hash: item.audio_info.hash_320 })
|
types.push({ type: '320k', size, hash: item.audio_info.hash_320 })
|
||||||
_types['320k'] = {
|
_types['320k'] = {
|
||||||
size,
|
size,
|
||||||
@@ -66,7 +66,7 @@ export const filterMusicInfoList = (rawList) => {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
if (item.audio_info.filesize_flac !== '0') {
|
if (item.audio_info.filesize_flac !== '0') {
|
||||||
let size = sizeFormate(parseInt(item.audio_info.filesize_flac))
|
const size = sizeFormate(parseInt(item.audio_info.filesize_flac))
|
||||||
types.push({ type: 'flac', size, hash: item.audio_info.hash_flac })
|
types.push({ type: 'flac', size, hash: item.audio_info.hash_flac })
|
||||||
_types.flac = {
|
_types.flac = {
|
||||||
size,
|
size,
|
||||||
@@ -74,7 +74,7 @@ export const filterMusicInfoList = (rawList) => {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
if (item.audio_info.filesize_high !== '0') {
|
if (item.audio_info.filesize_high !== '0') {
|
||||||
let size = sizeFormate(parseInt(item.audio_info.filesize_high))
|
const size = sizeFormate(parseInt(item.audio_info.filesize_high))
|
||||||
types.push({ type: 'flac24bit', size, hash: item.audio_info.hash_high })
|
types.push({ type: 'flac24bit', size, hash: item.audio_info.hash_high })
|
||||||
_types.flac24bit = {
|
_types.flac24bit = {
|
||||||
size,
|
size,
|
||||||
|
|||||||
@@ -17,7 +17,7 @@ export default {
|
|||||||
const types = []
|
const types = []
|
||||||
const _types = {}
|
const _types = {}
|
||||||
if (rawData.FileSize !== 0) {
|
if (rawData.FileSize !== 0) {
|
||||||
let size = sizeFormate(rawData.FileSize)
|
const size = sizeFormate(rawData.FileSize)
|
||||||
types.push({ type: '128k', size, hash: rawData.FileHash })
|
types.push({ type: '128k', size, hash: rawData.FileHash })
|
||||||
_types['128k'] = {
|
_types['128k'] = {
|
||||||
size,
|
size,
|
||||||
@@ -25,7 +25,7 @@ export default {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
if (rawData.HQFileSize !== 0) {
|
if (rawData.HQFileSize !== 0) {
|
||||||
let size = sizeFormate(rawData.HQFileSize)
|
const size = sizeFormate(rawData.HQFileSize)
|
||||||
types.push({ type: '320k', size, hash: rawData.HQFileHash })
|
types.push({ type: '320k', size, hash: rawData.HQFileHash })
|
||||||
_types['320k'] = {
|
_types['320k'] = {
|
||||||
size,
|
size,
|
||||||
@@ -33,7 +33,7 @@ export default {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
if (rawData.SQFileSize !== 0) {
|
if (rawData.SQFileSize !== 0) {
|
||||||
let size = sizeFormate(rawData.SQFileSize)
|
const size = sizeFormate(rawData.SQFileSize)
|
||||||
types.push({ type: 'flac', size, hash: rawData.SQFileHash })
|
types.push({ type: 'flac', size, hash: rawData.SQFileHash })
|
||||||
_types.flac = {
|
_types.flac = {
|
||||||
size,
|
size,
|
||||||
@@ -41,7 +41,7 @@ export default {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
if (rawData.ResFileSize !== 0) {
|
if (rawData.ResFileSize !== 0) {
|
||||||
let size = sizeFormate(rawData.ResFileSize)
|
const size = sizeFormate(rawData.ResFileSize)
|
||||||
types.push({ type: 'flac24bit', size, hash: rawData.ResFileHash })
|
types.push({ type: 'flac24bit', size, hash: rawData.ResFileHash })
|
||||||
_types.flac24bit = {
|
_types.flac24bit = {
|
||||||
size,
|
size,
|
||||||
@@ -67,7 +67,7 @@ export default {
|
|||||||
}
|
}
|
||||||
},
|
},
|
||||||
handleResult(rawData) {
|
handleResult(rawData) {
|
||||||
let ids = new Set()
|
const ids = new Set()
|
||||||
const list = []
|
const list = []
|
||||||
rawData.forEach((item) => {
|
rawData.forEach((item) => {
|
||||||
const key = item.Audioid + item.FileHash
|
const key = item.Audioid + item.FileHash
|
||||||
@@ -89,7 +89,7 @@ export default {
|
|||||||
// http://newlyric.kuwo.cn/newlyric.lrc?62355680
|
// http://newlyric.kuwo.cn/newlyric.lrc?62355680
|
||||||
return this.musicSearch(str, page, limit).then((result) => {
|
return this.musicSearch(str, page, limit).then((result) => {
|
||||||
if (!result || result.error_code !== 0) return this.search(str, page, limit, retryNum)
|
if (!result || result.error_code !== 0) return this.search(str, page, limit, retryNum)
|
||||||
let list = this.handleResult(result.data.lists)
|
const list = this.handleResult(result.data.lists)
|
||||||
|
|
||||||
if (list == null) return this.search(str, page, limit, retryNum)
|
if (list == null) return this.search(str, page, limit, retryNum)
|
||||||
|
|
||||||
|
|||||||
@@ -36,7 +36,7 @@ export default {
|
|||||||
})
|
})
|
||||||
return requestObj.promise.then(({ body }) => {
|
return requestObj.promise.then(({ body }) => {
|
||||||
if (body.error_code !== 0) return Promise.reject(new Error('图片获取失败'))
|
if (body.error_code !== 0) return Promise.reject(new Error('图片获取失败'))
|
||||||
let info = body.data[0].info
|
const info = body.data[0].info
|
||||||
const img = info.imgsize ? info.image.replace('{size}', info.imgsize[0]) : info.image
|
const img = info.imgsize ? info.image.replace('{size}', info.imgsize[0]) : info.image
|
||||||
if (!img) return Promise.reject(new Error('Pic get failed'))
|
if (!img) return Promise.reject(new Error('Pic get failed'))
|
||||||
return img
|
return img
|
||||||
|
|||||||
@@ -71,10 +71,10 @@ export default {
|
|||||||
if (tryNum > 2) throw new Error('try max num')
|
if (tryNum > 2) throw new Error('try max num')
|
||||||
|
|
||||||
const { body } = await httpFetch(this.getSongListDetailUrl(id)).promise
|
const { body } = await httpFetch(this.getSongListDetailUrl(id)).promise
|
||||||
let listData = body.match(this.regExps.listData)
|
const listData = body.match(this.regExps.listData)
|
||||||
let listInfo = body.match(this.regExps.listInfo)
|
const listInfo = body.match(this.regExps.listInfo)
|
||||||
if (!listData) return this.getListDetailBySpecialId(id, page, ++tryNum)
|
if (!listData) return this.getListDetailBySpecialId(id, page, ++tryNum)
|
||||||
let list = await this.getMusicInfos(JSON.parse(listData[1]))
|
const list = await this.getMusicInfos(JSON.parse(listData[1]))
|
||||||
// listData = this.filterData(JSON.parse(listData[1]))
|
// listData = this.filterData(JSON.parse(listData[1]))
|
||||||
let name
|
let name
|
||||||
let pic
|
let pic
|
||||||
@@ -82,7 +82,7 @@ export default {
|
|||||||
name = listInfo[1]
|
name = listInfo[1]
|
||||||
pic = listInfo[2]
|
pic = listInfo[2]
|
||||||
}
|
}
|
||||||
let desc = this.parseHtmlDesc(body)
|
const desc = this.parseHtmlDesc(body)
|
||||||
|
|
||||||
return {
|
return {
|
||||||
list,
|
list,
|
||||||
@@ -116,7 +116,7 @@ export default {
|
|||||||
const result = []
|
const result = []
|
||||||
if (rawData.status !== 1) return result
|
if (rawData.status !== 1) return result
|
||||||
for (const key of Object.keys(rawData.data)) {
|
for (const key of Object.keys(rawData.data)) {
|
||||||
let tag = rawData.data[key]
|
const tag = rawData.data[key]
|
||||||
result.push({
|
result.push({
|
||||||
id: tag.special_id,
|
id: tag.special_id,
|
||||||
name: tag.special_name,
|
name: tag.special_name,
|
||||||
@@ -219,7 +219,7 @@ export default {
|
|||||||
},
|
},
|
||||||
|
|
||||||
createTask(hashs) {
|
createTask(hashs) {
|
||||||
let data = {
|
const data = {
|
||||||
area_code: '1',
|
area_code: '1',
|
||||||
show_privilege: 1,
|
show_privilege: 1,
|
||||||
show_album_info: '1',
|
show_album_info: '1',
|
||||||
@@ -233,13 +233,13 @@ export default {
|
|||||||
fields: 'album_info,author_name,audio_info,ori_audio_name,base,songname'
|
fields: 'album_info,author_name,audio_info,ori_audio_name,base,songname'
|
||||||
}
|
}
|
||||||
let list = hashs
|
let list = hashs
|
||||||
let tasks = []
|
const tasks = []
|
||||||
while (list.length) {
|
while (list.length) {
|
||||||
tasks.push(Object.assign({ data: list.slice(0, 100) }, data))
|
tasks.push(Object.assign({ data: list.slice(0, 100) }, data))
|
||||||
if (list.length < 100) break
|
if (list.length < 100) break
|
||||||
list = list.slice(100)
|
list = list.slice(100)
|
||||||
}
|
}
|
||||||
let url = 'http://gateway.kugou.com/v2/album_audio/audio'
|
const url = 'http://gateway.kugou.com/v2/album_audio/audio'
|
||||||
return tasks.map((task) =>
|
return tasks.map((task) =>
|
||||||
this.createHttp(url, {
|
this.createHttp(url, {
|
||||||
method: 'POST',
|
method: 'POST',
|
||||||
@@ -283,7 +283,7 @@ export default {
|
|||||||
// console.log(songInfo)
|
// console.log(songInfo)
|
||||||
// type 1单曲,2歌单,3电台,4酷狗码,5别人的播放队列
|
// type 1单曲,2歌单,3电台,4酷狗码,5别人的播放队列
|
||||||
let songList
|
let songList
|
||||||
let info = songInfo.info
|
const info = songInfo.info
|
||||||
switch (info.type) {
|
switch (info.type) {
|
||||||
case 2:
|
case 2:
|
||||||
if (!info.global_collection_id) return this.getListDetailBySpecialId(info.id)
|
if (!info.global_collection_id) return this.getListDetailBySpecialId(info.id)
|
||||||
@@ -319,7 +319,7 @@ export default {
|
|||||||
})
|
})
|
||||||
// console.log(songList)
|
// console.log(songList)
|
||||||
}
|
}
|
||||||
let list = await this.getMusicInfos(songList || songInfo.list)
|
const list = await this.getMusicInfos(songList || songInfo.list)
|
||||||
return {
|
return {
|
||||||
list,
|
list,
|
||||||
page: 1,
|
page: 1,
|
||||||
@@ -354,7 +354,7 @@ export default {
|
|||||||
this.getUserListDetail5(chain)
|
this.getUserListDetail5(chain)
|
||||||
)
|
)
|
||||||
}
|
}
|
||||||
let list = await this.getMusicInfos(songInfo.list)
|
const list = await this.getMusicInfos(songInfo.list)
|
||||||
// console.log(info, songInfo)
|
// console.log(info, songInfo)
|
||||||
return {
|
return {
|
||||||
list,
|
list,
|
||||||
@@ -373,7 +373,7 @@ export default {
|
|||||||
},
|
},
|
||||||
|
|
||||||
deDuplication(datas) {
|
deDuplication(datas) {
|
||||||
let ids = new Set()
|
const ids = new Set()
|
||||||
return datas.filter(({ hash }) => {
|
return datas.filter(({ hash }) => {
|
||||||
if (ids.has(hash)) return false
|
if (ids.has(hash)) return false
|
||||||
ids.add(hash)
|
ids.add(hash)
|
||||||
@@ -407,11 +407,10 @@ export default {
|
|||||||
return result.list[0].global_collection_id
|
return result.list[0].global_collection_id
|
||||||
},
|
},
|
||||||
|
|
||||||
|
|
||||||
async getUserListDetailByLink({ info }, link) {
|
async getUserListDetailByLink({ info }, link) {
|
||||||
let listInfo = info['0']
|
const listInfo = info['0']
|
||||||
let total = listInfo.count
|
let total = listInfo.count
|
||||||
let tasks = []
|
const tasks = []
|
||||||
let page = 0
|
let page = 0
|
||||||
while (total) {
|
while (total) {
|
||||||
const limit = total > 90 ? 90 : total
|
const limit = total > 90 ? 90 : total
|
||||||
@@ -449,7 +448,7 @@ export default {
|
|||||||
}
|
}
|
||||||
},
|
},
|
||||||
createGetListDetail2Task(id, total) {
|
createGetListDetail2Task(id, total) {
|
||||||
let tasks = []
|
const tasks = []
|
||||||
let page = 0
|
let page = 0
|
||||||
while (total) {
|
while (total) {
|
||||||
const limit = total > 300 ? 300 : total
|
const limit = total > 300 ? 300 : total
|
||||||
@@ -482,13 +481,13 @@ export default {
|
|||||||
return Promise.all(tasks).then(([...datas]) => datas.flat())
|
return Promise.all(tasks).then(([...datas]) => datas.flat())
|
||||||
},
|
},
|
||||||
async getUserListDetail2(global_collection_id) {
|
async getUserListDetail2(global_collection_id) {
|
||||||
let id = global_collection_id
|
const id = global_collection_id
|
||||||
if (id.length > 1000) throw new Error('get list error')
|
if (id.length > 1000) throw new Error('get list error')
|
||||||
const params =
|
const params =
|
||||||
'appid=1058&specialid=0&global_specialid=' +
|
'appid=1058&specialid=0&global_specialid=' +
|
||||||
id +
|
id +
|
||||||
'&format=jsonp&srcappid=2919&clientver=20000&clienttime=1586163242519&mid=1586163242519&uuid=1586163242519&dfid=-'
|
'&format=jsonp&srcappid=2919&clientver=20000&clienttime=1586163242519&mid=1586163242519&uuid=1586163242519&dfid=-'
|
||||||
let info = await this.createHttp(
|
const info = await this.createHttp(
|
||||||
`https://mobiles.kugou.com/api/v5/special/info_v2?${params}&signature=${signatureParams(params, 'web')}`,
|
`https://mobiles.kugou.com/api/v5/special/info_v2?${params}&signature=${signatureParams(params, 'web')}`,
|
||||||
{
|
{
|
||||||
headers: {
|
headers: {
|
||||||
@@ -502,7 +501,7 @@ export default {
|
|||||||
}
|
}
|
||||||
)
|
)
|
||||||
const songInfo = await this.createGetListDetail2Task(id, info.songcount)
|
const songInfo = await this.createGetListDetail2Task(id, info.songcount)
|
||||||
let list = await this.getMusicInfos(songInfo)
|
const list = await this.getMusicInfos(songInfo)
|
||||||
// console.log(info, songInfo, list)
|
// console.log(info, songInfo, list)
|
||||||
return {
|
return {
|
||||||
list,
|
list,
|
||||||
@@ -535,7 +534,7 @@ export default {
|
|||||||
},
|
},
|
||||||
|
|
||||||
async getUserListDetailByPcChain(chain) {
|
async getUserListDetailByPcChain(chain) {
|
||||||
let key = `${chain}_pc_list`
|
const key = `${chain}_pc_list`
|
||||||
if (this.cache.has(key)) return this.cache.get(key)
|
if (this.cache.has(key)) return this.cache.get(key)
|
||||||
const { body } = await httpFetch(`http://www.kugou.com/share/${chain}.html`, {
|
const { body } = await httpFetch(`http://www.kugou.com/share/${chain}.html`, {
|
||||||
headers: {
|
headers: {
|
||||||
@@ -596,7 +595,7 @@ export default {
|
|||||||
|
|
||||||
async getUserListDetailById(id, page, limit) {
|
async getUserListDetailById(id, page, limit) {
|
||||||
const signature = await handleSignature(id, page, limit)
|
const signature = await handleSignature(id, page, limit)
|
||||||
let info = await this.createHttp(
|
const info = await this.createHttp(
|
||||||
`https://pubsongscdn.kugou.com/v2/get_other_list_file?srcappid=2919&clientver=20000&appid=1058&type=0&module=playlist&page=${page}&pagesize=${limit}&specialid=${id}&signature=${signature}`,
|
`https://pubsongscdn.kugou.com/v2/get_other_list_file?srcappid=2919&clientver=20000&appid=1058&type=0&module=playlist&page=${page}&pagesize=${limit}&specialid=${id}&signature=${signature}`,
|
||||||
{
|
{
|
||||||
headers: {
|
headers: {
|
||||||
@@ -609,7 +608,7 @@ export default {
|
|||||||
)
|
)
|
||||||
|
|
||||||
// console.log(info)
|
// console.log(info)
|
||||||
let result = await this.getMusicInfos(info.info)
|
const result = await this.getMusicInfos(info.info)
|
||||||
// console.log(info, songInfo)
|
// console.log(info, songInfo)
|
||||||
return result
|
return result
|
||||||
},
|
},
|
||||||
@@ -622,7 +621,7 @@ export default {
|
|||||||
link.replace(/^.*?global_collection_id=(\w+)(?:&.*$|#.*$|$)/, '$1')
|
link.replace(/^.*?global_collection_id=(\w+)(?:&.*$|#.*$|$)/, '$1')
|
||||||
)
|
)
|
||||||
if (link.includes('gcid_')) {
|
if (link.includes('gcid_')) {
|
||||||
let gcid = link.match(/gcid_\w+/)?.[0]
|
const gcid = link.match(/gcid_\w+/)?.[0]
|
||||||
if (gcid) {
|
if (gcid) {
|
||||||
const global_collection_id = await this.decodeGcid(gcid)
|
const global_collection_id = await this.decodeGcid(gcid)
|
||||||
if (global_collection_id) return this.getUserListDetail2(global_collection_id)
|
if (global_collection_id) return this.getUserListDetail2(global_collection_id)
|
||||||
@@ -668,7 +667,7 @@ export default {
|
|||||||
location.replace(/^.*?global_collection_id=(\w+)(?:&.*$|#.*$|$)/, '$1')
|
location.replace(/^.*?global_collection_id=(\w+)(?:&.*$|#.*$|$)/, '$1')
|
||||||
)
|
)
|
||||||
if (location.includes('gcid_')) {
|
if (location.includes('gcid_')) {
|
||||||
let gcid = link.match(/gcid_\w+/)?.[0]
|
const gcid = link.match(/gcid_\w+/)?.[0]
|
||||||
if (gcid) {
|
if (gcid) {
|
||||||
const global_collection_id = await this.decodeGcid(gcid)
|
const global_collection_id = await this.decodeGcid(gcid)
|
||||||
if (global_collection_id) return this.getUserListDetail2(global_collection_id)
|
if (global_collection_id) return this.getUserListDetail2(global_collection_id)
|
||||||
@@ -699,7 +698,7 @@ export default {
|
|||||||
// console.log('location', location)
|
// console.log('location', location)
|
||||||
return this.getUserListDetail(location, page, ++retryNum)
|
return this.getUserListDetail(location, page, ++retryNum)
|
||||||
}
|
}
|
||||||
if (typeof body == 'string') {
|
if (typeof body === 'string') {
|
||||||
let global_collection_id = body.match(/"global_collection_id":"(\w+)"/)?.[1]
|
let global_collection_id = body.match(/"global_collection_id":"(\w+)"/)?.[1]
|
||||||
if (!global_collection_id) {
|
if (!global_collection_id) {
|
||||||
let gcid = body.match(/"encode_gic":"(\w+)"/)?.[1]
|
let gcid = body.match(/"encode_gic":"(\w+)"/)?.[1]
|
||||||
@@ -736,7 +735,7 @@ export default {
|
|||||||
const types = []
|
const types = []
|
||||||
const _types = {}
|
const _types = {}
|
||||||
if (item.filesize !== 0) {
|
if (item.filesize !== 0) {
|
||||||
let size = sizeFormate(item.filesize)
|
const size = sizeFormate(item.filesize)
|
||||||
types.push({ type: '128k', size, hash: item.hash })
|
types.push({ type: '128k', size, hash: item.hash })
|
||||||
_types['128k'] = {
|
_types['128k'] = {
|
||||||
size,
|
size,
|
||||||
@@ -744,7 +743,7 @@ export default {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
if (item.filesize_320 !== 0) {
|
if (item.filesize_320 !== 0) {
|
||||||
let size = sizeFormate(item.filesize_320)
|
const size = sizeFormate(item.filesize_320)
|
||||||
types.push({ type: '320k', size, hash: item.hash_320 })
|
types.push({ type: '320k', size, hash: item.hash_320 })
|
||||||
_types['320k'] = {
|
_types['320k'] = {
|
||||||
size,
|
size,
|
||||||
@@ -752,7 +751,7 @@ export default {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
if (item.filesize_ape !== 0) {
|
if (item.filesize_ape !== 0) {
|
||||||
let size = sizeFormate(item.filesize_ape)
|
const size = sizeFormate(item.filesize_ape)
|
||||||
types.push({ type: 'ape', size, hash: item.hash_ape })
|
types.push({ type: 'ape', size, hash: item.hash_ape })
|
||||||
_types.ape = {
|
_types.ape = {
|
||||||
size,
|
size,
|
||||||
@@ -760,7 +759,7 @@ export default {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
if (item.filesize_flac !== 0) {
|
if (item.filesize_flac !== 0) {
|
||||||
let size = sizeFormate(item.filesize_flac)
|
const size = sizeFormate(item.filesize_flac)
|
||||||
types.push({ type: 'flac', size, hash: item.hash_flac })
|
types.push({ type: 'flac', size, hash: item.hash_flac })
|
||||||
_types.flac = {
|
_types.flac = {
|
||||||
size,
|
size,
|
||||||
@@ -850,8 +849,8 @@ export default {
|
|||||||
// hash list filter
|
// hash list filter
|
||||||
filterData2(rawList) {
|
filterData2(rawList) {
|
||||||
// console.log(rawList)
|
// console.log(rawList)
|
||||||
let ids = new Set()
|
const ids = new Set()
|
||||||
let list = []
|
const list = []
|
||||||
rawList.forEach((item) => {
|
rawList.forEach((item) => {
|
||||||
if (!item) return
|
if (!item) return
|
||||||
if (ids.has(item.audio_info.audio_id)) return
|
if (ids.has(item.audio_info.audio_id)) return
|
||||||
@@ -859,7 +858,7 @@ export default {
|
|||||||
const types = []
|
const types = []
|
||||||
const _types = {}
|
const _types = {}
|
||||||
if (item.audio_info.filesize !== '0') {
|
if (item.audio_info.filesize !== '0') {
|
||||||
let size = sizeFormate(parseInt(item.audio_info.filesize))
|
const size = sizeFormate(parseInt(item.audio_info.filesize))
|
||||||
types.push({ type: '128k', size, hash: item.audio_info.hash })
|
types.push({ type: '128k', size, hash: item.audio_info.hash })
|
||||||
_types['128k'] = {
|
_types['128k'] = {
|
||||||
size,
|
size,
|
||||||
@@ -867,7 +866,7 @@ export default {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
if (item.audio_info.filesize_320 !== '0') {
|
if (item.audio_info.filesize_320 !== '0') {
|
||||||
let size = sizeFormate(parseInt(item.audio_info.filesize_320))
|
const size = sizeFormate(parseInt(item.audio_info.filesize_320))
|
||||||
types.push({ type: '320k', size, hash: item.audio_info.hash_320 })
|
types.push({ type: '320k', size, hash: item.audio_info.hash_320 })
|
||||||
_types['320k'] = {
|
_types['320k'] = {
|
||||||
size,
|
size,
|
||||||
@@ -875,7 +874,7 @@ export default {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
if (item.audio_info.filesize_flac !== '0') {
|
if (item.audio_info.filesize_flac !== '0') {
|
||||||
let size = sizeFormate(parseInt(item.audio_info.filesize_flac))
|
const size = sizeFormate(parseInt(item.audio_info.filesize_flac))
|
||||||
types.push({ type: 'flac', size, hash: item.audio_info.hash_flac })
|
types.push({ type: 'flac', size, hash: item.audio_info.hash_flac })
|
||||||
_types.flac = {
|
_types.flac = {
|
||||||
size,
|
size,
|
||||||
@@ -883,7 +882,7 @@ export default {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
if (item.audio_info.filesize_high !== '0') {
|
if (item.audio_info.filesize_high !== '0') {
|
||||||
let size = sizeFormate(parseInt(item.audio_info.filesize_high))
|
const size = sizeFormate(parseInt(item.audio_info.filesize_high))
|
||||||
types.push({ type: 'flac24bit', size, hash: item.audio_info.hash_high })
|
types.push({ type: 'flac24bit', size, hash: item.audio_info.hash_high })
|
||||||
_types.flac24bit = {
|
_types.flac24bit = {
|
||||||
size,
|
size,
|
||||||
@@ -928,7 +927,7 @@ export default {
|
|||||||
|
|
||||||
// 获取列表数据
|
// 获取列表数据
|
||||||
getList(sortId, tagId, page) {
|
getList(sortId, tagId, page) {
|
||||||
let tasks = [this.getSongList(sortId, tagId, page)]
|
const tasks = [this.getSongList(sortId, tagId, page)]
|
||||||
tasks.push(
|
tasks.push(
|
||||||
this.currentTagInfo.id === tagId
|
this.currentTagInfo.id === tagId
|
||||||
? Promise.resolve(this.currentTagInfo.info)
|
? Promise.resolve(this.currentTagInfo.info)
|
||||||
@@ -965,7 +964,7 @@ export default {
|
|||||||
},
|
},
|
||||||
|
|
||||||
getDetailPageUrl(id) {
|
getDetailPageUrl(id) {
|
||||||
if (typeof id == 'string') {
|
if (typeof id === 'string') {
|
||||||
if (/^https?:\/\//.test(id)) return id
|
if (/^https?:\/\//.test(id)) return id
|
||||||
id = id.replace('id_', '')
|
id = id.replace('id_', '')
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -13,9 +13,9 @@ import { httpFetch } from '../../request'
|
|||||||
export const signatureParams = (params, platform = 'android', body = '') => {
|
export const signatureParams = (params, platform = 'android', body = '') => {
|
||||||
let keyparam = 'OIlwieks28dk2k092lksi2UIkp'
|
let keyparam = 'OIlwieks28dk2k092lksi2UIkp'
|
||||||
if (platform === 'web') keyparam = 'NVPh5oo715z5DIWAeQlhMDsWXXQV4hwt'
|
if (platform === 'web') keyparam = 'NVPh5oo715z5DIWAeQlhMDsWXXQV4hwt'
|
||||||
let param_list = params.split('&')
|
const param_list = params.split('&')
|
||||||
param_list.sort()
|
param_list.sort()
|
||||||
let sign_params = `${keyparam}${param_list.join('')}${body}${keyparam}`
|
const sign_params = `${keyparam}${param_list.join('')}${body}${keyparam}`
|
||||||
return toMD5(sign_params)
|
return toMD5(sign_params)
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|||||||
@@ -10,9 +10,9 @@ export default {
|
|||||||
// console.log(rawList)
|
// console.log(rawList)
|
||||||
// console.log(rawList.length, rawList2.length)
|
// console.log(rawList.length, rawList2.length)
|
||||||
return rawList.map((item, inedx) => {
|
return rawList.map((item, inedx) => {
|
||||||
let formats = item.formats.split('|')
|
const formats = item.formats.split('|')
|
||||||
let types = []
|
const types = []
|
||||||
let _types = {}
|
const _types = {}
|
||||||
if (formats.includes('MP3128')) {
|
if (formats.includes('MP3128')) {
|
||||||
types.push({ type: '128k', size: null })
|
types.push({ type: '128k', size: null })
|
||||||
_types['128k'] = {
|
_types['128k'] = {
|
||||||
|
|||||||
@@ -68,13 +68,13 @@ const kw = {
|
|||||||
},
|
},
|
||||||
|
|
||||||
getMusicUrls(musicInfo, cb) {
|
getMusicUrls(musicInfo, cb) {
|
||||||
let tasks = []
|
const tasks = []
|
||||||
let songId = musicInfo.songmid
|
const songId = musicInfo.songmid
|
||||||
musicInfo.types.forEach((type) => {
|
musicInfo.types.forEach((type) => {
|
||||||
tasks.push(kw.getMusicUrl(songId, type.type).promise)
|
tasks.push(kw.getMusicUrl(songId, type.type).promise)
|
||||||
})
|
})
|
||||||
Promise.all(tasks).then((urlInfo) => {
|
Promise.all(tasks).then((urlInfo) => {
|
||||||
let typeUrl = {}
|
const typeUrl = {}
|
||||||
urlInfo.forEach((info) => {
|
urlInfo.forEach((info) => {
|
||||||
typeUrl[info.type] = info.url
|
typeUrl[info.type] = info.url
|
||||||
})
|
})
|
||||||
|
|||||||
@@ -206,7 +206,7 @@ export default {
|
|||||||
|
|
||||||
filterBoardsData(rawList) {
|
filterBoardsData(rawList) {
|
||||||
// console.log(rawList)
|
// console.log(rawList)
|
||||||
let list = []
|
const list = []
|
||||||
for (const board of rawList) {
|
for (const board of rawList) {
|
||||||
if (board.source != '1') continue
|
if (board.source != '1') continue
|
||||||
list.push({
|
list.push({
|
||||||
|
|||||||
@@ -148,8 +148,8 @@ export default {
|
|||||||
}, */
|
}, */
|
||||||
sortLrcArr(arr) {
|
sortLrcArr(arr) {
|
||||||
const lrcSet = new Set()
|
const lrcSet = new Set()
|
||||||
let lrc = []
|
const lrc = []
|
||||||
let lrcT = []
|
const lrcT = []
|
||||||
|
|
||||||
let isLyricx = false
|
let isLyricx = false
|
||||||
for (const item of arr) {
|
for (const item of arr) {
|
||||||
@@ -192,11 +192,11 @@ export default {
|
|||||||
},
|
},
|
||||||
parseLrc(lrc) {
|
parseLrc(lrc) {
|
||||||
const lines = lrc.split(/\r\n|\r|\n/)
|
const lines = lrc.split(/\r\n|\r|\n/)
|
||||||
let tags = []
|
const tags = []
|
||||||
let lrcArr = []
|
const lrcArr = []
|
||||||
for (let i = 0; i < lines.length; i++) {
|
for (let i = 0; i < lines.length; i++) {
|
||||||
const line = lines[i].trim()
|
const line = lines[i].trim()
|
||||||
let result = timeExp.exec(line)
|
const result = timeExp.exec(line)
|
||||||
if (result) {
|
if (result) {
|
||||||
const text = line.replace(timeExp, '').trim()
|
const text = line.replace(timeExp, '').trim()
|
||||||
let time = RegExp.$1
|
let time = RegExp.$1
|
||||||
|
|||||||
@@ -32,7 +32,7 @@ export default {
|
|||||||
// console.log(rawData)
|
// console.log(rawData)
|
||||||
for (let i = 0; i < rawData.length; i++) {
|
for (let i = 0; i < rawData.length; i++) {
|
||||||
const info = rawData[i]
|
const info = rawData[i]
|
||||||
let songId = info.MUSICRID.replace('MUSIC_', '')
|
const songId = info.MUSICRID.replace('MUSIC_', '')
|
||||||
// const format = (info.FORMATS || info.formats).split('|')
|
// const format = (info.FORMATS || info.formats).split('|')
|
||||||
|
|
||||||
if (!info.N_MINFO) {
|
if (!info.N_MINFO) {
|
||||||
@@ -43,7 +43,7 @@ export default {
|
|||||||
const types = []
|
const types = []
|
||||||
const _types = {}
|
const _types = {}
|
||||||
|
|
||||||
let infoArr = info.N_MINFO.split(';')
|
const infoArr = info.N_MINFO.split(';')
|
||||||
for (let info of infoArr) {
|
for (let info of infoArr) {
|
||||||
info = info.match(this.regExps.mInfo)
|
info = info.match(this.regExps.mInfo)
|
||||||
if (info) {
|
if (info) {
|
||||||
@@ -77,7 +77,7 @@ export default {
|
|||||||
}
|
}
|
||||||
types.reverse()
|
types.reverse()
|
||||||
|
|
||||||
let interval = parseInt(info.DURATION)
|
const interval = parseInt(info.DURATION)
|
||||||
|
|
||||||
result.push({
|
result.push({
|
||||||
name: decodeName(info.SONGNAME),
|
name: decodeName(info.SONGNAME),
|
||||||
@@ -109,7 +109,7 @@ export default {
|
|||||||
// console.log(result)
|
// console.log(result)
|
||||||
if (!result || (result.TOTAL !== '0' && result.SHOW === '0'))
|
if (!result || (result.TOTAL !== '0' && result.SHOW === '0'))
|
||||||
return this.search(str, page, limit, ++retryNum)
|
return this.search(str, page, limit, ++retryNum)
|
||||||
let list = this.handleResult(result.abslist)
|
const list = this.handleResult(result.abslist)
|
||||||
|
|
||||||
if (list == null) return this.search(str, page, limit, ++retryNum)
|
if (list == null) return this.search(str, page, limit, ++retryNum)
|
||||||
|
|
||||||
|
|||||||
@@ -95,7 +95,7 @@ export default {
|
|||||||
let id
|
let id
|
||||||
let type
|
let type
|
||||||
if (tagId) {
|
if (tagId) {
|
||||||
let arr = tagId.split('-')
|
const arr = tagId.split('-')
|
||||||
id = arr[0]
|
id = arr[0]
|
||||||
type = arr[1]
|
type = arr[1]
|
||||||
} else {
|
} else {
|
||||||
@@ -235,9 +235,9 @@ export default {
|
|||||||
|
|
||||||
filterBDListDetail(rawList) {
|
filterBDListDetail(rawList) {
|
||||||
return rawList.map((item) => {
|
return rawList.map((item) => {
|
||||||
let types = []
|
const types = []
|
||||||
let _types = {}
|
const _types = {}
|
||||||
for (let info of item.audios) {
|
for (const info of item.audios) {
|
||||||
info.size = info.size?.toLocaleUpperCase()
|
info.size = info.size?.toLocaleUpperCase()
|
||||||
switch (info.bitrate) {
|
switch (info.bitrate) {
|
||||||
case '4000':
|
case '4000':
|
||||||
@@ -415,9 +415,9 @@ export default {
|
|||||||
filterListDetail(rawData) {
|
filterListDetail(rawData) {
|
||||||
// console.log(rawData)
|
// console.log(rawData)
|
||||||
return rawData.map((item) => {
|
return rawData.map((item) => {
|
||||||
let infoArr = item.N_MINFO.split(';')
|
const infoArr = item.N_MINFO.split(';')
|
||||||
let types = []
|
const types = []
|
||||||
let _types = {}
|
const _types = {}
|
||||||
for (let info of infoArr) {
|
for (let info of infoArr) {
|
||||||
info = info.match(this.regExps.mInfo)
|
info = info.match(this.regExps.mInfo)
|
||||||
if (info) {
|
if (info) {
|
||||||
@@ -478,7 +478,7 @@ export default {
|
|||||||
getDetailPageUrl(id) {
|
getDetailPageUrl(id) {
|
||||||
if (/[?&:/]/.test(id)) id = id.replace(this.regExps.listDetailLink, '$1')
|
if (/[?&:/]/.test(id)) id = id.replace(this.regExps.listDetailLink, '$1')
|
||||||
else if (/^digest-/.test(id)) {
|
else if (/^digest-/.test(id)) {
|
||||||
let result = id.split('__')
|
const result = id.split('__')
|
||||||
id = result[1]
|
id = result[1]
|
||||||
}
|
}
|
||||||
return `http://www.kuwo.cn/playlist_detail/${id}`
|
return `http://www.kuwo.cn/playlist_detail/${id}`
|
||||||
|
|||||||
@@ -111,8 +111,8 @@ export const lrcTools = {
|
|||||||
// 使用原始的酷我音乐时间计算逻辑,但输出绝对时间戳
|
// 使用原始的酷我音乐时间计算逻辑,但输出绝对时间戳
|
||||||
const offset = parseInt(str)
|
const offset = parseInt(str)
|
||||||
const offset2 = parseInt(str2)
|
const offset2 = parseInt(str2)
|
||||||
let startTime = Math.abs((offset + offset2) / (this.offset * 2))
|
const startTime = Math.abs((offset + offset2) / (this.offset * 2))
|
||||||
let duration = Math.abs((offset - offset2) / (this.offset2 * 2))
|
const duration = Math.abs((offset - offset2) / (this.offset2 * 2))
|
||||||
|
|
||||||
// 转换为基于行开始时间的绝对时间戳
|
// 转换为基于行开始时间的绝对时间戳
|
||||||
const absoluteStartTime = lineStartTime + startTime
|
const absoluteStartTime = lineStartTime + startTime
|
||||||
|
|||||||
@@ -9,7 +9,7 @@ export default {
|
|||||||
async getComment(musicInfo, page = 1, limit = 10) {
|
async getComment(musicInfo, page = 1, limit = 10) {
|
||||||
if (this._requestObj) this._requestObj.cancelHttp()
|
if (this._requestObj) this._requestObj.cancelHttp()
|
||||||
if (!musicInfo.songId) {
|
if (!musicInfo.songId) {
|
||||||
let id = await getSongId(musicInfo)
|
const id = await getSongId(musicInfo)
|
||||||
if (!id) throw new Error('获取评论失败')
|
if (!id) throw new Error('获取评论失败')
|
||||||
musicInfo.songId = id
|
musicInfo.songId = id
|
||||||
}
|
}
|
||||||
@@ -40,7 +40,7 @@ export default {
|
|||||||
if (this._requestObj2) this._requestObj2.cancelHttp()
|
if (this._requestObj2) this._requestObj2.cancelHttp()
|
||||||
|
|
||||||
if (!musicInfo.songId) {
|
if (!musicInfo.songId) {
|
||||||
let id = await getSongId(musicInfo)
|
const id = await getSongId(musicInfo)
|
||||||
if (!id) throw new Error('获取评论失败')
|
if (!id) throw new Error('获取评论失败')
|
||||||
musicInfo.songId = id
|
musicInfo.songId = id
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -102,7 +102,7 @@ export default {
|
|||||||
},
|
},
|
||||||
filterBoardsData(rawList) {
|
filterBoardsData(rawList) {
|
||||||
// console.log(rawList)
|
// console.log(rawList)
|
||||||
let list = []
|
const list = []
|
||||||
for (const board of rawList) {
|
for (const board of rawList) {
|
||||||
if (board.template != 'group1') continue
|
if (board.template != 'group1') continue
|
||||||
for (const item of board.itemList) {
|
for (const item of board.itemList) {
|
||||||
@@ -112,7 +112,7 @@ export default {
|
|||||||
)
|
)
|
||||||
continue
|
continue
|
||||||
|
|
||||||
let data = item.displayLogId.param
|
const data = item.displayLogId.param
|
||||||
list.push({
|
list.push({
|
||||||
id: 'mg__' + data.rankId,
|
id: 'mg__' + data.rankId,
|
||||||
name: data.rankName,
|
name: data.rankName,
|
||||||
@@ -164,7 +164,7 @@ export default {
|
|||||||
},
|
},
|
||||||
|
|
||||||
getDetailPageUrl(id) {
|
getDetailPageUrl(id) {
|
||||||
if (typeof id == 'string') id = id.replace('mg__', '')
|
if (typeof id === 'string') id = id.replace('mg__', '')
|
||||||
for (const item of boardList) {
|
for (const item of boardList) {
|
||||||
if (item.bangid == id) {
|
if (item.bangid == id) {
|
||||||
return `https://music.migu.cn/v3/music/top/${item.webId}`
|
return `https://music.migu.cn/v3/music/top/${item.webId}`
|
||||||
|
|||||||
@@ -16,21 +16,21 @@ const mrcTools = {
|
|||||||
|
|
||||||
for (const line of lines) {
|
for (const line of lines) {
|
||||||
if (line.length < 6) continue
|
if (line.length < 6) continue
|
||||||
let result = this.rxps.lineTime.exec(line)
|
const result = this.rxps.lineTime.exec(line)
|
||||||
if (!result) continue
|
if (!result) continue
|
||||||
|
|
||||||
const startTime = parseInt(result[1])
|
const startTime = parseInt(result[1])
|
||||||
let time = startTime
|
let time = startTime
|
||||||
let ms = time % 1000
|
const ms = time % 1000
|
||||||
time /= 1000
|
time /= 1000
|
||||||
let m = parseInt(time / 60)
|
const m = parseInt(time / 60)
|
||||||
.toString()
|
.toString()
|
||||||
.padStart(2, '0')
|
.padStart(2, '0')
|
||||||
time %= 60
|
time %= 60
|
||||||
let s = parseInt(time).toString().padStart(2, '0')
|
const s = parseInt(time).toString().padStart(2, '0')
|
||||||
time = `${m}:${s}.${ms}`
|
time = `${m}:${s}.${ms}`
|
||||||
|
|
||||||
let words = line.replace(this.rxps.lineTime, '')
|
const words = line.replace(this.rxps.lineTime, '')
|
||||||
|
|
||||||
lrcLines.push(`[${time}]${words.replace(this.rxps.wordTimeAll, '')}`)
|
lrcLines.push(`[${time}]${words.replace(this.rxps.wordTimeAll, '')}`)
|
||||||
|
|
||||||
@@ -100,11 +100,11 @@ export default {
|
|||||||
getLyricWeb(songInfo, tryNum = 0) {
|
getLyricWeb(songInfo, tryNum = 0) {
|
||||||
// console.log(songInfo.copyrightId)
|
// console.log(songInfo.copyrightId)
|
||||||
if (songInfo.lrcUrl) {
|
if (songInfo.lrcUrl) {
|
||||||
let requestObj = httpFetch(songInfo.lrcUrl)
|
const requestObj = httpFetch(songInfo.lrcUrl)
|
||||||
requestObj.promise = requestObj.promise.then(({ body, statusCode }) => {
|
requestObj.promise = requestObj.promise.then(({ body, statusCode }) => {
|
||||||
if (statusCode !== 200) {
|
if (statusCode !== 200) {
|
||||||
if (tryNum > 5) return Promise.reject(new Error('歌词获取失败'))
|
if (tryNum > 5) return Promise.reject(new Error('歌词获取失败'))
|
||||||
let tryRequestObj = this.getLyricWeb(songInfo, ++tryNum)
|
const tryRequestObj = this.getLyricWeb(songInfo, ++tryNum)
|
||||||
requestObj.cancelHttp = tryRequestObj.cancelHttp.bind(tryRequestObj)
|
requestObj.cancelHttp = tryRequestObj.cancelHttp.bind(tryRequestObj)
|
||||||
return tryRequestObj.promise
|
return tryRequestObj.promise
|
||||||
}
|
}
|
||||||
@@ -115,7 +115,7 @@ export default {
|
|||||||
})
|
})
|
||||||
return requestObj
|
return requestObj
|
||||||
} else {
|
} else {
|
||||||
let requestObj = httpFetch(
|
const requestObj = httpFetch(
|
||||||
`https://music.migu.cn/v3/api/music/audioPlayer/getLyric?copyrightId=${songInfo.copyrightId}`,
|
`https://music.migu.cn/v3/api/music/audioPlayer/getLyric?copyrightId=${songInfo.copyrightId}`,
|
||||||
{
|
{
|
||||||
headers: {
|
headers: {
|
||||||
@@ -126,7 +126,7 @@ export default {
|
|||||||
requestObj.promise = requestObj.promise.then(({ body }) => {
|
requestObj.promise = requestObj.promise.then(({ body }) => {
|
||||||
if (body.returnCode !== '000000' || !body.lyric) {
|
if (body.returnCode !== '000000' || !body.lyric) {
|
||||||
if (tryNum > 5) return Promise.reject(new Error('Get lyric failed'))
|
if (tryNum > 5) return Promise.reject(new Error('Get lyric failed'))
|
||||||
let tryRequestObj = this.getLyricWeb(songInfo, ++tryNum)
|
const tryRequestObj = this.getLyricWeb(songInfo, ++tryNum)
|
||||||
requestObj.cancelHttp = tryRequestObj.cancelHttp.bind(tryRequestObj)
|
requestObj.cancelHttp = tryRequestObj.cancelHttp.bind(tryRequestObj)
|
||||||
return tryRequestObj.promise
|
return tryRequestObj.promise
|
||||||
}
|
}
|
||||||
@@ -140,9 +140,9 @@ export default {
|
|||||||
},
|
},
|
||||||
|
|
||||||
getLyric(songInfo) {
|
getLyric(songInfo) {
|
||||||
let requestObj = mrcTools.getLyric(songInfo)
|
const requestObj = mrcTools.getLyric(songInfo)
|
||||||
requestObj.promise = requestObj.promise.catch(() => {
|
requestObj.promise = requestObj.promise.catch(() => {
|
||||||
let webRequestObj = this.getLyricWeb(songInfo)
|
const webRequestObj = this.getLyricWeb(songInfo)
|
||||||
requestObj.cancelHttp = webRequestObj.cancelHttp.bind(webRequestObj)
|
requestObj.cancelHttp = webRequestObj.cancelHttp.bind(webRequestObj)
|
||||||
return webRequestObj.promise
|
return webRequestObj.promise
|
||||||
})
|
})
|
||||||
|
|||||||
@@ -4,13 +4,13 @@ import { formatSingerName } from '../utils'
|
|||||||
|
|
||||||
const createGetMusicInfosTask = (ids) => {
|
const createGetMusicInfosTask = (ids) => {
|
||||||
let list = ids
|
let list = ids
|
||||||
let tasks = []
|
const tasks = []
|
||||||
while (list.length) {
|
while (list.length) {
|
||||||
tasks.push(list.slice(0, 100))
|
tasks.push(list.slice(0, 100))
|
||||||
if (list.length < 100) break
|
if (list.length < 100) break
|
||||||
list = list.slice(100)
|
list = list.slice(100)
|
||||||
}
|
}
|
||||||
let url = 'https://c.musicapp.migu.cn/MIGUM2.0/v1.0/content/resourceinfo.do?resourceType=2'
|
const url = 'https://c.musicapp.migu.cn/MIGUM2.0/v1.0/content/resourceinfo.do?resourceType=2'
|
||||||
return Promise.all(
|
return Promise.all(
|
||||||
tasks.map((task) =>
|
tasks.map((task) =>
|
||||||
createHttpFetch(url, {
|
createHttpFetch(url, {
|
||||||
@@ -25,7 +25,7 @@ const createGetMusicInfosTask = (ids) => {
|
|||||||
|
|
||||||
export const filterMusicInfoList = (rawList) => {
|
export const filterMusicInfoList = (rawList) => {
|
||||||
// console.log(rawList)
|
// console.log(rawList)
|
||||||
let ids = new Set()
|
const ids = new Set()
|
||||||
const list = []
|
const list = []
|
||||||
rawList.forEach((item) => {
|
rawList.forEach((item) => {
|
||||||
if (!item.songId || ids.has(item.songId)) return
|
if (!item.songId || ids.has(item.songId)) return
|
||||||
|
|||||||
@@ -212,7 +212,7 @@ export default {
|
|||||||
return Promise.reject(new Error(result ? result.info : '搜索失败'))
|
return Promise.reject(new Error(result ? result.info : '搜索失败'))
|
||||||
const songResultData = result.songResultData || { resultList: [], totalCount: 0 }
|
const songResultData = result.songResultData || { resultList: [], totalCount: 0 }
|
||||||
|
|
||||||
let list = this.filterData(songResultData.resultList)
|
const list = this.filterData(songResultData.resultList)
|
||||||
if (list == null) return this.search(str, page, limit, retryNum)
|
if (list == null) return this.search(str, page, limit, retryNum)
|
||||||
|
|
||||||
this.total = parseInt(songResultData.totalCount)
|
this.total = parseInt(songResultData.totalCount)
|
||||||
|
|||||||
@@ -3,7 +3,7 @@ import getSongId from './songId'
|
|||||||
|
|
||||||
export default {
|
export default {
|
||||||
async getPicUrl(songId, tryNum = 0) {
|
async getPicUrl(songId, tryNum = 0) {
|
||||||
let requestObj = httpFetch(
|
const requestObj = httpFetch(
|
||||||
`http://music.migu.cn/v3/api/music/audioPlayer/getSongPic?songId=${songId}`,
|
`http://music.migu.cn/v3/api/music/audioPlayer/getSongPic?songId=${songId}`,
|
||||||
{
|
{
|
||||||
headers: {
|
headers: {
|
||||||
@@ -14,7 +14,7 @@ export default {
|
|||||||
requestObj.promise.then(({ body }) => {
|
requestObj.promise.then(({ body }) => {
|
||||||
if (body.returnCode !== '000000') {
|
if (body.returnCode !== '000000') {
|
||||||
if (tryNum > 5) return Promise.reject(new Error('图片获取失败'))
|
if (tryNum > 5) return Promise.reject(new Error('图片获取失败'))
|
||||||
let tryRequestObj = this.getPic(songId, ++tryNum)
|
const tryRequestObj = this.getPic(songId, ++tryNum)
|
||||||
requestObj.cancelHttp = tryRequestObj.cancelHttp.bind(tryRequestObj)
|
requestObj.cancelHttp = tryRequestObj.cancelHttp.bind(tryRequestObj)
|
||||||
return tryRequestObj.promise
|
return tryRequestObj.promise
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -22,15 +22,15 @@ const teaDecrypt = (data, key) => {
|
|||||||
let j2 = data[0]
|
let j2 = data[0]
|
||||||
let j3 = toLong((6n + 52n / lengthBitint) * DELTA)
|
let j3 = toLong((6n + 52n / lengthBitint) * DELTA)
|
||||||
while (true) {
|
while (true) {
|
||||||
let j4 = j3
|
const j4 = j3
|
||||||
if (j4 == 0n) break
|
if (j4 == 0n) break
|
||||||
let j5 = toLong(3n & toLong(j4 >> 2n))
|
const j5 = toLong(3n & toLong(j4 >> 2n))
|
||||||
let j6 = lengthBitint
|
let j6 = lengthBitint
|
||||||
while (true) {
|
while (true) {
|
||||||
j6--
|
j6--
|
||||||
if (j6 > 0n) {
|
if (j6 > 0n) {
|
||||||
let j7 = data[j6 - 1n]
|
const j7 = data[j6 - 1n]
|
||||||
let i = j6
|
const i = j6
|
||||||
j2 = toLong(
|
j2 = toLong(
|
||||||
data[i] -
|
data[i] -
|
||||||
(toLong(toLong(j2 ^ j4) + toLong(j7 ^ key[toLong(toLong(3n & j6) ^ j5)])) ^
|
(toLong(toLong(j2 ^ j4) + toLong(j7 ^ key[toLong(toLong(3n & j6) ^ j5)])) ^
|
||||||
@@ -42,7 +42,7 @@ const teaDecrypt = (data, key) => {
|
|||||||
data[i] = j2
|
data[i] = j2
|
||||||
} else break
|
} else break
|
||||||
}
|
}
|
||||||
let j8 = data[lengthBitint - 1n]
|
const j8 = data[lengthBitint - 1n]
|
||||||
j2 = toLong(
|
j2 = toLong(
|
||||||
data[0n] -
|
data[0n] -
|
||||||
toLong(
|
toLong(
|
||||||
@@ -89,7 +89,7 @@ const toBigintArray = (data) => {
|
|||||||
const MAX = 9223372036854775807n
|
const MAX = 9223372036854775807n
|
||||||
const MIN = -9223372036854775808n
|
const MIN = -9223372036854775808n
|
||||||
const toLong = (str) => {
|
const toLong = (str) => {
|
||||||
const num = typeof str == 'string' ? BigInt('0x' + str) : str
|
const num = typeof str === 'string' ? BigInt('0x' + str) : str
|
||||||
if (num > MAX) return toLong(num - (1n << 64n))
|
if (num > MAX) return toLong(num - (1n << 64n))
|
||||||
else if (num < MIN) return toLong(num + (1n << 64n))
|
else if (num < MIN) return toLong(num + (1n << 64n))
|
||||||
return num
|
return num
|
||||||
|
|||||||
@@ -197,10 +197,10 @@ export default {
|
|||||||
},
|
},
|
||||||
filterNewComment(rawList) {
|
filterNewComment(rawList) {
|
||||||
return rawList.map((item) => {
|
return rawList.map((item) => {
|
||||||
let time = this.formatTime(item.time)
|
const time = this.formatTime(item.time)
|
||||||
let timeStr = time ? dateFormat2(time) : null
|
const timeStr = time ? dateFormat2(time) : null
|
||||||
if (item.middlecommentcontent) {
|
if (item.middlecommentcontent) {
|
||||||
let firstItem = item.middlecommentcontent[0]
|
const firstItem = item.middlecommentcontent[0]
|
||||||
firstItem.avatarurl = item.avatarurl
|
firstItem.avatarurl = item.avatarurl
|
||||||
firstItem.praisenum = item.praisenum
|
firstItem.praisenum = item.praisenum
|
||||||
item.avatarurl = null
|
item.avatarurl = null
|
||||||
@@ -270,12 +270,12 @@ export default {
|
|||||||
})
|
})
|
||||||
},
|
},
|
||||||
replaceEmoji(msg) {
|
replaceEmoji(msg) {
|
||||||
let rxp = /^\[em\](e\d+)\[\/em\]$/
|
const rxp = /^\[em\](e\d+)\[\/em\]$/
|
||||||
let result = msg.match(/\[em\]e\d+\[\/em\]/g)
|
let result = msg.match(/\[em\]e\d+\[\/em\]/g)
|
||||||
if (!result) return msg
|
if (!result) return msg
|
||||||
result = Array.from(new Set(result))
|
result = Array.from(new Set(result))
|
||||||
for (let item of result) {
|
for (const item of result) {
|
||||||
let code = item.replace(rxp, '$1')
|
const code = item.replace(rxp, '$1')
|
||||||
msg = msg.replace(
|
msg = msg.replace(
|
||||||
new RegExp(item.replace('[em]', '\\[em\\]').replace('[/em]', '\\[\\/em\\]'), 'g'),
|
new RegExp(item.replace('[em]', '\\[em\\]').replace('[/em]', '\\[\\/em\\]'), 'g'),
|
||||||
emojis[code] || ''
|
emojis[code] || ''
|
||||||
|
|||||||
@@ -2,7 +2,7 @@ import { httpFetch } from '../../request'
|
|||||||
import { formatPlayTime, sizeFormate } from '../index'
|
import { formatPlayTime, sizeFormate } from '../index'
|
||||||
import { formatSingerName } from '../utils'
|
import { formatSingerName } from '../utils'
|
||||||
|
|
||||||
let boardList = [
|
const boardList = [
|
||||||
{ id: 'tx__4', name: '流行指数榜', bangid: '4' },
|
{ id: 'tx__4', name: '流行指数榜', bangid: '4' },
|
||||||
{ id: 'tx__26', name: '热歌榜', bangid: '26' },
|
{ id: 'tx__26', name: '热歌榜', bangid: '26' },
|
||||||
{ id: 'tx__27', name: '新歌榜', bangid: '27' },
|
{ id: 'tx__27', name: '新歌榜', bangid: '27' },
|
||||||
@@ -137,31 +137,31 @@ export default {
|
|||||||
filterData(rawList) {
|
filterData(rawList) {
|
||||||
// console.log(rawList)
|
// console.log(rawList)
|
||||||
return rawList.map((item) => {
|
return rawList.map((item) => {
|
||||||
let types = []
|
const types = []
|
||||||
let _types = {}
|
const _types = {}
|
||||||
if (item.file.size_128mp3 !== 0) {
|
if (item.file.size_128mp3 !== 0) {
|
||||||
let size = sizeFormate(item.file.size_128mp3)
|
const size = sizeFormate(item.file.size_128mp3)
|
||||||
types.push({ type: '128k', size })
|
types.push({ type: '128k', size })
|
||||||
_types['128k'] = {
|
_types['128k'] = {
|
||||||
size
|
size
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
if (item.file.size_320mp3 !== 0) {
|
if (item.file.size_320mp3 !== 0) {
|
||||||
let size = sizeFormate(item.file.size_320mp3)
|
const size = sizeFormate(item.file.size_320mp3)
|
||||||
types.push({ type: '320k', size })
|
types.push({ type: '320k', size })
|
||||||
_types['320k'] = {
|
_types['320k'] = {
|
||||||
size
|
size
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
if (item.file.size_flac !== 0) {
|
if (item.file.size_flac !== 0) {
|
||||||
let size = sizeFormate(item.file.size_flac)
|
const size = sizeFormate(item.file.size_flac)
|
||||||
types.push({ type: 'flac', size })
|
types.push({ type: 'flac', size })
|
||||||
_types.flac = {
|
_types.flac = {
|
||||||
size
|
size
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
if (item.file.size_hires !== 0) {
|
if (item.file.size_hires !== 0) {
|
||||||
let size = sizeFormate(item.file.size_hires)
|
const size = sizeFormate(item.file.size_hires)
|
||||||
types.push({ type: 'flac24bit', size })
|
types.push({ type: 'flac24bit', size })
|
||||||
_types.flac24bit = {
|
_types.flac24bit = {
|
||||||
size
|
size
|
||||||
@@ -195,10 +195,10 @@ export default {
|
|||||||
},
|
},
|
||||||
getPeriods(bangid) {
|
getPeriods(bangid) {
|
||||||
return this.getData(this.periodUrl).then(({ body: html }) => {
|
return this.getData(this.periodUrl).then(({ body: html }) => {
|
||||||
let result = html.match(this.regExps.periodList)
|
const result = html.match(this.regExps.periodList)
|
||||||
if (!result) return Promise.reject(new Error('get data failed'))
|
if (!result) return Promise.reject(new Error('get data failed'))
|
||||||
result.forEach((item) => {
|
result.forEach((item) => {
|
||||||
let result = item.match(this.regExps.period)
|
const result = item.match(this.regExps.period)
|
||||||
if (!result) return
|
if (!result) return
|
||||||
this.periods[result[2]] = {
|
this.periods[result[2]] = {
|
||||||
name: result[1],
|
name: result[1],
|
||||||
@@ -212,7 +212,7 @@ export default {
|
|||||||
},
|
},
|
||||||
filterBoardsData(rawList) {
|
filterBoardsData(rawList) {
|
||||||
// console.log(rawList)
|
// console.log(rawList)
|
||||||
let list = []
|
const list = []
|
||||||
for (const board of rawList) {
|
for (const board of rawList) {
|
||||||
// 排除 MV榜
|
// 排除 MV榜
|
||||||
if (board.id == 201) continue
|
if (board.id == 201) continue
|
||||||
@@ -256,8 +256,8 @@ export default {
|
|||||||
getList(bangid, page, retryNum = 0) {
|
getList(bangid, page, retryNum = 0) {
|
||||||
if (++retryNum > 3) return Promise.reject(new Error('try max num'))
|
if (++retryNum > 3) return Promise.reject(new Error('try max num'))
|
||||||
bangid = parseInt(bangid)
|
bangid = parseInt(bangid)
|
||||||
let info = this.periods[bangid]
|
const info = this.periods[bangid]
|
||||||
let p = info ? Promise.resolve(info.period) : this.getPeriods(bangid)
|
const p = info ? Promise.resolve(info.period) : this.getPeriods(bangid)
|
||||||
return p.then((period) => {
|
return p.then((period) => {
|
||||||
return this.listDetailRequest(bangid, period, this.limit).then((resp) => {
|
return this.listDetailRequest(bangid, period, this.limit).then((resp) => {
|
||||||
if (resp.body.code !== 0) return this.getList(bangid, page, retryNum)
|
if (resp.body.code !== 0) return this.getList(bangid, page, retryNum)
|
||||||
@@ -273,7 +273,7 @@ export default {
|
|||||||
},
|
},
|
||||||
|
|
||||||
getDetailPageUrl(id) {
|
getDetailPageUrl(id) {
|
||||||
if (typeof id == 'string') id = id.replace('tx__', '')
|
if (typeof id === 'string') id = id.replace('tx__', '')
|
||||||
return `https://y.qq.com/n/ryqq/toplist/${id}`
|
return `https://y.qq.com/n/ryqq/toplist/${id}`
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -2,7 +2,7 @@ import { httpFetch } from '../../request'
|
|||||||
import { formatPlayTime, sizeFormate } from '../index'
|
import { formatPlayTime, sizeFormate } from '../index'
|
||||||
|
|
||||||
const getSinger = (singers) => {
|
const getSinger = (singers) => {
|
||||||
let arr = []
|
const arr = []
|
||||||
singers.forEach((singer) => {
|
singers.forEach((singer) => {
|
||||||
arr.push(singer.name)
|
arr.push(singer.name)
|
||||||
})
|
})
|
||||||
@@ -37,32 +37,32 @@ export default (songmid) => {
|
|||||||
const item = body.req.data.track_info
|
const item = body.req.data.track_info
|
||||||
if (!item.file?.media_mid) return null
|
if (!item.file?.media_mid) return null
|
||||||
|
|
||||||
let types = []
|
const types = []
|
||||||
let _types = {}
|
const _types = {}
|
||||||
const file = item.file
|
const file = item.file
|
||||||
if (file.size_128mp3 != 0) {
|
if (file.size_128mp3 != 0) {
|
||||||
let size = sizeFormate(file.size_128mp3)
|
const size = sizeFormate(file.size_128mp3)
|
||||||
types.push({ type: '128k', size })
|
types.push({ type: '128k', size })
|
||||||
_types['128k'] = {
|
_types['128k'] = {
|
||||||
size
|
size
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
if (file.size_320mp3 !== 0) {
|
if (file.size_320mp3 !== 0) {
|
||||||
let size = sizeFormate(file.size_320mp3)
|
const size = sizeFormate(file.size_320mp3)
|
||||||
types.push({ type: '320k', size })
|
types.push({ type: '320k', size })
|
||||||
_types['320k'] = {
|
_types['320k'] = {
|
||||||
size
|
size
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
if (file.size_flac !== 0) {
|
if (file.size_flac !== 0) {
|
||||||
let size = sizeFormate(file.size_flac)
|
const size = sizeFormate(file.size_flac)
|
||||||
types.push({ type: 'flac', size })
|
types.push({ type: 'flac', size })
|
||||||
_types.flac = {
|
_types.flac = {
|
||||||
size
|
size
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
if (file.size_hires !== 0) {
|
if (file.size_hires !== 0) {
|
||||||
let size = sizeFormate(file.size_hires)
|
const size = sizeFormate(file.size_hires)
|
||||||
types.push({ type: 'flac24bit', size })
|
types.push({ type: 'flac24bit', size })
|
||||||
_types.flac24bit = {
|
_types.flac24bit = {
|
||||||
size
|
size
|
||||||
|
|||||||
@@ -56,32 +56,32 @@ export default {
|
|||||||
rawList.forEach((item) => {
|
rawList.forEach((item) => {
|
||||||
if (!item.file?.media_mid) return
|
if (!item.file?.media_mid) return
|
||||||
|
|
||||||
let types = []
|
const types = []
|
||||||
let _types = {}
|
const _types = {}
|
||||||
const file = item.file
|
const file = item.file
|
||||||
if (file.size_128mp3 != 0) {
|
if (file.size_128mp3 != 0) {
|
||||||
let size = sizeFormate(file.size_128mp3)
|
const size = sizeFormate(file.size_128mp3)
|
||||||
types.push({ type: '128k', size })
|
types.push({ type: '128k', size })
|
||||||
_types['128k'] = {
|
_types['128k'] = {
|
||||||
size
|
size
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
if (file.size_320mp3 !== 0) {
|
if (file.size_320mp3 !== 0) {
|
||||||
let size = sizeFormate(file.size_320mp3)
|
const size = sizeFormate(file.size_320mp3)
|
||||||
types.push({ type: '320k', size })
|
types.push({ type: '320k', size })
|
||||||
_types['320k'] = {
|
_types['320k'] = {
|
||||||
size
|
size
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
if (file.size_flac !== 0) {
|
if (file.size_flac !== 0) {
|
||||||
let size = sizeFormate(file.size_flac)
|
const size = sizeFormate(file.size_flac)
|
||||||
types.push({ type: 'flac', size })
|
types.push({ type: 'flac', size })
|
||||||
_types.flac = {
|
_types.flac = {
|
||||||
size
|
size
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
if (file.size_hires !== 0) {
|
if (file.size_hires !== 0) {
|
||||||
let size = sizeFormate(file.size_hires)
|
const size = sizeFormate(file.size_hires)
|
||||||
types.push({ type: 'flac24bit', size })
|
types.push({ type: 'flac24bit', size })
|
||||||
_types.flac24bit = {
|
_types.flac24bit = {
|
||||||
size
|
size
|
||||||
@@ -123,7 +123,7 @@ export default {
|
|||||||
if (limit == null) limit = this.limit
|
if (limit == null) limit = this.limit
|
||||||
// http://newlyric.kuwo.cn/newlyric.lrc?62355680
|
// http://newlyric.kuwo.cn/newlyric.lrc?62355680
|
||||||
return this.musicSearch(str, page, limit).then(({ body, meta }) => {
|
return this.musicSearch(str, page, limit).then(({ body, meta }) => {
|
||||||
let list = this.handleResult(body.item_song)
|
const list = this.handleResult(body.item_song)
|
||||||
|
|
||||||
this.total = meta.estimate_sum
|
this.total = meta.estimate_sum
|
||||||
this.page = page
|
this.page = page
|
||||||
|
|||||||
@@ -7,28 +7,28 @@ export const filterMusicInfoItem = (item) => {
|
|||||||
const types = []
|
const types = []
|
||||||
const _types = {}
|
const _types = {}
|
||||||
if (item.file.size_128mp3 != 0) {
|
if (item.file.size_128mp3 != 0) {
|
||||||
let size = sizeFormate(item.file.size_128mp3)
|
const size = sizeFormate(item.file.size_128mp3)
|
||||||
types.push({ type: '128k', size })
|
types.push({ type: '128k', size })
|
||||||
_types['128k'] = {
|
_types['128k'] = {
|
||||||
size
|
size
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
if (item.file.size_320mp3 !== 0) {
|
if (item.file.size_320mp3 !== 0) {
|
||||||
let size = sizeFormate(item.file.size_320mp3)
|
const size = sizeFormate(item.file.size_320mp3)
|
||||||
types.push({ type: '320k', size })
|
types.push({ type: '320k', size })
|
||||||
_types['320k'] = {
|
_types['320k'] = {
|
||||||
size
|
size
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
if (item.file.size_flac !== 0) {
|
if (item.file.size_flac !== 0) {
|
||||||
let size = sizeFormate(item.file.size_flac)
|
const size = sizeFormate(item.file.size_flac)
|
||||||
types.push({ type: 'flac', size })
|
types.push({ type: 'flac', size })
|
||||||
_types.flac = {
|
_types.flac = {
|
||||||
size
|
size
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
if (item.file.size_hires !== 0) {
|
if (item.file.size_hires !== 0) {
|
||||||
let size = sizeFormate(item.file.size_hires)
|
const size = sizeFormate(item.file.size_hires)
|
||||||
types.push({ type: 'flac24bit', size })
|
types.push({ type: 'flac24bit', size })
|
||||||
_types.flac24bit = {
|
_types.flac24bit = {
|
||||||
size
|
size
|
||||||
|
|||||||
@@ -95,12 +95,12 @@ export default {
|
|||||||
})
|
})
|
||||||
},
|
},
|
||||||
filterInfoHotTag(html) {
|
filterInfoHotTag(html) {
|
||||||
let hotTag = html.match(this.regExps.hotTagHtml)
|
const hotTag = html.match(this.regExps.hotTagHtml)
|
||||||
const hotTags = []
|
const hotTags = []
|
||||||
if (!hotTag) return hotTags
|
if (!hotTag) return hotTags
|
||||||
|
|
||||||
hotTag.forEach((tagHtml) => {
|
hotTag.forEach((tagHtml) => {
|
||||||
let result = tagHtml.match(this.regExps.hotTag)
|
const result = tagHtml.match(this.regExps.hotTag)
|
||||||
if (!result) return
|
if (!result) return
|
||||||
hotTags.push({
|
hotTags.push({
|
||||||
id: parseInt(result[1]),
|
id: parseInt(result[1]),
|
||||||
@@ -240,31 +240,31 @@ export default {
|
|||||||
filterListDetail(rawList) {
|
filterListDetail(rawList) {
|
||||||
// console.log(rawList)
|
// console.log(rawList)
|
||||||
return rawList.map((item) => {
|
return rawList.map((item) => {
|
||||||
let types = []
|
const types = []
|
||||||
let _types = {}
|
const _types = {}
|
||||||
if (item.file.size_128mp3 !== 0) {
|
if (item.file.size_128mp3 !== 0) {
|
||||||
let size = sizeFormate(item.file.size_128mp3)
|
const size = sizeFormate(item.file.size_128mp3)
|
||||||
types.push({ type: '128k', size })
|
types.push({ type: '128k', size })
|
||||||
_types['128k'] = {
|
_types['128k'] = {
|
||||||
size
|
size
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
if (item.file.size_320mp3 !== 0) {
|
if (item.file.size_320mp3 !== 0) {
|
||||||
let size = sizeFormate(item.file.size_320mp3)
|
const size = sizeFormate(item.file.size_320mp3)
|
||||||
types.push({ type: '320k', size })
|
types.push({ type: '320k', size })
|
||||||
_types['320k'] = {
|
_types['320k'] = {
|
||||||
size
|
size
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
if (item.file.size_flac !== 0) {
|
if (item.file.size_flac !== 0) {
|
||||||
let size = sizeFormate(item.file.size_flac)
|
const size = sizeFormate(item.file.size_flac)
|
||||||
types.push({ type: 'flac', size })
|
types.push({ type: 'flac', size })
|
||||||
_types.flac = {
|
_types.flac = {
|
||||||
size
|
size
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
if (item.file.size_hires !== 0) {
|
if (item.file.size_hires !== 0) {
|
||||||
let size = sizeFormate(item.file.size_hires)
|
const size = sizeFormate(item.file.size_hires)
|
||||||
types.push({ type: 'flac24bit', size })
|
types.push({ type: 'flac24bit', size })
|
||||||
_types.flac24bit = {
|
_types.flac24bit = {
|
||||||
size
|
size
|
||||||
|
|||||||
@@ -42,7 +42,7 @@ export const formatSingerName = (singers, nameKey = 'name', join = '、') => {
|
|||||||
if (Array.isArray(singers)) {
|
if (Array.isArray(singers)) {
|
||||||
const singer = []
|
const singer = []
|
||||||
singers.forEach((item) => {
|
singers.forEach((item) => {
|
||||||
let name = item[nameKey]
|
const name = item[nameKey]
|
||||||
if (!name) return
|
if (!name) return
|
||||||
singer.push(name)
|
singer.push(name)
|
||||||
})
|
})
|
||||||
|
|||||||
@@ -70,7 +70,7 @@ const applyEmoji = (text) => {
|
|||||||
return text
|
return text
|
||||||
}
|
}
|
||||||
|
|
||||||
let cursorTools = {
|
const cursorTools = {
|
||||||
cache: {},
|
cache: {},
|
||||||
getCursor(id, page, limit) {
|
getCursor(id, page, limit) {
|
||||||
let cacheData = this.cache[id]
|
let cacheData = this.cache[id]
|
||||||
@@ -190,7 +190,7 @@ export default {
|
|||||||
},
|
},
|
||||||
filterComment(rawList) {
|
filterComment(rawList) {
|
||||||
return rawList.map((item) => {
|
return rawList.map((item) => {
|
||||||
let data = {
|
const data = {
|
||||||
id: item.commentId,
|
id: item.commentId,
|
||||||
text: item.content ? applyEmoji(item.content) : '',
|
text: item.content ? applyEmoji(item.content) : '',
|
||||||
time: item.time ? item.time : '',
|
time: item.time ? item.time : '',
|
||||||
@@ -203,7 +203,7 @@ export default {
|
|||||||
reply: []
|
reply: []
|
||||||
}
|
}
|
||||||
|
|
||||||
let replyData = item.beReplied && item.beReplied[0]
|
const replyData = item.beReplied && item.beReplied[0]
|
||||||
return replyData
|
return replyData
|
||||||
? {
|
? {
|
||||||
id: item.commentId,
|
id: item.commentId,
|
||||||
|
|||||||
@@ -134,7 +134,7 @@ export default {
|
|||||||
|
|
||||||
filterBoardsData(rawList) {
|
filterBoardsData(rawList) {
|
||||||
// console.log(rawList)
|
// console.log(rawList)
|
||||||
let list = []
|
const list = []
|
||||||
for (const board of rawList) {
|
for (const board of rawList) {
|
||||||
// 排除 MV榜
|
// 排除 MV榜
|
||||||
// if (board.id == 201) continue
|
// if (board.id == 201) continue
|
||||||
@@ -210,7 +210,7 @@ export default {
|
|||||||
},
|
},
|
||||||
|
|
||||||
getDetailPageUrl(id) {
|
getDetailPageUrl(id) {
|
||||||
if (typeof id == 'string') id = id.replace('wy__', '')
|
if (typeof id === 'string') id = id.replace('wy__', '')
|
||||||
return `https://music.163.com/#/discover/toplist?id=${id}`
|
return `https://music.163.com/#/discover/toplist?id=${id}`
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -64,13 +64,13 @@ const parseTools = {
|
|||||||
},
|
},
|
||||||
msFormat(timeMs) {
|
msFormat(timeMs) {
|
||||||
if (Number.isNaN(timeMs)) return ''
|
if (Number.isNaN(timeMs)) return ''
|
||||||
let ms = timeMs % 1000
|
const ms = timeMs % 1000
|
||||||
timeMs /= 1000
|
timeMs /= 1000
|
||||||
let m = parseInt(timeMs / 60)
|
const m = parseInt(timeMs / 60)
|
||||||
.toString()
|
.toString()
|
||||||
.padStart(2, '0')
|
.padStart(2, '0')
|
||||||
timeMs %= 60
|
timeMs %= 60
|
||||||
let s = parseInt(timeMs).toString().padStart(2, '0')
|
const s = parseInt(timeMs).toString().padStart(2, '0')
|
||||||
return `[${m}:${s}.${ms}]`
|
return `[${m}:${s}.${ms}]`
|
||||||
},
|
},
|
||||||
parseLyric(lines) {
|
parseLyric(lines) {
|
||||||
@@ -79,7 +79,7 @@ const parseTools = {
|
|||||||
|
|
||||||
for (let line of lines) {
|
for (let line of lines) {
|
||||||
line = line.trim()
|
line = line.trim()
|
||||||
let result = this.rxps.lineTime.exec(line)
|
const result = this.rxps.lineTime.exec(line)
|
||||||
if (!result) {
|
if (!result) {
|
||||||
if (line.startsWith('[offset')) {
|
if (line.startsWith('[offset')) {
|
||||||
lxlrcLines.push(line)
|
lxlrcLines.push(line)
|
||||||
@@ -92,7 +92,7 @@ const parseTools = {
|
|||||||
const startTimeStr = this.msFormat(startMsTime)
|
const startTimeStr = this.msFormat(startMsTime)
|
||||||
if (!startTimeStr) continue
|
if (!startTimeStr) continue
|
||||||
|
|
||||||
let words = line.replace(this.rxps.lineTime, '')
|
const words = line.replace(this.rxps.lineTime, '')
|
||||||
|
|
||||||
lrcLines.push(`${startTimeStr}${words.replace(this.rxps.wordTimeAll, '')}`)
|
lrcLines.push(`${startTimeStr}${words.replace(this.rxps.wordTimeAll, '')}`)
|
||||||
|
|
||||||
@@ -124,7 +124,7 @@ const parseTools = {
|
|||||||
getIntv(interval) {
|
getIntv(interval) {
|
||||||
if (!interval) return 0
|
if (!interval) return 0
|
||||||
if (!interval.includes('.')) interval += '.0'
|
if (!interval.includes('.')) interval += '.0'
|
||||||
let arr = interval.split(/:|\./)
|
const arr = interval.split(/:|\./)
|
||||||
while (arr.length < 3) arr.unshift('0')
|
while (arr.length < 3) arr.unshift('0')
|
||||||
const [m, s, ms] = arr
|
const [m, s, ms] = arr
|
||||||
return parseInt(m) * 3600000 + parseInt(s) * 1000 + parseInt(ms)
|
return parseInt(m) * 3600000 + parseInt(s) * 1000 + parseInt(ms)
|
||||||
@@ -134,7 +134,7 @@ const parseTools = {
|
|||||||
const targetlrcLines = targetlrc.split('\n')
|
const targetlrcLines = targetlrc.split('\n')
|
||||||
const timeRxp = /^\[([\d:.]+)\]/
|
const timeRxp = /^\[([\d:.]+)\]/
|
||||||
let temp = []
|
let temp = []
|
||||||
let newLrc = []
|
const newLrc = []
|
||||||
targetlrcLines.forEach((line) => {
|
targetlrcLines.forEach((line) => {
|
||||||
const result = timeRxp.exec(line)
|
const result = timeRxp.exec(line)
|
||||||
if (!result) return
|
if (!result) return
|
||||||
@@ -168,7 +168,7 @@ const parseTools = {
|
|||||||
crlyric: ''
|
crlyric: ''
|
||||||
}
|
}
|
||||||
if (ylrc) {
|
if (ylrc) {
|
||||||
let lines = this.parseHeaderInfo(ylrc)
|
const lines = this.parseHeaderInfo(ylrc)
|
||||||
if (lines) {
|
if (lines) {
|
||||||
const result = this.parseLyric(lines)
|
const result = this.parseLyric(lines)
|
||||||
if (ytlrc) {
|
if (ytlrc) {
|
||||||
@@ -245,8 +245,8 @@ const parseTools = {
|
|||||||
// https://github.com/lyswhut/lx-music-mobile/issues/370
|
// https://github.com/lyswhut/lx-music-mobile/issues/370
|
||||||
const fixTimeLabel = (lrc, tlrc, romalrc) => {
|
const fixTimeLabel = (lrc, tlrc, romalrc) => {
|
||||||
if (lrc) {
|
if (lrc) {
|
||||||
let newLrc = lrc.replace(/\[(\d{2}:\d{2}):(\d{2})]/g, '[$1.$2]')
|
const newLrc = lrc.replace(/\[(\d{2}:\d{2}):(\d{2})]/g, '[$1.$2]')
|
||||||
let newTlrc = tlrc?.replace(/\[(\d{2}:\d{2}):(\d{2})]/g, '[$1.$2]') ?? tlrc
|
const newTlrc = tlrc?.replace(/\[(\d{2}:\d{2}):(\d{2})]/g, '[$1.$2]') ?? tlrc
|
||||||
if (newLrc != lrc || newTlrc != tlrc) {
|
if (newLrc != lrc || newTlrc != tlrc) {
|
||||||
lrc = newLrc
|
lrc = newLrc
|
||||||
tlrc = newTlrc
|
tlrc = newTlrc
|
||||||
|
|||||||
@@ -5,7 +5,7 @@ import { formatPlayTime, sizeFormate } from '../index'
|
|||||||
|
|
||||||
export default {
|
export default {
|
||||||
getSinger(singers) {
|
getSinger(singers) {
|
||||||
let arr = []
|
const arr = []
|
||||||
singers?.forEach((singer) => {
|
singers?.forEach((singer) => {
|
||||||
arr.push(singer.name)
|
arr.push(singer.name)
|
||||||
})
|
})
|
||||||
|
|||||||
@@ -20,7 +20,7 @@ export default {
|
|||||||
return searchRequest.promise.then(({ body }) => body)
|
return searchRequest.promise.then(({ body }) => body)
|
||||||
},
|
},
|
||||||
getSinger(singers) {
|
getSinger(singers) {
|
||||||
let arr = []
|
const arr = []
|
||||||
singers.forEach((singer) => {
|
singers.forEach((singer) => {
|
||||||
arr.push(singer.name)
|
arr.push(singer.name)
|
||||||
})
|
})
|
||||||
@@ -87,7 +87,7 @@ export default {
|
|||||||
return this.musicSearch(str, page, limit).then((result) => {
|
return this.musicSearch(str, page, limit).then((result) => {
|
||||||
// console.log(result)
|
// console.log(result)
|
||||||
if (!result || result.code !== 200) return this.search(str, page, limit, retryNum)
|
if (!result || result.code !== 200) return this.search(str, page, limit, retryNum)
|
||||||
let list = this.handleResult(result.result.songs || [])
|
const list = this.handleResult(result.result.songs || [])
|
||||||
// console.log(list)
|
// console.log(list)
|
||||||
|
|
||||||
if (list == null) return this.search(str, page, limit, retryNum)
|
if (list == null) return this.search(str, page, limit, retryNum)
|
||||||
|
|||||||
@@ -90,8 +90,8 @@ export default {
|
|||||||
const { statusCode, body } = await requestObj_listDetail.promise
|
const { statusCode, body } = await requestObj_listDetail.promise
|
||||||
if (statusCode !== 200 || body.code !== this.successCode)
|
if (statusCode !== 200 || body.code !== this.successCode)
|
||||||
return this.getListDetail(id, page, ++tryNum)
|
return this.getListDetail(id, page, ++tryNum)
|
||||||
let limit = 1000
|
const limit = 1000
|
||||||
let rangeStart = (page - 1) * limit
|
const rangeStart = (page - 1) * limit
|
||||||
// console.log(body)
|
// console.log(body)
|
||||||
let list
|
let list
|
||||||
if (body.playlist.trackIds.length == body.privileges.length) {
|
if (body.playlist.trackIds.length == body.privileges.length) {
|
||||||
|
|||||||
@@ -21,7 +21,7 @@ const aesEncrypt = (buffer, mode, key, iv) => {
|
|||||||
}
|
}
|
||||||
|
|
||||||
const aesDecrypt = function (cipherBuffer, mode, key, iv) {
|
const aesDecrypt = function (cipherBuffer, mode, key, iv) {
|
||||||
let decipher = createDecipheriv(mode, key, iv)
|
const decipher = createDecipheriv(mode, key, iv)
|
||||||
return Buffer.concat([decipher.update(cipherBuffer), decipher.final()])
|
return Buffer.concat([decipher.update(cipherBuffer), decipher.final()])
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|||||||
@@ -1,23 +1,26 @@
|
|||||||
import electron from 'electron'
|
import electron from 'electron'
|
||||||
|
|
||||||
function getAppDirPath(name?: "home"
|
function getAppDirPath(
|
||||||
| "appData"
|
name?:
|
||||||
| "assets"
|
| 'home'
|
||||||
| "userData"
|
| 'appData'
|
||||||
| "sessionData"
|
| 'assets'
|
||||||
| "temp"
|
| 'userData'
|
||||||
| "exe"
|
| 'sessionData'
|
||||||
| "module"
|
| 'temp'
|
||||||
| "desktop"
|
| 'exe'
|
||||||
| "documents"
|
| 'module'
|
||||||
| "downloads"
|
| 'desktop'
|
||||||
| "music"
|
| 'documents'
|
||||||
| "pictures"
|
| 'downloads'
|
||||||
| "videos"
|
| 'music'
|
||||||
| "recent"
|
| 'pictures'
|
||||||
| "logs"
|
| 'videos'
|
||||||
| "crashDumps") {
|
| 'recent'
|
||||||
let dirPath: string = electron.app.getPath(name ?? 'userData')
|
| 'logs'
|
||||||
|
| 'crashDumps'
|
||||||
|
) {
|
||||||
|
const dirPath: string = electron.app.getPath(name ?? 'userData')
|
||||||
return dirPath
|
return dirPath
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|||||||
@@ -85,7 +85,7 @@ const defaultHeaders = {
|
|||||||
* @param {Object} options - 请求选项
|
* @param {Object} options - 请求选项
|
||||||
*/
|
*/
|
||||||
const buildHttpPromise = (url, options) => {
|
const buildHttpPromise = (url, options) => {
|
||||||
let obj = {
|
const obj = {
|
||||||
isCancelled: false,
|
isCancelled: false,
|
||||||
cancelToken: axios.CancelToken.source(),
|
cancelToken: axios.CancelToken.source(),
|
||||||
cancelHttp: () => {
|
cancelHttp: () => {
|
||||||
@@ -190,12 +190,12 @@ const fetchData = async (url, method = 'get', options = {}) => {
|
|||||||
let s = Buffer.from(bHh, 'hex').toString()
|
let s = Buffer.from(bHh, 'hex').toString()
|
||||||
s = s.replace(s.substr(-1), '')
|
s = s.replace(s.substr(-1), '')
|
||||||
s = Buffer.from(s, 'base64').toString()
|
s = Buffer.from(s, 'base64').toString()
|
||||||
let v = process.versions.app
|
const v = process.versions.app
|
||||||
.split('-')[0]
|
.split('-')[0]
|
||||||
.split('.')
|
.split('.')
|
||||||
.map((n) => (n.length < 3 ? n.padStart(3, '0') : n))
|
.map((n) => (n.length < 3 ? n.padStart(3, '0') : n))
|
||||||
.join('')
|
.join('')
|
||||||
let v2 = process.versions.app.split('-')[1] || ''
|
const v2 = process.versions.app.split('-')[1] || ''
|
||||||
requestHeaders[s] =
|
requestHeaders[s] =
|
||||||
!s ||
|
!s ||
|
||||||
`${(await handleDeflateRaw(Buffer.from(JSON.stringify(`${path}${v}`.match(regx), null, 1).concat(v)).toString('base64'))).toString('hex')}&${parseInt(v)}${v2}`
|
`${(await handleDeflateRaw(Buffer.from(JSON.stringify(`${path}${v}`.match(regx), null, 1).concat(v)).toString('base64'))).toString('hex')}&${parseInt(v)}${v2}`
|
||||||
@@ -385,7 +385,7 @@ export const http_jsonp = (url, options, callback) => {
|
|||||||
options = {}
|
options = {}
|
||||||
}
|
}
|
||||||
|
|
||||||
let jsonpCallback = 'jsonpCallback'
|
const jsonpCallback = 'jsonpCallback'
|
||||||
if (url.indexOf('?') < 0) url += '?'
|
if (url.indexOf('?') < 0) url += '?'
|
||||||
url += `&${options.jsonpCallback}=${jsonpCallback}`
|
url += `&${options.jsonpCallback}=${jsonpCallback}`
|
||||||
|
|
||||||
|
|||||||
@@ -1,176 +0,0 @@
|
|||||||
import { Tray, Menu, BrowserWindow } from 'electron'
|
|
||||||
import { electronApp, optimizer } from '@electron-toolkit/utils'
|
|
||||||
import path from 'node:path'
|
|
||||||
// 使用传入的 tray 对象
|
|
||||||
export default function useWindow(
|
|
||||||
createWindow: { (): void; (): void },
|
|
||||||
ipcMain: Electron.IpcMain,
|
|
||||||
app: Electron.App,
|
|
||||||
mainWindow: BrowserWindow | null,
|
|
||||||
isQuitting: { value: boolean },
|
|
||||||
trayObj: { value: Tray | null }
|
|
||||||
) {
|
|
||||||
function createTray(): void {
|
|
||||||
// 创建系统托盘
|
|
||||||
const trayIconPath = path.join(__dirname, '../../resources/logo.png')
|
|
||||||
trayObj.value = new Tray(trayIconPath)
|
|
||||||
|
|
||||||
// 创建托盘菜单
|
|
||||||
const contextMenu = Menu.buildFromTemplate([
|
|
||||||
{
|
|
||||||
label: '显示窗口',
|
|
||||||
click: () => {
|
|
||||||
if (mainWindow) {
|
|
||||||
mainWindow.show()
|
|
||||||
mainWindow.focus()
|
|
||||||
}
|
|
||||||
}
|
|
||||||
},
|
|
||||||
{
|
|
||||||
label: '播放/暂停',
|
|
||||||
click: () => {
|
|
||||||
// 这里可以添加播放控制逻辑
|
|
||||||
mainWindow?.webContents.send('music-control')
|
|
||||||
}
|
|
||||||
},
|
|
||||||
{ type: 'separator' },
|
|
||||||
{
|
|
||||||
label: '退出',
|
|
||||||
click: () => {
|
|
||||||
isQuitting.value = true
|
|
||||||
app.quit()
|
|
||||||
}
|
|
||||||
}
|
|
||||||
])
|
|
||||||
|
|
||||||
trayObj.value.setContextMenu(contextMenu)
|
|
||||||
trayObj.value.setToolTip('Ceru Music')
|
|
||||||
|
|
||||||
// 双击托盘图标显示窗口
|
|
||||||
trayObj.value.on('click', () => {
|
|
||||||
if (mainWindow) {
|
|
||||||
if (mainWindow.isVisible()) {
|
|
||||||
mainWindow.hide()
|
|
||||||
} else {
|
|
||||||
mainWindow.show()
|
|
||||||
mainWindow.focus()
|
|
||||||
}
|
|
||||||
}
|
|
||||||
})
|
|
||||||
}
|
|
||||||
|
|
||||||
app.whenReady().then(() => {
|
|
||||||
// Set app user model id for windows
|
|
||||||
electronApp.setAppUserModelId('com.cerulean.music')
|
|
||||||
|
|
||||||
// Default open or close DevTools by F12 in development
|
|
||||||
// and ignore CommandOrControl + R in production.
|
|
||||||
// see https://github.com/alex8088/electron-toolkit/tree/master/packages/utils
|
|
||||||
app.on('browser-window-created', (_, window) => {
|
|
||||||
optimizer.watchWindowShortcuts(window)
|
|
||||||
})
|
|
||||||
|
|
||||||
// 窗口控制 IPC 处理
|
|
||||||
ipcMain.on('window-minimize', () => {
|
|
||||||
console.log('收到 window-minimize 事件')
|
|
||||||
if (mainWindow) {
|
|
||||||
console.log('正在最小化窗口...')
|
|
||||||
mainWindow.minimize()
|
|
||||||
} else {
|
|
||||||
console.log('mainWindow 不存在')
|
|
||||||
const window = BrowserWindow.getFocusedWindow()
|
|
||||||
if (window) {
|
|
||||||
console.log('使用 getFocusedWindow 最小化窗口...')
|
|
||||||
window.minimize()
|
|
||||||
} else {
|
|
||||||
console.log('没有找到可用的窗口')
|
|
||||||
}
|
|
||||||
}
|
|
||||||
})
|
|
||||||
|
|
||||||
ipcMain.on('window-maximize', () => {
|
|
||||||
console.log('收到 window-maximize 事件')
|
|
||||||
if (mainWindow) {
|
|
||||||
console.log('正在最大化/还原窗口...')
|
|
||||||
if (mainWindow.isMaximized()) {
|
|
||||||
mainWindow.unmaximize()
|
|
||||||
} else {
|
|
||||||
mainWindow.maximize()
|
|
||||||
}
|
|
||||||
} else {
|
|
||||||
console.log('mainWindow 不存在')
|
|
||||||
const window = BrowserWindow.getFocusedWindow()
|
|
||||||
if (window) {
|
|
||||||
console.log('使用 getFocusedWindow 最大化/还原窗口...')
|
|
||||||
if (window.isMaximized()) {
|
|
||||||
window.unmaximize()
|
|
||||||
} else {
|
|
||||||
window.maximize()
|
|
||||||
}
|
|
||||||
} else {
|
|
||||||
console.log('没有找到可用的窗口')
|
|
||||||
}
|
|
||||||
}
|
|
||||||
})
|
|
||||||
|
|
||||||
ipcMain.on('window-close', () => {
|
|
||||||
console.log('收到 window-close 事件')
|
|
||||||
if (mainWindow) {
|
|
||||||
console.log('正在关闭窗口...')
|
|
||||||
mainWindow.close()
|
|
||||||
} else {
|
|
||||||
console.log('mainWindow 不存在')
|
|
||||||
const window = BrowserWindow.getFocusedWindow()
|
|
||||||
if (window) {
|
|
||||||
console.log('使用 getFocusedWindow 关闭窗口...')
|
|
||||||
window.close()
|
|
||||||
} else {
|
|
||||||
console.log('没有找到可用的窗口')
|
|
||||||
}
|
|
||||||
}
|
|
||||||
})
|
|
||||||
|
|
||||||
// Mini 模式 IPC 处理 - 最小化到系统托盘
|
|
||||||
ipcMain.on('window-mini-mode', (_, isMini) => {
|
|
||||||
console.log('收到 window-mini-mode 事件,isMini:', isMini)
|
|
||||||
if (mainWindow) {
|
|
||||||
if (isMini) {
|
|
||||||
// 进入 Mini 模式:隐藏窗口到系统托盘
|
|
||||||
console.log('正在隐藏窗口...')
|
|
||||||
mainWindow.hide()
|
|
||||||
// 显示托盘通知(可选)
|
|
||||||
if (trayObj.value) {
|
|
||||||
console.log('显示托盘通知...')
|
|
||||||
trayObj.value.displayBalloon({
|
|
||||||
title: '澜音 Music',
|
|
||||||
content: '已最小化到系统托盘啦,点击托盘图标可重新打开~'
|
|
||||||
})
|
|
||||||
} else {
|
|
||||||
console.log('托盘对象不存在!trayObj.value:', trayObj.value)
|
|
||||||
}
|
|
||||||
} else {
|
|
||||||
// 退出 Mini 模式:显示窗口
|
|
||||||
mainWindow.show()
|
|
||||||
mainWindow.focus()
|
|
||||||
}
|
|
||||||
}
|
|
||||||
})
|
|
||||||
|
|
||||||
// 全屏模式 IPC 处理
|
|
||||||
ipcMain.on('window-toggle-fullscreen', () => {
|
|
||||||
if (mainWindow) {
|
|
||||||
const isFullScreen = mainWindow.isFullScreen()
|
|
||||||
mainWindow.setFullScreen(!isFullScreen)
|
|
||||||
}
|
|
||||||
})
|
|
||||||
|
|
||||||
createWindow()
|
|
||||||
createTray()
|
|
||||||
|
|
||||||
app.on('activate', function () {
|
|
||||||
// On macOS it's common to re-create a window in the app when the
|
|
||||||
// dock icon is clicked and there are no other windows open.
|
|
||||||
if (BrowserWindow.getAllWindows().length === 0) createWindow()
|
|
||||||
})
|
|
||||||
})
|
|
||||||
}
|
|
||||||
76
src/preload/index.d.ts
vendored
@@ -24,7 +24,37 @@ interface CustomAPI {
|
|||||||
getInfo: () => Promise<any>
|
getInfo: () => Promise<any>
|
||||||
clear: () => Promise
|
clear: () => Promise
|
||||||
getSize: () => Promise<string>
|
getSize: () => Promise<string>
|
||||||
},
|
}
|
||||||
|
|
||||||
|
// 歌单管理 API
|
||||||
|
songList: {
|
||||||
|
// === 歌单管理 ===
|
||||||
|
create: (name: string, description?: string, source?: string) => Promise<any>
|
||||||
|
getAll: () => Promise<any>
|
||||||
|
getById: (hashId: string) => Promise<any>
|
||||||
|
delete: (hashId: string) => Promise<any>
|
||||||
|
batchDelete: (hashIds: string[]) => Promise<any>
|
||||||
|
edit: (hashId: string, updates: any) => Promise<any>
|
||||||
|
updateCover: (hashId: string, coverImgUrl: string) => Promise<any>
|
||||||
|
search: (keyword: string, source?: string) => Promise<any>
|
||||||
|
getStatistics: () => Promise<any>
|
||||||
|
exists: (hashId: string) => Promise<any>
|
||||||
|
|
||||||
|
// === 歌曲管理 ===
|
||||||
|
addSongs: (hashId: string, songs: any[]) => Promise<any>
|
||||||
|
removeSong: (hashId: string, songmid: string | number) => Promise<any>
|
||||||
|
removeSongs: (hashId: string, songmids: (string | number)[]) => Promise<any>
|
||||||
|
clearSongs: (hashId: string) => Promise<any>
|
||||||
|
getSongs: (hashId: string) => Promise<any>
|
||||||
|
getSongCount: (hashId: string) => Promise<any>
|
||||||
|
hasSong: (hashId: string, songmid: string | number) => Promise<any>
|
||||||
|
getSong: (hashId: string, songmid: string | number) => Promise<any>
|
||||||
|
searchSongs: (hashId: string, keyword: string) => Promise<any>
|
||||||
|
getSongStatistics: (hashId: string) => Promise<any>
|
||||||
|
validateIntegrity: (hashId: string) => Promise<any>
|
||||||
|
repairData: (hashId: string) => Promise<any>
|
||||||
|
forceSave: (hashId: string) => Promise<any>
|
||||||
|
}
|
||||||
|
|
||||||
ai: {
|
ai: {
|
||||||
ask: (prompt: string) => Promise<any>
|
ask: (prompt: string) => Promise<any>
|
||||||
@@ -46,9 +76,51 @@ interface CustomAPI {
|
|||||||
}
|
}
|
||||||
ping: (callback: Function<any>) => undefined
|
ping: (callback: Function<any>) => undefined
|
||||||
pingService: {
|
pingService: {
|
||||||
start: () => undefined,
|
start: () => undefined
|
||||||
stop: () => undefined
|
stop: () => undefined
|
||||||
}
|
}
|
||||||
|
|
||||||
|
// 目录设置API
|
||||||
|
directorySettings: {
|
||||||
|
getDirectories: () => Promise<{
|
||||||
|
cacheDir: string
|
||||||
|
downloadDir: string
|
||||||
|
}>
|
||||||
|
selectCacheDir: () => Promise<{
|
||||||
|
success: boolean
|
||||||
|
path?: string
|
||||||
|
message?: string
|
||||||
|
}>
|
||||||
|
selectDownloadDir: () => Promise<{
|
||||||
|
success: boolean
|
||||||
|
path?: string
|
||||||
|
message?: string
|
||||||
|
}>
|
||||||
|
saveDirectories: (directories: {
|
||||||
|
cacheDir: string
|
||||||
|
downloadDir: string
|
||||||
|
}) => Promise<{
|
||||||
|
success: boolean
|
||||||
|
message: string
|
||||||
|
}>
|
||||||
|
resetDirectories: () => Promise<{
|
||||||
|
success: boolean
|
||||||
|
directories?: {
|
||||||
|
cacheDir: string
|
||||||
|
downloadDir: string
|
||||||
|
}
|
||||||
|
message?: string
|
||||||
|
}>
|
||||||
|
openDirectory: (dirPath: string) => Promise<{
|
||||||
|
success: boolean
|
||||||
|
message?: string
|
||||||
|
}>
|
||||||
|
getDirectorySize: (dirPath: string) => Promise<{
|
||||||
|
size: number
|
||||||
|
formatted: string
|
||||||
|
}>
|
||||||
|
}
|
||||||
|
|
||||||
// 用户配置API
|
// 用户配置API
|
||||||
getUserConfig: () => Promise<any>
|
getUserConfig: () => Promise<any>
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -70,6 +70,47 @@ const api = {
|
|||||||
getSize: () => ipcRenderer.invoke('music-cache:get-size')
|
getSize: () => ipcRenderer.invoke('music-cache:get-size')
|
||||||
},
|
},
|
||||||
|
|
||||||
|
// 歌单管理 API
|
||||||
|
songList: {
|
||||||
|
// === 歌单管理 ===
|
||||||
|
create: (name: string, description?: string, source?: string) =>
|
||||||
|
ipcRenderer.invoke('songlist:create', name, description, source),
|
||||||
|
getAll: () => ipcRenderer.invoke('songlist:get-all'),
|
||||||
|
getById: (hashId: string) => ipcRenderer.invoke('songlist:get-by-id', hashId),
|
||||||
|
delete: (hashId: string) => ipcRenderer.invoke('songlist:delete', hashId),
|
||||||
|
batchDelete: (hashIds: string[]) => ipcRenderer.invoke('songlist:batch-delete', hashIds),
|
||||||
|
edit: (hashId: string, updates: any) => ipcRenderer.invoke('songlist:edit', hashId, updates),
|
||||||
|
updateCover: (hashId: string, coverImgUrl: string) =>
|
||||||
|
ipcRenderer.invoke('songlist:update-cover', hashId, coverImgUrl),
|
||||||
|
search: (keyword: string, source?: string) =>
|
||||||
|
ipcRenderer.invoke('songlist:search', keyword, source),
|
||||||
|
getStatistics: () => ipcRenderer.invoke('songlist:get-statistics'),
|
||||||
|
exists: (hashId: string) => ipcRenderer.invoke('songlist:exists', hashId),
|
||||||
|
|
||||||
|
// === 歌曲管理 ===
|
||||||
|
addSongs: (hashId: string, songs: any[]) =>
|
||||||
|
ipcRenderer.invoke('songlist:add-songs', hashId, songs),
|
||||||
|
removeSong: (hashId: string, songmid: string | number) =>
|
||||||
|
ipcRenderer.invoke('songlist:remove-song', hashId, songmid),
|
||||||
|
removeSongs: (hashId: string, songmids: (string | number)[]) =>
|
||||||
|
ipcRenderer.invoke('songlist:remove-songs', hashId, songmids),
|
||||||
|
clearSongs: (hashId: string) => ipcRenderer.invoke('songlist:clear-songs', hashId),
|
||||||
|
getSongs: (hashId: string) => ipcRenderer.invoke('songlist:get-songs', hashId),
|
||||||
|
getSongCount: (hashId: string) => ipcRenderer.invoke('songlist:get-song-count', hashId),
|
||||||
|
hasSong: (hashId: string, songmid: string | number) =>
|
||||||
|
ipcRenderer.invoke('songlist:has-song', hashId, songmid),
|
||||||
|
getSong: (hashId: string, songmid: string | number) =>
|
||||||
|
ipcRenderer.invoke('songlist:get-song', hashId, songmid),
|
||||||
|
searchSongs: (hashId: string, keyword: string) =>
|
||||||
|
ipcRenderer.invoke('songlist:search-songs', hashId, keyword),
|
||||||
|
getSongStatistics: (hashId: string) =>
|
||||||
|
ipcRenderer.invoke('songlist:get-song-statistics', hashId),
|
||||||
|
validateIntegrity: (hashId: string) =>
|
||||||
|
ipcRenderer.invoke('songlist:validate-integrity', hashId),
|
||||||
|
repairData: (hashId: string) => ipcRenderer.invoke('songlist:repair-data', hashId),
|
||||||
|
forceSave: (hashId: string) => ipcRenderer.invoke('songlist:force-save', hashId)
|
||||||
|
},
|
||||||
|
|
||||||
getUserConfig: () => ipcRenderer.invoke('get-user-config'),
|
getUserConfig: () => ipcRenderer.invoke('get-user-config'),
|
||||||
|
|
||||||
// 自动更新相关
|
// 自动更新相关
|
||||||
@@ -80,42 +121,61 @@ const api = {
|
|||||||
|
|
||||||
// 监听更新事件
|
// 监听更新事件
|
||||||
onCheckingForUpdate: (callback: () => void) => {
|
onCheckingForUpdate: (callback: () => void) => {
|
||||||
ipcRenderer.on('auto-updater:checking-for-update', callback);
|
ipcRenderer.on('auto-updater:checking-for-update', callback)
|
||||||
},
|
},
|
||||||
onUpdateAvailable: (callback: () => void) => {
|
onUpdateAvailable: (callback: () => void) => {
|
||||||
ipcRenderer.on('auto-updater:update-available', callback);
|
ipcRenderer.on('auto-updater:update-available', callback)
|
||||||
},
|
},
|
||||||
onUpdateNotAvailable: (callback: () => void) => {
|
onUpdateNotAvailable: (callback: () => void) => {
|
||||||
ipcRenderer.on('auto-updater:update-not-available', callback);
|
ipcRenderer.on('auto-updater:update-not-available', callback)
|
||||||
},
|
},
|
||||||
onDownloadProgress: (callback: (progress: any) => void) => {
|
onDownloadProgress: (callback: (progress: any) => void) => {
|
||||||
ipcRenderer.on('auto-updater:download-progress', (_, progress) => callback(progress));
|
ipcRenderer.on('auto-updater:download-progress', (_, progress) => callback(progress))
|
||||||
},
|
},
|
||||||
onUpdateDownloaded: (callback: () => void) => {
|
onUpdateDownloaded: (callback: () => void) => {
|
||||||
ipcRenderer.on('auto-updater:update-downloaded', callback);
|
ipcRenderer.on('auto-updater:update-downloaded', callback)
|
||||||
},
|
},
|
||||||
onError: (callback: (error: string) => void) => {
|
onError: (callback: (error: string) => void) => {
|
||||||
ipcRenderer.on('auto-updater:error', (_, error) => callback(error));
|
ipcRenderer.on('auto-updater:error', (_, error) => callback(error))
|
||||||
},
|
},
|
||||||
onDownloadStarted: (callback: (updateInfo: any) => void) => {
|
onDownloadStarted: (callback: (updateInfo: any) => void) => {
|
||||||
ipcRenderer.on('auto-updater:download-started', (_, updateInfo) => callback(updateInfo));
|
ipcRenderer.on('auto-updater:download-started', (_, updateInfo) => callback(updateInfo))
|
||||||
},
|
},
|
||||||
|
|
||||||
// 移除所有监听器
|
// 移除所有监听器
|
||||||
removeAllListeners: () => {
|
removeAllListeners: () => {
|
||||||
ipcRenderer.removeAllListeners('auto-updater:checking-for-update');
|
ipcRenderer.removeAllListeners('auto-updater:checking-for-update')
|
||||||
ipcRenderer.removeAllListeners('auto-updater:update-available');
|
ipcRenderer.removeAllListeners('auto-updater:update-available')
|
||||||
ipcRenderer.removeAllListeners('auto-updater:update-not-available');
|
ipcRenderer.removeAllListeners('auto-updater:update-not-available')
|
||||||
ipcRenderer.removeAllListeners('auto-updater:download-started');
|
ipcRenderer.removeAllListeners('auto-updater:download-started')
|
||||||
ipcRenderer.removeAllListeners('auto-updater:download-progress');
|
ipcRenderer.removeAllListeners('auto-updater:download-progress')
|
||||||
ipcRenderer.removeAllListeners('auto-updater:update-downloaded');
|
ipcRenderer.removeAllListeners('auto-updater:update-downloaded')
|
||||||
ipcRenderer.removeAllListeners('auto-updater:error');
|
ipcRenderer.removeAllListeners('auto-updater:error')
|
||||||
}
|
}
|
||||||
},
|
},
|
||||||
ping: (callbaack: Function) => ipcRenderer.on('song-ended', () => callbaack()),
|
ping: (callbaack: Function) => ipcRenderer.on('song-ended', () => callbaack()),
|
||||||
pingService: {
|
pingService: {
|
||||||
start: () => { ipcRenderer.send('startPing'); console.log('eventStart') },
|
start: () => {
|
||||||
stop: () => { ipcRenderer.send('stopPing') }
|
ipcRenderer.send('startPing')
|
||||||
|
console.log('eventStart')
|
||||||
|
},
|
||||||
|
stop: () => {
|
||||||
|
ipcRenderer.send('stopPing')
|
||||||
|
}
|
||||||
|
},
|
||||||
|
|
||||||
|
// 目录设置相关
|
||||||
|
directorySettings: {
|
||||||
|
getDirectories: () => ipcRenderer.invoke('directory-settings:get-directories'),
|
||||||
|
selectCacheDir: () => ipcRenderer.invoke('directory-settings:select-cache-dir'),
|
||||||
|
selectDownloadDir: () => ipcRenderer.invoke('directory-settings:select-download-dir'),
|
||||||
|
saveDirectories: (directories: any) =>
|
||||||
|
ipcRenderer.invoke('directory-settings:save-directories', directories),
|
||||||
|
resetDirectories: () => ipcRenderer.invoke('directory-settings:reset-directories'),
|
||||||
|
openDirectory: (dirPath: string) =>
|
||||||
|
ipcRenderer.invoke('directory-settings:open-directory', dirPath),
|
||||||
|
getDirectorySize: (dirPath: string) =>
|
||||||
|
ipcRenderer.invoke('directory-settings:get-directory-size', dirPath)
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|||||||
8
src/renderer/components.d.ts
vendored
@@ -9,11 +9,14 @@ export {}
|
|||||||
declare module 'vue' {
|
declare module 'vue' {
|
||||||
export interface GlobalComponents {
|
export interface GlobalComponents {
|
||||||
AIFloatBallSettings: typeof import('./src/components/Settings/AIFloatBallSettings.vue')['default']
|
AIFloatBallSettings: typeof import('./src/components/Settings/AIFloatBallSettings.vue')['default']
|
||||||
|
AudioVisualizer: typeof import('./src/components/Play/AudioVisualizer.vue')['default']
|
||||||
|
DirectorySettings: typeof import('./src/components/Settings/DirectorySettings.vue')['default']
|
||||||
FloatBall: typeof import('./src/components/AI/FloatBall.vue')['default']
|
FloatBall: typeof import('./src/components/AI/FloatBall.vue')['default']
|
||||||
FullPlay: typeof import('./src/components/Play/FullPlay.vue')['default']
|
FullPlay: typeof import('./src/components/Play/FullPlay.vue')['default']
|
||||||
GlobalAudio: typeof import('./src/components/Play/GlobalAudio.vue')['default']
|
GlobalAudio: typeof import('./src/components/Play/GlobalAudio.vue')['default']
|
||||||
MusicCache: typeof import('./src/components/Settings/MusicCache.vue')['default']
|
MusicCache: typeof import('./src/components/Settings/MusicCache.vue')['default']
|
||||||
PlaylistActions: typeof import('./src/components/Play/PlaylistActions.vue')['default']
|
PlaylistActions: typeof import('./src/components/Play/PlaylistActions.vue')['default']
|
||||||
|
PlaylistDrawer: typeof import('./src/components/Play/PlaylistDrawer.vue')['default']
|
||||||
PlaylistSettings: typeof import('./src/components/Settings/PlaylistSettings.vue')['default']
|
PlaylistSettings: typeof import('./src/components/Settings/PlaylistSettings.vue')['default']
|
||||||
PlayMusic: typeof import('./src/components/Play/PlayMusic.vue')['default']
|
PlayMusic: typeof import('./src/components/Play/PlayMusic.vue')['default']
|
||||||
RouterLink: typeof import('vue-router')['RouterLink']
|
RouterLink: typeof import('vue-router')['RouterLink']
|
||||||
@@ -28,7 +31,10 @@ declare module 'vue' {
|
|||||||
TCard: typeof import('tdesign-vue-next')['Card']
|
TCard: typeof import('tdesign-vue-next')['Card']
|
||||||
TContent: typeof import('tdesign-vue-next')['Content']
|
TContent: typeof import('tdesign-vue-next')['Content']
|
||||||
TDialog: typeof import('tdesign-vue-next')['Dialog']
|
TDialog: typeof import('tdesign-vue-next')['Dialog']
|
||||||
|
TDivider: typeof import('tdesign-vue-next')['Divider']
|
||||||
TDropdown: typeof import('tdesign-vue-next')['Dropdown']
|
TDropdown: typeof import('tdesign-vue-next')['Dropdown']
|
||||||
|
TForm: typeof import('tdesign-vue-next')['Form']
|
||||||
|
TFormItem: typeof import('tdesign-vue-next')['FormItem']
|
||||||
ThemeSelector: typeof import('./src/components/ThemeSelector.vue')['default']
|
ThemeSelector: typeof import('./src/components/ThemeSelector.vue')['default']
|
||||||
TIcon: typeof import('tdesign-vue-next')['Icon']
|
TIcon: typeof import('tdesign-vue-next')['Icon']
|
||||||
TImage: typeof import('tdesign-vue-next')['Image']
|
TImage: typeof import('tdesign-vue-next')['Image']
|
||||||
@@ -40,6 +46,8 @@ declare module 'vue' {
|
|||||||
TRadioGroup: typeof import('tdesign-vue-next')['RadioGroup']
|
TRadioGroup: typeof import('tdesign-vue-next')['RadioGroup']
|
||||||
TSlider: typeof import('tdesign-vue-next')['Slider']
|
TSlider: typeof import('tdesign-vue-next')['Slider']
|
||||||
TSwitch: typeof import('tdesign-vue-next')['Switch']
|
TSwitch: typeof import('tdesign-vue-next')['Switch']
|
||||||
|
TTag: typeof import('tdesign-vue-next')['Tag']
|
||||||
|
TTextarea: typeof import('tdesign-vue-next')['Textarea']
|
||||||
TTooltip: typeof import('tdesign-vue-next')['Tooltip']
|
TTooltip: typeof import('tdesign-vue-next')['Tooltip']
|
||||||
UpdateExample: typeof import('./src/components/UpdateExample.vue')['default']
|
UpdateExample: typeof import('./src/components/UpdateExample.vue')['default']
|
||||||
UpdateProgress: typeof import('./src/components/UpdateProgress.vue')['default']
|
UpdateProgress: typeof import('./src/components/UpdateProgress.vue')['default']
|
||||||
|
|||||||
@@ -2,7 +2,7 @@
|
|||||||
<html>
|
<html>
|
||||||
<head lang="zh-CN">
|
<head lang="zh-CN">
|
||||||
<meta charset="UTF-8" />
|
<meta charset="UTF-8" />
|
||||||
<title>Electron</title>
|
<title>澜音 Music</title>
|
||||||
<!-- https://developer.mozilla.org/en-US/docs/Web/HTTP/CSP -->
|
<!-- https://developer.mozilla.org/en-US/docs/Web/HTTP/CSP -->
|
||||||
<!-- <meta
|
<!-- <meta
|
||||||
http-equiv="Content-Security-Policy"
|
http-equiv="Content-Security-Policy"
|
||||||
|
|||||||
BIN
src/renderer/public/default-cover.png
Normal file
|
After Width: | Height: | Size: 824 KiB |
BIN
src/renderer/public/head.jpg
Normal file
|
After Width: | Height: | Size: 202 KiB |
BIN
src/renderer/public/star.png
Normal file
|
After Width: | Height: | Size: 103 KiB |
BIN
src/renderer/public/wldss.png
Normal file
|
After Width: | Height: | Size: 528 KiB |
@@ -35,7 +35,7 @@ const themes = [
|
|||||||
|
|
||||||
const loadSavedTheme = () => {
|
const loadSavedTheme = () => {
|
||||||
const savedTheme = localStorage.getItem('selected-theme')
|
const savedTheme = localStorage.getItem('selected-theme')
|
||||||
if (savedTheme && themes.some(t => t.name === savedTheme)) {
|
if (savedTheme && themes.some((t) => t.name === savedTheme)) {
|
||||||
applyTheme(savedTheme)
|
applyTheme(savedTheme)
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
@@ -59,8 +59,10 @@ const applyTheme = (themeName) => {
|
|||||||
<template>
|
<template>
|
||||||
<div class="page">
|
<div class="page">
|
||||||
<router-view v-slot="{ Component }">
|
<router-view v-slot="{ Component }">
|
||||||
<Transition :enter-active-class="`animate__animated animate__fadeIn pagesApp`"
|
<Transition
|
||||||
:leave-active-class="`animate__animated animate__fadeOut pagesApp`">
|
:enter-active-class="`animate__animated animate__fadeIn pagesApp`"
|
||||||
|
:leave-active-class="`animate__animated animate__fadeOut pagesApp`"
|
||||||
|
>
|
||||||
<component :is="Component" />
|
<component :is="Component" />
|
||||||
</Transition>
|
</Transition>
|
||||||
</router-view>
|
</router-view>
|
||||||
|
|||||||
478
src/renderer/src/api/songList.ts
Normal file
@@ -0,0 +1,478 @@
|
|||||||
|
import type {
|
||||||
|
SongListAPI,
|
||||||
|
IPCResponse,
|
||||||
|
BatchOperationResult,
|
||||||
|
RemoveSongsResult,
|
||||||
|
SongListStatistics,
|
||||||
|
SongStatistics,
|
||||||
|
IntegrityCheckResult,
|
||||||
|
RepairResult
|
||||||
|
} from '../../../types/songList'
|
||||||
|
import type { SongList, Songs } from '@common/types/songList'
|
||||||
|
|
||||||
|
// 检查是否在 Electron 环境中
|
||||||
|
const isElectron = typeof window !== 'undefined' && window.api && window.api.songList
|
||||||
|
|
||||||
|
/**
|
||||||
|
* 歌单管理 API 封装类
|
||||||
|
*/
|
||||||
|
class SongListService implements SongListAPI {
|
||||||
|
private get songListAPI() {
|
||||||
|
if (!isElectron) {
|
||||||
|
throw new Error('当前环境不支持 Electron API 调用')
|
||||||
|
}
|
||||||
|
return window.api.songList
|
||||||
|
}
|
||||||
|
|
||||||
|
// === 歌单管理方法 ===
|
||||||
|
|
||||||
|
/**
|
||||||
|
* 创建新歌单
|
||||||
|
*/
|
||||||
|
async create(
|
||||||
|
name: string,
|
||||||
|
description: string = '',
|
||||||
|
source: SongList['source'] = 'local'
|
||||||
|
): Promise<IPCResponse<{ id: string }>> {
|
||||||
|
try {
|
||||||
|
return await this.songListAPI.create(name, description, source)
|
||||||
|
} catch (error) {
|
||||||
|
return {
|
||||||
|
success: false,
|
||||||
|
error: error instanceof Error ? error.message : '创建歌单失败'
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* 获取所有歌单
|
||||||
|
*/
|
||||||
|
async getAll(): Promise<IPCResponse<SongList[]>> {
|
||||||
|
try {
|
||||||
|
return await this.songListAPI.getAll()
|
||||||
|
} catch (error) {
|
||||||
|
return {
|
||||||
|
success: false,
|
||||||
|
error: error instanceof Error ? error.message : '获取歌单列表失败'
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* 根据ID获取歌单信息
|
||||||
|
*/
|
||||||
|
async getById(hashId: string): Promise<IPCResponse<SongList | null>> {
|
||||||
|
try {
|
||||||
|
return await this.songListAPI.getById(hashId)
|
||||||
|
} catch (error) {
|
||||||
|
return {
|
||||||
|
success: false,
|
||||||
|
error: error instanceof Error ? error.message : '获取歌单信息失败'
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* 删除歌单
|
||||||
|
*/
|
||||||
|
async delete(hashId: string): Promise<IPCResponse> {
|
||||||
|
try {
|
||||||
|
return await this.songListAPI.delete(hashId)
|
||||||
|
} catch (error) {
|
||||||
|
return {
|
||||||
|
success: false,
|
||||||
|
error: error instanceof Error ? error.message : '删除歌单失败'
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* 批量删除歌单
|
||||||
|
*/
|
||||||
|
async batchDelete(hashIds: string[]): Promise<IPCResponse<BatchOperationResult>> {
|
||||||
|
try {
|
||||||
|
return await this.songListAPI.batchDelete(hashIds)
|
||||||
|
} catch (error) {
|
||||||
|
return {
|
||||||
|
success: false,
|
||||||
|
error: error instanceof Error ? error.message : '批量删除歌单失败'
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* 编辑歌单信息
|
||||||
|
*/
|
||||||
|
async edit(
|
||||||
|
hashId: string,
|
||||||
|
updates: Partial<Omit<SongList, 'id' | 'createTime'>>
|
||||||
|
): Promise<IPCResponse> {
|
||||||
|
try {
|
||||||
|
return await this.songListAPI.edit(hashId, updates)
|
||||||
|
} catch (error) {
|
||||||
|
return {
|
||||||
|
success: false,
|
||||||
|
error: error instanceof Error ? error.message : '编辑歌单失败'
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* 更新歌单封面
|
||||||
|
*/
|
||||||
|
async updateCover(hashId: string, coverImgUrl: string): Promise<IPCResponse> {
|
||||||
|
try {
|
||||||
|
return await this.songListAPI.updateCover(hashId, coverImgUrl)
|
||||||
|
} catch (error) {
|
||||||
|
return {
|
||||||
|
success: false,
|
||||||
|
error: error instanceof Error ? error.message : '更新封面失败'
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* 搜索歌单
|
||||||
|
*/
|
||||||
|
async search(keyword: string, source?: SongList['source']): Promise<IPCResponse<SongList[]>> {
|
||||||
|
try {
|
||||||
|
return await this.songListAPI.search(keyword, source)
|
||||||
|
} catch (error) {
|
||||||
|
return {
|
||||||
|
success: false,
|
||||||
|
error: error instanceof Error ? error.message : '搜索歌单失败'
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* 获取歌单统计信息
|
||||||
|
*/
|
||||||
|
async getStatistics(): Promise<IPCResponse<SongListStatistics>> {
|
||||||
|
try {
|
||||||
|
return await this.songListAPI.getStatistics()
|
||||||
|
} catch (error) {
|
||||||
|
return {
|
||||||
|
success: false,
|
||||||
|
error: error instanceof Error ? error.message : '获取统计信息失败'
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* 检查歌单是否存在
|
||||||
|
*/
|
||||||
|
async exists(hashId: string): Promise<IPCResponse<boolean>> {
|
||||||
|
try {
|
||||||
|
return await this.songListAPI.exists(hashId)
|
||||||
|
} catch (error) {
|
||||||
|
return {
|
||||||
|
success: false,
|
||||||
|
error: error instanceof Error ? error.message : '检查歌单存在性失败'
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
// === 歌曲管理方法 ===
|
||||||
|
|
||||||
|
/**
|
||||||
|
* 添加歌曲到歌单
|
||||||
|
*/
|
||||||
|
async addSongs(hashId: string, songs: Songs[]): Promise<IPCResponse> {
|
||||||
|
try {
|
||||||
|
return await this.songListAPI.addSongs(hashId, songs)
|
||||||
|
} catch (error) {
|
||||||
|
return {
|
||||||
|
success: false,
|
||||||
|
error: error instanceof Error ? error.message : '添加歌曲失败'
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* 从歌单移除歌曲
|
||||||
|
*/
|
||||||
|
async removeSong(hashId: string, songmid: string | number): Promise<IPCResponse<boolean>> {
|
||||||
|
try {
|
||||||
|
return await this.songListAPI.removeSong(hashId, songmid)
|
||||||
|
} catch (error) {
|
||||||
|
return {
|
||||||
|
success: false,
|
||||||
|
error: error instanceof Error ? error.message : '移除歌曲失败'
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* 批量移除歌曲
|
||||||
|
*/
|
||||||
|
async removeSongs(
|
||||||
|
hashId: string,
|
||||||
|
songmids: (string | number)[]
|
||||||
|
): Promise<IPCResponse<RemoveSongsResult>> {
|
||||||
|
try {
|
||||||
|
return await this.songListAPI.removeSongs(hashId, songmids)
|
||||||
|
} catch (error) {
|
||||||
|
return {
|
||||||
|
success: false,
|
||||||
|
error: error instanceof Error ? error.message : '批量移除歌曲失败'
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* 清空歌单
|
||||||
|
*/
|
||||||
|
async clearSongs(hashId: string): Promise<IPCResponse> {
|
||||||
|
try {
|
||||||
|
return await this.songListAPI.clearSongs(hashId)
|
||||||
|
} catch (error) {
|
||||||
|
return {
|
||||||
|
success: false,
|
||||||
|
error: error instanceof Error ? error.message : '清空歌单失败'
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* 获取歌单中的歌曲列表
|
||||||
|
*/
|
||||||
|
async getSongs(hashId: string): Promise<IPCResponse<readonly Songs[]>> {
|
||||||
|
try {
|
||||||
|
return await this.songListAPI.getSongs(hashId)
|
||||||
|
} catch (error) {
|
||||||
|
return {
|
||||||
|
success: false,
|
||||||
|
error: error instanceof Error ? error.message : '获取歌曲列表失败'
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* 获取歌单歌曲数量
|
||||||
|
*/
|
||||||
|
async getSongCount(hashId: string): Promise<IPCResponse<number>> {
|
||||||
|
try {
|
||||||
|
return await this.songListAPI.getSongCount(hashId)
|
||||||
|
} catch (error) {
|
||||||
|
return {
|
||||||
|
success: false,
|
||||||
|
error: error instanceof Error ? error.message : '获取歌曲数量失败'
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* 检查歌曲是否在歌单中
|
||||||
|
*/
|
||||||
|
async hasSong(hashId: string, songmid: string | number): Promise<IPCResponse<boolean>> {
|
||||||
|
try {
|
||||||
|
return await this.songListAPI.hasSong(hashId, songmid)
|
||||||
|
} catch (error) {
|
||||||
|
return {
|
||||||
|
success: false,
|
||||||
|
error: error instanceof Error ? error.message : '检查歌曲存在性失败'
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* 根据ID获取歌曲
|
||||||
|
*/
|
||||||
|
async getSong(hashId: string, songmid: string | number): Promise<IPCResponse<Songs | null>> {
|
||||||
|
try {
|
||||||
|
return await this.songListAPI.getSong(hashId, songmid)
|
||||||
|
} catch (error) {
|
||||||
|
return {
|
||||||
|
success: false,
|
||||||
|
error: error instanceof Error ? error.message : '获取歌曲信息失败'
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* 搜索歌单中的歌曲
|
||||||
|
*/
|
||||||
|
async searchSongs(hashId: string, keyword: string): Promise<IPCResponse<Songs[]>> {
|
||||||
|
try {
|
||||||
|
return await this.songListAPI.searchSongs(hashId, keyword)
|
||||||
|
} catch (error) {
|
||||||
|
return {
|
||||||
|
success: false,
|
||||||
|
error: error instanceof Error ? error.message : '搜索歌曲失败'
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* 获取歌单歌曲统计信息
|
||||||
|
*/
|
||||||
|
async getSongStatistics(hashId: string): Promise<IPCResponse<SongStatistics>> {
|
||||||
|
try {
|
||||||
|
return await this.songListAPI.getSongStatistics(hashId)
|
||||||
|
} catch (error) {
|
||||||
|
return {
|
||||||
|
success: false,
|
||||||
|
error: error instanceof Error ? error.message : '获取歌曲统计信息失败'
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* 验证歌单完整性
|
||||||
|
*/
|
||||||
|
async validateIntegrity(hashId: string): Promise<IPCResponse<IntegrityCheckResult>> {
|
||||||
|
try {
|
||||||
|
return await this.songListAPI.validateIntegrity(hashId)
|
||||||
|
} catch (error) {
|
||||||
|
return {
|
||||||
|
success: false,
|
||||||
|
error: error instanceof Error ? error.message : '验证数据完整性失败'
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* 修复歌单数据
|
||||||
|
*/
|
||||||
|
async repairData(hashId: string): Promise<IPCResponse<RepairResult>> {
|
||||||
|
try {
|
||||||
|
return await this.songListAPI.repairData(hashId)
|
||||||
|
} catch (error) {
|
||||||
|
return {
|
||||||
|
success: false,
|
||||||
|
error: error instanceof Error ? error.message : '修复数据失败'
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* 强制保存歌单
|
||||||
|
*/
|
||||||
|
async forceSave(hashId: string): Promise<IPCResponse> {
|
||||||
|
try {
|
||||||
|
return await this.songListAPI.forceSave(hashId)
|
||||||
|
} catch (error) {
|
||||||
|
return {
|
||||||
|
success: false,
|
||||||
|
error: error instanceof Error ? error.message : '强制保存失败'
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
// === 便捷方法 ===
|
||||||
|
|
||||||
|
/**
|
||||||
|
* 创建本地歌单的便捷方法
|
||||||
|
*/
|
||||||
|
async createLocal(name: string, description?: string): Promise<IPCResponse<{ id: string }>> {
|
||||||
|
return this.create(name, description, 'local')
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* 获取歌单详细信息(包含歌曲列表)
|
||||||
|
*/
|
||||||
|
async getPlaylistDetail(hashId: string): Promise<{
|
||||||
|
playlist: SongList | null
|
||||||
|
songs: readonly Songs[]
|
||||||
|
success: boolean
|
||||||
|
error?: string
|
||||||
|
}> {
|
||||||
|
try {
|
||||||
|
const [playlistRes, songsRes] = await Promise.all([
|
||||||
|
this.getById(hashId),
|
||||||
|
this.getSongs(hashId)
|
||||||
|
])
|
||||||
|
|
||||||
|
if (!playlistRes.success) {
|
||||||
|
return {
|
||||||
|
playlist: null,
|
||||||
|
songs: [],
|
||||||
|
success: false,
|
||||||
|
error: playlistRes.error
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
return {
|
||||||
|
playlist: playlistRes.data || null,
|
||||||
|
songs: songsRes.success ? songsRes.data || [] : [],
|
||||||
|
success: true
|
||||||
|
}
|
||||||
|
} catch (error) {
|
||||||
|
return {
|
||||||
|
playlist: null,
|
||||||
|
songs: [],
|
||||||
|
success: false,
|
||||||
|
error: error instanceof Error ? error.message : '获取歌单详情失败'
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* 安全删除歌单(带确认)
|
||||||
|
*/
|
||||||
|
async safeDelete(hashId: string, confirmCallback?: () => Promise<boolean>): Promise<IPCResponse> {
|
||||||
|
if (confirmCallback) {
|
||||||
|
const confirmed = await confirmCallback()
|
||||||
|
if (!confirmed) {
|
||||||
|
return {
|
||||||
|
success: false,
|
||||||
|
error: '用户取消删除操作'
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
return this.delete(hashId)
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* 检查并修复歌单数据
|
||||||
|
*/
|
||||||
|
async checkAndRepair(hashId: string): Promise<{
|
||||||
|
needsRepair: boolean
|
||||||
|
repairResult?: RepairResult
|
||||||
|
success: boolean
|
||||||
|
error?: string
|
||||||
|
}> {
|
||||||
|
try {
|
||||||
|
const integrityRes = await this.validateIntegrity(hashId)
|
||||||
|
if (!integrityRes.success) {
|
||||||
|
return {
|
||||||
|
needsRepair: false,
|
||||||
|
success: false,
|
||||||
|
error: integrityRes.error
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
const { isValid } = integrityRes.data!
|
||||||
|
if (isValid) {
|
||||||
|
return {
|
||||||
|
needsRepair: false,
|
||||||
|
success: true
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
const repairRes = await this.repairData(hashId)
|
||||||
|
return {
|
||||||
|
needsRepair: true,
|
||||||
|
repairResult: repairRes.data,
|
||||||
|
success: repairRes.success,
|
||||||
|
error: repairRes.error
|
||||||
|
}
|
||||||
|
} catch (error) {
|
||||||
|
return {
|
||||||
|
needsRepair: false,
|
||||||
|
success: false,
|
||||||
|
error: error instanceof Error ? error.message : '检查修复失败'
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
// 创建单例实例
|
||||||
|
export const songListAPI = new SongListService()
|
||||||
|
|
||||||
|
// 默认导出
|
||||||
|
export default songListAPI
|
||||||
|
|
||||||
|
// 导出类型
|
||||||
|
export type { SongListAPI, IPCResponse }
|
||||||