api token新增权限控制

音乐界面新增下载按钮
音乐列表新增返回功能
新增音乐文件夹功能
新增在文件夹内双击播放则按顺序播放当前文件夹内的歌
新增音乐文件夹列表的图标
This commit is contained in:
yutou 2020-10-26 16:50:16 +08:00
parent 180346963c
commit 3d60754263
17 changed files with 953 additions and 84 deletions

View File

@ -10,7 +10,7 @@
</parent>
<groupId>com.yutou</groupId>
<artifactId>tools</artifactId>
<version>1.0.9.3</version>
<version>1.0.9.5</version>
<name>tools</name>
<description>Demo project for Spring Boot</description>

View File

@ -1,5 +1,7 @@
package com.yutou.tools;
import com.yutou.tools.home.nas.MusicController;
import com.yutou.tools.utils.APIFilter;
import com.yutou.tools.utils.MusicTools;
import com.yutou.tools.utils.RedisTools;
import org.springframework.boot.SpringApplication;
@ -9,9 +11,19 @@ import org.springframework.boot.autoconfigure.SpringBootApplication;
public class ToolsApplication {
public static void main(String[] args) {
System.out.println("当前版本号:1.0.9.5");
SpringApplication.run(ToolsApplication.class, args);
RedisTools.initRedisPoolSub();
MusicTools.getInstance().setMusicPath("C:\\Users\\admin\\Music\\");
if(APIFilter.isDebug) {
MusicController.defaultMusicPath="C:\\Users\\admin\\Music\\";
MusicTools.getInstance().setMusicPath("C:\\Users\\admin\\Music\\");
}
else{
MusicController.defaultMusicPath="/media/yutou/4t/public/音乐";
MusicTools.getInstance().setMusicPath("/media/yutou/4t/public/音乐");
}
}
}

View File

