Skip to content

Commit

Permalink
Merge branch 'blossom-editor:dev' into dev
Browse files Browse the repository at this point in the history
  • Loading branch information
T1anjiu authored Jan 28, 2024
2 parents cb3c02b + 1ac36e2 commit 1c59f0a
Show file tree
Hide file tree
Showing 68 changed files with 3,203 additions and 669 deletions.
17 changes: 5 additions & 12 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -73,18 +73,11 @@ docker compose -f docker/compose/blossom-mysql8.yaml up -d

**感谢每一个位赞助者对 Blossom 的大力支持,Blossom 因为你们变得更好。**

| 赞助者 / Sponsors | 赞助者 / Sponsors | 赞助者 / Sponsors | 赞助者 / Sponsors |
| :------------------- | :---------------- | :---------------- | :---------------- |
| i just walked away🏃 | KalyanYang | dsx | 熊猫不是猫 |
| 白驹过隙 | 支付宝用户-\*| 支付宝用户-\*| 支付宝匿名用户 |
| 疾风剑豪索隆 | 放羊的星星 | 立冬 | 给你一支烟 |
| 林诗 | Criesgod | 支付宝用户-\*| 黑醋栗和丁香 |
| Mr_tg000 | Lucky | egil | Glimpse |
| 支付宝用户-\*\*| 支付宝用户-\*\*| 支付宝用户-\*\*| 何其正 |
| -A 明 | 开心。 | Please | 樹梢 |
| 支付宝用户-\*\*耀 | Crius | 初五 | 一巷灯火深 |
| 支付宝用户-\*\*| 木辰音 | 宁采臣 | 支付宝用户-\*\*|
| Klaus | | | |
<p align="center">
<a target="_blank" href="https://www.wangyunf.com/blossom-doc/guide/about/sponsor-list.html">
<img alt="sponsors" src="https://www.wangyunf.com/bl/pic/home/bl/img/U1/pic/sponsor.svg">
</a>
</p>

---

Expand Down
17 changes: 5 additions & 12 deletions SPONSORS.md
Original file line number Diff line number Diff line change
Expand Up @@ -2,15 +2,8 @@

感谢每一个位赞助者对 Blossom 的大力支持,Blossom 因为你们变得更好。

