Skip to content

Commit

Permalink
refactor: setting options definition for thumbnail param pattern
Browse files Browse the repository at this point in the history
  • Loading branch information
guqing committed Sep 11, 2024
1 parent 36d9267 commit df11ff2
Show file tree
Hide file tree
Showing 5 changed files with 34 additions and 127 deletions.
2 changes: 1 addition & 1 deletion build.gradle
Original file line number Diff line number Diff line change
Expand Up @@ -40,7 +40,7 @@ configurations.runtimeClasspath {


halo {
version = '2.17.0'
version = '2.19'
}

haloPlugin {
Expand Down
74 changes: 0 additions & 74 deletions src/main/java/run/halo/s3os/AttachmentThumbnailReconciler.java

This file was deleted.

8 changes: 1 addition & 7 deletions src/main/java/run/halo/s3os/S3OsProperties.java
Original file line number Diff line number Diff line change
Expand Up @@ -50,13 +50,7 @@ public class S3OsProperties {

private List<urlSuffixItem> urlSuffixes;

private ThumbnailParam thumbnailParam;

public record ThumbnailParam(String type, String pattern) {
public boolean hasPattern() {
return StringUtils.hasText(type) && StringUtils.hasText(pattern);
}
}
private String thumbnailParamPattern;

@Data
@AllArgsConstructor
Expand Down
12 changes: 7 additions & 5 deletions src/main/java/run/halo/s3os/S3ThumbnailProvider.java
Original file line number Diff line number Diff line change
Expand Up @@ -43,8 +43,10 @@ public Mono<URI> generate(ThumbnailContext thumbnailContext) {
.mapNotNull(cacheValue -> placedPattern(cacheValue.pattern(), size))
.map(param -> {
if (param.startsWith("?")) {
UriComponentsBuilder.fromHttpUrl(url)
.queryParam(param.substring(1));
return UriComponentsBuilder.fromHttpUrl(url)
.queryParam(param.substring(1))
.build()
.toString();
}
return url + param;
})
Expand Down Expand Up @@ -91,13 +93,13 @@ private Flux<Map.Entry<String, S3PropsCacheValue>> listAllS3ObjectDomain() {
var s3ConfigMapName = s3Policy.getSpec().getConfigMapName();
return fetchS3PropsByConfigMapName(s3ConfigMapName)
.mapNotNull(properties -> {
var thumbnailParam = properties.getThumbnailParam();
if (thumbnailParam == null || !thumbnailParam.hasPattern()) {
var thumbnailParam = properties.getThumbnailParamPattern();
if (StringUtils.isBlank(thumbnailParam)) {
return null;
}
var objectDomain = properties.toObjectURL("");
var cacheValue = S3PropsCacheValue.builder()
.pattern(thumbnailParam.pattern())
.pattern(thumbnailParam)
.configMapName(s3ConfigMapName)
.build();
return Map.entry(objectDomain, cacheValue);
Expand Down
65 changes: 25 additions & 40 deletions src/main/resources/extensions/policy-template-s3os.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -145,44 +145,29 @@ spec:
label: 网址后缀
placeholder: 例如:?imageMogr2/format/webp
validation: required
- $formkit: group
- $formkit: select
name: thumbnailParamPattern
label: 缩略图参数
name: thumbnailParam
children:
- $formkit: select
name: type
key: type
label: 类型
options:
- label:
value: ""
- label: 预设参数
value: preset
- label: 自定义参数
value: custom
- $formkit: select
if: "$value.type == preset"
name: pattern
key: type
label: 使用预设参数
help: 请根据您的对象存储服务商选择对应的缩略图参数
options:
- label: 腾讯云 COS
value: "?imageView2/0/w/{width}"
- label: 七牛云 KODO
value: "?imageView2/0/w/{width}"
- label: 阿里云 OSS
value: "?x-oss-process=image/resize,w_{width},m_lfit"
- label: 百度云 BOS
value: "?x-bce-process=image/resize,m_lfit,w_{width}"
- label: 青云 OSS
value: "?image&action=resize:w_{width},m_2"
- label: 京东云
value: "?x-oss-process=img/sw/{width}"
- label: 又拍云
value: "!/fw/{width}"
- $formkit: text
if: "$value.type == custom"
label: 自定义参数
help: "{width} 为宽度占位符将被替换为所需缩略图宽度值,如: 400,参数需要以 ? 开头,间隔符除外"
name: pattern
allowCreate: true
searchable: true
value: ""
help: |
请根据您的对象存储服务商选择对应的缩略图参数或自定义参数,{width} 为宽度占位符将被替换为所需缩略图宽度值,
如: 400,参数需要以 ? 开头,间隔符除外
options:
- label:
value: ""
- label: 腾讯云 COS
value: "?imageView2/0/w/{width}"
- label: 七牛云 KODO
value: "?imageView2/0/w/{width}"
- label: 阿里云 OSS
value: "?x-oss-process=image/resize,w_{width},m_lfit"
- label: 百度云 BOS
value: "?x-bce-process=image/resize,m_lfit,w_{width}"
- label: 青云 OSS
value: "?image&action=resize:w_{width},m_2"
- label: 京东云
value: "?x-oss-process=img/sw/{width}"
- label: 又拍云
value: "!/fw/{width}"

0 comments on commit df11ff2

Please sign in to comment.