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 12, 2024
2 parents 81aafca + 393cc89 commit cb3c02b
Show file tree
Hide file tree
Showing 273 changed files with 4,218 additions and 38,098 deletions.
22 changes: 12 additions & 10 deletions README-EN.md
Original file line number Diff line number Diff line change
Expand Up @@ -27,7 +27,6 @@ Blossom doesn't rely on any third-party storage or image hosting; it functions a

You can write in Markdown with non-destructive syntax extensions, content created here can be displayed correctly in any Markdown software.


### Quick Migration

All images and articles support one-click backup and export, making migration easy within minutes. The exported files can seamlessly be opened with local software like VS Code or Obsidian.
Expand Down Expand Up @@ -75,15 +74,18 @@ However, sustaining a livelihood through open-source software is challenging. Th

**Thanks to every sponsor for their strong support, Blossom becomes better because of all of you.**

| Sponsors | Sponsors | Sponsors | Sponsors |
| :------------------- | :---------------- | :---------------- | :---------------- |
| i just walked away🏃 | KalyanYang | dsx | 熊猫不是猫 |
| 白驹过隙 | Alipay-\*| Alipay-\*| Alipay Anonymous |
| 疾风剑豪索隆 | 放羊的星星 | 立冬 | 给你一支烟 |
| 林诗 | Criesgod | Alipay-\*| 黑醋栗和丁香 |
| Mr_tg000 | Lucky | egil | Glimpse |
| Alipay-\*\*| Alipay-\*\*| Alipay-\*\*| 何其正 |
| -A 明 | 开心。 | Please | |
| Sponsors | Sponsors | Sponsors | Sponsors |
| :------------------- | :------------ | :------------ | :--------------- |
| i just walked away🏃 | KalyanYang | dsx | 熊猫不是猫 |
| 白驹过隙 | Alipay-\*| Alipay-\*| Alipay Anonymous |
| 疾风剑豪索隆 | 放羊的星星 | 立冬 | 给你一支烟 |
| 林诗 | Criesgod | Alipay-\*| 黑醋栗和丁香 |
| Mr_tg000 | Lucky | egil | Glimpse |
| Alipay-\*\*| Alipay-\*\*| Alipay-\*\*| 何其正 |
| -A 明 | 开心。 | Please | 樹梢 |
| Alipay-\*\*耀 | Crius | 初五 | 一巷灯火深 |
| Alipay-\*\*| 木辰音 | 宁采臣 | Alipay-\*\*|
| Klaus | | | |

---

Expand Down
5 changes: 4 additions & 1 deletion README.md
Original file line number Diff line number Diff line change
Expand Up @@ -81,7 +81,10 @@ docker compose -f docker/compose/blossom-mysql8.yaml up -d
| 林诗 | Criesgod | 支付宝用户-\*| 黑醋栗和丁香 |
| Mr_tg000 | Lucky | egil | Glimpse |
| 支付宝用户-\*\*| 支付宝用户-\*\*| 支付宝用户-\*\*| 何其正 |
| -A 明 | 开心。 | Please | |
| -A 明 | 开心。 | Please | 樹梢 |
| 支付宝用户-\*\*耀 | Crius | 初五 | 一巷灯火深 |
| 支付宝用户-\*\*| 木辰音 | 宁采臣 | 支付宝用户-\*\*|
| Klaus | | | |

---

