新增分享音乐文件夹
音乐请求使用md5而不再使用文件 API请求排除拦截public的接口
This commit is contained in:
@@ -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;
|
||||
|
||||
@@ -29,71 +29,75 @@ 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){
|
||||
JSONObject json=new JSONObject();
|
||||
|
||||
String address= RedisTools.get("adminAddress");
|
||||
if(address==null){
|
||||
json.put("code",-1);
|
||||
json.put("msg","暂未设置管理后台");
|
||||
}else{
|
||||
JSONObject js=JSONObject.parseObject(address);
|
||||
json.put("code",0);
|
||||
json.put("msg","当前状态:"+js.getString("url")+":"+js.getString("port"));
|
||||
@ResponseBody
|
||||
@RequestMapping(value = "/auth/nas/address/get.do", method = RequestMethod.GET)
|
||||
public String getAdminAddress(HttpServletRequest request) {
|
||||
JSONObject json = new JSONObject();
|
||||
|
||||
String address = RedisTools.get("adminAddress");
|
||||
if (address == null) {
|
||||
json.put("code", -1);
|
||||
json.put("msg", "暂未设置管理后台");
|
||||
} else {
|
||||
JSONObject js = JSONObject.parseObject(address);
|
||||
json.put("code", 0);
|
||||
json.put("msg", "当前状态:" + js.getString("url") + ":" + js.getString("port"));
|
||||
}
|
||||
return json.toJSONString();
|
||||
}
|
||||
|
||||
@ResponseBody
|
||||
@RequestMapping(value = "/auth/nas/address/list.do",method = RequestMethod.GET)
|
||||
public String addressList(HttpServletRequest request){
|
||||
JSONObject json =new JSONObject();
|
||||
try{
|
||||
List<NasAdminAddress> list=adminAddressDao.selectByExample(new NasAdminAddressExample());
|
||||
json.put("code",0);
|
||||
json.put("msg","ok");
|
||||
json.put("count",list.size());
|
||||
if(list.size()==0){
|
||||
json.put("data",new JSONArray());
|
||||
}else {
|
||||
@RequestMapping(value = "/auth/nas/address/list.do", method = RequestMethod.GET)
|
||||
public String addressList(HttpServletRequest request) {
|
||||
JSONObject json = new JSONObject();
|
||||
try {
|
||||
List<NasAdminAddress> list = adminAddressDao.selectByExample(new NasAdminAddressExample());
|
||||
json.put("code", 0);
|
||||
json.put("msg", "ok");
|
||||
json.put("count", list.size());
|
||||
if (list.size() == 0) {
|
||||
json.put("data", new JSONArray());
|
||||
} else {
|
||||
json.put("data", JSONArray.toJSON(list));
|
||||
}
|
||||
}catch (Exception e){
|
||||
} catch (Exception e) {
|
||||
e.printStackTrace();
|
||||
json.put("code",-1);
|
||||
json.put("count",0);
|
||||
json.put("msg",e.getMessage());
|
||||
json.put("data","[]");
|
||||
json.put("code", -1);
|
||||
json.put("count", 0);
|
||||
json.put("msg", e.getMessage());
|
||||
json.put("data", "[]");
|
||||
}
|
||||
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) {
|
||||
JSONObject json=new JSONObject();
|
||||
@RequestMapping(value = "/auth/nas/address/add.do", method = RequestMethod.POST)
|
||||
public String addAddress(HttpServletRequest request, String url, String port, String title) {
|
||||
JSONObject json = new JSONObject();
|
||||
try {
|
||||
NasAdminAddress address=new NasAdminAddress();
|
||||
NasAdminAddress address = new NasAdminAddress();
|
||||
address.setUrl(url);
|
||||
address.setPort(Integer.parseInt(port));
|
||||
address.setTitle(title);
|
||||
adminAddressDao.insert(address);
|
||||
json.put("code",0);
|
||||
json.put("msg","ok");
|
||||
}catch (Exception e){
|
||||
json.put("code", 0);
|
||||
json.put("msg", "ok");
|
||||
} catch (Exception e) {
|
||||
e.printStackTrace();
|
||||
json.put("code",-1);
|
||||
json.put("msg",e.getMessage());
|
||||
json.put("code", -1);
|
||||
json.put("msg", e.getMessage());
|
||||
}
|
||||
return json.toJSONString();
|
||||
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){
|
||||
JSONObject json=new JSONObject();
|
||||
@RequestMapping(value = "/auth/nas/address/update.do", method = RequestMethod.POST)
|
||||
public String updateAddress(HttpServletRequest request, String url, String port, String title, String id) {
|
||||
JSONObject json = new JSONObject();
|
||||
try {
|
||||
NasAdminAddress address=adminAddressDao.selectByPrimaryKey(Integer.parseInt(id));
|
||||
if(address!=null) {
|
||||
NasAdminAddress address = adminAddressDao.selectByPrimaryKey(Integer.parseInt(id));
|
||||
if (address != null) {
|
||||
if (!StringUtils.isEmpty(url)) {
|
||||
address.setUrl(url);
|
||||
}
|
||||
@@ -104,58 +108,61 @@ public class NasManager {
|
||||
address.setTitle(title);
|
||||
}
|
||||
adminAddressDao.updateByPrimaryKey(address);
|
||||
json.put("code",0);
|
||||
json.put("msg","ok");
|
||||
}else {
|
||||
json.put("code",1);
|
||||
json.put("msg","无更新");
|
||||
json.put("code", 0);
|
||||
json.put("msg", "ok");
|
||||
} else {
|
||||
json.put("code", 1);
|
||||
json.put("msg", "无更新");
|
||||
}
|
||||
|
||||
}catch (Exception e){
|
||||
} catch (Exception e) {
|
||||
e.printStackTrace();
|
||||
json.put("code",-1);
|
||||
json.put("msg",e.getMessage());
|
||||
json.put("code", -1);
|
||||
json.put("msg", e.getMessage());
|
||||
}
|
||||
return json.toJSONString();
|
||||
}
|
||||
|
||||
@ResponseBody
|
||||
@RequestMapping(value = "/auth/nas/address/remove.do",method = RequestMethod.POST)
|
||||
public String removeAddress(HttpServletRequest request,String id){
|
||||
JSONObject json=new JSONObject();
|
||||
try{
|
||||
int code=adminAddressDao.deleteByPrimaryKey(Integer.parseInt(id));
|
||||
json.put("code",code);
|
||||
json.put("msg","ok");
|
||||
}catch (Exception e){
|
||||
e.printStackTrace();
|
||||
json.put("code",-1);
|
||||
json.put("msg",e.getMessage());
|
||||
}
|
||||
return json.toJSONString();
|
||||
}
|
||||
@ResponseBody
|
||||
@RequestMapping(value = "/auth/nas/address/set.do",method = RequestMethod.POST)
|
||||
public String setAddress(HttpServletRequest request,String id){
|
||||
JSONObject json=new JSONObject();
|
||||
@RequestMapping(value = "/auth/nas/address/remove.do", method = RequestMethod.POST)
|
||||
public String removeAddress(HttpServletRequest request, String id) {
|
||||
JSONObject json = new JSONObject();
|
||||
try {
|
||||
NasAdminAddress address=adminAddressDao.selectByPrimaryKey(Integer.parseInt(id));
|
||||
if(address!=null){
|
||||
RedisTools.set("adminAddress",JSONObject.toJSONString(address));
|
||||
}
|
||||
json.put("code",0);
|
||||
json.put("msg","ok");
|
||||
}catch (Exception e){
|
||||
int code = adminAddressDao.deleteByPrimaryKey(Integer.parseInt(id));
|
||||
json.put("code", code);
|
||||
json.put("msg", "ok");
|
||||
} catch (Exception e) {
|
||||
e.printStackTrace();
|
||||
json.put("code",-1);
|
||||
json.put("msg",e.getMessage());
|
||||
json.put("code", -1);
|
||||
json.put("msg", e.getMessage());
|
||||
}
|
||||
return json.toJSONString();
|
||||
}
|
||||
|
||||
@ResponseBody
|
||||
@RequestMapping(value = "/auth/nas/address/set.do", method = RequestMethod.POST)
|
||||
public String setAddress(HttpServletRequest request, String id) {
|
||||
JSONObject json = new JSONObject();
|
||||
try {
|
||||
NasAdminAddress address = adminAddressDao.selectByPrimaryKey(Integer.parseInt(id));
|
||||
if (address != null) {
|
||||
RedisTools.set("adminAddress", JSONObject.toJSONString(address));
|
||||
}
|
||||
json.put("code", 0);
|
||||
json.put("msg", "ok");
|
||||
} catch (Exception e) {
|
||||
e.printStackTrace();
|
||||
json.put("code", -1);
|
||||
json.put("msg", e.getMessage());
|
||||
}
|
||||
return json.toJSONString();
|
||||
}
|
||||
|
||||
@ResponseBody
|
||||
@RequestMapping(value = "/jellyfin.do")
|
||||
public void jellyfin(HttpServletResponse response){
|
||||
public void jellyfin(HttpServletResponse response) {
|
||||
try {
|
||||
response.sendRedirect("http://"+UpdateIp.nas_ip+":8096");
|
||||
response.sendRedirect("http://" + UpdateIp.nas_ip + ":8096");
|
||||
} catch (IOException e) {
|
||||
e.printStackTrace();
|
||||
}
|
||||
@@ -165,67 +172,119 @@ public class NasManager {
|
||||
@ResponseBody
|
||||
public String getLocalHost() {
|
||||
JSONObject json = new JSONObject();
|
||||
if("dev".equals(ConfigTools.load(ConfigTools.CONFIG, "model"))){
|
||||
json.put("data", NasUrl+":8001");
|
||||
}else {
|
||||
if(UpdateIp.nas_ip==null) {
|
||||
if ("dev".equals(ConfigTools.load(ConfigTools.CONFIG, "model"))) {
|
||||
json.put("data", NasUrl + ":8000");
|
||||
} else {
|
||||
if (UpdateIp.nas_ip == null) {
|
||||
json.put("data", "http://yutou233.cn:8001");
|
||||
}else {
|
||||
} else {
|
||||
json.put("data", String.format("http://%s:8000", UpdateIp.nas_ip));
|
||||
}
|
||||
}
|
||||
json.put("code", 0);
|
||||
return json.toJSONString();
|
||||
}
|
||||
|
||||
@ResponseBody
|
||||
@RequestMapping("/nas/music/share.do")
|
||||
public JSONObject share(String file){
|
||||
JSONObject json=new JSONObject();
|
||||
String token= Tools.getMD5(UUID.randomUUID() +file);
|
||||
json.put("token",token);
|
||||
json.put("file",file);
|
||||
HashMap<String,String> header=new HashMap<>();
|
||||
header.put("content-type","application/json");
|
||||
String url=NasUrl+":8001";
|
||||
if(UpdateIp.nas_ip!=null){
|
||||
url="http://"+UpdateIp.nas_ip+":8000";
|
||||
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 + ":8000";
|
||||
if (UpdateIp.nas_ip != null) {
|
||||
url = "http://" + UpdateIp.nas_ip + ":8000";
|
||||
}
|
||||
String data=HttpTools.http_post(url+"/nas/music/share.do",json.toJSONString().getBytes(StandardCharsets.UTF_8),1,header);
|
||||
JSONObject _data=JSONObject.parseObject(data);
|
||||
if(_data.getInteger("code")==1) {
|
||||
String data = HttpTools.http_post(url + "/nas/music/share.do", json.toJSONString().getBytes(StandardCharsets.UTF_8), 1, header);
|
||||
JSONObject _data = JSONObject.parseObject(data);
|
||||
if (_data.getInteger("code") == 1) {
|
||||
RedisTools.set(token, data, 3600);
|
||||
System.out.println("设置分享token:" + token + " -> " + data);
|
||||
_data.put("token", token);
|
||||
}
|
||||
json.clear();
|
||||
json.put("code",0);
|
||||
json.put("msg","ok");
|
||||
json.put("data",_data);
|
||||
json.put("code", 0);
|
||||
json.put("msg", "ok");
|
||||
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";
|
||||
if(UpdateIp.nas_ip!=null){
|
||||
url="http://"+UpdateIp.nas_ip+":8000";
|
||||
public JSONObject playShare(String share) {
|
||||
JSONObject json = new JSONObject();
|
||||
String redis = RedisTools.get(share);
|
||||
if (redis != null && !"-999".equals(redis)) {
|
||||
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"));
|
||||
String _json = HttpTools.get(url + "/nas/music/playShare.do?token=" + JSONObject.parseObject(redis).getJSONObject("data").getString("share"));
|
||||
System.out.println(_json);
|
||||
JSONObject item=JSONObject.parseObject(_json);
|
||||
if(item.getInteger("code")==0) {
|
||||
JSONObject item = JSONObject.parseObject(_json);
|
||||
if (item.getInteger("code") == 0) {
|
||||
json.put("code", 0);
|
||||
json.put("data", item.getJSONObject("data").getString("file"));
|
||||
}else{
|
||||
json.put("code","-1");
|
||||
json.put("msg","分享已过期");
|
||||
JSONArray array = item.getJSONObject("data").getJSONArray("file");
|
||||
json.put("data", array);
|
||||
} else {
|
||||
json.put("code", "-1");
|
||||
json.put("msg", "分享已过期");
|
||||
}
|
||||
}else{
|
||||
json.put("code","-2");
|
||||
json.put("msg","连接错误");
|
||||
} else {
|
||||
json.put("code", "-2");
|
||||
json.put("msg", "连接错误");
|
||||
}
|
||||
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;
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user