diff --git a/src/main/java/com/quinn/common/QuinnConstant.java b/src/main/java/com/quinn/common/QuinnConstant.java index 0a23c19..8919a83 100644 --- a/src/main/java/com/quinn/common/QuinnConstant.java +++ b/src/main/java/com/quinn/common/QuinnConstant.java @@ -3,6 +3,10 @@ package com.quinn.common; public interface QuinnConstant { String LINK_SUFFIX = "."; + + String LINK_KEY_WORD = ","; + + String LINK_DATE_STR = "_"; /** * REDIS PATTEN */ @@ -11,5 +15,9 @@ public interface QuinnConstant { String GUN = "The emperor's new clothes"; String SOURCE_KEY = "SOURCE_KEY_"; + /** + * PASSWORD //TODO 可以配置数据库MD5加密 + */ + String SOURCE_PASSWORD = "926462"; } diff --git a/src/main/java/com/quinn/common/SourceType.java b/src/main/java/com/quinn/common/SourceType.java new file mode 100644 index 0000000..f6fc591 --- /dev/null +++ b/src/main/java/com/quinn/common/SourceType.java @@ -0,0 +1,14 @@ +package com.quinn.common; + +public enum SourceType { + + /** + * OSS文件 + */ + OSS, + /** + * 百度网盘 + */ + BAIDU + +} diff --git a/src/main/java/com/quinn/config/SecurityConfig.java b/src/main/java/com/quinn/config/SecurityConfig.java index 89c43cd..1937de5 100644 --- a/src/main/java/com/quinn/config/SecurityConfig.java +++ b/src/main/java/com/quinn/config/SecurityConfig.java @@ -1,5 +1,6 @@ package com.quinn.config; +import com.quinn.common.SourceType; import com.quinn.service.impl.UserServiceImpl; import org.springframework.beans.factory.annotation.Autowired; import org.springframework.context.annotation.Bean; @@ -27,6 +28,7 @@ public class SecurityConfig extends WebSecurityConfigurerAdapter { http.authorizeRequests() .antMatchers("/","/index").permitAll() .antMatchers("/register","/login","/toLogin").permitAll() + .antMatchers("/tracy/mcgrady/lmq/love/wn").permitAll() .antMatchers("/*").authenticated(); // 登录配置 diff --git a/src/main/java/com/quinn/controller/LoginController.java b/src/main/java/com/quinn/controller/LoginController.java index 56fd57c..414cc68 100644 --- a/src/main/java/com/quinn/controller/LoginController.java +++ b/src/main/java/com/quinn/controller/LoginController.java @@ -26,11 +26,19 @@ public class LoginController { @Autowired UserInfoService userInfoService; - @GetMapping({"/","/index"}) + @GetMapping({"/","/index","/source/view/index", + "/tracy/mcgrady/lmq/love/wn/index", + "/blog/read/index" + }) public String index(){ return "index"; } + @GetMapping("/error/check") + public String error(){ + return "error/check"; + } + @GetMapping("/toLogin") public String toLogin(){ return "login"; diff --git a/src/main/java/com/quinn/controller/QuestionCategoryController.java b/src/main/java/com/quinn/controller/QuestionCategoryController.java index d3ec565..6b5de4c 100644 --- a/src/main/java/com/quinn/controller/QuestionCategoryController.java +++ b/src/main/java/com/quinn/controller/QuestionCategoryController.java @@ -22,7 +22,8 @@ import java.util.List; * @author limqsh * @since 2020-06-28 */ -@Controller +//@Controller +@Deprecated public class QuestionCategoryController { @Autowired diff --git a/src/main/java/com/quinn/controller/QuestionController.java b/src/main/java/com/quinn/controller/QuestionController.java index ab9577c..356d0bd 100644 --- a/src/main/java/com/quinn/controller/QuestionController.java +++ b/src/main/java/com/quinn/controller/QuestionController.java @@ -35,7 +35,8 @@ import java.util.UUID; * @author limqsh * @since 2020-06-28 */ -@Controller +//@Controller +@Deprecated public class QuestionController { @Autowired diff --git a/src/main/java/com/quinn/controller/SourceCommentController.java b/src/main/java/com/quinn/controller/SourceCommentController.java deleted file mode 100644 index c5a606a..0000000 --- a/src/main/java/com/quinn/controller/SourceCommentController.java +++ /dev/null @@ -1,17 +0,0 @@ -package com.quinn.controller; - - -import org.springframework.stereotype.Controller; -/** - *

- * 前端控制器 - *

- * - * @author limqsh - * @since 2022-05-03 - */ -@Controller -public class SourceCommentController { - -} - diff --git a/src/main/java/com/quinn/controller/SourceController.java b/src/main/java/com/quinn/controller/SourceController.java index 1d3b771..1e580a8 100644 --- a/src/main/java/com/quinn/controller/SourceController.java +++ b/src/main/java/com/quinn/controller/SourceController.java @@ -4,11 +4,13 @@ package com.quinn.controller; import com.baomidou.mybatisplus.core.conditions.query.QueryWrapper; import com.baomidou.mybatisplus.extension.plugins.pagination.Page; import com.quinn.common.QuinnConstant; +import com.quinn.common.SourceType; import com.quinn.pojo.*; import com.quinn.pojo.param.QuerySource; import com.quinn.service.SourceCategoryService; import com.quinn.service.SourceCommentService; import com.quinn.service.SourceService; +import org.springframework.beans.factory.annotation.Value; import org.springframework.stereotype.Controller; import org.springframework.transaction.annotation.Transactional; import org.springframework.ui.Model; @@ -53,6 +55,10 @@ public class SourceController { if (!CollectionUtils.isEmpty(sourceList)){ sourceList.forEach(x ->{ x.setSourceLink(QuinnConstant.GUN); + x.setKeyWord1(QuinnConstant.GUN); + x.setKeyWord2(QuinnConstant.GUN); + x.setKeyWord3(QuinnConstant.GUN); + x.setSourceContent(QuinnConstant.GUN); }); } model.addAttribute("sourceList",sourceList); @@ -97,7 +103,10 @@ public class SourceController { if (!CollectionUtils.isEmpty(sourceList)){ sourceList.forEach(x ->{ x.setSourceLink(QuinnConstant.GUN); - x.setSourceContent(""); + x.setKeyWord1(QuinnConstant.GUN); + x.setKeyWord2(QuinnConstant.GUN); + x.setKeyWord3(QuinnConstant.GUN); + x.setSourceContent(QuinnConstant.GUN); }); } model.addAttribute("sourceList",sourceList); @@ -113,9 +122,13 @@ public class SourceController { */ @GetMapping("/source/view/{sid}") public String read(@PathVariable("sid") String sid, Model model){ - Source source = sourceService.hotResource(sid); + Source source = sourceService.view(sid); if(source != null){ source.setSourceLink(QuinnConstant.GUN); + source.setKeyWord1(QuinnConstant.GUN); + source.setKeyWord2(QuinnConstant.GUN); + source.setKeyWord3(QuinnConstant.GUN); + source.setSourceType(QuinnConstant.GUN); } model.addAttribute("source",source); List commentList = sourceCommentService.list(new QueryWrapper().eq("topic_id", sid).orderByDesc("gmt_create")); @@ -129,13 +142,19 @@ public class SourceController { * @param sid * @throws IOException */ - @GetMapping("/source/download/{sid}") + @PostMapping("/source/download/{sid}") public void download(HttpServletResponse response, @PathVariable("sid") String sid) throws IOException { - Source source = sourceService.getOne(new QueryWrapper().eq("id", sid)); - //通知浏览器以附件形式下载 - response.setHeader("Content-Disposition", - "attachment;filename=" + source.getEnName() + QuinnConstant.LINK_SUFFIX + source.getFileType()); - this.sourceService.downloadSource(response.getOutputStream(),source); + Source source = sourceService.getOne(new QueryWrapper().eq("sid", sid)); + if (source!=null){ + if (SourceType.OSS.name().equals(source.getSourceType())){ + //通知浏览器以附件形式下载 + response.setHeader("Content-Disposition", + "attachment;filename=" + source.getEnName() + QuinnConstant.LINK_SUFFIX + source.getFileType()); + this.sourceService.downloadSource(response,source); + }else { + this.sourceService.downloadForBaidu(response,source); + } + } } private void addParam(QueryWrapper sourceQuery, String name, int category) { diff --git a/src/main/java/com/quinn/controller/SourceUploadController.java b/src/main/java/com/quinn/controller/SourceUploadController.java new file mode 100644 index 0000000..fc17f15 --- /dev/null +++ b/src/main/java/com/quinn/controller/SourceUploadController.java @@ -0,0 +1,110 @@ +package com.quinn.controller; + + +import com.baomidou.mybatisplus.core.conditions.query.QueryWrapper; +import com.quinn.common.QuinnConstant; +import com.quinn.pojo.Source; +import com.quinn.pojo.SourceCategory; +import com.quinn.service.SourceCategoryService; +import com.quinn.service.SourceService; +import com.quinn.vo.SourceDeleteForm; +import com.quinn.vo.SourceUpdateForm; +import com.quinn.vo.SourceWriteForm; +import org.springframework.stereotype.Controller; +import org.springframework.ui.Model; +import org.springframework.util.StringUtils; +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.multipart.MultipartFile; + +import javax.annotation.Resource; +import javax.servlet.http.HttpServletResponse; +import java.io.IOException; +import java.io.PrintWriter; +import java.util.List; + +/** + *

+ * 前端控制器 + *

+ * + * @author limqsh + * @since 2022-05-03 + */ +@Controller +public class SourceUploadController { + + @Resource + SourceCategoryService sourceCategoryService; + @Resource + SourceService sourceService; + + // 写文章 + @GetMapping("/tracy/mcgrady/lmq/love/wn") + public String toWrite(Model model){ + // 分类信息 + List categoryList = sourceCategoryService.list(null); + model.addAttribute("categoryList",categoryList); + return "source/uploadSource"; + } + + @PostMapping("/tracy/mcgrady/lmq/love/wn") + public synchronized String write(MultipartFile file, SourceWriteForm sourceWriteForm) throws IOException { + if (!QuinnConstant.SOURCE_PASSWORD.equals(sourceWriteForm.getUploadPassWord())){ + return "error/check"; + } + sourceService.uploadNewSource(file,sourceWriteForm); + // 重定向到列表页面 + return "redirect:/source"; + } + + // 编辑信息 + @GetMapping("/tracy/mcgrady/lmq/love/wn/{sid}") + public String toEdit(@PathVariable("sid") String sid, Model model){ + Source source = sourceService.getOne(new QueryWrapper().eq("sid",sid)); + source.setKeyWord1(concatKeyWord(source.getKeyWord2()) + concatKeyWord(source.getKeyWord2()) + concatKeyWord(source.getKeyWord3())); + model.addAttribute("source",source); + // 分类信息 + List categoryList = sourceCategoryService.list(null); + model.addAttribute("categoryList",categoryList); + return "source/editorSource"; + } + + private String concatKeyWord(String keyWord) { + if (!StringUtils.isEmpty(keyWord)) { + return keyWord + QuinnConstant.LINK_KEY_WORD; + } + return ""; + } + + // 编辑信息 + @PostMapping("/tracy/mcgrady/lmq/love/wn/update") + public String toEdit(MultipartFile file, SourceUpdateForm sourceUpdateForm) throws IOException { + if (!QuinnConstant.SOURCE_PASSWORD.equals(sourceUpdateForm.getUploadPassWord())){ + return "error/check"; + } + sourceService.updateSource(file,sourceUpdateForm); + // 重定向详情页面 + return "redirect:/source/view/" + sourceUpdateForm.getSid(); + } + + // 编辑信息 + @PostMapping("/tracy/mcgrady/lmq/love/wn/del") + public void toEdit(HttpServletResponse response, SourceDeleteForm sourceDeleteForm) throws IOException { + PrintWriter writer = response.getWriter(); + if (!QuinnConstant.SOURCE_PASSWORD.equals(sourceDeleteForm.getUploadPassWord())){ + writer.write("/error/check"); + writer.flush(); + writer.close(); + return; + } + sourceService.deleteSource(sourceDeleteForm.getSid()); + // 重定向详情页面 + writer.write("/source"); + writer.flush(); + writer.close(); + } + +} + diff --git a/src/main/java/com/quinn/pojo/Source.java b/src/main/java/com/quinn/pojo/Source.java index cc96267..a149b35 100644 --- a/src/main/java/com/quinn/pojo/Source.java +++ b/src/main/java/com/quinn/pojo/Source.java @@ -13,7 +13,7 @@ import lombok.experimental.Accessors; /** *

- * + * *

* * @author limqsh @@ -31,6 +31,9 @@ public class Source implements Serializable { @TableId(value = "id", type = IdType.AUTO) private Integer id; + @ApiModelProperty(value = "资源ID") + private String sid; + @ApiModelProperty(value = "资源名") private String sourceName; diff --git a/src/main/java/com/quinn/service/SourceService.java b/src/main/java/com/quinn/service/SourceService.java index 055219f..7aa1102 100644 --- a/src/main/java/com/quinn/service/SourceService.java +++ b/src/main/java/com/quinn/service/SourceService.java @@ -2,8 +2,12 @@ package com.quinn.service; import com.quinn.pojo.Source; import com.baomidou.mybatisplus.extension.service.IService; +import com.quinn.vo.SourceUpdateForm; +import com.quinn.vo.SourceWriteForm; +import org.springframework.web.multipart.MultipartFile; import javax.servlet.ServletOutputStream; +import javax.servlet.http.HttpServletResponse; import java.io.IOException; import java.io.OutputStream; @@ -19,17 +23,38 @@ public interface SourceService extends IService { /** * 下载对应的资源 - * @param outputStream + * @param response * @param source * @throws IOException */ - void downloadSource(ServletOutputStream outputStream, Source source) throws IOException; + void downloadSource(HttpServletResponse response, Source source) throws IOException; + + void downloadForBaidu(HttpServletResponse response, Source source) throws IOException; /** * 点击对应的资源 * @throws IOException * @return */ - Source hotResource(String sid); + Source view(String sid); + /** + * 上传新资源 + * @param file + * @param sourceWriteForm + */ + void uploadNewSource(MultipartFile file, SourceWriteForm sourceWriteForm) throws IOException; + + /** + * 更新资源 + * @param file + * @param sourceUpdateForm + */ + void updateSource(MultipartFile file, SourceUpdateForm sourceUpdateForm) throws IOException; + + /** + * 删除资源 + * @param sid + */ + void deleteSource(String sid); } diff --git a/src/main/java/com/quinn/service/impl/SourceServiceImpl.java b/src/main/java/com/quinn/service/impl/SourceServiceImpl.java index 693e6b2..961eae4 100644 --- a/src/main/java/com/quinn/service/impl/SourceServiceImpl.java +++ b/src/main/java/com/quinn/service/impl/SourceServiceImpl.java @@ -2,20 +2,29 @@ package com.quinn.service.impl; import com.baomidou.mybatisplus.core.conditions.query.QueryWrapper; import com.quinn.common.QuinnConstant; +import com.quinn.common.SourceType; +import com.quinn.mapper.SourceCategoryMapper; import com.quinn.pojo.Source; import com.quinn.mapper.SourceMapper; +import com.quinn.pojo.SourceCategory; import com.quinn.service.SourceService; import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl; import com.quinn.utils.OSSClientUtil; +import com.quinn.utils.QuinnUtils; import com.quinn.utils.RedisUtils; +import com.quinn.vo.SourceUpdateForm; +import com.quinn.vo.SourceWriteForm; import org.springframework.stereotype.Service; import org.springframework.util.StringUtils; +import org.springframework.web.multipart.MultipartFile; import javax.annotation.Resource; -import javax.servlet.ServletOutputStream; +import javax.servlet.http.HttpServletResponse; import java.io.BufferedInputStream; import java.io.BufferedOutputStream; import java.io.IOException; +import java.io.PrintWriter; +import java.util.Date; /** *

@@ -32,14 +41,16 @@ public class SourceServiceImpl extends ServiceImpl impleme OSSClientUtil ossClientUtil; @Resource RedisUtils redisUtils; + @Resource + SourceCategoryMapper sourceCategoryMapper; @Override - public void downloadSource(ServletOutputStream outputStream, Source source) throws IOException { + public void downloadSource(HttpServletResponse response, Source source) throws IOException { String sourceLink = source.getSourceLink(); addDownLoadRecord(source); // 读取文件内容。 BufferedInputStream in = new BufferedInputStream(ossClientUtil.downloadFile(sourceLink)); - BufferedOutputStream out = new BufferedOutputStream(outputStream); + BufferedOutputStream out = new BufferedOutputStream(response.getOutputStream()); byte[] buffer = new byte[1024]; int lenght = 0; while ((lenght = in.read(buffer)) != -1) { @@ -55,26 +66,137 @@ public class SourceServiceImpl extends ServiceImpl impleme } @Override - public Source hotResource(String sid) { - Source source = getOne(new QueryWrapper().eq("id", sid)); + public void downloadForBaidu(HttpServletResponse response, Source source) throws IOException { + addDownLoadRecord(source); + PrintWriter writer = response.getWriter(); + writer.write(source.getSourceLink()); + writer.flush(); + writer.close(); + } + + @Override + public Source view(String sid) { + Source source = getOne(new QueryWrapper().eq("sid", sid)); addDownLoadRecord(source); return source; } + @Override + public void uploadNewSource(MultipartFile file, SourceWriteForm sourceWriteForm) throws IOException { + // 先进行文件上传成功再落地 + String fileType = ""; + String fileLink = sourceWriteForm.getSourceLink(); + if (file != null && !file.isEmpty() && SourceType.OSS.name().equals(sourceWriteForm.getSourceType())){ + String originalFilename = file.getOriginalFilename(); + fileType = originalFilename.substring(originalFilename.lastIndexOf(QuinnConstant.LINK_SUFFIX)).toLowerCase(); + fileLink = ossClientUtil.uploadFile(QuinnUtils.getUuid() + QuinnConstant.LINK_DATE_STR + + QuinnUtils.getStrFromDate(new Date()), file.getInputStream()); + } + // 构建问题对象 + Source source = new Source(); + source.setSid(QuinnUtils.getUuid()); + source.setEnName(sourceWriteForm.getEnName()); + source.setFileType(fileType); + source.setSourceName(sourceWriteForm.getTitle()); + source.setDetail(sourceWriteForm.getSubContent()); + source.setSourceContent(sourceWriteForm.getContent()); + String keyWords = sourceWriteForm.getKeyWords(); + if (!StringUtils.isEmpty(keyWords)){ + //兼容中英文逗号 + keyWords = keyWords.replaceAll(",",","); + String[] split = keyWords.split(QuinnConstant.LINK_KEY_WORD); + source.setKeyWord1(split[0]); + if (split.length > 1){ + source.setKeyWord2(split[1]); + if (split.length > 2){ + source.setKeyWord3(split[2]); + } + } + } + source.setSourceType(sourceWriteForm.getSourceType()); + source.setSourceLink(fileLink); + + // 类型 + source.setCategoryId(sourceWriteForm.getCategoryId()); + SourceCategory category = sourceCategoryMapper.selectById(sourceWriteForm.getCategoryId()); + source.setCategoryName(category.getCategory()); + source.setDownRecord(0); + source.setGmtCreate(QuinnUtils.getTime()); + source.setGmtUpdate(QuinnUtils.getTime()); + // 存储对象 + save(source); + } + + @Override + public void updateSource(MultipartFile file, SourceUpdateForm sourceUpdateForm) throws IOException { + Source before = getOne(new QueryWrapper().eq("sid",sourceUpdateForm.getSid())); + String fileType = before.getFileType(); + // 先进行文件上传成功再落地 + String fileLink = before.getSourceLink(); + if (file != null && !file.isEmpty() && SourceType.OSS.name().equals(sourceUpdateForm.getSourceType())){ + // 上传了新文件,需要删除之前的文件 + ossClientUtil.deleteFile(before.getSourceLink()); + String originalFilename = file.getOriginalFilename(); + fileType = originalFilename.substring(originalFilename.lastIndexOf(QuinnConstant.LINK_SUFFIX)).toLowerCase(); + fileLink = ossClientUtil.uploadFile(QuinnUtils.getUuid() + QuinnConstant.LINK_DATE_STR + + QuinnUtils.getStrFromDate(new Date()), file.getInputStream()); + }else if (!SourceType.OSS.name().equals(sourceUpdateForm.getSourceType()) && !StringUtils.isEmpty(sourceUpdateForm.getSourceLink())){ + fileLink = sourceUpdateForm.getSourceLink(); + } + before.setEnName(sourceUpdateForm.getEnName()); + before.setFileType(fileType); + before.setSourceName(sourceUpdateForm.getSourceName()); + before.setDetail(sourceUpdateForm.getDetail()); + before.setSourceContent(sourceUpdateForm.getSourceContent()); + String keyWords = sourceUpdateForm.getKeyWords(); + if (!StringUtils.isEmpty(keyWords)){ + //兼容中英文逗号 + keyWords = keyWords.replaceAll(",",","); + String[] split = keyWords.split(QuinnConstant.LINK_KEY_WORD); + before.setKeyWord1(split[0]); + if (split.length > 1){ + before.setKeyWord2(split[1]); + if (split.length > 2){ + before.setKeyWord3(split[2]); + } + } + } + before.setSourceType(sourceUpdateForm.getSourceType()); + before.setSourceLink(fileLink); + + // 类型 + before.setCategoryId(sourceUpdateForm.getCategoryId()); + SourceCategory category = sourceCategoryMapper.selectById(sourceUpdateForm.getCategoryId()); + before.setCategoryName(category.getCategory()); + before.setGmtUpdate(QuinnUtils.getTime()); + updateById(before); + } + + @Override + public void deleteSource(String sid) { + Source before = getOne(new QueryWrapper().eq("sid",sid)); + if (SourceType.OSS.name().equals(before.getSourceType())){ + // 上传了新文件,需要删除之前的文件 + ossClientUtil.deleteFile(before.getSourceLink()); + } + removeById(before); + } + /** * 更新页码 * @param source */ private void addDownLoadRecord(Source source) { - String downLoadTime = redisUtils.get(QuinnConstant.SOURCE_KEY + source.getId()); + String downLoadTime = redisUtils.get(QuinnConstant.SOURCE_KEY + source.getSid()); int downTimes = 0; if (StringUtils.isEmpty(downLoadTime)){ downTimes = source.getDownRecord() + 1; }else { downTimes = Integer.parseInt(downLoadTime) + 1; } - redisUtils.set(QuinnConstant.SOURCE_KEY + source.getId(),downTimes + ""); + redisUtils.set(QuinnConstant.SOURCE_KEY + source.getSid(),downTimes + ""); source.setDownRecord(source.getDownRecord() + 1); updateById(source); } + } diff --git a/src/main/java/com/quinn/utils/OSSClientUtil.java b/src/main/java/com/quinn/utils/OSSClientUtil.java index 121223e..416c761 100644 --- a/src/main/java/com/quinn/utils/OSSClientUtil.java +++ b/src/main/java/com/quinn/utils/OSSClientUtil.java @@ -49,8 +49,10 @@ public class OSSClientUtil { private String url; private OSSClient ossClient; - public String upload(String filename, InputStream file) { - return uploadImg(file, filename); + String SAVE_DIR = "data/recovery/"; + + public String uploadFile(String filename, InputStream file) { + return uploadFile(file, filename); } /** @@ -59,28 +61,23 @@ public class OSSClientUtil { * @param file * @return */ - public String uploadImg(MultipartFile file) throws IOException { + public String uploadFile(MultipartFile file) throws IOException { String originalFilename = file.getOriginalFilename(); - return uploadImg(file.getInputStream(), originalFilename); + return uploadFile(file.getInputStream(), originalFilename); } - public String uploadImg(InputStream inputStream, String originalFilename) { + private String uploadFile(InputStream inputStream, String fileName) { String backUrl = ""; try { ossClient = new OSSClient(endpoint, accessKeyId, accessKeySecret); - String substring = originalFilename.substring(originalFilename.lastIndexOf(".")).toLowerCase(); - Random random = new Random(); - String name = random.nextInt(10000) + System.currentTimeMillis() + substring; - backUrl = "imageDir/" + name; + backUrl = SAVE_DIR + fileName; // 上传文件 ossClient.putObject(bucketName, backUrl, inputStream); ossClient.setObjectAcl(bucketName, backUrl, CannedAccessControlList.PublicRead); // 判断是否上传成功 boolean uploadResult = ossClient.doesObjectExist(bucketName, backUrl); - if (uploadResult) { - backUrl = getImgUrl(name); - } else { + if (!uploadResult) { backUrl = ""; } } finally { @@ -112,4 +109,14 @@ public class OSSClientUtil { return ossObject.getObjectContent(); } + public void deleteFile(String objName){ + // ossObject包含文件所在的存储空间名称、文件名称、文件元信息以及一个输入流。 + ossClient = new OSSClient(endpoint, accessKeyId, accessKeySecret); + try { + ossClient.deleteObject(bucketName,objName); + }catch (Exception e){ + log.error("删除失败",e); + } + } + } diff --git a/src/main/java/com/quinn/utils/QuinnUtils.java b/src/main/java/com/quinn/utils/QuinnUtils.java index 0ac56a5..1222f49 100644 --- a/src/main/java/com/quinn/utils/QuinnUtils.java +++ b/src/main/java/com/quinn/utils/QuinnUtils.java @@ -1,6 +1,7 @@ package com.quinn.utils; import java.sql.Timestamp; +import java.text.SimpleDateFormat; import java.util.Date; import java.util.UUID; @@ -8,6 +9,8 @@ public class QuinnUtils { static boolean printFlag = true; + private final static SimpleDateFormat sdf = new SimpleDateFormat( "yyyyMMdd"); + public static String getUuid(){ return UUID.randomUUID().toString().replaceAll("-",""); } @@ -16,6 +19,10 @@ public class QuinnUtils { return new Timestamp(new Date().getTime()); } + public static String getStrFromDate(Date date){ + return sdf.format(date); + } + public static void print(String msg){ if (printFlag){ System.out.println("quinn:=>"+msg); diff --git a/src/main/java/com/quinn/vo/QuestionWriteForm.java b/src/main/java/com/quinn/vo/QuestionWriteForm.java index 118168e..d706de8 100644 --- a/src/main/java/com/quinn/vo/QuestionWriteForm.java +++ b/src/main/java/com/quinn/vo/QuestionWriteForm.java @@ -10,12 +10,12 @@ import lombok.experimental.Accessors; @Accessors(chain = true) public class QuestionWriteForm { - @ApiModelProperty(value = "问题标题") + @ApiModelProperty(value = "标题") private String title; - @ApiModelProperty(value = "问题内容") + @ApiModelProperty(value = "内容") private String content; - @ApiModelProperty(value = "问题分类id") + @ApiModelProperty(value = "分类") private Integer categoryId; @ApiModelProperty(value = "作者id") diff --git a/src/main/java/com/quinn/vo/SourceDeleteForm.java b/src/main/java/com/quinn/vo/SourceDeleteForm.java new file mode 100644 index 0000000..e0b42ce --- /dev/null +++ b/src/main/java/com/quinn/vo/SourceDeleteForm.java @@ -0,0 +1,27 @@ +package com.quinn.vo; + +import io.swagger.annotations.ApiModelProperty; +import lombok.Data; +import lombok.EqualsAndHashCode; +import lombok.experimental.Accessors; + +/** + *

+ * + *

+ * + * @author limqsh + * @since 2022-05-03 + */ +@Data +@EqualsAndHashCode(callSuper = false) +@Accessors(chain = true) +public class SourceDeleteForm { + + @ApiModelProperty(value = "资源ID") + private String sid; + + @ApiModelProperty(value = "管理员密码") + private String uploadPassWord; + +} diff --git a/src/main/java/com/quinn/vo/SourceUpdateForm.java b/src/main/java/com/quinn/vo/SourceUpdateForm.java new file mode 100644 index 0000000..63cd2b0 --- /dev/null +++ b/src/main/java/com/quinn/vo/SourceUpdateForm.java @@ -0,0 +1,54 @@ +package com.quinn.vo; + +import io.swagger.annotations.ApiModelProperty; +import lombok.Data; +import lombok.EqualsAndHashCode; +import lombok.experimental.Accessors; + +/** + *

+ * + *

+ * + * @author limqsh + * @since 2022-05-03 + */ +@Data +@EqualsAndHashCode(callSuper = false) +@Accessors(chain = true) +public class SourceUpdateForm { + + @ApiModelProperty(value = "资源ID") + private String sid; + + @ApiModelProperty(value = "资源名") + private String sourceName; + + @ApiModelProperty(value = "描述") + private String detail; + + @ApiModelProperty(value = "资源内容") + private String sourceContent; + + @ApiModelProperty(value = "关键字") + private String keyWords; + + @ApiModelProperty(value = "资源类型") + private String sourceType; + + @ApiModelProperty(value = "资源链接") + private String sourceLink; + + @ApiModelProperty(value = "类别ID") + private Integer categoryId; + + @ApiModelProperty(value = "类别名") + private String categoryName; + + @ApiModelProperty(value = "英文名") + private String enName; + + @ApiModelProperty(value = "管理员密码") + private String uploadPassWord; + +} diff --git a/src/main/java/com/quinn/vo/SourceWriteForm.java b/src/main/java/com/quinn/vo/SourceWriteForm.java new file mode 100644 index 0000000..5709101 --- /dev/null +++ b/src/main/java/com/quinn/vo/SourceWriteForm.java @@ -0,0 +1,34 @@ +package com.quinn.vo; + +import io.swagger.annotations.ApiModelProperty; +import lombok.Data; +import lombok.EqualsAndHashCode; +import lombok.experimental.Accessors; + +@Data +@EqualsAndHashCode(callSuper = false) +@Accessors(chain = true) +public class SourceWriteForm { + + @ApiModelProperty(value = "标题") + private String title; + @ApiModelProperty(value = "简介") + private String subContent; + @ApiModelProperty(value = "内容") + private String content; + @ApiModelProperty(value = "英文名") + private String enName; + @ApiModelProperty(value = "摘要") + private String keyWords; + + @ApiModelProperty(value = "分类") + private Integer categoryId; + + @ApiModelProperty(value = "文档类型") + private String sourceType; + @ApiModelProperty(value = "文档路径") + private String sourceLink; + + @ApiModelProperty(value = "管理员密码") + private String uploadPassWord; +} diff --git a/src/main/resources/application.properties b/src/main/resources/application.properties index c615839..4848f88 100644 --- a/src/main/resources/application.properties +++ b/src/main/resources/application.properties @@ -1,5 +1,10 @@ spring.profiles.active=dev +#设置单个文件大小 +spring.servlet.multipart.max-file-size= 20MB +#设置单次请求文件的总大小 +spring.servlet.multipart.max-request-size= 20MB + oss.accessKeyId=LTAIlbtS4W2Xe4OV oss.accessKeySecret=qWMYkSfmXFtRoIv9q9OCbszcF9U7dX oss.protocol=http diff --git a/src/main/resources/static/css/error.css b/src/main/resources/static/css/error.css index a6c5d50..f4cf10f 100644 --- a/src/main/resources/static/css/error.css +++ b/src/main/resources/static/css/error.css @@ -37,7 +37,7 @@ body { .NotPage { position: relative; /*z-index: -10;*/ - background: #000; + background: #4d4d4d; height: 100vh; overflow: hidden; display: flex; diff --git a/src/main/resources/static/live/js/addlive2d.js b/src/main/resources/static/live/js/addlive2d.js index 038c76c..1d504eb 100644 --- a/src/main/resources/static/live/js/addlive2d.js +++ b/src/main/resources/static/live/js/addlive2d.js @@ -49,8 +49,8 @@ try { "www.fghrsh.net": ["FGHRSH 的论坛"] }, "model_message": { - "1": ["来自 Potion Maker 的 Pio 酱 ~"], - "2": ["来自 Potion Maker 的 Tia 酱 ~"] + "1": ["来自 Pio 酱 ~"], + "2": ["来自 Tia 酱 ~"] }, "hitokoto_api_message": { "lwl12.com": ["干了这碗鸡汤,再来一碗?"], @@ -90,7 +90,7 @@ try { { "selector": "c-player div.volume", "text": ["在这里可以调整音量呢"] }, { "selector": "c-player div.list-button", "text": ["播放列表里都有什么呢"] }, { "selector": "c-player div.lyric-button", "text": ["有歌词的话就能跟着一起唱呢"] }, - { "selector": ".waifu #live2d", "text": ["干嘛呢你,快把手拿开", "鼠…鼠标放错地方了!"] } + { "selector": ".waifu #live2d", "text": ["要不~给我换个位置(ó﹏ò。)", "快…快把手拿开!"] } ], "click": [ { @@ -132,7 +132,7 @@ try { live2d_settings['screenshotCaptureName']= 'quinn.png'; live2d_settings['waifuEdgeSide'] = 'right:88'; // 看板娘贴边方向,例如 'left:0'(靠左 0px), 'right:30'(靠右 30px) live2d_settings['waifuDraggable'] = 'unlimited'; // 拖拽样式,例如 'disable'(禁用), 'axis-x'(只能水平拖拽), 'unlimited'(自由拖拽) - live2d_settings['waifuDraggableRevert'] = true; // 松开鼠标还原拖拽位置,可选 true(真), false(假) + live2d_settings['waifuDraggableRevert'] = false; // 松开鼠标还原拖拽位置,可选 true(真), false(假) initModel(modelJson); } }); diff --git a/src/main/resources/static/wangedit/js/wang.init.js b/src/main/resources/static/wangedit/js/wang.init.js new file mode 100644 index 0000000..29b194e --- /dev/null +++ b/src/main/resources/static/wangedit/js/wang.init.js @@ -0,0 +1,85 @@ +/* 如果使用该初始化方法,请一定要在html放三个标签,或者直接看代码修改内容 +*
+*
+* +* 另外此方法依赖layer.js & axios.js 做遮罩弹框, +* 也可以重写 uploadImage:onFailed | onError 自定义提示 +* */ +const E = window.wangEditor + +// 切换语言 +const LANG = location.href.indexOf('lang=en') > 0 ? 'en' : 'zh-CN' +E.i18nChangeLanguage(LANG) + +const editorConfig = { + placeholder: '请输入...', + scroll: true, // 禁止编辑器滚动 + MENU_CONF: { + uploadImage: { + fieldName: 'your-fileName', + server: '#', // 可以配置上传应用的地址 + base64LimitSize: 2 * 1024 * 1024, // 5M 以下插入 base64 + // 单个文件的最大体积限制,默认为 2M + maxFileSize: 2 * 1024 * 1024, + // 单个文件上传失败 + onFailed(file, res) { + console.log("文件过大") + $('#warn-text').html(res); + $('.toast').toast(); + }, + // 上传错误,或者触发 timeout 超时 + onError(file, err, res) { + console.log("文件过大") + layer.open({ + type: 1, //1:自定义内容 2:iframe + title: '图片大于2M', + // area: ['500px', '170px'], + content: '资源有限,大佬请使用网络图片╮(╯▽╰)╭', + btn: ['好吧穷鬼'], + skin: 'layui-layer-hui', + yes: function(){ + layer.closeAll(); //关闭所有弹出框 + }, + cancel: function(){ + //右上角关闭回调 + //return false 开启该代码可禁止点击该按钮关闭 + } + }); + } + } + }, + onChange(editor) { + // console.log(editor.getHtml()) + // $('#content-textarea').value = editor.getHtml() + const content = editor.children + // const contentStr = JSON.stringify(content) + // document.getElementById('content-textarea').value = contentStr + const html = editor.getHtml() + $('#content-textarea').val(html) + } +} + +// 先创建 editor +const editor = E.createEditor({ + selector: '#editor-text-area', + // content: [], + html: $('#content-textarea').val(), + config: editorConfig +}) + +// 创建 toolbar +const toolbar = E.createToolbar({ + editor, + selector: '#editor-toolbar', + config: { + excludeKeys: 'fullScreen,uploadVideo', + } +}) + +// 点击空白处 focus 编辑器 +$('#editor-text-area')[0].addEventListener('click', e => { + if (e.target.id === 'editor-text-area') { + editor.blur() + editor.focus(true) // focus 到末尾 + } +}) diff --git a/src/main/resources/templates/blog/editor.html b/src/main/resources/templates/blog/editor.html index d4efcaa..f33888e 100644 --- a/src/main/resources/templates/blog/editor.html +++ b/src/main/resources/templates/blog/editor.html @@ -52,13 +52,13 @@
- +
- + @@ -75,57 +75,8 @@ - + + + diff --git a/src/main/resources/templates/blog/read.html b/src/main/resources/templates/blog/read.html index c854c46..cf2084b 100644 --- a/src/main/resources/templates/blog/read.html +++ b/src/main/resources/templates/blog/read.html @@ -83,7 +83,7 @@
- + diff --git a/src/main/resources/templates/blog/write.html b/src/main/resources/templates/blog/write.html index d45b13d..1596310 100644 --- a/src/main/resources/templates/blog/write.html +++ b/src/main/resources/templates/blog/write.html @@ -53,19 +53,18 @@
- +
- + -
返回顶部 @@ -76,58 +75,9 @@ - + + + diff --git a/src/main/resources/templates/common/header.html b/src/main/resources/templates/common/header.html index 354be2f..8a53604 100644 --- a/src/main/resources/templates/common/header.html +++ b/src/main/resources/templates/common/header.html @@ -20,9 +20,9 @@
  • 首页
  • -
  • - 问答 -
  • + + +
  • 论坛
  • diff --git a/src/main/resources/templates/error/check.html b/src/main/resources/templates/error/check.html new file mode 100644 index 0000000..d09483b --- /dev/null +++ b/src/main/resources/templates/error/check.html @@ -0,0 +1,18 @@ + + + + + + ERROR-Quinn + + + + + + + + diff --git a/src/main/resources/templates/login.html b/src/main/resources/templates/login.html index 59b1ee5..87625ca 100644 --- a/src/main/resources/templates/login.html +++ b/src/main/resources/templates/login.html @@ -23,7 +23,7 @@ - +

    没有账号?去注册 diff --git a/src/main/resources/templates/question/editor.html b/src/main/resources/templates/question/editor.html index 40a29af..7e7f70e 100644 --- a/src/main/resources/templates/question/editor.html +++ b/src/main/resources/templates/question/editor.html @@ -56,7 +56,7 @@ - + diff --git a/src/main/resources/templates/question/read.html b/src/main/resources/templates/question/read.html index 0e71052..5712ee7 100644 --- a/src/main/resources/templates/question/read.html +++ b/src/main/resources/templates/question/read.html @@ -83,7 +83,7 @@

    - + diff --git a/src/main/resources/templates/question/write.html b/src/main/resources/templates/question/write.html index 4faf390..c959e38 100644 --- a/src/main/resources/templates/question/write.html +++ b/src/main/resources/templates/question/write.html @@ -57,7 +57,7 @@ - + diff --git a/src/main/resources/templates/register.html b/src/main/resources/templates/register.html index a9d1884..a3ddab6 100644 --- a/src/main/resources/templates/register.html +++ b/src/main/resources/templates/register.html @@ -20,7 +20,7 @@ - +

    已有账号?去登录 diff --git a/src/main/resources/templates/source/editorSource.html b/src/main/resources/templates/source/editorSource.html new file mode 100644 index 0000000..b29104d --- /dev/null +++ b/src/main/resources/templates/source/editorSource.html @@ -0,0 +1,151 @@ + + + + + + 论坛-Quinn + + + + + + +

    +
    +
    +
    +
    +

    修改资源

    + 删除资源 +
    +
    + + +
    +
    + + +
    +
    + + +
    +
    + + +
    + +
    + + +
    + +
    + + +
    + +
    + + +
    + +
    + + +
    + + + + + +
    +
    +
    +
    +
    + +
    +
    +
    + + +
    +
    +
    +
    +
    +
    + +返回顶部 + + + + + + + + + + + + + diff --git a/src/main/resources/templates/source/hotspot.html b/src/main/resources/templates/source/hotspot.html index f267c94..b1efae4 100644 --- a/src/main/resources/templates/source/hotspot.html +++ b/src/main/resources/templates/source/hotspot.html @@ -26,7 +26,7 @@ diff --git a/src/main/resources/templates/source/list.html b/src/main/resources/templates/source/list.html index d384aed..b6e63b8 100644 --- a/src/main/resources/templates/source/list.html +++ b/src/main/resources/templates/source/list.html @@ -48,21 +48,21 @@ - + - - + diff --git a/src/main/resources/templates/source/uploadSource.html b/src/main/resources/templates/source/uploadSource.html new file mode 100644 index 0000000..806e0d6 --- /dev/null +++ b/src/main/resources/templates/source/uploadSource.html @@ -0,0 +1,124 @@ + + + + + + 资源-Quinn + + + + +
    +
    +
    +
    +

    发布新资源

    + +
    + + + + + +
    +
    + + +
    + +
    + + +
    + +
    + + +
    + +
    + + +
    + +
    + + +
    + +
    + + +
    + +
    + + +
    + + + + + +
    +
    +
    +
    +
    + +
    +
    +
    + + +
    +
    +
    +
    + +返回顶部 + + + + + + + + + + + + + + + diff --git a/src/main/resources/templates/source/view.html b/src/main/resources/templates/source/view.html index 1797610..bd583a7 100644 --- a/src/main/resources/templates/source/view.html +++ b/src/main/resources/templates/source/view.html @@ -22,10 +22,15 @@ 类别- - 下载 + 下载

    - +
    +
    + + +
    +
    @@ -40,15 +45,15 @@
    -
    + - +
    - +
    @@ -96,6 +101,26 @@ + diff --git a/src/main/resources/templates/user/settings.html b/src/main/resources/templates/user/settings.html index da5e7af..e4233e0 100644 --- a/src/main/resources/templates/user/settings.html +++ b/src/main/resources/templates/user/settings.html @@ -83,7 +83,7 @@
    - +
    # 资源名 资源简介 资源类型热度 去下载
    - 详情 + + 详情