添加同名文件处理方式
parent
cabd4e53eb
commit
da6a83e1c0
10
app/main.js
10
app/main.js
|
@ -2,7 +2,7 @@ const http = require("http");
|
||||||
const url = require("url");
|
const url = require("url");
|
||||||
const { ServerModel } = require('./model/ServerModel');
|
const { ServerModel } = require('./model/ServerModel');
|
||||||
const { SearchModel } = require('./model/SearchModel');
|
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 { SuccessResult, ErrorResult } = require('./model/ResultModel');
|
||||||
|
|
||||||
const { QQSource } = require('./source/QQSource');
|
const { QQSource } = require('./source/QQSource');
|
||||||
|
@ -34,6 +34,7 @@ searcher.registerSourceModel(new mfm.MyFreemp31tingSource());
|
||||||
// ***********************************************************************
|
// ***********************************************************************
|
||||||
// 添加API接口
|
// 添加API接口
|
||||||
const _server = new ServerModel();
|
const _server = new ServerModel();
|
||||||
|
|
||||||
_server.get("/api/source/all", (req, res, query) => {
|
_server.get("/api/source/all", (req, res, query) => {
|
||||||
// 罗列都有哪些源
|
// 罗列都有哪些源
|
||||||
return new SuccessResult(searcher.getSourceList());
|
return new SuccessResult(searcher.getSourceList());
|
||||||
|
@ -45,6 +46,11 @@ _server.get("/api/search", async (req, res, query) => {
|
||||||
return new SuccessResult(result);
|
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) => {
|
_server.get("/api/store", async (req, res, query) => {
|
||||||
//存储文件
|
//存储文件
|
||||||
let music_path = query.music_path;
|
let music_path = query.music_path;
|
||||||
|
@ -80,6 +86,7 @@ const server = http.createServer(async (req, res) => {
|
||||||
let reqUrl = req.url;
|
let reqUrl = req.url;
|
||||||
let reqApi = reqUrl.split('?')[0];
|
let reqApi = reqUrl.split('?')[0];
|
||||||
console.log(method, reqUrl);
|
console.log(method, reqUrl);
|
||||||
|
|
||||||
let result;
|
let result;
|
||||||
try {
|
try {
|
||||||
if(method == "GET") {
|
if(method == "GET") {
|
||||||
|
@ -94,6 +101,7 @@ const server = http.createServer(async (req, res) => {
|
||||||
console.error(err);
|
console.error(err);
|
||||||
result = new ErrorResult(err);
|
result = new ErrorResult(err);
|
||||||
}
|
}
|
||||||
|
|
||||||
res.setHeader('Access-Control-Allow-Origin', '*');
|
res.setHeader('Access-Control-Allow-Origin', '*');
|
||||||
//res.setHeader('Access-Control-Allow-Methods', '*');
|
//res.setHeader('Access-Control-Allow-Methods', '*');
|
||||||
res.setHeader('Access-Control-Allow-Headers', '*');
|
res.setHeader('Access-Control-Allow-Headers', '*');
|
||||||
|
|
|
@ -41,8 +41,13 @@ async function storePic(path, url) {
|
||||||
return await storeResource(path, url);
|
return await storeResource(path, url);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
function checkMusicExists(path) {
|
||||||
|
return fs.existsSync(path);
|
||||||
|
}
|
||||||
|
|
||||||
module.exports = {
|
module.exports = {
|
||||||
storeMusic,
|
storeMusic,
|
||||||
storeLrc,
|
storeLrc,
|
||||||
storePic
|
storePic,
|
||||||
|
checkMusicExists
|
||||||
}
|
}
|
|
@ -35,7 +35,7 @@
|
||||||
</Checkbox-Group>
|
</Checkbox-Group>
|
||||||
</div>
|
</div>
|
||||||
<div style="margin: 10px 0">
|
<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>
|
<i-button :loading="is_searching" @click="searches" style="width:18%">搜索</i-button>
|
||||||
</div>
|
</div>
|
||||||
<Alert v-if="messages.length">
|
<Alert v-if="messages.length">
|
||||||
|
@ -79,15 +79,15 @@
|
||||||
<p>
|
<p>
|
||||||
<i-input v-model="store_path" style="display: inline-block;"></i-input>
|
<i-input v-model="store_path" style="display: inline-block;"></i-input>
|
||||||
<p style="color:#888;word-break:break-all;">{{ renderedStorePath }}</p>
|
<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 style="color:green;">{{ store_message }}</p>
|
||||||
</p>
|
</p>
|
||||||
</i-col>
|
</i-col>
|
||||||
</Row>
|
</Row>
|
||||||
</template>
|
</template>
|
||||||
</i-col>
|
</i-col>
|
||||||
<i-col span="10" style="padding:5px;height:250px;overflow: auto;border:#bbb;background-color: antiquewhite;">
|
<i-col span="10" style="padding:5px;height:250px;">
|
||||||
<pre>{{ current_item.lrc }}</pre>
|
<i-input v-model="current_item.lrc" type="textarea" :autosize="{minRows: 11,maxRows: 11}"></i-input>
|
||||||
</i-col>
|
</i-col>
|
||||||
</Row>
|
</Row>
|
||||||
<div style="margin-top:10px;">
|
<div style="margin-top:10px;">
|
||||||
|
@ -97,7 +97,7 @@
|
||||||
<div style="margin:10px 0;">
|
<div style="margin:10px 0;">
|
||||||
<Row>
|
<Row>
|
||||||
<i-col v-for="(item2, index) in result" span="8" style="padding:5px;">
|
<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)">
|
<div @click="handleSelectItem(item2)">
|
||||||
<Row>
|
<Row>
|
||||||
<i-col span="8">
|
<i-col span="8">
|
||||||
|
@ -122,8 +122,8 @@
|
||||||
el: "#app",
|
el: "#app",
|
||||||
data() {
|
data() {
|
||||||
const ajax = axios.create({
|
const ajax = axios.create({
|
||||||
baseURL: 'http://www.amuliang.top:5750',
|
//baseURL: 'http://www.amuliang.top:5750',
|
||||||
//baseURL: 'http://localhost:5000',
|
baseURL: 'http://localhost:5000',
|
||||||
timeout: 10000,
|
timeout: 10000,
|
||||||
headers: {
|
headers: {
|
||||||
'Content-Type': 'application/x-www-form-urlencoded',
|
'Content-Type': 'application/x-www-form-urlencoded',
|
||||||
|
@ -197,10 +197,11 @@
|
||||||
this.$set(this, 'result', result);
|
this.$set(this, 'result', result);
|
||||||
this.is_searching = false;
|
this.is_searching = false;
|
||||||
if(result.length > 0) {
|
if(result.length > 0) {
|
||||||
this.$set(this, 'current_item', result[0]);
|
this.handleSelectItem(result[0]);
|
||||||
}
|
}
|
||||||
},
|
},
|
||||||
handleSelectItem(item) {
|
handleSelectItem(item) {
|
||||||
|
this.store_message = '';
|
||||||
this.$set(this, 'current_item', item);
|
this.$set(this, 'current_item', item);
|
||||||
},
|
},
|
||||||
search(source_name, keywords, result) {
|
search(source_name, keywords, result) {
|
||||||
|
@ -223,10 +224,32 @@
|
||||||
resolve([]);
|
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() {
|
handleStore() {
|
||||||
this.is_storing = true;
|
|
||||||
this.store_message = '';
|
this.store_message = '';
|
||||||
if(getExtension(this.renderedStorePath) == '') {
|
if(getExtension(this.renderedStorePath) == '') {
|
||||||
this.$Message.error("请指定有效歌曲后缀名");
|
this.$Message.error("请指定有效歌曲后缀名");
|
||||||
|
|
Loading…
Reference in New Issue