新增分享音乐文件夹

音乐请求使用md5而不再使用文件
API请求排除拦截public的接口
This commit is contained in:
Yutousama 2022-01-06 02:11:28 +08:00
parent d9a4e4a81a
commit 1497d11754
3 changed files with 304 additions and 218 deletions

View File

@ -44,9 +44,11 @@ public class RoleAccessDecisionManager implements AccessDecisionManager {
case "/login/check.do":
return;
}
if(url.startsWith("/public/")){
return;
}
if(!Tools.isAdminLogin()){
String redis=RedisTools.get(musicShare);
System.out.println("分享token="+musicShare+" redis="+redis);
if(redis!=null&&!"-999".equals(redis)){
authentication.setAuthenticated(true);
return;

View File

@ -29,6 +29,7 @@ public class NasManager {
public static final String NasUrl="http://yutou233.cn";
@Resource
NasAdminAddressDao adminAddressDao;
@ResponseBody
@RequestMapping(value = "/auth/nas/address/get.do", method = RequestMethod.GET)
public String getAdminAddress(HttpServletRequest request) {
@ -45,6 +46,7 @@ public class NasManager {
}
return json.toJSONString();
}
@ResponseBody
@RequestMapping(value = "/auth/nas/address/list.do", method = RequestMethod.GET)
public String addressList(HttpServletRequest request) {
@ -68,6 +70,7 @@ public class NasManager {
}
return json.toJSONString();
}
@ResponseBody
@RequestMapping(value = "/auth/nas/address/add.do", method = RequestMethod.POST)
public String addAddress(HttpServletRequest request, String url, String port, String title) {
@ -87,6 +90,7 @@ public class NasManager {
}
return json.toJSONString();
}
@ResponseBody
@RequestMapping(value = "/auth/nas/address/update.do", method = RequestMethod.POST)
public String updateAddress(HttpServletRequest request, String url, String port, String title, String id) {
@ -118,6 +122,7 @@ public class NasManager {
}
return json.toJSONString();
}
@ResponseBody
@RequestMapping(value = "/auth/nas/address/remove.do", method = RequestMethod.POST)
public String removeAddress(HttpServletRequest request, String id) {
@ -133,6 +138,7 @@ public class NasManager {
}
return json.toJSONString();
}
@ResponseBody
@RequestMapping(value = "/auth/nas/address/set.do", method = RequestMethod.POST)
public String setAddress(HttpServletRequest request, String id) {
@ -151,6 +157,7 @@ public class NasManager {
}
return json.toJSONString();
}
@ResponseBody
@RequestMapping(value = "/jellyfin.do")
public void jellyfin(HttpServletResponse response) {
@ -166,7 +173,7 @@ public class NasManager {
public String getLocalHost() {
JSONObject json = new JSONObject();
if ("dev".equals(ConfigTools.load(ConfigTools.CONFIG, "model"))) {
json.put("data", NasUrl+":8001");
json.put("data", NasUrl + ":8000");
} else {
if (UpdateIp.nas_ip == null) {
json.put("data", "http://yutou233.cn:8001");
@ -177,16 +184,18 @@ public class NasManager {
json.put("code", 0);
return json.toJSONString();
}
@ResponseBody
@RequestMapping("/nas/music/share.do")
public JSONObject share(String file){
public JSONObject share(String file,boolean isDir) {
JSONObject json = new JSONObject();
String token = Tools.getMD5(UUID.randomUUID() + file);
json.put("token", token);
json.put("file", file);
json.put("isDir",isDir);
HashMap<String, String> header = new HashMap<>();
header.put("content-type", "application/json");
String url=NasUrl+":8001";
String url = NasUrl + ":8000";
if (UpdateIp.nas_ip != null) {
url = "http://" + UpdateIp.nas_ip + ":8000";
}
@ -203,13 +212,14 @@ public class NasManager {
json.put("data", _data);
return json;
}
@ResponseBody
@RequestMapping("/nas/music/playShare.do")
public JSONObject playShare(String share) {
JSONObject json = new JSONObject();
String redis = RedisTools.get(share);
if (redis != null && !"-999".equals(redis)) {
String url=NasUrl+":8001";
String url = NasUrl + ":8000";
if (UpdateIp.nas_ip != null) {
url = "http://" + UpdateIp.nas_ip + ":8000";
}
@ -218,7 +228,8 @@ public class NasManager {
JSONObject item = JSONObject.parseObject(_json);
if (item.getInteger("code") == 0) {
json.put("code", 0);
json.put("data", item.getJSONObject("data").getString("file"));
JSONArray array = item.getJSONObject("data").getJSONArray("file");
json.put("data", array);
} else {
json.put("code", "-1");
json.put("msg", "分享已过期");
@ -229,4 +240,52 @@ public class NasManager {
}
return json;
}
@ResponseBody
@RequestMapping(value = "/public/nas/music/pplist.do",produces = "application/json")
public JSONObject getPlayList(String share) {
String redis = RedisTools.get(share);
JSONObject json = new JSONObject();
String url = NasUrl + ":8000";
if (UpdateIp.nas_ip != null) {
url = "http://" + UpdateIp.nas_ip + ":8000";
}
String _json = HttpTools.get(url + "/nas/music/playShare.do?token=" + JSONObject.parseObject(redis).getJSONObject("data").getString("share"));
JSONObject item = JSONObject.parseObject(_json);
JSONArray array = item.getJSONObject("data").getJSONArray("file");
json.put("size", array.size());
json.put("scan", false);
json.put("data", array);
json.put("code",0);
return json;
}
@ResponseBody
@RequestMapping("/public/nas/music/playlist.do")
public JSONObject getMusicPlayList(String share) {
JSONObject json = new JSONObject();
String redis = RedisTools.get(share);
if ((StringUtils.isEmpty(redis) || "-999".equals(redis)) && !Tools.isAdminLogin()) {
json.put("code", -1);
} else {
json.put("code", 0);
if (!StringUtils.isEmpty(share)) {
json.put("data", "/public/nas/music/pplist.do?share=" + share);
} else if (Tools.isAdminLogin()) {
if ("dev".equals(ConfigTools.load(ConfigTools.CONFIG, "model"))) {
json.put("data", NasUrl + ":8000/nas/music/list.do?token=");
} else {
if (UpdateIp.nas_ip == null) {
json.put("data", "http://yutou233.cn:8001/nas/music/list.do?token=");
} else {
json.put("data", String.format("http://%s:8000/nas/music/list.do?token=", UpdateIp.nas_ip));
}
}
} else {
json.put("code", -1);
}
}
return json;
}
}

View File

@ -66,7 +66,7 @@
let playNow = ""
let share=getParam('share');
if(share!=null){
$('#playlist').remove()
//$('#playlist').remove()
$('#reload').remove()
$('#next').remove()
$('#play_share').remove()
@ -89,9 +89,14 @@
layui.use(['table', 'element'], function () {
let table = layui.table;
let element = layui.element;
let listTable = table.render({
let listTable = undefined;
$.post("/public/nas/music/playlist.do",{share:share},function (json) {
if(json.code!==0){
return;
}
listTable=table.render({
elem: '#playlist'
, url: localhost + '/nas/music/list.do?token=' //数据接口
, url: json.data //数据接口
, method: 'post'
, where: {
path: 'root',
@ -110,15 +115,19 @@
, done: function (res, curr, count) {
musicLib = res.data
$('#musicSize').html("歌单总数:" + res.size)
},error:function (e,data){
}
})
table.on('rowDouble(music)', function (obj) {
console.log("双击:"+obj)
//obj 同上
if (obj.data.isdir === 1) {
let path=obj.data.md5;
if(path===undefined){
path=obj.data.file;
}
listTable.reload({
where: {
path: obj.data.file
path:path
}
, page: {
curr: 1
@ -127,18 +136,23 @@
} else {
isRandom = false;
playIndex = obj.tr[0].dataset.index;
play(obj.data.file)
play(obj.data)
}
});
table.on('tool(music)', function (obj) {
let data = obj.data;
if (obj.event === 'download') {
if (data.isdir === 0) {
window.open(localhost + "/nas/music/play.do?token=&random=false&filePath=" + new Base64().encode(data.file))
window.open(localhost + "/nas/music/play.do?token=&random=false&filePath=" + data.md5)
}
} else if (obj.event === 'play') {
if(data.md5!==undefined){
play(data)
return;
}
$.ajax({
type: "POST",
url:localhost + "/nas/music/list.do",
@ -165,7 +179,13 @@
}
})
}else if(obj.event==='share'){
$.post('/nas/music/share.do',{file:data.file},function (json){
let isDir=false;
let file=data.md5;
if(data.isdir===1){
isDir=true;
file=data.file;
}
$.post('/nas/music/share.do',{file:file,isDir:isDir},function (json){
if(json.code===0){
layer.prompt({
title:"分享链接",
@ -177,6 +197,20 @@
});
element.on('nav(menus)', function (elem) {
});
})
function playShare(){
$.get('/nas/music/playShare.do?share='+share,function (json) {
isRandom = false;
playIndex =0;
json.data.forEach(function (item) {
musicLib.push(item)
})
play(json.data[0])
})
}
if(share!==null){
playShare()
}
});
});
@ -218,7 +252,7 @@
playNext()
});
$('#play_share').click(function (){
$.post('/nas/music/share.do',{file:new Base64().decode(decodeURIComponent(playNow))},function (json){
$.post('/nas/music/share.do',{file:playNow},function (json){
if(json.code===0){
layer.prompt({
title:"分享链接",
@ -246,7 +280,7 @@
playIndex++
playNext()
} else {
play(musicLib[playIndex].file);
play(musicLib[playIndex]);
playIndex++
}
}
@ -268,14 +302,14 @@
})
}
function play(file) {
let filePath = escape(new Base64().encode(file))
playNow = filePath
console.log(localhost + "/nas/music/play.do?random=false&filePath=" + filePath )
function play(_json) {
let md5=''
md5=_json.md5
playNow = _json.md5
player.updateSource({
source: localhost + "/nas/music/play.do?random=false&filePath=" + filePath
source: localhost + "/nas/music/play.do?random=false&filePath=" + md5
});
update(filePath)
update(md5)
player.play()
}
@ -316,17 +350,8 @@
})
$('#img').attr("src",localhost+'/nas/music/web/image.do?fileName='+fileName);
}
function playShare(){
console.log("播放分享:"+share)
$.get('/nas/music/playShare.do?share='+share,function (json) {
isRandom = false;
playIndex =0;
play(json.data)
})
}
if(share!==null){
playShare()
}
</script>
<style>