|
@@ -1,8 +1,14 @@
|
|
|
import {dialog} from "electron"
|
|
|
-import {ApiType, ErrorCode, RequestData, ResponseData} from "@/types/apiTypes.ts";
|
|
|
+import { ErrorCode, RequestData, ResponseData} from "@/types/apiTypes.ts";
|
|
|
import Logger from "@/util/logger.ts";
|
|
|
import {MusicScanSetting} from "@/types/musicType.ts";
|
|
|
-import {addScanConfig, getScanConfig, getScanConfigByPath, updateScanConfig} from "@/common/db/db_music.ts";
|
|
|
+import {
|
|
|
+ addScanConfig,
|
|
|
+ deleteScanConfig, getPlayList,
|
|
|
+ getScanConfig,
|
|
|
+ getScanConfigByPath,
|
|
|
+ updateScanConfig
|
|
|
+} from "@/common/db/db_music.ts";
|
|
|
import {ResType} from "@/util/promiseHandle.ts";
|
|
|
import {t_gen_res, t_res_ok} from "@/main/tools/ipcRouter.ts";
|
|
|
let logger = Logger.logger('music', 'info');
|
|
@@ -11,17 +17,13 @@ let logger = Logger.logger('music', 'info');
|
|
|
|
|
|
export async function c_fetchPlayList(requestData: RequestData<null>)
|
|
|
{
|
|
|
- let responseData: ResponseData<any>
|
|
|
- responseData = {
|
|
|
- type: ApiType.res,
|
|
|
- code: ErrorCode.success,
|
|
|
- callId: requestData.callId,
|
|
|
- action: requestData.action,
|
|
|
- msg: '暂无歌单',
|
|
|
- data: [],
|
|
|
+ let [err, playList] = await getPlayList();
|
|
|
+ if (err)
|
|
|
+ {
|
|
|
+ logger.error(`[获取扫描设置列表失败] ${err.message}`)
|
|
|
+ return t_gen_res(requestData, ErrorCode.db, '获取扫描设置列表失败', [])
|
|
|
}
|
|
|
-
|
|
|
- return responseData;
|
|
|
+ return t_gen_res(requestData, ErrorCode.success, '', playList);
|
|
|
}
|
|
|
|
|
|
/**
|
|
@@ -31,7 +33,6 @@ export async function c_fetchPlayList(requestData: RequestData<null>)
|
|
|
export async function c_scanMusicSelect(requestData: RequestData<string>): Promise<ResponseData<string>>
|
|
|
{
|
|
|
let defaultPath = requestData.data;
|
|
|
- logger.info(`select scan dir`);
|
|
|
let result = await dialog.showOpenDialog({
|
|
|
defaultPath: defaultPath,
|
|
|
properties: ['openDirectory'],
|
|
@@ -98,7 +99,7 @@ export async function c_scanMusicUpdate(requestData: RequestData<MusicScanSettin
|
|
|
let scanSetting: MusicScanSetting = requestData.data;
|
|
|
let res: ResType<any> = false;
|
|
|
// 判断路径是否重复
|
|
|
- let [err, scanSettingList] = await getScanConfigByPath(scanSetting.path)
|
|
|
+ let [err, scanSettingList] = await getScanConfigByPath(scanSetting.path, [scanSetting.id])
|
|
|
if (err) {
|
|
|
logger.error(`[获取扫描设置列表失败] ${err.message}`)
|
|
|
return t_gen_res(requestData, ErrorCode.db, '获取扫描设置列表失败', false)
|
|
@@ -106,6 +107,7 @@ export async function c_scanMusicUpdate(requestData: RequestData<MusicScanSettin
|
|
|
scanSettingList = scanSettingList as MusicScanSetting[];
|
|
|
if (scanSettingList.length> 0)
|
|
|
{
|
|
|
+ // 防止找到正在修改的配置
|
|
|
logger.error(`[扫描路径重复] ${scanSetting.path}`)
|
|
|
return t_gen_res(requestData, ErrorCode.params, '扫描路径重复', false)
|
|
|
}
|
|
@@ -117,4 +119,18 @@ export async function c_scanMusicUpdate(requestData: RequestData<MusicScanSettin
|
|
|
}
|
|
|
res = res as boolean;
|
|
|
return t_res_ok(requestData, res)
|
|
|
-}
|
|
|
+}
|
|
|
+
|
|
|
+
|
|
|
+export async function c_scanMusicDelete(requestData: RequestData<number>) : Promise<ResponseData<boolean>>
|
|
|
+{
|
|
|
+ let res: ResType<any> = false;
|
|
|
+ let err : Error | null = null;
|
|
|
+ [err, res] = await deleteScanConfig(requestData.data);
|
|
|
+ if (err) {
|
|
|
+ logger.error(`[删除扫描设置失败] ${err.message}`)
|
|
|
+ return t_gen_res(requestData, ErrorCode.db, '删除扫描设置失败', false)
|
|
|
+ }
|
|
|
+ res = res as boolean;
|
|
|
+ return t_res_ok(requestData, res)
|
|
|
+}
|