Expand Down
5 changes: 4 additions & 1 deletion SPONSORS.md
Original file line number Diff line number Diff line change
Expand Up @@ -10,4 +10,7 @@
| 林诗 | Criesgod | 支付宝用户-\*| 黑醋栗和丁香 |
| Mr_tg000 | Lucky | egil | Glimpse |
| 支付宝用户-\*\*| 支付宝用户-\*\*| 支付宝用户-\*\*| 何其正 |
| -A 明 | 开心。 | Please | |
| -A 明 | 开心。 | Please | 樹梢 |
| 支付宝用户-\*\*耀 | Crius | 初五 | 一巷灯火深 |
| 支付宝用户-\*\*| 木辰音 | 宁采臣 | 支付宝用户-\*\*|
| Klaus | | | |
1 change: 1 addition & 0 deletions blossom-backend/.gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,7 @@ target/
!.mvn/wrapper/maven-wrapper.jar
#!**/src/main/**
!**/src/test/**
/smart-doc-2.6.7/

### static ###
/backend/src/main/resources/static/blog/**
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -60,7 +60,7 @@ public class IndexMsgConsumer {
try (Directory directory = FSDirectory.open(this.searchProperties.getUserIndexDirectory(userId));
IndexWriter indexWriter = new IndexWriter(directory, new IndexWriterConfig(new StandardAnalyzer()))) {
// 查询最新的消息
ArticleEntity article = this.articleService.selectById(id, false, true, false);
ArticleEntity article = this.articleService.selectById(id, false, true, false, userId);
Document document = new Document();
document.add(new StringField("id", Convert.toStr(id), Field.Store.YES));
document.add(new TextField("name", article.getName(), Field.Store.YES));
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -41,15 +41,21 @@ public void onApplicationEvent(ApplicationEnvironmentPreparedEvent event) {
"\n[CHECK] 数据库配置: {}" +
"\n[CHECK] 数据库用户: {}" +
"\n[CHECK] 数据库密码: {}" +
"\n[CHECK] 图片前缀: {}" +
"\n[CHECK] 图片存储: {}" +
"\n[CHECK] 文件前缀: {}, 非 [http://www.xxx.com/] 内容会强制覆盖后台配置" +
"\n[CHECK] 文件存储: {}" +
"\n[CHECK] 文件大小: {}" +
"\n[CHECK] 授权时长: {}" +
"\n[CHECK] 重置密码: {}" +
"\n[CHECK] ==========================================================================================================================\n\n",
get(env, SpringUtil.PROFILE_ACTION), get(env, "project.base.version"),
get(env, "spring.datasource.url"),
get(env, "spring.datasource.username"),
get(env, "spring.datasource.password"),
get(env, "project.iaas.blos.domain"),
get(env, "project.iaas.blos.default-path")
get(env, "project.iaas.blos.default-path"),
get(env, "spring.servlet.multipart.max-file-size"),
get(env, "project.auth.clients[0].duration"),
get(env, "project.auth.password-reset")
);

String defaultPath = get(env, "project.iaas.blos.default-path");
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -92,7 +92,7 @@ public R<ArticleInfoRes> info(@RequestParam("id") Long id,
if (showHtml == null) {
showHtml = false;
}
ArticleEntity article = baseService.selectById(id, showToc, showMarkdown, showHtml);
ArticleEntity article = baseService.selectById(id, showToc, showMarkdown, showHtml, AuthContext.getUserId());
XzException400.throwBy(ObjUtil.isNull(article), "文章不存在");
ArticleInfoRes res = article.to(ArticleInfoRes.class);
res.setTags(DocUtil.toTagList(article.getTags()));
Expand Down Expand Up @@ -177,7 +177,7 @@ public R<?> updName(@Validated @RequestBody ArticleUpdNameReq name) {
*/
@PostMapping("/upd/tag")
public R<List<String>> updTag(@Validated @RequestBody ArticleUpdTagReq req) {
ArticleEntity info = baseService.selectById(req.getId(), false, false, false);
ArticleEntity info = baseService.selectById(req.getId(), false, false, false, AuthContext.getUserId());
List<String> tags = DocUtil.toTagList(info.getTags());
if (tags.contains(req.getTag().toLowerCase()) || tags.contains(req.getTag().toUpperCase())) {
tags.remove(req.getTag().toLowerCase());
Expand All @@ -196,7 +196,7 @@ public R<List<String>> updTag(@Validated @RequestBody ArticleUpdTagReq req) {
*/
@PostMapping("/del")
public R<?> delete(@Validated @RequestBody DelReq req) {
baseService.delete(req.getId());
baseService.delete(req.getId(), AuthContext.getUserId());
return R.ok();
}

Expand All @@ -219,7 +219,7 @@ public R<Long> star(@Validated @RequestBody ArticleStarReq req) {
*/
@GetMapping("/download")
public void download(@RequestParam("id") Long id, HttpServletResponse response) throws IOException {
ArticleEntity article = baseService.selectById(id, false, true, false);
ArticleEntity article = baseService.selectById(id, false, true, false, AuthContext.getUserId());
if (StrUtil.isBlank(article.getMarkdown())) {
throw new IllegalArgumentException("文章内容为空,无法导出");
}
Expand All @@ -240,7 +240,7 @@ public void download(@RequestParam("id") Long id, HttpServletResponse response)
*/
@GetMapping("/download/html")
public void downloadHtml(@RequestParam("id") Long id, HttpServletResponse response) throws IOException {
ArticleEntity article = baseService.selectById(id, false, false, true);
ArticleEntity article = baseService.selectById(id, false, false, true, AuthContext.getUserId());
if (StrUtil.isBlank(article.getHtml())) {
throw new IllegalArgumentException("文章内容为空,无法导出");
}
Expand Down Expand Up @@ -271,6 +271,7 @@ public R<?> upload(@RequestParam("file") MultipartFile file, @RequestParam(value
ArticleEntity article = new ArticleEntity();
article.setMarkdown(content);
article.setPid(pid);
article.setUserId(AuthContext.getUserId());
article.setName(FileUtil.getPrefix(file.getOriginalFilename()));
baseService.insert(article);
} catch (Exception e) {
Expand Down Expand Up @@ -302,7 +303,7 @@ public R<String> createTempVisitKey(@RequestParam("id") Long id) {
public String content(@RequestParam("k") String s, HttpServletResponse resp) {
ArticleTempVisitService.TempVisit visit = tempVisitService.get(s);
XzException404.throwBy(ObjUtil.isNull(visit), "文章不存在或您无权限查看");
ArticleEntity article = baseService.selectById(visit.getArticleId(), false, false, true);
ArticleEntity article = baseService.selectById(visit.getArticleId(), false, false, true, visit.getUserId());
resp.setContentType("text/html");
return ArticleUtil.toHtml(article, userService.selectById(visit.getUserId()));
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -129,7 +129,7 @@ public List<DocTreeRes> listTree(ArticleQueryReq req) {
* @param showMarkdown 是否返回 markdown 正文
* @param showHtml 是否返回 html 正文
*/
public ArticleEntity selectById(Long id, boolean showToc, boolean showMarkdown, boolean showHtml) {
public ArticleEntity selectById(Long id, boolean showToc, boolean showMarkdown, boolean showHtml, Long userId) {
QueryWrapper<ArticleEntity> where = new QueryWrapper<>();
List<String> column = CollUtil.newArrayList("id", "pid", "name", "icon", "tags", "sort", "cover", "describes", "star_status",
"open_status", "pv", "uv", "likes", "words", "version", "cre_time", "upd_time");
Expand All @@ -143,7 +143,7 @@ public ArticleEntity selectById(Long id, boolean showToc, boolean showMarkdown,
column.add("html");
}
where.select(column);
where.eq("id", id).last("limit 1");
where.eq("id", id).eq("user_id", userId).last("limit 1");
return baseMapper.selectOne(where);
}

Expand Down Expand Up @@ -200,8 +200,8 @@ public Integer updateContentById(ArticleEntity req) {
*/
@EnableIndex(type = IndexMsgTypeEnum.DELETE, id = "#id")
@Transactional(rollbackFor = Exception.class)
public void delete(Long id) {
ArticleEntity article = selectById(id, false, true, true);
public void delete(Long id, Long userId) {
ArticleEntity article = selectById(id, false, true, true, userId);
XzException404.throwBy(ObjUtil.isNull(article), "文章不存在");
/*
@since 1.10.0
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -76,19 +76,4 @@ public TempVisit(Long articleId, Long userId) {
this.userId = userId;
}
}


// public static void main(String[] args) throws InterruptedException {
// ArticleTempService a = new ArticleTempService();
// String key = a.create(20034L);
// System.out.println(key);
//
// Thread.sleep(2000);
// Long v1 = a.get(key);
// System.out.println(v1);
//
// Thread.sleep(5000);
// Long v2 = a.get(key);
// System.out.println(v2);
// }
}
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,7 @@
import com.blossom.backend.base.paramu.UserParamEnum;
import com.blossom.backend.base.paramu.UserParamService;
import com.blossom.backend.base.paramu.pojo.UserParamEntity;
import com.blossom.backend.config.BlConstants;
import com.blossom.backend.server.article.draft.ArticleService;
import com.blossom.backend.server.article.draft.pojo.ArticleEntity;
import com.blossom.backend.server.article.draft.pojo.ArticleInfoRes;
Expand Down Expand Up @@ -57,7 +58,9 @@ public class ArticleOpenController {
*/
@AuthIgnore
@GetMapping("/info")
public R<ArticleInfoRes> infoOpen(@RequestParam("id") Long id, HttpServletRequest request) {
public R<ArticleInfoRes> infoOpen(@RequestHeader(BlConstants.REQ_HEADER_USERID) Long userId,
@RequestParam("id") Long id,
HttpServletRequest request) {
log.info("公开文章被查看:{}", id);
ArticleOpenEntity open = openService.selectById(id, true, false, true);
XzException404.throwBy(ObjUtil.isNull(open), "文章不存在");
Expand All @@ -68,7 +71,7 @@ public R<ArticleInfoRes> infoOpen(@RequestParam("id") Long id, HttpServletReques
res.setSyncTime(open.getSyncTime());
res.setType(DocTypeEnum.A.getType());

ArticleEntity article = articleService.selectById(id, false, false, false);
ArticleEntity article = articleService.selectById(id, false, false, false, userId);
if (article != null) {
res.setTags(DocUtil.toTagList(article.getTags()));
res.setName(article.getName());
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -129,11 +129,11 @@ private void sendfile(String filename, HttpServletResponse resp) {
long size = fileChannel.size();
String contentType = Files.probeContentType(file);
if (contentType == null) {
contentType = MediaType.APPLICATION_OCTET_STREAM_VALUE;
contentType = probContentType(filename);
}
resp.setContentType(contentType);
resp.setContentLengthLong(size);
// resp.setHeader(HttpHeaders.CACHE_CONTROL,"max-age=3600");
// resp.setHeader(HttpHeaders.CACHE_CONTROL, "max-age=13600");

long position = 0;
WritableByteChannel channel = Channels.newChannel(os);
Expand All @@ -149,5 +149,12 @@ private void sendfile(String filename, HttpServletResponse resp) {
}
}

private String probContentType(String filename) {
if (filename.endsWith(".svg")) {
return "image/svg+xml";
}
return MediaType.APPLICATION_OCTET_STREAM_VALUE;
}

// endregion
}
Original file line number Diff line number Diff line change
Expand Up @@ -178,7 +178,6 @@ public PictureEntity insert(MultipartFile file, String filename, Long pid, Long

PictureEntity originPic;
if ((originPic = baseMapper.selectByPathName(pic.getPathName())) != null) {

// 如果允许重复上传, 则修改大小
if (repeatUpload) {
PictureEntity upd = new PictureEntity();
Expand All @@ -187,12 +186,13 @@ public PictureEntity insert(MultipartFile file, String filename, Long pid, Long
upd.setCreTime(new Date());
baseMapper.updById(upd);
pic.setId(originPic.getId());
return pic;
} else {
throw new XzException400HTTP("图片[" + pic.getPathName() + "]已存在, 请重命名文件或选择其他路径!");
}
throw new XzException400HTTP("图片[" + pic.getPathName() + "]已存在, 请重命名文件或选择其他路径!");
} else {
baseMapper.insert(pic);
}

baseMapper.insert(pic);
// 入库后进行文件上传操作
try (InputStream inputStream = file.getInputStream()) {
osManager.put(pic.getPathName(), inputStream);
Expand Down
Loading

0 comments on commit cb3c02b

Please sign in to comment.