15 Commits
Author SHA1 Message Date
hello-hao e2e723eb52 feat:添加强制删除,优化七牛云对接 2023-12-29 17:28:08 +08:00
hello-hao 60db6036a5 📝 2023-10-13 10:02:55 +08:00
hello-hao 790fded8ca :bug:修复了一些功能 2023-09-25 14:03:53 +08:00
hello-hao fc53e4c8ac :snail:优化了一些功能 2023-09-18 17:17:21 +08:00
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
hello-hao 3fce125334 📝 2023-05-23 10:04:38 +08:00
hello-hao 062823ae53 feat:支持查询图像,自动检测新版本 2023-05-19 18:58:57 +08:00
hello-hao 349845e6f1 📝 2023-05-19 18:50:25 +08:00
hello-hao f40f4177f7 📝 2023-05-19 18:41:58 +08:00
hello-hao 17c49157c2 📝 2023-05-19 18:39:22 +08:00
22 changed files with 437 additions and 475 deletions
+25 -24
View File
@@ -12,7 +12,7 @@
### 引导
[官网](https://tbed.hellohao.cn) | [论坛](http://bbs.hellohao.cn) | [文档](https://doc.hellohao.cn) | [演示站](https://pic.hellohao.cn) | [桌面客户端](https://tbed.hellohao.cn/app) | [前端源码](https://github.com/Hello-hao/tbed-web)
[官网](https://tbed.hellohao.cn) | [文档](https://doc.hellohao.cn) | [演示站](https://pic.hellohao.cn) | [桌面客户端](https://tbed.hellohao.cn/app) | [微信小程序](https://tbed.hellohao.cn/wechat) | [前端源码](https://github.com/Hello-hao/tbed-web)
### 前言
@@ -23,19 +23,14 @@
**存储源支持:**
开源版:`本地`,`阿里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+存储源)
### 更新日志 `20230320`
### 更新日志 `20230925`
- 修复了修改/保存存储源时,状态不能及时更新
- 优化移动端后台状态栏遮罩关闭异常的情况
- 修复百度图像鉴别不能使用的情况,鉴别违规图像不自动删除的情况
- 优化图像鉴别线程池配置
- 适配移动端页面首页状态栏
- 新增支持Docker-compose方式部署程序
- 修复一些sql异常错误的问题
[^_^]: 程序宣传视频:[自制宣传视频](https://www.bilibili.com/video/BV11r4y1y7mH/)
@@ -97,7 +92,8 @@
version: "3"
services:
tbed-free:
image: hellohao/tbed-free:20230320
# 具体版本号需要填写目前发行的最新版本
image: hellohao/tbed-free:2023xxxx
networks:
hellohao_network:
ports:
@@ -107,6 +103,8 @@
- /HellohaoData/:/HellohaoData/
environment:
MYSQL_URL: jdbc:mysql://hellohaodb/tbed?useUnicode=true&characterEncoding=UTF-8&serverTimezone=Asia/Shanghai
# 数据库用户名(一般使用本镜像数据库无需修改,如果使用外部三方数据库自行修改自己的用户名)
MYSQL_USERNAME: root
# 自定设置一个MySQL的密码,请保证与下方 POSTGRES_PASSWORD 的变量值一致
MYSQL_PASS: tIaNGg@SHa&hIo56
# 前端域名(反代10089端口的域名)
@@ -154,7 +152,7 @@
### 系统预览
![首页](https://upload.cc/i1/2022/02/11/t2wCEF.png)
![首页](https://upload.cc/i1/2023/05/23/Lsdivj.png)
![控制台详情](https://upload.cc/i1/2022/02/11/Al8UrH.png)
@@ -170,11 +168,22 @@
[^_^]: ![多存储源](http://img.wwery.com/Hellohao/xXSMlsTg.png)
[^_^]: ![站点设置](http://img.wwery.com/Hellohao/n5zXistG.png)
### 客户端(win64/mac)
### 桌面客户端(win/mac)
> 获取地址:[官网获取](https://www.hellohao.cn/app)
> 目前已经正式上线
> `开源版`/`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))
### 运行环境
@@ -200,17 +209,9 @@
- JWT认证
- Shiro
### 微信小程序
> 目前已有测试版,更多功能开发中,开发进度的快慢要根据作者的工作压力、心情状况等自身情况进行评估。
> 暂时无法给出具体发布小程序的时间。大家期待吧。
![Hellohao图像托管](https://upload.cc/i1/2022/03/28/Vnp0bT.png)
[^_^]: ![小程序UI](https://upload.cc/i1/2022/02/11/6kPmr8.png)
### 声明
Hellohao图像托管已申请[**中国国家版权局计算机软件著作权**](https://register.ccopyright.com.cn/query.html)登记,受法律法规保护。
> 登记号:2023SR1210640
本项目遵循[GNU Affero General Public License v3.0](https://choosealicense.com/licenses/agpl-3.0/#)开源协议,使用前请悉知。
如果你想商用或程序定制,请先与我们联系,分享你的利益。
+1 -1
View File
@@ -196,7 +196,7 @@
<dependency>
<groupId>com.qiniu</groupId>
<artifactId>qiniu-java-sdk</artifactId>
<version>7.2.22</version>
<version>7.14.0</version>
</dependency>
<dependency>
<groupId>com.qcloud</groupId>
@@ -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;
@@ -8,7 +8,6 @@ import com.auth0.jwt.algorithms.Algorithm;
import com.auth0.jwt.exceptions.TokenExpiredException;
import com.auth0.jwt.interfaces.DecodedJWT;
import java.text.SimpleDateFormat;
import java.util.Calendar;
import java.util.Date;
@@ -24,7 +23,7 @@ public class JWTUtil {
public static String createToken(User user){
Calendar calendar = Calendar.getInstance();
calendar.add(Calendar.SECOND,604800 );//单位秒604800 为7天
calendar.add(Calendar.SECOND,2592000 );//单位秒
Algorithm algorithm = Algorithm.HMAC256(SECRET);
String token = JWT.create()
.withClaim("email", user.getEmail())
@@ -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")) {
@@ -459,6 +467,7 @@ public class AdminController {
JSONObject jsonObj = JSONObject.parseObject(data);
String images = jsonObj.getString("images");
String uuid = jsonObj.getString("uuid");
Boolean forceDel = jsonObj.getBoolean("forceDel")==null?false:jsonObj.getBoolean("forceDel");
if (images == null) {
msg.setCode("404");
msg.setInfo("为获取到图像信息");
@@ -491,7 +500,7 @@ public class AdminController {
if (imgIds.size() == 0) {
msg.setCode("110404");
} else {
deleimages.dele(uuid, imgIds.stream().toArray(Long[]::new));
deleimages.dele(forceDel,uuid, imgIds.stream().toArray(Long[]::new));
msg.setCode("200");
}
return msg;
@@ -4,7 +4,9 @@ import cn.hellohao.pojo.*;
import cn.hellohao.service.*;
import cn.hellohao.service.impl.*;
import cn.hellohao.utils.NewSendEmail;
import cn.hellohao.utils.Print;
import cn.hellohao.utils.SetFiles;
import cn.hutool.http.HttpUtil;
import com.alibaba.fastjson.JSON;
import com.alibaba.fastjson.JSONArray;
import com.alibaba.fastjson.JSONObject;
@@ -19,6 +21,9 @@ import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RequestParam;
import org.springframework.web.bind.annotation.ResponseBody;
import java.net.HttpURLConnection;
import java.net.URL;
import java.util.HashMap;
import java.util.List;
@Controller
@@ -392,5 +397,50 @@ public class AdminRootController {
return msg;
}
@PostMapping("/sysVersion")
@ResponseBody
public Msg sysupdate(@RequestParam(value = "data", defaultValue = "") String data) {
final Msg msg = new Msg();
JSONObject jsonObj = JSONObject.parseObject(data);
String dates = jsonObj.getString("dates");
HashMap<String, Object> paramMap = new HashMap<>();
String urls = "http://check.hellohao.cn:8090/getNoticeText";
JSONObject jsonObject =null;
try {
URL u = new URL(urls);
HttpURLConnection uConnection = (HttpURLConnection) u.openConnection();
uConnection.connect();
if(uConnection.getResponseCode()==200){
jsonObject =JSONObject.parseObject(HttpUtil.get(urls));
String openv = jsonObject.getString("openv");
String opentext = jsonObject.getString("opentext");
JSONObject versionJson = new JSONObject();
if(Double.valueOf(openv)>Double.valueOf(dates)){
versionJson.put("code","110200");
versionJson.put("newVersion",openv);
versionJson.put("versionMsg",opentext);
msg.setCode("110200");
msg.setData(versionJson);
}else{
versionJson.put("code","110300");
versionJson.put("newVersion",openv);
versionJson.put("versionMsg","当前已是最新版本");
msg.setCode("110300");
msg.setData(versionJson);
}
}else{
msg.setCode("110500");
msg.setData("未获取到更新状态");
}
uConnection.disconnect();
} catch (Exception e) {
e.printStackTrace();
Print.warning("connect failed");
msg.setCode("110500");
msg.setData("未获取到更新状态");
}
return msg;
}
}
@@ -44,10 +44,11 @@ public class IndexController {
@Autowired private IRedisService iRedisService;
@Autowired private AppClientService appClientService;
public static String version = "20230925";
@RequestMapping(value = "/")
public String Welcome(Model model, HttpServletRequest httpServletRequest) {
model.addAttribute("name", "服务端程序(开源版)");
model.addAttribute("version", "20230320");
model.addAttribute("version", version);
model.addAttribute("ip", GetIPS.getIpAddr(httpServletRequest));
model.addAttribute("links", "https://github.com/Hello-hao/tbed");
return "welcome";
@@ -64,6 +65,7 @@ public class IndexController {
JSONObject jsonObject = new JSONObject();
AppClient appClient = appClientService.getAppClientData("app");
jsonObject.put("webname", cd.getString("webname"));
jsonObject.put("version",version);
jsonObject.put("websubtitle", cd.getString("websubtitle"));
jsonObject.put("keywords", cd.getString("keywords"));
jsonObject.put("webms", cd.getString("webms"));
@@ -79,6 +81,7 @@ public class IndexController {
jsonObject.put("clientname", appClient.getAppname());
jsonObject.put("clientlogo", appClient.getApplogo());
jsonObject.put("appupdate", appClient.getAppupdate());
jsonObject.put("serverVersion",version);
msg.setData(jsonObject);
return msg;
}
@@ -146,6 +149,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 +169,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 +323,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);
@@ -353,7 +383,7 @@ public class IndexController {
return msg;
}
}
msg = deleimages.dele(null, image.getId());
msg = deleimages.dele(false,null, image.getId());
List<Long> Delids = (List<Long>) msg.getData();
if (!Delids.contains(image.getId())) {
msg.setCode("500");
@@ -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");
+4 -322
View File
@@ -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;
}
@@ -5,10 +5,10 @@ import cn.hellohao.pojo.Keys;
import cn.hellohao.pojo.ReturnImage;
import com.google.gson.Gson;
import com.qiniu.common.QiniuException;
import com.qiniu.common.Zone;
import com.qiniu.http.Response;
import com.qiniu.storage.BucketManager;
import com.qiniu.storage.Configuration;
import com.qiniu.storage.Region;
import com.qiniu.storage.UploadManager;
import com.qiniu.storage.model.DefaultPutRet;
import com.qiniu.storage.model.FileInfo;
@@ -28,18 +28,7 @@ public class KODOImageupload {
public ReturnImage ImageuploadKODO(
Map<Map<String, String>, File> fileMap, String username, Integer keyID) {
ReturnImage returnImage = new ReturnImage();
Configuration cfg;
if (key.getEndpoint().equals("1")) {
cfg = new Configuration(Zone.zone0());
} else if (key.getEndpoint().equals("2")) {
cfg = new Configuration(Zone.zone1());
} else if (key.getEndpoint().equals("3")) {
cfg = new Configuration(Zone.zone2());
} else if (key.getEndpoint().equals("4")) {
cfg = new Configuration(Zone.zoneNa0());
} else {
cfg = new Configuration(Zone.zoneAs0());
}
Configuration cfg = new Configuration(Region.autoRegion());
UploadManager uploadManager = new UploadManager(cfg);
Auth auth = Auth.create(key.getAccessKey(), key.getAccessSecret());
String upToken = auth.uploadToken(key.getBucketname(), null, 7200, null);
@@ -76,41 +65,25 @@ public class KODOImageupload {
public static Integer Initialize(Keys k) {
int ret = -1;
if (org.apache.commons.lang3.StringUtils.isBlank(k.getAccessKey())
|| org.apache.commons.lang3.StringUtils.isBlank(k.getAccessSecret())
|| org.apache.commons.lang3.StringUtils.isBlank(k.getEndpoint())
|| org.apache.commons.lang3.StringUtils.isBlank(k.getBucketname())
if (StringUtils.isBlank(k.getAccessKey())
|| StringUtils.isBlank(k.getAccessSecret())
|| StringUtils.isBlank(k.getEndpoint())
|| StringUtils.isBlank(k.getBucketname())
|| StringUtils.isBlank(k.getRequestAddress())) {
return -1;
}
Configuration cfg;
if (k.getEndpoint().equals("1")) {
cfg = new Configuration(Zone.zone0());
} else if (k.getEndpoint().equals("2")) {
cfg = new Configuration(Zone.zone1());
} else if (k.getEndpoint().equals("3")) {
cfg = new Configuration(Zone.zone2());
} else if (k.getEndpoint().equals("4")) {
cfg = new Configuration(Zone.zoneNa0());
} else {
cfg = new Configuration(Zone.zoneAs0());
}
Configuration cfg = new Configuration(Region.autoRegion());
UploadManager uploadManager = new UploadManager(cfg);
Auth auth = Auth.create(k.getAccessKey(), k.getAccessSecret());
String upToken =
auth.uploadToken(
k.getBucketname(),
null,
7200,
null); // auth.uploadToken(k.getBucketname());
BucketManager bmObj = new BucketManager(auth, cfg);
String upToken = auth.uploadToken(k.getBucketname(), null, 7200, null);
BucketManager BM = new BucketManager(auth, cfg);
BucketManager.FileListIterator fileListIterator = null;
try {
fileListIterator = bmObj.createFileListIterator(k.getBucketname(), "", 1, "/");
fileListIterator = BM.createFileListIterator(k.getBucketname(), "", 1, "/");
FileInfo[] items = fileListIterator.next();
if (items != null) {
ret = 1;
bucketManager = bmObj;
bucketManager = BM;
key = k;
}
} catch (Exception e) {
@@ -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;
@@ -32,7 +32,7 @@ public class deleImages {
@Autowired private KeysServiceImpl keysService;
@Autowired private IRedisService iRedisService;
public Msg dele(String uuid, Long... imgIds) {
public Msg dele(boolean forceDel,String uuid, Long... imgIds) {
Msg msg = new Msg();
MyProgress myProgress = new MyProgress();
myProgress.InitializeDelImg();
@@ -44,6 +44,20 @@ public class deleImages {
boolean isDele = false;
try {
Images image = imgService.selectByPrimaryKey(imgIds[i]);
if (!forceDel) {
try {
imgAndAlbumService.deleteImgAndAlbum(image.getImgurl());
imgTempService.delImgAndExp(image.getImguid());
imgService.deleimg(image.getId());
ids.add(image.getId());
successCount++;
System.out.println("删除成功加一个" + image.getId());
} catch (Exception e) {
e.printStackTrace();
System.err.println(image.getImgname() + ":图片数据库记录时发生错误");
errorIds.add(image.getImgurl());
}
}
Keys key = keysService.selectKeys(image.getSource());
if (key.getStorageType() == 1) {
isDele = nosImageupload.delNOS(key.getId(), image);
@@ -64,20 +78,21 @@ public class deleImages {
} else {
System.err.println("未获取到对象存储参数,删除失败。");
}
// if (isDele) {
try {
imgAndAlbumService.deleteImgAndAlbum(image.getImgurl());
imgTempService.delImgAndExp(image.getImguid());
imgService.deleimg(image.getId());
ids.add(image.getId());
successCount++;
System.out.println("删除成功加一个" + image.getId());
} catch (Exception e) {
e.printStackTrace();
System.err.println(image.getImgname() + ":图片数据库记录时发生错误");
errorIds.add(image.getImgurl());
if (!forceDel) {
try {
imgAndAlbumService.deleteImgAndAlbum(image.getImgurl());
imgTempService.delImgAndExp(image.getImguid());
imgService.deleimg(image.getId());
ids.add(image.getId());
successCount++;
System.out.println("删除成功加一个" + image.getId());
} catch (Exception e) {
e.printStackTrace();
System.err.println(image.getImgname() + ":图片数据库记录时发生错误");
errorIds.add(image.getImgurl());
}
}
// }
if(uuid!=null){
myProgress.setDelSuccessCount(successCount);
myProgress.setDelSuccessImgList(ids);
@@ -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;
}
}
+9 -3
View File
@@ -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
+7 -5
View File
@@ -9,11 +9,12 @@
FROM
`album`
<where>
1=1
<if test="albumkey != null">
`albumkey` = #{albumkey}
and `albumkey` = #{albumkey}
</if>
<if test="userid != null">
`userid` = #{userid}
and `userid` = #{userid}
</if>
</where>
</select>
@@ -38,14 +39,15 @@
u.username
FROM `album` a LEFT JOIN user u on a.userid = u.id
<where>
1=1
<if test="albumkey != null">
`albumkey` like '%${albumkey}%'
and `albumkey` like '%${albumkey}%'
</if>
<if test="username != null">
`username` like '%${username}%'
and `username` like '%${username}%'
</if>
<if test="userid != null">
a.userid = #{userid}
and a.userid = #{userid}
</if>
</where>
order by a.createdate
@@ -9,6 +9,7 @@
FROM
`imgandalbum`
<where>
1=1
<if test="albumkey != null">
`albumkey` = #{albumkey}
</if>
@@ -21,6 +22,7 @@
FROM
`imgandalbum`
<where>
1=1
<if test="imgname != null">
`imgname` = #{imgname}
</if>
+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>