6 Commits
Author SHA1 Message Date
hello-hao 86ae47e632 📝 2023-08-01 14:33:16 +08:00
hello-hao 241ab625c0 📝 2023-08-01 14:22:05 +08:00
hello-hao 19c2b3ce9f 📝 2023-08-01 14:19:43 +08:00
hellohao c5b800ad56 更新文档 2023-06-22 19:15:06 +08:00
hellohao c960d2a812 update:优化url上传,修复多个问题 2023-06-22 19:12:53 +08:00
hello-hao 7906948ab7 update:优化调整了多个问题 2023-06-21 19:04:59 +08:00
13 changed files with 556 additions and 400 deletions
+23 -19
View File
@@ -23,17 +23,21 @@
**存储源支持:**
开源版:`本地`,`阿里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`
### 更新日志 `20230622`
- 优化了上传页面的上传逻辑
- 添加了自动检测新版本
- 新增了图像搜索功能,可通过名称/链接进行模糊查询
- 修复多个页面问题
- 修复首页批量复制窗点击复制报错
- 优化画廊分享复制分享信息时网址和提示字符的分割,以防被encode
- 修复选择筛选框表单内容后,不检索也会筛选的异常情况
- 筛选条件添加时间倒序/顺序、文件大小倒序/顺序
- 优化用户登录账号支持邮箱/用户名方式登录
- 修复了移动端web页面首页退出按钮无反应问题
- 优化默认的站点logo展示逻辑,解决进入页面瞬间显示默认logo的问题
- 强化图像链接转存功能,支持防盗链地址转存
[^_^]: 程序宣传视频:[自制宣传视频](https://www.bilibili.com/video/BV11r4y1y7mH/)
@@ -169,11 +173,21 @@
[^_^]: ![多存储源](http://img.wwery.com/Hellohao/xXSMlsTg.png)
[^_^]: ![站点设置](http://img.wwery.com/Hellohao/n5zXistG.png)
### 客户端(win64/mac)
### 桌面客户端(win/mac)
> 目前已经正式上线
> `开源版`/`Core版` 都可以使用
> ![桌面客户端软件](https://upload.cc/i1/2022/07/13/5W8Pxh.png)
### 微信小程序
> 仅适用于对接`Core付费版`,开源版暂不可对接使用。
> 获取地址:[官网获取](https://www.hellohao.cn/pay)
![Hellohao图像托管](https://hellohao.cn/newassets/img/twechat.png)
[//]: # (![Hellohao图像托管](https://upload.cc/i1/2022/03/28/Vnp0bT.png))
### 运行环境
@@ -199,16 +213,6 @@
- JWT认证
- Shiro
### 微信小程序
> 目前已有测试版,更多功能开发中,开发进度的快慢要根据作者的工作压力、心情状况等自身情况进行评估。
> 暂时无法给出具体发布小程序的时间。大家期待吧。
![Hellohao图像托管](https://upload.cc/i1/2022/03/28/Vnp0bT.png)
[^_^]: ![小程序UI](https://upload.cc/i1/2022/02/11/6kPmr8.png)
### 声明
本项目遵循[GNU Affero General Public License v3.0](https://choosealicense.com/licenses/agpl-3.0/#)开源协议,使用前请悉知。
@@ -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", "20230622");
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 {
@@ -62,10 +62,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){
@@ -198,15 +204,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");
+324 -320
View File
@@ -1,5 +1,8 @@
package cn.hellohao.pojo;
import lombok.Data;
@Data
public class Images {
// 默认的时间字符串格式
@@ -38,326 +41,327 @@ 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;
//
// 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;
// }
}
@@ -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
+1 -1
View File
@@ -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;
}
}
+7 -1
View File
@@ -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_core.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
+31 -1
View File
@@ -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">
+3
View File
@@ -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>