添加同名文件处理方式

main
amuliang 2023-08-03 22:59:36 +08:00
parent cabd4e53eb
commit da6a83e1c0
3 changed files with 48 additions and 12 deletions

View File

@ -2,7 +2,7 @@ const http = require("http");
const url = require("url");
const { ServerModel } = require('./model/ServerModel');
const { SearchModel } = require('./model/SearchModel');
const { storeMusic, storeLrc, storePic } = require('./model/StoreModel');
const { storeMusic, storeLrc, storePic, checkMusicExists } = require('./model/StoreModel');
const { SuccessResult, ErrorResult } = require('./model/ResultModel');
const { QQSource } = require('./source/QQSource');
@ -34,6 +34,7 @@ searcher.registerSourceModel(new mfm.MyFreemp31tingSource());
// ***********************************************************************
// 添加API接口
const _server = new ServerModel();
_server.get("/api/source/all", (req, res, query) => {
// 罗列都有哪些源
return new SuccessResult(searcher.getSourceList());
@ -45,6 +46,11 @@ _server.get("/api/search", async (req, res, query) => {
return new SuccessResult(result);
});
_server.get("/api/store/check", async (req, res, query) => {
let is_exists = checkMusicExists(query.music_path);
return new SuccessResult(is_exists);
});
_server.get("/api/store", async (req, res, query) => {
//存储文件
let music_path = query.music_path;
@ -80,6 +86,7 @@ const server = http.createServer(async (req, res) => {
let reqUrl = req.url;
let reqApi = reqUrl.split('?')[0];
console.log(method, reqUrl);
let result;
try {
if(method == "GET") {
@ -94,6 +101,7 @@ const server = http.createServer(async (req, res) => {
console.error(err);
result = new ErrorResult(err);
}
res.setHeader('Access-Control-Allow-Origin', '*');
//res.setHeader('Access-Control-Allow-Methods', '*');
res.setHeader('Access-Control-Allow-Headers', '*');

View File

@ -41,8 +41,13 @@ async function storePic(path, url) {
return await storeResource(path, url);
}
function checkMusicExists(path) {
return fs.existsSync(path);
}
module.exports = {
storeMusic,
storeLrc,
storePic
storePic,
checkMusicExists
}

View File

@ -35,7 +35,7 @@
</Checkbox-Group>
</div>
<div style="margin: 10px 0">
<i-input v-model="keywords" style="display: inline-block;width: 80%;"></i-input>
<i-input v-model="keywords" @on-enter="searches" style="display: inline-block;width: 80%;"></i-input>
<i-button :loading="is_searching" @click="searches" style="width:18%">搜索</i-button>
</div>
<Alert v-if="messages.length">
@ -79,15 +79,15 @@
<p>
<i-input v-model="store_path" style="display: inline-block;"></i-input>
<p style="color:#888;word-break:break-all;">{{ renderedStorePath }}</p>
<i-button :loading="is_storing" @click="handleStore">确认存储</i-button>
<i-button :loading="is_storing" @click="handleStoreClick">确认存储</i-button>
<p style="color:green;">{{ store_message }}</p>
</p>
</i-col>
</Row>
</template>
</i-col>
<i-col span="10" style="padding:5px;height:250px;overflow: auto;border:#bbb;background-color: antiquewhite;">
<pre>{{ current_item.lrc }}</pre>
<i-col span="10" style="padding:5px;height:250px;">
<i-input v-model="current_item.lrc" type="textarea" :autosize="{minRows: 11,maxRows: 11}"></i-input>
</i-col>
</Row>
<div style="margin-top:10px;">
@ -97,7 +97,7 @@
<div style="margin:10px 0;">
<Row>
<i-col v-for="(item2, index) in result" span="8" style="padding:5px;">
<Card style="height:125px;">
<Card style="height:125px;overflow:hidden;">
<div @click="handleSelectItem(item2)">
<Row>
<i-col span="8">
@ -122,8 +122,8 @@
el: "#app",
data() {
const ajax = axios.create({
baseURL: 'http://www.amuliang.top:5750',
//baseURL: 'http://localhost:5000',
//baseURL: 'http://www.amuliang.top:5750',
baseURL: 'http://localhost:5000',
timeout: 10000,
headers: {
'Content-Type': 'application/x-www-form-urlencoded',
@ -197,10 +197,11 @@
this.$set(this, 'result', result);
this.is_searching = false;
if(result.length > 0) {
this.$set(this, 'current_item', result[0]);
this.handleSelectItem(result[0]);
}
},
handleSelectItem(item) {
this.store_message = '';
this.$set(this, 'current_item', item);
},
search(source_name, keywords, result) {
@ -223,10 +224,32 @@
resolve([]);
});
});
},
async handleStoreClick() {
this.is_storing = true;
let is_exists = await this.handleCheckMusicExists();
if(is_exists) {
this.$Modal.confirm({
title: '同名文件处理方式',
content: '歌曲已经存在,是否覆盖?',
onOk: () => {
this.handleStore();
},
onCancel: () => {
this.is_storing = false;
}
});
}else {
this.handleStore();
}
},
async handleCheckMusicExists() {
let response = await this.get('/api/store/check', {
music_path: this.renderedStorePath
});
return response.data.data;
},
handleStore() {
this.is_storing = true;
this.store_message = '';
if(getExtension(this.renderedStorePath) == '') {
this.$Message.error("请指定有效歌曲后缀名");