mirror of
https://github.com/Hello-hao/Tbed.git
synced 2024-04-21 12:32:10 +00:00
Compare commits
| Author | SHA1 | Date | |
|---|---|---|---|
|
|
fc53e4c8ac | ||
|
|
86ae47e632 | ||
|
|
241ab625c0 | ||
|
|
19c2b3ce9f | ||
|
|
c5b800ad56 | ||
|
|
c960d2a812 | ||
|
|
7906948ab7 |
@@ -23,17 +23,20 @@
|
||||
|
||||
**存储源支持:**
|
||||
|
||||
开源版:`本地`,`阿里OSS`,`又拍USS`,`七牛KODO`,`腾讯COS`,`网易NOS`,~~`U-File`~~,`FTP`,`AWS S3协议`(`百度云BOS`,`青云Qingstor`,`Ucloud US3`,`Minio`等兼容S3协议)
|
||||
开源版:`本地`,`阿里OSS`,`又拍USS`,`七牛KODO`,`腾讯COS`,`网易NOS`,`FTP`,`AWS S3协议`(`百度云BOS`,`青云Qingstor`,`Ucloud US3`,`Minio`等兼容S3协议)
|
||||
|
||||
[Core版](https://hellohao.cn):开源版的基础上增加`Backblaze(B2)` 并且可同个对象存储商家可开多个存储源(可添加至90+存储源)
|
||||
[Core版](https://hellohao.cn):开源版的基础上增加`Backblaze(B2)` 并且可`同个对象存储商家`可开多个存储源(可添加至90+存储源)
|
||||
|
||||
|
||||
### 更新日志 `20230519`
|
||||
### 更新日志 `20230918`
|
||||
|
||||
- 优化了上传页面的上传逻辑
|
||||
- 添加了自动检测新版本
|
||||
- 新增了图像搜索功能,可通过名称/链接进行模糊查询
|
||||
- 修复多个页面问题
|
||||
- 修复首页批量复制窗点击复制报错
|
||||
- 调整菜单个人相册名字为相册空间
|
||||
- 调整首页UI宽度
|
||||
- 优化代码未激活账号登录时提示重新激活
|
||||
- docker-compose方式部署添加数据库用户名配置项
|
||||
- 修改拦截器写入响应数据时逻辑
|
||||
- 优化图像链接转存功能
|
||||
|
||||
|
||||
[^_^]: 程序宣传视频:[自制宣传视频](https://www.bilibili.com/video/BV11r4y1y7mH/)
|
||||
@@ -169,11 +172,22 @@
|
||||
[^_^]: 
|
||||
[^_^]: 
|
||||
|
||||
### 客户端(win64/mac)
|
||||
### 桌面客户端(win/mac)
|
||||
> 获取地址:[官网获取](https://www.hellohao.cn/app)
|
||||
|
||||
> 目前已经正式上线
|
||||
> `开源版`/`Core版` 都可以使用
|
||||
> 
|
||||
|
||||
### 微信小程序
|
||||
|
||||
> 仅适用于对接`Core付费版`,开源版暂不可对接使用。
|
||||
> 获取地址:[官网获取](https://www.hellohao.cn/pay)
|
||||
|
||||
|
||||

|
||||
|
||||
[//]: # ()
|
||||
|
||||
|
||||
### 运行环境
|
||||
|
||||
@@ -199,16 +213,6 @@
|
||||
- JWT认证
|
||||
- Shiro
|
||||
|
||||
|
||||
### 微信小程序
|
||||
|
||||
> 目前已有测试版,更多功能开发中,开发进度的快慢要根据作者的工作压力、心情状况等自身情况进行评估。
|
||||
> 暂时无法给出具体发布小程序的时间。大家期待吧。
|
||||
|
||||

|
||||
|
||||
[^_^]: 
|
||||
|
||||
### 声明
|
||||
|
||||
本项目遵循[GNU Affero General Public License v3.0](https://choosealicense.com/licenses/agpl-3.0/#)开源协议,使用前请悉知。
|
||||
|
||||
@@ -10,10 +10,12 @@ import org.apache.shiro.SecurityUtils;
|
||||
import org.apache.shiro.authc.UsernamePasswordToken;
|
||||
import org.apache.shiro.subject.Subject;
|
||||
import org.apache.shiro.web.filter.authc.BasicHttpAuthenticationFilter;
|
||||
|
||||
import javax.servlet.ServletRequest;
|
||||
import javax.servlet.ServletResponse;
|
||||
import javax.servlet.http.HttpServletRequest;
|
||||
import javax.servlet.http.HttpServletResponse;
|
||||
import java.io.PrintWriter;
|
||||
|
||||
/**
|
||||
* @author Hellohao
|
||||
@@ -139,11 +141,16 @@ public class SubjectFilter extends BasicHttpAuthenticationFilter {
|
||||
info = "用户未找到";
|
||||
}
|
||||
System.err.println("拦截器False-"+info);
|
||||
response.setContentType("application/json;charset=UTF-8");
|
||||
final JSONObject jsonObject = new JSONObject();
|
||||
HttpServletResponse httpServletResponse = (HttpServletResponse) response;
|
||||
httpServletResponse.setStatus(HttpServletResponse.SC_OK);
|
||||
httpServletResponse.setCharacterEncoding("UTF-8");
|
||||
httpServletResponse.setContentType("application/json");
|
||||
PrintWriter writer = httpServletResponse.getWriter();
|
||||
JSONObject jsonObject = new JSONObject();
|
||||
jsonObject.put("code",this.CODE);
|
||||
jsonObject.put("info",info);
|
||||
response.getWriter().write(jsonObject.toJSONString());
|
||||
writer.write(jsonObject.toJSONString());
|
||||
writer.flush();
|
||||
} catch (Exception e) {
|
||||
System.out.println("返回token验证失败403请求,报异常了");
|
||||
}
|
||||
|
||||
@@ -31,6 +31,7 @@ public class ShiroConfig {
|
||||
filterMap.put("/verifyCode","anon");
|
||||
filterMap.put("/verifyCodeForRegister","anon");
|
||||
filterMap.put("/verifyCodeForRetrieve","anon");
|
||||
filterMap.put("/verifyCodeFortowSendEmail","anon");
|
||||
filterMap.put("/api/**","anon");
|
||||
filterMap.put("/user/**","anon");
|
||||
filterMap.put("/ota/**","anon");
|
||||
|
||||
@@ -2,6 +2,7 @@ package cn.hellohao.auth.shiro;
|
||||
|
||||
import cn.hellohao.pojo.User;
|
||||
import cn.hellohao.service.UserService;
|
||||
import cn.hellohao.utils.SetText;
|
||||
import org.apache.shiro.SecurityUtils;
|
||||
import org.apache.shiro.authc.*;
|
||||
import org.apache.shiro.authz.AuthorizationInfo;
|
||||
@@ -46,7 +47,11 @@ public class UserRealm extends AuthorizingRealm {
|
||||
UsernamePasswordToken userToken = null;
|
||||
userToken = (UsernamePasswordToken)tokenOBJ;
|
||||
User user = new User();
|
||||
user.setEmail(userToken.getUsername());
|
||||
if(SetText.checkEmail(userToken.getUsername())){
|
||||
user.setEmail(userToken.getUsername());
|
||||
}else{
|
||||
user.setUsername(userToken.getUsername());
|
||||
}
|
||||
User u = userService.getUsers(user);
|
||||
if(u==null){
|
||||
return null;
|
||||
|
||||
@@ -313,6 +313,7 @@ public class AdminController {
|
||||
String starttime = jsonObj.getString("starttime");
|
||||
String stoptime = jsonObj.getString("stoptime");
|
||||
String selectUserType = jsonObj.getString("selectUserType"); // me/all
|
||||
String order = jsonObj.getString("order");
|
||||
String username = jsonObj.getString("username");
|
||||
String searchname = jsonObj.getString("searchname");
|
||||
Integer selecttype = jsonObj.getInteger("selecttype");
|
||||
@@ -359,6 +360,7 @@ public class AdminController {
|
||||
if(!StringUtils.isBlank(searchname)){
|
||||
img.setSearchname(searchname);
|
||||
}
|
||||
img.setOrder(StringUtils.isBlank(order)?"desc":order);
|
||||
List<Images> images = imgService.selectimg(img);
|
||||
PageInfo<Images> rolePageInfo = new PageInfo<>(images);
|
||||
PageResultBean<Images> pageResultBean =
|
||||
@@ -407,9 +409,15 @@ public class AdminController {
|
||||
return msg;
|
||||
}
|
||||
String regex = "^\\w+$";
|
||||
if (username.length() > 20 || !username.matches(regex)) {
|
||||
if (username.length() > 30) {
|
||||
msg.setCode("110403");
|
||||
msg.setInfo("用户名不得超过20位字符");
|
||||
msg.setInfo("用户名不得超过30位字符");
|
||||
return msg;
|
||||
}
|
||||
if(!username.matches (regex)){
|
||||
//用户名格式不正确
|
||||
msg.setCode("110403");
|
||||
msg.setInfo("用户名不得含有特殊字符");
|
||||
return msg;
|
||||
}
|
||||
if (subject.hasRole("admin")) {
|
||||
|
||||
@@ -47,7 +47,7 @@ public class IndexController {
|
||||
@RequestMapping(value = "/")
|
||||
public String Welcome(Model model, HttpServletRequest httpServletRequest) {
|
||||
model.addAttribute("name", "服务端程序(开源版)");
|
||||
model.addAttribute("version", "20230320");
|
||||
model.addAttribute("version", "20230918");
|
||||
model.addAttribute("ip", GetIPS.getIpAddr(httpServletRequest));
|
||||
model.addAttribute("links", "https://github.com/Hello-hao/tbed");
|
||||
return "welcome";
|
||||
@@ -146,6 +146,7 @@ public class IndexController {
|
||||
JSONObject jsonObj = JSONObject.parseObject(data);
|
||||
Integer setday = jsonObj.getInteger("day");
|
||||
String imgUrl = jsonObj.getString("imgUrl");
|
||||
String referer = jsonObj.getString("referer");
|
||||
String[] URLArr = imgUrl.split("\n");
|
||||
|
||||
Subject subject = SecurityUtils.getSubject();
|
||||
@@ -165,7 +166,10 @@ public class IndexController {
|
||||
for (int i = 0; i < URLArr.length; i++) {
|
||||
int temp = i + 1;
|
||||
if (syscounts >= temp) {
|
||||
Msg msg = uploadServicel.uploadForLoc(request, null,"URL转存图像", setday, URLArr[i],null);
|
||||
JSONObject imgJson = new JSONObject();
|
||||
imgJson.put("imgUrl",URLArr[i]);
|
||||
imgJson.put("referer",referer);
|
||||
Msg msg = uploadServicel.uploadForLoc(request, null,"URL转存图像", setday, imgJson,null);
|
||||
if (!msg.getCode().equals("200")) {
|
||||
errcounts++;
|
||||
} else {
|
||||
@@ -316,6 +320,29 @@ public class IndexController {
|
||||
}
|
||||
}
|
||||
|
||||
@PostMapping(value = {"/verifyCodeFortowSendEmail","/wechat/verifyCodeFortowSendEmail"})
|
||||
@ResponseBody
|
||||
public Msg verifyCodeFortowSendEmail() {
|
||||
Msg msg = new Msg();
|
||||
try {
|
||||
ShearCaptcha captcha = CaptchaUtil.createShearCaptcha(90, 35, 2, 2);
|
||||
// 自定义验证码内容为四则运算方式
|
||||
captcha.setGenerator(new MathGenerator(1));
|
||||
String code = getVerifyCodeOperator(captcha.getCode());
|
||||
String uid = UUID.randomUUID().toString().replace("-", "").toLowerCase();
|
||||
iRedisService.setValue("verifyCodeFortowSendEmail_"+uid,code);
|
||||
JSONObject jsonObject = new JSONObject();
|
||||
jsonObject.put("codeKey",uid);
|
||||
jsonObject.put("codeImg",captcha.getImageBase64());
|
||||
msg.setData(jsonObject);
|
||||
return msg;
|
||||
} catch (Exception e) {
|
||||
e.printStackTrace();
|
||||
msg.setCode("500");
|
||||
return msg;
|
||||
}
|
||||
}
|
||||
|
||||
public static String getVerifyCodeOperator(String str) {
|
||||
int a = Integer.valueOf(str.substring(0, 1));
|
||||
String yxf = str.substring(1, 2);
|
||||
|
||||
@@ -16,6 +16,8 @@ import org.apache.shiro.authc.IncorrectCredentialsException;
|
||||
import org.apache.shiro.authc.UnknownAccountException;
|
||||
import org.apache.shiro.authc.UsernamePasswordToken;
|
||||
import org.apache.shiro.subject.Subject;
|
||||
import org.slf4j.Logger;
|
||||
import org.slf4j.LoggerFactory;
|
||||
import org.springframework.beans.factory.annotation.Autowired;
|
||||
import org.springframework.stereotype.Controller;
|
||||
import org.springframework.ui.Model;
|
||||
@@ -44,6 +46,7 @@ public class UserController {
|
||||
private SysConfigService sysConfigService;
|
||||
@Autowired
|
||||
IRedisService iRedisService;
|
||||
private Logger logger = LoggerFactory.getLogger(UserController.class);
|
||||
|
||||
@PostMapping("/register")
|
||||
@ResponseBody
|
||||
@@ -62,10 +65,16 @@ public class UserController {
|
||||
return msg;
|
||||
}
|
||||
String regex = "^\\w+$";
|
||||
if(username.length()>20 || !username.matches (regex)){
|
||||
if(username.length()>30){
|
||||
//用户名格式不正确
|
||||
msg.setCode("110403");
|
||||
msg.setInfo("用户名不得超过20位字符");
|
||||
msg.setInfo("用户名不得超过30位字符");
|
||||
return msg;
|
||||
}
|
||||
if(!username.matches (regex)){
|
||||
//用户名格式不正确
|
||||
msg.setCode("110403");
|
||||
msg.setInfo("用户名不得含有特殊字符");
|
||||
return msg;
|
||||
}
|
||||
if(null==redis_verifyCodeForRegister){
|
||||
@@ -137,6 +146,57 @@ public class UserController {
|
||||
return msg;
|
||||
}
|
||||
|
||||
@PostMapping(value = {"/validateEmail","/wechat/validateEmail"})
|
||||
@ResponseBody
|
||||
public Msg validateEmail(HttpServletRequest httpServletRequest,@RequestParam(value = "data", defaultValue = "") String data) {
|
||||
Msg msg = new Msg();
|
||||
try {
|
||||
JSONObject jsonObj = JSONObject.parseObject(data);
|
||||
String email = jsonObj.getString("email");
|
||||
String towSendEmailCode = jsonObj.getString("towSendEmailCode");
|
||||
Object verifyCodeFortowSendEmail =iRedisService.getValue("verifyCodeFortowSendEmail_"+httpServletRequest.getHeader("verifyCodeFortowSendEmail"));
|
||||
User u = new User();
|
||||
u.setEmail(email);
|
||||
User user = userService.getUsers(u);
|
||||
if(user.getIsok()!=0){
|
||||
msg.setInfo("不知细叶谁裁出,二月春风似剪刀");
|
||||
return msg;
|
||||
}
|
||||
if(null==verifyCodeFortowSendEmail){
|
||||
msg.setCode("4035");
|
||||
msg.setInfo("验证码已失效,请重新弄获取。");
|
||||
return msg;
|
||||
}else if(null==towSendEmailCode){
|
||||
msg.setCode("4036");
|
||||
msg.setInfo("验证码不能为空。");
|
||||
return msg;
|
||||
}
|
||||
if((verifyCodeFortowSendEmail.toString().toLowerCase()).compareTo((towSendEmailCode.toLowerCase()))==0){
|
||||
//注册完发激活链接
|
||||
final Confdata dataJson = confdataService.selectConfdata("config");
|
||||
JSONObject confdata = JSONObject.parseObject(dataJson.getJsondata());
|
||||
EmailConfig emailConfig = emailConfigService.getemail();
|
||||
Thread thread = new Thread() {
|
||||
public void run() {
|
||||
Integer a = NewSendEmail.sendEmail(emailConfig,user.getUsername(), user.getUid(), user.getEmail(),confdata);
|
||||
}
|
||||
};
|
||||
thread.start();
|
||||
msg.setInfo("邮件已发送,请注意查收邮箱尽快激活账户(如果没收到,请检查垃圾邮件)");
|
||||
}else{
|
||||
msg.setCode("110408");
|
||||
msg.setInfo("验证码不正确");
|
||||
return msg;
|
||||
}
|
||||
|
||||
}catch (Exception e){
|
||||
logger.error("报错位置:/validateEmail",e);
|
||||
msg.setCode("500");
|
||||
msg.setInfo("邮件发送失败");
|
||||
}
|
||||
return msg;
|
||||
}
|
||||
|
||||
@PostMapping("/login")//new
|
||||
@ResponseBody
|
||||
public Msg login(HttpServletRequest httpServletRequest,@RequestParam(value = "data", defaultValue = "") String data) {
|
||||
@@ -178,7 +238,8 @@ public class UserController {
|
||||
User user = (User) SecurityUtils.getSubject().getPrincipal();
|
||||
if(user.getIsok()==0){
|
||||
msg.setInfo("你的账号暂未激活");
|
||||
msg.setCode("110403");
|
||||
msg.setData(user.getEmail());
|
||||
msg.setCode("110402");
|
||||
return msg;
|
||||
}
|
||||
if(user.getIsok()<0){
|
||||
@@ -198,15 +259,15 @@ public class UserController {
|
||||
} catch (UnknownAccountException e) {
|
||||
//此异常说明用户名不存在
|
||||
msg.setCode("4000");
|
||||
msg.setInfo("登录邮箱不存在");
|
||||
System.err.println("邮箱不存在");
|
||||
e.printStackTrace();
|
||||
msg.setInfo("登录账号不存在");
|
||||
System.err.println("邮箱/用户名不存在");
|
||||
// e.printStackTrace();
|
||||
return msg;
|
||||
}catch (IncorrectCredentialsException e) {
|
||||
msg.setCode("4000");
|
||||
msg.setInfo("登录密码错误");
|
||||
System.err.println("密码不存在");
|
||||
e.printStackTrace();
|
||||
// e.printStackTrace();
|
||||
return msg;
|
||||
}catch (Exception e) {
|
||||
msg.setCode("5000");
|
||||
|
||||
@@ -1,8 +1,9 @@
|
||||
package cn.hellohao.pojo;
|
||||
|
||||
public class Images {
|
||||
// 默认的时间字符串格式
|
||||
import lombok.Data;
|
||||
|
||||
@Data
|
||||
public class Images {
|
||||
//id, imgname, imgurl, userid
|
||||
private Long id;
|
||||
private String imgname;
|
||||
@@ -38,326 +39,7 @@ public class Images {
|
||||
private String idname;
|
||||
private Integer isRepeat;//如果没有开启查重的时候他是0,开启为1
|
||||
private String searchname;
|
||||
|
||||
public Images() {
|
||||
super();
|
||||
}
|
||||
|
||||
public Images(String imgurl, String sizes, String abnormal, String updatetime, String username, String md5key, String imguid) {
|
||||
this.imgurl = imgurl;
|
||||
this.sizes = sizes;
|
||||
this.abnormal = abnormal;
|
||||
this.updatetime = updatetime;
|
||||
this.username = username;
|
||||
this.md5key = md5key;
|
||||
this.imguid = imguid;
|
||||
}
|
||||
|
||||
public Images(Long id, String imgname, String imgurl, Integer userid, String sizes, String abnormal, Integer source,
|
||||
Integer imgtype, String updatetime, String username, Integer storageType, String starttime, String stoptime,
|
||||
String explains, String md5key, String notes, String useridlist, String imguid, String albumtitle,
|
||||
String password, Integer selecttype,Long countNum,Integer monthNum,String yyyy,
|
||||
String format,String about,Integer great,String[] classifuidlist,String classificationuid,String violation,
|
||||
String idname,Integer isRepeat,String searchname) {
|
||||
this.id = id;
|
||||
this.imgname = imgname;
|
||||
this.imgurl = imgurl;
|
||||
this.userid = userid;
|
||||
this.sizes = sizes;
|
||||
this.abnormal = abnormal;
|
||||
this.source = source;
|
||||
this.imgtype = imgtype;
|
||||
this.updatetime = updatetime;
|
||||
this.username = username;
|
||||
this.storageType = storageType;
|
||||
this.starttime = starttime;
|
||||
this.stoptime = stoptime;
|
||||
this.explains = explains;
|
||||
this.md5key = md5key;
|
||||
this.notes = notes;
|
||||
this.useridlist = useridlist;
|
||||
this.imguid = imguid;
|
||||
this.albumtitle = albumtitle;
|
||||
this.password = password;
|
||||
this.selecttype = selecttype;
|
||||
this.countNum = countNum;
|
||||
this.monthNum = monthNum;
|
||||
this.yyyy = yyyy;
|
||||
this.format = format;
|
||||
this.about = about;
|
||||
this.great = great;
|
||||
this.classifuidlist = classifuidlist;
|
||||
this.classificationuid = classificationuid;
|
||||
this.violation = violation;
|
||||
this.idname = idname;
|
||||
this.isRepeat = isRepeat;
|
||||
this.searchname = searchname;
|
||||
}
|
||||
|
||||
public Long getId() {
|
||||
return id;
|
||||
}
|
||||
|
||||
public void setId(Long id) {
|
||||
this.id = id;
|
||||
}
|
||||
|
||||
public String getImgname() {
|
||||
return imgname;
|
||||
}
|
||||
|
||||
public void setImgname(String imgname) {
|
||||
this.imgname = imgname;
|
||||
}
|
||||
|
||||
public String getImgurl() {
|
||||
return imgurl;
|
||||
}
|
||||
|
||||
public void setImgurl(String imgurl) {
|
||||
this.imgurl = imgurl;
|
||||
}
|
||||
|
||||
public Integer getUserid() {
|
||||
return userid;
|
||||
}
|
||||
|
||||
public void setUserid(Integer userid) {
|
||||
this.userid = userid;
|
||||
}
|
||||
|
||||
public String getSizes() {
|
||||
return sizes;
|
||||
}
|
||||
|
||||
public void setSizes(String sizes) {
|
||||
this.sizes = sizes;
|
||||
}
|
||||
|
||||
public String getAbnormal() {
|
||||
return abnormal;
|
||||
}
|
||||
|
||||
public void setAbnormal(String abnormal) {
|
||||
this.abnormal = abnormal;
|
||||
}
|
||||
|
||||
public Integer getSource() {
|
||||
return source;
|
||||
}
|
||||
|
||||
public void setSource(Integer source) {
|
||||
this.source = source;
|
||||
}
|
||||
|
||||
public Integer getImgtype() {
|
||||
return imgtype;
|
||||
}
|
||||
|
||||
public void setImgtype(Integer imgtype) {
|
||||
this.imgtype = imgtype;
|
||||
}
|
||||
|
||||
public String getUpdatetime() {
|
||||
return updatetime;
|
||||
}
|
||||
|
||||
public void setUpdatetime(String updatetime) {
|
||||
this.updatetime = updatetime;
|
||||
}
|
||||
|
||||
public String getUsername() {
|
||||
return username;
|
||||
}
|
||||
|
||||
public void setUsername(String username) {
|
||||
this.username = username;
|
||||
}
|
||||
|
||||
public Integer getStorageType() {
|
||||
return storageType;
|
||||
}
|
||||
|
||||
public void setStorageType(Integer storageType) {
|
||||
this.storageType = storageType;
|
||||
}
|
||||
|
||||
public String getStarttime() {
|
||||
return starttime;
|
||||
}
|
||||
|
||||
public void setStarttime(String starttime) {
|
||||
this.starttime = starttime;
|
||||
}
|
||||
|
||||
public String getStoptime() {
|
||||
return stoptime;
|
||||
}
|
||||
|
||||
public void setStoptime(String stoptime) {
|
||||
this.stoptime = stoptime;
|
||||
}
|
||||
|
||||
public String getExplains() {
|
||||
return explains;
|
||||
}
|
||||
|
||||
public void setExplains(String explains) {
|
||||
this.explains = explains;
|
||||
}
|
||||
|
||||
public String getMd5key() {
|
||||
return md5key;
|
||||
}
|
||||
|
||||
public void setMd5key(String md5key) {
|
||||
this.md5key = md5key;
|
||||
}
|
||||
|
||||
public String getNotes() {
|
||||
return notes;
|
||||
}
|
||||
|
||||
public void setNotes(String notes) {
|
||||
this.notes = notes;
|
||||
}
|
||||
|
||||
public String getUseridlist() {
|
||||
return useridlist;
|
||||
}
|
||||
|
||||
public void setUseridlist(String useridlist) {
|
||||
this.useridlist = useridlist;
|
||||
}
|
||||
|
||||
public String getImguid() {
|
||||
return imguid;
|
||||
}
|
||||
|
||||
public void setImguid(String imguid) {
|
||||
this.imguid = imguid;
|
||||
}
|
||||
|
||||
|
||||
public String getAlbumtitle() {
|
||||
return albumtitle;
|
||||
}
|
||||
|
||||
public void setAlbumtitle(String albumtitle) {
|
||||
this.albumtitle = albumtitle;
|
||||
}
|
||||
|
||||
public String getPassword() {
|
||||
return password;
|
||||
}
|
||||
|
||||
public void setPassword(String password) {
|
||||
this.password = password;
|
||||
}
|
||||
|
||||
public Integer getSelecttype() {
|
||||
return selecttype;
|
||||
}
|
||||
|
||||
public void setSelecttype(Integer selecttype) {
|
||||
this.selecttype = selecttype;
|
||||
}
|
||||
|
||||
public Long getCountNum() {
|
||||
return countNum;
|
||||
}
|
||||
|
||||
public void setCountNum(Long countNum) {
|
||||
this.countNum = countNum;
|
||||
}
|
||||
|
||||
public Integer getMonthNum() {
|
||||
return monthNum;
|
||||
}
|
||||
|
||||
public void setMonthNum(Integer monthNum) {
|
||||
this.monthNum = monthNum;
|
||||
}
|
||||
|
||||
public String getYyyy() {
|
||||
return yyyy;
|
||||
}
|
||||
|
||||
public void setYyyy(String yyyy) {
|
||||
this.yyyy = yyyy;
|
||||
}
|
||||
|
||||
public String getFormat() {
|
||||
return format;
|
||||
}
|
||||
|
||||
public void setFormat(String format) {
|
||||
this.format = format;
|
||||
}
|
||||
|
||||
public String getAbout() {
|
||||
return about;
|
||||
}
|
||||
|
||||
public void setAbout(String about) {
|
||||
this.about = about;
|
||||
}
|
||||
|
||||
public Integer getGreat() {
|
||||
return great;
|
||||
}
|
||||
|
||||
public void setGreat(Integer great) {
|
||||
this.great = great;
|
||||
}
|
||||
|
||||
public String[] getClassifuidlist() {
|
||||
return classifuidlist;
|
||||
}
|
||||
|
||||
public void setClassifuidlist(String[] classifuidlist ) {
|
||||
this.classifuidlist = classifuidlist;
|
||||
}
|
||||
|
||||
public String getClassificationuid() {
|
||||
return classificationuid;
|
||||
}
|
||||
|
||||
public void setClassificationuid(String classificationuid) {
|
||||
this.classificationuid = classificationuid;
|
||||
}
|
||||
|
||||
public String getViolation() {
|
||||
return violation;
|
||||
}
|
||||
|
||||
public void setViolation(String violation) {
|
||||
this.violation = violation;
|
||||
}
|
||||
|
||||
public String getIdname() {
|
||||
return idname;
|
||||
}
|
||||
|
||||
public void setIdname(String idname) {
|
||||
this.idname = idname;
|
||||
}
|
||||
|
||||
public Integer getIsRepeat() {
|
||||
return isRepeat;
|
||||
}
|
||||
|
||||
public void setIsRepeat(Integer isRepeat) {
|
||||
this.isRepeat = isRepeat;
|
||||
}
|
||||
|
||||
public String getSearchname() {
|
||||
return searchname;
|
||||
}
|
||||
|
||||
public void setSearchname(String searchname) {
|
||||
this.searchname = searchname;
|
||||
}
|
||||
private String order;
|
||||
}
|
||||
|
||||
|
||||
|
||||
@@ -53,7 +53,7 @@ public class UploadServicel {
|
||||
File file,
|
||||
String imgName,
|
||||
Integer setday,
|
||||
String imgUrl,
|
||||
JSONObject imgJson,
|
||||
String md5key) {
|
||||
Msg msg = new Msg();
|
||||
try {
|
||||
@@ -69,8 +69,8 @@ public class UploadServicel {
|
||||
u = userMapper.getUsers(u);
|
||||
}
|
||||
Integer sourceKeyId = 0;
|
||||
if (imgUrl != null) {
|
||||
Msg imgData = uploadForURL(request, imgUrl);
|
||||
if (imgJson != null) {
|
||||
Msg imgData = uploadForURL(request, imgJson.getString("imgUrl"),imgJson.getString("referer"));
|
||||
if (imgData.getCode().equals("200")) {
|
||||
file = new File((String) imgData.getData());
|
||||
} else {
|
||||
@@ -254,42 +254,49 @@ public class UploadServicel {
|
||||
}
|
||||
|
||||
|
||||
public static Msg uploadForURL(HttpServletRequest request, String imgurl) {
|
||||
Msg msg = new Msg();
|
||||
if (true) {
|
||||
Long imgsize = 0L;
|
||||
try {
|
||||
if (imgsize == 0) {
|
||||
String ShortUID = SetText.getShortUuid();
|
||||
String savePath =
|
||||
request.getSession().getServletContext().getRealPath("/")
|
||||
+ File.separator
|
||||
+ "hellohaotmp"
|
||||
+ File.separator;
|
||||
Map<String, Object> bl = ImgUrlUtil.downLoadFromUrl(imgurl, ShortUID, savePath);
|
||||
if ((Boolean) bl.get("res") == true) {
|
||||
msg.setCode("200");
|
||||
msg.setData(bl.get("imgPath"));
|
||||
return msg;
|
||||
} else {
|
||||
if (bl.get("StatusCode").equals("110403")) {
|
||||
msg.setInfo("该链接非图像文件,无法上传");
|
||||
} else {
|
||||
msg.setInfo("该链接暂时无法上传");
|
||||
}
|
||||
msg.setCode("500");
|
||||
}
|
||||
public static Msg uploadForURL(HttpServletRequest request, String imgurls,String referer) {
|
||||
final Msg msg = new Msg();
|
||||
String url = imgurls;
|
||||
// 先判断是不是有效链接 并且自动判断协议头http(s)://
|
||||
GetProtocol getProtocol = new GetProtocol();
|
||||
String protocol = getProtocol.getProtocol(url,referer);
|
||||
if (protocol == null) {
|
||||
msg.setInfo("服务器解析该链接失败");
|
||||
msg.setCode("500");
|
||||
return msg;
|
||||
} else {
|
||||
url = protocol;
|
||||
}
|
||||
Long imgsize = 0L;
|
||||
try {
|
||||
if (imgsize == 0) {
|
||||
String ShortUID = SetText.getShortUuid();
|
||||
String savePath =
|
||||
request.getSession().getServletContext().getRealPath("/")
|
||||
+ File.separator
|
||||
+ "hellohaotmp"
|
||||
+ File.separator;
|
||||
Map<String, Object> bl = ImgUrlUtil.downLoadFromUrl(url,referer, ShortUID, savePath);
|
||||
if ((Boolean) bl.get("res") == true) {
|
||||
// File file = new File();
|
||||
msg.setCode("200");
|
||||
msg.setData(bl.get("imgPath")); // savePath + File.separator + ShortUID
|
||||
return msg;
|
||||
} else {
|
||||
if (bl.get("StatusCode").equals("110403")) {
|
||||
msg.setInfo("该链接非图像文件,无法上传");
|
||||
} else {
|
||||
msg.setInfo("该链接暂时无法上传");
|
||||
}
|
||||
msg.setCode("500");
|
||||
msg.setInfo("获取资源失败");
|
||||
}
|
||||
} catch (Exception e) {
|
||||
} else {
|
||||
msg.setCode("500");
|
||||
msg.setInfo("获取资源失败");
|
||||
}
|
||||
} else {
|
||||
} catch (Exception e) {
|
||||
msg.setCode("500");
|
||||
msg.setInfo("该链接无效");
|
||||
msg.setInfo("获取资源失败");
|
||||
}
|
||||
|
||||
return msg;
|
||||
|
||||
@@ -0,0 +1,89 @@
|
||||
package cn.hellohao.utils;
|
||||
|
||||
import java.net.HttpURLConnection;
|
||||
import java.net.URL;
|
||||
import org.apache.commons.lang3.StringUtils;
|
||||
|
||||
public class GetProtocol {
|
||||
private final static String HTTP= "http://";
|
||||
private final static String HTTPS = "https://";
|
||||
private String newurl;
|
||||
|
||||
//判断协议 能连接上则协议正确
|
||||
public String getProtocol(String url,String referer) {
|
||||
newurl = clearUrl(url);
|
||||
url = HTTP + newurl;
|
||||
if (exists(url,referer)) {
|
||||
return url;
|
||||
} else {
|
||||
url = HTTPS + newurl;
|
||||
if (exists(url,referer)) {
|
||||
return url;
|
||||
} else {
|
||||
return null;
|
||||
}
|
||||
}
|
||||
|
||||
}
|
||||
//清除URL里多余的符号
|
||||
private String clearUrl(String url) {
|
||||
if (url.contains(HTTP)) {
|
||||
url = url.substring(url.lastIndexOf(HTTP) + HTTP.length());
|
||||
for (int i = 0; i < url.length(); i++) {
|
||||
if (url.charAt(i) == '/' || url.charAt(i) == '.'
|
||||
|| url.charAt(i) == '\\') {
|
||||
} else {
|
||||
url = url.substring(i);
|
||||
return url;
|
||||
}
|
||||
}
|
||||
} else if (url.contains(HTTPS)) {
|
||||
url = url.substring(url.lastIndexOf(HTTPS) + HTTPS.length());
|
||||
for (int i = 0; i < url.length(); i++) {
|
||||
if (url.charAt(i) == '/' || url.charAt(i) == '.'
|
||||
|| url.charAt(i) == '\\') {
|
||||
} else {
|
||||
url = url.substring(i);
|
||||
return url;
|
||||
}
|
||||
}
|
||||
}else{
|
||||
for (int i = 0; i < url.length(); i++) {
|
||||
if (url.charAt(i) == '/' || url.charAt(i) == '.'
|
||||
|| url.charAt(i) == '\\') {
|
||||
} else {
|
||||
url = url.substring(i);
|
||||
return url;
|
||||
}
|
||||
}
|
||||
}
|
||||
return url;
|
||||
}
|
||||
//是否能连接上
|
||||
private boolean exists(String url,String referer) {
|
||||
try {
|
||||
HttpURLConnection con = (HttpURLConnection) new URL(url).openConnection();
|
||||
con.setConnectTimeout(3000);
|
||||
con.setRequestProperty("User-Agent", "Mozilla/5.0 (Windows NT 10.0; Win64; x64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/112.0.0.0 Safari/537.36");
|
||||
con.setRequestProperty("referer", StringUtils.isBlank(referer)?"no-referrer":referer);
|
||||
System.out.println(con.getResponseCode() );
|
||||
return (con.getResponseCode() == 200);
|
||||
} catch (Exception e) {
|
||||
return false;
|
||||
}
|
||||
}
|
||||
|
||||
public static void main(String[] args){
|
||||
|
||||
try {
|
||||
String url = "https://img-blog.csdnimg.cn/cbf3201a3cfe4fc38a7cef006487158c.png";
|
||||
URL obj = new URL(url);
|
||||
HttpURLConnection con = (HttpURLConnection) obj.openConnection();
|
||||
String referer = con.getRequestProperty("Referer");
|
||||
System.out.println("Referer: " + referer);
|
||||
} catch (Exception e) {
|
||||
e.printStackTrace();
|
||||
}
|
||||
}
|
||||
|
||||
}
|
||||
@@ -2,6 +2,7 @@ package cn.hellohao.utils;
|
||||
|
||||
import cn.hellohao.TbedApplication;
|
||||
import cn.hellohao.pojo.Msg;
|
||||
import org.apache.commons.lang3.StringUtils;
|
||||
|
||||
import java.io.*;
|
||||
import java.net.HttpURLConnection;
|
||||
@@ -83,14 +84,7 @@ public class ImgUrlUtil {
|
||||
}
|
||||
|
||||
|
||||
/**
|
||||
* 从网络Url中下载文件
|
||||
* @param urlStr
|
||||
* @param fileName
|
||||
* @param savePath
|
||||
* @throws IOException
|
||||
*/
|
||||
public static Map<String ,Object> downLoadFromUrl(String urlStr,String fileName,String savePath){
|
||||
public static Map<String ,Object> downLoadFromUrl(String urlStr,String referer,String fileName,String savePath){
|
||||
|
||||
Map<String ,Object> resmap = new HashMap<>();
|
||||
Map<String ,String> map = checkURLStatusCode(urlStr);
|
||||
@@ -102,11 +96,11 @@ public class ImgUrlUtil {
|
||||
try {
|
||||
URL url = new URL(urlStr);
|
||||
HttpURLConnection conn = (HttpURLConnection)url.openConnection();
|
||||
conn.setRequestProperty("referer", StringUtils.isBlank(referer) ? "no-referrer" : referer);
|
||||
//设置超时间为3秒
|
||||
conn.setConnectTimeout(5*1000);
|
||||
//防止屏蔽程序抓取而返回403错误 Referer
|
||||
conn.setRequestProperty("User-Agent", "Mozilla/4.0 (compatible; MSIE 5.0; Windows NT; DigExt)");
|
||||
|
||||
//防止屏蔽程序抓取而返回403错误
|
||||
conn.setRequestProperty("User-Agent", "Mozilla/5.0 (Windows NT 10.0; Win64; x64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/112.0.0.0 Safari/537.36");
|
||||
//得到输入流
|
||||
InputStream inputStream = conn.getInputStream();
|
||||
//获取自己数组
|
||||
@@ -125,7 +119,6 @@ public class ImgUrlUtil {
|
||||
inputStream.close();
|
||||
}
|
||||
//下载并且保存成功后 判断格式 如果不是图像格式 就删除
|
||||
//
|
||||
if(new File(saveDir+File.separator+fileName).exists()){
|
||||
Msg msg = TypeDict.FileMiME(file);
|
||||
if(msg.getCode().equals("200")){
|
||||
@@ -144,8 +137,6 @@ public class ImgUrlUtil {
|
||||
resmap.put("res",false);
|
||||
resmap.put("StatusCode","500");
|
||||
}
|
||||
|
||||
|
||||
return resmap;
|
||||
}catch (Exception e){
|
||||
e.printStackTrace();
|
||||
@@ -155,7 +146,6 @@ public class ImgUrlUtil {
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
/**
|
||||
* 从输入流中获取字节数组
|
||||
* @param inputStream
|
||||
|
||||
@@ -57,6 +57,7 @@ public class SetText {
|
||||
boolean flag = false;
|
||||
try {
|
||||
String check = "^\\w+@[a-zA-Z0-9]{2,10}(?:\\.[a-z]{2,4}){1,3}$";
|
||||
// String regex = "\\w+([-+.']\\w+)*@\\w+([-.]\\w+)*\\.\\w+([-.]\\w+)*"; //这个也可以用
|
||||
Pattern regex = Pattern.compile(check);
|
||||
Matcher matcher = regex.matcher(email);
|
||||
flag = matcher.matches();
|
||||
@@ -66,6 +67,5 @@ public class SetText {
|
||||
return flag;
|
||||
}
|
||||
|
||||
|
||||
}
|
||||
|
||||
|
||||
@@ -4,11 +4,11 @@ server.port=10088
|
||||
#前端域名需要带协议头http(s)://
|
||||
CROS_ALLOWED_ORIGINS=${HELLOHAO_WEB_HOST:http://127.0.0.1:8080}
|
||||
#数据库账号
|
||||
spring.datasource.username=root
|
||||
spring.datasource.username=${MYSQL_NAME:root}
|
||||
#数据库密码test
|
||||
spring.datasource.password=${MYSQL_PASS:root}
|
||||
#数据库链接地址
|
||||
spring.datasource.url=${MYSQL_URL:jdbc:mysql://127.0.0.1:3306/tbed?useUnicode=true&characterEncoding=utf8&serverTimezone=GMT%2B8}
|
||||
spring.datasource.url=${MYSQL_URL:jdbc:mysql://localhost:3306/tbed?useUnicode=true&characterEncoding=utf8&serverTimezone=GMT%2B8}
|
||||
#MySQL Driver 无需修改
|
||||
spring.datasource.driver-class-name=com.mysql.cj.jdbc.Driver
|
||||
|
||||
@@ -49,4 +49,10 @@ spring.datasource.druid.stat-view-servlet.login-password=52BNmXPJL0rQQ3CU
|
||||
spring.datasource.druid.stat-view-servlet.allow=127.0.0.1
|
||||
spring.datasource.druid.web-stat-filter.exclusions=false
|
||||
#log4j.logger.cn.hellohao.dao=DEBUG
|
||||
log4j2.formatMsgNoLookups=True
|
||||
log4j2.formatMsgNoLookups=True
|
||||
logging.level.cn.hellohao=DEBUG
|
||||
logging.file.name=/HellohaoData/tbedlog/tbed.log
|
||||
logging.pattern.console=%blue(%d{yyyy-MM-dd HH:mm:ss,SSS}) [%cyan(%t)] [%yellow(%c)]-[%highlight(%p)] %msg%n
|
||||
logging.pattern.file=%d{yyyy-MM-dd HH:mm:ss.SSS} [%thread] %-5level %logger{50} - %msg%n
|
||||
logging.logback.rollingpolicy.clean-history-on-start=true
|
||||
logging.logback.rollingpolicy.max-history=7
|
||||
|
||||
@@ -76,7 +76,37 @@
|
||||
<if test="idname != null and idname !=''">
|
||||
and idname LIKE '%${idname}%'
|
||||
</if>
|
||||
order by a.id desc
|
||||
order by
|
||||
<choose>
|
||||
<when test="order == 'desc'">
|
||||
a.updatetime desc
|
||||
</when>
|
||||
<when test="order == 'asc'">
|
||||
a.updatetime asc
|
||||
</when>
|
||||
<when test="order == 'sizeAsc'">
|
||||
CONVERT(a.sizes,SIGNED) asc
|
||||
</when>
|
||||
<when test="order == 'sizeDesc'">
|
||||
CONVERT(a.sizes,SIGNED) desc
|
||||
</when>
|
||||
<otherwise>
|
||||
a.updatetime desc
|
||||
</otherwise>
|
||||
</choose>
|
||||
<!-- <if test="order == 'desc'">-->
|
||||
<!-- a.updatetime desc-->
|
||||
<!-- </if>-->
|
||||
<!-- <if test="order == 'asc'">-->
|
||||
<!-- a.updatetime asc-->
|
||||
<!-- </if>-->
|
||||
<!-- <if test="order == 'sizeAsc'">-->
|
||||
<!-- CONVERT(a.sizes,SIGNED) asc-->
|
||||
<!-- </if>-->
|
||||
<!-- <if test="order == 'sizeDesc'">-->
|
||||
<!-- CONVERT(a.sizes,SIGNED) desc-->
|
||||
<!-- </if>-->
|
||||
|
||||
</select>
|
||||
|
||||
<insert id="insertImgData" parameterType="cn.hellohao.pojo.Images">
|
||||
|
||||
@@ -74,6 +74,9 @@
|
||||
<if test="email != null">
|
||||
and email = #{email}
|
||||
</if>
|
||||
<if test="username != null">
|
||||
and username = #{username}
|
||||
</if>
|
||||
<if test="uid != null">
|
||||
and uid = #{uid}
|
||||
</if>
|
||||
|
||||
Reference in New Issue
Block a user