Commit Graph

437 Commits (fb9aff00cad2904f4c4fe7e2067b37cb8afd8c23)

Author SHA1 Message Date
John Niang fb9aff00ca
Add chunked transfer support for rendering templates (#6580)
#### What type of PR is this?

/kind improvement
/area core
/milestone 2.20.x

#### What this PR does / why we need it:

This PR adds chunked transfer support for rendering templates, which means that the max memory used by rendering template will be max chunk size instead of size of rendering result.

Users can define the max chunk size like below:

```yaml
spring:
  thymeleaf:
    reactive:
      maxChunkSize: 8KB # Setting to 0 will disable the chunked response.
```

#### Special notes for your reviewer:

1. Try to start Halo instance
2. Execute the command like below and see if the response headers contain `transfer-encoding: chunked`:
		
    ```bash
	http http://localhost:8090/ -p h
	HTTP/1.1 200 OK
	Cache-Control: no-cache, no-store, max-age=0, must-revalidate
	Content-Language: en-CN
	Content-Type: text/html
	Expires: 0
	Pragma: no-cache
	Referrer-Policy: strict-origin-when-cross-origin
	Vary: Origin
	Vary: Access-Control-Request-Method
	Vary: Access-Control-Request-Headers
	X-Content-Type-Options: nosniff
	X-Frame-Options: SAMEORIGIN
	X-XSS-Protection: 0
	content-encoding: gzip
	set-cookie: XSRF-TOKEN=1e677724-ce82-4b63-911c-f78b22cd9169; Path=/
	transfer-encoding: chunked
	```

#### Does this PR introduce a user-facing change?

```release-note
优化模板渲染时所需的内存
```
2024-09-19 10:16:55 +00:00
guqing 1c31917778
chore: replace deprecated Version methods with updated API (#6678)
#### What type of PR is this?
/milestone 2.20.x
/area core

#### What this PR does / why we need it:
替换 Version 过时方法的引用为新 API

#### Does this PR introduce a user-facing change?
```release-note
None
```
2024-09-19 07:50:55 +00:00
guqing dcadd38843
feat: add Halo version variable to theme model (#6677)
#### What type of PR is this?
/kind feature
/milestone 2.20.x
/area theme

#### What this PR does / why we need it:
主题支持通过 `${site.version}` 得到 Halo 版本号

#### Which issue(s) this PR fixes:
Fixes #6676

#### Does this PR introduce a user-facing change?
```release-note
主题支持通过 `${site.version}` 得到 Halo 版本号
```
2024-09-19 07:20:54 +00:00
John Niang 07077f7d0c
Provide ElementTagProcessor to handle element tag in plugin (#6670)
#### What type of PR is this?

/kind feature
/area plugin

#### What this PR does / why we need it:

This PR provides an interface ElementTagProcessor to make plugin handle element tag easily. e.g.:

```java
public class ImgTagProcessor implements ElementTagPostProcessor {

    @Override
    public Mono<Void> process(ITemplateContext context, IProcessableElementTag tag,
        IElementTagStructureHandler structureHandler) {
        var elementName = tag.getElementDefinition().getElementName();
        if (!Objects.equals("img", elementName.getElementName())) {
            return Mono.empty();
        }
        var srcAttr = tag.getAttribute("src");
        if (srcAttr == null) {
            return Mono.empty();
        }
        var newSrc = srcAttr.getValue();
        // TODO rewrite src
        structureHandler.setAttribute("src", newSrc);
        return Mono.empty();
    }
    
}
```

After PR merged, plugins https://github.com/webp-sh/halo-plugin-webp-cloud and https://github.com/guqing/plugin-cloudinary can be refined with new method.

#### Does this PR introduce a user-facing change?

```release-note
支持在插件中操作渲染结果
```
2024-09-19 02:56:53 +00:00
John Niang ded5b4135f
Generate JS and CSS bundle with fixed buffer size (#6573)
#### What type of PR is this?

/kind improvement
/area core
/milestone 2.20.x

#### What this PR does / why we need it:

If we are running Halo instance in machine with small memory available, the JS/CSS bundle might  not be accessible.

This RP refactors generation of JS and CSS bundle with fixed buffer size rather than length of original resources.

```java
2024-09-02T15:01:27.667+08:00  WARN 62039 --- [boundedElastic-3] reactor.core.Exceptions                  : throwIfFatal detected a jvm fatal exception, which is thrown and logged below:

java.lang.OutOfMemoryError: Java heap space
        at java.base/java.nio.HeapByteBuffer.<init>(HeapByteBuffer.java:64) ~[na:na]
        at java.base/java.nio.ByteBuffer.allocate(ByteBuffer.java:363) ~[na:na]
        at org.springframework.core.io.buffer.DefaultDataBuffer.allocate(DefaultDataBuffer.java:234) ~[spring-core-6.1.12.jar:6.1.12]
        at org.springframework.core.io.buffer.DefaultDataBuffer.setCapacity(DefaultDataBuffer.java:196) ~[spring-core-6.1.12.jar:6.1.12]
        at org.springframework.core.io.buffer.DefaultDataBuffer.ensureWritable(DefaultDataBuffer.java:228) ~[spring-core-6.1.12.jar:6.1.12]
        at org.springframework.core.io.buffer.DefaultDataBuffer.write(DefaultDataBuffer.java:296) ~[spring-core-6.1.12.jar:6.1.12]
        at org.springframework.core.io.buffer.DefaultDataBuffer.write(DefaultDataBuffer.java:289) ~[spring-core-6.1.12.jar:6.1.12]
        at org.springframework.core.io.buffer.DefaultDataBuffer.write(DefaultDataBuffer.java:43) ~[spring-core-6.1.12.jar:6.1.12]
        at run.halo.app.core.extension.service.impl.PluginServiceImpl.lambda$uglifyJsBundle$17(PluginServiceImpl.java:257) ~[classes/:na]
        at run.halo.app.core.extension.service.impl.PluginServiceImpl$$Lambda$4661/0x000000c80214e298.accept(Unknown Source) ~[na:na]
        at reactor.core.publisher.FluxPeekFuseable$PeekFuseableSubscriber.onNext(FluxPeekFuseable.java:196) ~[reactor-core-3.6.9.jar:3.6.9]
        at reactor.core.publisher.FluxUsing$UsingFuseableSubscriber.onNext(FluxUsing.java:353) ~[reactor-core-3.6.9.jar:3.6.9]
        at reactor.core.publisher.FluxGenerate$GenerateSubscription.next(FluxGenerate.java:178) ~[reactor-core-3.6.9.jar:3.6.9]
        at org.springframework.core.io.buffer.DataBufferUtils$ReadableByteChannelGenerator.accept(DataBufferUtils.java:1002) ~[spring-core-6.1.12.jar:6.1.12]
        at org.springframework.core.io.buffer.DataBufferUtils$ReadableByteChannelGenerator.accept(DataBufferUtils.java:974) ~[spring-core-6.1.12.jar:6.1.12]
        at reactor.core.publisher.FluxGenerate.lambda$new$1(FluxGenerate.java:58) ~[reactor-core-3.6.9.jar:3.6.9]
        at reactor.core.publisher.FluxGenerate$$Lambda$4155/0x000000c802069228.apply(Unknown Source) ~[na:na]
        at reactor.core.publisher.FluxGenerate$GenerateSubscription.slowPath(FluxGenerate.java:271) ~[reactor-core-3.6.9.jar:3.6.9]
        at reactor.core.publisher.FluxGenerate$GenerateSubscription.request(FluxGenerate.java:213) ~[reactor-core-3.6.9.jar:3.6.9]
        at reactor.core.publisher.FluxUsing$UsingFuseableSubscriber.request(FluxUsing.java:320) ~[reactor-core-3.6.9.jar:3.6.9]
        at reactor.core.publisher.FluxPeekFuseable$PeekFuseableSubscriber.request(FluxPeekFuseable.java:144) ~[reactor-core-3.6.9.jar:3.6.9]
        at reactor.core.publisher.FluxFlatMap$FlatMapInner.onSubscribe(FluxFlatMap.java:968) ~[reactor-core-3.6.9.jar:3.6.9]
        at reactor.core.publisher.FluxPeekFuseable$PeekFuseableSubscriber.onSubscribe(FluxPeekFuseable.java:178) ~[reactor-core-3.6.9.jar:3.6.9]
        at reactor.core.publisher.FluxUsing$UsingFuseableSubscriber.onSubscribe(FluxUsing.java:347) ~[reactor-core-3.6.9.jar:3.6.9]
        at reactor.core.publisher.FluxGenerate.subscribe(FluxGenerate.java:85) ~[reactor-core-3.6.9.jar:3.6.9]
        at reactor.core.publisher.FluxUsing.subscribe(FluxUsing.java:102) ~[reactor-core-3.6.9.jar:3.6.9]
        at reactor.core.publisher.Flux.subscribe(Flux.java:8848) ~[reactor-core-3.6.9.jar:3.6.9]
        at reactor.core.publisher.FluxFlatMap$FlatMapMain.onNext(FluxFlatMap.java:430) ~[reactor-core-3.6.9.jar:3.6.9]
        at reactor.core.publisher.FluxHandleFuseable$HandleFuseableSubscriber.tryOnNext(FluxHandleFuseable.java:135) ~[reactor-core-3.6.9.jar:3.6.9]
        at reactor.core.publisher.FluxIterable$IterableSubscriptionConditional.slowPath(FluxIterable.java:664) ~[reactor-core-3.6.9.jar:3.6.9]
        at reactor.core.publisher.FluxIterable$IterableSubscriptionConditional.request(FluxIterable.java:623) ~[reactor-core-3.6.9.jar:3.6.9]
        at reactor.core.publisher.FluxHandleFuseable$HandleFuseableSubscriber.request(FluxHandleFuseable.java:260) ~[reactor-core-3.6.9.jar:3.6.9]

2024-09-02T15:01:27.681+08:00 DEBUG 62039 --- [boundedElastic-3] a.w.r.e.AbstractErrorWebExceptionHandler : [131a559b-102] Resolved [OutOfMemoryError: Java heap space] for HTTP GET /apis/api.console.halo.run/v1alpha1/plugins/-/bundle.js
2024-09-02T15:01:27.681+08:00 ERROR 62039 --- [boundedElastic-3] a.w.r.e.AbstractErrorWebExceptionHandler : [131a559b-102]  500 Server Error for HTTP GET "/apis/api.console.halo.run/v1alpha1/plugins/-/bundle.js?v=1725260408176"

java.lang.OutOfMemoryError: Java heap space
        at java.base/java.nio.HeapByteBuffer.<init>(HeapByteBuffer.java:64) ~[na:na]
```

#### Does this PR introduce a user-facing change?

```release-note
优化在内存紧张时 Console 端无法加载插件资源的问题
```
2024-09-18 08:22:50 +00:00
guqing 749c80cb96
chore: cleanup subscription integration test (#6671)
#### What type of PR is this?
/kind cleanup
/area core
/milestone 2.20.x

#### What this PR does / why we need it:
删除 SubscriptionServiceIntegrationTest 类。因为当前测试类不经常性出错,暂时无法排查原因。

#### Does this PR introduce a user-facing change?
```release-note
None
```
2024-09-18 04:18:49 +00:00
guqing 3fda9e6db4
refactor: remove trailing slash in site url for notification (#6660)
#### What type of PR is this?
/kind improvement
/area core
/milestone 2.20.x

#### What this PR does / why we need it:
修复 external-url 配置带了尾部斜杠导致邮件通知的查看通知链接无法访问的问题

#### Which issue(s) this PR fixes:
Fixes #6655

#### Does this PR introduce a user-facing change?
```release-note
修复 external-url 配置带了尾部斜杠导致邮件通知的查看通知链接无法访问的问题
```
2024-09-14 07:16:31 +00:00
John Niang a9c0ecebe3
Support resolving i18n message with standard way (#6648)
#### What type of PR is this?

/kind feature
/area theme
/sig docs
/milestone 2.20.x

#### What this PR does / why we need it:

After this PR, we can define i18n message files next to the template file.

```yaml
i18n:
    default.properties
templates:
    index.html
    index.properties # Higher properties than default.properties
    index_zh.properties # Higher properties than index.properties
    index_zh_CN.properties # Higher priority than index_zh.properties
```

It's convenient for plugins that define the template files.

See https://www.thymeleaf.org/doc/tutorials/3.1/usingthymeleaf.html#standard-message-resolver for more.

#### Does this PR introduce a user-facing change?

```release-note
支持在主题中通过 Thymeleaf 默认行为实现国际化
```
2024-09-14 02:52:30 +00:00
John Niang c5f9c766bb
Support changing locale using query language (#6658)
#### What type of PR is this?

/kind improvement
/area core
/milestone 2.20.x

#### What this PR does / why we need it:

This PR adds support changing locale using query `language`. After passing the query, we will automatically respond a cookie `language` back to browser.

Please see the result below:

```bash
http http://localhost:8090/\?language\=zh-CN Accept:text/html -p h

HTTP/1.1 200 OK
Cache-Control: no-cache, no-store, max-age=0, must-revalidate
Content-Language: zh-CN
Content-Type: text/html
Expires: 0
Pragma: no-cache
Referrer-Policy: strict-origin-when-cross-origin
Vary: Origin
Vary: Access-Control-Request-Method
Vary: Access-Control-Request-Headers
X-Content-Type-Options: nosniff
X-Frame-Options: SAMEORIGIN
X-XSS-Protection: 0
content-encoding: gzip
content-length: 4765
set-cookie: language=zh-CN; Path=/; Secure
set-cookie: XSRF-TOKEN=f0f2c972-0024-4575-aef2-0609356b4757; Path=/
```

#### Does this PR introduce a user-facing change?

```release-note
支持利用参数 language 切换地域语言
```
2024-09-14 02:48:29 +00:00
John Niang 8ab8a440b6
Simplify ThemeLocaleContextResolver (#6651)
#### What type of PR is this?

/kind improvement
/area theme
/milestone 2.20.x

#### What this PR does / why we need it:

This PR simplifies ThemeLocaleContextResolver by removing unused attributes. 

In another PR <https://github.com/halo-dev/halo/pull/6647>, fixed locale resolution for query parameter `language`. This PR fixes locale resolution for cookie `language` as well.

Please see the results below:

```bash
http https://www.halo.run/ Cookie:language=zh-CN -p h

HTTP/1.1 200 OK
Content-Language: und
```

```bash
http http://localhost:8090 Cookie:language=zh-CN -p h

HTTP/1.1 200 OK
Content-Language: zh-CN
```

#### Does this PR introduce a user-facing change?

```release-note
None
```
2024-09-13 07:44:26 +00:00
guqing 7ed859cefb
refactor: prevent replies to comments that are pending approval (#6622)
#### What type of PR is this?
/kind improvement
/area core
/milestone 2.20.x

#### What this PR does / why we need it:
不允许回复未通过审核的评论

#### Does this PR introduce a user-facing change?
```release-note
禁止非管理员回复未通过审核的评论
```
2024-09-13 02:14:25 +00:00
guqing 07d200b45b
Trigger attachment status update on storage policy config change (#6639) 2024-09-12 17:13:19 +08:00
John Niang 6a5e9c4932
Fix the problem of resolving locale context by language parameter (#6647)
#### What type of PR is this?

/kind bug
/area theme
/milestone 2.20.x

#### What this PR does / why we need it:

If we pass a query `language` while requesting index page, we will get the wrong header `Content-Language`. Please see the result below:

```bash
http https://www.halo.run/\?language\=zh-CN -p h

HTTP/1.1 200 OK
Content-Language: und
...
```

After fixing, we will get the right header `Content-Language`.

```bash
http http://localhost:8090/\?language\=zh-CN -p h

HTTP/1.1 200 OK
Content-Language: zh-CN
...
```

#### Does this PR introduce a user-facing change?

```release-note
修复主题端区域和语言解析错误的问题
```
2024-09-12 09:12:22 +00:00
John Niang ba18f7010b
Update attachment permalink only when handler is available (#6641) 2024-09-12 11:02:21 +08:00
John Niang a36822c861
Expose CryptoService and RateLimiterRegistry to plugins (#6638)
#### What type of PR is this?

/kind feature
/area core
/area plugin
/milestone 2.20.x

#### What this PR does / why we need it:

Currently, we are refactoring login and logout pages to make them extensible. If plugins want to realize a new authentication method, the CryptoService and RateLimiterRegistry may be used to authenticate.

So this PR exposes the two beans to plugins. No side effect will be introduced.

#### Does this PR introduce a user-facing change?

```release-note
【开发相关】允许在插件使用 CryptoService 和 RateLimiterRegistry
```
2024-09-12 02:34:20 +00:00
guqing 39545a1e4c
refactor: optimize request headers when generating thumbnails from URI (#6628)
#### What type of PR is this?
/kind improvement
/area core
/milestone 2.20.x

#### What this PR does / why we need it:
优化根据 URI 生成缩略图时的请求头

1. 由于之前 attachment 的 permalink 是 `URI.toString` 会导致根据 permalink 索引查询附件可能由于编码问题无法查询到导致生成缩略图只能根据 URI 生成
2. 可能配置了 nginx 判断请求头不允许脚本请求如导致根据 URI 访问图片无法访问导致无法生成,如
```
if ($http_user agent ~*(python curlljava wget go-http-client httpclient okhttp)){
}
```

Fixes #6627

#### Does this PR introduce a user-facing change?
```release-note
None
```
2024-09-10 09:28:10 +00:00
John Niang 93ffb7d8ea
Prevent null role while getting permissions (#6612)
#### What type of PR is this?

/kind bug
/area core
/milestone 2.20.x

#### What this PR does / why we need it:

This PR filters blank role name while granting roles for an user to prevent null role in permissions.

#### Which issue(s) this PR fixes:

Fixes https://github.com/halo-dev/halo/issues/6604

#### Does this PR introduce a user-facing change?

```release-note
修复取消用户角色后无法正常渲染用户列表的问题
```
2024-09-06 14:01:52 +00:00
guqing 2ea063d37f
fix: skip thumbnail generation for GIF images (#6597)
#### What type of PR is this?
/kind bug
/area core
/milestone 2.20.x

#### What this PR does / why we need it:
修复 GIF 缩略图生成只会保留第一帧的问题

#### Which issue(s) this PR fixes:
Fixes #6596

#### Does this PR introduce a user-facing change?
```release-note
修复 GIF 缩略图生成只会保留第一帧的问题
```
2024-09-06 09:27:52 +00:00
guqing 7991ef8cf1
refactor: preserve original image if smaller than requested thumbnail size (#6582)
#### What type of PR is this?
/kind improvement
/area core
/milestone 2.20.x

#### What this PR does / why we need it:
当生成缩略图时如果原图尺寸小于请求尺寸则返回原图以保持其质量

#### Which issue(s) this PR fixes:
Fixes #6579

#### Does this PR introduce a user-facing change?
```release-note
当生成缩略图时如果原图尺寸小于请求尺寸则返回原图以保持其质量
```
2024-09-04 06:07:43 +00:00
John Niang 19de4db273
Fix the problem that Lucene lock is held by VM (#6570)
#### What type of PR is this?

/kind bug
/area core
/milestone 2.20.x

#### What this PR does / why we need it:

This PR add keyword synchronized for methods `addOrUpdateDocuments`, `deleteDocuments` and `deleteAll` to ensure the write lock of Lucene is obtained only by one IndexWriter at the same time.

#### Which issue(s) this PR fixes:

Fixes #6569 

#### Does this PR introduce a user-facing change?

```release-note
修复重启后无法搜索部分文档的问题
```
2024-09-03 05:11:39 +00:00
Ryan Wang 710777a10a
refactor: change scalingMethod parameter to automatic for thumbnail generation (#6563)
#### What type of PR is this?

/area core
/kind improvement
/milestone 2.19.0

#### What this PR does / why we need it:

将缩略图生成的模式改为自动,速度优先会导致图片失真率较高,部分图片在 w1600 的尺寸下看起来会比较模糊。

#### Does this PR introduce a user-facing change?

```release-note
None
```
2024-09-01 14:49:34 +00:00
guqing 9a0ebdad25
refactor: redirect to original image if thumbnail is inaccessible (#6556)
#### What type of PR is this?
/kind improvement
/area core
/milestone 2.19.x

#### What this PR does / why we need it:
获取缩略图时检查缩略图链接是否可访问否则重定向到原图链接

#### Does this PR introduce a user-facing change?
```release-note
获取缩略图时检查缩略图链接是否可访问否则重定向到原图链接
```
2024-08-30 09:45:29 +00:00
John Niang e476ddac71
Make slug of single page be not unique (#6545)
#### What type of PR is this?

/kind cleanup
/area core
/milestone 2.19.0

#### What this PR does / why we need it:

For backward compatibility, the slug of single page should not be unique.

BTW, the problem was introduced by <https://github.com/halo-dev/halo/pull/6540>.

#### Does this PR introduce a user-facing change?

```release-note
None
```
2024-08-29 04:17:25 +00:00
guqing ad267ebed7
refactor: optimize comment and reply logic to reduce duplicate code (#6542)
#### What type of PR is this?
/kind improvement
/area core
/milestone 2.19.x

#### What this PR does / why we need it:
优化评论和回复的逻辑并减少重复代码

#### Does this PR introduce a user-facing change?
```release-note
None
```
2024-08-29 04:07:25 +00:00
guqing 0a13981c0d
fix: post list sorting parameter not working (#6544)
#### What type of PR is this?
/kind bug
/area core
/milestone 2.19.x

#### What this PR does / why we need it:
修复 postFinder 的 list 排序参数不生效的问题

此问题由于 https://github.com/halo-dev/halo/pull/6531 导致

#### Which issue(s) this PR fixes:
Fixes #6534

#### Does this PR introduce a user-facing change?
```release-note
None
```
2024-08-29 03:25:24 +00:00
John Niang 157b7ad281
Fix the problem of LockObtainFailedException while performing a rolling update (#6543)
#### What type of PR is this?

/kind bug
/area core
/milestone 2.19.0

#### What this PR does / why we need it:

This PR refactors LuceneSearchEngine to let IndexWriter and SearcherManager load lazily to prevent LockObtainFailedException from performing a rolling update.

#### Which issue(s) this PR fixes:

Fixes #6541 

#### Special notes for your reviewer:

1. Use MySQL or PostgreSQL as database for Halo
2. Start an instance of Halo
3. Try to initialize Halo and search posts
4. Change the `server.port` and start another instance of Halo
5. Check the status of another instance

#### Does this PR introduce a user-facing change?

```release-note
修复滚动更新时无法启动新的 Halo 实例的问题
```
2024-08-29 03:05:24 +00:00
John Niang f61f846a7f
Cleanup code with SortableRequest (#6540)
#### What type of PR is this?

/kind cleanup
/kind improvement
/area core
/milestone 2.19.0

#### What this PR does / why we need it:

This PR refactors some requests with sort parameter by reusing SortableRequest, and refactors some queries with indexer.

#### Does this PR introduce a user-facing change?

```release-note
None
```
2024-08-29 02:39:24 +00:00
guqing a5c6d6672f
chore: rename thumbnail parameter from width to size for clarity (#6533)
#### What type of PR is this?
/kind improvement
/area core
/milestone 2.19.x

#### What this PR does / why we need it:
重命名缩略图大小的参数名以便和主题端 finder 用法保持一致
同时确保通过 encode 或者没有 encode 的 uri 都可以获取到缩略图

#### Does this PR introduce a user-facing change?
```release-note
None
```
2024-08-27 10:19:19 +00:00
guqing ac0700e668
feat: add unified parameter list method for post finder (#6531)
#### What type of PR is this?
/kind feature
/milestone 2.19.x
/area core

#### What this PR does / why we need it:
为 postFinder 添加一个统一参数的 list 方法并支持传递排序参数

Fixes https://github.com/halo-dev/halo/issues/4933

#### Does this PR introduce a user-facing change?
```release-note
为 postFinder 添加一个统一参数的 list 方法并支持传递排序参数
```
2024-08-27 10:17:18 +00:00
John Niang 97257f9577
Fix the problem that return empty result while listing users (#6532)
#### What type of PR is this?

/kind bug
/area core
/milestone 2.19.0

#### What this PR does / why we need it:

This PR makes the return value of method `DefaultRoleService#getRolesByUsernames` never be `Mono#empty`.

See https://github.com/halo-dev/halo/issues/6528 for more.

#### Which issue(s) this PR fixes:

Fixes https://github.com/halo-dev/halo/issues/6528 

#### Special notes for your reviewer:

1. Try to execute command `http -a admin:admin http://127.0.0.1:8090/apis/api.console.halo.run/v1alpha1/users?keyword=xyz`.
2. See the output

#### Does this PR introduce a user-facing change?

```release-note
修复获取用户列表时可能返回空结果的问题
```
2024-08-27 09:23:18 +00:00
John Niang b6222f48a4
Fix the incorrect list options builder while listing aggregated roles (#6530)
#### What type of PR is this?

/kind bug
/area core
/milestone 2.19.0

#### What this PR does / why we need it:

This PR corrects list options builder for listing aggregated roles, because I wrongly used the label selector in <https://github.com/halo-dev/halo/pull/6471>.

#### Special notes for your reviewer:

1. Try to install the plugin <https://www.halo.run/store/apps/app-YXyaD>
2. Enable the plugin and enable setting `匿名评论需要验证码`
3. **Anonymous** request any of posts with comment enabled
4. Check the captcha in comment area

#### Does this PR introduce a user-facing change?

```release-note
修复可能无法正常访问插件提供的接口的问题
```
2024-08-27 07:09:18 +00:00
guqing ef37aa794b
feat: implement new mechanisms for generating and managing attachment thumbnails (#6454)
#### What type of PR is this?
/kind feature
/area core
/milestone 2.19.x

#### What this PR does / why we need it:
实现了图片类型的附件缩略图生成和管理的新机制

实现依据 RFC:https://github.com/halo-dev/rfcs/pull/24

使用缩略图前需要配置 externalUrl 才能生成

**How to test it?**
1. 测试本地缩略图的文件是否正确,每个图片对应到相应 size 的目录如 thumbnails/w400 应该是一对一
2. 每个图片生成缩略图的只会在 `http://localhost:8090/apis/storage.halo.run/v1alpha1/thumbnails` 中存在一份记录
3. 测试删除附件会删除对应的缩略图文件和 [thumbnails](http://localhost:8090/apis/storage.halo.run/v1alpha1/thumbnails) 
记录
4. 修改 externalUrl 以上功能均不会受到影响

#### Which issue(s) this PR fixes:
Fixes #2387 

#### Does this PR introduce a user-facing change?
```release-note
附件图片支持生成多尺寸图片,文章支持响应式图片。
```
2024-08-26 10:27:14 +00:00
guqing 8405a6376e
refactor: add post-index build validation to ensure data count matches index (#6507)
#### What type of PR is this?
/kind improvement
/area core
/milestone 2.19.x

#### What this PR does / why we need it:
构建完索引后增加数据量一致性校验的步骤

#### Does this PR introduce a user-facing change?
```release-note
None
```
2024-08-26 09:05:14 +00:00
Ryan Wang 3db80bfaf3
chore: bump preset plugins version (#6517)
#### What type of PR is this?

/kind improvement
/area core
/milestone 2.19.0

#### What this PR does / why we need it:

升级预设插件的版本。

#### Does this PR introduce a user-facing change?

```release-note
None
```
2024-08-26 08:21:13 +00:00
Ryan Wang d77c258951
chore: update default theme version to 1.9.0 (#6516)
#### What type of PR is this?

/area core
/kind feature
/milestone 2.19.x

#### What this PR does / why we need it:

升级默认主题的版本为 [1.9.0](https://github.com/halo-dev/theme-earth/releases/tag/v1.9.0)。

#### Does this PR introduce a user-facing change?

```release-note
None
```
2024-08-26 08:11:13 +00:00
Ryan Wang 72e7b19697
chore: update Halo official website URL (#6514)
Co-authored-by: John Niang <johnniang@foxmail.com>
2024-08-26 15:53:04 +08:00
John Niang d68dca931b
Fix "Missing exception attribute in ServerWebExchange" error after upgrading Spring Boot 3.3.3 (#6515)
#### What type of PR is this?

/kind bug
/area core
/milestone 2.19.0

#### What this PR does / why we need it:

After merging https://github.com/halo-dev/halo/pull/6512 and https://github.com/halo-dev/halo/pull/6511, unit tests fail due to the changes of <05b73ceeec>.

This PR fixes the problem by letting `run.halo.app.infra.exception.handlers.ProblemDetailErrorAttributes` extend  `org.springframework.boot.web.reactive.error.DefaultErrorAttributes`.

#### Does this PR introduce a user-facing change?

```release-note
None
```
2024-08-26 07:49:13 +00:00
Takagi e5bbbb3b7b
feat: API to save external links as attachments (#6364)
#### What type of PR is this?

/kind api-change
/kind feature
/area core

#### What this PR does / why we need it:

see #2335 

增加将第三方资源转存为附件资源的接口。

`/apis/api.console.halo.run/v1alpha1/attachments/-/upload-from-url`

UC:

`/apis/uc.api.content.halo.run/v1alpha1/attachments/-/upload-from-url`

其中参数为

```json
{
  "url": "string",
  "filename": "string",
  "groupName": "string",
  "policyName": "string"
}
```

#### How to test it?

测试能否将第三方接口的资源保存至附件中。
测试各类附件,例如图片、视频、文本等。

#### Does this PR introduce a user-facing change?
```release-note
增加通过链接转存第三方资源至附件库的接口
```
2024-08-26 06:31:14 +00:00
John Niang 50adc29e42
Respond not found if no theme template found (#6511)
#### What type of PR is this?

/kind improvement
/area core
/milestone 2.19.0

#### What this PR does / why we need it:

This PR refactors "Template Not Found Exception" into "NotFoundException" to prevent too many exception stacktraces in logs file.

#### Which issue(s) this PR fixes:

Fixes #6501 

#### Special notes for your reviewer:

1. Activate default theme
2. Request <http://localhost:8090/categories>
3. See the result

#### Does this PR introduce a user-facing change?

```release-note
优化当主题模板找不到的异常提示
```
2024-08-26 02:47:12 +00:00
guqing 87368df18a
fix: correct device information update during account switch (#6483)
#### What type of PR is this?
/kind bug
/area core
/milestone 2.19.x

#### What this PR does / why we need it:
修复切换账号登录时设备信息更新不正确的问题

原因:
1. 使用 admin 账号登录,此时会记录 device_id 的 cookie
2. 退出登录,device_id 会保留在 cookie 中并随着新账号带到服务端
3. 服务端根据 device_id 查询当前设备是否有对应的记录,但是没有校验用户名是否与当前登陆的一致然后就去更新登录时间
4. 正确的处理是校验 device_id 是否有与之对应的记录并且用户名相同,如果不相同则认为是新设备重新生成 device_id

**how to test it?**
1. 先清理 cookie 然后使用一个账号登录
2. 退出登陆并切换新账号登录
3. 检查新登录的账号的设备信息是否正确

#### Does this PR introduce a user-facing change?
```release-note
修复切换账号登录时设备信息更新不正确的问题
```
2024-08-22 09:02:56 +00:00
guqing f9615d072d
chore: remove transactional annotation (#6492)
#### What type of PR is this?
/kind cleanup
/area core
/milestone 2.19.x

#### What this PR does / why we need it:
移除事务注解避免对索引创建产生影响,原因参考改动中的方法注释

**其中一点特别注意:**
在执行 `client.create(name, data)` 方法后,会尝试进行 `indexer.indexRecord` 操作。但 indexRecord 可能会因唯一索引中存在重复键而导致 indexRecord 失败,索引创建也会随之失败。为确保索引与数据的一致性,此时应回滚由 `client.create(name, data)` 对数据产生的影响,因此除非找到更佳的一致性问题解决方案,否则暂时不能移除此处的手动事务操作。

```java
 return client.create(name, version, data)
                .map(updated -> converter.convertFrom(type, updated))
                .doOnNext(extension -> indexer.indexRecord(convertToRealExtension(extension)))
                .as(transactionalOperator::transactional);
```
将变更传递给 extension watcher 是在 `doCreate` 或 `doUpdate` 成功之后才会被处理,因此这里的事务回滚不会对 watcher 造成影响

#### Does this PR introduce a user-facing change?
```release-note
None
```
2024-08-22 08:26:55 +00:00
guqing d8ec34b724
fix: previous and next post links included hidden posts (#6491)
#### What type of PR is this?
/kind bug
/area core
/milestone 2.19.x

#### What this PR does / why we need it:
修复文章的上一篇下一篇链接包含了隐藏分类下的文章

#### Does this PR introduce a user-facing change?
```release-note
修复文章的上一篇下一篇链接包含了隐藏分类下的文章
```
2024-08-22 08:24:55 +00:00
JohnNiang 3460d4c94b Add support for restoring from backup root
Signed-off-by: JohnNiang <johnniang@foxmail.com>
2024-08-21 11:45:49 +08:00
John Niang 3a782be607
Fix the problem that roles could not be granted sometimes (#6471)
#### What type of PR is this?

/kind improvement
/area core

#### What this PR does / why we need it:

This PR refactors searching roles by using index mechanism to speed up every request and fix the problem of not being able to grant roles to users sometimes.

#### Which issue(s) this PR fixes:

Fixes #5807 
Fixes https://github.com/halo-dev/halo/issues/4954
Fixes https://github.com/halo-dev/halo/issues/5057

#### Does this PR introduce a user-facing change?

```release-note
修复有时无法给用户赋权限的问题
```
2024-08-21 03:22:50 +00:00
guqing 7ba5fc671f
chore: cleanup unused index for notification (#6481)
#### What type of PR is this?
/kind cleanup
/area core
/milestone 2.19.x

#### What this PR does / why we need it:
清理没有用到的索引

#### Does this PR introduce a user-facing change?
```release-note
None
```
2024-08-20 06:52:47 +00:00
guqing 30d482f0f8
refactor: optimize user creation (#6480)
#### What type of PR is this?
/kind improvement
/area core
/milestone 2.19.x

#### What this PR does / why we need it:
优化用户创建

#### Does this PR introduce a user-facing change?
```release-note
None
```
2024-08-19 07:38:42 +00:00
guqing 88b5e190a6 refactor: rename and restructure enabled plugins in bundle.js 2024-08-15 17:29:31 +08:00
John Niang 40386557a7
Support filtering search result by types, ownerNames, categoryNames and tagNames (#6442)
#### What type of PR is this?

/kind improvement
/area core

#### What this PR does / why we need it:

This PR allows users to filter search result by types, owner names, category names and tag names.

#### Does this PR introduce a user-facing change?

```release-note
完善搜索引擎过滤功能
```
2024-08-08 04:58:37 +00:00
guqing 3822cbee15
chore: remove incorrect index declaration (#6427)
#### What type of PR is this?
/milestone 2.19.x
/area core
/kind cleanup

#### What this PR does / why we need it:
删除对文章错误的索引声明

#### Does this PR introduce a user-facing change?
```release-note
None
```
2024-08-01 08:14:10 +00:00
guqing 58fe872844
feat: add file size and type restriction for local file uploads (#6390)
#### What type of PR is this?
/kind feature
/area core

#### What this PR does / why we need it:
本次 PR 为本地附件存储策略增加了对上传单文件大小和文件类型限制的功能,具体包括:

1. 单文件大小限制:
实现了对单个文件上传大小的验证功能,确保上传文件不超过设定的最大值。
2. 文件类型限制:
添加了文件类型限制功能,使用 Apache Tika 读取上传文件的 magic numbers 得到文件 mime type 并根据用户配置来决定是否允许上传

参考链接:
- [List of file signatures](https://en.wikipedia.org/wiki/List_of_file_signatures)
- [File Magic Numbers: The Easy way to Identify File Extensions](https://library.mosse-institute.com/articles/2022/04/file-magic-numbers-the-easy-way-to-identify-file-extensions/file-magic-numbers-the-easy-way-to-identify-file-extensions.html)

#### Which issue(s) this PR fixes:
Fixes #6385

#### Does this PR introduce a user-facing change?
```release-note
为本地附件存储策略增加了对上传单文件大小和文件类型限制的功能
```
2024-08-01 01:58:12 +00:00