mirror of
https://github.com/Hello-hao/Tbed.git
synced 2024-04-21 12:32:10 +00:00
2019-7-16更新 支持本地存储
This commit is contained in:
@@ -4,6 +4,7 @@ import cn.hellohao.pojo.*;
|
||||
import cn.hellohao.pojo.vo.PageResultBean;
|
||||
import cn.hellohao.service.*;
|
||||
import cn.hellohao.service.impl.ImgServiceImpl;
|
||||
import cn.hellohao.utils.LocUpdateImg;
|
||||
import cn.hellohao.utils.StringUtils;
|
||||
import com.alibaba.fastjson.JSONArray;
|
||||
import com.alibaba.fastjson.JSONObject;
|
||||
@@ -104,13 +105,13 @@ public class AdminController {
|
||||
public String getwebconfig(HttpSession session) {
|
||||
JSONObject jsonObject = new JSONObject();
|
||||
Config config = configService.getSourceype();//查询当前系统使用的存储源类型。
|
||||
Keys key = keysService.selectKeys(config.getSourcekey());
|
||||
User u = (User) session.getAttribute("user");
|
||||
Imgreview imgreview = imgreviewService.selectByPrimaryKey(1);
|
||||
jsonObject.put("usercount", imgService.countimg(u.getId()));//这个是根据用户id查询他的图片数
|
||||
jsonObject.put("counts", imgService.counts(null) );//总数
|
||||
jsonObject.put("getusertotal", userService.getUserTotal() );
|
||||
jsonObject.put("imgreviewcount", imgreview.getCount());
|
||||
Keys key= keysService.selectKeys(config.getSourcekey());//然后根据类型再查询key
|
||||
Boolean b = StringUtils.doNull(key);//判断对象是否有空值
|
||||
if(b){
|
||||
jsonObject.put("source", key.getStorageType());
|
||||
@@ -220,9 +221,10 @@ public class AdminController {
|
||||
} else if (key.getStorageType() == 3) {
|
||||
de.delectUSS(key, images.getImgname());
|
||||
} else if (key.getStorageType() == 4) {
|
||||
//初始化七牛云
|
||||
de.delectKODO(key, images.getImgname());
|
||||
} else {
|
||||
} else if (key.getStorageType() == 5) {
|
||||
LocUpdateImg.deleteLOCImg(images.getImgname());
|
||||
}else {
|
||||
System.err.println("未获取到对象存储参数,删除失败。");
|
||||
}
|
||||
Integer ret = imgService.deleimg(id);
|
||||
@@ -263,7 +265,9 @@ public class AdminController {
|
||||
} else if (key.getStorageType() == 4) {
|
||||
//初始化七牛云
|
||||
de.delectKODO(key, images.getImgname());
|
||||
} else {
|
||||
} else if (key.getStorageType() == 5) {
|
||||
LocUpdateImg.deleteLOCImg(images.getImgname());
|
||||
}else {
|
||||
System.err.println("未获取到对象存储参数,删除失败。");
|
||||
}
|
||||
Integer ret = imgService.deleimg(ids[i]);
|
||||
|
||||
@@ -42,26 +42,32 @@ public class AdminRootController {
|
||||
@RequestMapping(value = "tostorage")
|
||||
public String tostorage(HttpSession session, Model model, HttpServletRequest request) {
|
||||
Config config = configService.getSourceype();//查询当前系统使用的存储源类型。
|
||||
Keys key = keysService.selectKeys(config.getSourcekey());
|
||||
Keys key= keysService.selectKeys(config.getSourcekey());//然后根据类型再查询key
|
||||
Boolean b = StringUtils.doNull(key);//判断对象是否有空值
|
||||
Integer StorageType = 0;
|
||||
if(b){
|
||||
//key信息
|
||||
model.addAttribute("AccessKey", key.getAccessKey());
|
||||
model.addAttribute("AccessSecret", key.getAccessSecret());
|
||||
if(config.getSourcekey()!=5){
|
||||
if(b){
|
||||
//key信息
|
||||
model.addAttribute("AccessKey", key.getAccessKey());
|
||||
model.addAttribute("AccessSecret", key.getAccessSecret());
|
||||
|
||||
model.addAttribute("Endpoint", key.getEndpoint());
|
||||
model.addAttribute("Bucketname", key.getBucketname());
|
||||
model.addAttribute("RequestAddress", key.getRequestAddress());
|
||||
model.addAttribute("StorageType", config.getSourcekey());
|
||||
}
|
||||
//如果是4就是七牛
|
||||
if(config.getSourcekey()==4){
|
||||
model.addAttribute("Endpoint2", key.getEndpoint());
|
||||
model.addAttribute("Endpoint", key.getEndpoint());
|
||||
model.addAttribute("Bucketname", key.getBucketname());
|
||||
model.addAttribute("RequestAddress", key.getRequestAddress());
|
||||
model.addAttribute("StorageType", config.getSourcekey());
|
||||
}
|
||||
//如果是4就是七牛
|
||||
if(config.getSourcekey()==4){
|
||||
model.addAttribute("Endpoint2", key.getEndpoint());
|
||||
}else{
|
||||
model.addAttribute("Endpoint2", 0);
|
||||
}
|
||||
}else{
|
||||
model.addAttribute("StorageType", 5);//切换到本地
|
||||
model.addAttribute("Endpoint2", 0);
|
||||
}
|
||||
|
||||
|
||||
return "admin/storageconfig";
|
||||
}
|
||||
|
||||
|
||||
@@ -0,0 +1,35 @@
|
||||
package cn.hellohao.controller;
|
||||
|
||||
import org.springframework.boot.web.servlet.error.ErrorController;
|
||||
import org.springframework.stereotype.Controller;
|
||||
import org.springframework.web.bind.annotation.RequestMapping;
|
||||
|
||||
import javax.servlet.http.HttpServletRequest;
|
||||
|
||||
/**
|
||||
* 错误页面拦截
|
||||
* */
|
||||
|
||||
@Controller
|
||||
class MainsiteErrorController implements ErrorController {
|
||||
|
||||
@RequestMapping("/error")
|
||||
public String handleError(HttpServletRequest request){
|
||||
//获取statusCode:401,404,500
|
||||
Integer statusCode = (Integer) request.getAttribute("javax.servlet.error.status_code");
|
||||
if(statusCode == 401){
|
||||
return "/401";
|
||||
}else if(statusCode == 404){
|
||||
return "/404";
|
||||
}else if(statusCode == 403){
|
||||
return "/403";
|
||||
}else{
|
||||
return "/500";
|
||||
}
|
||||
|
||||
}
|
||||
@Override
|
||||
public String getErrorPath() {
|
||||
return "/error";
|
||||
}
|
||||
}
|
||||
@@ -7,12 +7,12 @@ import java.util.*;
|
||||
import javax.servlet.http.HttpServletRequest;
|
||||
import javax.servlet.http.HttpSession;
|
||||
|
||||
import cn.hellohao.TbedApplication;
|
||||
import cn.hellohao.pojo.*;
|
||||
import cn.hellohao.service.*;
|
||||
import cn.hellohao.service.impl.KODOImageupload;
|
||||
import cn.hellohao.service.impl.OSSImageupload;
|
||||
import cn.hellohao.service.impl.USSImageupload;
|
||||
import cn.hellohao.utils.IPPortUtil;
|
||||
import cn.hellohao.utils.*;
|
||||
import com.alibaba.fastjson.JSONObject;
|
||||
import org.springframework.beans.factory.annotation.Autowired;
|
||||
@@ -47,8 +47,9 @@ public class UpdateImgController {
|
||||
|
||||
@RequestMapping({"/", "/index"})
|
||||
public String indexImg(Model model, HttpSession httpSession) {
|
||||
Print.Normal("欢迎使用Hellohao图床源码。者也许是最好用的java图床项目。");
|
||||
Print.warning("当前项目路径:"+System.getProperty("user.dir"));
|
||||
Config config = configService.getSourceype();//查询当前系统使用的存储源类型。
|
||||
System.out.println("域名:"+config.getDomain());
|
||||
UploadConfig uploadConfig = uploadConfigService.getUpdateConfig();
|
||||
Integer filesizetourists = 0;
|
||||
Integer filesizeuser = 0;
|
||||
@@ -58,8 +59,12 @@ public class UpdateImgController {
|
||||
if(uploadConfig.getFilesizeuser()!=null){filesizeuser = uploadConfig.getFilesizeuser();}
|
||||
if(uploadConfig.getImgcounttourists()!=null){imgcounttourists = uploadConfig.getImgcounttourists();}
|
||||
if(uploadConfig.getImgcountuser()!=null){imgcountuser = uploadConfig.getImgcountuser();}
|
||||
Keys key = keysService.selectKeys(config.getSourcekey());//然后根据类型再查询key
|
||||
Boolean b = StringUtils.doNull(key);//判断对象是否有空值
|
||||
Boolean b =false;
|
||||
Keys key = null;
|
||||
if(config.getSourcekey()!=0 && config.getSourcekey()!=5){
|
||||
key= keysService.selectKeys(config.getSourcekey());//然后根据类型再查询key
|
||||
b = StringUtils.doNull(key);//判断对象是否有空值
|
||||
}
|
||||
if(b)
|
||||
{
|
||||
if(key.getStorageType()!=0 || key.getStorageType()!=null){
|
||||
@@ -151,6 +156,8 @@ public class UpdateImgController {
|
||||
}else if(key.getStorageType()==4){
|
||||
//初始化七牛云
|
||||
m = kodoImageupload.ImageuploadKODO(map, username,null);
|
||||
}else if(key.getStorageType()==5){
|
||||
m = LocUpdateImg.ImageuploadLOC(map, username,null);
|
||||
}else{
|
||||
System.err.println("未获取到对象存储参数,上传失败。");
|
||||
}
|
||||
@@ -159,8 +166,19 @@ public class UpdateImgController {
|
||||
String times = df.format(new Date());
|
||||
System.out.println("上传图片的时间是:"+times);
|
||||
for (Map.Entry<String, Integer> entry : m.entrySet()) {
|
||||
jsonArray.add(entry.getKey());
|
||||
img.setImgurl(entry.getKey());//图片链接
|
||||
if(key.getStorageType()==5){
|
||||
if(config.getDomain()!=null){
|
||||
jsonArray.add(config.getDomain()+"/links/"+entry.getKey());
|
||||
img.setImgurl(config.getDomain()+"/links/"+entry.getKey());//图片链接
|
||||
}else{
|
||||
jsonArray.add(config.getDomain()+"/links/"+entry.getKey());
|
||||
img.setImgurl("http://"+IPPortUtil.getLocalIP()+":"+IPPortUtil.getLocalPort()+"/links/"+entry.getKey());//图片链接
|
||||
}
|
||||
}else{
|
||||
jsonArray.add(entry.getKey());
|
||||
img.setImgurl(entry.getKey());//图片链接
|
||||
}
|
||||
|
||||
img.setUpdatetime(times);
|
||||
img.setSource(key.getStorageType());
|
||||
if (u == null) {
|
||||
@@ -247,10 +265,10 @@ public class UpdateImgController {
|
||||
m = ossImageupload.ImageuploadOSS(null, username,map);
|
||||
}else if(key.getStorageType()==3){
|
||||
m = ussImageupload.ImageuploadUSS(null, username,map);
|
||||
//初始化又拍
|
||||
}else if(key.getStorageType()==4){
|
||||
//初始化七牛云
|
||||
m = kodoImageupload.ImageuploadKODO(null, username,map);
|
||||
}else if(key.getStorageType()==5){
|
||||
m = LocUpdateImg.ImageuploadLOC(null,username,map);
|
||||
}else{
|
||||
System.err.println("未获取到对象存储参数,上传失败。");
|
||||
}
|
||||
@@ -259,8 +277,18 @@ public class UpdateImgController {
|
||||
String times = df.format(new Date());
|
||||
System.out.println("上传图片的时间是:"+times);
|
||||
for (Map.Entry<String, Integer> entry : m.entrySet()) {
|
||||
jsonArray.add(entry.getKey());
|
||||
img.setImgurl(entry.getKey());//图片链接
|
||||
if(key.getStorageType()==5){
|
||||
if(config.getDomain()!=null){
|
||||
jsonArray.add(config.getDomain()+"/links/"+entry.getKey());
|
||||
img.setImgurl(config.getDomain()+"/links/"+entry.getKey());//图片链接
|
||||
}else{
|
||||
jsonArray.add(config.getDomain()+"/links/"+entry.getKey());
|
||||
img.setImgurl("http://"+IPPortUtil.getLocalIP()+":"+IPPortUtil.getLocalPort()+"/links/"+entry.getKey());//图片链接
|
||||
}
|
||||
}else{
|
||||
jsonArray.add(entry.getKey());
|
||||
}
|
||||
//img.setImgurl(entry.getKey());//图片链接
|
||||
img.setUpdatetime(times);
|
||||
img.setSource(key.getStorageType());
|
||||
if (u == null) {
|
||||
@@ -316,10 +344,10 @@ public class UpdateImgController {
|
||||
m = ossImageupload.ImageuploadOSS(null, username,map);
|
||||
}else if(key.getStorageType()==3){
|
||||
m = ussImageupload.ImageuploadUSS(null, username,map);
|
||||
//初始化又拍
|
||||
}else if(key.getStorageType()==4){
|
||||
//初始化七牛云
|
||||
m = kodoImageupload.ImageuploadKODO(null, username,map);
|
||||
}else if(key.getStorageType()==5){
|
||||
m =LocUpdateImg.ImageuploadLOC(null,username, map);
|
||||
}else{
|
||||
System.err.println("未获取到对象存储参数,上传失败。");
|
||||
}
|
||||
@@ -328,8 +356,18 @@ public class UpdateImgController {
|
||||
String times = df.format(new Date());
|
||||
System.out.println("上传图片的时间是:"+times);
|
||||
for (Map.Entry<String, Integer> entry : m.entrySet()) {
|
||||
jsonArray.add(entry.getKey());
|
||||
img.setImgurl(entry.getKey());//图片链接
|
||||
if(key.getStorageType()==5){
|
||||
if(config.getDomain()!=null){
|
||||
jsonArray.add(config.getDomain()+"/links/"+entry.getKey());
|
||||
img.setImgurl(config.getDomain()+"/links/"+entry.getKey());//图片链接
|
||||
}else{
|
||||
jsonArray.add(config.getDomain()+"/links/"+entry.getKey());
|
||||
img.setImgurl("http://"+IPPortUtil.getLocalIP()+":"+IPPortUtil.getLocalPort()+"/links/"+entry.getKey());//图片链接
|
||||
}
|
||||
}else{
|
||||
jsonArray.add(entry.getKey());
|
||||
}
|
||||
//img.setImgurl(entry.getKey());//图片链接
|
||||
img.setUpdatetime(times);
|
||||
img.setSource(key.getStorageType());
|
||||
if (u == null) {
|
||||
|
||||
@@ -0,0 +1,28 @@
|
||||
package cn.hellohao.test;
|
||||
|
||||
import cn.hellohao.utils.Print;
|
||||
|
||||
import java.io.File;
|
||||
|
||||
public class test1 {
|
||||
private static void deleteDirectory(File file) {
|
||||
if (file.isFile()) {// 表示该文件不是文件夹
|
||||
file.delete();
|
||||
} else {
|
||||
// 首先得到当前的路径
|
||||
String[] childFilePaths = file.list();
|
||||
for (String childFilePath : childFilePaths) {
|
||||
String filePath =File.separator + "HellohaoData" + File.separator;
|
||||
File childFile = new File(filePath + "admin"+ File.separator);
|
||||
deleteDirectory(childFile);
|
||||
}
|
||||
file.delete();
|
||||
}
|
||||
}
|
||||
|
||||
public static void main(String[] args) {
|
||||
|
||||
Print.warning(System.getProperty("user.dir"));
|
||||
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,54 @@
|
||||
package cn.hellohao.utils;
|
||||
|
||||
import javax.management.MBeanServer;
|
||||
import javax.management.MalformedObjectNameException;
|
||||
import javax.management.ObjectName;
|
||||
import javax.management.Query;
|
||||
import java.lang.management.ManagementFactory;
|
||||
import java.net.InetAddress;
|
||||
import java.util.Set;
|
||||
|
||||
|
||||
public class IPPortUtil {
|
||||
|
||||
public static void main(String[] args)throws Exception {
|
||||
Print.warning(IPPortUtil.getLocalIP());
|
||||
Print.warning(IPPortUtil.getLocalPort());
|
||||
}
|
||||
/**
|
||||
* @return
|
||||
* @throws MalformedObjectNameException
|
||||
* 获取当前机器的端口号
|
||||
*/
|
||||
public static String getLocalPort() throws MalformedObjectNameException {
|
||||
MBeanServer beanServer = ManagementFactory.getPlatformMBeanServer();
|
||||
Set<ObjectName> objectNames = beanServer.queryNames(new ObjectName("*:type=Connector,*"),
|
||||
Query.match(Query.attr("protocol"), Query.value("HTTP/1.1")));
|
||||
String port = objectNames.iterator().next().getKeyProperty("port");
|
||||
return port;
|
||||
}
|
||||
|
||||
/**
|
||||
* @return
|
||||
* 获取当前机器的IP
|
||||
*/
|
||||
public static String getLocalIP() {
|
||||
InetAddress addr = null;
|
||||
try {
|
||||
addr = InetAddress.getLocalHost();
|
||||
} catch (Exception e) {
|
||||
e.printStackTrace();
|
||||
}
|
||||
|
||||
|
||||
byte[] ipAddr = addr.getAddress();
|
||||
String ipAddrStr = "";
|
||||
for (int i = 0; i < ipAddr.length; i++) {
|
||||
if (i > 0) {
|
||||
ipAddrStr += ".";
|
||||
}
|
||||
ipAddrStr += ipAddr[i] & 0xFF;
|
||||
}
|
||||
return ipAddrStr;
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user