diff --git "a/00fly-Web\346\226\207\344\273\266\345\217\212\346\226\207\346\234\254\345\205\261\344\272\253\345\267\245\345\205\267/Dockerfile" "b/00fly-Web\346\226\207\344\273\266\345\217\212\346\226\207\346\234\254\345\205\261\344\272\253\345\267\245\345\205\267/Dockerfile" new file mode 100644 index 0000000000000000000000000000000000000000..bb9266fa47b6cd22754af2634cbbefc4eda1bcfb --- /dev/null +++ "b/00fly-Web\346\226\207\344\273\266\345\217\212\346\226\207\346\234\254\345\205\261\344\272\253\345\267\245\345\205\267/Dockerfile" @@ -0,0 +1,14 @@ +#基础镜像 +FROM adoptopenjdk/openjdk8-openj9:alpine-slim + +RUN ln -sf /usr/share/zoneinfo/Asia/Shanghai /etc/localtime && echo 'Asia/Shanghai' >/etc/timezone + +#拷贝发布包 +COPY target/*.jar /app.jar + +EXPOSE 8080 + +CMD ["--server.port=8080"] + +#启动脚本 +ENTRYPOINT ["java", "-Djava.security.egd=file:/dev/./urandom", "-Xshareclasses", "-Xquickstart", "-jar", "/app.jar"] diff --git "a/00fly-Web\346\226\207\344\273\266\345\217\212\346\226\207\346\234\254\345\205\261\344\272\253\345\267\245\345\205\267/README.md" "b/00fly-Web\346\226\207\344\273\266\345\217\212\346\226\207\346\234\254\345\205\261\344\272\253\345\267\245\345\205\267/README.md" new file mode 100644 index 0000000000000000000000000000000000000000..17e68c3ad4d3cfc7a6902429db25ae5a49f1f8b5 --- /dev/null +++ "b/00fly-Web\346\226\207\344\273\266\345\217\212\346\226\207\346\234\254\345\205\261\344\272\253\345\267\245\345\205\267/README.md" @@ -0,0 +1,4 @@ +# Web文件共享工具 + + +功能演示: http://124.71.129.204:8080/ \ No newline at end of file diff --git "a/00fly-Web\346\226\207\344\273\266\345\217\212\346\226\207\346\234\254\345\205\261\344\272\253\345\267\245\345\205\267/docker/docker-compose.yml" "b/00fly-Web\346\226\207\344\273\266\345\217\212\346\226\207\346\234\254\345\205\261\344\272\253\345\267\245\345\205\267/docker/docker-compose.yml" new file mode 100644 index 0000000000000000000000000000000000000000..1ee5ef7d6d66ffc4e000e27c1cb2d38e4b8c07e7 --- /dev/null +++ "b/00fly-Web\346\226\207\344\273\266\345\217\212\346\226\207\346\234\254\345\205\261\344\272\253\345\267\245\345\205\267/docker/docker-compose.yml" @@ -0,0 +1,25 @@ +version: '3.7' +services: + luck-share: + image: registry.cn-shanghai.aliyuncs.com/00fly/springboot-luck-share:1.1.0 + container_name: luck-share + deploy: + resources: + limits: + cpus: '1' + memory: 200M + reservations: + cpus: '0.05' + memory: 200M + ports: + - 8080:8080 + environment: + TOKEN_VALIDE_HOURS: 3 + SYSTEM_AUTO_LOGIN: true + restart: on-failure + logging: + driver: json-file + options: + max-size: 5m + max-file: '1' + diff --git "a/00fly-Web\346\226\207\344\273\266\345\217\212\346\226\207\346\234\254\345\205\261\344\272\253\345\267\245\345\205\267/docker/restart.sh" "b/00fly-Web\346\226\207\344\273\266\345\217\212\346\226\207\346\234\254\345\205\261\344\272\253\345\267\245\345\205\267/docker/restart.sh" new file mode 100644 index 0000000000000000000000000000000000000000..1a8d9fa7d2fa48ab80a12dfcbbe9bb9b1a4f6e1a --- /dev/null +++ "b/00fly-Web\346\226\207\344\273\266\345\217\212\346\226\207\346\234\254\345\205\261\344\272\253\345\267\245\345\205\267/docker/restart.sh" @@ -0,0 +1,4 @@ +#!/bin/bash +docker-compose down && docker system prune -f && docker-compose --compatibility up -d + + diff --git "a/00fly-Web\346\226\207\344\273\266\345\217\212\346\226\207\346\234\254\345\205\261\344\272\253\345\267\245\345\205\267/docker/stop.sh" "b/00fly-Web\346\226\207\344\273\266\345\217\212\346\226\207\346\234\254\345\205\261\344\272\253\345\267\245\345\205\267/docker/stop.sh" new file mode 100644 index 0000000000000000000000000000000000000000..48fce7b76cd5c2dba453f05adabfe538dca46403 --- /dev/null +++ "b/00fly-Web\346\226\207\344\273\266\345\217\212\346\226\207\346\234\254\345\205\261\344\272\253\345\267\245\345\205\267/docker/stop.sh" @@ -0,0 +1,3 @@ +#!/bin/bash +docker-compose down + diff --git "a/00fly-Web\346\226\207\344\273\266\345\217\212\346\226\207\346\234\254\345\205\261\344\272\253\345\267\245\345\205\267/pom.xml" "b/00fly-Web\346\226\207\344\273\266\345\217\212\346\226\207\346\234\254\345\205\261\344\272\253\345\267\245\345\205\267/pom.xml" new file mode 100644 index 0000000000000000000000000000000000000000..85306bab8651b57627d7609008e0729eb96f2fb4 --- /dev/null +++ "b/00fly-Web\346\226\207\344\273\266\345\217\212\346\226\207\346\234\254\345\205\261\344\272\253\345\267\245\345\205\267/pom.xml" @@ -0,0 +1,147 @@ + + + 4.0.0 + com.fly + springboot-luck-share + 1.1.0 + jar + + + org.springframework.boot + spring-boot-starter-parent + 2.2.4.RELEASE + + + + + UTF-8 + yyyyMMdd-HH + registry.cn-shanghai.aliyuncs.com + 1.8 + true + + + + + + org.springframework.boot + spring-boot-starter-web + + + org.apache.tomcat.embed + tomcat-embed-websocket + + + org.springframework.boot + spring-boot-starter-logging + + + + + org.springframework.boot + spring-boot-starter-log4j2 + + + org.springframework.boot + spring-boot-starter-thymeleaf + + + com.github.xiaoymin + knife4j-spring-boot-starter + 2.0.8 + + + com.google.zxing + core + 3.4.0 + + + + org.apache.commons + commons-lang3 + + + commons-io + commons-io + 2.15.0 + + + org.projectlombok + lombok + provided + + + org.springframework.boot + spring-boot-devtools + true + + + + + ${project.artifactId}-${project.version} + + + org.springframework.boot + spring-boot-maven-plugin + + + + org.projectlombok + lombok + + + + + + + io.fabric8 + docker-maven-plugin + 0.40.3 + + + package + + build + push + remove + + + + + + + + ${docker.hub} + + + + + ${docker.hub}/00fly/${project.artifactId}:${project.version} + + + ${project.basedir} + + + + + + + + + src/main/java + + **/*.java + + + + src/main/resources + + **/** + + false + + + + diff --git "a/00fly-Web\346\226\207\344\273\266\345\217\212\346\226\207\346\234\254\345\205\261\344\272\253\345\267\245\345\205\267/src/main/java/com/fly/FilesSendBootApplication.java" "b/00fly-Web\346\226\207\344\273\266\345\217\212\346\226\207\346\234\254\345\205\261\344\272\253\345\267\245\345\205\267/src/main/java/com/fly/FilesSendBootApplication.java" new file mode 100644 index 0000000000000000000000000000000000000000..89a369ed0965c9f5196db26335cc131fcc6ff0a2 --- /dev/null +++ "b/00fly-Web\346\226\207\344\273\266\345\217\212\346\226\207\346\234\254\345\205\261\344\272\253\345\267\245\345\205\267/src/main/java/com/fly/FilesSendBootApplication.java" @@ -0,0 +1,37 @@ +package com.fly; + +import java.net.InetAddress; + +import org.apache.commons.lang3.SystemUtils; +import org.springframework.beans.factory.annotation.Value; +import org.springframework.boot.CommandLineRunner; +import org.springframework.boot.SpringApplication; +import org.springframework.boot.autoconfigure.SpringBootApplication; +import org.springframework.boot.autoconfigure.condition.ConditionalOnWebApplication; +import org.springframework.context.annotation.Bean; + +@SpringBootApplication +public class FilesSendBootApplication +{ + @Value("${server.port}") + String port; + + public static void main(String[] args) + { + SpringApplication.run(FilesSendBootApplication.class, args); + } + + @Bean + @ConditionalOnWebApplication + CommandLineRunner init() + { + return args -> { + if (SystemUtils.IS_OS_WINDOWS)// 防止非windows系统报错,启动失败 + { + String ip = InetAddress.getLocalHost().getHostAddress(); + String url = "http://" + ip + ":" + port; + Runtime.getRuntime().exec("cmd /c start " + url); + } + }; + } +} diff --git "a/00fly-Web\346\226\207\344\273\266\345\217\212\346\226\207\346\234\254\345\205\261\344\272\253\345\267\245\345\205\267/src/main/java/com/fly/core/auth/AuthInterceptor.java" "b/00fly-Web\346\226\207\344\273\266\345\217\212\346\226\207\346\234\254\345\205\261\344\272\253\345\267\245\345\205\267/src/main/java/com/fly/core/auth/AuthInterceptor.java" new file mode 100644 index 0000000000000000000000000000000000000000..5b3b7ce16f142b3488f85cd78c6283ba92e90731 --- /dev/null +++ "b/00fly-Web\346\226\207\344\273\266\345\217\212\346\226\207\346\234\254\345\205\261\344\272\253\345\267\245\345\205\267/src/main/java/com/fly/core/auth/AuthInterceptor.java" @@ -0,0 +1,49 @@ +package com.fly.core.auth; + +import java.nio.charset.StandardCharsets; + +import javax.servlet.http.HttpServletRequest; +import javax.servlet.http.HttpServletResponse; + +import org.springframework.beans.factory.annotation.Autowired; +import org.springframework.http.MediaType; +import org.springframework.stereotype.Component; +import org.springframework.web.servlet.handler.HandlerInterceptorAdapter; + +import com.fasterxml.jackson.databind.ObjectMapper; +import com.fly.filesend.entity.JsonResult; +import com.fly.filesend.service.TokenService; + +/** + * + * AuthInterceptor + * + * @author 00fly + * @version [版本号, 2019年7月21日] + * @see [相关类/方法] + * @since [产品/模块版本] + */ +@Component +public class AuthInterceptor extends HandlerInterceptorAdapter +{ + @Autowired + TokenService tokenService; + + private ObjectMapper mapper = new ObjectMapper(); + + @Override + public boolean preHandle(HttpServletRequest request, HttpServletResponse response, Object handler) + throws Exception + { + String token = (String)request.getSession().getAttribute("token"); + if (!tokenService.valide(token)) + { + JsonResult> result = JsonResult.error("系统登录状态失效,请重新登录"); + response.setContentType(MediaType.APPLICATION_JSON_VALUE); + response.setCharacterEncoding(StandardCharsets.UTF_8.toString()); + response.getWriter().print(mapper.writeValueAsString(result)); + return false; + } + return true; + } +} \ No newline at end of file diff --git "a/00fly-Web\346\226\207\344\273\266\345\217\212\346\226\207\346\234\254\345\205\261\344\272\253\345\267\245\345\205\267/src/main/java/com/fly/core/config/Knife4jConfig.java" "b/00fly-Web\346\226\207\344\273\266\345\217\212\346\226\207\346\234\254\345\205\261\344\272\253\345\267\245\345\205\267/src/main/java/com/fly/core/config/Knife4jConfig.java" new file mode 100644 index 0000000000000000000000000000000000000000..0b01668fc3b90152cc96f426ca4996a339c29900 --- /dev/null +++ "b/00fly-Web\346\226\207\344\273\266\345\217\212\346\226\207\346\234\254\345\205\261\344\272\253\345\267\245\345\205\267/src/main/java/com/fly/core/config/Knife4jConfig.java" @@ -0,0 +1,62 @@ +package com.fly.core.config; + +import java.util.Collections; +import java.util.List; + +import org.springframework.boot.autoconfigure.condition.ConditionalOnWebApplication; +import org.springframework.context.annotation.Bean; +import org.springframework.context.annotation.Configuration; +import org.springframework.context.annotation.Import; + +import com.github.xiaoymin.knife4j.spring.annotations.EnableKnife4j; + +import io.swagger.annotations.ApiOperation; +import springfox.bean.validators.configuration.BeanValidatorPluginsConfiguration; +import springfox.documentation.builders.ApiInfoBuilder; +import springfox.documentation.builders.PathSelectors; +import springfox.documentation.builders.RequestHandlerSelectors; +import springfox.documentation.service.ApiInfo; +import springfox.documentation.service.ApiKey; +import springfox.documentation.spi.DocumentationType; +import springfox.documentation.spring.web.plugins.Docket; +import springfox.documentation.swagger2.annotations.EnableSwagger2WebMvc; + +/** + * Knife4jConfig + * + */ +@EnableKnife4j +@Configuration +@EnableSwagger2WebMvc +@ConditionalOnWebApplication +@Import(BeanValidatorPluginsConfiguration.class) +public class Knife4jConfig +{ + /** + * 开发、测试环境接口文档打开 + * + * @return + * @see [类、类#方法、类#成员] + */ + @Bean + Docket createRestApi() + { + return new Docket(DocumentationType.SWAGGER_2).apiInfo(apiInfo()) + .enable(true) + .select() + .apis(RequestHandlerSelectors.withMethodAnnotation(ApiOperation.class)) + .paths(PathSelectors.any()) // 包下的类,生成接口文档 + .build() + .securitySchemes(security()); + } + + private ApiInfo apiInfo() + { + return new ApiInfoBuilder().title("数据接口API").description("接口文档").termsOfServiceUrl("http://00fly.online/").version("1.0.0").build(); + } + + private List security() + { + return Collections.singletonList(new ApiKey("token", "token", "header")); + } +} \ No newline at end of file diff --git "a/00fly-Web\346\226\207\344\273\266\345\217\212\346\226\207\346\234\254\345\205\261\344\272\253\345\267\245\345\205\267/src/main/java/com/fly/core/config/WebMvcConfig.java" "b/00fly-Web\346\226\207\344\273\266\345\217\212\346\226\207\346\234\254\345\205\261\344\272\253\345\267\245\345\205\267/src/main/java/com/fly/core/config/WebMvcConfig.java" new file mode 100644 index 0000000000000000000000000000000000000000..e96bd8e38cf2a754424f8d1cc14a3800390a7724 --- /dev/null +++ "b/00fly-Web\346\226\207\344\273\266\345\217\212\346\226\207\346\234\254\345\205\261\344\272\253\345\267\245\345\205\267/src/main/java/com/fly/core/config/WebMvcConfig.java" @@ -0,0 +1,98 @@ +package com.fly.core.config; + +import java.util.ArrayList; +import java.util.List; +import java.util.Map; +import java.util.concurrent.ConcurrentHashMap; + +import org.springframework.beans.factory.annotation.Autowired; +import org.springframework.boot.autoconfigure.condition.ConditionalOnWebApplication; +import org.springframework.context.annotation.Bean; +import org.springframework.context.annotation.Configuration; +import org.springframework.http.MediaType; +import org.springframework.http.converter.HttpMessageConverter; +import org.springframework.http.converter.StringHttpMessageConverter; +import org.springframework.http.converter.json.MappingJackson2HttpMessageConverter; +import org.springframework.web.servlet.config.annotation.ContentNegotiationConfigurer; +import org.springframework.web.servlet.config.annotation.InterceptorRegistry; +import org.springframework.web.servlet.config.annotation.ViewControllerRegistry; +import org.springframework.web.servlet.config.annotation.WebMvcConfigurer; + +import com.fly.core.auth.AuthInterceptor; + +/** + * + * mvc配置 + * + * @author 00fly + * @version [版本号, 2021年4月23日] + * @see [相关类/方法] + * @since [产品/模块版本] + */ +@Configuration +@ConditionalOnWebApplication +public class WebMvcConfig implements WebMvcConfigurer +{ + @Autowired + private AuthInterceptor authInterceptor; + + @Override + public void configureMessageConverters(final List> converters) + { + converters.add(stringHttpMessageConverter()); + converters.add(mappingJackson2HttpMessageConverter()); + } + + @Override + public void configureContentNegotiation(final ContentNegotiationConfigurer configurer) + { + configurer.defaultContentType(MediaType.APPLICATION_JSON); + configurer.ignoreUnknownPathExtensions(false); + configurer.favorPathExtension(true); + configurer.favorParameter(false); + final Map mediaTypes = new ConcurrentHashMap<>(3); + mediaTypes.put("atom", MediaType.APPLICATION_ATOM_XML); + mediaTypes.put("html", MediaType.TEXT_HTML); + mediaTypes.put("json", MediaType.APPLICATION_JSON); + configurer.mediaTypes(mediaTypes); + } + + @Bean + StringHttpMessageConverter stringHttpMessageConverter() + { + return new StringHttpMessageConverter(); + } + + @Bean + MappingJackson2HttpMessageConverter mappingJackson2HttpMessageConverter() + { + final MappingJackson2HttpMessageConverter messageConverter = new MappingJackson2HttpMessageConverter(); + final List list = new ArrayList<>(); + list.add(MediaType.APPLICATION_JSON); + list.add(MediaType.APPLICATION_XML); + list.add(MediaType.TEXT_PLAIN); + list.add(MediaType.TEXT_HTML); + list.add(MediaType.TEXT_XML); + messageConverter.setSupportedMediaTypes(list); + return messageConverter; + } + + /** + * 等价于mvc中 + * 等价于mvc中 + * + * @param registry + */ + @Override + public void addViewControllers(final ViewControllerRegistry registry) + { + // registry.addViewController("/").setViewName("redirect:index"); + // registry.addViewController("/index").setViewName("index.html"); + } + + @Override + public void addInterceptors(InterceptorRegistry registry) + { + registry.addInterceptor(authInterceptor).addPathPatterns("/rest/file/**", "/file/**"); + } +} diff --git "a/00fly-Web\346\226\207\344\273\266\345\217\212\346\226\207\346\234\254\345\205\261\344\272\253\345\267\245\345\205\267/src/main/java/com/fly/core/exception/GlobalExceptionHandler.java" "b/00fly-Web\346\226\207\344\273\266\345\217\212\346\226\207\346\234\254\345\205\261\344\272\253\345\267\245\345\205\267/src/main/java/com/fly/core/exception/GlobalExceptionHandler.java" new file mode 100644 index 0000000000000000000000000000000000000000..529fe06bd2a9731e0f6df2cc705f023f46c63af6 --- /dev/null +++ "b/00fly-Web\346\226\207\344\273\266\345\217\212\346\226\207\346\234\254\345\205\261\344\272\253\345\267\245\345\205\267/src/main/java/com/fly/core/exception/GlobalExceptionHandler.java" @@ -0,0 +1,63 @@ +package com.fly.core.exception; + +import java.util.ArrayList; +import java.util.Collections; +import java.util.List; + +import org.apache.commons.lang3.StringUtils; +import org.springframework.validation.BindException; +import org.springframework.validation.BindingResult; +import org.springframework.web.bind.MethodArgumentNotValidException; +import org.springframework.web.bind.annotation.ExceptionHandler; +import org.springframework.web.bind.annotation.RestControllerAdvice; + +import com.fly.filesend.entity.JsonResult; + +import lombok.extern.slf4j.Slf4j; + +/** + * 统一异常处理器 + * + * @author 00fly + * @version [版本号, 2018-09-11] + * @see [相关类/方法] + * @since [产品/模块版本] + */ +@Slf4j +@RestControllerAdvice +public class GlobalExceptionHandler +{ + @ExceptionHandler(value = Exception.class) + public JsonResult> handleBadRequest(Exception exception) + { + // JSR303参数校验异常 + if (exception instanceof BindException) + { + BindingResult bindingResult = ((BindException)exception).getBindingResult(); + if (null != bindingResult && bindingResult.hasErrors()) + { + List errMsg = new ArrayList<>(); + bindingResult.getFieldErrors().stream().forEach(fieldError -> { + errMsg.add(fieldError.getDefaultMessage()); + }); + Collections.sort(errMsg); + return JsonResult.error(StringUtils.join(errMsg, ",")); + } + } + if (exception instanceof MethodArgumentNotValidException) + { + BindingResult bindingResult = ((MethodArgumentNotValidException)exception).getBindingResult(); + if (null != bindingResult && bindingResult.hasErrors()) + { + List errMsg = new ArrayList<>(); + bindingResult.getFieldErrors().stream().forEach(fieldError -> { + errMsg.add(fieldError.getDefaultMessage()); + }); + return JsonResult.error(StringUtils.join(errMsg, ",")); + } + } + // 其余情况 + log.error("Error: handleBadRequest StackTrace : {}", exception); + return JsonResult.error(StringUtils.defaultString(exception.getMessage(), "系统异常,请联系管理员")); + } +} diff --git "a/00fly-Web\346\226\207\344\273\266\345\217\212\346\226\207\346\234\254\345\205\261\344\272\253\345\267\245\345\205\267/src/main/java/com/fly/core/exception/ValidateException.java" "b/00fly-Web\346\226\207\344\273\266\345\217\212\346\226\207\346\234\254\345\205\261\344\272\253\345\267\245\345\205\267/src/main/java/com/fly/core/exception/ValidateException.java" new file mode 100644 index 0000000000000000000000000000000000000000..9d6c15f35c8be0da277eb45db22d4e0313946a2c --- /dev/null +++ "b/00fly-Web\346\226\207\344\273\266\345\217\212\346\226\207\346\234\254\345\205\261\344\272\253\345\267\245\345\205\267/src/main/java/com/fly/core/exception/ValidateException.java" @@ -0,0 +1,16 @@ +package com.fly.core.exception; + +public class ValidateException extends RuntimeException +{ + private static final long serialVersionUID = -939208231165751812L; + + public ValidateException() + { + super(); + } + + public ValidateException(String message) + { + super(message); + } +} diff --git "a/00fly-Web\346\226\207\344\273\266\345\217\212\346\226\207\346\234\254\345\205\261\344\272\253\345\267\245\345\205\267/src/main/java/com/fly/core/qr/BufferedImageLuminanceSource.java" "b/00fly-Web\346\226\207\344\273\266\345\217\212\346\226\207\346\234\254\345\205\261\344\272\253\345\267\245\345\205\267/src/main/java/com/fly/core/qr/BufferedImageLuminanceSource.java" new file mode 100644 index 0000000000000000000000000000000000000000..67c67d800cd86d3e0b1e366e045b37ca022a8365 --- /dev/null +++ "b/00fly-Web\346\226\207\344\273\266\345\217\212\346\226\207\346\234\254\345\205\261\344\272\253\345\267\245\345\205\267/src/main/java/com/fly/core/qr/BufferedImageLuminanceSource.java" @@ -0,0 +1,108 @@ +package com.fly.core.qr; + +import java.awt.Graphics2D; +import java.awt.geom.AffineTransform; +import java.awt.image.BufferedImage; + +import com.google.zxing.LuminanceSource; + +public class BufferedImageLuminanceSource extends LuminanceSource +{ + private BufferedImage image; + + private int left; + + private int top; + + public BufferedImageLuminanceSource(BufferedImage image) + { + this(image, 0, 0, image.getWidth(), image.getHeight()); + } + + public BufferedImageLuminanceSource(BufferedImage image, int left, int top, int width, int height) + { + super(width, height); + + int sourceWidth = image.getWidth(); + int sourceHeight = image.getHeight(); + if (left + width > sourceWidth || top + height > sourceHeight) + { + throw new IllegalArgumentException("Crop rectangle does not fit within image data."); + } + + for (int y = top; y < top + height; y++) + { + for (int x = left; x < left + width; x++) + { + if ((image.getRGB(x, y) & 0xFF000000) == 0) + { + image.setRGB(x, y, 0xFFFFFFFF); + } + } + } + + this.image = new BufferedImage(sourceWidth, sourceHeight, BufferedImage.TYPE_BYTE_GRAY); + this.image.getGraphics().drawImage(image, 0, 0, null); + this.left = left; + this.top = top; + } + + @Override + public byte[] getRow(int y, byte[] row) + { + if (y < 0 || y >= getHeight()) + { + throw new IllegalArgumentException("Requested row is outside the image: " + y); + } + int width = getWidth(); + if (row == null || row.length < width) + { + row = new byte[width]; + } + image.getRaster().getDataElements(left, top + y, width, 1, row); + return row; + } + + @Override + public byte[] getMatrix() + { + int width = getWidth(); + int height = getHeight(); + int area = width * height; + byte[] matrix = new byte[area]; + image.getRaster().getDataElements(left, top, width, height, matrix); + return matrix; + } + + @Override + public boolean isCropSupported() + { + return true; + } + + @Override + public LuminanceSource crop(int left, int top, int width, int height) + { + return new BufferedImageLuminanceSource(image, this.left + left, this.top + top, width, height); + } + + @Override + public boolean isRotateSupported() + { + return true; + } + + @Override + public LuminanceSource rotateCounterClockwise() + { + int sourceWidth = image.getWidth(); + int sourceHeight = image.getHeight(); + AffineTransform transform = new AffineTransform(0.0, -1.0, 1.0, 0.0, 0.0, sourceWidth); + BufferedImage rotatedImage = new BufferedImage(sourceHeight, sourceWidth, BufferedImage.TYPE_BYTE_GRAY); + Graphics2D g = rotatedImage.createGraphics(); + g.drawImage(image, transform, null); + g.dispose(); + int width = getWidth(); + return new BufferedImageLuminanceSource(rotatedImage, top, sourceWidth - (left + width), getHeight(), width); + } +} \ No newline at end of file diff --git "a/00fly-Web\346\226\207\344\273\266\345\217\212\346\226\207\346\234\254\345\205\261\344\272\253\345\267\245\345\205\267/src/main/java/com/fly/core/qr/QRCodeUtil.java" "b/00fly-Web\346\226\207\344\273\266\345\217\212\346\226\207\346\234\254\345\205\261\344\272\253\345\267\245\345\205\267/src/main/java/com/fly/core/qr/QRCodeUtil.java" new file mode 100644 index 0000000000000000000000000000000000000000..78ac279203a8c9b7723349b0912fe6789a11226d --- /dev/null +++ "b/00fly-Web\346\226\207\344\273\266\345\217\212\346\226\207\346\234\254\345\205\261\344\272\253\345\267\245\345\205\267/src/main/java/com/fly/core/qr/QRCodeUtil.java" @@ -0,0 +1,153 @@ +package com.fly.core.qr; + +import java.awt.BasicStroke; +import java.awt.Graphics; +import java.awt.Graphics2D; +import java.awt.Image; +import java.awt.Shape; +import java.awt.geom.RoundRectangle2D; +import java.awt.image.BufferedImage; +import java.io.File; +import java.net.URL; +import java.nio.charset.StandardCharsets; +import java.util.Hashtable; + +import javax.imageio.ImageIO; + +import com.google.zxing.BarcodeFormat; +import com.google.zxing.BinaryBitmap; +import com.google.zxing.DecodeHintType; +import com.google.zxing.EncodeHintType; +import com.google.zxing.MultiFormatReader; +import com.google.zxing.MultiFormatWriter; +import com.google.zxing.Result; +import com.google.zxing.common.BitMatrix; +import com.google.zxing.common.HybridBinarizer; +import com.google.zxing.qrcode.decoder.ErrorCorrectionLevel; + +public class QRCodeUtil +{ + /** + * 二维码尺寸 + */ + private static final int QRCODE_SIZE = 300; + + /** + * LOGO宽度 + */ + private static final int WIDTH = 60; + + /** + * LOGO高度 + */ + private static final int HEIGHT = 60; + + /** + * 给定内容、图标生成二维码图片 + * + * @param content 內容 + * @param imgURL 图标 + * @param needCompress 是否压缩尺寸 + * @return + * @throws Exception + * @see [类、类#方法、类#成员] + */ + public static BufferedImage createImage(String content, URL imgURL, boolean needCompress) + throws Exception + { + Hashtable hints = new Hashtable<>(); + hints.put(EncodeHintType.ERROR_CORRECTION, ErrorCorrectionLevel.H); + hints.put(EncodeHintType.CHARACTER_SET, StandardCharsets.UTF_8); + hints.put(EncodeHintType.MARGIN, 1); + BitMatrix bitMatrix = new MultiFormatWriter().encode(content, BarcodeFormat.QR_CODE, QRCODE_SIZE, QRCODE_SIZE, hints); + int width = bitMatrix.getWidth(); + int height = bitMatrix.getHeight(); + BufferedImage image = new BufferedImage(width, height, BufferedImage.TYPE_INT_RGB); + for (int x = 0; x < width; x++) + { + for (int y = 0; y < height; y++) + { + image.setRGB(x, y, bitMatrix.get(x, y) ? 0xFF000000 : 0xFFFFFFFF); + } + } + if (imgURL == null) + { + return image; + } + // 插入图片 + insertImage(image, imgURL, needCompress); + return image; + } + + private static void insertImage(BufferedImage source, URL imgURL, boolean needCompress) + throws Exception + { + if (imgURL == null) + { + System.err.println("文件不存在!"); + return; + } + Image src = ImageIO.read(imgURL); + int width = src.getWidth(null); + int height = src.getHeight(null); + if (needCompress) + { + // 压缩LOGO + width = Math.min(width, WIDTH); + height = Math.min(height, HEIGHT); + Image image = src.getScaledInstance(width, height, Image.SCALE_SMOOTH); + BufferedImage tag = new BufferedImage(width, height, BufferedImage.TYPE_INT_RGB); + Graphics g = tag.getGraphics(); + g.drawImage(image, 0, 0, null); + g.dispose(); + src = image; + } + // 插入LOGO + Graphics2D graph = source.createGraphics(); + int x = (QRCODE_SIZE - width) / 2; + int y = (QRCODE_SIZE - height) / 2; + graph.drawImage(src, x, y, width, height, null); + Shape shape = new RoundRectangle2D.Float(x, y, width, width, 6, 6); + graph.setStroke(new BasicStroke(3f)); + graph.draw(shape); + graph.dispose(); + } + + /** + * 解析二维码图 + * + * @param file + * @return + * @throws Exception + * @see [类、类#方法、类#成员] + */ + public static String decode(File file) + throws Exception + { + BufferedImage image = ImageIO.read(file); + if (image == null) + { + return null; + } + BufferedImageLuminanceSource source = new BufferedImageLuminanceSource(image); + BinaryBitmap bitmap = new BinaryBitmap(new HybridBinarizer(source)); + Hashtable hints = new Hashtable<>(); + hints.put(DecodeHintType.CHARACTER_SET, StandardCharsets.UTF_8.name()); + Result result = new MultiFormatReader().decode(bitmap, hints); + return result.getText(); + } + + /** + * 解析二维码图 + * + * @param path + * @return + * @throws Exception + * @see [类、类#方法、类#成员] + */ + public static String decode(String path) + throws Exception + { + return decode(new File(path)); + } +} \ No newline at end of file diff --git "a/00fly-Web\346\226\207\344\273\266\345\217\212\346\226\207\346\234\254\345\205\261\344\272\253\345\267\245\345\205\267/src/main/java/com/fly/filesend/controller/ApiController.java" "b/00fly-Web\346\226\207\344\273\266\345\217\212\346\226\207\346\234\254\345\205\261\344\272\253\345\267\245\345\205\267/src/main/java/com/fly/filesend/controller/ApiController.java" new file mode 100644 index 0000000000000000000000000000000000000000..146cc999ecc8832c7ef347fe711cf84ca813b421 --- /dev/null +++ "b/00fly-Web\346\226\207\344\273\266\345\217\212\346\226\207\346\234\254\345\205\261\344\272\253\345\267\245\345\205\267/src/main/java/com/fly/filesend/controller/ApiController.java" @@ -0,0 +1,84 @@ +package com.fly.filesend.controller; + +import java.awt.image.BufferedImage; +import java.net.URL; + +import javax.imageio.ImageIO; +import javax.servlet.http.HttpServletResponse; +import javax.servlet.http.HttpSession; + +import org.apache.commons.lang3.StringUtils; +import org.apache.commons.lang3.time.DateFormatUtils; +import org.springframework.beans.factory.annotation.Autowired; +import org.springframework.core.io.ClassPathResource; +import org.springframework.core.io.Resource; +import org.springframework.http.MediaType; +import org.springframework.web.bind.annotation.PostMapping; +import org.springframework.web.bind.annotation.RequestMapping; +import org.springframework.web.bind.annotation.RestController; + +import com.fly.core.qr.QRCodeUtil; +import com.fly.filesend.entity.JsonResult; +import com.fly.filesend.service.TokenService; +import com.github.xiaoymin.knife4j.annotations.ApiOperationSupport; + +import io.swagger.annotations.Api; +import io.swagger.annotations.ApiImplicitParam; +import io.swagger.annotations.ApiOperation; + +@Api(tags = "系统接口") +@RestController +@RequestMapping("/api") +public class ApiController +{ + @Autowired + HttpSession httpSession; + + @Autowired + TokenService tokenService; + + @ApiOperationSupport(order = 10) + @PostMapping("/login") + @ApiOperation("登录系统") + public JsonResult> login(String token) + { + if (!tokenService.valide(token)) + { + return JsonResult.error("token empty or valide failed!"); + } + httpSession.setAttribute("token", token); + String date = DateFormatUtils.format(System.currentTimeMillis(), "yyyy-MM-dd HH:mm:ss"); + return JsonResult.success(date + " login success!"); + } + + @ApiOperationSupport(order = 20) + @PostMapping("/logout") + @ApiOperation("退出系统") + public JsonResult> logout() + { + httpSession.invalidate(); + String date = DateFormatUtils.format(System.currentTimeMillis(), "yyyy-MM-dd HH:mm:ss"); + return JsonResult.success(date + " logout success!"); + } + + @ApiOperation("生成二维码") + @ApiImplicitParam(name = "content", value = "二维码文本", required = true, example = "乡愁是一棵没有年轮的树,永不老去") + @PostMapping(value = "/qr/create", produces = MediaType.IMAGE_JPEG_VALUE) + public void index(String content, HttpServletResponse response) + throws Exception + { + BufferedImage image; + if (StringUtils.isNotBlank(content)) + { + Resource resource = new ClassPathResource("img/dog.jpg"); + URL imgURL = resource.getURL(); + image = QRCodeUtil.createImage(content, imgURL, true); + } + else + { + image = new BufferedImage(300, 300, BufferedImage.TYPE_INT_RGB); + } + // 输出图象到页面 + ImageIO.write(image, "JPEG", response.getOutputStream()); + } +} diff --git "a/00fly-Web\346\226\207\344\273\266\345\217\212\346\226\207\346\234\254\345\205\261\344\272\253\345\267\245\345\205\267/src/main/java/com/fly/filesend/controller/IndexController.java" "b/00fly-Web\346\226\207\344\273\266\345\217\212\346\226\207\346\234\254\345\205\261\344\272\253\345\267\245\345\205\267/src/main/java/com/fly/filesend/controller/IndexController.java" new file mode 100644 index 0000000000000000000000000000000000000000..e72047d85fc794fb25532d22643f50623eb9de73 --- /dev/null +++ "b/00fly-Web\346\226\207\344\273\266\345\217\212\346\226\207\346\234\254\345\205\261\344\272\253\345\267\245\345\205\267/src/main/java/com/fly/filesend/controller/IndexController.java" @@ -0,0 +1,69 @@ +package com.fly.filesend.controller; + +import java.io.File; +import java.util.Comparator; +import java.util.List; +import java.util.stream.Collectors; + +import javax.servlet.http.HttpSession; + +import org.apache.commons.io.FileUtils; +import org.springframework.beans.factory.annotation.Autowired; +import org.springframework.stereotype.Controller; +import org.springframework.ui.Model; +import org.springframework.web.bind.annotation.GetMapping; +import org.springframework.web.bind.annotation.PostMapping; + +import com.fly.filesend.service.TextService; +import com.fly.filesend.service.TokenService; + +@Controller +public class IndexController +{ + @Autowired + HttpSession httpSession; + + File root = new File("upload"); + + @Autowired + TokenService tokenService; + + @Autowired + TextService textService; + + @GetMapping({"/", "/index"}) + public String index(Model model) + { + String token = (String)httpSession.getAttribute("token"); + if (tokenService.valide(token)) + { + model.addAttribute("text", textService.getText()); + model.addAttribute("isLogin", true); + model.addAttribute("sysTokenTime", tokenService.getTokenTime()); + if (root.exists()) + { + List files = FileUtils.listFiles(root, null, true).stream().filter(f -> f.isFile()).sorted(Comparator.comparing(File::getAbsolutePath)).collect(Collectors.toList()); + model.addAttribute("files", files); + model.addAttribute("size", FileUtils.byteCountToDisplaySize(FileUtils.sizeOfDirectory(root))); + } + } + return "index"; + } + + @PostMapping("/login") + public String login(String token) + { + if (tokenService.valide(token)) + { + httpSession.setAttribute("token", token); + } + return "redirect:/index"; + } + + @GetMapping("/logout") + public String logout() + { + httpSession.invalidate(); + return "redirect:/index"; + } +} diff --git "a/00fly-Web\346\226\207\344\273\266\345\217\212\346\226\207\346\234\254\345\205\261\344\272\253\345\267\245\345\205\267/src/main/java/com/fly/filesend/controller/file/FileController.java" "b/00fly-Web\346\226\207\344\273\266\345\217\212\346\226\207\346\234\254\345\205\261\344\272\253\345\267\245\345\205\267/src/main/java/com/fly/filesend/controller/file/FileController.java" new file mode 100644 index 0000000000000000000000000000000000000000..60014fbe73e3afae2bdcc83be5b5bc066c649c17 --- /dev/null +++ "b/00fly-Web\346\226\207\344\273\266\345\217\212\346\226\207\346\234\254\345\205\261\344\272\253\345\267\245\345\205\267/src/main/java/com/fly/filesend/controller/file/FileController.java" @@ -0,0 +1,103 @@ +package com.fly.filesend.controller.file; + +import java.io.File; +import java.io.FileInputStream; +import java.io.FileOutputStream; +import java.io.IOException; +import java.net.URLEncoder; +import java.nio.charset.StandardCharsets; +import java.util.Arrays; +import java.util.Comparator; +import java.util.List; +import java.util.stream.Collectors; + +import javax.servlet.http.HttpServletResponse; + +import org.apache.commons.io.FileUtils; +import org.apache.commons.lang3.StringUtils; +import org.apache.commons.lang3.time.DateFormatUtils; +import org.springframework.http.MediaType; +import org.springframework.stereotype.Controller; +import org.springframework.util.FileCopyUtils; +import org.springframework.web.bind.annotation.GetMapping; +import org.springframework.web.bind.annotation.PathVariable; +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.multipart.MultipartFile; + +import com.fly.core.exception.ValidateException; + +import lombok.extern.slf4j.Slf4j; + +@Slf4j +@Controller +@RequestMapping("/file") +public class FileController +{ + File root = new File("upload"); + + @PostMapping("/upload") + public String upload(@RequestParam MultipartFile[] files) + throws IOException + { + if (files == null || files.length == 0) + { + throw new ValidateException("files is null"); + } + String date = DateFormatUtils.format(System.currentTimeMillis(), "yyyyMMdd"); + String dir = root.getCanonicalPath() + File.separator + date + File.separator; + new File(dir).mkdirs(); + + // 保存文件 + Arrays.stream(files).filter(file -> StringUtils.isNotBlank(file.getOriginalFilename())).forEach(file -> { + try + { + File newFile = new File(dir + file.getOriginalFilename()); + FileCopyUtils.copy(file.getInputStream(), new FileOutputStream(newFile)); + log.info("###### file upload to: {}", dir); + } + catch (IOException e) + { + log.error(e.getMessage(), e); + } + }); + return "redirect:/index"; + } + + @GetMapping(value = "/down/{index}", produces = MediaType.APPLICATION_OCTET_STREAM_VALUE) + public void down(@PathVariable int index, HttpServletResponse response) + throws IOException + { + List files = FileUtils.listFiles(root, null, true).stream().filter(f -> f.isFile()).sorted(Comparator.comparing(File::getAbsolutePath)).collect(Collectors.toList()); + if (index >= 0 && index < files.size()) + { + File file = files.get(index); + response.setHeader("Content-Disposition", "attachment;filename=" + URLEncoder.encode(file.getName(), StandardCharsets.UTF_8.name())); + response.setHeader("Cache-Control", "no-store, no-cache"); + FileCopyUtils.copy(new FileInputStream(file), response.getOutputStream()); + } + } + + @GetMapping(value = "/clear") + public String clear() + throws IOException + { + if (root.exists()) + { + FileUtils.cleanDirectory(root); + } + return "redirect:/index"; + } + + @GetMapping(value = "/delete/{index}") + public String delete(@PathVariable int index) + { + List files = FileUtils.listFiles(root, null, true).stream().filter(f -> f.isFile()).sorted(Comparator.comparing(File::getAbsolutePath)).collect(Collectors.toList()); + if (index >= 0 && index < files.size()) + { + files.get(index).delete(); + } + return "redirect:/index"; + } +} diff --git "a/00fly-Web\346\226\207\344\273\266\345\217\212\346\226\207\346\234\254\345\205\261\344\272\253\345\267\245\345\205\267/src/main/java/com/fly/filesend/controller/file/RestFileController.java" "b/00fly-Web\346\226\207\344\273\266\345\217\212\346\226\207\346\234\254\345\205\261\344\272\253\345\267\245\345\205\267/src/main/java/com/fly/filesend/controller/file/RestFileController.java" new file mode 100644 index 0000000000000000000000000000000000000000..083d927cf5de86151581905f25219063f599f097 --- /dev/null +++ "b/00fly-Web\346\226\207\344\273\266\345\217\212\346\226\207\346\234\254\345\205\261\344\272\253\345\267\245\345\205\267/src/main/java/com/fly/filesend/controller/file/RestFileController.java" @@ -0,0 +1,106 @@ +package com.fly.filesend.controller.file; + +import java.io.File; +import java.io.FileInputStream; +import java.io.FileOutputStream; +import java.io.IOException; +import java.net.URLEncoder; +import java.nio.charset.StandardCharsets; +import java.util.Arrays; +import java.util.Comparator; +import java.util.List; +import java.util.stream.Collectors; + +import javax.servlet.http.HttpServletResponse; + +import org.apache.commons.io.FileUtils; +import org.apache.commons.lang3.StringUtils; +import org.apache.commons.lang3.SystemUtils; +import org.apache.commons.lang3.time.DateFormatUtils; +import org.springframework.http.MediaType; +import org.springframework.util.FileCopyUtils; +import org.springframework.web.bind.annotation.GetMapping; +import org.springframework.web.bind.annotation.PathVariable; +import org.springframework.web.bind.annotation.PostMapping; +import org.springframework.web.bind.annotation.RequestMapping; +import org.springframework.web.bind.annotation.RestController; +import org.springframework.web.multipart.MultipartFile; + +import com.fly.core.exception.ValidateException; +import com.fly.filesend.entity.JsonResult; + +import io.swagger.annotations.Api; +import io.swagger.annotations.ApiImplicitParam; +import io.swagger.annotations.ApiOperation; +import lombok.extern.slf4j.Slf4j; + +@Slf4j +@Api(tags = "文件上传、下载接口") +@RestController +@RequestMapping("/rest/file") +public class RestFileController +{ + File root = new File("upload"); + + @ApiOperation("文件下载, index取值 [0, files.length)") + @ApiImplicitParam(name = "index", value = "文件索引,起始值0", required = true, allowableValues = "0,1,2,3,4,5,6,7,8,9,10") + @GetMapping(value = "/down/{index}", produces = MediaType.APPLICATION_OCTET_STREAM_VALUE) + public void down(@PathVariable int index, HttpServletResponse response) + throws IOException + { + List files = FileUtils.listFiles(root, null, true).stream().filter(f -> f.isFile()).sorted(Comparator.comparing(File::getAbsolutePath)).collect(Collectors.toList()); + if (index >= 0 && index < files.size()) + { + File file = files.get(index); + response.setHeader("Content-Disposition", "attachment;filename=" + URLEncoder.encode(file.getName(), StandardCharsets.UTF_8.name())); + response.setHeader("Cache-Control", "no-store, no-cache"); + FileCopyUtils.copy(new FileInputStream(file), response.getOutputStream()); + } + } + + @ApiOperation("文件搜索") + @PostMapping("/list") + public JsonResult> list() + { + if (!root.exists() || !root.isDirectory()) + { + return JsonResult.error("文件目录不存在"); + } + // 检索文件路径排序 + List paths = FileUtils.listFiles(root, null, true).stream().filter(f -> f.isFile()).map(f -> f.getPath()).sorted().collect(Collectors.toList()); + return JsonResult.success(paths); + } + + @ApiOperation("文件批量上传处理") + @PostMapping("/upload") + public JsonResult> upload(MultipartFile[] files) + throws IOException + { + if (files == null || files.length == 0) + { + throw new ValidateException("文件不能为空"); + } + String date = DateFormatUtils.format(System.currentTimeMillis(), "yyyyMMdd"); + String dir = root.getCanonicalPath() + File.separator + date + File.separator; + new File(dir).mkdirs(); + + // 保存文件 + Arrays.stream(files).filter(file -> StringUtils.isNotBlank(file.getOriginalFilename())).forEach(file -> { + try + { + File newFile = new File(dir + file.getOriginalFilename()); + FileCopyUtils.copy(file.getInputStream(), new FileOutputStream(newFile)); + log.info("###### file upload to: {}", dir); + } + catch (IOException e) + { + log.error(e.getMessage(), e); + } + }); + if (SystemUtils.IS_OS_WINDOWS) + { + Runtime.getRuntime().exec("cmd /c start " + dir); + } + return JsonResult.success("文件上传成功,保存目录:" + dir); + } +} diff --git "a/00fly-Web\346\226\207\344\273\266\345\217\212\346\226\207\346\234\254\345\205\261\344\272\253\345\267\245\345\205\267/src/main/java/com/fly/filesend/controller/file/TextController.java" "b/00fly-Web\346\226\207\344\273\266\345\217\212\346\226\207\346\234\254\345\205\261\344\272\253\345\267\245\345\205\267/src/main/java/com/fly/filesend/controller/file/TextController.java" new file mode 100644 index 0000000000000000000000000000000000000000..77e0a5dbe89edbc90eb49b9d696892a63b20b473 --- /dev/null +++ "b/00fly-Web\346\226\207\344\273\266\345\217\212\346\226\207\346\234\254\345\205\261\344\272\253\345\267\245\345\205\267/src/main/java/com/fly/filesend/controller/file/TextController.java" @@ -0,0 +1,23 @@ +package com.fly.filesend.controller.file; + +import org.springframework.beans.factory.annotation.Autowired; +import org.springframework.stereotype.Controller; +import org.springframework.web.bind.annotation.PostMapping; +import org.springframework.web.bind.annotation.RequestMapping; + +import com.fly.filesend.service.TextService; + +@Controller +@RequestMapping("/text") +public class TextController +{ + @Autowired + TextService textService; + + @PostMapping("/submit") + public String upload(String text) + { + textService.setText(text); + return "redirect:/index"; + } +} diff --git "a/00fly-Web\346\226\207\344\273\266\345\217\212\346\226\207\346\234\254\345\205\261\344\272\253\345\267\245\345\205\267/src/main/java/com/fly/filesend/entity/JsonResult.java" "b/00fly-Web\346\226\207\344\273\266\345\217\212\346\226\207\346\234\254\345\205\261\344\272\253\345\267\245\345\205\267/src/main/java/com/fly/filesend/entity/JsonResult.java" new file mode 100644 index 0000000000000000000000000000000000000000..4e102b790648eb23a832af3cf24390b04517248e --- /dev/null +++ "b/00fly-Web\346\226\207\344\273\266\345\217\212\346\226\207\346\234\254\345\205\261\344\272\253\345\267\245\345\205\267/src/main/java/com/fly/filesend/entity/JsonResult.java" @@ -0,0 +1,65 @@ +package com.fly.filesend.entity; + +import io.swagger.annotations.ApiModel; +import io.swagger.annotations.ApiModelProperty; +import lombok.Data; + +/** + * + * 结果对象 + * + * @author 00fly + * @version [版本号, 2021年5月2日] + * @see [相关类/方法] + * @since [产品/模块版本] + */ +@Data +@ApiModel(description = "Json格式消息体") +public class JsonResult +{ + @ApiModelProperty(value = "数据对象") + private T data; + + @ApiModelProperty(value = "是否成功", required = true, example = "true") + private boolean success; + + @ApiModelProperty(value = "错误码") + private String errorCode; + + @ApiModelProperty(value = "提示信息") + private String message; + + public JsonResult() + { + super(); + } + + public static JsonResult success(T data) + { + JsonResult r = new JsonResult<>(); + r.setData(data); + r.setSuccess(true); + return r; + } + + public static JsonResult> success() + { + JsonResult r = new JsonResult<>(); + r.setSuccess(true); + return r; + } + + public static JsonResult error(String code, String msg) + { + JsonResult r = new JsonResult<>(); + r.setSuccess(false); + r.setErrorCode(code); + r.setMessage(msg); + return r; + } + + public static JsonResult error(String msg) + { + return error("500", msg); + } +} diff --git "a/00fly-Web\346\226\207\344\273\266\345\217\212\346\226\207\346\234\254\345\205\261\344\272\253\345\267\245\345\205\267/src/main/java/com/fly/filesend/service/TextService.java" "b/00fly-Web\346\226\207\344\273\266\345\217\212\346\226\207\346\234\254\345\205\261\344\272\253\345\267\245\345\205\267/src/main/java/com/fly/filesend/service/TextService.java" new file mode 100644 index 0000000000000000000000000000000000000000..bf4d4e6ebcb89d116246ae661a72de18fd26d349 --- /dev/null +++ "b/00fly-Web\346\226\207\344\273\266\345\217\212\346\226\207\346\234\254\345\205\261\344\272\253\345\267\245\345\205\267/src/main/java/com/fly/filesend/service/TextService.java" @@ -0,0 +1,20 @@ +package com.fly.filesend.service; + +import org.apache.commons.lang3.StringUtils; +import org.springframework.stereotype.Service; + +@Service +public class TextService +{ + private String text; + + public String getText() + { + return StringUtils.trimToEmpty(text); + } + + public void setText(String text) + { + this.text = text; + } +} diff --git "a/00fly-Web\346\226\207\344\273\266\345\217\212\346\226\207\346\234\254\345\205\261\344\272\253\345\267\245\345\205\267/src/main/java/com/fly/filesend/service/TextService2.java" "b/00fly-Web\346\226\207\344\273\266\345\217\212\346\226\207\346\234\254\345\205\261\344\272\253\345\267\245\345\205\267/src/main/java/com/fly/filesend/service/TextService2.java" new file mode 100644 index 0000000000000000000000000000000000000000..0079dc0da31b4bbcd0ae7e951efb62c26acca64d --- /dev/null +++ "b/00fly-Web\346\226\207\344\273\266\345\217\212\346\226\207\346\234\254\345\205\261\344\272\253\345\267\245\345\205\267/src/main/java/com/fly/filesend/service/TextService2.java" @@ -0,0 +1,50 @@ +package com.fly.filesend.service; + +import java.util.Map; +import java.util.Set; +import java.util.concurrent.ConcurrentSkipListMap; + +import org.apache.commons.lang3.StringUtils; +import org.apache.commons.lang3.time.DateFormatUtils; +import org.springframework.stereotype.Service; + +@Service +public class TextService2 +{ + Map map = new ConcurrentSkipListMap<>(); + + /** + * 时间戳keys + * + * @return + */ + public Set getKeys() + { + return map.keySet(); + } + + /** + * 获取值 + * + * @param key + * @return + */ + public String getText(String key) + { + return StringUtils.trimToEmpty(map.get(key)); + } + + public void setText(String text) + { + if (StringUtils.isNotBlank(text)) + { + String key = DateFormatUtils.format(System.currentTimeMillis(), "yyyy-MM-dd HH:mm:ss.SSS"); + map.put(key, text); + while (map.size() > 10)// 保留10次历史 + { + String firstKey = map.keySet().stream().findFirst().get(); + map.remove(firstKey); + } + } + } +} diff --git "a/00fly-Web\346\226\207\344\273\266\345\217\212\346\226\207\346\234\254\345\205\261\344\272\253\345\267\245\345\205\267/src/main/java/com/fly/filesend/service/TokenService.java" "b/00fly-Web\346\226\207\344\273\266\345\217\212\346\226\207\346\234\254\345\205\261\344\272\253\345\267\245\345\205\267/src/main/java/com/fly/filesend/service/TokenService.java" new file mode 100644 index 0000000000000000000000000000000000000000..1f789f9c8c698721b90544fff90174f4b81129b7 --- /dev/null +++ "b/00fly-Web\346\226\207\344\273\266\345\217\212\346\226\207\346\234\254\345\205\261\344\272\253\345\267\245\345\205\267/src/main/java/com/fly/filesend/service/TokenService.java" @@ -0,0 +1,84 @@ +package com.fly.filesend.service; + +import java.util.Date; +import java.util.UUID; + +import org.apache.commons.lang3.StringUtils; +import org.apache.commons.lang3.time.DateFormatUtils; +import org.apache.commons.lang3.time.DateUtils; +import org.springframework.beans.factory.annotation.Value; +import org.springframework.stereotype.Service; + +import lombok.extern.slf4j.Slf4j; + +@Slf4j +@Service +public class TokenService +{ + private String sysToken; + + /** + * sysToken有效时间 + */ + private Date sysTokenTime; + + private String sysTokenTimeShow; + + /** + * sysToken有效小时数(default:2) + */ + @Value("${token.valide.hours:2}") + private Integer hours; + + @Value("${system.auto.login:false}") + private Boolean autoLogin; + + /** + * 验证token是否合法 + * + * @param token + * @return + * @return + */ + public boolean valide(String token) + { + if (autoLogin) + { + return true; + } + boolean success = StringUtils.equals(token, getToken()); + if (!success) + { + log.info("------ now valid sysToken is: {}", sysToken); + } + return success; + } + + /** + * 获取sysToken有效时间 + * + * @return + */ + public String getTokenTime() + { + return sysTokenTimeShow; + } + + /** + * 获取sysToken + * + * @return + * @see [类、类#方法、类#成员] + */ + private String getToken() + { + Date now = new Date(); + if (sysTokenTime == null || now.after(sysTokenTime)) + { + sysToken = UUID.randomUUID().toString().replace("-", ""); + sysTokenTime = DateUtils.addHours(now, hours); + sysTokenTimeShow = DateFormatUtils.format(sysTokenTime, "yyyy-MM-dd HH:mm:ss"); + } + return sysToken; + } +} diff --git "a/00fly-Web\346\226\207\344\273\266\345\217\212\346\226\207\346\234\254\345\205\261\344\272\253\345\267\245\345\205\267/src/main/resources/application-dev.yml" "b/00fly-Web\346\226\207\344\273\266\345\217\212\346\226\207\346\234\254\345\205\261\344\272\253\345\267\245\345\205\267/src/main/resources/application-dev.yml" new file mode 100644 index 0000000000000000000000000000000000000000..48ac8c9333be4f19cc49c2aecf6105dad707b61c --- /dev/null +++ "b/00fly-Web\346\226\207\344\273\266\345\217\212\346\226\207\346\234\254\345\205\261\344\272\253\345\267\245\345\205\267/src/main/resources/application-dev.yml" @@ -0,0 +1,16 @@ +spring: + servlet: + multipart: + max-file-size: 10MB + max-request-size: 100MB + thymeleaf: + cache: false + check-template-location: true + encoding: UTF-8 + mode: HTML + prefix: classpath:/templates/ + suffix: .html + +logging: + level: + root: info diff --git "a/00fly-Web\346\226\207\344\273\266\345\217\212\346\226\207\346\234\254\345\205\261\344\272\253\345\267\245\345\205\267/src/main/resources/application-prod.yml" "b/00fly-Web\346\226\207\344\273\266\345\217\212\346\226\207\346\234\254\345\205\261\344\272\253\345\267\245\345\205\267/src/main/resources/application-prod.yml" new file mode 100644 index 0000000000000000000000000000000000000000..f6cdb60d64e8cbd40369e9a12c8fa796eea839d3 --- /dev/null +++ "b/00fly-Web\346\226\207\344\273\266\345\217\212\346\226\207\346\234\254\345\205\261\344\272\253\345\267\245\345\205\267/src/main/resources/application-prod.yml" @@ -0,0 +1,16 @@ +spring: + servlet: + multipart: + max-file-size: 10MB + max-request-size: 100MB + thymeleaf: + cache: true + check-template-location: true + encoding: UTF-8 + mode: HTML + prefix: classpath:/templates/ + suffix: .html + +logging: + level: + root: info diff --git "a/00fly-Web\346\226\207\344\273\266\345\217\212\346\226\207\346\234\254\345\205\261\344\272\253\345\267\245\345\205\267/src/main/resources/application-test.yml" "b/00fly-Web\346\226\207\344\273\266\345\217\212\346\226\207\346\234\254\345\205\261\344\272\253\345\267\245\345\205\267/src/main/resources/application-test.yml" new file mode 100644 index 0000000000000000000000000000000000000000..c1a40712ad61ef47bbc1eb3fea71b7ab949e6778 --- /dev/null +++ "b/00fly-Web\346\226\207\344\273\266\345\217\212\346\226\207\346\234\254\345\205\261\344\272\253\345\267\245\345\205\267/src/main/resources/application-test.yml" @@ -0,0 +1,16 @@ +spring: + servlet: + multipart: + max-file-size: 1000MB + max-request-size: 1000MB + thymeleaf: + cache: true + check-template-location: true + encoding: UTF-8 + mode: HTML + prefix: classpath:/templates/ + suffix: .html + +logging: + level: + root: info diff --git "a/00fly-Web\346\226\207\344\273\266\345\217\212\346\226\207\346\234\254\345\205\261\344\272\253\345\267\245\345\205\267/src/main/resources/application.yml" "b/00fly-Web\346\226\207\344\273\266\345\217\212\346\226\207\346\234\254\345\205\261\344\272\253\345\267\245\345\205\267/src/main/resources/application.yml" new file mode 100644 index 0000000000000000000000000000000000000000..c398aa324dbdb77eea6279212910d7cd0dfef824 --- /dev/null +++ "b/00fly-Web\346\226\207\344\273\266\345\217\212\346\226\207\346\234\254\345\205\261\344\272\253\345\267\245\345\205\267/src/main/resources/application.yml" @@ -0,0 +1,13 @@ +server: + port: 8080 + servlet: + context-path: / + session: + timeout: 1800 #以秒为单位 + tomcat: + max-http-form-post-size: 200MB #post表单请求体数据限制,默认2MB + max-swallow-size: 200MB #内嵌tomcat最大请求吞吐量限制,默认2MB +spring: + profiles: + active: + - dev diff --git "a/00fly-Web\346\226\207\344\273\266\345\217\212\346\226\207\346\234\254\345\205\261\344\272\253\345\267\245\345\205\267/src/main/resources/img/dog.jpg" "b/00fly-Web\346\226\207\344\273\266\345\217\212\346\226\207\346\234\254\345\205\261\344\272\253\345\267\245\345\205\267/src/main/resources/img/dog.jpg" new file mode 100644 index 0000000000000000000000000000000000000000..8c503cd2867cc6eb7cfd9fd8853fc0bbc9389236 Binary files /dev/null and "b/00fly-Web\346\226\207\344\273\266\345\217\212\346\226\207\346\234\254\345\205\261\344\272\253\345\267\245\345\205\267/src/main/resources/img/dog.jpg" differ diff --git "a/00fly-Web\346\226\207\344\273\266\345\217\212\346\226\207\346\234\254\345\205\261\344\272\253\345\267\245\345\205\267/src/main/resources/static/error/404.html" "b/00fly-Web\346\226\207\344\273\266\345\217\212\346\226\207\346\234\254\345\205\261\344\272\253\345\267\245\345\205\267/src/main/resources/static/error/404.html" new file mode 100644 index 0000000000000000000000000000000000000000..a099b7c496d467e2545614a04a8b36783147898a --- /dev/null +++ "b/00fly-Web\346\226\207\344\273\266\345\217\212\346\226\207\346\234\254\345\205\261\344\272\253\345\267\245\345\205\267/src/main/resources/static/error/404.html" @@ -0,0 +1,31 @@ + + + + + + + 404(找不到页面) + + + + + + + + + + + + + 404! + 很抱歉,没有找到这个页面! + + 返回首页 + + + + + \ No newline at end of file diff --git "a/00fly-Web\346\226\207\344\273\266\345\217\212\346\226\207\346\234\254\345\205\261\344\272\253\345\267\245\345\205\267/src/main/resources/templates/index.html" "b/00fly-Web\346\226\207\344\273\266\345\217\212\346\226\207\346\234\254\345\205\261\344\272\253\345\267\245\345\205\267/src/main/resources/templates/index.html" new file mode 100644 index 0000000000000000000000000000000000000000..e61c8649ca6de5e66f1bf1d6967bde09b7fab0b7 --- /dev/null +++ "b/00fly-Web\346\226\207\344\273\266\345\217\212\346\226\207\346\234\254\345\205\261\344\272\253\345\267\245\345\205\267/src/main/resources/templates/index.html" @@ -0,0 +1,138 @@ + + + + + + + + + +simple文件共享工具 + + + + + + Navigate + + + index + 出错页面 + doc.html + + + + + + + + 功能列表 + + + + + 登录系统 + token + + + + + + + + + 退出登录 | 清空文件 + + + + + + 批量上传,单个文件小于10MB,单个请求小于100MB + + + + + + + + + + + + + + + + + + + + 删除 + + + + + + + 文本 + + + + + + + + + + + + + + + + \ No newline at end of file