mirror of
https://github.com/algerkong/AlgerMusicPlayer.git
synced 2026-05-17 10:27:30 +08:00
🌈 style: 优化代码格式化
This commit is contained in:
@@ -29,4 +29,4 @@ export const openDirectory = (path: string | undefined, message: MessageApi, sho
|
||||
} else if (showTip) {
|
||||
message.info('目录不存在');
|
||||
}
|
||||
};
|
||||
};
|
||||
|
||||
@@ -1,4 +1,5 @@
|
||||
import { computed } from 'vue';
|
||||
|
||||
import store from '@/store';
|
||||
|
||||
// 设置歌手背景图片
|
||||
@@ -71,4 +72,4 @@ export const isMobile = computed(() => {
|
||||
return !!flag;
|
||||
});
|
||||
|
||||
export const isElectron = (window as any).electron !== undefined;
|
||||
export const isElectron = (window as any).electron !== undefined;
|
||||
|
||||
@@ -1,26 +1,27 @@
|
||||
import axios, { InternalAxiosRequestConfig } from 'axios';
|
||||
import { isElectron } from '.';
|
||||
import { createDiscreteApi } from 'naive-ui';
|
||||
|
||||
import store from '@/store';
|
||||
import { createDiscreteApi } from 'naive-ui'
|
||||
|
||||
import { isElectron } from '.';
|
||||
|
||||
const { notification } = createDiscreteApi(
|
||||
['notification']
|
||||
)
|
||||
const { notification } = createDiscreteApi(['notification']);
|
||||
|
||||
let setData: any = null;
|
||||
const getSetData = ()=>{
|
||||
const getSetData = () => {
|
||||
if (window.electron) {
|
||||
setData = window.electron.ipcRenderer.sendSync('get-store-value', 'set');
|
||||
}
|
||||
}
|
||||
getSetData()
|
||||
};
|
||||
getSetData();
|
||||
// 扩展请求配置接口
|
||||
interface CustomAxiosRequestConfig extends InternalAxiosRequestConfig {
|
||||
retryCount?: number;
|
||||
}
|
||||
|
||||
const baseURL = window.electron ? `http://127.0.0.1:${setData?.musicApiPort}` : import.meta.env.VITE_API;
|
||||
const baseURL = window.electron
|
||||
? `http://127.0.0.1:${setData?.musicApiPort}`
|
||||
: import.meta.env.VITE_API;
|
||||
|
||||
const request = axios.create({
|
||||
baseURL,
|
||||
@@ -46,23 +47,23 @@ request.interceptors.request.use(
|
||||
if (config.method === 'get') {
|
||||
config.params = {
|
||||
...config.params,
|
||||
timestamp: Date.now(),
|
||||
timestamp: Date.now()
|
||||
};
|
||||
const token = localStorage.getItem('token');
|
||||
if (token) {
|
||||
config.params.cookie = token + ' os=pc;';
|
||||
}else{
|
||||
config.params.cookie = `${token} os=pc;`;
|
||||
} else {
|
||||
config.params.cookie = 'os=pc;';
|
||||
}
|
||||
}
|
||||
|
||||
if(isElectron){
|
||||
const proxyConfig = setData?.proxyConfig
|
||||
if (isElectron) {
|
||||
const proxyConfig = setData?.proxyConfig;
|
||||
if (proxyConfig?.enable && ['http', 'https'].includes(proxyConfig?.protocol)) {
|
||||
config.params.proxy = `${proxyConfig.protocol}://${proxyConfig.host}:${proxyConfig.port}`
|
||||
config.params.proxy = `${proxyConfig.protocol}://${proxyConfig.host}:${proxyConfig.port}`;
|
||||
}
|
||||
if(setData.enableRealIP && setData.realIP){
|
||||
config.params.realIP = setData.realIP
|
||||
if (setData.enableRealIP && setData.realIP) {
|
||||
config.params.realIP = setData.realIP;
|
||||
}
|
||||
}
|
||||
|
||||
@@ -80,7 +81,7 @@ request.interceptors.response.use(
|
||||
return response;
|
||||
},
|
||||
async (error) => {
|
||||
console.log('error',error)
|
||||
console.log('error', error);
|
||||
const config = error.config as CustomAxiosRequestConfig;
|
||||
|
||||
// 如果没有配置,直接返回错误
|
||||
@@ -102,7 +103,7 @@ request.interceptors.response.use(
|
||||
meta: '请重新登录',
|
||||
duration: 2500,
|
||||
keepAliveOnHover: true
|
||||
})
|
||||
});
|
||||
|
||||
// 延迟重试
|
||||
await new Promise((resolve) => setTimeout(resolve, RETRY_DELAY));
|
||||
|
||||
@@ -1,6 +1,8 @@
|
||||
import axios from 'axios';
|
||||
import config from '../../../package.json';
|
||||
import { useDateFormat } from '@vueuse/core';
|
||||
import axios from 'axios';
|
||||
|
||||
import config from '../../../package.json';
|
||||
|
||||
interface GithubReleaseInfo {
|
||||
tag_name: string;
|
||||
body: string;
|
||||
@@ -39,15 +41,15 @@ export const getLatestReleaseInfo = async (): Promise<GithubReleaseInfo | null>
|
||||
const apiUrls = [
|
||||
// 原始地址
|
||||
'https://api.github.com/repos/algerkong/AlgerMusicPlayer/releases/latest',
|
||||
|
||||
|
||||
// 使用 ghproxy.com 代理
|
||||
'https://www.ghproxy.cn/https://raw.githubusercontent.com/algerkong/AlgerMusicPlayer/dev_electron/package.json',
|
||||
|
||||
'https://www.ghproxy.cn/https://raw.githubusercontent.com/algerkong/AlgerMusicPlayer/dev_electron/package.json'
|
||||
|
||||
// 使用 gitee 镜像(如果有的话)
|
||||
// 'https://gitee.com/api/v5/repos/[用户名]/AlgerMusicPlayer/releases/latest'
|
||||
];
|
||||
if (token) {
|
||||
headers['Authorization'] = `token ${token}`;
|
||||
headers['Authorization'] = `token ${token}`;
|
||||
}
|
||||
|
||||
for (const url of apiUrls) {
|
||||
@@ -58,7 +60,11 @@ export const getLatestReleaseInfo = async (): Promise<GithubReleaseInfo | null>
|
||||
// 如果是 package.json,直接读取版本号
|
||||
return {
|
||||
tag_name: response.data.version,
|
||||
body:(await axios.get('https://raw.githubusercontent.com/algerkong/AlgerMusicPlayer/dev_electron/CHANGELOG.md')).data,
|
||||
body: (
|
||||
await axios.get(
|
||||
'https://raw.githubusercontent.com/algerkong/AlgerMusicPlayer/dev_electron/CHANGELOG.md'
|
||||
)
|
||||
).data,
|
||||
html_url: 'https://github.com/algerkong/AlgerMusicPlayer/releases/latest',
|
||||
assets: []
|
||||
} as unknown as GithubReleaseInfo;
|
||||
@@ -86,10 +92,12 @@ export const formatDate = (dateStr: string): string => {
|
||||
/**
|
||||
* 检查更新
|
||||
*/
|
||||
export const checkUpdate = async (currentVersion: string = config.version): Promise<UpdateResult | null> => {
|
||||
export const checkUpdate = async (
|
||||
currentVersion: string = config.version
|
||||
): Promise<UpdateResult | null> => {
|
||||
try {
|
||||
const releaseInfo = await getLatestReleaseInfo();
|
||||
console.log('releaseInfo',releaseInfo)
|
||||
console.log('releaseInfo', releaseInfo);
|
||||
if (!releaseInfo) {
|
||||
return null;
|
||||
}
|
||||
@@ -98,8 +106,8 @@ export const checkUpdate = async (currentVersion: string = config.version): Prom
|
||||
if (latestVersion === currentVersion) {
|
||||
return null;
|
||||
}
|
||||
console.log('latestVersion',latestVersion)
|
||||
console.log('currentVersion',currentVersion)
|
||||
console.log('latestVersion', latestVersion);
|
||||
console.log('currentVersion', currentVersion);
|
||||
|
||||
return {
|
||||
hasUpdate: true,
|
||||
@@ -109,7 +117,7 @@ export const checkUpdate = async (currentVersion: string = config.version): Prom
|
||||
tag_name: latestVersion,
|
||||
body: `## 更新内容\n\n- 版本: ${latestVersion}\n${releaseInfo.body}`,
|
||||
html_url: releaseInfo.html_url,
|
||||
assets: releaseInfo.assets.map(asset => ({
|
||||
assets: releaseInfo.assets.map((asset) => ({
|
||||
browser_download_url: asset.browser_download_url,
|
||||
name: asset.name
|
||||
}))
|
||||
@@ -119,4 +127,4 @@ export const checkUpdate = async (currentVersion: string = config.version): Prom
|
||||
console.error('检查更新失败:', error);
|
||||
return null;
|
||||
}
|
||||
};
|
||||
};
|
||||
|
||||
Reference in New Issue
Block a user