修复双击文件夹会显示所有音乐的问题

This commit is contained in:
Yutousama 2020-10-26 23:19:20 +08:00
parent 806b257e81
commit dbe2b3fe1c
3 changed files with 17 additions and 9 deletions

View File

@ -40,7 +40,7 @@ public class MusicController {
} }
@RequestMapping("list.do") @RequestMapping("list.do")
@ResponseBody @ResponseBody
public String getMusicListOfPath(String path){ public String getMusicListOfPath(String path,String type){
if(!StringUtils.isEmpty(path)&&!new File(path).exists()){ if(!StringUtils.isEmpty(path)&&!new File(path).exists()){
path=base64ToString(path); path=base64ToString(path);
} }
@ -58,7 +58,7 @@ public class MusicController {
MusicTools tools = MusicTools.getInstance(); MusicTools tools = MusicTools.getInstance();
json.put("scan", tools.isScan()); json.put("scan", tools.isScan());
json.put("size", tools.getLength()); json.put("size", tools.getLength());
json.put("data", JSONArray.toJSON(tools.getPath(path))); json.put("data", JSONArray.toJSON(tools.getPath(path,!StringUtils.isEmpty(type))));
return json.toJSONString(); return json.toJSONString();
} }

View File

@ -89,16 +89,24 @@ public class MusicTools {
} }
} }
public List<MusicData> getPath(String path) { /**
* 获取指定目录下的音乐
* @param path 指定目录
* @param isDir 是否扫描目录下的所有文件false则仅为当前目录
* @return 音乐列表
*/
public List<MusicData> getPath(String path,boolean isDir) {
List<MusicData> list = new ArrayList<>(); List<MusicData> list = new ArrayList<>();
if (new File(path).isDirectory()&&!path.equals(MusicController.defaultMusicPath)) { if(isDir) {
if (new File(path).isDirectory() && !path.equals(MusicController.defaultMusicPath)) {
for (String key : musicMap.keySet()) { for (String key : musicMap.keySet()) {
if(key.startsWith(path)){ if (key.startsWith(path)) {
list.addAll(musicMap.get(key)); list.addAll(musicMap.get(key));
} }
} }
return list; return list;
} }
}
if (musicMap.containsKey(path)) { if (musicMap.containsKey(path)) {
MusicData tmp = musicMap.get(path).isEmpty() ? null : musicMap.get(path).get(0); MusicData tmp = musicMap.get(path).isEmpty() ? null : musicMap.get(path).get(0);
if (tmp != null) { if (tmp != null) {

View File

@ -119,7 +119,7 @@
} }
} else if (obj.event === 'play') { } else if (obj.event === 'play') {
console.log(data.file) console.log(data.file)
$.get(localhost + "/nas/music/list.do?token=PlVodzYhvxRQbOHKakpKs2dvnoc43Cnk&path=" + new Base64().encode(data.file), function (obj) { $.get(localhost + "/nas/music/list.do?token=PlVodzYhvxRQbOHKakpKs2dvnoc43Cnk&type=all&path=" + new Base64().encode(data.file), function (obj) {
let json = JSON.parse(obj); let json = JSON.parse(obj);
console.log(json) console.log(json)
if(json.code===0){ if(json.code===0){