diff --git a/pom.xml b/pom.xml index 0e8d7e4..e062332 100644 --- a/pom.xml +++ b/pom.xml @@ -10,7 +10,7 @@ com.yutou tools - 1.0.9.3 + 1.0.9.5 tools Demo project for Spring Boot diff --git a/src/main/java/com/yutou/tools/ToolsApplication.java b/src/main/java/com/yutou/tools/ToolsApplication.java index 58dbd82..3f904c7 100644 --- a/src/main/java/com/yutou/tools/ToolsApplication.java +++ b/src/main/java/com/yutou/tools/ToolsApplication.java @@ -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/音乐"); + } + + } } diff --git a/src/main/java/com/yutou/tools/home/nas/Data/MusicData.java b/src/main/java/com/yutou/tools/home/nas/Data/MusicData.java index 7a640d2..2ec66b5 100644 --- a/src/main/java/com/yutou/tools/home/nas/Data/MusicData.java +++ b/src/main/java/com/yutou/tools/home/nas/Data/MusicData.java @@ -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; } } diff --git a/src/main/java/com/yutou/tools/home/nas/MusicController.java b/src/main/java/com/yutou/tools/home/nas/MusicController.java index 7f81b2a..9ce1a79 100644 --- a/src/main/java/com/yutou/tools/home/nas/MusicController.java +++ b/src/main/java/com/yutou/tools/home/nas/MusicController.java @@ -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 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 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()) { diff --git a/src/main/java/com/yutou/tools/mybatis/dao/PermissionDao.java b/src/main/java/com/yutou/tools/mybatis/dao/PermissionDao.java new file mode 100644 index 0000000..f0b0c12 --- /dev/null +++ b/src/main/java/com/yutou/tools/mybatis/dao/PermissionDao.java @@ -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 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); +} \ No newline at end of file diff --git a/src/main/java/com/yutou/tools/mybatis/dao/UKeyDao.java b/src/main/java/com/yutou/tools/mybatis/dao/UKeyDao.java index c0f4efb..cf1370b 100644 --- a/src/main/java/com/yutou/tools/mybatis/dao/UKeyDao.java +++ b/src/main/java/com/yutou/tools/mybatis/dao/UKeyDao.java @@ -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); diff --git a/src/main/java/com/yutou/tools/mybatis/model/Permission.java b/src/main/java/com/yutou/tools/mybatis/model/Permission.java new file mode 100644 index 0000000..d5d351f --- /dev/null +++ b/src/main/java/com/yutou/tools/mybatis/model/Permission.java @@ -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; +} \ No newline at end of file diff --git a/src/main/java/com/yutou/tools/mybatis/model/PermissionExample.java b/src/main/java/com/yutou/tools/mybatis/model/PermissionExample.java new file mode 100644 index 0000000..f28127b --- /dev/null +++ b/src/main/java/com/yutou/tools/mybatis/model/PermissionExample.java @@ -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 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 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 criteria; + + protected GeneratedCriteria() { + super(); + criteria = new ArrayList<>(); + } + + public boolean isValid() { + return criteria.size() > 0; + } + + public List getAllCriteria() { + return criteria; + } + + public List 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 values) { + addCriterion("id in", values, "id"); + return (Criteria) this; + } + + public Criteria andIdNotIn(List 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 values) { + addCriterion("title in", values, "title"); + return (Criteria) this; + } + + public Criteria andTitleNotIn(List 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 values) { + addCriterion("url in", values, "url"); + return (Criteria) this; + } + + public Criteria andUrlNotIn(List 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); + } + } +} \ No newline at end of file diff --git a/src/main/java/com/yutou/tools/mybatis/model/UKey.java b/src/main/java/com/yutou/tools/mybatis/model/UKey.java index 63fd4a9..6c9b998 100644 --- a/src/main/java/com/yutou/tools/mybatis/model/UKey.java +++ b/src/main/java/com/yutou/tools/mybatis/model/UKey.java @@ -13,5 +13,7 @@ public class UKey implements Serializable { private String key; + private String power; + private static final long serialVersionUID = 1L; } \ No newline at end of file diff --git a/src/main/java/com/yutou/tools/mybatis/model/UKeyExample.java b/src/main/java/com/yutou/tools/mybatis/model/UKeyExample.java index 6dc9e4c..555127a 100644 --- a/src/main/java/com/yutou/tools/mybatis/model/UKeyExample.java +++ b/src/main/java/com/yutou/tools/mybatis/model/UKeyExample.java @@ -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 values) { + addCriterion("`power` in", values, "power"); + return (Criteria) this; + } + + public Criteria andPowerNotIn(List 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; + } } /** diff --git a/src/main/java/com/yutou/tools/utils/APIFilter.java b/src/main/java/com/yutou/tools/utils/APIFilter.java index e9902e0..6f0f2cc 100644 --- a/src/main/java/com/yutou/tools/utils/APIFilter.java +++ b/src/main/java/com/yutou/tools/utils/APIFilter.java @@ -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 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 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; } diff --git a/src/main/java/com/yutou/tools/utils/MusicTools.java b/src/main/java/com/yutou/tools/utils/MusicTools.java index 835da82..a3432b4 100644 --- a/src/main/java/com/yutou/tools/utils/MusicTools.java +++ b/src/main/java/com/yutou/tools/utils/MusicTools.java @@ -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 getPath(String path){ if(musicMap.containsKey(path)){ - return musicMap.get(path); + List 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 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 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 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); diff --git a/src/main/java/com/yutou/tools/utils/Tools.java b/src/main/java/com/yutou/tools/utils/Tools.java index d504a46..74353cd 100644 --- a/src/main/java/com/yutou/tools/utils/Tools.java +++ b/src/main/java/com/yutou/tools/utils/Tools.java @@ -262,11 +262,20 @@ public class Tools { downloadInterface.onError(e); } } + + /** + * 构造给前端的文件 + * @param file 文件路径 + * @return 前端获取的文件 + */ public static ResponseEntity 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()); diff --git a/src/main/resources/mapper/PermissionDao.xml b/src/main/resources/mapper/PermissionDao.xml new file mode 100644 index 0000000..6c0b828 --- /dev/null +++ b/src/main/resources/mapper/PermissionDao.xml @@ -0,0 +1,173 @@ + + + + + + + + + + + + + + + + + and ${criterion.condition} + + + and ${criterion.condition} #{criterion.value} + + + and ${criterion.condition} #{criterion.value} and #{criterion.secondValue} + + + and ${criterion.condition} + + #{listItem} + + + + + + + + + + + + + + + + + + and ${criterion.condition} + + + and ${criterion.condition} #{criterion.value} + + + and ${criterion.condition} #{criterion.value} and #{criterion.secondValue} + + + and ${criterion.condition} + + #{listItem} + + + + + + + + + + + id, title, url + + + + + delete from permission + where id = #{id,jdbcType=INTEGER} + + + delete from permission + + + + + + insert into permission (title, url) + values (#{title,jdbcType=VARCHAR}, #{url,jdbcType=VARCHAR}) + + + insert into permission + + + title, + + + url, + + + + + #{title,jdbcType=VARCHAR}, + + + #{url,jdbcType=VARCHAR}, + + + + + + update permission + + + id = #{record.id,jdbcType=INTEGER}, + + + title = #{record.title,jdbcType=VARCHAR}, + + + url = #{record.url,jdbcType=VARCHAR}, + + + + + + + + update permission + set id = #{record.id,jdbcType=INTEGER}, + title = #{record.title,jdbcType=VARCHAR}, + url = #{record.url,jdbcType=VARCHAR} + + + + + + update permission + + + title = #{title,jdbcType=VARCHAR}, + + + url = #{url,jdbcType=VARCHAR}, + + + where id = #{id,jdbcType=INTEGER} + + + update permission + set title = #{title,jdbcType=VARCHAR}, + url = #{url,jdbcType=VARCHAR} + where id = #{id,jdbcType=INTEGER} + + \ No newline at end of file diff --git a/src/main/resources/mapper/UKeyDao.xml b/src/main/resources/mapper/UKeyDao.xml index 40e20b7..38ac3ec 100644 --- a/src/main/resources/mapper/UKeyDao.xml +++ b/src/main/resources/mapper/UKeyDao.xml @@ -4,6 +4,7 @@ + @@ -64,7 +65,7 @@ - id, `key` + id, `key`, `power` @@ -119,13 +126,6 @@ - update u_key @@ -135,6 +135,9 @@ `key` = #{record.key,jdbcType=VARCHAR}, + + `power` = #{record.power,jdbcType=VARCHAR}, + @@ -143,7 +146,8 @@ update u_key set id = #{record.id,jdbcType=INTEGER}, - `key` = #{record.key,jdbcType=VARCHAR} + `key` = #{record.key,jdbcType=VARCHAR}, + `power` = #{record.power,jdbcType=VARCHAR} @@ -154,12 +158,16 @@ `key` = #{key,jdbcType=VARCHAR}, + + `power` = #{power,jdbcType=VARCHAR}, + where id = #{id,jdbcType=INTEGER} update u_key - set `key` = #{key,jdbcType=VARCHAR} + set `key` = #{key,jdbcType=VARCHAR}, + `power` = #{power,jdbcType=VARCHAR} where id = #{id,jdbcType=INTEGER} \ No newline at end of file diff --git a/web/html/body/nas/music.html b/web/html/body/nas/music.html index 4ba2b58..6583c62 100644 --- a/web/html/body/nas/music.html +++ b/web/html/body/nas/music.html @@ -24,19 +24,12 @@
艺术家:
专辑:
作曲家
+ 下载
-
@@ -46,33 +39,78 @@ - + +