24 Commits
Author SHA1 Message Date
hello-hao 2ee49dcae2 :art:完善部分新功能 2022-11-21 19:03:58 +08:00
hello-hao b978f33aba 📝 2022-11-20 22:29:04 +08:00
hello-hao d8bb6c1738 :art:完善部分新功能 2022-11-19 16:49:23 +08:00
hellohao e1018bde75 📝 2022-10-26 21:55:21 +08:00
hellohao 8c8e44f82c :rocket:优化验证码失效等问题 2022-10-26 21:51:25 +08:00
hellohao f61e672e54 📝 2022-09-05 16:44:16 +08:00
hellohao 4a5147b862 📝 2022-09-03 02:06:21 +08:00
hellohao f9374cbc0e :rocket:优化代码 2022-09-01 18:51:47 +08:00
hellohao 10b919be95 📝 2022-09-01 18:48:42 +08:00
hellohao 8d96a3d636 处理已知问题 2022-09-01 00:58:05 +08:00
hellohao a086e708b4 Merge branch 'hellohao-dev' 2022-09-01 00:50:36 +08:00
hellohao 903cd6c74a Merge remote-tracking branch 'origin/hellohao-dev' into hellohao-dev
# Conflicts:
#	src/main/java/cn/hellohao/utils/FirstRun.java
2022-09-01 00:49:58 +08:00
hellohao 7c5524c1ee 代码更新 2022-09-01 00:49:16 +08:00
hellohao 444f16dc2c Merge branch 'master' of https://github.com/Hello-hao/Tbed 2022-09-01 00:45:11 +08:00
hellohao d96096965f Merge branch 'master' into hellohao-dev 2022-09-01 00:39:17 +08:00
hello-hao 3d4ff813fe :art:完善部分新功能 2022-07-20 18:16:03 +08:00
hello-hao 9ac31c22ca :art:自动修改数据库字段大小 2022-07-20 10:28:49 +08:00
hellohao 5041d65612 代码更新 2022-07-19 22:57:12 +08:00
hellohao 196bbf8026 代码更新 2022-07-19 22:55:52 +08:00
hellohao d1942a5295 代码更新 2022-07-19 22:53:15 +08:00
hello-hao 9293c0d295 :art:完善部分新功能 2022-07-18 17:12:18 +08:00
hello-hao 1de06c6352 📝 2022-07-13 10:38:24 +08:00
hello-hao b9d020f7a6 📝 2022-07-13 10:23:01 +08:00
hellohao dcf753b2b3 代码更新 2022-07-12 22:41:44 +08:00
40 changed files with 1708 additions and 1225 deletions
+18 -10
View File
@@ -10,12 +10,12 @@
### 引导
[官网](https://tbed.hellohao.cn) | [宣传视频](https://www.bilibili.com/video/BV11r4y1y7mH/) | [文档](https://doc.hellohao.cn) | [演示站](https://pic.hellohao.cn) | [前端源码](https://github.com/Hello-hao/tbed-web)
[官网](https://tbed.hellohao.cn) | [宣传视频](https://www.bilibili.com/video/BV11r4y1y7mH/) | [文档](https://doc.hellohao.cn) | [演示站](https://pic.hellohao.cn) | [前端源码](https://github.com/Hello-hao/tbed-web) | [桌面客户端](https://tbed.hellohao.cn/app)
### 前言
**Hellohao图像托管程序**(图床)这是一个由JAVA语言编写SpringBoot框架开发的开源图像托管程序。具备多对象存储源对接,采用`前后端分离`式设计的一款专门托管图像的程序,支持多种格式的图像 多功能的图床系统。
**Hellohao图像托管程序**(图床)这是一个由JAVA语言编写SpringBoot框架开发的开源图像托管程序。具备多对象存储源对接,采用`前后端分离`式设计的一款专门托管图像的程序,支持多种格式的图像 多功能的图床系统。该程序支持除了`web端`之外,同时支持`客户端(win/mac`,`移动端(小程序)`等常用全平台支持。
程序主要使用领域:`个人照片存储``团队共享图像``博客/商城等网站图片托管``图像批量云分享`等。具备优秀的多用户图像上传功能和完善的图像查询管理逻辑,同时支持对接多家对象存储。
@@ -23,16 +23,15 @@
开源版:`本地`,`阿里OSS`,`又拍USS`,`七牛KODO`,`腾讯COS`,`网易NOS`,~~`U-File`~~,`FTP`
Core版:`本地`,`阿里OSS`,`又拍USS`,`七牛KODO`,`腾讯COS`,`网易NOS`,~~`U-File`~~,`FTP`,`Backblaze(B2)`,`百度云BOS`,`青云Qingstor`,`Ucloud US3`,`Minio`,`AWS S3`
Core版:`本地`,`阿里OSS`,`又拍USS`,`七牛KODO`,`腾讯COS`,`网易NOS`,~~`U-File`~~,`FTP`,`Backblaze(B2)`,`百度云BOS`,`青云Qingstor`,`Ucloud US3`,`Minio`,`AWS S3`等通用S3协议
### 更新日志 `20220506`
- [x] 新增个人相册复制链接功能可选链接格式
- [x] 修复了系统已知安全隐患
- [x] 优化重写删除图像功能,修复部分场景下图像删除失败的问题(支持进度展示)
- [x] 优化多个页面细节
### 更新日志 `20221027`
- `修复`部分场景下登录或者注册时出现验证码一直不正确的问题
- `调整`URL转存时提示登陆的限制
- `优化`服务端返回值的一些问题
[^_^]:程序宣传视频:[自制宣传视频](https://www.bilibili.com/video/BV11r4y1y7mH/)
@@ -60,6 +59,8 @@ Core版:`本地`,`阿里OSS`,`又拍USS`,`七牛KODO`,`腾讯COS`,`网易NOS`,
### 主要功能
- [x] 全端支持,不限于(`web端`/`桌面端Windows/Mac`/`移动端小程序`)
- [x] 前后端分离式架构设计,部署更方便
- [x] 个人相册浏览,图像详细资料展示卡片
@@ -76,7 +77,9 @@ Core版:`本地`,`阿里OSS`,`又拍USS`,`七牛KODO`,`腾讯COS`,`网易NOS`,
- [x] 图片定期暂存
- [x] 支持多种图像格式如:`jfif`,`webp`,`ico`,`svg`
- [x] 图片名称记录/修改
- [x] 支持常见多种图像格式如:`webp`,`ico`,`svg`等等
- [x] 支持画廊批量分享模式
@@ -157,6 +160,11 @@ Core版:`本地`,`阿里OSS`,`又拍USS`,`七牛KODO`,`腾讯COS`,`网易NOS`,
初始邮箱:`admin`
初始密码:`admin`
### 客户端(win64/mac)
> 目前已经正式上线
![桌面客户端软件](https://upload.cc/i1/2022/07/13/5W8Pxh.png)
### 微信小程序
> 目前已有测试版,更多功能开发中,开发进度的快慢要根据作者的工作压力、心情状况等自身情况进行评估。
> 暂时无法给出具体发布小程序的时间。大家期待吧。
+72 -51
View File
@@ -1,17 +1,17 @@
/*
Navicat Premium Data Transfer
Source Server : localhost
Source Server : locMysql
Source Server Type : MySQL
Source Server Version : 50720
Source Server Version : 80028
Source Host : localhost:3306
Source Schema : tbed
Target Server Type : MySQL
Target Server Version : 50720
Target Server Version : 80028
File Encoding : 65001
Date: 29/10/2021 14:42:28
Date: 01/09/2022 00:28:28
*/
SET NAMES utf8mb4;
@@ -26,23 +26,42 @@ CREATE TABLE `album` (
`albumtitle` varchar(255) CHARACTER SET utf8 COLLATE utf8_general_ci NULL DEFAULT NULL,
`createdate` varchar(255) CHARACTER SET utf8 COLLATE utf8_general_ci NULL DEFAULT NULL,
`password` varchar(255) CHARACTER SET utf8 COLLATE utf8_general_ci NULL DEFAULT NULL,
`userid` int(10) NULL DEFAULT NULL
`userid` int(0) NULL DEFAULT NULL
) ENGINE = InnoDB CHARACTER SET = utf8 COLLATE = utf8_general_ci ROW_FORMAT = Compact;
-- ----------------------------
-- Records of album
-- ----------------------------
-- ----------------------------
-- Table structure for appclient
-- ----------------------------
DROP TABLE IF EXISTS `appclient`;
CREATE TABLE `appclient` (
`id` varchar(10) CHARACTER SET utf8 COLLATE utf8_general_ci NOT NULL,
`isuse` varchar(10) CHARACTER SET utf8 COLLATE utf8_general_ci NOT NULL,
`winpackurl` varchar(255) CHARACTER SET utf8 COLLATE utf8_general_ci NULL DEFAULT NULL,
`macpackurl` varchar(255) CHARACTER SET utf8 COLLATE utf8_general_ci NULL DEFAULT NULL,
`appname` varchar(20) CHARACTER SET utf8 COLLATE utf8_general_ci NULL DEFAULT NULL,
`applogo` varchar(255) CHARACTER SET utf8 COLLATE utf8_general_ci NULL DEFAULT NULL,
`appupdate` varchar(10) CHARACTER SET utf8 COLLATE utf8_general_ci NOT NULL
) ENGINE = InnoDB CHARACTER SET = utf8 COLLATE = utf8_general_ci ROW_FORMAT = Dynamic;
-- ----------------------------
-- Records of appclient
-- ----------------------------
INSERT INTO `appclient` VALUES ('app', 'on', '', '', 'Hellohao图像托管', 'https://hellohao.nos-eastchina1.126.net/TbedClient/app.png', '1.0.1');
-- ----------------------------
-- Table structure for code
-- ----------------------------
DROP TABLE IF EXISTS `code`;
CREATE TABLE `code` (
`id` int(255) NOT NULL AUTO_INCREMENT,
`id` int(0) NOT NULL AUTO_INCREMENT,
`value` varchar(500) CHARACTER SET utf8 COLLATE utf8_general_ci NULL DEFAULT NULL,
`code` varchar(500) CHARACTER SET utf8 COLLATE utf8_general_ci NOT NULL,
PRIMARY KEY (`id`) USING BTREE
) ENGINE = InnoDB AUTO_INCREMENT = 1 CHARACTER SET = utf8 COLLATE = utf8_general_ci ROW_FORMAT = Compact;
) ENGINE = InnoDB AUTO_INCREMENT = 11 CHARACTER SET = utf8 COLLATE = utf8_general_ci ROW_FORMAT = Compact;
-- ----------------------------
-- Records of code
@@ -53,24 +72,24 @@ CREATE TABLE `code` (
-- ----------------------------
DROP TABLE IF EXISTS `config`;
CREATE TABLE `config` (
`id` int(4) NOT NULL AUTO_INCREMENT,
`sourcekey` int(4) NULL DEFAULT NULL,
`emails` int(4) NULL DEFAULT NULL COMMENT '邮箱配置',
`id` int(0) NOT NULL AUTO_INCREMENT,
`sourcekey` int(0) NULL DEFAULT NULL,
`emails` int(0) NULL DEFAULT NULL COMMENT '邮箱配置',
`webname` varchar(255) CHARACTER SET utf8 COLLATE utf8_general_ci NULL DEFAULT NULL COMMENT '网站名',
`explain` varchar(1000) CHARACTER SET utf8 COLLATE utf8_general_ci NULL DEFAULT NULL,
`explain` text CHARACTER SET utf8 COLLATE utf8_general_ci NULL,
`video` varchar(1000) CHARACTER SET utf8 COLLATE utf8_general_ci NULL DEFAULT NULL,
`backtype` varchar(500) CHARACTER SET utf8 COLLATE utf8_general_ci NULL DEFAULT NULL COMMENT '背景类型',
`links` varchar(1000) CHARACTER SET utf8 COLLATE utf8_general_ci NULL DEFAULT NULL,
`notice` varchar(1000) CHARACTER SET utf8 COLLATE utf8_general_ci NULL DEFAULT NULL,
`baidu` varchar(1000) CHARACTER SET utf8 COLLATE utf8_general_ci NULL DEFAULT NULL,
`links` text CHARACTER SET utf8 COLLATE utf8_general_ci NULL,
`notice` text CHARACTER SET utf8 COLLATE utf8_general_ci NULL,
`baidu` text CHARACTER SET utf8 COLLATE utf8_general_ci NULL,
`domain` varchar(1000) CHARACTER SET utf8 COLLATE utf8_general_ci NULL DEFAULT NULL,
`background1` varchar(1000) CHARACTER SET utf8 COLLATE utf8_general_ci NULL DEFAULT NULL,
`background2` varchar(1000) CHARACTER SET utf8 COLLATE utf8_general_ci NULL DEFAULT NULL,
`sett` int(2) NOT NULL COMMENT '首页样式',
`sett` int(0) NOT NULL COMMENT '首页样式',
`webms` varchar(1000) CHARACTER SET utf8 COLLATE utf8_general_ci NULL DEFAULT NULL,
`webkeywords` varchar(1000) CHARACTER SET utf8 COLLATE utf8_general_ci NULL DEFAULT NULL,
`webfavicons` varchar(1000) CHARACTER SET utf8 COLLATE utf8_general_ci NULL DEFAULT NULL,
`theme` int(4) NULL DEFAULT 1 COMMENT '主题',
`theme` int(0) NULL DEFAULT 1 COMMENT '主题',
`websubtitle` mediumtext CHARACTER SET utf8 COLLATE utf8_general_ci NULL,
`logo` mediumtext CHARACTER SET utf8 COLLATE utf8_general_ci NULL,
`aboutinfo` mediumtext CHARACTER SET utf8 COLLATE utf8_general_ci NULL,
@@ -87,13 +106,13 @@ INSERT INTO `config` VALUES (1, 7, 1, 'Hellohao图床', 'Hellohao图像托管,
-- ----------------------------
DROP TABLE IF EXISTS `emailconfig`;
CREATE TABLE `emailconfig` (
`id` int(2) NOT NULL AUTO_INCREMENT,
`id` int(0) NOT NULL AUTO_INCREMENT,
`emails` varchar(255) CHARACTER SET utf8 COLLATE utf8_general_ci NULL DEFAULT NULL COMMENT '邮箱',
`emailkey` varchar(255) CHARACTER SET utf8 COLLATE utf8_general_ci NULL DEFAULT NULL COMMENT '授权码',
`emailurl` varchar(255) CHARACTER SET utf8 COLLATE utf8_general_ci NULL DEFAULT NULL COMMENT '服务器',
`port` varchar(255) CHARACTER SET utf8 COLLATE utf8_general_ci NULL DEFAULT NULL COMMENT '端口',
`emailname` varchar(255) CHARACTER SET utf8 COLLATE utf8_general_ci NULL DEFAULT NULL COMMENT '用户名',
`using` int(4) NULL DEFAULT NULL COMMENT '1为可用,其他为不使用',
`using` int(0) NULL DEFAULT NULL COMMENT '1为可用,其他为不使用',
PRIMARY KEY (`id`) USING BTREE
) ENGINE = InnoDB AUTO_INCREMENT = 2 CHARACTER SET = utf8 COLLATE = utf8_general_ci ROW_FORMAT = Compact;
@@ -107,11 +126,11 @@ INSERT INTO `emailconfig` VALUES (1, '', '', '', '465', 'Hellohao图床', 0);
-- ----------------------------
DROP TABLE IF EXISTS `group`;
CREATE TABLE `group` (
`id` int(255) NOT NULL AUTO_INCREMENT,
`id` int(0) NOT NULL AUTO_INCREMENT,
`groupname` varchar(255) CHARACTER SET utf8 COLLATE utf8_general_ci NOT NULL COMMENT '组名称',
`keyid` int(255) NULL DEFAULT NULL,
`usertype` int(4) NULL DEFAULT NULL,
`compress` int(4) NULL DEFAULT NULL,
`keyid` int(0) NULL DEFAULT NULL,
`usertype` int(0) NULL DEFAULT NULL,
`compress` int(0) NULL DEFAULT NULL,
PRIMARY KEY (`id`) USING BTREE
) ENGINE = InnoDB AUTO_INCREMENT = 2 CHARACTER SET = utf8 COLLATE = utf8_general_ci ROW_FORMAT = Compact;
@@ -140,24 +159,25 @@ INSERT INTO `imgandalbum` VALUES ('http://img.wwery.com/ccx51/5GBv93Ks.jpg', 'TO
-- ----------------------------
DROP TABLE IF EXISTS `imgdata`;
CREATE TABLE `imgdata` (
`id` int(255) NOT NULL AUTO_INCREMENT COMMENT '主键',
`id` int(0) NOT NULL AUTO_INCREMENT COMMENT '主键',
`imgname` varchar(500) CHARACTER SET utf8 COLLATE utf8_general_ci NULL DEFAULT NULL COMMENT '图片名',
`imgurl` varchar(500) CHARACTER SET utf8 COLLATE utf8_general_ci NULL DEFAULT NULL COMMENT '图片链接',
`userid` int(10) NULL DEFAULT NULL COMMENT '用户名',
`userid` int(0) NULL DEFAULT NULL COMMENT '用户名',
`updatetime` varchar(50) CHARACTER SET utf8 COLLATE utf8_general_ci NULL DEFAULT NULL COMMENT '上传时间',
`sizes` varchar(500) CHARACTER SET utf8 COLLATE utf8_general_ci NULL DEFAULT NULL,
`abnormal` varchar(255) CHARACTER SET utf8 COLLATE utf8_general_ci NULL DEFAULT NULL,
`source` int(2) NULL DEFAULT NULL COMMENT '存储源',
`imgtype` int(2) NULL DEFAULT NULL,
`source` int(0) NULL DEFAULT NULL COMMENT '存储源',
`imgtype` int(0) NULL DEFAULT NULL,
`explains` varchar(500) CHARACTER SET utf8 COLLATE utf8_general_ci NULL DEFAULT NULL,
`md5key` varchar(500) CHARACTER SET utf8 COLLATE utf8_general_ci NULL DEFAULT NULL,
`imguid` varchar(255) CHARACTER SET utf8 COLLATE utf8_general_ci NULL DEFAULT NULL,
`format` varchar(255) CHARACTER SET utf8 COLLATE utf8_general_ci NULL DEFAULT NULL,
`about` text CHARACTER SET utf8 COLLATE utf8_general_ci NULL,
`violation` varchar(50) CHARACTER SET utf8 COLLATE utf8_general_ci NULL DEFAULT NULL,
`idname` varchar(255) CHARACTER SET utf8 COLLATE utf8_general_ci NULL DEFAULT '未命名图像',
PRIMARY KEY (`id`) USING BTREE,
INDEX `index_md5key_url`(`md5key`(255), `imgurl`(255)) USING BTREE
) ENGINE = InnoDB AUTO_INCREMENT = 6 CHARACTER SET = utf8 COLLATE = utf8_general_ci ROW_FORMAT = Compressed;
) ENGINE = InnoDB AUTO_INCREMENT = 12 CHARACTER SET = utf8 COLLATE = utf8_general_ci ROW_FORMAT = Compressed;
-- ----------------------------
-- Records of imgdata
@@ -168,12 +188,12 @@ CREATE TABLE `imgdata` (
-- ----------------------------
DROP TABLE IF EXISTS `imgreview`;
CREATE TABLE `imgreview` (
`id` int(4) NOT NULL AUTO_INCREMENT,
`id` int(0) NOT NULL AUTO_INCREMENT,
`app_id` varchar(255) CHARACTER SET utf8 COLLATE utf8_general_ci NULL DEFAULT NULL,
`api_key` varchar(255) CHARACTER SET utf8 COLLATE utf8_general_ci NULL DEFAULT NULL,
`secret_key` varchar(255) CHARACTER SET utf8 COLLATE utf8_general_ci NULL DEFAULT NULL,
`Using` int(4) NULL DEFAULT NULL,
`count` int(255) NULL DEFAULT NULL COMMENT '拦截数量',
`Using` int(0) NULL DEFAULT NULL,
`count` int(0) NULL DEFAULT NULL COMMENT '拦截数量',
PRIMARY KEY (`id`) USING BTREE
) ENGINE = InnoDB AUTO_INCREMENT = 3 CHARACTER SET = utf8 COLLATE = utf8_general_ci ROW_FORMAT = Compact;
@@ -187,7 +207,7 @@ INSERT INTO `imgreview` VALUES (1, '', '', '', 0, 0);
-- ----------------------------
DROP TABLE IF EXISTS `imgtemp`;
CREATE TABLE `imgtemp` (
`id` int(255) NOT NULL AUTO_INCREMENT,
`id` int(0) NOT NULL AUTO_INCREMENT,
`imguid` varchar(255) CHARACTER SET utf8 COLLATE utf8_general_ci NULL DEFAULT NULL,
`deltime` varchar(255) CHARACTER SET utf8 COLLATE utf8_general_ci NULL DEFAULT NULL,
PRIMARY KEY (`id`) USING BTREE
@@ -202,13 +222,13 @@ CREATE TABLE `imgtemp` (
-- ----------------------------
DROP TABLE IF EXISTS `keys`;
CREATE TABLE `keys` (
`id` int(11) NOT NULL AUTO_INCREMENT,
`id` int(0) NOT NULL AUTO_INCREMENT,
`AccessKey` varchar(255) CHARACTER SET utf8 COLLATE utf8_general_ci NULL DEFAULT NULL,
`AccessSecret` varchar(255) CHARACTER SET utf8 COLLATE utf8_general_ci NULL DEFAULT NULL,
`Endpoint` varchar(255) CHARACTER SET utf8 COLLATE utf8_general_ci NULL DEFAULT NULL,
`Bucketname` varchar(255) CHARACTER SET utf8 COLLATE utf8_general_ci NULL DEFAULT NULL,
`RequestAddress` varchar(255) CHARACTER SET utf8 COLLATE utf8_general_ci NULL DEFAULT NULL,
`storageType` int(11) NULL DEFAULT NULL,
`storageType` int(0) NULL DEFAULT NULL,
`keyname` varchar(255) CHARACTER SET utf8 COLLATE utf8_general_ci NULL DEFAULT '未定义策略名称' COMMENT '策略名称',
PRIMARY KEY (`id`) USING BTREE
) ENGINE = InnoDB AUTO_INCREMENT = 14 CHARACTER SET = utf8 COLLATE = utf8_general_ci ROW_FORMAT = Compact;
@@ -230,8 +250,8 @@ INSERT INTO `keys` VALUES (13, '', '', '', '0', '', 7, 'ftp');
-- ----------------------------
DROP TABLE IF EXISTS `sysconfig`;
CREATE TABLE `sysconfig` (
`id` int(2) NOT NULL AUTO_INCREMENT,
`register` int(2) NOT NULL COMMENT '是否可以注册',
`id` int(0) NOT NULL AUTO_INCREMENT,
`register` int(0) NOT NULL COMMENT '是否可以注册',
`checkduplicate` varchar(255) CHARACTER SET utf8 COLLATE utf8_general_ci NULL DEFAULT '0',
PRIMARY KEY (`id`) USING BTREE
) ENGINE = InnoDB AUTO_INCREMENT = 2 CHARACTER SET = utf8 COLLATE = utf8_general_ci ROW_FORMAT = Compact;
@@ -246,19 +266,19 @@ INSERT INTO `sysconfig` VALUES (1, 1, '0');
-- ----------------------------
DROP TABLE IF EXISTS `uploadconfig`;
CREATE TABLE `uploadconfig` (
`id` int(2) NOT NULL AUTO_INCREMENT,
`id` int(0) NOT NULL AUTO_INCREMENT,
`filesizetourists` varchar(500) CHARACTER SET utf8 COLLATE utf8_general_ci NULL DEFAULT NULL,
`filesizeuser` varchar(500) CHARACTER SET utf8 COLLATE utf8_general_ci NULL DEFAULT NULL,
`imgcounttourists` int(10) NULL DEFAULT NULL COMMENT '游客文件总数量, 超出则不允许加入队列',
`imgcountuser` int(10) NULL DEFAULT NULL COMMENT '用户文件总数量, 超出则不允许加入队列',
`imgcounttourists` int(0) NULL DEFAULT NULL COMMENT '游客文件总数量, 超出则不允许加入队列',
`imgcountuser` int(0) NULL DEFAULT NULL COMMENT '用户文件总数量, 超出则不允许加入队列',
`suffix` varchar(255) CHARACTER SET utf8 COLLATE utf8_general_ci NULL DEFAULT NULL COMMENT '支持后缀',
`urltype` int(2) NULL DEFAULT NULL COMMENT 'url类型',
`isupdate` int(2) NULL DEFAULT NULL COMMENT '禁止游客上传',
`api` int(2) NOT NULL COMMENT '开启api',
`urltype` int(0) NULL DEFAULT NULL COMMENT 'url类型',
`isupdate` int(0) NULL DEFAULT NULL COMMENT '禁止游客上传',
`api` int(0) NOT NULL COMMENT '开启api',
`visitormemory` varchar(500) CHARACTER SET utf8 COLLATE utf8_general_ci NULL DEFAULT NULL,
`usermemory` varchar(500) CHARACTER SET utf8 COLLATE utf8_general_ci NULL DEFAULT NULL,
`blacklist` varchar(4000) CHARACTER SET utf8 COLLATE utf8_general_ci NULL DEFAULT NULL,
`userclose` int(4) NULL DEFAULT 0 COMMENT '用户上传开关',
`userclose` int(0) NULL DEFAULT 0 COMMENT '用户上传开关',
PRIMARY KEY (`id`) USING BTREE
) ENGINE = InnoDB AUTO_INCREMENT = 2 CHARACTER SET = utf8 COLLATE = utf8_general_ci ROW_FORMAT = Compact;
@@ -272,34 +292,35 @@ INSERT INTO `uploadconfig` VALUES (1, '10485760', '20971520', 5, 10, 'gif,jpg,jp
-- ----------------------------
DROP TABLE IF EXISTS `user`;
CREATE TABLE `user` (
`id` int(10) NOT NULL AUTO_INCREMENT COMMENT '主键',
`id` int(0) NOT NULL AUTO_INCREMENT COMMENT '主键',
`username` varchar(50) CHARACTER SET utf8 COLLATE utf8_general_ci NOT NULL COMMENT '用户名',
`password` varchar(50) CHARACTER SET utf8 COLLATE utf8_general_ci NOT NULL COMMENT '密码',
`email` varchar(50) CHARACTER SET utf8 COLLATE utf8_general_ci NULL DEFAULT NULL,
`birthder` date NULL DEFAULT NULL COMMENT '注册时间',
`level` int(10) NULL DEFAULT NULL COMMENT '等级',
`level` int(0) NULL DEFAULT NULL COMMENT '等级',
`uid` varchar(50) CHARACTER SET utf8 COLLATE utf8_general_ci NULL DEFAULT NULL COMMENT '用户唯一标识',
`isok` int(2) NOT NULL,
`isok` int(0) NOT NULL,
`memory` varchar(500) CHARACTER SET utf8 COLLATE utf8_general_ci NULL DEFAULT NULL,
`groupid` int(255) NULL DEFAULT NULL,
`groupid` int(0) NULL DEFAULT NULL,
`token` varchar(255) CHARACTER SET utf8 COLLATE utf8_general_ci NULL DEFAULT NULL,
PRIMARY KEY (`id`) USING BTREE
) ENGINE = InnoDB AUTO_INCREMENT = 3 CHARACTER SET = utf8 COLLATE = utf8_general_ci ROW_FORMAT = Compact;
-- ----------------------------
-- Records of user
-- ----------------------------
INSERT INTO `user` VALUES (1, 'admin', 'YWRtaW4=', 'admin', '2019-01-10', 2, 'e95c0571bfe04ec680c249fb15cc22e9', 1, '2147483648', 1);
INSERT INTO `user` VALUES (1, 'admin', 'YWRtaW4=', 'admin', '2019-01-10', 2, '9b76655b2706483780bf54988ca12531', 1, '2147483648', 1, '');
-- ----------------------------
-- Table structure for usergroup
-- ----------------------------
DROP TABLE IF EXISTS `usergroup`;
CREATE TABLE `usergroup` (
`id` int(255) NOT NULL AUTO_INCREMENT,
`userid` int(255) NULL DEFAULT NULL,
`groupid` int(255) NULL DEFAULT NULL,
`id` int(0) NOT NULL AUTO_INCREMENT,
`userid` int(0) NULL DEFAULT NULL,
`groupid` int(0) NULL DEFAULT NULL,
PRIMARY KEY (`id`) USING BTREE
) ENGINE = InnoDB AUTO_INCREMENT = 2 CHARACTER SET = utf8 COLLATE = utf8_general_ci ROW_FORMAT = Compact;
) ENGINE = InnoDB AUTO_INCREMENT = 1 CHARACTER SET = utf8 COLLATE = utf8_general_ci ROW_FORMAT = Compact;
-- ----------------------------
-- Records of usergroup
@@ -34,8 +34,8 @@ public class SubjectFilter extends BasicHttpAuthenticationFilter {
String Users_Origin = httpServletRequest.getHeader("usersOrigin");
String token = httpServletRequest.getHeader("Authorization");
//验证前端域名
if(httpServletRequest.getMethod().equals("POST") && !serviceName.contains("/api")
&& !serviceName.contains("/verifyCode") && !serviceName.contains("/client")){
if(httpServletRequest.getMethod().equals("POST") && !serviceName.contains("/api") && !serviceName.contains("/verifyCode")
&& !serviceName.contains("/getClientVersion") && !serviceName.contains("/client")){
try{
if(Users_Origin.compareTo(SecureUtil.md5(WEBHOST))!=0){
System.out.println("前端域名校验未通过");
@@ -24,7 +24,6 @@ public class XssFilter implements Filter {
//由于我的@WebFilter注解配置的是urlPatterns="/*"(过滤所有请求),所以这里对不需要过滤的静态资源url,作忽略处理(大家可以依照具体需求配置)
String[] exclusionsUrls = {".js",".gif",".jpg",".png",".bmp",".css",".ico"};//,"/","/index","/admin/root/"
for (String str : exclusionsUrls) {
//System.out.println(path.contains(str));
if (path.contains(str)) {
filterChain.doFilter(servletRequest,servletResponse);
return;
@@ -89,8 +89,6 @@ public class XssHttpServletRequestWrapper extends HttpServletRequestWrapper {
String line = "";
StringBuilder body = new StringBuilder();
int counter = 0;
// 读取POST提交的数据内容
BufferedReader reader = new BufferedReader(new InputStreamReader(stream, Charset.forName("UTF-8")));
try {
while ((line = reader.readLine()) != null) {
@@ -4,9 +4,14 @@ import cn.hellohao.config.SysName;
import cn.hellohao.pojo.*;
import cn.hellohao.pojo.vo.PageResultBean;
import cn.hellohao.service.*;
import cn.hellohao.service.impl.*;
import cn.hellohao.utils.*;
import cn.hellohao.service.impl.AlbumServiceImpl;
import cn.hellohao.service.impl.UserServiceImpl;
import cn.hellohao.service.impl.deleImages;
import cn.hellohao.utils.Base64Encryption;
import cn.hellohao.utils.SetFiles;
import cn.hellohao.utils.SetText;
import cn.hellohao.utils.progress.MyProgress;
import com.alibaba.fastjson.JSON;
import com.alibaba.fastjson.JSONArray;
import com.alibaba.fastjson.JSONObject;
import com.github.pagehelper.PageHelper;
@@ -15,11 +20,17 @@ import org.apache.shiro.SecurityUtils;
import org.apache.shiro.subject.Subject;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Controller;
import org.springframework.web.bind.annotation.*;
import javax.servlet.http.HttpSession;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RequestParam;
import org.springframework.web.bind.annotation.ResponseBody;
import java.text.ParseException;
import java.text.SimpleDateFormat;
import java.util.*;
import java.util.ArrayList;
import java.util.Date;
import java.util.List;
import java.util.UUID;
/**
* @author Hellohao
@@ -30,25 +41,16 @@ import java.util.*;
@RequestMapping("/admin")
public class AdminController {
@Autowired
private ImgService imgService;
@Autowired
private KeysService keysService;
@Autowired
private UserServiceImpl userService;
@Autowired
private ImgreviewService imgreviewService;
@Autowired
private UploadConfigService uploadConfigService;
@Autowired
private CodeService codeService;
@Autowired
private AlbumService albumService;
@Autowired
AlbumServiceImpl albumServiceI;
@Autowired
private deleImages deleimages;
@Autowired private ImgService imgService;
@Autowired private KeysService keysService;
@Autowired private UserServiceImpl userService;
@Autowired private ImgreviewService imgreviewService;
@Autowired private UploadConfigService uploadConfigService;
@Autowired private CodeService codeService;
@Autowired private AlbumService albumService;
@Autowired AlbumServiceImpl albumServiceI;
@Autowired private deleImages deleimages;
@Autowired private IRedisService iRedisService;
@PostMapping(value = "/overviewData")
@ResponseBody
@@ -56,7 +58,7 @@ public class AdminController {
Msg msg = new Msg();
Subject subject = SecurityUtils.getSubject();
User user = (User) subject.getPrincipal();
user = userService.getUsers(user);
user = userService.getUsers(user);
JSONObject jsonObject = new JSONObject();
UploadConfig uploadConfig = uploadConfigService.getUpdateConfig();
Imgreview imgreview = imgreviewService.selectByPrimaryKey(1);
@@ -66,45 +68,51 @@ public class AdminController {
jsonObject.put("myImgTotal", imgService.countimg(user.getId()));
jsonObject.put("myAlbumTitle", albumService.selectAlbumCount(user.getId()));
long memory = Long.valueOf(user.getMemory());
Long usermemory = imgService.getusermemory(user.getId())==null?0L:imgService.getusermemory(user.getId());
if(memory==0){
jsonObject.put("myMemory","无容量");
}else{
Double aDouble = Double.valueOf(String.format("%.2f", (((double)usermemory/(double)memory)*100)));
if(aDouble>=999){
jsonObject.put("myMemory",999);
}else{
jsonObject.put("myMemory",aDouble);
Long usermemory =
imgService.getusermemory(user.getId()) == null
? 0L
: imgService.getusermemory(user.getId());
if (memory == 0) {
jsonObject.put("myMemory", "无容量");
} else {
Double aDouble =
Double.valueOf(String.format("%.2f", (((double) usermemory / (double) memory) * 100)));
if (aDouble >= 999) {
jsonObject.put("myMemory", 999);
} else {
jsonObject.put("myMemory", aDouble);
}
}
jsonObject.put("myMemorySum",SetFiles.readableFileSize(memory));
if(user.getLevel()>1){
jsonObject.put("myMemorySum", SetFiles.readableFileSize(memory));
if (user.getLevel() > 1) {
ok = "true";
jsonObject.put("imgTotal", imgService.counts(null) );
jsonObject.put("imgTotal", imgService.counts(null));
jsonObject.put("userTotal", userService.getUserTotal());
jsonObject.put("ViolationImgTotal", imgreview.getCount());
jsonObject.put("ViolationSwitch", isImgreviewOK==null?0:isImgreviewOK.getId());
jsonObject.put("ViolationSwitch", isImgreviewOK == null ? 0 : isImgreviewOK.getId());
jsonObject.put("VisitorUpload", uploadConfig.getIsupdate());
jsonObject.put("VisitorMemory", SetFiles.readableFileSize(Long.valueOf(uploadConfig.getVisitormemory())));//访客共大小
if(uploadConfig.getIsupdate()!=1){
jsonObject.put(
"VisitorMemory",
SetFiles.readableFileSize(Long.valueOf(uploadConfig.getVisitormemory()))); // 访客共大小
if (uploadConfig.getIsupdate() != 1) {
jsonObject.put("VisitorUpload", 0);
jsonObject.put("VisitorProportion",100.00);
jsonObject.put("VisitorProportion", 100.00);
jsonObject.put("VisitorMemory", "禁用");
}else{
Long temp = imgService.getusermemory(0)==null?0:imgService.getusermemory(0);
} else {
Long temp = imgService.getusermemory(0) == null ? 0 : imgService.getusermemory(0);
jsonObject.put("UsedMemory", (temp == null ? 0 : SetFiles.readableFileSize(temp)));
if(Long.valueOf(uploadConfig.getVisitormemory())==0){
jsonObject.put("VisitorProportion",100.00);
}else if(Long.valueOf(uploadConfig.getVisitormemory())==-1){
jsonObject.put("VisitorProportion",0);
if (Long.valueOf(uploadConfig.getVisitormemory()) == 0) {
jsonObject.put("VisitorProportion", 100.00);
} else if (Long.valueOf(uploadConfig.getVisitormemory()) == -1) {
jsonObject.put("VisitorProportion", 0);
jsonObject.put("VisitorMemory", "无限");
}else{
} else {
double sum = Double.valueOf(uploadConfig.getVisitormemory());
Double aDouble = Double.valueOf(String.format("%.2f", ((double) temp / sum) * 100));
if(aDouble>=999){
jsonObject.put("VisitorProportion",999);
}else{
jsonObject.put("VisitorProportion",aDouble);
if (aDouble >= 999) {
jsonObject.put("VisitorProportion", 999);
} else {
jsonObject.put("VisitorProportion", aDouble);
}
}
}
@@ -117,55 +125,74 @@ public class AdminController {
@PostMapping(value = "/SpaceExpansion")
@ResponseBody
public Msg SpaceExpansion(@RequestParam(value = "data", defaultValue = "") String data) {
final Msg msg = new Msg();
final JSONObject jsonObject = JSONObject.parseObject(data);
Msg msg = new Msg();
JSONObject jsonObject = JSONObject.parseObject(data);
Subject subject = SecurityUtils.getSubject();
User user = (User) subject.getPrincipal();
user = userService.getUsers(user);
if(user.getIsok()==0){
user = userService.getUsers(user);
if (user.getIsok() == 0) {
msg.setCode("100403");
msg.setInfo("你暂时无法使用此功能");
return msg;
}
if(null==user){
if (null == user) {
msg.setCode("100405");
msg.setInfo("用户信息不存在");
return msg;
}else{
} else {
long sizes = 0;
Code code = codeService.selectCodekey(jsonObject.getString("code"));
if(null==code){
if (null == code) {
msg.setCode("100404");
msg.setInfo("扩容码不存在,请重新填写");
return msg;
}
Long userMemory = Long.valueOf(user.getMemory());
sizes = Long.valueOf(code.getValue())+ userMemory;
sizes = Long.valueOf(code.getValue()) + userMemory;
User newMemoryUser = new User();
newMemoryUser.setMemory(Long.toString(sizes));
newMemoryUser.setId(user.getId());
userService.usersetmemory(newMemoryUser,jsonObject.getString("code"));
msg.setInfo("你已成功扩容"+SetFiles.readableFileSize(sizes));
userService.usersetmemory(newMemoryUser, jsonObject.getString("code"));
msg.setInfo("你已成功扩容" + SetFiles.readableFileSize(sizes));
return msg;
}
}
@PostMapping(value = {"/setImgFileName", "/client/setImgFileName"})
@ResponseBody
public Msg setImgFileName(@RequestParam(value = "data", defaultValue = "") String data) {
Msg msg = new Msg();
try {
JSONObject jsonObject = JSONObject.parseObject(data);
String name = jsonObject.getString("name");
String imgname = jsonObject.getString("imgname");
Images images = new Images();
images.setIdname(name.replaceAll(" ", ""));
images.setImgname(imgname);
imgService.setImg(images);
} catch (Exception e) {
e.printStackTrace();
msg.setCode("500");
}
return msg;
}
@PostMapping("/getRecently")
@ResponseBody
public Msg getRecently() {
Msg msg = new Msg();
final JSONObject jsonObject = new JSONObject();
JSONObject jsonObject = new JSONObject();
try {
Subject subject = SecurityUtils.getSubject();
User user = (User) subject.getPrincipal();
user = userService.getUsers(user);
if(user.getLevel()>1){
jsonObject.put("RecentlyUser",imgService.RecentlyUser());
jsonObject.put("RecentlyUploaded",imgService.RecentlyUploaded(user.getId()));
}else{
jsonObject.put("RecentlyUploaded",imgService.RecentlyUploaded(user.getId()));
user = userService.getUsers(user);
if (user.getLevel() > 1) {
jsonObject.put("RecentlyUser", imgService.RecentlyUser());
jsonObject.put("RecentlyUploaded", imgService.RecentlyUploaded(user.getId()));
} else {
jsonObject.put("RecentlyUploaded", imgService.RecentlyUploaded(user.getId()));
}
}catch (Exception e){
} catch (Exception e) {
e.printStackTrace();
msg.setInfo("系统内部错误");
msg.setCode("500");
@@ -179,7 +206,7 @@ public class AdminController {
@ResponseBody
public Msg updateToken() {
Msg msg = new Msg();
try{
try {
Subject subject = SecurityUtils.getSubject();
User user = (User) subject.getPrincipal();
User u = new User();
@@ -189,63 +216,64 @@ public class AdminController {
user.setToken(u.getToken());
msg.setData(u.getToken());
msg.setInfo("Token更新成功,即可生效");
}catch (Exception e){
} catch (Exception e) {
e.printStackTrace();
msg.setCode("500");
msg.setInfo("Token更新失败");
}
return msg;
}
@PostMapping("/getYyyy")
@PostMapping("/getYyyy")
@ResponseBody
public Msg getYyyy(){
final Msg msg = new Msg();
public Msg getYyyy() {
Msg msg = new Msg();
Subject subject = SecurityUtils.getSubject();
User u = (User) subject.getPrincipal();
final JSONObject jsonObject = new JSONObject();
jsonObject.put("allYyyy",imgService.getyyyy(null));
jsonObject.put("userYyyy",imgService.getyyyy(u.getId()));
JSONObject jsonObject = new JSONObject();
jsonObject.put("allYyyy", imgService.getyyyy(null));
jsonObject.put("userYyyy", imgService.getyyyy(u.getId()));
msg.setData(jsonObject);
return msg;
}
@PostMapping("/getChart")
@PostMapping("/getChart")
@ResponseBody
public Msg getChart(@RequestParam(value = "data", defaultValue = "") String data){
public Msg getChart(@RequestParam(value = "data", defaultValue = "") String data) {
Msg msg = new Msg();
JSONObject jsonObject = JSONObject.parseObject(data);
String yyyy = jsonObject.getString("yyyy");
Integer type = jsonObject.getInteger("type");
Subject subject = SecurityUtils.getSubject();
User u = (User) subject.getPrincipal();
List<Images> list =null;
if(u.getLevel()>1){
if(type==2){
List<Images> list = null;
if (u.getLevel() > 1) {
if (type == 2) {
Images images = new Images();
images.setYyyy(yyyy);
list = imgService.countByM(images);
}else{
} else {
Images images = new Images();
images.setYyyy(yyyy);
images.setUserid(u.getId());
list = imgService.countByM(images);
}
}else{
} else {
Images images = new Images();
images.setYyyy(yyyy);
images.setUserid(u.getId());
list = imgService.countByM(images);
}
JSONArray json = JSONArray.parseArray("[{\"id\":1,\"monthNum\":\"一月\",\"countNum\":0},{\"id\":2,\"monthNum\":\"二月\",\"countNum\":0},{\"id\":3,\"monthNum\":\"三月\",\"countNum\":0},{\"id\":4,\"monthNum\":\"四月\",\"countNum\":0},{\"id\":5,\"monthNum\":\"五月\",\"countNum\":0},{\"id\":6,\"monthNum\":\"六月\",\"countNum\":0},{\"id\":7,\"monthNum\":\"七月\",\"countNum\":0},{\"id\":8,\"monthNum\":\"八月\",\"countNum\":0},{\"id\":9,\"monthNum\":\"九月\",\"countNum\":0},{\"id\":10,\"monthNum\":\"十月\",\"countNum\":0},{\"id\":11,\"monthNum\":\"十一月\",\"countNum\":0},{\"id\":12,\"monthNum\":\"十二月\",\"countNum\":0}]");
JSONArray json =
JSONArray.parseArray(
"[{\"id\":1,\"monthNum\":\"一月\",\"countNum\":0},{\"id\":2,\"monthNum\":\"二月\",\"countNum\":0},{\"id\":3,\"monthNum\":\"三月\",\"countNum\":0},{\"id\":4,\"monthNum\":\"四月\",\"countNum\":0},{\"id\":5,\"monthNum\":\"五月\",\"countNum\":0},{\"id\":6,\"monthNum\":\"六月\",\"countNum\":0},{\"id\":7,\"monthNum\":\"七月\",\"countNum\":0},{\"id\":8,\"monthNum\":\"八月\",\"countNum\":0},{\"id\":9,\"monthNum\":\"九月\",\"countNum\":0},{\"id\":10,\"monthNum\":\"十月\",\"countNum\":0},{\"id\":11,\"monthNum\":\"十一月\",\"countNum\":0},{\"id\":12,\"monthNum\":\"十二月\",\"countNum\":0}]");
JSONArray jsonArray = new JSONArray();
for (int j = 0; j < list.size(); j++) {
for (int i = 0; i < json.size(); i++) {
JSONObject jobj = json.getJSONObject(i);
if(jobj.getInteger("id")==list.get(j).getMonthNum()){
jobj.put("monthNum",getChinaes(list.get(j).getMonthNum()));
jobj.put("countNum",list.get(j).getCountNum());
if (jobj.getInteger("id") == list.get(j).getMonthNum()) {
jobj.put("monthNum", getChinaes(list.get(j).getMonthNum()));
jobj.put("countNum", list.get(j).getCountNum());
}
}
}
@@ -253,7 +281,7 @@ public class AdminController {
return msg;
}
@PostMapping("/getStorage")
@PostMapping("/getStorage")
@ResponseBody
public Msg getStorage() {
Msg msg = new Msg();
@@ -262,7 +290,7 @@ public class AdminController {
return msg;
}
@PostMapping("/getStorageName")
@PostMapping("/getStorageName")
@ResponseBody
public Msg getStorageName() {
Msg msg = new Msg();
@@ -271,7 +299,7 @@ public class AdminController {
return msg;
}
@PostMapping(value = {"/selectPhoto","/client/selectPhoto"})
@PostMapping(value = {"/selectPhoto", "/client/selectPhoto"})
@ResponseBody
public Msg selectPhoto(@RequestParam(value = "data", defaultValue = "") String data) {
Msg msg = new Msg();
@@ -283,18 +311,18 @@ public class AdminController {
Integer source = jsonObj.getInteger("source");
String starttime = jsonObj.getString("starttime");
String stoptime = jsonObj.getString("stoptime");
String selectUserType = jsonObj.getString("selectUserType");//me/all
String selectUserType = jsonObj.getString("selectUserType"); // me/all
String username = jsonObj.getString("username");
Integer selecttype = jsonObj.getInteger("selecttype");
boolean violation = jsonObj.getBoolean("violation");
SimpleDateFormat format = new SimpleDateFormat("yyyy-MM-dd HH:mm:ss");
if(starttime!=null){
if (starttime != null) {
try {
Date date1 = format.parse(starttime);
Date date2 = format.parse(stoptime==null?format.format(new Date()):stoptime);
Date date2 = format.parse(stoptime == null ? format.format(new Date()) : stoptime);
int compareTo = date1.compareTo(date2);
System.out.println(compareTo);
if(compareTo==1){
if (compareTo == 1) {
msg.setCode("110500");
msg.setInfo("起始日期不能大于结束日期");
return msg;
@@ -308,45 +336,45 @@ public class AdminController {
}
Images img = new Images();
PageHelper.startPage(pageNum, pageSize);
if(violation){
if (violation) {
img.setViolation("true");
}
img.setStarttime(starttime);
img.setStoptime(stoptime);
if(subject.hasRole("admin")){
if (subject.hasRole("admin")) {
img.setSource(source);
if(selectUserType.equals("me")){
if (selectUserType.equals("me")) {
img.setUserid(user.getId());
img.setUsername(null);
img.setSelecttype(null);
}else{
} else {
img.setUsername(username);
img.setSelecttype(selecttype);
}
}else{
//普通用户
} else {
img.setUserid(user.getId());
}
List<Images> images = imgService.selectimg(img);
PageInfo<Images> rolePageInfo = new PageInfo<>(images);
PageResultBean<Images> pageResultBean = new PageResultBean<>(rolePageInfo.getTotal(), rolePageInfo.getList());
PageResultBean<Images> pageResultBean =
new PageResultBean<>(rolePageInfo.getTotal(), rolePageInfo.getList());
msg.setData(pageResultBean);
return msg;
}
@PostMapping(value = "/getUserInfo")
@PostMapping(value = "/getUserInfo")
@ResponseBody
public Msg getUserInfo() {
Msg msg = new Msg();
try {
Subject subject = SecurityUtils.getSubject();
User user = (User) subject.getPrincipal();
final User u = new User();
User u = new User();
u.setId(user.getId());
User userInfo = userService.getUsers(u);
JSONObject jsonObject = new JSONObject();
jsonObject.put("username",userInfo.getUsername());
jsonObject.put("email",userInfo.getEmail());
jsonObject.put("username", userInfo.getUsername());
jsonObject.put("email", userInfo.getEmail());
msg.setData(jsonObject);
} catch (Exception e) {
e.printStackTrace();
@@ -356,7 +384,7 @@ public class AdminController {
return msg;
}
@PostMapping("/setUserInfo")
@PostMapping("/setUserInfo")
@ResponseBody
public Msg setUserInfo(@RequestParam(value = "data", defaultValue = "") String data) {
Msg msg = new Msg();
@@ -368,44 +396,44 @@ public class AdminController {
Subject subject = SecurityUtils.getSubject();
User u = (User) subject.getPrincipal();
User user = new User();
if(!SetText.checkEmail(email)){
if (!SetText.checkEmail(email)) {
msg.setCode("110403");
msg.setInfo("邮箱格式不正确");
return msg;
}
String regex = "^\\w+$";
if(username.length()>20 || !username.matches (regex)){
if (username.length() > 20 || !username.matches(regex)) {
msg.setCode("110403");
msg.setInfo("用户名不得超过20位字符");
return msg;
}
if(subject.hasRole("admin")){
final User userOld = new User();
if (subject.hasRole("admin")) {
User userOld = new User();
userOld.setId(u.getId());
User userInfo = userService.getUsers(userOld);
if(!userInfo.getUsername().equals(username)){
if (!userInfo.getUsername().equals(username)) {
Integer countusername = userService.countusername(username);
if(countusername == 1 || !SysName.CheckSysName(username)){
if (countusername == 1 || !SysName.CheckSysName(username)) {
msg.setCode("110406");
msg.setInfo("此用户名已存在");
return msg;
}else {
} else {
user.setUsername(username);
}
}
if(!userInfo.getEmail().equals(email)){
if (!userInfo.getEmail().equals(email)) {
Integer countmail = userService.countmail(email);
if(countmail == 1){
if (countmail == 1) {
msg.setCode("110407");
msg.setInfo("此邮箱已被注册");
return msg;
}else{
} else {
user.setEmail(email);
}
}
user.setPassword(Base64Encryption.encryptBASE64(password.getBytes()));
user.setUid(u.getUid());
}else{
} else {
user.setPassword(Base64Encryption.encryptBASE64(password.getBytes()));
user.setUid(u.getUid());
}
@@ -419,26 +447,27 @@ public class AdminController {
return msg;
}
@PostMapping({"/deleImages","/client/deleImages"})
@PostMapping({"/deleImages", "/client/deleImages"})
@ResponseBody
public Msg deleImages(HttpSession httpSession, @RequestParam(value = "data", defaultValue = "") String data) {
public Msg deleImages(@RequestParam(value = "data", defaultValue = "") String data) {
Msg msg = new Msg();
JSONObject jsonObj = JSONObject.parseObject(data);
final String images = jsonObj.getString("images");
if(images==null){
String images = jsonObj.getString("images");
String uuid = jsonObj.getString("uuid");
if (images == null) {
msg.setCode("404");
msg.setInfo("为获取到图像信息");
return msg;
}
final String[] split = images.split(",");
String[] split = images.split(",");
Subject subject = SecurityUtils.getSubject();
User user = (User) subject.getPrincipal();
if(null == user){
if (null == user) {
msg.setCode("500");
msg.setInfo("当前用户信息不存在");
return msg;
}
if(split.length==0){
if (split.length == 0) {
msg.setCode("404");
msg.setInfo("为获取到图像信息");
return msg;
@@ -447,94 +476,105 @@ public class AdminController {
for (int i = 0; i < split.length; i++) {
Integer imgid = Integer.valueOf(split[i]);
Images image = imgService.selectByPrimaryKey(imgid);
if(!subject.hasRole("admin")){
if(!image.getUserid().equals(user.getId())){
if (!subject.hasRole("admin")) {
if (!image.getUserid().equals(user.getId())) {
break;
}
}
imgIds.add(imgid);
}
if(imgIds.size()==0){
if (imgIds.size() == 0) {
msg.setCode("110404");
}else{
deleimages.dele(httpSession,imgIds.stream().toArray(Integer[]::new));
} else {
deleimages.dele(uuid, imgIds.stream().toArray(Integer[]::new));
msg.setCode("200");
}
return msg;
}
@PostMapping({"/GetDelprogress","/client/GetDelprogress"})
@PostMapping({"/GetDelprogress", "/client/GetDelprogress"})
@ResponseBody
public Msg GetDelprogress(HttpSession httpSession) {
Msg msg =new Msg();
JSONObject jsonObject = new JSONObject();
MyProgress myProgress = (MyProgress)httpSession.getAttribute("myProgressForDel");
if(null==myProgress){
jsonObject.put("succ",myProgress.getDelSuccessCount());
jsonObject.put("errorlist",new ArrayList<String>());
jsonObject.put("oklist",new ArrayList<Long>());
jsonObject.put("delover",false);
}else{
jsonObject.put("succ",myProgress.getDelSuccessCount());
jsonObject.put("errorlist",myProgress.getDelErrorImgListt());
jsonObject.put("oklist",myProgress.getDelSuccessImgList());
jsonObject.put("delover",myProgress.getDelOCT());
public Msg GetDelprogress(@RequestParam(value = "data", defaultValue = "") String data) {
Msg msg = new Msg();
try {
JSONObject jsonObj = JSONObject.parseObject(data);
String uuid = jsonObj.getString("uuid");
JSONObject jsonObject = new JSONObject();
MyProgress myProgress = null;
try{
myProgress = JSON.parseObject(iRedisService.getValue(uuid).toString(), MyProgress.class);
}catch (Exception e){ }
if (null == myProgress) {
jsonObject.put("succ", myProgress.getDelSuccessCount());
jsonObject.put("errorlist", new ArrayList<String>());
jsonObject.put("oklist", new ArrayList<Long>());
jsonObject.put("delover", false);
} else {
jsonObject.put("succ", myProgress.getDelSuccessCount());
jsonObject.put("errorlist", myProgress.getDelErrorImgListt());
jsonObject.put("oklist", myProgress.getDelSuccessImgList());
jsonObject.put("delover", myProgress.getDelOCT());
}
msg.setData(jsonObject);
if (myProgress.getDelOCT()==1) {
System.out.println("循环遍历的值:" + myProgress.getDelOCT());
msg.setCode("100");
} else {
msg.setCode("110666");
msg.setInfo("正在执行");
}
return msg;
} catch (Exception e) {
e.printStackTrace();
msg.setCode("110500");
msg.setInfo("正在执行过程中发生错误");
return msg;
}
msg.setData(jsonObject);
if(myProgress.getDelOCT()){
System.out.println("循环遍历的值:"+myProgress.getDelOCT());
msg.setCode("100");
}else{
msg.setCode("110666");
msg.setInfo("正在执行");
}
return msg;
}
//工具函数
private static String getChinaes(int v){
private static String getChinaes(int v) {
String ch = "";
switch(v){
case 1 :
switch (v) {
case 1:
ch = "一月";
break; //可选
case 2 :
break; // 可选
case 2:
ch = "二月";
break; //可选
case 3 :
break; // 可选
case 3:
ch = "三月";
break; //可选
case 4 :
break; // 可选
case 4:
ch = "四月";
break; //可选
case 5 :
break; // 可选
case 5:
ch = "五月";
break; //可选
case 6 :
break; // 可选
case 6:
ch = "六月";
break; //可选
case 7 :
break; // 可选
case 7:
ch = "七月";
break; //可选
case 8 :
break; // 可选
case 8:
ch = "八月";
break; //可选
case 9 :
break; // 可选
case 9:
ch = "九月";
break; //可选
case 10 :
break; // 可选
case 10:
ch = "十月";
break; //可选
case 11 :
break; // 可选
case 11:
ch = "十一月";
break; //可选
case 12 :
break; // 可选
case 12:
ch = "十二月";
break; //可选
default : ch = "";//可选
//语句
break; // 可选
default:
ch = ""; // 可选
// 语句
}
return ch;
}
}
@@ -313,9 +313,6 @@ public class AdminRootController {
if (!appClient.getIsuse().equals("on")) {
appClient.setIsuse("off");
}
if (!appClient.getAppupdate().equals("on")) {
appClient.setAppupdate("off");
}
appClientService.editAppClientData(appClient);
msg.setInfo("配置保存成功");
} catch (Exception e) {
@@ -1,18 +1,22 @@
package cn.hellohao.controller;
import cn.hellohao.auth.token.JWTUtil;
import cn.hellohao.pojo.AppClient;
import cn.hellohao.pojo.Msg;
import cn.hellohao.pojo.UploadConfig;
import cn.hellohao.pojo.User;
import cn.hellohao.service.AppClientService;
import cn.hellohao.service.ImgService;
import cn.hellohao.service.UploadConfigService;
import cn.hellohao.service.impl.UploadServicel;
import cn.hellohao.service.impl.UserServiceImpl;
import cn.hellohao.utils.Base64ToMultipartFile;
import com.alibaba.fastjson.JSONObject;
import org.apache.shiro.SecurityUtils;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;
import org.springframework.web.multipart.MultipartFile;
import javax.servlet.http.HttpServletRequest;
/**
* @author Hellohao
@@ -31,14 +35,16 @@ public class ClientAppController {
private UserServiceImpl userService;
@Autowired
private UploadConfigService uploadConfigService;
@Autowired
private UploadServicel uploadServicel;
@PostMapping("/loginByToken")
@ResponseBody
public Msg loginByToken(@RequestParam(value = "data", defaultValue = "") String data) {
Msg msg = new Msg();
JSONObject jsonObj = JSONObject.parseObject(data);
JSONObject jsonObject = new JSONObject();
try{
JSONObject jsonObj = JSONObject.parseObject(data);
JSONObject jsonObject = new JSONObject();
User newUser = new User();
String userToken = jsonObj.getString("userToken");
newUser.setToken(userToken);
@@ -79,22 +85,37 @@ public class ClientAppController {
return msg;
}
@PostMapping("/getVersion")
@ResponseBody
public Msg getVersion() {
@PostMapping("/imgUpload")
public Msg imgUpload(HttpServletRequest request, @RequestParam(required = true, value = "file") MultipartFile file,
@RequestParam(required = true, value = "days") String days) {
Msg msg = new Msg();
try {
AppClient app = appClientService.getAppClientData("app");
if(app.getAppupdate().equals("on")){
JSONObject jsonObject = new JSONObject();
jsonObject.put("winpackurl",app.getWinpackurl());
jsonObject.put("macpackurl",app.getMacpackurl());
msg.setData(jsonObject);
try{
if (null != file) {
msg = uploadServicel.uploadForLoc(request,file,Integer.valueOf(days),null);
}else{
msg.setCode("000");
msg.setCode("500");
}
}catch (Exception e){
msg.setCode("000");
e.printStackTrace();
msg.setCode("500");
}
return msg;
}
@PostMapping("/imgUploadForCopy")
public Msg imgUploadForCopy(@RequestParam(required = true, value = "data") String data, HttpServletRequest request) {
Msg msg = new Msg();
try{
JSONObject jsonObj = JSONObject.parseObject(data);
String imgstr = jsonObj.getString("imgstr");
Integer days = jsonObj.getInteger("days");
if (null != imgstr && !imgstr.isEmpty()) {
MultipartFile multipartFile = Base64ToMultipartFile.base64Convert(imgstr);
msg = uploadServicel.uploadForLoc(request, multipartFile, days, null);
}
}catch (Exception e){
e.printStackTrace();
msg.setCode("500");
}
return msg;
}
@@ -2,11 +2,9 @@ package cn.hellohao.controller;
import cn.hellohao.pojo.Msg;
import cn.hellohao.service.impl.ClientService;
import org.apache.commons.lang3.StringUtils;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.RequestParam;
import org.springframework.web.bind.annotation.ResponseBody;
import org.springframework.web.bind.annotation.RestController;
import org.springframework.web.bind.annotation.*;
import org.springframework.web.multipart.MultipartFile;
import javax.servlet.http.HttpServletRequest;
@@ -17,18 +15,30 @@ import javax.servlet.http.HttpServletRequest;
* @date 2019-07-18 17:22
*/
@RestController
@RequestMapping("/api")
public class ClientController {
@Autowired
private ClientService clientService;
@Autowired private ClientService clientService;
@PostMapping(value = "/uploadbymail")
@ResponseBody
public Msg uploadbymail(HttpServletRequest request, @RequestParam("file") MultipartFile file, String mail, String pass) {
Msg resultBean = clientService.uploadImg(request, file, mail, pass);
public Msg uploadbymail(
HttpServletRequest request,
@RequestParam(value = "file") MultipartFile file,
@RequestParam(value = "mail", defaultValue = "") String mail,
@RequestParam(value = "pass", defaultValue = "") String pass,
@RequestParam(value = "days", defaultValue = "0") String days) {
if (file == null
|| StringUtils.isBlank(mail)
|| StringUtils.isBlank(pass)) {
Msg msg = new Msg();
msg.setCode("400");
msg.setInfo("相关参数不能为空");
return msg;
}
Msg resultBean =
clientService.uploadImg(
request, file, mail, pass, Integer.valueOf(days.toString()));
return resultBean;
}
}
@@ -6,88 +6,93 @@ import cn.hellohao.service.*;
import cn.hellohao.service.impl.AlbumServiceImpl;
import cn.hellohao.service.impl.UploadServicel;
import cn.hellohao.service.impl.deleImages;
import cn.hellohao.utils.verifyCode.IVerifyCodeGen;
import cn.hellohao.utils.verifyCode.SimpleCharVerifyCodeGenImpl;
import cn.hellohao.utils.GetIPS;
import cn.hellohao.utils.MyVersion;
import cn.hutool.captcha.CaptchaUtil;
import cn.hutool.captcha.ShearCaptcha;
import cn.hutool.captcha.generator.MathGenerator;
import com.alibaba.fastjson.JSONArray;
import com.alibaba.fastjson.JSONObject;
import org.apache.commons.lang3.StringUtils;
import org.apache.shiro.SecurityUtils;
import org.apache.shiro.authc.UsernamePasswordToken;
import org.apache.shiro.subject.Subject;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Controller;
import org.springframework.web.bind.annotation.*;
import org.springframework.ui.Model;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RequestParam;
import org.springframework.web.bind.annotation.ResponseBody;
import org.springframework.web.multipart.MultipartFile;
import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;
import javax.servlet.http.HttpSession;
import java.io.IOException;
import java.util.List;
import java.util.Timer;
import java.util.TimerTask;
import java.util.UUID;
@Controller
public class IndexController {
@Autowired
private ImgService imgService;
@Autowired
private SysConfigService sysConfigService;
@Autowired
private ConfigService configService;
@Autowired
private UploadConfigService uploadConfigService;
@Autowired
private UploadServicel uploadServicel;
@Autowired
private deleImages deleimages;
@Autowired
AlbumServiceImpl albumService;
@Autowired
AppClientService appClientService;
@Autowired private ImgService imgService;
@Autowired private SysConfigService sysConfigService;
@Autowired private ConfigService configService;
@Autowired private UploadConfigService uploadConfigService;
@Autowired private UploadServicel uploadServicel;
@Autowired private deleImages deleimages;
@Autowired private IRedisService iRedisService;
@Autowired private AlbumServiceImpl albumService;
@Autowired private AppClientService appClientService;
@RequestMapping(value = "/")
public String Welcome(Model model, HttpServletRequest httpServletRequest) {
model.addAttribute("name", "服务端程序");
model.addAttribute("version", "20221027");
model.addAttribute("ip", GetIPS.getIpAddr(httpServletRequest));
model.addAttribute("links", "tbed.hellohao.cn");
return "welcome";
}
@RequestMapping(value = "/webInfo")
@ResponseBody
public Msg webInfo() {
final Msg msg = new Msg();
Msg msg = new Msg();
Config config = configService.getSourceype();
UploadConfig updateConfig = uploadConfigService.getUpdateConfig();
SysConfig sysConfig = sysConfigService.getstate();
JSONObject jsonObject = new JSONObject();
AppClient appClient = appClientService.getAppClientData("app");
jsonObject.put("webname",config.getWebname());
jsonObject.put("websubtitle",config.getWebsubtitle());
jsonObject.put("keywords",config.getWebkeywords());
jsonObject.put("description",config.getWebms());
jsonObject.put("explain",config.getExplain());
jsonObject.put("favicon",config.getWebfavicons());
jsonObject.put("baidu",config.getBaidu());
jsonObject.put("links",config.getLinks());
jsonObject.put("aboutinfo",config.getAboutinfo());
jsonObject.put("logo",config.getLogo());
jsonObject.put("api",updateConfig.getApi());
jsonObject.put("register",sysConfig.getRegister());
jsonObject.put("isuse",appClient.getIsuse());
// jsonObject.put("packurl",appClient.getPackurl());
jsonObject.put("clientname",appClient.getAppname());
jsonObject.put("clientlogo",appClient.getApplogo());
jsonObject.put("appupdate",appClient.getAppupdate());
jsonObject.put("webname", config.getWebname());
jsonObject.put("websubtitle", config.getWebsubtitle());
jsonObject.put("keywords", config.getWebkeywords());
jsonObject.put("description", config.getWebms());
jsonObject.put("explain", config.getExplain());
jsonObject.put("favicon", config.getWebfavicons());
jsonObject.put("baidu", config.getBaidu());
jsonObject.put("links", config.getLinks());
jsonObject.put("aboutinfo", config.getAboutinfo());
jsonObject.put("logo", config.getLogo());
jsonObject.put("api", updateConfig.getApi());
jsonObject.put("register", sysConfig.getRegister());
jsonObject.put("isuse", appClient.getIsuse());
jsonObject.put("clientname", appClient.getAppname());
jsonObject.put("clientlogo", appClient.getApplogo());
jsonObject.put("appupdate", appClient.getAppupdate());
msg.setData(jsonObject);
return msg;
}
@PostMapping(value = {"/upload","/client/upload"})// new
@PostMapping(value = {"/upload", "/client/upload"})
@ResponseBody
public Msg upimg(HttpServletRequest request, @RequestParam(value = "file", required = false) MultipartFile multipartFile,Integer day) {
return uploadServicel.uploadForLoc(request,multipartFile,day,null);
public Msg upimg(
HttpServletRequest request,
@RequestParam(value = "file", required = false) MultipartFile multipartFile,
Integer day) {
return uploadServicel.uploadForLoc(request, multipartFile, day, null);
}
@PostMapping(value = {"/uploadForUrl","/client/uploadForUrl"}) //new
@PostMapping(value = {"/uploadForUrl", "/client/uploadForUrl"})
@ResponseBody
public Msg upurlimg(HttpServletRequest request,@RequestParam(value = "data", defaultValue = "") String data) {
public Msg upurlimg(
HttpServletRequest request, @RequestParam(value = "data", defaultValue = "") String data) {
JSONObject jsonObj = JSONObject.parseObject(data);
Integer setday = jsonObj.getInteger("day");
String imgUrl = jsonObj.getString("imgUrl");
@@ -97,9 +102,9 @@ public class IndexController {
User user = (User) subject.getPrincipal();
UploadConfig updateConfig = uploadConfigService.getUpdateConfig();
int syscounts = 0;
if(null==user){
if (null == user) {
syscounts = updateConfig.getImgcounttourists();
}else{
} else {
syscounts = updateConfig.getImgcountuser();
}
Msg retMsg = new Msg();
@@ -108,27 +113,27 @@ public class IndexController {
int errcounts = 0;
int excess = 0;
for (int i = 0; i < URLArr.length; i++) {
int temp = i+1;
if(syscounts>=temp){
int temp = i + 1;
if (syscounts >= temp) {
Msg msg = uploadServicel.uploadForLoc(request, null, setday, URLArr[i]);
if(!msg.getCode().equals("200")){
if (!msg.getCode().equals("200")) {
errcounts++;
}else{
} else {
retArray.add(msg);
}
}else{
} else {
excess++;
}
}
jsonObject.put("counts",URLArr.length);
jsonObject.put("errcounts",errcounts);
jsonObject.put("excess",excess);
jsonObject.put("urls",retArray);
jsonObject.put("counts", URLArr.length);
jsonObject.put("errcounts", errcounts);
jsonObject.put("excess", excess);
jsonObject.put("urls", retArray);
retMsg.setData(jsonObject);
return retMsg;
}
@RequestMapping(value = "/getUploadInfo")//new
@RequestMapping(value = "/getUploadInfo")
@ResponseBody
public Msg getUploadInfo() {
Msg msg = new Msg();
@@ -137,19 +142,19 @@ public class IndexController {
User user = (User) subject.getPrincipal();
try {
UploadConfig updateConfig = uploadConfigService.getUpdateConfig();
jsonObject.put("suffix",updateConfig.getSuffix().split(","));
if(null==user){
jsonObject.put("filesize",Integer.valueOf(updateConfig.getFilesizetourists())/1024);
jsonObject.put("imgcount",updateConfig.getImgcounttourists());
jsonObject.put("uploadSwitch",updateConfig.getIsupdate());
jsonObject.put("uploadInfo","您登陆后才能使用此功能哦");
}else{
jsonObject.put("filesize",Integer.valueOf(updateConfig.getFilesizeuser())/1024);
jsonObject.put("imgcount",updateConfig.getImgcountuser());
jsonObject.put("uploadSwitch",updateConfig.getUserclose());
jsonObject.put("uploadInfo","系统暂时关闭了用户上传功能");
jsonObject.put("suffix", updateConfig.getSuffix().split(","));
if (null == user) {
jsonObject.put("filesize", Integer.valueOf(updateConfig.getFilesizetourists()) / 1024);
jsonObject.put("imgcount", updateConfig.getImgcounttourists());
jsonObject.put("uploadSwitch", updateConfig.getIsupdate());
jsonObject.put("uploadInfo", "您登陆后才能使用此功能哦");
} else {
jsonObject.put("filesize", Integer.valueOf(updateConfig.getFilesizeuser()) / 1024);
jsonObject.put("imgcount", updateConfig.getImgcountuser());
jsonObject.put("uploadSwitch", updateConfig.getUserclose());
jsonObject.put("uploadInfo", "系统暂时关闭了用户上传功能");
}
}catch (Exception e){
} catch (Exception e) {
e.printStackTrace();
}
msg.setData(jsonObject);
@@ -161,19 +166,21 @@ public class IndexController {
public Msg checkStatus(HttpServletRequest request) {
Msg msg = new Msg();
String token = request.getHeader("Authorization");
if(token != null) {
if (token != null) {
JSONObject tokenJson = JWTUtil.checkToken(token);
if(tokenJson.getBoolean("check")){
if (tokenJson.getBoolean("check")) {
Subject subject = SecurityUtils.getSubject();
UsernamePasswordToken tokenOBJ = new UsernamePasswordToken(tokenJson.getString("email"),tokenJson.getString("password"));
UsernamePasswordToken tokenOBJ =
new UsernamePasswordToken(
tokenJson.getString("email"), tokenJson.getString("password"));
tokenOBJ.setRememberMe(true);
try {
subject.login(tokenOBJ);
SecurityUtils.getSubject().getSession().setTimeout(3600000);
User u = (User) subject.getPrincipal();
final JSONObject jsonObject = new JSONObject();
jsonObject.put("RoleLevel",u.getLevel()==2?"admin":"user");
jsonObject.put("userName",u.getUsername());
JSONObject jsonObject = new JSONObject();
jsonObject.put("RoleLevel", u.getLevel() == 2 ? "admin" : "user");
jsonObject.put("userName", u.getUsername());
msg.setCode("200");
msg.setData(jsonObject);
} catch (Exception e) {
@@ -182,131 +189,160 @@ public class IndexController {
System.err.println("登录失效,请重新登录");
e.printStackTrace();
}
}else{
} else {
msg.setCode("40041");
msg.setInfo("登录失效,请重新登录");
}
}else{
} else {
msg.setCode("40040");
msg.setInfo("当前未登录,请先登录");
}
return msg;
}
@GetMapping("/verifyCode")
public void verifyCode(HttpServletRequest request, HttpServletResponse response,HttpSession httpSession) {
IVerifyCodeGen iVerifyCodeGen = new SimpleCharVerifyCodeGenImpl();
@PostMapping("/verifyCode")
@ResponseBody
public Msg verifyCode() {
Msg msg = new Msg();
try {
ShearCaptcha captcha = CaptchaUtil.createShearCaptcha(90, 35, 2, 2);
captcha.setGenerator(new MathGenerator(1));
httpSession.setAttribute("_hellohao_verifyCode",captcha);
response.setHeader("Pragma", "no-cache");
response.setHeader("Cache-Control", "no-cache");
response.setDateHeader("Expires", 0);
response.setContentType("image/jpeg");
captcha.write(response.getOutputStream());
final Timer timer=new Timer();
timer.schedule(new TimerTask() {
@Override
public void run() {
httpSession.removeAttribute("_hellohao_verifyCode");
timer.cancel();
}
},5*60*1000);
response.getOutputStream().flush();
} catch (IOException e) {
String code = getVerifyCodeOperator(captcha.getCode());
String uid = UUID.randomUUID().toString().replace("-", "").toLowerCase();
iRedisService.setValue("verifyCode_" + 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;
}
}
@GetMapping("/verifyCodeForRegister")
public void verifyCodeForRegister(HttpServletRequest request, HttpServletResponse response,HttpSession httpSession) {
IVerifyCodeGen iVerifyCodeGen = new SimpleCharVerifyCodeGenImpl();
@PostMapping("/verifyCodeForRegister")
@ResponseBody
public Msg verifyCodeForRegister() {
Msg msg = new Msg();
try {
ShearCaptcha captcha = CaptchaUtil.createShearCaptcha(90, 35, 2, 2);
httpSession.setAttribute("_hellohao_verifyCodeForRegister",captcha);
response.setHeader("Pragma", "no-cache");
response.setHeader("Cache-Control", "no-cache");
response.setDateHeader("Expires", 0);
response.setContentType("image/jpeg");
captcha.write(response.getOutputStream());
final Timer timer=new Timer();
timer.schedule(new TimerTask() {
@Override
public void run() {
httpSession.removeAttribute("_hellohao_verifyCodeForRegister");
timer.cancel();
}
},5*60*1000);
response.getOutputStream().flush();
} catch (IOException e) {
captcha.setGenerator(new MathGenerator(1));
String code = getVerifyCodeOperator(captcha.getCode());
String uid = UUID.randomUUID().toString().replace("-", "").toLowerCase();
iRedisService.setValue("verifyCodeForRegister_" + 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;
}
}
@GetMapping("/verifyCodeForRetrieve")
public void verifyCodeForRetrieve(HttpServletRequest request, HttpServletResponse response,HttpSession httpSession) {
IVerifyCodeGen iVerifyCodeGen = new SimpleCharVerifyCodeGenImpl();
@PostMapping("/verifyCodeForRetrieve")
@ResponseBody
public Msg verifyCodeForRetrieve() {
Msg msg = new Msg();
try {
ShearCaptcha captcha = CaptchaUtil.createShearCaptcha(90, 35, 2, 2);
httpSession.setAttribute("_hellohao_verifyCodeForEmailRetrieve",captcha);
response.setHeader("Pragma", "no-cache");
response.setHeader("Cache-Control", "no-cache");
response.setDateHeader("Expires", 0);
response.setContentType("image/jpeg");
captcha.write(response.getOutputStream());
final Timer timer=new Timer();
timer.schedule(new TimerTask() {
@Override
public void run() {
httpSession.removeAttribute("_hellohao_verifyCodeForEmailRetrieve");
timer.cancel();
}
},5*60*1000);
response.getOutputStream().flush();
} catch (IOException e) {
captcha.setGenerator(new MathGenerator(1));
String code = getVerifyCodeOperator(captcha.getCode());
String uid = UUID.randomUUID().toString().replace("-", "").toLowerCase();
iRedisService.setValue("verifyCodeForRetrieve_" + 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;
}
}
@PostMapping({"/deleImagesByUid","/client/deleImagesByUid"}) //new
public static String getVerifyCodeOperator(String str) {
int a = Integer.valueOf(str.substring(0, 1));
String yxf = str.substring(1, 2);
int b = Integer.valueOf(str.substring(2, 3));
switch (yxf) {
case "*":
return Integer.toString(a * b);
case "+":
return Integer.toString(a + b);
case ",":
default:
return Integer.toString(82);
case "-":
return Integer.toString(a - b);
}
}
@PostMapping({"/deleImagesByUid", "/client/deleImagesByUid"})
@ResponseBody
public Msg deleImagesByUid(@RequestParam(value = "data", defaultValue = "") String data) {
Msg msg = new Msg();
JSONObject jsonObj = JSONObject.parseObject(data);
String imguid = jsonObj.getString("imguid");
Images image = imgService.selectImgUrlByImgUID(imguid);
if(null==image){
if (null == image) {
msg.setInfo("图像已不存在,删除成功");
return msg;
}
//判断是不是自己的图片 因为这里的删除功能只能是首页上传后才会调用的接口 能删除的图片只能是自己的
Subject subject = SecurityUtils.getSubject();
User user = (User) subject.getPrincipal();
if(null!=user){
//由于integer类型的==比较方式适用于-128~127之间,所以超过这个范围就会不对
// if(user.getId()!=image.getUserid()){
if(!user.getId().equals(image.getUserid())){
if (null != user) {
if (!user.getId().equals(image.getUserid())) {
msg.setInfo("删除失败,该图片不允许你执行操作");
msg.setCode("100403");
return msg;
}
}
msg = deleimages.dele(null,image.getId());
List<Long> Delids = (List<Long>)msg.getData();
if(!Delids.contains(image.getId())){
msg = deleimages.dele(null, image.getId());
List<Long> Delids = (List<Long>) msg.getData();
if (!Delids.contains(image.getId())) {
msg.setCode("500");
msg.setInfo("图像删除失败");
}else{
} else {
msg.setCode("200");
msg.setInfo("图像已成功删除");
}
return msg;
}
@PostMapping("/getClientVersion")
@ResponseBody
public Msg getClientVersion(@RequestParam(value = "data", defaultValue = "") String data) {
Msg msg = new Msg();
msg.setCode("000");
try {
JSONObject jsonObj = JSONObject.parseObject(data);
String appv = jsonObj.getString("version");
AppClient app = appClientService.getAppClientData("app");
if (!StringUtils.isBlank(app.getAppupdate())) {
String version = app.getAppupdate().replaceAll("\\.", "");
if (MyVersion.compareVersion(app.getAppupdate(), appv) == 1) {
JSONObject jsonObject = new JSONObject();
jsonObject.put("winpackurl", app.getWinpackurl());
jsonObject.put("macpackurl", app.getMacpackurl());
msg.setCode("200");
msg.setData(jsonObject);
}
}
} catch (Exception e) {
msg.setCode("000");
}
return msg;
}
@RequestMapping("/authError")
@ResponseBody
public Msg authError(HttpServletRequest request){
public Msg authError(HttpServletRequest request) {
Msg msg = new Msg();
msg.setCode("4031");
msg.setInfo("You don't have authority");
@@ -315,13 +351,10 @@ public class IndexController {
@RequestMapping("/jurisError")
@ResponseBody
public Msg jurisError(HttpServletRequest request){
public Msg jurisError(HttpServletRequest request) {
Msg msg = new Msg();
msg.setCode("4031");
msg.setInfo("Authentication request failed");
return msg;
}
}
@@ -13,6 +13,8 @@ public interface ImgMapper {
List<Images> selectimg(Images images);
Integer insertImgData(Images images);
Integer countimg(@Param("userid") Integer userid);
Integer deleimg(@Param("id") Integer id);
@@ -1,11 +1,9 @@
package cn.hellohao.dao;
import cn.hellohao.pojo.User;
import org.apache.ibatis.annotations.Mapper;
import org.apache.ibatis.annotations.Param;
import cn.hellohao.pojo.Images;
import cn.hellohao.pojo.User;
import java.util.List;
@Mapper
@@ -14,7 +12,6 @@ public interface UserMapper {
Integer login(@Param("email") String email, @Param("password") String password,@Param("uid") String uid);
User getUsers(User user);
User loginByToken (@Param("token") String token);
Integer insertimg(Images img);
Integer change(User user);
Integer changeUser(User user);
Integer checkUsername(@Param("username") String username);
@@ -10,6 +10,7 @@ public class AppClient {
private String applogo;
private String appupdate;
public AppClient(){}
public AppClient(String id, String isuse, String winpackurl, String macpackurl, String appname, String applogo, String appupdate) {
+22 -1
View File
@@ -35,6 +35,8 @@ public class Images {
private String yyyy;
private String[] classifuidlist; //类别uid集合
private String classificationuid; //类别uid集合
private String idname;
private Integer isRepeat;//如果没有开启查重的时候他是0,开启为1
public Images() {
super();
@@ -54,7 +56,8 @@ public class Images {
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 format,String about,Integer great,String[] classifuidlist,String classificationuid,String violation,
String idname,Integer isRepeat) {
this.id = id;
this.imgname = imgname;
this.imgurl = imgurl;
@@ -85,6 +88,8 @@ public class Images {
this.classifuidlist = classifuidlist;
this.classificationuid = classificationuid;
this.violation = violation;
this.idname = idname;
this.isRepeat = isRepeat;
}
@@ -328,6 +333,22 @@ public class Images {
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;
}
}
@@ -4,14 +4,16 @@ import java.util.Map;
public interface IRedisService {
// 加入元素
void setValue(String key, Map<String, Object> value);
// 加入元素
void setValue(String key, String value);
// 加入元素
void setValue(String key, Object value);
// 获取元素
Object getMapValue(String key);
// 获取元素
Object getValue(String key);
}
// 加入元素
void setValue(String key, Map<String, Object> value);
// 加入元素
void setValue(String key, String value);
// 加入元素
void setTimeValue(String key, Object value,Long time);
// 获取元素
Object getMapValue(String key);
// 获取元素
Object getValue(String key);
// 删除某个值
Boolean removeValue(String key);
}
@@ -13,6 +13,8 @@ import org.springframework.stereotype.Service;
public interface ImgService {
List<Images> selectimg(Images images);
Integer insertImgData(Images images);
Integer deleimg(Integer id);
Integer deleimgForImgUid(String imguid);
@@ -1,6 +1,5 @@
package cn.hellohao.service;
import cn.hellohao.pojo.Images;
import cn.hellohao.pojo.User;
import org.springframework.stereotype.Service;
@@ -16,8 +15,6 @@ public interface UserService {
User getUsers(User user);
Integer insertimg(Images img);
Integer change(User user);
Integer changeUser(User user);
@@ -8,16 +8,13 @@ import cn.hellohao.exception.CodeException;
import cn.hellohao.pojo.Album;
import cn.hellohao.pojo.Images;
import cn.hellohao.pojo.ImgAndAlbum;
import cn.hellohao.pojo.Msg;
import cn.hellohao.service.AlbumService;
import com.alibaba.fastjson.JSONArray;
import com.alibaba.fastjson.JSONObject;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;
import org.springframework.transaction.annotation.Transactional;
import java.util.List;
import java.util.UUID;
/**
* @author Hellohao
@@ -26,92 +23,86 @@ import java.util.UUID;
*/
@Service
public class AlbumServiceImpl implements AlbumService {
@Autowired
AlbumMapper albumMapper;
@Autowired
ImgAndAlbumMapper andAlbumMapper;
@Autowired
ConfigMapper configMapper;
@Autowired
ImgMapper imgMapper;
@Autowired AlbumMapper albumMapper;
@Autowired ImgAndAlbumMapper andAlbumMapper;
@Autowired ConfigMapper configMapper;
@Autowired ImgMapper imgMapper;
@Override
public JSONArray getAlbumList(JSONArray array) {
JSONArray jsonArray = new JSONArray();
for (int i = 0; i < array.size(); i++) {
Images images = new Images();
images.setImguid(array.getString(i));
jsonArray.add(imgMapper.selectimg(images).get(0));
}
return jsonArray;
@Override
public JSONArray getAlbumList(JSONArray array) {
JSONArray jsonArray = new JSONArray();
for (int i = 0; i < array.size(); i++) {
Images images = new Images();
images.setImguid(array.getString(i));
jsonArray.add(imgMapper.selectimg(images).get(0));
}
return jsonArray;
}
@Override
public Album selectAlbum(Album album) {
return albumMapper.selectAlbum(album);
@Override
public Album selectAlbum(Album album) {
return albumMapper.selectAlbum(album);
}
@Override
public Integer addAlbum(Album album) {
return albumMapper.addAlbum(album);
}
@Transactional
public Integer addAlbumForImgAndAlbumMapper(ImgAndAlbum imgAndAlbum) {
Integer tem = 0;
Integer r2 = andAlbumMapper.addImgAndAlbum(imgAndAlbum);
if (r2 > 0) {
tem = 1;
} else {
throw new CodeException("插入画廊数据失败,回滚");
}
return tem;
}
@Override
public Integer addAlbum(Album album) {
return albumMapper.addAlbum(album);
@Override
public Integer deleteAlbum(String albumkey) {
return albumMapper.deleteAlbum(albumkey);
}
@Override
public List<Album> selectAlbumURLList(Album album) {
return albumMapper.selectAlbumURLList(album);
}
@Override
public Integer selectAlbumCount(Integer userid) {
return albumMapper.selectAlbumCount(userid);
}
@Override
public Integer updateAlbum(Album album) {
return albumMapper.updateAlbum(album);
}
@Transactional
public Integer delete(String albumkey) {
Integer ret1 = albumMapper.deleteAlbum(albumkey);
if (ret1 > 0) {
ret1 = andAlbumMapper.deleteImgAndAlbumForKey(albumkey);
} else {
throw new CodeException("删除画廊失败。");
}
return ret1;
}
@Transactional
public Integer addAlbumForImgAndAlbumMapper(ImgAndAlbum imgAndAlbum) {
Integer tem = 0;
Integer r2 = andAlbumMapper.addImgAndAlbum(imgAndAlbum);
if(r2>0){
tem = 1;
}else{
throw new CodeException("插入画廊数据失败,回滚");
}
return tem;
@Transactional
public Integer deleteAll(String[] albumkeyArr) {
Integer ret1 = 0;
for (String s : albumkeyArr) {
ret1 = albumMapper.deleteAlbum(s);
if (ret1 > 0) {
ret1 = andAlbumMapper.deleteImgAndAlbumForKey(s);
} else {
throw new CodeException("删除画廊失败。");
}
}
@Override
public Integer deleteAlbum(String albumkey) {
return albumMapper.deleteAlbum(albumkey);
}
@Override
public List<Album> selectAlbumURLList(Album album) {
return albumMapper.selectAlbumURLList(album);
}
@Override
public Integer selectAlbumCount(Integer userid) {
return albumMapper.selectAlbumCount(userid);
}
@Override
public Integer updateAlbum(Album album) {
return albumMapper.updateAlbum(album);
}
@Transactional
public Integer delete(String albumkey) {
Integer ret1 = albumMapper.deleteAlbum(albumkey);
if(ret1>0){
ret1 = andAlbumMapper.deleteImgAndAlbumForKey(albumkey);
}else{
throw new CodeException("删除画廊失败。");
}
return ret1;
}
@Transactional
public Integer deleteAll(String[] albumkeyArr) {
Integer ret1 = 0 ;
for (String s : albumkeyArr) {
ret1 = albumMapper.deleteAlbum(s);
if(ret1>0){
ret1 = andAlbumMapper.deleteImgAndAlbumForKey(s);
}else{
throw new CodeException("删除画廊失败。");
}
}
return ret1;
}
return ret1;
}
}
@@ -3,42 +3,43 @@ package cn.hellohao.service.impl;
import cn.hellohao.pojo.Images;
import cn.hellohao.pojo.Keys;
import cn.hellohao.pojo.ReturnImage;
import cn.hellohao.utils.*;
import com.qcloud.cos.COSClient;
import com.qcloud.cos.ClientConfig;
import com.qcloud.cos.auth.BasicCOSCredentials;
import com.qcloud.cos.auth.COSCredentials;
import com.qcloud.cos.exception.CosClientException;
import com.qcloud.cos.exception.CosServiceException;
import com.qcloud.cos.model.*;
import com.qcloud.cos.model.ListObjectsRequest;
import com.qcloud.cos.model.ObjectListing;
import com.qcloud.cos.model.PutObjectRequest;
import com.qcloud.cos.model.PutObjectResult;
import com.qcloud.cos.region.Region;
import org.apache.commons.lang3.StringUtils;
import org.springframework.stereotype.Service;
import java.io.File;
import java.util.*;
import java.util.Map;
@Service
public class COSImageupload {
static COSClient cosClient;
static Keys key;
public ReturnImage ImageuploadCOS(Map<String, File> fileMap, String username,Integer keyID) {
public ReturnImage ImageuploadCOS(
Map<Map<String, String>, File> fileMap, String username, Integer keyID) {
ReturnImage returnImage = new ReturnImage();
File file = null;
Map<ReturnImage, Integer> ImgUrl = new HashMap<>();
try {
for (Map.Entry<String, File> entry : fileMap.entrySet()) {
String ShortUID = SetText.getShortUuid();
for (Map.Entry<Map<String, String>, File> entry : fileMap.entrySet()) {
String prefix = entry.getKey().get("prefix");
String ShortUIDName = entry.getKey().get("name");
file = entry.getValue();
try {
String bucketName = key.getBucketname();
String userkey =username + "/" + ShortUID + "." + entry.getKey();
PutObjectRequest putObjectRequest = new PutObjectRequest(bucketName, userkey, file);
String userkey = username + "/" + ShortUIDName + "." + prefix;
PutObjectRequest putObjectRequest =
new PutObjectRequest(bucketName, userkey, file);
PutObjectResult putObjectResult = cosClient.putObject(putObjectRequest);
returnImage.setImgname(userkey);
returnImage.setImgurl(key.getRequestAddress() + "/" + userkey);
returnImage.setImgSize(entry.getValue().length());
returnImage.setCode("200");
} catch (CosServiceException serverException) {
returnImage.setCode("400");
serverException.printStackTrace();
@@ -47,41 +48,42 @@ public class COSImageupload {
clientException.printStackTrace();
}
}
}catch(Exception e){
returnImage.setCode("200");
} catch (Exception e) {
e.printStackTrace();
returnImage.setCode("500");
}
return returnImage;
}
public static Integer Initialize(Keys k) {
int ret = -1;
if(k.getEndpoint()!=null && k.getAccessSecret()!=null && k.getEndpoint()!=null
&& k.getBucketname()!=null && k.getRequestAddress()!=null ) {
if (!k.getEndpoint().equals("") && !k.getAccessSecret().equals("") && !k.getEndpoint().equals("")
&& !k.getBucketname().equals("") && !k.getRequestAddress().equals("")) {
String secretId = k.getAccessKey();
String secretKey = k.getAccessSecret();
COSCredentials cred = new BasicCOSCredentials(secretId, secretKey);
Region region = new Region(k.getEndpoint());
ClientConfig clientConfig = new ClientConfig(region);
COSClient cos = new COSClient(cred, clientConfig);
ListObjectsRequest listObjectsRequest = new ListObjectsRequest();
listObjectsRequest.setBucketName(k.getBucketname());
listObjectsRequest.setDelimiter("/");
listObjectsRequest.setMaxKeys(1);
ObjectListing objectListing = null;
try {
objectListing = cos.listObjects(listObjectsRequest);
ret = 1;
cosClient = cos;
key = k;
} catch (Exception e) {
System.out.println("COS Object Is null");
ret = -1;
}
}
if (StringUtils.isBlank(k.getAccessKey())
|| StringUtils.isBlank(k.getAccessSecret())
|| StringUtils.isBlank(k.getEndpoint())
|| StringUtils.isBlank(k.getBucketname())
|| StringUtils.isBlank(k.getRequestAddress())) {
return -1;
}
String secretId = k.getAccessKey();
String secretKey = k.getAccessSecret();
COSCredentials cred = new BasicCOSCredentials(secretId, secretKey);
Region region = new Region(k.getEndpoint());
ClientConfig clientConfig = new ClientConfig(region);
COSClient cos = new COSClient(cred, clientConfig);
ListObjectsRequest listObjectsRequest = new ListObjectsRequest();
listObjectsRequest.setBucketName(k.getBucketname());
listObjectsRequest.setDelimiter("/");
listObjectsRequest.setMaxKeys(1);
ObjectListing objectListing = null;
try {
objectListing = cos.listObjects(listObjectsRequest);
ret = 1;
cosClient = cos;
key = k;
} catch (Exception e) {
System.out.println("COS Object Is null");
ret = -1;
}
return ret;
}
@@ -94,10 +96,6 @@ public class COSImageupload {
e.printStackTrace();
b = false;
}
return b ;
return b;
}
}
@@ -2,6 +2,7 @@ package cn.hellohao.service.impl;
import cn.hellohao.dao.*;
import cn.hellohao.pojo.*;
import cn.hellohao.service.ImgTempService;
import cn.hellohao.service.SysConfigService;
import cn.hellohao.utils.*;
import com.alibaba.fastjson.JSON;
@@ -12,6 +13,7 @@ import org.apache.commons.codec.digest.DigestUtils;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;
import org.springframework.web.multipart.MultipartFile;
import javax.servlet.http.HttpServletRequest;
import java.io.File;
import java.io.FileInputStream;
@@ -26,29 +28,23 @@ import java.util.*;
@Service
public class ClientService {
@Autowired
private SysConfigService sysConfigService;
@Autowired
private UserMapper userMapper;
@Autowired
private KeysMapper keysMapper;
@Autowired
private ConfigMapper configMapper;
@Autowired
private UploadConfigMapper uploadConfigMapper;
@Autowired
private ImgMapper imgMapper;
@Autowired
ImgreviewMapper imgreviewMapper;
@Autowired private SysConfigService sysConfigService;
@Autowired private UserMapper userMapper;
@Autowired private KeysMapper keysMapper;
@Autowired private UploadConfigMapper uploadConfigMapper;
@Autowired private ImgMapper imgMapper;
@Autowired private ImgreviewMapper imgreviewMapper;
@Autowired private ImgTempService imgTempService;
@Autowired private KeysServiceImpl keysService;
public Msg uploadImg(HttpServletRequest request, MultipartFile multipartFile, String email, String pass ){
public Msg uploadImg(
HttpServletRequest request, MultipartFile multipartFile, String email, String pass,Integer setday) {
Msg msg = new Msg();
try {
SimpleDateFormat df = new SimpleDateFormat("yyyy-MM-dd HH:mm:ss");
Integer sourceKeyId = 0;
FileInputStream fis = null;
String md5key = null;
Integer setday = 0;
JSONObject jsonObject = new JSONObject();
String userip = GetIPS.getIpAddr(request);
UploadConfig uploadConfig = uploadConfigMapper.getUpdateConfig();
@@ -119,56 +115,96 @@ public class ClientService {
}
}
}
if(Integer.valueOf(sysConfigService.getstate().getCheckduplicate())==1) {
// if (Integer.valueOf(sysConfigService.getstate().getCheckduplicate()) == 1) {
// Images imaOBJ = new Images();
// imaOBJ.setMd5key(md5key);
// imaOBJ.setUserid(u.getId());
// if (imgMapper.md5Count(imaOBJ) > 0) {
// List<Images> images = imgMapper.selectImgUrlByMD5(md5key);
// jsonObject.put("url", images.get(0).getImgurl());
// jsonObject.put("name", file.getName());
// jsonObject.put("size", images.get(0).getSizes());
// msg.setData(jsonObject);
// return msg;
// }
// }
Images imgObj = new Images();
String imgnameEd = null;
Map<Map<String, String>, File> map = new HashMap<>();
if (file.exists()) {
Map<String, String> m1 = new HashMap<>();
String shortUuid_y = SetText.getShortUuid();
m1.put("prefix", prefix);
m1.put("name", shortUuid_y);
map.put(m1, file);
imgnameEd = updatePath + "/" + shortUuid_y + "." + prefix;
imgObj.setImgname(imgnameEd);
if (key.getStorageType().equals(5)) {
imgObj.setImgurl(key.getRequestAddress() + "/ota/" + imgnameEd);
} else {
imgObj.setImgurl(key.getRequestAddress() + "/" + imgnameEd);
}
imgObj.setSizes(Long.toString(file.length()));
}
imgObj.setUpdatetime(df.format(new Date()));
imgObj.setSource(key.getId());
imgObj.setUserid(u == null ? 0 : u.getId());
if (setday == 1 || setday == 3 || setday == 7 || setday == 30) {
imgObj.setImgtype(1);
ImgTemp imgDataExp = new ImgTemp();
imgDataExp.setDeltime(UploadServicel.plusDay(setday));
imgDataExp.setImguid(imguid);
imgTempService.insertImgExp(imgDataExp);
} else {
imgObj.setImgtype(0);
}
imgObj.setAbnormal(userip);
imgObj.setMd5key(md5key);
imgObj.setImguid(imguid);
imgObj.setFormat(fileMiME.getData().toString());
Integer insertRet = imgMapper.insertImgData(imgObj);
if (insertRet == 0) {
Images imaOBJ = new Images();
imaOBJ.setMd5key(md5key);
imaOBJ.setUserid(u.getId());
if (imgMapper.md5Count(imaOBJ) > 0) {
List<Images> images = imgMapper.selectImgUrlByMD5(md5key);
imaOBJ.setUserid(u == null ? 0 : u.getId());
List<Images> images = imgMapper.selectImgUrlByMD5(md5key);
if (images.size() > 0) {
jsonObject.put("url", images.get(0).getImgurl());
// Keys imgFromKey = keysService.selectKeys(images.get(0).getSource());
// if (imgFromKey.getStorageType().equals(5)) {
// jsonObject.put(
// "url",
// imgFromKey.getRequestAddress()
// + "/ota/"
// + images.get(0).getImgname());
// } else {
// jsonObject.put("url", images.get(0).getImgurl());
// }
jsonObject.put("name", file.getName());
jsonObject.put("size", images.get(0).getSizes());
msg.setData(jsonObject);
return msg;
} else {
msg.setInfo("未获取到指定图像");
msg.setCode("110501");
return msg;
}
}
Map<String, File> map = new HashMap<>();
if (file.exists()) {
map.put(prefix, file);
}
long stime = System.currentTimeMillis();
Map<ReturnImage, Integer> m = null;
ReturnImage returnImage = GetSource.storageSource(key.getStorageType(), map, updatePath, key.getId());
Images img = new Images();
SimpleDateFormat df = new SimpleDateFormat("yyyy-MM-dd HH:mm:ss");
ReturnImage returnImage =
GetSource.storageSource(key.getStorageType(), map, updatePath, key.getId());
if (returnImage.getCode().equals("200")) {
String imgurl = returnImage.getImgurl();
Long imgsize = returnImage.getImgSize();
String imgname = returnImage.getImgname();
img.setImgurl(imgurl);
img.setUpdatetime(df.format(new Date()));
img.setSource(key.getId());
img.setUserid(u == null ? 0 : u.getId());
img.setSizes(imgsize.toString());
if (uploadConfig.getUrltype() == 2) {
img.setImgname(imgname);
} else {
img.setImgname(SetText.getSubString(imgname, key.getRequestAddress() + "/", ""));
}
img.setImgtype(setday > 0 ? 1 : 0);
img.setAbnormal(userip);
img.setMd5key(md5key);
img.setImguid(imguid);
img.setFormat(fileMiME.getData().toString());
userMapper.insertimg(img);
long etime = System.currentTimeMillis();
Print.Normal("上传图片所用总时长:" + String.valueOf(etime - stime) + "ms");
jsonObject.put("url", img.getImgurl());
jsonObject.put("name", imgname);
jsonObject.put("size", img.getSizes());
new Thread(() -> {
LegalImageCheck(img);
}).start();
jsonObject.put("url", imgObj.getImgurl());
jsonObject.put("name", imgObj.getImgname());
jsonObject.put("size", imgObj.getSizes());
new Thread(
() -> {
LegalImageCheck(imgObj);
})
.start();
} else {
msg.setCode("5001");
msg.setInfo("上传服务内部错误");
@@ -177,53 +213,55 @@ public class ClientService {
file.delete();
msg.setData(jsonObject);
return msg;
}catch (Exception e){
} catch (Exception e) {
e.printStackTrace();
msg.setCode("5001");
msg.setInfo("Error for server:500");
return msg;
}
}
public static Group group;
public static Long memory;
public static Long TotleMemory;
public static Long UsedTotleMemory;
public static String updatePath = "tourist";
public static Group group; //上传用户或游客的所属分组
public static Long memory;//上传用户或者游客的分配容量 memory
public static Long TotleMemory;//用户或者游客下可使用的总容量 //maxsize
public static Long UsedTotleMemory;//用户或者游客已经用掉的总容量 //usermemory
public static String updatePath="tourist";
//判断用户 或 游客 当前上传图片的一系列校验
private Msg updateImgCheck(User user, UploadConfig uploadConfig){
final Msg msg = new Msg();
private Msg updateImgCheck(User user, UploadConfig uploadConfig) {
Msg msg = new Msg();
java.text.DateFormat dateFormat = null;
try {
dateFormat = new SimpleDateFormat("yyyy/MM/dd");
if (user == null) {
//用户没有登陆,值判断游客能不能上传即可
if(uploadConfig.getIsupdate()!=1){
if (uploadConfig.getIsupdate() != 1) {
msg.setCode("1000");
msg.setInfo("系统已禁用游客上传");
return msg;
}
group = GetCurrentSource.GetSource(null);
memory = Long.valueOf(uploadConfig.getVisitormemory());//单位 B 游客设置总量
TotleMemory = Long.valueOf(uploadConfig.getFilesizetourists());//单位 B 游客单文件大小
UsedTotleMemory = imgMapper.getusermemory(0)==null?0L : imgMapper.getusermemory(0);//单位 B
memory = Long.valueOf(uploadConfig.getVisitormemory()); // 单位 B 游客设置总量
TotleMemory = Long.valueOf(uploadConfig.getFilesizetourists()); // 单位 B 游客单文件大小
UsedTotleMemory =
imgMapper.getusermemory(0) == null
? 0L
: imgMapper.getusermemory(0); // 单位 B
} else {
//判断用户能不能上传
if(uploadConfig.getUserclose()!=1){
// 判断用户能不能上传
if (uploadConfig.getUserclose() != 1) {
msg.setCode("1001");
msg.setInfo("系统已禁用上传功能");
return msg;
}
updatePath = user.getUsername();
group= GetCurrentSource.GetSource(user.getId());
memory = Long.valueOf(user.getMemory());//单位 B
TotleMemory = Long.valueOf(uploadConfig.getFilesizeuser());//单位 B
UsedTotleMemory = imgMapper.getusermemory(user.getId())==null?0L:imgMapper.getusermemory(user.getId());//单位 B
group = GetCurrentSource.GetSource(user.getId());
memory = Long.valueOf(user.getMemory()); // 单位 B
TotleMemory = Long.valueOf(uploadConfig.getFilesizeuser()); // 单位 B
UsedTotleMemory =
imgMapper.getusermemory(user.getId()) == null
? 0L
: imgMapper.getusermemory(user.getId()); // 单位 B
}
//判断上传的图片目录结构类型
// 判断上传的图片目录结构类型
if (uploadConfig.getUrltype() == 2) {
updatePath = dateFormat.format(new Date());
}
@@ -235,9 +273,8 @@ public class ClientService {
return msg;
}
//图片鉴黄
private synchronized void LegalImageCheck(Images images){
System.out.println("非法图像鉴别进程启动");
// 图片鉴黄
private synchronized void LegalImageCheck(Images images) {
Imgreview imgreview = null;
try {
imgreview = imgreviewMapper.selectByusing(1);
@@ -245,23 +282,33 @@ public class ClientService {
Print.warning("获取鉴别程序的时候发生错误");
e.printStackTrace();
}
LegalImageCheckForBaiDu(imgreview,images);
if(imgreview==null){
System.out.println("没有找到可用的图像鉴别进程");
}else{
LegalImageCheckForBaiDu(imgreview, images);
}
}
private void LegalImageCheckForBaiDu(Imgreview imgreview,Images images){
if(imgreview.getUsing()==1){
private void LegalImageCheckForBaiDu(Imgreview imgreview, Images images) {
if (imgreview.getUsing() == 1) {
try {
AipContentCensor client = new AipContentCensor(imgreview.getAppId(), imgreview.getApiKey(), imgreview.getSecretKey());
AipContentCensor client =
new AipContentCensor(
imgreview.getAppId(),
imgreview.getApiKey(),
imgreview.getSecretKey());
client.setConnectionTimeoutInMillis(5000);
client.setSocketTimeoutInMillis(30000);
org.json.JSONObject res = client.antiPorn(images.getImgurl());
res = client.imageCensorUserDefined(images.getImgurl(), EImgType.URL, null);
com.alibaba.fastjson.JSONArray jsonArray = JSON.parseArray("[" + res.toString() + "]");
com.alibaba.fastjson.JSONArray jsonArray =
JSON.parseArray("[" + res.toString() + "]");
for (Object o : jsonArray) {
JSONObject jsonObject = (JSONObject) o;
com.alibaba.fastjson.JSONArray data = jsonObject.getJSONArray("data");
Integer conclusionType = jsonObject.getInteger("conclusionType");
if(conclusionType!=null){
if (conclusionType != null) {
if (conclusionType == 2) {
for (Object datum : data) {
JSONObject imgdata = (JSONObject) datum;
@@ -283,14 +330,10 @@ public class ClientService {
}
}
}catch (Exception e){
} catch (Exception e) {
System.out.println("图像鉴黄线程执行过程中出现异常");
e.printStackTrace();
}
}
}
}
@@ -5,22 +5,23 @@ import cn.hellohao.pojo.Keys;
import cn.hellohao.pojo.ReturnImage;
import cn.hellohao.utils.FTPUtils;
import cn.hellohao.utils.Print;
import cn.hellohao.utils.SetText;
import org.apache.commons.lang3.StringUtils;
import org.apache.commons.net.ftp.FTPClient;
import org.apache.commons.net.ftp.FTPReply;
import org.springframework.stereotype.Service;
import java.io.File;
import java.io.FileInputStream;
import java.io.FileOutputStream;
import java.io.IOException;
import java.util.HashMap;
import java.util.Map;
@Service
public class FTPImageupload {
static Keys key;
public ReturnImage ImageuploadFTP(Map<String, File> fileMap, String username,Integer keyID) {
public ReturnImage ImageuploadFTP(
Map<Map<String, String>, File> fileMap, String username, Integer keyID) {
ReturnImage returnImage = new ReturnImage();
String[] host = key.getEndpoint().split("\\:");
String h = host[0];
@@ -28,27 +29,28 @@ public class FTPImageupload {
FTPUtils ftps = new FTPUtils(h, p, key.getAccessKey(), key.getAccessSecret());
boolean flag = ftps.open();
File file = null;
Map<ReturnImage, Integer> ImgUrl = new HashMap<>();
ftps.mkDir(File.separator+username);
ftps.mkDir(File.separator + username);
try {
for (Map.Entry<String, File> entry : fileMap.entrySet()) {
String ShortUID = SetText.getShortUuid();
for (Map.Entry<Map<String, String>, File> entry : fileMap.entrySet()) {
String prefix = entry.getKey().get("prefix");
String ShortUIDName = entry.getKey().get("name");
file = entry.getValue();
String userkey =username + "/"+ ShortUID + "." + entry.getKey();
String userkey = username + "/" + ShortUIDName + "." + prefix;
if (flag) {
boolean isUpload = ftps.upload(file, "/" + userkey, "");
if(isUpload){
returnImage.setImgname(userkey);
returnImage.setImgurl(key.getRequestAddress() + "/"+ userkey);
returnImage.setImgSize(entry.getValue().length());
returnImage.setCode("200");
}else{
returnImage.setCode("500");
if (isUpload) {
} else {
returnImage.setCode("400");
}
} else {
returnImage.setCode("400");
}
Print.Normal("要上传的文件路径:/"+userkey);
Print.Normal("要上传的文件路径:/" + userkey);
}
}catch (Exception e){
returnImage.setCode("200");
} catch (Exception e) {
e.printStackTrace();
returnImage.setCode("500");
}
@@ -57,55 +59,57 @@ public class FTPImageupload {
public static Integer Initialize(Keys k) {
int ret = -1;
if(k.getEndpoint()!=null && k.getAccessSecret()!=null && k.getEndpoint()!=null && k.getRequestAddress()!=null ) {
if(!k.getEndpoint().equals("") && !k.getAccessSecret().equals("") && !k.getEndpoint().equals("") && !k.getRequestAddress().equals("") ) {
FTPClient ftp = new FTPClient();
ftp.setConnectTimeout(0);
int flag = k.getEndpoint().indexOf(":");
if(flag>0){
String[] host = k.getEndpoint().split("\\:");
String h = host[0];
Integer p = Integer.parseInt(host[1]);
try {
if(!ftp.isConnected()){
ftp.connect(h,p);
}
ftp.login(k.getAccessKey(), k.getAccessSecret());
int reply = ftp.getReplyCode();
if (!FTPReply.isPositiveCompletion(reply)) {
System.out.println("FTP Object Is null");
ftp.disconnect();
return -1;
}
ret = 1;
key = k;
} catch (IOException e) {
System.out.println("FTP Object Is null");
return -1;
}
if (StringUtils.isBlank(k.getAccessKey())
|| StringUtils.isBlank(k.getAccessSecret())
|| StringUtils.isBlank(k.getEndpoint())
|| StringUtils.isBlank(k.getRequestAddress())) {
return -1;
}
FTPClient ftp = new FTPClient();
ftp.setConnectTimeout(0);
int flag = k.getEndpoint().indexOf(":");
if (flag > 0) {
String[] host = k.getEndpoint().split("\\:");
String h = host[0];
Integer p = Integer.parseInt(host[1]);
try {
if (!ftp.isConnected()) {
ftp.connect(h, p);
}
ftp.login(k.getAccessKey(), k.getAccessSecret());
int reply = ftp.getReplyCode();
if (!FTPReply.isPositiveCompletion(reply)) {
System.out.println("FTP Object Is null");
ftp.disconnect();
return -1;
}
ret = 1;
key = k;
} catch (IOException e) {
System.out.println("FTP Object Is null");
return -1;
}
}
return ret;
}
public static void fuzhi(String p1,String p2){
String a=p1;
try{
File afile=new File(a);
File bfile=new File(p2);//定义一个复制后的文件路径
public static void copyFile(String p1, String p2) {
String a = p1;
try {
File afile = new File(a);
File bfile = new File(p2); // 定义一个复制后的文件路径
bfile.createNewFile();
FileInputStream c=new FileInputStream(afile);
FileOutputStream d=new FileOutputStream(bfile);
byte[] date=new byte[512];
int i=0;
while((i=c.read(date))>0){
FileInputStream c = new FileInputStream(afile);
FileOutputStream d = new FileOutputStream(bfile);
byte[] date = new byte[512];
int i = 0;
while ((i = c.read(date)) > 0) {
d.write(date);
}
c.close();
d.close();
System.out.println("文件复制成功");}
catch(IOException e){
System.out.println("文件复制成功");
} catch (IOException e) {
e.printStackTrace();
}
}
@@ -116,7 +120,6 @@ public class FTPImageupload {
String[] host = key.getEndpoint().split("\\:");
String h = host[0];
Integer p = Integer.parseInt(host[1]);
//创建FTP客户端,所有的操作都基于FTPClinet
FTPUtils ftps = new FTPUtils(h, p, key.getAccessKey(), key.getAccessSecret());
ftps.open();
b = ftps.deleteFile(images.getImgname());
@@ -126,6 +129,4 @@ public class FTPImageupload {
}
return b;
}
}
@@ -20,6 +20,11 @@ public class ImgServiceImpl implements ImgService {
return imgMapper.selectimg(images);
}
@Override
public Integer insertImgData(Images images) {
return imgMapper.insertImgData(images);
}
@Override
public Integer deleimg(Integer id) {
// TODO Auto-generated method stub
@@ -1,13 +1,8 @@
package cn.hellohao.service.impl;
import cn.hellohao.config.GlobalConstant;
import cn.hellohao.pojo.Images;
import cn.hellohao.pojo.Keys;
import cn.hellohao.pojo.ReturnImage;
import cn.hellohao.pojo.UploadConfig;
import cn.hellohao.utils.*;
import com.aliyun.oss.OSSClient;
import com.aliyun.oss.model.ObjectMetadata;
import com.google.gson.Gson;
import com.qiniu.common.QiniuException;
import com.qiniu.common.Zone;
@@ -18,14 +13,11 @@ import com.qiniu.storage.UploadManager;
import com.qiniu.storage.model.DefaultPutRet;
import com.qiniu.storage.model.FileInfo;
import com.qiniu.util.Auth;
import org.apache.commons.lang3.StringUtils;
import org.springframework.stereotype.Service;
import org.springframework.web.multipart.MultipartFile;
import java.io.File;
import java.util.Date;
import java.util.HashMap;
import java.util.Map;
import java.util.UUID;
@Service
public class KODOImageupload {
@@ -33,7 +25,8 @@ public class KODOImageupload {
static BucketManager bucketManager;
static Keys key;
public ReturnImage ImageuploadKODO(Map<String, File> fileMap, String username, Integer keyID){
public ReturnImage ImageuploadKODO(
Map<Map<String, String>, File> fileMap, String username, Integer keyID) {
ReturnImage returnImage = new ReturnImage();
Configuration cfg;
if (key.getEndpoint().equals("1")) {
@@ -49,19 +42,20 @@ public class KODOImageupload {
}
UploadManager uploadManager = new UploadManager(cfg);
Auth auth = Auth.create(key.getAccessKey(), key.getAccessSecret());
String upToken = auth.uploadToken(key.getBucketname(),null,7200,null);
String upToken = auth.uploadToken(key.getBucketname(), null, 7200, null);
File file = null;
try {
for (Map.Entry<String, File> entry : fileMap.entrySet()) {
String ShortUID = SetText.getShortUuid();
for (Map.Entry<Map<String, String>, File> entry : fileMap.entrySet()) {
String prefix = entry.getKey().get("prefix");
String ShortUIDName = entry.getKey().get("name");
file = entry.getValue();
try {
Response response = uploadManager.put(file,username + "/" + ShortUID + "." + entry.getKey(),upToken);
DefaultPutRet putRet = new Gson().fromJson(response.bodyString(), DefaultPutRet.class);
returnImage.setImgname(username + "/" + ShortUID + "." + entry.getKey());
returnImage.setImgurl(key.getRequestAddress() + "/" + username + "/" + ShortUID + "." + entry.getKey());
returnImage.setImgSize(entry.getValue().length());
returnImage.setCode("200");
Response response =
uploadManager.put(
file, username + "/" + ShortUIDName + "." + prefix, upToken);
DefaultPutRet putRet =
new Gson().fromJson(response.bodyString(), DefaultPutRet.class);
} catch (QiniuException ex) {
returnImage.setCode("400");
Response r = ex.response;
@@ -72,7 +66,8 @@ public class KODOImageupload {
}
}
}
}catch (Exception e){
returnImage.setCode("200");
} catch (Exception e) {
e.printStackTrace();
returnImage.setCode("500");
}
@@ -81,40 +76,46 @@ public class KODOImageupload {
public static Integer Initialize(Keys k) {
int ret = -1;
if (k.getEndpoint() != null && k.getAccessSecret() != null && k.getEndpoint() != null
&& k.getBucketname() != null && k.getRequestAddress() != null) {
if (!k.getEndpoint().equals("") && !k.getAccessSecret() .equals("") && !k.getEndpoint() .equals("")
&& !k.getBucketname().equals("") && !k.getRequestAddress() .equals("")) {
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());
}
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);
BucketManager.FileListIterator fileListIterator = null;
try {
fileListIterator = bmObj.createFileListIterator(k.getBucketname(), "", 1, "/");
FileInfo[] items = fileListIterator.next();
if(items!=null){
ret = 1;
bucketManager = bmObj;
key = k;
}
}catch (Exception e){
System.out.println("KODO Object Is null");
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())
|| 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());
}
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);
BucketManager.FileListIterator fileListIterator = null;
try {
fileListIterator = bmObj.createFileListIterator(k.getBucketname(), "", 1, "/");
FileInfo[] items = fileListIterator.next();
if (items != null) {
ret = 1;
bucketManager = bmObj;
key = k;
}
} catch (Exception e) {
System.out.println("KODO Object Is null");
ret = -1;
}
return ret;
}
@@ -128,6 +129,4 @@ public class KODOImageupload {
}
return b;
}
}
@@ -8,6 +8,7 @@ import com.netease.cloud.auth.BasicCredentials;
import com.netease.cloud.auth.Credentials;
import com.netease.cloud.services.nos.NosClient;
import com.netease.cloud.services.nos.model.ObjectListing;
import org.apache.commons.lang3.StringUtils;
import org.springframework.stereotype.Service;
import java.io.File;
@@ -18,20 +19,19 @@ public class NOSImageupload {
static NosClient nosClient;
static Keys key;
public ReturnImage Imageupload(Map<String, File> fileMap, String username,Integer keyID){
public ReturnImage Imageupload(Map<Map<String, String>, File> fileMap, String username,Integer keyID){
ReturnImage returnImage = new ReturnImage();
File file = null;
try {
for (Map.Entry<String, File> entry : fileMap.entrySet()) {
String ShortUID = SetText.getShortUuid();
for (Map.Entry<Map<String, String>, File> entry : fileMap.entrySet()) {
String prefix = entry.getKey().get("prefix");
String ShortUIDName = entry.getKey().get("name");
file = entry.getValue();
nosClient.putObject(key.getBucketname(), username + "/" + ShortUID+ "." + entry.getKey(), file);
returnImage.setImgname(username + "/" + ShortUID+ "." + entry.getKey());
returnImage.setImgurl(key.getRequestAddress() + "/" + username + "/" + ShortUID + "." + entry.getKey());
returnImage.setImgSize(entry.getValue().length());
returnImage.setCode("200");
nosClient.putObject(
key.getBucketname(), username + "/" + ShortUIDName + "." + prefix, file);
}
}catch (Exception e){
returnImage.setCode("200");
} catch (Exception e) {
e.printStackTrace();
returnImage.setCode("500");
}
@@ -42,25 +42,25 @@ public class NOSImageupload {
public static Integer Initialize(Keys k) {
int ret = -1;
if(k.getEndpoint()!=null && k.getAccessSecret()!=null && k.getEndpoint()!=null
&& k.getBucketname()!=null && k.getRequestAddress()!=null ){
if(!k.getEndpoint().equals("") && !k.getAccessSecret().equals("") && !k.getEndpoint().equals("")
&& !k.getBucketname().equals("") && !k.getRequestAddress().equals("") ){
// 初始化
Credentials credentials = new BasicCredentials(k.getAccessKey(), k.getAccessSecret());
NosClient nosObj = new NosClient(credentials);
nosObj.setEndpoint(k.getEndpoint());
ObjectListing objectListing = null;
try {
objectListing = nosObj.listObjects(k.getBucketname());
ret = 1;
nosClient = nosObj;
key = k;
}catch (Exception e){
System.out.println("NOS Object Is null");
ret = -1;
}
}
if (StringUtils.isBlank(k.getAccessKey())
|| StringUtils.isBlank(k.getAccessSecret())
|| StringUtils.isBlank(k.getEndpoint())
|| StringUtils.isBlank(k.getBucketname())
|| StringUtils.isBlank(k.getRequestAddress())) {
return -1;
}
Credentials credentials = new BasicCredentials(k.getAccessKey(), k.getAccessSecret());
NosClient nosObj = new NosClient(credentials);
nosObj.setEndpoint(k.getEndpoint());
ObjectListing objectListing = null;
try {
objectListing = nosObj.listObjects(k.getBucketname());
ret = 1;
nosClient = nosObj;
key = k;
}catch (Exception e){
System.out.println("NOS Object Is null");
ret = -1;
}
return ret;
}
@@ -4,12 +4,13 @@ import cn.hellohao.pojo.Images;
import cn.hellohao.pojo.Keys;
import cn.hellohao.pojo.Msg;
import cn.hellohao.pojo.ReturnImage;
import cn.hellohao.utils.SetText;
import cn.hellohao.utils.TypeDict;
import com.aliyun.oss.OSS;
import com.aliyun.oss.OSSClientBuilder;
import com.aliyun.oss.model.ObjectListing;
import com.aliyun.oss.model.ObjectMetadata;
import com.aliyun.oss.model.PutObjectRequest;
import org.apache.commons.lang3.StringUtils;
import org.springframework.stereotype.Service;
import java.io.File;
@@ -20,57 +21,63 @@ public class OSSImageupload {
static OSS ossClient;
static Keys key;
public ReturnImage ImageuploadOSS(Map<String, File> fileMap, String username,Integer keyID){
public ReturnImage ImageuploadOSS(
Map<Map<String, String>, File> fileMap, String username, Integer keyID) {
ReturnImage returnImage = new ReturnImage();
File file = null;
ObjectMetadata meta = new ObjectMetadata();
meta.setHeader("Content-Disposition", "inline");
try {
for (Map.Entry<String, File> entry : fileMap.entrySet()) {
String ShortUID = SetText.getShortUuid();
java.text.DateFormat format1 = new java.text.SimpleDateFormat("MMddhhmmss");
for (Map.Entry<Map<String, String>, File> entry : fileMap.entrySet()) {
String prefix = entry.getKey().get("prefix");
String ShortUIDName = entry.getKey().get("name");
file = entry.getValue();
Msg fileMiME = TypeDict.FileMiME(file);
meta.setHeader("content-type", fileMiME.getData().toString());
System.out.println("待上传的图片:"+username + "/" + ShortUID + "." + entry.getKey());
ossClient.putObject(key.getBucketname(), username + "/" + ShortUID + "." + entry.getKey(),file);
returnImage.setImgname(username + "/" + ShortUID + "." + entry.getKey());//entry.getValue().getOriginalFilename()
returnImage.setImgurl(key.getRequestAddress() + "/" + username + "/" + ShortUID + "." + entry.getKey());
returnImage.setImgSize(file.length());
returnImage.setCode("200");
PutObjectRequest putObjectRequest =
new PutObjectRequest(
key.getBucketname(),
username + "/" + ShortUIDName + "." + prefix,
file,
meta);
ossClient.putObject(putObjectRequest);
}
}catch (Exception e){
returnImage.setCode("200");
} catch (Exception e) {
e.printStackTrace();
returnImage.setCode("500");
}
return returnImage;
}
public static Integer Initialize(Keys k) {
int ret = -1;
ObjectListing objectListing = null;
if(k.getEndpoint()!=null && k.getAccessSecret()!=null && k.getAccessKey()!=null && k.getEndpoint()!=null
&& k.getBucketname()!=null && k.getRequestAddress()!=null ) {
if(!k.getEndpoint().equals("") && !k.getAccessSecret().equals("") && !k.getAccessKey().equals("") && !k.getEndpoint().equals("")
&& !k.getBucketname().equals("") && !k.getRequestAddress().equals("") ) {
OSS ossObj = new OSSClientBuilder().build(k.getEndpoint(), k.getAccessKey(), k.getAccessSecret());
try {
objectListing = ossObj.listObjects(k.getBucketname());
ret=1;
ossClient = ossObj;
key = k;
} catch (Exception e) {
System.out.println("OSS Object Is null");
ret = -1;
}
}
if (StringUtils.isBlank(k.getAccessKey())
|| StringUtils.isBlank(k.getAccessSecret())
|| StringUtils.isBlank(k.getEndpoint())
|| StringUtils.isBlank(k.getBucketname())
|| StringUtils.isBlank(k.getRequestAddress())) {
return -1;
}
OSS ossObj =
new OSSClientBuilder()
.build(k.getEndpoint(), k.getAccessKey(), k.getAccessSecret());
try {
objectListing = ossObj.listObjects(k.getBucketname());
ret = 1;
ossClient = ossObj;
key = k;
} catch (Exception e) {
System.out.println("OSS Object Is null");
ret = -1;
}
return ret;
}
public boolean delOSS(Integer keyID, Images images){
boolean b =true;
public boolean delOSS(Integer keyID, Images images) {
boolean b = true;
try {
ossClient.deleteObject(key.getBucketname(), images.getImgname());
} catch (Exception e) {
@@ -79,6 +86,4 @@ public class OSSImageupload {
}
return b;
}
}
@@ -12,42 +12,44 @@ import java.util.concurrent.TimeUnit;
@Service
public class RedisServiceImpl implements IRedisService {
@Autowired
private StringRedisTemplate stringRedisTemplate;
@Autowired
private RedisTemplate redisTemplate;
@Autowired private StringRedisTemplate stringRedisTemplate;
@Autowired private RedisTemplate redisTemplate;
@Override
public void setValue(String key, Map<String, Object> value) {
ValueOperations<String, Object> vo = redisTemplate.opsForValue();
vo.set(key, value);
redisTemplate.expire(key, 1, TimeUnit.HOURS); // 这里指的是1小时后失效
}
@Override
public void setValue(String key, Map<String, Object> value) {
ValueOperations<String, Object> vo = redisTemplate.opsForValue();
vo.set(key, value);
redisTemplate.expire(key, 1, TimeUnit.HOURS); // 这里指的是1小时后失效
}
@Override
public Object getValue(String key) {
ValueOperations<String, String> vo = redisTemplate.opsForValue();
return vo.get(key);
}
@Override
public Object getValue(String key) {
ValueOperations<String, String> vo = redisTemplate.opsForValue();
return vo.get(key);
}
@Override
public void setValue(String key, String value) {
ValueOperations<String, Object> vo = redisTemplate.opsForValue();
vo.set(key, value);
redisTemplate.expire(key, 3, TimeUnit.MINUTES); // 这里指的是1小时后失效 时HOURS 分 MINUTES
}
@Override
public void setValue(String key, String value) {
ValueOperations<String, Object> vo = redisTemplate.opsForValue();
vo.set(key, value);
redisTemplate.expire(key, 3, TimeUnit.MINUTES); // 这里指的是1小时后失效 时HOURS 分 MINUTES
}
@Override
public void setTimeValue(String key, Object value, Long time) {
ValueOperations<String, Object> vo = redisTemplate.opsForValue();
vo.set(key, value);
redisTemplate.expire(key, time, TimeUnit.HOURS);
}
@Override
public void setValue(String key, Object value) {
ValueOperations<String, Object> vo = redisTemplate.opsForValue();
vo.set(key, value);
redisTemplate.expire(key, 1, TimeUnit.HOURS); // 这里指的是1小时后失效
}
@Override
public Object getMapValue(String key) {
ValueOperations<String, String> vo = redisTemplate.opsForValue();
return vo.get(key);
}
@Override
public Object getMapValue(String key) {
ValueOperations<String, String> vo = redisTemplate.opsForValue();
return vo.get(key);
}
}
@Override
public Boolean removeValue(String key) {
return redisTemplate.delete(key);
}
}
@@ -9,6 +9,7 @@ import cn.hellohao.utils.TypeDict;
import com.UpYun;
import com.aliyun.oss.model.ObjectMetadata;
import org.springframework.stereotype.Service;
import java.io.File;
import java.util.List;
import java.util.Map;
@@ -18,47 +19,64 @@ public class UFileImageupload {
static UpYun uFile;
static Keys key;
public ReturnImage ImageuploadUFile(Map<String, File> fileMap, String username,Integer keyID) {
/*
* 废弃方法待补位
* */
public ReturnImage ImageuploadUFile(
Map<Map<String, String>, File> fileMap, String username, Integer keyID) {
ReturnImage returnImage = new ReturnImage();
File file = null;
ObjectMetadata meta = new ObjectMetadata();
meta.setHeader("Content-Disposition", "inline");
try {
for (Map.Entry<String, File> entry : fileMap.entrySet()) {
for (Map.Entry<Map<String, String>, File> entry : fileMap.entrySet()) {
String ShortUID = SetText.getShortUuid();
file = entry.getValue();
Msg fileMiME = TypeDict.FileMiME(file);
meta.setHeader("content-type", fileMiME.getData().toString());
uFile.setContentMD5(UpYun.md5(file));
boolean result = uFile.writeFile(username + "/" + ShortUID + "." + entry.getKey(), file, true);
if(result){
boolean result =
uFile.writeFile(
username + "/" + ShortUID + "." + entry.getKey(), file, true);
if (result) {
returnImage.setImgname(username + "/" + ShortUID + "." + entry.getKey());
returnImage.setImgurl(key.getRequestAddress() + "/" +username + "/" + ShortUID + "." + entry.getKey());
returnImage.setImgurl(
key.getRequestAddress()
+ "/"
+ username
+ "/"
+ ShortUID
+ "."
+ entry.getKey());
returnImage.setImgSize(entry.getValue().length());
returnImage.setCode("200");
}else{
} else {
returnImage.setCode("400");
System.err.println("上传失败");
}
}
}catch(Exception e){
} catch (Exception e) {
returnImage.setCode("500");
}
returnImage.setCode("500");
return returnImage;
}
public static Integer Initialize(Keys k) {
int ret = -1;
if(k.getAccessSecret()!=null && k.getAccessKey()!=null
&& k.getBucketname()!=null && k.getRequestAddress()!=null ) {
if(!k.getAccessSecret().equals("") && !k.getAccessKey().equals("")
&& !k.getBucketname().equals("") && !k.getRequestAddress().equals("") ) {
if (k.getAccessSecret() != null
&& k.getAccessKey() != null
&& k.getBucketname() != null
&& k.getRequestAddress() != null) {
if (!k.getAccessSecret().equals("")
&& !k.getAccessKey().equals("")
&& !k.getBucketname().equals("")
&& !k.getRequestAddress().equals("")) {
UpYun ufObj = new UpYun(k.getBucketname(), k.getAccessKey(), k.getAccessSecret());
List<UpYun.FolderItem> items = null;
try {
items = ufObj.readDir("/",null);
items = ufObj.readDir("/", null);
ret = 1;
uFile = ufObj;
key = k;
@@ -81,5 +99,4 @@ public class UFileImageupload {
}
return b;
}
}
@@ -4,11 +4,12 @@ import cn.hellohao.pojo.Images;
import cn.hellohao.pojo.Keys;
import cn.hellohao.pojo.Msg;
import cn.hellohao.pojo.ReturnImage;
import cn.hellohao.utils.SetText;
import cn.hellohao.utils.TypeDict;
import com.UpYun;
import com.aliyun.oss.model.ObjectMetadata;
import org.apache.commons.lang3.StringUtils;
import org.springframework.stereotype.Service;
import java.io.File;
import java.util.List;
import java.util.Map;
@@ -18,58 +19,59 @@ public class USSImageupload {
static UpYun upyun;
static Keys key;
public ReturnImage ImageuploadUSS(Map<String, File> fileMap, String username,Integer keyID) {
public ReturnImage ImageuploadUSS(
Map<Map<String, String>, File> fileMap, String username, Integer keyID) {
ReturnImage returnImage = new ReturnImage();
File file = null;
ObjectMetadata meta = new ObjectMetadata();
meta.setHeader("Content-Disposition", "inline");
try {
for (Map.Entry<String, File> entry : fileMap.entrySet()) {
String ShortUID = SetText.getShortUuid();
for (Map.Entry<Map<String, String>, File> entry : fileMap.entrySet()) {
String prefix = entry.getKey().get("prefix");
String ShortUIDName = entry.getKey().get("name");
file = entry.getValue();
Msg fileMiME = TypeDict.FileMiME(file);
meta.setHeader("content-type", fileMiME.getData().toString());
upyun.setContentMD5(UpYun.md5(file));
boolean result = upyun.writeFile(username + "/" + ShortUID + "." + entry.getKey(), file, true);
if(result){
returnImage.setImgname(username + "/" + ShortUID + "." + entry.getKey());
returnImage.setImgurl(key.getRequestAddress() + "/" +username + "/" + ShortUID + "." + entry.getKey());
returnImage.setImgSize(entry.getValue().length());
returnImage.setCode("200");
}else{
returnImage.setCode("400");
boolean result =
upyun.writeFile(username + "/" + ShortUIDName + "." + prefix, file, true);
if (result) {
} else {
System.err.println("上传失败");
returnImage.setCode("400");
}
}
}catch (Exception e){
returnImage.setCode("200");
} catch (Exception e) {
e.printStackTrace();
returnImage.setCode("500");
}
return returnImage;
}
//初始化
// 初始化
public static Integer Initialize(Keys k) {
int ret = -1;
if(k.getStorageType()!=null && k.getAccessKey() != null && k.getAccessSecret() != null && k.getBucketname() != null
&& k.getRequestAddress() !=null ) {
if(!k.getStorageType().equals("") && !k.getAccessKey().equals("") && !k.getAccessSecret().equals("") && !k.getBucketname().equals("")
&& !k.getRequestAddress().equals("") ) {
// 初始化
// 创建UpYun实例。
UpYun upObj= new UpYun(k.getBucketname(), k.getAccessKey(), k.getAccessSecret());
List<UpYun.FolderItem> items = null;
try {
items = upObj.readDir("/",null);
ret = 1;
upyun = upObj;
key = k;
} catch (Exception e) {
System.out.println("USS Object Is null");
ret = -1;
}
}
if (StringUtils.isBlank(k.getAccessKey())
|| StringUtils.isBlank(k.getKeyname())
|| StringUtils.isBlank(k.getAccessSecret())
|| StringUtils.isBlank(k.getEndpoint())
|| StringUtils.isBlank(k.getBucketname())
|| StringUtils.isBlank(k.getRequestAddress())
|| k.getStorageType() == null) {
return -1;
}
UpYun upObj = new UpYun(k.getBucketname(), k.getAccessKey(), k.getAccessSecret());
List<UpYun.FolderItem> items = null;
try {
items = upObj.readDir("/", null);
ret = 1;
upyun = upObj;
key = k;
} catch (Exception e) {
System.out.println("USS Object Is null");
ret = -1;
}
return ret;
}
@@ -80,10 +82,8 @@ public class USSImageupload {
boolean result = upyun.deleteFile(images.getImgname(), null);
} catch (Exception e) {
e.printStackTrace();
b=false;
b = false;
}
return b;
}
}
@@ -3,7 +3,6 @@ package cn.hellohao.service.impl;
import cn.hellohao.dao.*;
import cn.hellohao.pojo.*;
import cn.hellohao.service.ImgTempService;
import cn.hellohao.service.SysConfigService;
import cn.hellohao.utils.*;
import com.alibaba.fastjson.JSON;
import com.alibaba.fastjson.JSONObject;
@@ -27,56 +26,49 @@ import java.util.*;
* @version 1.0
* @date 2020/1/9 15:46
*/
@Service
public class UploadServicel {
@Autowired
ConfigMapper configMapper;
@Autowired
SysConfigService sysConfigService;
@Autowired
UploadConfigMapper uploadConfigMapper;
@Autowired
KeysMapper keysMapper;
@Autowired
ImgMapper imgMapper;
@Autowired
UserMapper userMapper;
@Autowired
ImgreviewMapper imgreviewMapper;
@Autowired
ImgTempService imgTempService;
@Autowired private UploadConfigMapper uploadConfigMapper;
@Autowired private KeysMapper keysMapper;
@Autowired private ImgMapper imgMapper;
@Autowired private UserMapper userMapper;
@Autowired private ImgreviewMapper imgreviewMapper;
@Autowired private ImgTempService imgTempService;
@Autowired private KeysServiceImpl keysService;
public Msg uploadForLoc(HttpServletRequest request,
MultipartFile multipartFile, Integer setday, String imgUrl) {
public Msg uploadForLoc(
HttpServletRequest request,
MultipartFile multipartFile,
Integer setday,
String imgUrl) {
Msg msg = new Msg();
try{
try {
SimpleDateFormat df = new SimpleDateFormat("yyyy-MM-dd HH:mm:ss");
JSONObject jsonObject = new JSONObject();
UploadConfig uploadConfig = uploadConfigMapper.getUpdateConfig();
String userip = GetIPS.getIpAddr(request);
Subject subject = SecurityUtils.getSubject();
User u = (User) subject.getPrincipal();
if(null!=u){
u = userMapper.getUsers(u);
if (null != u) {
u = userMapper.getUsers(u);
}
Integer sourceKeyId = 0;
String md5key = null;
FileInputStream fis = null;
File file =null;
if(imgUrl==null){
File file = null;
if (imgUrl == null) {
file = SetFiles.changeFile_new(multipartFile);
}else{
} else {
Msg imgData = uploadForURL(request, imgUrl);
if(imgData.getCode().equals("200")){
if (imgData.getCode().equals("200")) {
file = new File((String) imgData.getData());
}else{
} else {
return imgData;
}
}
String imguid = UUID.randomUUID().toString().replace("-", "");
Msg msg1 = updateImgCheck(u,uploadConfig);
if(!msg1.getCode().equals("300")){
Msg msg1 = updateImgCheck(u, uploadConfig);
if (!msg1.getCode().equals("300")) {
return msg1;
}
sourceKeyId = group.getKeyid();
@@ -84,12 +76,12 @@ public class UploadServicel {
Long tmp = (memory == -1 ? -2 : UsedTotleMemory);
if (tmp >= memory) {
msg.setCode("4005");
msg.setInfo(u==null?"游客空间已用尽":"您的可用空间不足");
msg.setInfo(u == null ? "游客空间已用尽" : "您的可用空间不足");
return msg;
}
if (file.length() > TotleMemory) {
System.err.println("文件大小:"+file.length());
System.err.println("最大限制:"+TotleMemory);
System.err.println("文件大小:" + file.length());
System.err.println("最大限制:" + TotleMemory);
msg.setCode("4006");
msg.setInfo("图像超出系统限制大小");
return msg;
@@ -102,29 +94,29 @@ public class UploadServicel {
System.out.println("未获取到图片的MD5,成成UUID");
}
Msg fileMiME = TypeDict.FileMiME(file);
if(!fileMiME.getCode().equals("200")) {
if (!fileMiME.getCode().equals("200")) {
msg.setCode("4000");
msg.setInfo(fileMiME.getInfo());
return msg;
}
if(md5key==null || md5key.equals("")){
if (md5key == null || md5key.equals("")) {
md5key = UUID.randomUUID().toString().replace("-", "");
}
if(Integer.valueOf(sysConfigService.getstate().getCheckduplicate())==1){
Images imaOBJ = new Images();
imaOBJ.setMd5key(md5key);
imaOBJ.setUserid(u==null?0:u.getId());
if(imgMapper.md5Count(imaOBJ)>0){
List<Images> images = imgMapper.selectImgUrlByMD5(md5key);
jsonObject.put("url", images.get(0).getImgurl());
jsonObject.put("name",file.getName());
jsonObject.put("imguid",images.get(0).getImguid());
msg.setData(jsonObject);
return msg;
}
}
String prefix = file.getName().substring(file.getName().lastIndexOf(".")+1);
//判断黑名单
// if(Integer.valueOf(sysConfigService.getstate().getCheckduplicate())==1){
// Images imaOBJ = new Images();
// imaOBJ.setMd5key(md5key);
// imaOBJ.setUserid(u==null?0:u.getId());
// if(imgMapper.md5Count(imaOBJ)>0){
// List<Images> images = imgMapper.selectImgUrlByMD5(md5key);
// jsonObject.put("url", images.get(0).getImgurl());
// jsonObject.put("name",file.getName());
// jsonObject.put("imguid",images.get(0).getImguid());
// msg.setData(jsonObject);
// return msg;
// }
// }
String prefix = file.getName().substring(file.getName().lastIndexOf(".") + 1);
// 判断黑名单
if (uploadConfig.getBlacklist() != null) {
String[] iparr = uploadConfig.getBlacklist().split(";");
for (String s : iparr) {
@@ -136,50 +128,84 @@ public class UploadServicel {
}
}
}
Map<String, File> map = new HashMap<>();
// 先存数据库
Images imgObj = new Images();
String imgnameEd = null;
Map<Map<String, String>, File> map = new HashMap<>();
if (file.exists()) {
map.put(prefix, file);//prefix
Map<String, String> m1 = new HashMap<>();
String shortUuid_y = SetText.getShortUuid();
m1.put("prefix", prefix);
m1.put("name", shortUuid_y);
map.put(m1, file);
imgnameEd = updatePath + "/" + shortUuid_y + "." + prefix;
imgObj.setImgname(imgnameEd);
if (key.getStorageType().equals(5)) {
imgObj.setImgurl(key.getRequestAddress() + "/ota/" + imgnameEd);
} else {
imgObj.setImgurl(key.getRequestAddress() + "/" + imgnameEd);
}
imgObj.setSizes(Long.toString(file.length()));
}
imgObj.setUpdatetime(df.format(new Date()));
imgObj.setSource(key.getId());
imgObj.setUserid(u == null ? 0 : u.getId());
if (setday == 1 || setday == 3 || setday == 7 || setday == 30) {
imgObj.setImgtype(1);
ImgTemp imgDataExp = new ImgTemp();
imgDataExp.setDeltime(plusDay(setday));
imgDataExp.setImguid(imguid);
imgTempService.insertImgExp(imgDataExp);
} else {
imgObj.setImgtype(0);
}
imgObj.setAbnormal(userip);
imgObj.setMd5key(md5key);
imgObj.setImguid(imguid);
imgObj.setFormat(fileMiME.getData().toString());
Integer insertRet = imgMapper.insertImgData(imgObj);
if (insertRet == 0) {
Images imaOBJ = new Images();
imaOBJ.setMd5key(md5key);
imaOBJ.setUserid(u == null ? 0 : u.getId());
List<Images> images = imgMapper.selectImgUrlByMD5(md5key);
if (images.size() > 0) {
jsonObject.put("url", images.get(0).getImgurl());
// Keys imgFromKey = keysService.selectKeys(images.get(0).getSource());
// if (imgFromKey.getStorageType().equals(5)) {
// jsonObject.put(
// "url",
// imgFromKey.getRequestAddress()
// + "/ota/"
// + images.get(0).getImgname());
// } else {
// jsonObject.put("url", images.get(0).getImgurl());
// }
jsonObject.put("name", file.getName());
jsonObject.put("imguid", images.get(0).getImguid());
msg.setData(jsonObject);
return msg;
} else {
msg.setInfo("未获取到指定图像");
msg.setCode("110501");
return msg;
}
}
long stime = System.currentTimeMillis();
Map<ReturnImage, Integer> m = null;
ReturnImage returnImage = GetSource.storageSource(key.getStorageType(), map, updatePath, key.getId());
Images img = new Images();
SimpleDateFormat df = new SimpleDateFormat("yyyy-MM-dd HH:mm:ss");
if(returnImage.getCode().equals("200")){
String imgurl = returnImage.getImgurl();
Long imgsize = returnImage.getImgSize();
String imgname = returnImage.getImgname();
img.setImgurl(imgurl);
img.setUpdatetime(df.format(new Date()));
img.setSource(key.getId());
img.setUserid(u == null ? 0 : u.getId());
img.setSizes(imgsize.toString());
if(uploadConfig.getUrltype()==2){
img.setImgname(imgname);
}else{
img.setImgname(SetText.getSubString(imgname, key.getRequestAddress() + "/", ""));
}
if(setday == 1 || setday == 3 || setday == 7 || setday == 30){
img.setImgtype(1);
ImgTemp imgDataExp = new ImgTemp();
imgDataExp.setDeltime(plusDay(setday));
imgDataExp.setImguid(imguid);
imgTempService.insertImgExp(imgDataExp);
}else{
img.setImgtype(0);
}
img.setAbnormal(userip);
img.setMd5key(md5key);
img.setImguid(imguid);
img.setFormat(fileMiME.getData().toString());
userMapper.insertimg(img);
ReturnImage returnImage =
GetSource.storageSource(key.getStorageType(), map, updatePath, key.getId());
if (returnImage.getCode().equals("200")) {
long etime = System.currentTimeMillis();
Print.Normal("上传图片所用总时长:" + String.valueOf(etime - stime) + "ms");
jsonObject.put("url", img.getImgurl());
jsonObject.put("name", imgname);
jsonObject.put("imguid",img.getImguid());
new Thread(()->{LegalImageCheck(img);}).start();
}else{
jsonObject.put("url", imgObj.getImgurl());
jsonObject.put("name", imgObj.getImgname());
jsonObject.put("imguid", imgObj.getImguid());
new Thread(
() -> {
LegalImageCheck(imgObj);
})
.start();
} else {
msg.setCode("5001");
msg.setInfo("上传服务内部错误");
return msg;
@@ -187,37 +213,40 @@ public class UploadServicel {
file.delete();
msg.setData(jsonObject);
return msg;
}catch (Exception e){
} catch (Exception e) {
e.printStackTrace();
msg.setInfo("上传时发生了一些错误");
msg.setCode("110500");
return msg;
}
}
public static Msg uploadForURL(HttpServletRequest request, String imgurl){
final Msg msg = new Msg();
if(true){
public static Msg uploadForURL(HttpServletRequest request, String imgurl) {
Msg msg = new Msg();
if (true) {
Long imgsize = 0L;
try {
if(imgsize==0){
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){
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")){
} else {
if (bl.get("StatusCode").equals("110403")) {
msg.setInfo("该链接非图像文件,无法上传");
}else{
} else {
msg.setInfo("该链接暂时无法上传");
}
msg.setCode("500");
}
}else{
} else {
msg.setCode("500");
msg.setInfo("获取资源失败");
}
@@ -225,7 +254,7 @@ public class UploadServicel {
msg.setCode("500");
msg.setInfo("获取资源失败");
}
}else{
} else {
msg.setCode("500");
msg.setInfo("该链接无效");
}
@@ -233,40 +262,46 @@ public class UploadServicel {
return msg;
}
private static Group group; //上传用户或游客的所属分组
private static Long memory;//上传用户或者游客的分配容量 memory
private static Long TotleMemory;//用户或者游客下可使用的总容量 //maxsize
private static Long UsedTotleMemory;//用户或者游客已经用掉的总容量 //usermemory
private static String updatePath="tourist";
private static Group group; // 上传用户或游客的所属分组
private static Long memory; // 上传用户或者游客的分配容量 memory
private static Long TotleMemory; // 用户或者游客下可使用的总容量 //maxsize
private static Long UsedTotleMemory; // 用户或者游客已经用掉的总容量 //usermemory
private static String updatePath = "tourist";
//判断用户 或 游客 当前上传图片的一系列校验
private Msg updateImgCheck(User user, UploadConfig uploadConfig){
final Msg msg = new Msg();
// 判断用户 或 游客 当前上传图片的一系列校验
private Msg updateImgCheck(User user, UploadConfig uploadConfig) {
Msg msg = new Msg();
java.text.DateFormat dateFormat = null;
try {
dateFormat = new SimpleDateFormat("yyyy/MM/dd");
if (user == null) {
if(uploadConfig.getIsupdate()!=1){
if (uploadConfig.getIsupdate() != 1) {
msg.setCode("1000");
msg.setInfo("系统已禁用游客上传");
return msg;
}
updatePath="tourist";
updatePath = "tourist";
group = GetCurrentSource.GetSource(null);
memory = Long.valueOf(uploadConfig.getVisitormemory());//单位 B 游客设置总量
TotleMemory = Long.valueOf(uploadConfig.getFilesizetourists());//单位 B 游客单文件大小
UsedTotleMemory = imgMapper.getusermemory(0)==null?0L : imgMapper.getusermemory(0);//单位 B
memory = Long.valueOf(uploadConfig.getVisitormemory()); // 单位 B 游客设置总量
TotleMemory = Long.valueOf(uploadConfig.getFilesizetourists()); // 单位 B 游客单文件大小
UsedTotleMemory =
imgMapper.getusermemory(0) == null
? 0L
: imgMapper.getusermemory(0); // 单位 B
} else {
if(uploadConfig.getUserclose()!=1){
if (uploadConfig.getUserclose() != 1) {
msg.setCode("1001");
msg.setInfo("系统已禁用上传功能");
return msg;
}
updatePath = user.getUsername();
group= GetCurrentSource.GetSource(user.getId());
memory = Long.valueOf(user.getMemory());//单位 B *1024*1024
TotleMemory = Long.valueOf(uploadConfig.getFilesizeuser());//单位 B
UsedTotleMemory = imgMapper.getusermemory(user.getId())==null?0L:imgMapper.getusermemory(user.getId());//单位 B
group = GetCurrentSource.GetSource(user.getId());
memory = Long.valueOf(user.getMemory()); // 单位 B *1024*1024
TotleMemory = Long.valueOf(uploadConfig.getFilesizeuser()); // 单位 B
UsedTotleMemory =
imgMapper.getusermemory(user.getId()) == null
? 0L
: imgMapper.getusermemory(user.getId()); // 单位 B
}
if (uploadConfig.getUrltype() == 2) {
updatePath = dateFormat.format(new Date());
@@ -279,7 +314,7 @@ public class UploadServicel {
return msg;
}
private synchronized void LegalImageCheck(Images images){
private synchronized void LegalImageCheck(Images images) {
System.out.println("非法图像鉴别进程启动");
Imgreview imgreview = null;
try {
@@ -288,31 +323,37 @@ public class UploadServicel {
Print.warning("获取鉴别程序的时候发生错误");
e.printStackTrace();
}
if(null != imgreview){
LegalImageCheckForBaiDu(imgreview,images);
if (null != imgreview) {
LegalImageCheckForBaiDu(imgreview, images);
}
}
private void LegalImageCheckForBaiDu(Imgreview imgreview,Images images){
private void LegalImageCheckForBaiDu(Imgreview imgreview, Images images) {
System.out.println("非法图像鉴别进程启动-BaiDu");
if(imgreview.getUsing()==1){
if (imgreview.getUsing() == 1) {
try {
AipContentCensor client = new AipContentCensor(imgreview.getAppId(), imgreview.getApiKey(), imgreview.getSecretKey());
AipContentCensor client =
new AipContentCensor(
imgreview.getAppId(),
imgreview.getApiKey(),
imgreview.getSecretKey());
client.setConnectionTimeoutInMillis(5000);
client.setSocketTimeoutInMillis(30000);
org.json.JSONObject res = client.antiPorn(images.getImgurl());
res = client.imageCensorUserDefined(images.getImgurl(), EImgType.URL, null);
System.err.println("返回的鉴黄json:"+res.toString());
com.alibaba.fastjson.JSONArray jsonArray = JSON.parseArray("[" + res.toString() + "]");
System.err.println("返回的鉴黄json:" + res.toString());
com.alibaba.fastjson.JSONArray jsonArray =
JSON.parseArray("[" + res.toString() + "]");
for (Object o : jsonArray) {
com.alibaba.fastjson.JSONObject jsonObject = (com.alibaba.fastjson.JSONObject) o;
com.alibaba.fastjson.JSONObject jsonObject =
(com.alibaba.fastjson.JSONObject) o;
com.alibaba.fastjson.JSONArray data = jsonObject.getJSONArray("data");
Integer conclusionType = jsonObject.getInteger("conclusionType");
if(conclusionType!=null){
if (conclusionType != null) {
if (conclusionType == 2) {
for (Object datum : data) {
com.alibaba.fastjson.JSONObject imgdata = (com.alibaba.fastjson.JSONObject) datum;
com.alibaba.fastjson.JSONObject imgdata =
(com.alibaba.fastjson.JSONObject) datum;
if (imgdata.getInteger("type") == 1) {
Images img = new Images();
img.setImgname(images.getImgname());
@@ -331,29 +372,25 @@ public class UploadServicel {
}
}
}catch (Exception e){
} catch (Exception e) {
System.out.println("图像鉴黄线程执行过程中出现异常");
e.printStackTrace();
}
}
}
//计算时间
public static String plusDay(int setday){
// 计算时间
public static String plusDay(int setday) {
Date d = new Date();
SimpleDateFormat format = new SimpleDateFormat("yyyy-MM-dd HH:mm:ss");
String currdate = format.format(d);
System.out.println("现在的日期是:" + currdate);
Calendar ca = Calendar.getInstance();
ca.setTime(d);
ca.add(Calendar.DATE, setday);// num为增加的天数,可以改变的
ca.add(Calendar.DATE, setday); // num为增加的天数,可以改变的
d = ca.getTime();
String enddate = format.format(d);
System.out.println("到期的日期:" + enddate);
return enddate;
}
}
@@ -3,7 +3,6 @@ package cn.hellohao.service.impl;
import cn.hellohao.dao.CodeMapper;
import cn.hellohao.dao.UserMapper;
import cn.hellohao.exception.CodeException;
import cn.hellohao.pojo.Images;
import cn.hellohao.pojo.User;
import cn.hellohao.service.UserService;
import cn.hellohao.utils.Print;
@@ -42,11 +41,6 @@ public class UserServiceImpl implements UserService {
return userMapper.getUsers(user);
}
@Override
public Integer insertimg(Images img) {
// TODO Auto-generated method stub
return userMapper.insertimg(img);
}
@Override
public Integer change(User user) {
@@ -3,104 +3,107 @@ package cn.hellohao.service.impl;
import cn.hellohao.pojo.Images;
import cn.hellohao.pojo.Keys;
import cn.hellohao.pojo.Msg;
import cn.hellohao.service.IRedisService;
import cn.hellohao.service.ImgAndAlbumService;
import cn.hellohao.service.ImgService;
import cn.hellohao.service.ImgTempService;
import cn.hellohao.utils.LocUpdateImg;
import cn.hellohao.utils.progress.MyProgress;
import com.alibaba.fastjson.JSONObject;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;
import javax.servlet.http.HttpSession;
import java.util.ArrayList;
import java.util.List;
@Service
public class deleImages {
@Autowired private NOSImageupload nosImageupload;
@Autowired private OSSImageupload ossImageupload;
@Autowired private COSImageupload cosImageupload;
@Autowired private KODOImageupload kodoImageupload;
@Autowired private USSImageupload ussImageupload;
@Autowired private UFileImageupload uFileImageupload;
@Autowired private FTPImageupload ftpImageupload;
@Autowired private ImgAndAlbumService imgAndAlbumService;
@Autowired private ImgTempService imgTempService;
@Autowired private ImgService imgService;
@Autowired private KeysServiceImpl keysService;
@Autowired private IRedisService iRedisService;
@Autowired
private NOSImageupload nosImageupload;
@Autowired
private OSSImageupload ossImageupload;
@Autowired
private COSImageupload cosImageupload;
@Autowired
private KODOImageupload kodoImageupload;
@Autowired
private USSImageupload ussImageupload;
@Autowired
private UFileImageupload uFileImageupload;
@Autowired
private FTPImageupload ftpImageupload;
@Autowired
private ImgAndAlbumService imgAndAlbumService;
@Autowired
private ImgTempService imgTempService;
@Autowired
private ImgService imgService;
@Autowired
private KeysServiceImpl keysService;
public Msg dele(HttpSession httpSession,Integer... imgIds) {
Msg msg = new Msg();
MyProgress myProgress = new MyProgress();
myProgress.InitializeDelImg();
List<Integer> ids = new ArrayList<>();
int successCount = 0;
List<String> errorIds = new ArrayList<>();
for (Integer id : imgIds) {
//删除图片
boolean isDele = false;
try {
Images image = imgService.selectByPrimaryKey(id);
Keys key = keysService.selectKeys(image.getSource());
if (key.getStorageType() == 1) {
isDele = nosImageupload.delNOS(key.getId(), image);
} else if (key.getStorageType() == 2) {
isDele = ossImageupload.delOSS(key.getId(), image);
} else if (key.getStorageType() == 3) {
isDele = ussImageupload.delUSS(key.getId(), image);
} else if (key.getStorageType() == 4) {
isDele = kodoImageupload.delKODO(key.getId(), image);
} else if (key.getStorageType() == 5) {
isDele = LocUpdateImg.deleteLOCImg(image);
} else if (key.getStorageType() == 6) {
isDele = cosImageupload.delCOS(key.getId(), image);
} else if (key.getStorageType() == 7) {
isDele = ftpImageupload.delFTP(key.getId(), image);
} else if (key.getStorageType() == 8) {
isDele = uFileImageupload.delUFile(key.getId(), image);
} 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());
}
}
myProgress.setDelSuccessCount(successCount);
myProgress.setDelSuccessImgList(ids);
myProgress.setDelErrorImgListt(errorIds);
if(null !=httpSession){
httpSession.setAttribute("myProgressForDel",myProgress);
}
} catch (Exception e) {
System.err.println("删除的时候发生了一些异常");
e.printStackTrace();
}
public Msg dele(String uuid, Integer... imgIds) {
Msg msg = new Msg();
MyProgress myProgress = new MyProgress();
myProgress.InitializeDelImg();
List<Integer> ids = new ArrayList<>();
int successCount = 0;
List<String> errorIds = new ArrayList<>();
for (int i = 0; i < imgIds.length; i++) {
// 删除图片
boolean isDele = false;
try {
Images image = imgService.selectByPrimaryKey(imgIds[i]);
Keys key = keysService.selectKeys(image.getSource());
if (key.getStorageType() == 1) {
isDele = nosImageupload.delNOS(key.getId(), image);
} else if (key.getStorageType() == 2) {
isDele = ossImageupload.delOSS(key.getId(), image);
} else if (key.getStorageType() == 3) {
isDele = ussImageupload.delUSS(key.getId(), image);
} else if (key.getStorageType() == 4) {
isDele = kodoImageupload.delKODO(key.getId(), image);
} else if (key.getStorageType() == 5) {
isDele = LocUpdateImg.deleteLOCImg(image);
} else if (key.getStorageType() == 6) {
isDele = cosImageupload.delCOS(key.getId(), image);
} else if (key.getStorageType() == 7) {
isDele = ftpImageupload.delFTP(key.getId(), image);
} else if (key.getStorageType() == 8) {
isDele = uFileImageupload.delUFile(key.getId(), image);
} else {
System.err.println("未获取到对象存储参数,删除失败。");
}
myProgress.setDelOCT(true);
msg.setData(ids);
return msg;
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(uuid!=null){
myProgress.setDelSuccessCount(successCount);
myProgress.setDelSuccessImgList(ids);
myProgress.setDelErrorImgListt(errorIds);
if (imgIds.length == (i + 1)) {
myProgress.setDelOCT(1);
} else {
myProgress.setDelOCT(0);
}
iRedisService.setTimeValue(uuid, JSONObject.toJSONString(myProgress), 24L);
}
// if (null != httpSession) {
// httpSession.setAttribute("myProgressForDel", myProgress);
// }
} catch (Exception e) {
System.err.println("删除的时候发生了一些异常");
e.printStackTrace();
}
}
msg.setData(ids);
return msg;
}
public static void main(String[] args) {
MyProgress myProgress = new MyProgress();
myProgress.InitializeDelImg();
System.out.println(JSONObject.toJSONString(myProgress));
}
}
@@ -0,0 +1,98 @@
package cn.hellohao.utils;
import org.springframework.web.multipart.MultipartFile;
import sun.misc.BASE64Decoder;
import java.io.*;
/**
* base64转为multipartFile工具类
* base64Convert
*/
public class Base64ToMultipartFile implements MultipartFile {
private final byte[] imgContent;
private final String header;
public Base64ToMultipartFile (byte[] imgContent, String header) {
this.imgContent = imgContent;
this.header = header.split(";")[0];
}
@Override
public String getName() {
return System.currentTimeMillis() + Math.random() + "." + header.split("/")[1];
}
@Override
public String getOriginalFilename() {
return System.currentTimeMillis() + (int) Math.random() * 10000 + "." + header.split("/")[1];
}
@Override
public String getContentType() {
return header.split(":")[1];
}
@Override
public boolean isEmpty() {
return imgContent == null || imgContent.length == 0;
}
@Override
public long getSize() {
return imgContent.length;
}
@Override
public byte[] getBytes() throws IOException {
return imgContent;
}
@Override
public InputStream getInputStream() throws IOException {
ByteArrayInputStream byteArrayInputStream = new ByteArrayInputStream(imgContent);
// 关闭流,不然文件会一直占用资源,无法对其操作
byteArrayInputStream.close();
return byteArrayInputStream;
}
@Override
public void transferTo(File dest) throws IOException, IllegalStateException {
FileOutputStream fileOutputStream = new FileOutputStream(dest);
fileOutputStream.write(imgContent);
// 关闭流,不然文件会一直占用资源,无法对其操作
fileOutputStream.close();
}
/**
* base64转multipartFile
*
* @param base64
* @return
*/
public static MultipartFile base64Convert(String base64) {
String[] baseStrs = base64.split(",");
BASE64Decoder decoder = new BASE64Decoder();
byte[] b = new byte[0];
try {
b = decoder.decodeBuffer(baseStrs[1]);
} catch (IOException e) {
e.printStackTrace();
}
for (int i = 0; i < b.length; ++i) {
if (b[i] < 0) {
b[i] += 256;
}
}
return new Base64ToMultipartFile (b, baseStrs[0]);
}
}
@@ -97,7 +97,7 @@ public class FirstRun implements InitializingBean {
// Print.Normal("Add imgdata.idname");
// }
RunSqlScript.RunInsert(sql10);
RunSqlScript.RunInsert("alter table `config` modify column `explain` text,modify column `links` text,modify column `notice` text,modify column `baidu` text");
//RunSqlScript.RunInsert("alter table imgdata drop index index_md5key_url");
RunSqlScript.RunInsert(inddx_md5key);
@@ -122,15 +122,13 @@ public class FirstRun implements InitializingBean {
//添加imgdata表字段md5key
private String sql8 = "alter table imgdata add md5key varchar(5000)";
private String sql9 = "ALTER TABLE config ADD theme int(4) DEFAULT '1' COMMENT '主题' ";
//修改字段长度
private String sql10 = "alter table config modify column `explain` varchar(1000),modify column links varchar(1000),modify column notice varchar(1000),modify column baidu varchar(1000)";
// 图片标识名字段
private String sql11 = "alter table `imgdata` add idname varchar(255) DEFAULT '未命名' ;";
private String sql12 = "alter table tbed.user add `token` varchar(255)";
//创建客户端程序相关表
private String createAppclient = "CREATE TABLE `appclient` (`id` varchar(10) NOT NULL,`isuse` varchar(10) NOT NULL,`winpackurl` varchar(255) NULL DEFAULT NULL,`macpackurl` varchar(255) NULL DEFAULT NULL,`appname` varchar(20) NULL,`applogo` varchar(255) NULL,`appupdate` varchar(10) NOT NULL) ";
private String instartAppclient = "INSERT INTO `appclient` VALUES ('app', 'on', NULL, NULL, 'Hellohao图像托管', 'https://hellohao.nos-eastchina1.126.net/TbedClient/app.png', 'off');";
private String instartAppclient = "INSERT INTO `appclient` VALUES ('app', 'on', NULL, NULL, 'Hellohao图像托管', 'https://hellohao.nos-eastchina1.126.net/TbedClient/app.png', '1.0.1');";
private String inddx_md5key = "ALTER TABLE imgdata ADD INDEX index_md5key_url ( md5key,imgurl)";
@@ -14,7 +14,7 @@ import java.util.Map;
* @date 2019/11/7 17:12
*/
public class GetSource {
public static ReturnImage storageSource(Integer type, Map<String, File> fileMap, String userpath,Integer keyID){
public static ReturnImage storageSource(Integer type, Map<Map<String, String>, File> fileMap, String userpath,Integer keyID){
NOSImageupload nosImageupload = SpringContextHolder.getBean(NOSImageupload.class);
OSSImageupload ossImageupload = SpringContextHolder.getBean(OSSImageupload.class);
USSImageupload ussImageupload = SpringContextHolder.getBean(USSImageupload.class);
@@ -4,15 +4,10 @@ import cn.hellohao.config.GlobalConstant;
import cn.hellohao.pojo.Images;
import cn.hellohao.pojo.Keys;
import cn.hellohao.pojo.ReturnImage;
import cn.hellohao.pojo.UploadConfig;
import cn.hellohao.service.impl.KeysServiceImpl;
import org.springframework.web.multipart.MultipartFile;
import java.io.*;
import java.util.Date;
import java.util.HashMap;
import java.util.Map;
import java.util.UUID;
public class LocUpdateImg {
public static boolean deleteLOCImg(Images images){
@@ -20,7 +15,11 @@ public class LocUpdateImg {
try {
String filePath = GlobalConstant.LOCPATH + File.separator+images.getImgname();
File file = new File(filePath);
isDele = file.delete();
if(file.exists()){
isDele = file.delete();
}else{
isDele = true;
}
}catch (Exception e){
e.printStackTrace();
isDele = false;
@@ -28,43 +27,35 @@ public class LocUpdateImg {
return isDele;
}
public static ReturnImage ImageuploadLOC(Map<String, File> fileMap, String username,Integer keyID) throws Exception {
KeysServiceImpl keysService = SpringContextHolder.getBean(KeysServiceImpl.class);
final Keys key = keysService.selectKeys(keyID);
public static ReturnImage ImageuploadLOC(
Map<Map<String, String>, File> fileMap, String username, Integer keyID) {
ReturnImage returnImage = new ReturnImage();
String filePath =GlobalConstant.LOCPATH + File.separator;
File file = null;
for (Map.Entry<String, File> entry : fileMap.entrySet()) {
String ShortUID = SetText.getShortUuid();
System.out.println("待上传的图片:"+username + File.separator + ShortUID + "." + entry.getKey());
File dest = new File(filePath + username + File.separator+ ShortUID + "." + entry.getKey());
File temppath = new File(filePath + username+ File.separator );
String filePath = GlobalConstant.LOCPATH + File.separator;
try {
for (Map.Entry<Map<String, String>, File> entry : fileMap.entrySet()) {
String prefix = entry.getKey().get("prefix");
String ShortUIDName = entry.getKey().get("name");
File dest = new File(filePath + username + File.separator + ShortUIDName + "." + prefix);
if (!dest.getParentFile().exists()) {
dest.getParentFile().mkdirs();
dest.getParentFile().mkdirs();
}
try {
InputStream fileInputStream = new FileInputStream(entry.getValue());
BufferedOutputStream bos = new BufferedOutputStream(new FileOutputStream(dest));
byte[] bs = new byte[1024];
int len;
while ((len = fileInputStream.read(bs)) != -1) {
bos.write(bs, 0, len);
}
bos.flush();
bos.close();
returnImage.setImgname(username + "/" +ShortUID + "." + entry.getKey());//entry.getValue().getOriginalFilename()
returnImage.setImgurl(key.getRequestAddress() +"/ota/"+username + "/" + ShortUID + "." + entry.getKey());
returnImage.setImgSize(entry.getValue().length());
returnImage.setCode("200");
} catch (IOException e) {
e.printStackTrace();
returnImage.setCode("500");
System.err.println("上传失败");
InputStream fileInputStream = new FileInputStream(entry.getValue());
BufferedOutputStream bos = new BufferedOutputStream(new FileOutputStream(dest));
byte[] bs = new byte[1024];
int len;
while ((len = fileInputStream.read(bs)) != -1) {
bos.write(bs, 0, len);
}
bos.flush();
bos.close();
}
returnImage.setCode("200");
} catch (Exception e) {
e.printStackTrace();
returnImage.setCode("500");
System.err.println("上传失败");
}
return returnImage;
}
}
@@ -0,0 +1,50 @@
package cn.hellohao.utils;
/**
* @author Hellohao
* @version 1.0
* @date 2022/7/18 9:49
*/
public class MyVersion {
/**
* 版本号比较
*
* @param v1
* @param v2
* @return 0代表相等,1代表左边大,-1代表右边大
* Utils.compareVersion("1.0.358_20180820090554","1.0.358_20180820090553")=1
*/
public static int compareVersion(String v1, String v2) {
if (v1.equals(v2)) {
return 0;
}
String[] version1Array = v1.split("[._]");
String[] version2Array = v2.split("[._]");
int index = 0;
int minLen = Math.min(version1Array.length, version2Array.length);
long diff = 0;
while (index < minLen
&& (diff = Long.parseLong(version1Array[index])
- Long.parseLong(version2Array[index])) == 0) {
index++;
}
if (diff == 0) {
for (int i = index; i < version1Array.length; i++) {
if (Long.parseLong(version1Array[i]) > 0) {
return 1;
}
}
for (int i = index; i < version2Array.length; i++) {
if (Long.parseLong(version2Array[i]) > 0) {
return -1;
}
}
return 0;
} else {
return diff > 0 ? 1 : -1;
}
}
}
@@ -4,26 +4,22 @@ import java.util.ArrayList;
import java.util.List;
public class MyProgress {
//删除图片时候的数据
private int delSuccessCount=0;//已经成功的个数
private List<String> delErrorImgListt = new ArrayList<>();//已经失败的图片
private boolean delOCT=false; //控制开关
private int delOCT=0; //控制开关
private List<Integer> delSuccessImgList = new ArrayList<>(); //删除成功的图片
public void InitializeDelImg(){
//删除图片时候的数据
this.delSuccessCount=0;//已经成功的个数
this.delErrorImgListt = new ArrayList<>();//已经失败的图片
this.delOCT=false; //控制开关
this.delOCT=0; //控制开关 0代表false 1代表true
this.delSuccessImgList = new ArrayList<>(); //删除成功的图片
}
public MyProgress() {
}
public MyProgress(int delSuccessCount, List<String> delErrorImgListt, boolean delOCT, List<Integer> delSuccessImgList) {
public MyProgress(int delSuccessCount, List<String> delErrorImgListt, int delOCT, List<Integer> delSuccessImgList) {
this.delSuccessCount = delSuccessCount;
this.delErrorImgListt = delErrorImgListt;
this.delOCT = delOCT;
@@ -46,11 +42,11 @@ public class MyProgress {
this.delErrorImgListt = delErrorImgListt;
}
public boolean getDelOCT() {
public int getDelOCT() {
return delOCT;
}
public void setDelOCT(boolean delOCT) {
public void setDelOCT(int delOCT) {
this.delOCT = delOCT;
}
@@ -62,13 +58,5 @@ public class MyProgress {
this.delSuccessImgList = delSuccessImgList;
}
@Override
public String toString() {
return "MyProgress{" +
", delSuccessCount=" + delSuccessCount +
", delErrorImgListt=" + delErrorImgListt +
", delOCT=" + delOCT +
", delSuccessImgList=" + delSuccessImgList +
'}';
}
}
+52 -2
View File
@@ -19,7 +19,8 @@
a.imguid,
a.format,
a.about,
a.violation
a.violation,
a.idname
FROM
imgdata a
LEFT JOIN user b ON a.userid = b.id
@@ -66,9 +67,55 @@
and
a.imguid = #{imguid}
</if>
<if test="idname != null and idname !=''">
and idname LIKE '%${idname}%'
</if>
order by a.id desc
</select>
<insert id="insertImgData" parameterType="cn.hellohao.pojo.Images">
INSERT INTO imgdata (
id,
imgname,
imgurl,
userid,
updatetime,
sizes,
abnormal,
`source`,
imgtype,
explains,
md5key,
imguid,
`format`,
about,
violation,
idname
)
select * from (
SELECT NULL id,
#{imgname} imgname,
#{imgurl} imgurl,
#{userid} userid,
#{updatetime} updatetime,
#{sizes} sizes,
#{abnormal} abnormal,
#{source} `source`,
#{imgtype} imgtype,
#{explains} explains,
#{md5key} md5key,
#{imguid} imguid,
#{format} `format`,
#{about} about,
null violation,
#{idname} idname
) temp_t
where
IF((select (select checkduplicate from sysconfig where id =1)=1),
not exists (select md5key from imgdata img_t where temp_t.md5key = img_t.md5key),true)
</insert>
<!-- 此用户下总数 -->
<select id="countimg" parameterType="integer" resultType="integer">
select count(*) from imgdata where userid = #{userid}
@@ -104,6 +151,9 @@
<if test="explains!=null">
explains=#{explains}
</if>
<if test="idname!=null and idname!=''">
idname=#{idname}
</if>
</set>
where imgname=#{imgname}
</update>
+4 -4
View File
@@ -116,10 +116,10 @@
</select>
<!-- 插入图片信息 -->
<insert id="insertimg" parameterType="cn.hellohao.pojo.Images">
INSERT INTO imgdata (id, imgname, imgurl, userid, updatetime,sizes,abnormal,source,imgtype,md5key,imguid,format,about,violation)
VALUES (NULL, #{imgname}, #{imgurl}, #{userid}, #{updatetime},#{sizes},#{abnormal},#{source},#{imgtype},#{md5key},#{imguid},#{format},#{about},null)
</insert>
<!-- <insert id="insertimg" parameterType="cn.hellohao.pojo.Images">-->
<!-- INSERT INTO imgdata (id, imgname, imgurl, userid, updatetime,sizes,abnormal,source,imgtype,md5key,imguid,format,about,violation)-->
<!-- VALUES (NULL, #{imgname}, #{imgurl}, #{userid}, #{updatetime},#{sizes},#{abnormal},#{source},#{imgtype},#{md5key},#{imguid},#{format},#{about},null)-->
<!-- </insert>-->
<!-- 修改资料 -->
<update id="change" parameterType="cn.hellohao.pojo.User">
+64
View File
@@ -0,0 +1,64 @@
<!doctype html>
<html lang="en" xmlns:th="http://www.thymeleaf.org">
<head>
<meta charset="utf-8">
<title>Welcome</title>
<meta name="viewport" content="width=device-width, initial-scale=1">
<style>
* {
line-height: 1.2;
margin: 0;
}
html {
color: #888;
display: table;
font-family: sans-serif;
height: 100%;
text-align: center;
width: 100%;
}
body {
display: table-cell;
vertical-align: middle;
margin: 2em auto;
}
h1 {
color: #555;
font-size: 2em;
font-weight: 400;
}
p {
margin: 0 auto;
width: 280px;
}
@media only screen and (max-width: 280px) {
body, p {
width: 95%;
}
h1 {
font-size: 1.5em;
margin: 0 0 0.3em;
}
}
</style>
</head>
<body>
<h1 style="font-size: 4.5em;" th:text="'Welcome'"></h1>
<br />
<h3 style="line-height: 80px;" th:text="${name}"></h3>
<p th:text="'服务版本:'+${version}"></p>
<p th:text="'来访者IP'+${ip}"></p>
<a style="font-weight: bold; line-height: 80px;" th:href="'http://'+${links}" th:text="${links}"></a>
</body>
</html>
<!-- IE needs 512+ bytes: https://blogs.msdn.microsoft.com/ieinternals/2010/08/18/friendly-http-error-pages/ -->