@ -6,6 +6,7 @@ import ealvatag.tag.NullTag;
import ealvatag.tag.Tag;
import ealvatag.tag.images.NullArtwork;
import lombok.Data;
import org.springframework.util.StringUtils;
import java.io.*;
import java.nio.file.Files;
@ -23,13 +24,28 @@ public class MusicData {
private String composer;//作曲
private String artist_sort;//分类
private File file;//音乐文件
private String lastDir;//上一个文件夹
private boolean isDir = false;
public void setFile(File file) {
this.file = file;
this.isDir = file.isDirectory();
this.lastDir=file.getParentFile().getParent();
}
public String getTitle() {
if (StringUtils.isEmpty(title)) {
title = file.getName();
}
return title;
}
public byte[] readImage() throws Exception {
AudioFile audioFile = null;
audioFile = AudioFileIO.read(file);
Tag tag = audioFile.getTag().or(NullTag.INSTANCE);
byte[] bytes=tag.getFirstArtwork().or(NullArtwork.INSTANCE).getBinaryData();
if (bytes.length==0) {
byte[] bytes = tag.getFirstArtwork().or(NullArtwork.INSTANCE).getBinaryData();
if (bytes.length == 0) {
return readImageFile();
}
return bytes;
@ -42,7 +58,7 @@ public class MusicData {
img = new File(path, "Cover.jpg");
if (!img.exists()) {
img = new File(path, "COVER.jpg");
if(!img.exists()){
if (!img.exists()) {
return null;
}
}

View File

@ -3,6 +3,8 @@ package com.yutou.tools.home.nas;
import com.alibaba.fastjson.JSONArray;
import com.alibaba.fastjson.JSONObject;
import com.yutou.tools.home.nas.Data.MusicData;
import com.yutou.tools.nas.UpdateIp;
import com.yutou.tools.utils.APIFilter;
import com.yutou.tools.utils.MusicTools;
import com.yutou.tools.utils.Tools;
import org.springframework.core.io.FileSystemResource;
@ -22,8 +24,7 @@ import java.util.List;
@RequestMapping("/nas/music/")
public class MusicController {
private String defaultMusicPath="C:\\Users\\admin\\Music";
private String musicPath=defaultMusicPath;
public static String defaultMusicPath="/media/yutou/4t/public/音乐";
@RequestMapping("all.do")
@ResponseBody
@ -40,21 +41,17 @@ public class MusicController {
@RequestMapping("list.do")
@ResponseBody
public String getMusicListOfPath(String path){
if(StringUtils.isEmpty(path)){
return getAllMusicList();
}
if(path.equals("root")){
return getAllMusicList();
if(StringUtils.isEmpty(path)||path.equals("root")){
path=defaultMusicPath;
}
//path=path.replace(defaultMusicPath+File.separator,"");
JSONObject json=new JSONObject();
JSONObject data = new JSONObject();
json.put("code", 1);
json.put("code", 0);
MusicTools tools = MusicTools.getInstance();
data.put("scan", tools.isScan());
data.put("size", tools.getLength());
data.put("list", JSONArray.toJSON(tools.getPath(path)));
json.put("data", data);
json.put("scan", tools.isScan());
json.put("size", tools.getLength());
json.put("data", JSONArray.toJSON(tools.getPath(path)));
return json.toJSONString();
}
@ -67,10 +64,22 @@ public class MusicController {
json.put("msg","地址为空");
return json.toJSONString();
}
json.put("code",1);
json.put("code",0);
json.put("data",MusicTools.getInstance().getMetadata(new File(base64ToString(path))));
return json.toJSONString();
}
@RequestMapping("getlocalhost.do")
@ResponseBody
public String getLocalHost(){
JSONObject json=new JSONObject();
if(APIFilter.isDebug){
json.put("data","");
}else{
json.put("data", "http://"+UpdateIp.nas_ip);
}
json.put("code",0);
return json.toJSONString();
}
@RequestMapping("image.do")
@ResponseBody
@ -79,7 +88,7 @@ public class MusicController {
json.put("code", 1);
if (StringUtils.isEmpty(fileName)) {
json.put("msg", "文件为空");
json.put("code", 0);
json.put("code", -1);
json.put("data", "");
return json.toJSONString();
}
@ -87,16 +96,16 @@ public class MusicController {
try {
if (file.exists()) {
json.put("msg", "ok");
json.put("code", 1);
json.put("code", 0);
json.put("data", MusicTools.getInstance().getMetadata(file).readImage());
} else {
json.put("msg", "文件不存在");
json.put("code", 0);
json.put("code", -1);
json.put("data", "");
}
}catch (Exception e){
json.put("msg", "图片读取失败");
json.put("code", 0);
json.put("code", -1);
json.put("data", "");
e.printStackTrace();
}
@ -109,7 +118,7 @@ public class MusicController {
List<MusicData> list=MusicTools.getInstance().getMusicList();
MusicData data=list.get(Tools.randomCommon(0,list.size()-1,1)[0]);
JSONObject json=new JSONObject();
json.put("code",1);
json.put("code",0);
try {
json.put("data", URLEncoder.encode(getBase64(data.getFile().getAbsolutePath()),"UTF-8"));
} catch (UnsupportedEncodingException e) {
@ -131,10 +140,8 @@ public class MusicController {
}
if(random){
List<MusicData> list=MusicTools.getInstance().getMusicList();
System.out.println("size = "+list.size());
MusicData data=list.get(Tools.randomCommon(0,list.size()-1,1)[0]);
filePath=data.getFile().getAbsolutePath();
System.out.println("随机歌曲:"+data.getTitle());
}
File file = new File(filePath);
if (file.exists()) {

View File

@ -0,0 +1,33 @@
package com.yutou.tools.mybatis.dao;
import com.yutou.tools.mybatis.model.Permission;
import com.yutou.tools.mybatis.model.PermissionExample;
import java.util.List;
import org.apache.ibatis.annotations.Mapper;
import org.apache.ibatis.annotations.Param;
@Mapper
public interface PermissionDao {
long countByExample(PermissionExample example);
int deleteByExample(PermissionExample example);
int deleteByPrimaryKey(Integer id);
int insert(Permission record);
int insertSelective(Permission record);
List<Permission> selectByExample(PermissionExample example);
Permission selectByPrimaryKey(Integer id);
int updateByExampleSelective(@Param("record") Permission record, @Param("example") PermissionExample example);
int updateByExample(@Param("record") Permission record, @Param("example") PermissionExample example);
int updateByPrimaryKeySelective(Permission record);
int updateByPrimaryKey(Permission record);
}

View File

@ -6,6 +6,7 @@ import java.util.List;
import org.apache.ibatis.annotations.Mapper;
import org.apache.ibatis.annotations.Param;
@Mapper
public interface UKeyDao {
long countByExample(UKeyExample example);
@ -22,8 +23,6 @@ public interface UKeyDao {
UKey selectByPrimaryKey(Integer id);
UKey selectByKey(String key);
int updateByExampleSelective(@Param("record") UKey record, @Param("example") UKeyExample example);
int updateByExample(@Param("record") UKey record, @Param("example") UKeyExample example);

View File

@ -0,0 +1,19 @@
package com.yutou.tools.mybatis.model;
import java.io.Serializable;
import lombok.Data;
/**
* permission
* @author
*/
@Data
public class Permission implements Serializable {
private Integer id;
private String title;
private String url;
private static final long serialVersionUID = 1L;
}

View File

@ -0,0 +1,401 @@
package com.yutou.tools.mybatis.model;
import java.util.ArrayList;
import java.util.List;
public class PermissionExample {
protected String orderByClause;
protected boolean distinct;
protected List<Criteria> oredCriteria;
public PermissionExample() {
oredCriteria = new ArrayList<>();
}
public void setOrderByClause(String orderByClause) {
this.orderByClause = orderByClause;
}
public String getOrderByClause() {
return orderByClause;
}
public void setDistinct(boolean distinct) {
this.distinct = distinct;
}
public boolean isDistinct() {
return distinct;
}
public List<Criteria> getOredCriteria() {
return oredCriteria;
}
public void or(Criteria criteria) {
oredCriteria.add(criteria);
}
public Criteria or() {
Criteria criteria = createCriteriaInternal();
oredCriteria.add(criteria);
return criteria;
}
public Criteria createCriteria() {
Criteria criteria = createCriteriaInternal();
if (oredCriteria.size() == 0) {
oredCriteria.add(criteria);
}
return criteria;
}
protected Criteria createCriteriaInternal() {
Criteria criteria = new Criteria();
return criteria;
}
public void clear() {
oredCriteria.clear();
orderByClause = null;
distinct = false;
}
protected abstract static class GeneratedCriteria {
protected List<Criterion> criteria;
protected GeneratedCriteria() {
super();
criteria = new ArrayList<>();
}
public boolean isValid() {
return criteria.size() > 0;
}
public List<Criterion> getAllCriteria() {
return criteria;
}
public List<Criterion> getCriteria() {
return criteria;
}
protected void addCriterion(String condition) {
if (condition == null) {
throw new RuntimeException("Value for condition cannot be null");
}
criteria.add(new Criterion(condition));
}
protected void addCriterion(String condition, Object value, String property) {
if (value == null) {
throw new RuntimeException("Value for " + property + " cannot be null");
}
criteria.add(new Criterion(condition, value));
}
protected void addCriterion(String condition, Object value1, Object value2, String property) {
if (value1 == null || value2 == null) {
throw new RuntimeException("Between values for " + property + " cannot be null");
}
criteria.add(new Criterion(condition, value1, value2));
}
public Criteria andIdIsNull() {
addCriterion("id is null");
return (Criteria) this;
}
public Criteria andIdIsNotNull() {
addCriterion("id is not null");
return (Criteria) this;
}
public Criteria andIdEqualTo(Integer value) {
addCriterion("id =", value, "id");
return (Criteria) this;
}
public Criteria andIdNotEqualTo(Integer value) {
addCriterion("id <>", value, "id");
return (Criteria) this;
}
public Criteria andIdGreaterThan(Integer value) {
addCriterion("id >", value, "id");
return (Criteria) this;
}
public Criteria andIdGreaterThanOrEqualTo(Integer value) {
addCriterion("id >=", value, "id");
return (Criteria) this;
}
public Criteria andIdLessThan(Integer value) {
addCriterion("id <", value, "id");
return (Criteria) this;
}
public Criteria andIdLessThanOrEqualTo(Integer value) {
addCriterion("id <=", value, "id");
return (Criteria) this;
}
public Criteria andIdIn(List<Integer> values) {
addCriterion("id in", values, "id");
return (Criteria) this;
}
public Criteria andIdNotIn(List<Integer> values) {
addCriterion("id not in", values, "id");
return (Criteria) this;
}
public Criteria andIdBetween(Integer value1, Integer value2) {
addCriterion("id between", value1, value2, "id");
return (Criteria) this;
}
public Criteria andIdNotBetween(Integer value1, Integer value2) {
addCriterion("id not between", value1, value2, "id");
return (Criteria) this;
}
public Criteria andTitleIsNull() {
addCriterion("title is null");
return (Criteria) this;
}
public Criteria andTitleIsNotNull() {
addCriterion("title is not null");
return (Criteria) this;
}
public Criteria andTitleEqualTo(String value) {
addCriterion("title =", value, "title");
return (Criteria) this;
}
public Criteria andTitleNotEqualTo(String value) {
addCriterion("title <>", value, "title");
return (Criteria) this;
}
public Criteria andTitleGreaterThan(String value) {
addCriterion("title >", value, "title");
return (Criteria) this;
}
public Criteria andTitleGreaterThanOrEqualTo(String value) {
addCriterion("title >=", value, "title");
return (Criteria) this;
}
public Criteria andTitleLessThan(String value) {
addCriterion("title <", value, "title");
return (Criteria) this;
}
public Criteria andTitleLessThanOrEqualTo(String value) {
addCriterion("title <=", value, "title");
return (Criteria) this;
}
public Criteria andTitleLike(String value) {
addCriterion("title like", value, "title");
return (Criteria) this;
}
public Criteria andTitleNotLike(String value) {
addCriterion("title not like", value, "title");
return (Criteria) this;
}
public Criteria andTitleIn(List<String> values) {
addCriterion("title in", values, "title");
return (Criteria) this;
}
public Criteria andTitleNotIn(List<String> values) {
addCriterion("title not in", values, "title");
return (Criteria) this;
}
public Criteria andTitleBetween(String value1, String value2) {
addCriterion("title between", value1, value2, "title");
return (Criteria) this;
}
public Criteria andTitleNotBetween(String value1, String value2) {
addCriterion("title not between", value1, value2, "title");
return (Criteria) this;
}
public Criteria andUrlIsNull() {
addCriterion("url is null");
return (Criteria) this;
}
public Criteria andUrlIsNotNull() {
addCriterion("url is not null");
return (Criteria) this;
}
public Criteria andUrlEqualTo(String value) {
addCriterion("url =", value, "url");
return (Criteria) this;
}
public Criteria andUrlNotEqualTo(String value) {
addCriterion("url <>", value, "url");
return (Criteria) this;
}
public Criteria andUrlGreaterThan(String value) {
addCriterion("url >", value, "url");
return (Criteria) this;
}
public Criteria andUrlGreaterThanOrEqualTo(String value) {
addCriterion("url >=", value, "url");
return (Criteria) this;
}
public Criteria andUrlLessThan(String value) {
addCriterion("url <", value, "url");
return (Criteria) this;
}
public Criteria andUrlLessThanOrEqualTo(String value) {
addCriterion("url <=", value, "url");
return (Criteria) this;
}
public Criteria andUrlLike(String value) {
addCriterion("url like", value, "url");
return (Criteria) this;
}
public Criteria andUrlNotLike(String value) {
addCriterion("url not like", value, "url");
return (Criteria) this;
}
public Criteria andUrlIn(List<String> values) {
addCriterion("url in", values, "url");
return (Criteria) this;
}
public Criteria andUrlNotIn(List<String> values) {
addCriterion("url not in", values, "url");
return (Criteria) this;
}
public Criteria andUrlBetween(String value1, String value2) {
addCriterion("url between", value1, value2, "url");
return (Criteria) this;
}
public Criteria andUrlNotBetween(String value1, String value2) {
addCriterion("url not between", value1, value2, "url");
return (Criteria) this;
}
}
/**
*/
public static class Criteria extends GeneratedCriteria {
protected Criteria() {
super();
}
}
public static class Criterion {
private String condition;
private Object value;
private Object secondValue;
private boolean noValue;
private boolean singleValue;
private boolean betweenValue;
private boolean listValue;
private String typeHandler;
public String getCondition() {
return condition;
}
public Object getValue() {
return value;
}
public Object getSecondValue() {
return secondValue;
}
public boolean isNoValue() {
return noValue;
}
public boolean isSingleValue() {
return singleValue;
}
public boolean isBetweenValue() {
return betweenValue;
}
public boolean isListValue() {
return listValue;
}
public String getTypeHandler() {
return typeHandler;
}
protected Criterion(String condition) {
super();
this.condition = condition;
this.typeHandler = null;
this.noValue = true;
}
protected Criterion(String condition, Object value, String typeHandler) {
super();
this.condition = condition;
this.value = value;
this.typeHandler = typeHandler;
if (value instanceof List<?>) {
this.listValue = true;
} else {
this.singleValue = true;
}
}
protected Criterion(String condition, Object value) {
this(condition, value, null);
}
protected Criterion(String condition, Object value, Object secondValue, String typeHandler) {
super();
this.condition = condition;
this.value = value;
this.secondValue = secondValue;
this.typeHandler = typeHandler;
this.betweenValue = true;
}
protected Criterion(String condition, Object value, Object secondValue) {
this(condition, value, secondValue, null);
}
}
}

View File

@ -13,5 +13,7 @@ public class UKey implements Serializable {
private String key;
private String power;
private static final long serialVersionUID = 1L;
}

View File

@ -233,6 +233,76 @@ public class UKeyExample {
addCriterion("`key` not between", value1, value2, "key");
return (Criteria) this;
}
public Criteria andPowerIsNull() {
addCriterion("`power` is null");
return (Criteria) this;
}
public Criteria andPowerIsNotNull() {
addCriterion("`power` is not null");
return (Criteria) this;
}
public Criteria andPowerEqualTo(String value) {
addCriterion("`power` =", value, "power");
return (Criteria) this;
}
public Criteria andPowerNotEqualTo(String value) {
addCriterion("`power` <>", value, "power");
return (Criteria) this;
}
public Criteria andPowerGreaterThan(String value) {
addCriterion("`power` >", value, "power");
return (Criteria) this;
}
public Criteria andPowerGreaterThanOrEqualTo(String value) {
addCriterion("`power` >=", value, "power");
return (Criteria) this;
}
public Criteria andPowerLessThan(String value) {
addCriterion("`power` <", value, "power");
return (Criteria) this;
}
public Criteria andPowerLessThanOrEqualTo(String value) {
addCriterion("`power` <=", value, "power");
return (Criteria) this;
}
public Criteria andPowerLike(String value) {
addCriterion("`power` like", value, "power");
return (Criteria) this;
}
public Criteria andPowerNotLike(String value) {
addCriterion("`power` not like", value, "power");
return (Criteria) this;
}
public Criteria andPowerIn(List<String> values) {
addCriterion("`power` in", values, "power");
return (Criteria) this;
}
public Criteria andPowerNotIn(List<String> values) {
addCriterion("`power` not in", values, "power");
return (Criteria) this;
}
public Criteria andPowerBetween(String value1, String value2) {
addCriterion("`power` between", value1, value2, "power");
return (Criteria) this;
}
public Criteria andPowerNotBetween(String value1, String value2) {
addCriterion("`power` not between", value1, value2, "power");
return (Criteria) this;
}
}
/**

View File

@ -1,6 +1,11 @@
package com.yutou.tools.utils;
import com.alibaba.fastjson.JSONArray;
import com.yutou.tools.mybatis.dao.PermissionDao;
import com.yutou.tools.mybatis.dao.UKeyDao;
import com.yutou.tools.mybatis.model.Permission;
import com.yutou.tools.mybatis.model.PermissionExample;
import com.yutou.tools.mybatis.model.UKey;
import com.yutou.tools.mybatis.model.UKeyExample;
import org.springframework.stereotype.Component;
import org.springframework.util.StringUtils;
@ -13,22 +18,25 @@ import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;
import java.io.IOException;
import java.util.Enumeration;
import java.util.List;
@Component
@WebFilter
public class APIFilter implements Filter {
private static boolean isDebug=true;
public static boolean isDebug = false;
@Resource
UKeyDao keyDao;
@Resource
PermissionDao permissionDao;
@Override
public void doFilter(ServletRequest servletRequest, ServletResponse servletResponse, FilterChain filterChain) throws IOException, ServletException {
if(isDebug){
/* if(isDebug){
filterChain.doFilter(servletRequest, servletResponse);
return;
}
}*/
HttpServletRequest request = (HttpServletRequest) servletRequest;
HttpServletResponse response= (HttpServletResponse) servletResponse;
HttpServletResponse response = (HttpServletResponse) servletResponse;
String token = request.getParameter("token");
Cookie cookie = Tools.getCookie(request, "user");
System.out.println("接收到请求:" + request.getRequestURI() + " " + token);
@ -37,8 +45,29 @@ public class APIFilter implements Filter {
if (!StringUtils.isEmpty(token)) {
UKeyExample example = new UKeyExample();
example.createCriteria().andKeyEqualTo(token);
if (keyDao.selectByExample(example).size() > 0) {
isToken = true;
List<UKey> list = keyDao.selectByExample(example);
if (list.size() > 0) {
String url = null;
String tmp = request.getRequestURI();
try {
url = tmp.split(tmp.split("/")[tmp.split("/").length - 1])[0];
} catch (Exception ignored) {
}
UKey key = list.get(0);
JSONArray powers = JSONArray.parseArray(key.getPower());
if(powers.toJavaList(String.class).contains("-1")){
isToken=true;
}else {
PermissionExample pExample = new PermissionExample();
pExample.createCriteria().andUrlEqualTo(url);
List<Permission> permissions = permissionDao.selectByExample(pExample);
if (permissions != null && permissions.size() > 0) {
if (powers.toJavaList(Integer.class).contains(permissions.get(0).getId())) {
isToken = true;
}
}
}
}
}
if (cookie != null) {
@ -50,7 +79,7 @@ public class APIFilter implements Filter {
if (!isCookie && !isToken) {
//response.sendRedirect("/");
System.out.println("请求无令牌,拦截");
if(!request.getRequestURI().contains("/login/")&&!request.getRequestURI().equals("/favicon.ico")){
if (!request.getRequestURI().contains("/login/") && !request.getRequestURI().equals("/favicon.ico")) {
response.sendRedirect("/");
return;
}

View File

@ -1,6 +1,7 @@
package com.yutou.tools.utils;
import com.yutou.tools.home.nas.Data.MusicData;
import com.yutou.tools.home.nas.MusicController;
import ealvatag.audio.AudioFile;
import ealvatag.audio.AudioFileIO;
import ealvatag.audio.exceptions.CannotReadException;
@ -77,16 +78,52 @@ public class MusicTools {
}
public List<MusicData> getPath(String path){
if(musicMap.containsKey(path)){
return musicMap.get(path);
List<MusicData> list=new ArrayList<>();
MusicData tmp=musicMap.get(path).isEmpty()?null:musicMap.get(path).get(0);
if(tmp!=null){
if(!tmp.getFile().getParent().equals(MusicController.defaultMusicPath)) {
MusicData t2 = new MusicData();
t2.setTitle("返回");
t2.setFile(new File(tmp.getLastDir()));
list.add(t2);
}
}
getDirList(path, list);
list.addAll(musicMap.get(path));
return list;
}else{
if(path.contains(MusicController.defaultMusicPath)){
List<MusicData> list=new ArrayList<>();
MusicData t2 = new MusicData();
t2.setTitle("返回");
t2.setFile(new File(path).getParentFile());
list.add(t2);
getDirList(path, list);
return list;
}
}
return new ArrayList<>();
}
private void getDirList(String path, List<MusicData> list) {
File file=new File(path);
for (File listFile : file.listFiles()) {
if(listFile.isDirectory()){
MusicData data=new MusicData();
data.setTitle(listFile.getName());
data.setFile(listFile);
list.add(data);
}
}
}
private void add(File file) {
MusicData data = getMetadata(file);
if (data != null) {
musicList.add(data);
String path=file.getAbsolutePath().replace(file.getName(),"");
String path=file.getAbsolutePath().replace(File.separator+file.getName(),"");
List<MusicData> list;
if(musicMap.containsKey(path)){
list=musicMap.get(path);
@ -100,7 +137,10 @@ public class MusicTools {
public MusicData getMetadata(File file) {
try {
if (file.getName().endsWith(".lrc") || file.getName().endsWith(".jpg")) {
if (file.getName().endsWith(".lrc")
|| file.getName().endsWith(".jpg")
|| file.getName().endsWith(".ini")
) {
return null;
}
AudioFile audioFile = AudioFileIO.read(file);

View File

@ -262,11 +262,20 @@ public class Tools {
downloadInterface.onError(e);
}
}
/**
* 构造给前端的文件
* @param file 文件路径
* @return 前端获取的文件
*/
public static ResponseEntity<FileSystemResource> getFile(File file){
HttpHeaders headers = new HttpHeaders();
System.out.println(file.getName());
headers.add("Cache-Control", "no-cache, no-store, must-revalidate");
headers.add("Content-Disposition", "attachment; filename=" + file.getName());
try {
headers.add("Content-Disposition", "attachment; filename=" +URLEncoder.encode(file.getName(),"UTF-8"));
} catch (UnsupportedEncodingException e) {
headers.add("Content-Disposition", "attachment; filename=" +file.getName());
}
headers.add("Pragma", "no-cache");
headers.add("Expires", "0");
headers.add("Last-Modified", new Date().toString());

View File

@ -0,0 +1,173 @@
<?xml version="1.0" encoding="UTF-8"?>
<!DOCTYPE mapper PUBLIC "-//mybatis.org//DTD Mapper 3.0//EN" "http://mybatis.org/dtd/mybatis-3-mapper.dtd">
<mapper namespace="com.yutou.tools.mybatis.dao.PermissionDao">
<resultMap id="BaseResultMap" type="com.yutou.tools.mybatis.model.Permission">
<id column="id" jdbcType="INTEGER" property="id" />
<result column="title" jdbcType="VARCHAR" property="title" />
<result column="url" jdbcType="VARCHAR" property="url" />
</resultMap>
<sql id="Example_Where_Clause">
<where>
<foreach collection="oredCriteria" item="criteria" separator="or">
<if test="criteria.valid">
<trim prefix="(" prefixOverrides="and" suffix=")">
<foreach collection="criteria.criteria" item="criterion">
<choose>
<when test="criterion.noValue">
and ${criterion.condition}
</when>
<when test="criterion.singleValue">
and ${criterion.condition} #{criterion.value}
</when>
<when test="criterion.betweenValue">
and ${criterion.condition} #{criterion.value} and #{criterion.secondValue}
</when>
<when test="criterion.listValue">
and ${criterion.condition}
<foreach close=")" collection="criterion.value" item="listItem" open="(" separator=",">
#{listItem}
</foreach>
</when>
</choose>
</foreach>
</trim>
</if>
</foreach>
</where>
</sql>
<sql id="Update_By_Example_Where_Clause">
<where>
<foreach collection="example.oredCriteria" item="criteria" separator="or">
<if test="criteria.valid">
<trim prefix="(" prefixOverrides="and" suffix=")">
<foreach collection="criteria.criteria" item="criterion">
<choose>
<when test="criterion.noValue">
and ${criterion.condition}
</when>
<when test="criterion.singleValue">
and ${criterion.condition} #{criterion.value}
</when>
<when test="criterion.betweenValue">
and ${criterion.condition} #{criterion.value} and #{criterion.secondValue}
</when>
<when test="criterion.listValue">
and ${criterion.condition}
<foreach close=")" collection="criterion.value" item="listItem" open="(" separator=",">
#{listItem}
</foreach>
</when>
</choose>
</foreach>
</trim>
</if>
</foreach>
</where>
</sql>
<sql id="Base_Column_List">
id, title, url
</sql>
<select id="selectByExample" parameterType="com.yutou.tools.mybatis.model.PermissionExample" resultMap="BaseResultMap">
select
<if test="distinct">
distinct
</if>
<include refid="Base_Column_List" />
from permission
<if test="_parameter != null">
<include refid="Example_Where_Clause" />
</if>
<if test="orderByClause != null">
order by ${orderByClause}
</if>
</select>
<select id="selectByPrimaryKey" parameterType="java.lang.Integer" resultMap="BaseResultMap">
select
<include refid="Base_Column_List" />
from permission
where id = #{id,jdbcType=INTEGER}
</select>
<delete id="deleteByPrimaryKey" parameterType="java.lang.Integer">
delete from permission
where id = #{id,jdbcType=INTEGER}
</delete>
<delete id="deleteByExample" parameterType="com.yutou.tools.mybatis.model.PermissionExample">
delete from permission
<if test="_parameter != null">
<include refid="Example_Where_Clause" />
</if>
</delete>
<insert id="insert" keyColumn="id" keyProperty="id" parameterType="com.yutou.tools.mybatis.model.Permission" useGeneratedKeys="true">
insert into permission (title, url)
values (#{title,jdbcType=VARCHAR}, #{url,jdbcType=VARCHAR})
</insert>
<insert id="insertSelective" keyColumn="id" keyProperty="id" parameterType="com.yutou.tools.mybatis.model.Permission" useGeneratedKeys="true">
insert into permission
<trim prefix="(" suffix=")" suffixOverrides=",">
<if test="title != null">
title,
</if>
<if test="url != null">
url,
</if>
</trim>
<trim prefix="values (" suffix=")" suffixOverrides=",">
<if test="title != null">
#{title,jdbcType=VARCHAR},
</if>
<if test="url != null">
#{url,jdbcType=VARCHAR},
</if>
</trim>
</insert>
<select id="countByExample" parameterType="com.yutou.tools.mybatis.model.PermissionExample" resultType="java.lang.Long">
select count(*) from permission
<if test="_parameter != null">
<include refid="Example_Where_Clause" />
</if>
</select>
<update id="updateByExampleSelective" parameterType="map">
update permission
<set>
<if test="record.id != null">
id = #{record.id,jdbcType=INTEGER},
</if>
<if test="record.title != null">
title = #{record.title,jdbcType=VARCHAR},
</if>
<if test="record.url != null">
url = #{record.url,jdbcType=VARCHAR},
</if>
</set>
<if test="_parameter != null">
<include refid="Update_By_Example_Where_Clause" />
</if>
</update>
<update id="updateByExample" parameterType="map">
update permission
set id = #{record.id,jdbcType=INTEGER},
title = #{record.title,jdbcType=VARCHAR},
url = #{record.url,jdbcType=VARCHAR}
<if test="_parameter != null">
<include refid="Update_By_Example_Where_Clause" />
</if>
</update>
<update id="updateByPrimaryKeySelective" parameterType="com.yutou.tools.mybatis.model.Permission">
update permission
<set>
<if test="title != null">
title = #{title,jdbcType=VARCHAR},
</if>
<if test="url != null">
url = #{url,jdbcType=VARCHAR},
</if>
</set>
where id = #{id,jdbcType=INTEGER}
</update>
<update id="updateByPrimaryKey" parameterType="com.yutou.tools.mybatis.model.Permission">
update permission
set title = #{title,jdbcType=VARCHAR},
url = #{url,jdbcType=VARCHAR}
where id = #{id,jdbcType=INTEGER}
</update>
</mapper>

View File

@ -4,6 +4,7 @@
<resultMap id="BaseResultMap" type="com.yutou.tools.mybatis.model.UKey">
<id column="id" jdbcType="INTEGER" property="id" />
<result column="key" jdbcType="VARCHAR" property="key" />
<result column="power" jdbcType="VARCHAR" property="power" />
</resultMap>
<sql id="Example_Where_Clause">
<where>
@ -64,7 +65,7 @@
</where>
</sql>
<sql id="Base_Column_List">
id, `key`
id, `key`, `power`
</sql>
<select id="selectByExample" parameterType="com.yutou.tools.mybatis.model.UKeyExample" resultMap="BaseResultMap">
select
@ -97,8 +98,8 @@
</if>
</delete>
<insert id="insert" keyColumn="id" keyProperty="id" parameterType="com.yutou.tools.mybatis.model.UKey" useGeneratedKeys="true">
insert into u_key (`key`)
values (#{key,jdbcType=VARCHAR})
insert into u_key (`key`, `power`)
values (#{key,jdbcType=VARCHAR}, #{power,jdbcType=VARCHAR})
</insert>
<insert id="insertSelective" keyColumn="id" keyProperty="id" parameterType="com.yutou.tools.mybatis.model.UKey" useGeneratedKeys="true">
insert into u_key
@ -106,11 +107,17 @@
<if test="key != null">
`key`,
</if>
<if test="power != null">
`power`,
</if>
</trim>
<trim prefix="values (" suffix=")" suffixOverrides=",">
<if test="key != null">
#{key,jdbcType=VARCHAR},
</if>
<if test="power != null">
#{power,jdbcType=VARCHAR},
</if>
</trim>
</insert>
<select id="countByExample" parameterType="com.yutou.tools.mybatis.model.UKeyExample" resultType="java.lang.Long">
@ -119,13 +126,6 @@
<include refid="Example_Where_Clause" />
</if>
</select>
<select id="selectByKey" resultType="com.yutou.tools.mybatis.model.UKey">
select
<include refid="Base_Column_List"/>
from u_key
where
`key` =#{key,jdbcType=VARCHAR}
</select>
<update id="updateByExampleSelective" parameterType="map">
update u_key
<set>
@ -135,6 +135,9 @@
<if test="record.key != null">
`key` = #{record.key,jdbcType=VARCHAR},
</if>
<if test="record.power != null">
`power` = #{record.power,jdbcType=VARCHAR},
</if>
</set>
<if test="_parameter != null">
<include refid="Update_By_Example_Where_Clause" />
@ -143,7 +146,8 @@
<update id="updateByExample" parameterType="map">
update u_key
set id = #{record.id,jdbcType=INTEGER},
`key` = #{record.key,jdbcType=VARCHAR}
`key` = #{record.key,jdbcType=VARCHAR},
`power` = #{record.power,jdbcType=VARCHAR}
<if test="_parameter != null">
<include refid="Update_By_Example_Where_Clause" />
</if>
@ -154,12 +158,16 @@
<if test="key != null">
`key` = #{key,jdbcType=VARCHAR},
</if>
<if test="power != null">
`power` = #{power,jdbcType=VARCHAR},
</if>
</set>
where id = #{id,jdbcType=INTEGER}
</update>
<update id="updateByPrimaryKey" parameterType="com.yutou.tools.mybatis.model.UKey">
update u_key
set `key` = #{key,jdbcType=VARCHAR}
set `key` = #{key,jdbcType=VARCHAR},
`power` = #{power,jdbcType=VARCHAR}
where id = #{id,jdbcType=INTEGER}
</update>
</mapper>

View File

@ -24,19 +24,12 @@
<div id="artist">艺术家:</div>
<div id="album">专辑:</div>
<div id="composer">作曲家</div>
<a class="layui-btn layui-btn-normal" id="download">下载</a>
</div>
<div id="audioWrap"></div>
</div>
<ul class="layui-nav layui-bg-cyan" lay-filter="menus" style="margin-right: 10px;">
<div style="margin-top: 10px;">
<span id="menu" class="layui-breadcrumb" lay-separator="/"
style="visibility: visible;">
<a href="javascript:onMenuClick('root');">主目录</a>
</span>
</div>
</ul>
<table id="playlist" lay-filter="music"></table>
</div>
@ -46,33 +39,78 @@
</div>
<script src="/layui/layui.js"></script>
<script src="/js/jquery-3.2.1.js"></script>
<script src="/js/video.min.js"></script>
<script src="/js/myjs.js"></script>
<link rel="stylesheet" href="/css/AudioPlayer.css">
<script src="/js/AudioPlayer.js"></script>
<script id="listTemplet">
{{# if(d.dir){ }}
<div><i class="layui-icon">&#xe656;</i>{{d.title}}</div>
{{# } else { }}
<div><i class="layui-icon">&#xe6fc;</i>{{d.title}}</div>
{{# } }}
</script>
<script type="text/html" id="music">
<a class="layui-btn layui-btn-xs" lay-event="download">下载</a>
</script>
<script>
//let localhost="http://192.168.31.88:8000";
let localhost = "";
let musicLib=[]
let isRandom=true;
let playIndex=0;
let playNow=""
$.get("/nas/music/getlocalhost.do",function (obj){
/* let json=JSON.parse(obj);
localhost=json.data;*/
// localhost="http://116.22.200.20:8000"
})
layui.use(['table', 'element'], function () {
let table = layui.table;
let element = layui.element;
table.render({
let listTable=table.render({
elem: '#playlist'
, height: 312
, url: localhost + '/nas/music/all.do' //数据接口
, url: localhost + '/nas/music/list.do?token=PlVodzYhvxRQbOHKakpKs2dvnoc43Cnk' //数据接口
, page: true //开启分页
, cols: [[
{field: 'title', title: '标题', width: 400}
{field: 'title', title: '标题', width: 400,templet:"#listTemplet"}
, {field: 'artist', title: '艺术家', width: 200}
, {field: 'album', title: '专辑', width: 200}
, {field: 'composer', title: '作曲', width: 200}
, {field: 'track', title: '音轨号', width: 100}
, {field: "right", width: 100, toolbar: '#music'}
]]
,done:function (res,curr,count){
musicLib=res.data
}
})
table.on('rowDouble(music)', function (obj) {
//obj 同上
console.log(obj.data.file) //得到当前行元素对象
play(obj.data.file)
console.log(obj.data) //得到当前行元素对象
if(obj.data.dir){
listTable.reload({
where:{
path:obj.data.file
}
,page:{
curr:1
}
});
}else{
isRandom=false;
playIndex=obj.tr[0].dataset.index;
play(obj.data.file)
}
});
table.on('tool(music)', function (obj) {
let data = obj.data;
if(obj.event === 'download'){
if(!data.dir){
window.open(localhost+"/nas/music/play.do?token=PlVodzYhvxRQbOHKakpKs2dvnoc43Cnk&random=false&filePath="+new Base64().encode(data.file))
}
}
});
element.on('nav(menus)', function (elem) {
console.log(elem); //得到当前点击的DOM对象
@ -94,7 +132,12 @@
, allowSeek: true
, endedCallback: function () {
console.log('播放完成')
random()
if(isRandom){
random()
}else{
playNext()
}
}, canplayCallback: function () {
console.log("点击播放")
}
@ -104,19 +147,34 @@
$('#footer').load("/html/footer.html");
$('#side').load("/html/body/nas/side.html");
$('#img').click(function () {
isRandom=true;
random()
});
$('#download').click(function (){
window.open(localhost+"/nas/music/play.do?token=PlVodzYhvxRQbOHKakpKs2dvnoc43Cnk&random=false&filePath="+playNow)
})
function onMenuClick(that) {
console.log(that)
function playNext(){
if(playIndex===musicLib.length){
playIndex=0;
}
if(musicLib[playIndex].dir){
playIndex++
playNext()
}else{
play(musicLib[playIndex].file);
playIndex++
}
}
function random() {
$.get(localhost + "/nas/music/random.do", function (data) {
$.get(localhost + "/nas/music/random.do?token=PlVodzYhvxRQbOHKakpKs2dvnoc43Cnk", function (data) {
let json = JSON.parse(data)
if (json.code === 1) {
if (json.code === 0) {
playNow=json.data
player.updateSource({
source: localhost + "/nas/music/play.do?random=false&filePath=" + json.data
source: localhost + "/nas/music/play.do?random=false&filePath=" + json.data+"&token=PlVodzYhvxRQbOHKakpKs2dvnoc43Cnk"
});
update(json.data)
player.play()
@ -129,31 +187,24 @@
function play(file) {
let filePath = escape(new Base64().encode(file))
playNow=filePath
player.updateSource({
source: localhost + "/nas/music/play.do?random=false&filePath=" + filePath
source: localhost + "/nas/music/play.do?random=false&filePath=" + filePath+"&token=PlVodzYhvxRQbOHKakpKs2dvnoc43Cnk"
});
update(filePath)
player.play()
}
function update(fileName) {
$.get(localhost + '/nas/music/find/file.do?path=' + fileName, function (data) {
$.get(localhost + '/nas/music/find/file.do?token=PlVodzYhvxRQbOHKakpKs2dvnoc43Cnk&path=' + fileName, function (data) {
let json = JSON.parse(data);
if (json.code === 0) {
layer.msg(json.msg);
return
}
$('#title').html("标题:" + json.data.title)
$('#artist').html("艺术家:" + json.data.artist)
$('#album').html("专辑:" + json.data.album)
$('#composer').html("作曲:" + json.data.composer)
})
$.get(localhost + "/nas/music/image.do?fileName=" + fileName, function (data) {
$.get(localhost + "/nas/music/image.do?token=PlVodzYhvxRQbOHKakpKs2dvnoc43Cnk&fileName=" + fileName, function (data) {
let json = JSON.parse(data);
if (json.code === 0) {
layer.msg(json.msg);
return
}
$('#img').attr("src", "data:image/png;base64," + json.data)
})
}

View File

@ -54,7 +54,7 @@
$('#side').load("/html/body/nas/side.html");
$.get("/login/check.do", function (data) {
let json = JSON.parse(data);
if (json.code != 0) {
if (json.code !== 0) {
window.location.href = "/"
}
})