| 赞助者 / Sponsors | 赞助者 / Sponsors | 赞助者 / Sponsors | 赞助者 / Sponsors |
| :------------------- | :---------------- | :---------------- | :---------------- |
| i just walked away🏃 | KalyanYang | dsx | 熊猫不是猫 |
| 白驹过隙 | 支付宝用户-\*| 支付宝用户-\*| 支付宝匿名用户 |
| 疾风剑豪索隆 | 放羊的星星 | 立冬 | 给你一支烟 |
| 林诗 | Criesgod | 支付宝用户-\*| 黑醋栗和丁香 |
| Mr_tg000 | Lucky | egil | Glimpse |
| 支付宝用户-\*\*| 支付宝用户-\*\*| 支付宝用户-\*\*| 何其正 |
| -A 明 | 开心。 | Please | 樹梢 |
| 支付宝用户-\*\*耀 | Crius | 初五 | 一巷灯火深 |
| 支付宝用户-\*\*| 木辰音 | 宁采臣 | 支付宝用户-\*\*|
| Klaus | | | |
<p align="center">
<a target="_blank" href="https://www.wangyunf.com/blossom-doc/guide/about/sponsor-list.html">
<img alt="sponsors" src="https://www.wangyunf.com/bl/pic/home/bl/img/U1/pic/sponsor.svg">
</a>
</p>
Original file line number Diff line number Diff line change
Expand Up @@ -47,7 +47,7 @@ public enum ParamEnum {
/**
* BLOSSOM 对象存储地址
*/
BLOSSOM_OBJECT_STORAGE_DOMAIN(false, 0,"http://www.xxx.com/"),
BLOSSOM_OBJECT_STORAGE_DOMAIN(false, 0,"http://www.google.com/"),

/**
* 服务器JWT加密字符串
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -41,7 +41,7 @@ public void onApplicationEvent(ApplicationEnvironmentPreparedEvent event) {
"\n[CHECK] 数据库配置: {}" +
"\n[CHECK] 数据库用户: {}" +
"\n[CHECK] 数据库密码: {}" +
"\n[CHECK] 文件前缀: {}, 非 [http://www.xxx.com/] 内容会强制覆盖后台配置" +
"\n[CHECK] 文件前缀: {}, 非 [http://www.google.com/] 内容会强制覆盖后台配置" +
"\n[CHECK] 文件存储: {}" +
"\n[CHECK] 文件大小: {}" +
"\n[CHECK] 授权时长: {}" +
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -139,6 +139,7 @@ public R<ArticleEntity> insert(@Validated @RequestBody ArticleAddReq req) {
public R<Long> insert(@Validated @RequestBody ArticleUpdReq req) {
ArticleEntity article = req.to(ArticleEntity.class);
article.setTags(DocUtil.toTagStr(req.getTags()));
article.setUserId(AuthContext.getUserId());
return R.ok(baseService.update(article));
}

Expand Down Expand Up @@ -166,6 +167,7 @@ public R<ArticleUpdContentRes> updateContent(@Validated @RequestBody ArticleUpdC
@PostMapping("/upd/name")
public R<?> updName(@Validated @RequestBody ArticleUpdNameReq name) {
ArticleEntity article = name.to(ArticleEntity.class);
article.setUserId(AuthContext.getUserId());
baseService.update(article);
return R.ok();
}
Expand All @@ -187,6 +189,7 @@ public R<List<String>> updTag(@Validated @RequestBody ArticleUpdTagReq req) {
}
ArticleEntity article = req.to(ArticleEntity.class);
article.setTags(DocUtil.toTagStr(tags));
article.setUserId(AuthContext.getUserId());
baseService.update(article);
return R.ok(tags);
}
Expand All @@ -207,7 +210,9 @@ public R<?> delete(@Validated @RequestBody DelReq req) {
*/
@PostMapping("/star")
public R<Long> star(@Validated @RequestBody ArticleStarReq req) {
return R.ok(baseService.update(req.to(ArticleEntity.class)));
ArticleEntity article = req.to(ArticleEntity.class);
article.setUserId(AuthContext.getUserId());
return R.ok(baseService.update(article));
}

/**
Expand All @@ -221,12 +226,11 @@ public R<Long> star(@Validated @RequestBody ArticleStarReq req) {
public void download(@RequestParam("id") Long id, HttpServletResponse response) throws IOException {
ArticleEntity article = baseService.selectById(id, false, true, false, AuthContext.getUserId());
if (StrUtil.isBlank(article.getMarkdown())) {
throw new IllegalArgumentException("文章内容为空,无法导出");
article.setMarkdown("文章无内容");
}
try (InputStream is = new ByteArrayInputStream(article.getMarkdown().getBytes(StandardCharsets.UTF_8));
BufferedInputStream bis = new BufferedInputStream(is)) {
String filename = URLEncodeUtil.encode(article.getName() + ".md");

DownloadUtil.forceDownload(response, bis, filename);
}
}
Expand All @@ -242,7 +246,7 @@ public void download(@RequestParam("id") Long id, HttpServletResponse response)
public void downloadHtml(@RequestParam("id") Long id, HttpServletResponse response) throws IOException {
ArticleEntity article = baseService.selectById(id, false, false, true, AuthContext.getUserId());
if (StrUtil.isBlank(article.getHtml())) {
throw new IllegalArgumentException("文章内容为空,无法导出");
article.setHtml("<span>文章无内容</span>");
}
String reportHtml = ArticleUtil.toHtml(article, userService.selectById(AuthContext.getUserId()));
try (InputStream is = new ByteArrayInputStream(reportHtml.getBytes(StandardCharsets.UTF_8));
Expand Down Expand Up @@ -270,9 +274,11 @@ public R<?> upload(@RequestParam("file") MultipartFile file, @RequestParam(value
String content = new String(file.getBytes(), StandardCharsets.UTF_8);
ArticleEntity article = new ArticleEntity();
article.setMarkdown(content);
article.setVersion(1);
article.setPid(pid);
article.setUserId(AuthContext.getUserId());
article.setName(FileUtil.getPrefix(file.getOriginalFilename()));
article.setWords(ArticleUtil.statWords(content));
baseService.insert(article);
} catch (Exception e) {
e.printStackTrace();
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -166,6 +166,7 @@ public ArticleEntity insert(ArticleEntity req) {
public Long update(ArticleEntity req) {
XzException404.throwBy(req.getId() == null, "ID不得为空");
baseMapper.updById(req);
referenceService.updateInnerName(req.getUserId(), req.getId(), req.getName());
return req.getId();
}

Expand Down Expand Up @@ -212,8 +213,10 @@ public void delete(Long id, Long userId) {
baseMapper.deleteById(id);
// 删除公开文章
openMapper.delById(id);
// 删除引用
// 删除主动引用
referenceService.delete(id);
// 将被动引用中的名称修改为未知
referenceService.updateToUnknown(userId, id);
// 删除访问记录
viewService.delete(id);
}
Expand Down
Original file line number Diff line number Diff line change
@@ -1,23 +1,33 @@
package com.blossom.backend.server.article.recycle;


import cn.hutool.core.net.URLEncodeUtil;
import cn.hutool.core.util.StrUtil;
import com.blossom.backend.base.auth.AuthContext;
import com.blossom.backend.server.article.recycle.pojo.ArticleRecycleEntity;
import com.blossom.backend.server.article.recycle.pojo.ArticleRecycleListRes;
import com.blossom.backend.server.article.recycle.pojo.ArticleRecycleRestoreReq;
import com.blossom.backend.server.utils.DownloadUtil;
import com.blossom.common.base.pojo.R;
import lombok.AllArgsConstructor;
import lombok.extern.slf4j.Slf4j;
import org.springframework.validation.annotation.Validated;
import org.springframework.web.bind.annotation.*;

import javax.servlet.http.HttpServletResponse;
import java.io.BufferedInputStream;
import java.io.ByteArrayInputStream;
import java.io.IOException;
import java.io.InputStream;
import java.nio.charset.StandardCharsets;
import java.util.List;

/**
* 文章回收站 [A#Recycle]
*
* @author xzzz
* @since 1.10.0
* @order 7
* @since 1.10.0
*/
@Slf4j
@RestController
Expand All @@ -44,7 +54,27 @@ public R<List<ArticleRecycleListRes>> listAll() {
*/
@PostMapping("/restore")
public R<?> restore(@Validated @RequestBody ArticleRecycleRestoreReq req) {
baseService.restore(req.getId());
baseService.restore(AuthContext.getUserId(), req.getId());
return R.ok();
}

/**
* 下载文章
*
* @param id 文章ID
* @param response 文章流
* @apiNote 返回流
*/
@GetMapping("/download")
public void download(@RequestParam("id") Long id, HttpServletResponse response) throws IOException {
ArticleRecycleEntity article = baseService.selectById(id);
if (StrUtil.isBlank(article.getMarkdown())) {
article.setMarkdown("文章无内容");
}
try (InputStream is = new ByteArrayInputStream(article.getMarkdown().getBytes(StandardCharsets.UTF_8));
BufferedInputStream bis = new BufferedInputStream(is)) {
String filename = URLEncodeUtil.encode(article.getName() + ".md");
DownloadUtil.forceDownload(response, bis, filename);
}
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,7 @@
import com.blossom.backend.base.search.EnableIndex;
import com.blossom.backend.base.search.message.IndexMsgTypeEnum;
import com.blossom.backend.server.article.recycle.pojo.ArticleRecycleEntity;
import com.blossom.backend.server.article.reference.ArticleReferenceService;
import com.blossom.backend.server.folder.FolderService;
import com.blossom.backend.server.folder.pojo.FolderEntity;
import com.blossom.common.base.util.DateUtils;
Expand All @@ -34,6 +35,7 @@ public class ArticleRecycleService extends ServiceImpl<ArticleRecycleMapper, Art

private final FolderService folderService;
private final ParamService paramService;
private final ArticleReferenceService referenceService;


/**
Expand All @@ -45,14 +47,23 @@ public List<ArticleRecycleEntity> listAll(Long userId) {
return baseMapper.listAll(userId);
}

/**
* 根据ID查询
*
* @param id 文章ID
*/
public ArticleRecycleEntity selectById(Long id) {
return baseMapper.selectById(id);
}

/**
* 还原数据
*
* @param id 文章ID
*/
@EnableIndex(type = IndexMsgTypeEnum.ADD, id = "#id")
@Transactional(rollbackFor = Exception.class)
public void restore(Long id) {
public void restore(Long userId, Long id) {
ArticleRecycleEntity article = baseMapper.selectById(id);
FolderEntity folder = folderService.selectById(article.getPid());
if (ObjUtil.isNull(folder)) {
Expand All @@ -61,10 +72,13 @@ public void restore(Long id) {
baseMapper.restore(id, folder.getId());
}
baseMapper.deleteById(id);
// 将被动引用中的未知文章名修改为正常文章名
referenceService.updateToKnown(userId, id, article.getName());
}

/**
* 每天凌晨4点执行
*
* @Scheduled(cron = "0 0/1 * * * ?")
*/
@Scheduled(cron = "0 0 04 * * ?")
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,30 @@
package com.blossom.backend.server.article.reference;

import lombok.Getter;

public enum ArticleReferenceEnum {
/**
* 图片
*/
FILE(10),
/**
* 内部文章
*/
INNER(11),
/**
* 未知内部文章
*/
INNER_UNKNOWN(12),

/**
* 外部文章
*/
OUTSIDE(21);

@Getter
private final Integer type;

ArticleReferenceEnum(Integer type) {
this.type = type;
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -40,4 +40,25 @@ public interface ArticleReferenceMapper extends BaseMapper<ArticleReferenceEntit
* @param articleId 文章ID
*/
List<ArticleReferenceEntity> listGraph(@Param("inner") Boolean inner, @Param("userId") Long userId, @Param("articleId") Long articleId);

/**
* 修改 sourceName
*/
void updateSourceName(@Param("userId") Long userId, @Param("sourceId") Long sourceId, @Param("sourceName") String sourceName);

/**
* 修改 targetName
*/
void updateTargetName(@Param("userId") Long userId, @Param("targetId") Long targetId, @Param("targetName") String targetName);

/**
* 被引用的文章修改为未知
*/
void updateToUnknown(@Param("userId") Long userId, @Param("targetId") Long targetId, @Param("targetName") String targetName);

/**
* 被引用的文章修改为未知
*/
void updateToKnown(@Param("userId") Long userId, @Param("targetId") Long targetId, @Param("targetName") String targetName);

}
Loading

0 comments on commit 1c59f0a

Please sign in to comment.