8 Commits

Author SHA1 Message Date
John Niang
a2120c3a42 Fix the problem of stopping local attachment deletion 2025-07-04 12:00:08 +08:00
John Niang
42e27da86b Ignore non-existing object when deleting (#193) 2025-06-11 00:24:19 +08:00
John Niang
19469d0537 Upgrade Halo Gradle plugin to 0.6.0 (#192) 2025-06-11 00:20:41 +08:00
John Niang
545b7ac4ea Merge pull request #191 from halo-dev/chore/upgrade-infra
Update Gradle, dependencies, and workflow
2025-06-06 23:58:11 +08:00
John Niang
26038491f2 Update Gradle, dependencies, and workflow 2025-06-06 17:59:31 +08:00
Ryan Wang
538c5f3ef9 Refactor data list using VEntityContainer (#190)
Refactor data list using ⁠VEntityContainer to optimize display across devices of various sizes.

See https://github.com/halo-dev/halo/pull/7383

Note: Updating to this version requires Halo >= 2.21.0.

```release-note
适配 Halo 2.21.0 的数据列表样式
```
2025-05-29 07:28:26 +00:00
guqing
a7919266d5 chore: update requires to 2.20.0 (#171)
### What this PR does?
将 requires 改动到 2.20.0
目前 Halo 2.20.0 已经发布,此 https://github.com/halo-dev/plugin-s3/pull/167 功能需要在 2.20.0 才能完整工作,因此升级到此版本后准备发版

```release-note
None
```
2024-10-14 04:47:16 +00:00
guqing
68b0bee948 feat: ability to configure and use image thumbnails (#167)
### What this PR does?
适配 Halo 2.19(WIP) 的缩略图机制支持 S3 配置并使用缩略图

缩略图规则参考:
- [腾讯云 OSS 图片缩放](https://cloud.tencent.com/document/product/1246/109210)
- [百度 OSS 图片缩放](https://cloud.baidu.com/doc/BOS/s/gkbisf3l4)
- [阿里云 OSS 图片缩放](https://help.aliyun.com/zh/oss/user-guide/resize-images-4)
- [七牛云 OSS 图片缩放](https://developer.qiniu.com/dora/api/basic-processing-images-imageview2)
- [青云 OSS 图片缩放](https://docsv3.qingcloud.com/storage/object-storage/api/object/image_process/resize/)
- [京东云 OSS](https://docs.jdcloud.com/cn/object-storage-service/resize-images)
- [又拍云图片缩放](https://docs.upyun.com/cloud/image/#_11)


```release-note
支持配置并使用图片缩略图机制
```
2024-09-26 07:37:29 +00:00
18 changed files with 413 additions and 230 deletions

View File

@@ -7,11 +7,13 @@ on:
jobs: jobs:
cd: cd:
uses: halo-sigs/reusable-workflows/.github/workflows/plugin-cd.yaml@v1 uses: halo-sigs/reusable-workflows/.github/workflows/plugin-cd.yaml@v3
secrets: secrets:
halo-username: ${{ secrets.HALO_USERNAME }} halo-pat: ${{ secrets.HALO_PAT }}
halo-password: ${{ secrets.HALO_PASSWORD }}
permissions: permissions:
contents: write contents: write
with: with:
app-id: app-Qxhpp app-id: app-Qxhpp
pnpm-version: 9
node-version: 22
java-version: 21

View File

@@ -10,4 +10,8 @@ on:
jobs: jobs:
ci: ci:
uses: halo-sigs/reusable-workflows/.github/workflows/plugin-ci.yaml@v1 uses: halo-sigs/reusable-workflows/.github/workflows/plugin-ci.yaml@v3
with:
pnpm-version: 9
node-version: 22
java-version: 21

View File

@@ -1,30 +1,35 @@
plugins { plugins {
id 'java' id 'java'
id "com.github.node-gradle.node" version "5.0.0" id "com.github.node-gradle.node" version "7.1.0"
id "io.freefair.lombok" version "8.0.1" id "io.freefair.lombok" version "8.13.1"
id "run.halo.plugin.devtools" version "0.0.9" id "run.halo.plugin.devtools" version "0.6.0"
id 'org.openapi.generator' version '7.7.0' id 'org.openapi.generator' version '7.12.0'
} }
group 'run.halo.s3os' group 'run.halo.s3os'
tasks.withType(JavaCompile).configureEach {
options.encoding = 'UTF-8'
options.release = 21
}
java { java {
sourceCompatibility = JavaVersion.VERSION_17 toolchain {
languageVersion = JavaLanguageVersion.of(21)
}
} }
repositories { repositories {
mavenCentral() mavenCentral()
maven { url 'https://s01.oss.sonatype.org/content/repositories/releases' }
maven { url 'https://s01.oss.sonatype.org/content/repositories/snapshots/' }
maven { url 'https://repo.spring.io/milestone' } maven { url 'https://repo.spring.io/milestone' }
} }
dependencies { dependencies {
implementation platform('run.halo.tools.platform:plugin:2.17.0-SNAPSHOT') implementation platform('run.halo.tools.platform:plugin:2.21.0-alpha.1')
compileOnly 'run.halo.app:api' compileOnly 'run.halo.app:api'
implementation platform('software.amazon.awssdk:bom:2.19.8') implementation platform('software.amazon.awssdk:bom:2.31.58')
implementation ('software.amazon.awssdk:s3') { implementation('software.amazon.awssdk:s3') {
exclude group: 'org.slf4j' exclude group: 'org.slf4j'
exclude group: 'commons-logging' exclude group: 'commons-logging'
} }
@@ -32,6 +37,7 @@ dependencies {
testImplementation 'run.halo.app:api' testImplementation 'run.halo.app:api'
testImplementation 'org.springframework.boot:spring-boot-starter-test' testImplementation 'org.springframework.boot:spring-boot-starter-test'
testImplementation 'io.projectreactor:reactor-test' testImplementation 'io.projectreactor:reactor-test'
testRuntimeOnly 'org.junit.platform:junit-platform-launcher'
} }
configurations.runtimeClasspath { configurations.runtimeClasspath {
@@ -40,7 +46,7 @@ configurations.runtimeClasspath {
halo { halo {
version = '2.17.0' version = '2.21.0-alpha.2'
} }
haloPlugin { haloPlugin {
@@ -59,21 +65,16 @@ node {
nodeProjectDir = file("${project.projectDir}/console") nodeProjectDir = file("${project.projectDir}/console")
} }
task buildFrontend(type: PnpmTask) { tasks.register('buildFrontend', PnpmTask) {
args = ['build'] args = ['build']
dependsOn(tasks.named('pnpmInstall'))
} }
tasks.named('buildFrontend') { tasks.named('processResources') {
dependsOn 'pnpmInstall' dependsOn(tasks.named('buildFrontend'))
} }
build { tasks.register('downloadOpenApiSpec') {
// build frontend before build
tasks.getByName('compileJava').dependsOn('buildFrontend')
}
task downloadOpenApiSpec {
doLast { doLast {
def url = 'http://localhost:8090/v3/api-docs/plugin-s3' def url = 'http://localhost:8090/v3/api-docs/plugin-s3'
def file = layout.buildDirectory.dir("apidocs/openapi.json").get().asFile def file = layout.buildDirectory.dir("apidocs/openapi.json").get().asFile
@@ -87,11 +88,11 @@ openApiGenerate {
inputSpec = layout.buildDirectory.dir("apidocs/openapi.json").get().asFile.getAbsolutePath() inputSpec = layout.buildDirectory.dir("apidocs/openapi.json").get().asFile.getAbsolutePath()
outputDir = "${projectDir}/console/src/api" outputDir = "${projectDir}/console/src/api"
additionalProperties = [ additionalProperties = [
useES6: true, useES6 : true,
useSingleRequestParameter: true, useSingleRequestParameter: true,
withSeparateModelsAndApi: true, withSeparateModelsAndApi : true,
apiPackage: "api", apiPackage : "api",
modelPackage: "models" modelPackage : "models"
] ]
typeMappings = [ typeMappings = [
set: "Array" set: "Array"

View File

@@ -12,7 +12,7 @@
}, },
"dependencies": { "dependencies": {
"@halo-dev/api-client": "^2.17.0", "@halo-dev/api-client": "^2.17.0",
"@halo-dev/components": "^2.17.0", "@halo-dev/components": "https://pkg.pr.new/@halo-dev/components@7383",
"@halo-dev/console-shared": "^2.17.0", "@halo-dev/console-shared": "^2.17.0",
"@tanstack/vue-query": "4.29.1", "@tanstack/vue-query": "4.29.1",
"axios": "^1.7.2", "axios": "^1.7.2",
@@ -46,5 +46,6 @@
"vitest": "^0.34.1", "vitest": "^0.34.1",
"vue-router": "^4.4.0", "vue-router": "^4.4.0",
"vue-tsc": "^1.8.27" "vue-tsc": "^1.8.27"
} },
"packageManager": "pnpm@9.15.0+sha512.76e2379760a4328ec4415815bcd6628dee727af3779aaa4c914e3944156c4299921a89f976381ee107d41f12cfa4b66681ca9c718f0668fa0831ed4c6d8ba56c"
} }

22
console/pnpm-lock.yaml generated
View File

@@ -12,8 +12,8 @@ importers:
specifier: ^2.17.0 specifier: ^2.17.0
version: 2.17.0(axios@1.7.2) version: 2.17.0(axios@1.7.2)
'@halo-dev/components': '@halo-dev/components':
specifier: ^2.17.0 specifier: https://pkg.pr.new/@halo-dev/components@7383
version: 2.17.0(vue-router@4.4.0(vue@3.4.31(typescript@5.3.3)))(vue@3.4.31(typescript@5.3.3)) version: https://pkg.pr.new/@halo-dev/components@7383(vue-router@4.4.0(vue@3.4.31(typescript@5.3.3)))(vue@3.4.31(typescript@5.3.3))
'@halo-dev/console-shared': '@halo-dev/console-shared':
specifier: ^2.17.0 specifier: ^2.17.0
version: 2.17.0(axios@1.7.2)(vue-router@4.4.0(vue@3.4.31(typescript@5.3.3)))(vue@3.4.31(typescript@5.3.3)) version: 2.17.0(axios@1.7.2)(vue-router@4.4.0(vue@3.4.31(typescript@5.3.3)))(vue@3.4.31(typescript@5.3.3))
@@ -449,10 +449,11 @@ packages:
peerDependencies: peerDependencies:
axios: ^1.7.x axios: ^1.7.x
'@halo-dev/components@2.17.0': '@halo-dev/components@https://pkg.pr.new/@halo-dev/components@7383':
resolution: {integrity: sha512-yujCVNfpZA1HjpilxD1Dzkh5Ge54u9hcIyuGj7Mr8hNHAY1xgiVo0uvuYwm8ik5/njI9HED4GXR2JIreSu/PeA==} resolution: {tarball: https://pkg.pr.new/@halo-dev/components@7383}
version: 2.21.0
peerDependencies: peerDependencies:
vue: ^3.4.27 vue: ^3.5.13
vue-router: ^4.3.2 vue-router: ^4.3.2
'@halo-dev/console-shared@2.17.0': '@halo-dev/console-shared@2.17.0':
@@ -573,55 +574,46 @@ packages:
resolution: {integrity: sha512-C/zbRYRXFjWvz9Z4haRxcTdnkPt1BtCkz+7RtBSuNmKzMzp3ZxdM28Mpccn6pt28/UWUCTXa+b0Mx1k3g6NOMA==} resolution: {integrity: sha512-C/zbRYRXFjWvz9Z4haRxcTdnkPt1BtCkz+7RtBSuNmKzMzp3ZxdM28Mpccn6pt28/UWUCTXa+b0Mx1k3g6NOMA==}
cpu: [arm] cpu: [arm]
os: [linux] os: [linux]
libc: [glibc]
'@rollup/rollup-linux-arm-musleabihf@4.18.0': '@rollup/rollup-linux-arm-musleabihf@4.18.0':
resolution: {integrity: sha512-l3m9ewPgjQSXrUMHg93vt0hYCGnrMOcUpTz6FLtbwljo2HluS4zTXFy2571YQbisTnfTKPZ01u/ukJdQTLGh9A==} resolution: {integrity: sha512-l3m9ewPgjQSXrUMHg93vt0hYCGnrMOcUpTz6FLtbwljo2HluS4zTXFy2571YQbisTnfTKPZ01u/ukJdQTLGh9A==}
cpu: [arm] cpu: [arm]
os: [linux] os: [linux]
libc: [musl]
'@rollup/rollup-linux-arm64-gnu@4.18.0': '@rollup/rollup-linux-arm64-gnu@4.18.0':
resolution: {integrity: sha512-rJ5D47d8WD7J+7STKdCUAgmQk49xuFrRi9pZkWoRD1UeSMakbcepWXPF8ycChBoAqs1pb2wzvbY6Q33WmN2ftw==} resolution: {integrity: sha512-rJ5D47d8WD7J+7STKdCUAgmQk49xuFrRi9pZkWoRD1UeSMakbcepWXPF8ycChBoAqs1pb2wzvbY6Q33WmN2ftw==}
cpu: [arm64] cpu: [arm64]
os: [linux] os: [linux]
libc: [glibc]
'@rollup/rollup-linux-arm64-musl@4.18.0': '@rollup/rollup-linux-arm64-musl@4.18.0':
resolution: {integrity: sha512-be6Yx37b24ZwxQ+wOQXXLZqpq4jTckJhtGlWGZs68TgdKXJgw54lUUoFYrg6Zs/kjzAQwEwYbp8JxZVzZLRepQ==} resolution: {integrity: sha512-be6Yx37b24ZwxQ+wOQXXLZqpq4jTckJhtGlWGZs68TgdKXJgw54lUUoFYrg6Zs/kjzAQwEwYbp8JxZVzZLRepQ==}
cpu: [arm64] cpu: [arm64]
os: [linux] os: [linux]
libc: [musl]
'@rollup/rollup-linux-powerpc64le-gnu@4.18.0': '@rollup/rollup-linux-powerpc64le-gnu@4.18.0':
resolution: {integrity: sha512-hNVMQK+qrA9Todu9+wqrXOHxFiD5YmdEi3paj6vP02Kx1hjd2LLYR2eaN7DsEshg09+9uzWi2W18MJDlG0cxJA==} resolution: {integrity: sha512-hNVMQK+qrA9Todu9+wqrXOHxFiD5YmdEi3paj6vP02Kx1hjd2LLYR2eaN7DsEshg09+9uzWi2W18MJDlG0cxJA==}
cpu: [ppc64] cpu: [ppc64]
os: [linux] os: [linux]
libc: [glibc]
'@rollup/rollup-linux-riscv64-gnu@4.18.0': '@rollup/rollup-linux-riscv64-gnu@4.18.0':
resolution: {integrity: sha512-ROCM7i+m1NfdrsmvwSzoxp9HFtmKGHEqu5NNDiZWQtXLA8S5HBCkVvKAxJ8U+CVctHwV2Gb5VUaK7UAkzhDjlg==} resolution: {integrity: sha512-ROCM7i+m1NfdrsmvwSzoxp9HFtmKGHEqu5NNDiZWQtXLA8S5HBCkVvKAxJ8U+CVctHwV2Gb5VUaK7UAkzhDjlg==}
cpu: [riscv64] cpu: [riscv64]
os: [linux] os: [linux]
libc: [glibc]
'@rollup/rollup-linux-s390x-gnu@4.18.0': '@rollup/rollup-linux-s390x-gnu@4.18.0':
resolution: {integrity: sha512-0UyyRHyDN42QL+NbqevXIIUnKA47A+45WyasO+y2bGJ1mhQrfrtXUpTxCOrfxCR4esV3/RLYyucGVPiUsO8xjg==} resolution: {integrity: sha512-0UyyRHyDN42QL+NbqevXIIUnKA47A+45WyasO+y2bGJ1mhQrfrtXUpTxCOrfxCR4esV3/RLYyucGVPiUsO8xjg==}
cpu: [s390x] cpu: [s390x]
os: [linux] os: [linux]
libc: [glibc]
'@rollup/rollup-linux-x64-gnu@4.18.0': '@rollup/rollup-linux-x64-gnu@4.18.0':
resolution: {integrity: sha512-xuglR2rBVHA5UsI8h8UbX4VJ470PtGCf5Vpswh7p2ukaqBGFTnsfzxUBetoWBWymHMxbIG0Cmx7Y9qDZzr648w==} resolution: {integrity: sha512-xuglR2rBVHA5UsI8h8UbX4VJ470PtGCf5Vpswh7p2ukaqBGFTnsfzxUBetoWBWymHMxbIG0Cmx7Y9qDZzr648w==}
cpu: [x64] cpu: [x64]
os: [linux] os: [linux]
libc: [glibc]
'@rollup/rollup-linux-x64-musl@4.18.0': '@rollup/rollup-linux-x64-musl@4.18.0':
resolution: {integrity: sha512-LKaqQL9osY/ir2geuLVvRRs+utWUNilzdE90TpyoX0eNqPzWjRm14oMEE+YLve4k/NAqCdPkGYDaDF5Sw+xBfg==} resolution: {integrity: sha512-LKaqQL9osY/ir2geuLVvRRs+utWUNilzdE90TpyoX0eNqPzWjRm14oMEE+YLve4k/NAqCdPkGYDaDF5Sw+xBfg==}
cpu: [x64] cpu: [x64]
os: [linux] os: [linux]
libc: [musl]
'@rollup/rollup-win32-arm64-msvc@4.18.0': '@rollup/rollup-win32-arm64-msvc@4.18.0':
resolution: {integrity: sha512-7J6TkZQFGo9qBKH0pk2cEVSRhJbL6MtfWxth7Y5YmZs57Pi+4x6c2dStAUvaQkHQLnEQv1jzBUW43GvZW8OFqA==} resolution: {integrity: sha512-7J6TkZQFGo9qBKH0pk2cEVSRhJbL6MtfWxth7Y5YmZs57Pi+4x6c2dStAUvaQkHQLnEQv1jzBUW43GvZW8OFqA==}
@@ -2817,7 +2809,7 @@ snapshots:
dependencies: dependencies:
axios: 1.7.2 axios: 1.7.2
'@halo-dev/components@2.17.0(vue-router@4.4.0(vue@3.4.31(typescript@5.3.3)))(vue@3.4.31(typescript@5.3.3))': '@halo-dev/components@https://pkg.pr.new/@halo-dev/components@7383(vue-router@4.4.0(vue@3.4.31(typescript@5.3.3)))(vue@3.4.31(typescript@5.3.3))':
dependencies: dependencies:
floating-vue: 5.2.2(vue@3.4.31(typescript@5.3.3)) floating-vue: 5.2.2(vue@3.4.31(typescript@5.3.3))
vue: 3.4.31(typescript@5.3.3) vue: 3.4.31(typescript@5.3.3)

View File

@@ -8,6 +8,7 @@ import {
VCard, VCard,
VEmpty, VEmpty,
VEntity, VEntity,
VEntityContainer,
VEntityField, VEntityField,
VLoading, VLoading,
VModal, VModal,
@@ -22,12 +23,16 @@ import { axiosInstance, coreApiClient, type Group } from "@halo-dev/api-client";
import { S3LinkControllerApi } from "@/api"; import { S3LinkControllerApi } from "@/api";
import type { S3ListResult, LinkResultItem, Policy, ObjectVo } from "@/api"; import type { S3ListResult, LinkResultItem, Policy, ObjectVo } from "@/api";
const s3LinkControllerApi = new S3LinkControllerApi(undefined, axiosInstance.defaults.baseURL, axiosInstance); const s3LinkControllerApi = new S3LinkControllerApi(
undefined,
axiosInstance.defaults.baseURL,
axiosInstance
);
const componentInstance = getCurrentInstance(); const componentInstance = getCurrentInstance();
const t = (key: string) => { const t = (key: string) => {
// @ts-ignore // @ts-ignore
if (typeof componentInstance?.proxy?.$t === 'function') { if (typeof componentInstance?.proxy?.$t === "function") {
// @ts-ignore // @ts-ignore
return componentInstance.proxy.$t(key); return componentInstance.proxy.$t(key);
} }
@@ -38,12 +43,14 @@ const selectedFiles = ref<string[]>([]);
const policyName = ref<string>(""); const policyName = ref<string>("");
const page = ref(1); const page = ref(1);
const size = ref(50); const size = ref(50);
const selectedGroup = ref("") const selectedGroup = ref("");
const policyOptions = ref<{ label: string; value: string; attrs: any }[]>([{ const policyOptions = ref<{ label: string; value: string; attrs: any }[]>([
label: "请选择存储策略", {
value: "", label: "请选择存储策略",
attrs: {disabled: true} value: "",
}]); attrs: { disabled: true },
},
]);
const defaultGroup = ref<Group>({ const defaultGroup = ref<Group>({
apiVersion: "", apiVersion: "",
kind: "", kind: "",
@@ -76,13 +83,15 @@ const isFetchingPolicies = ref(true);
const linkTips = ref(""); const linkTips = ref("");
const linkFailedTable = ref<LinkResultItem[]>([]); const linkFailedTable = ref<LinkResultItem[]>([]);
const linkedStatusItems: { label: string; value?: boolean }[] = [ const linkedStatusItems: { label: string; value?: boolean }[] = [
{label: "全部"}, { label: "全部" },
{label: "未关联", value: true}, { label: "未关联", value: true },
]; ];
// action state // action state
const checkedAll = ref(false); const checkedAll = ref(false);
const selectedLinkedStatusItem = ref<boolean | undefined>(linkedStatusItems[0].value); const selectedLinkedStatusItem = ref<boolean | undefined>(
linkedStatusItems[0].value
);
const emptyTips = computed(() => { const emptyTips = computed(() => {
if (isFetchingPolicies.value) { if (isFetchingPolicies.value) {
@@ -98,34 +107,37 @@ const emptyTips = computed(() => {
}); });
const handleCheckAllChange = (e: Event) => { const handleCheckAllChange = (e: Event) => {
const {checked} = e.target as HTMLInputElement; const { checked } = e.target as HTMLInputElement;
if (checked) { if (checked) {
selectedFiles.value = selectedFiles.value =
s3Objects.value.objects?.filter(file => !file.isLinked).map((file) => { s3Objects.value.objects
return file.key || ""; ?.filter((file) => !file.isLinked)
}) || []; .map((file) => {
return file.key || "";
}) || [];
} else { } else {
selectedFiles.value.length = 0; selectedFiles.value.length = 0;
checkedAll.value = false; checkedAll.value = false;
} }
}; };
const fetchPolicies = async () => { const fetchPolicies = async () => {
try { try {
const {status, data} = await s3LinkControllerApi.listS3Policies(); const { status, data } = await s3LinkControllerApi.listS3Policies();
if (status === 200) { if (status === 200) {
policyOptions.value = [{ policyOptions.value = [
label: "请选择存储策略", {
value: "", label: "请选择存储策略",
attrs: {disabled: true} value: "",
}]; attrs: { disabled: true },
},
];
data.forEach((policy: Policy) => { data.forEach((policy: Policy) => {
policyOptions.value.push({ policyOptions.value.push({
label: policy.spec.displayName, label: policy.spec.displayName,
value: policy.metadata.name, value: policy.metadata.name,
attrs: {} attrs: {},
}); });
}); });
} }
@@ -137,7 +149,8 @@ const fetchPolicies = async () => {
const changeNextTokenAndObject = () => { const changeNextTokenAndObject = () => {
s3Objects.value.currentToken = s3Objects.value.nextToken; s3Objects.value.currentToken = s3Objects.value.nextToken;
s3Objects.value.currentContinuationObject = s3Objects.value.nextContinuationObject; s3Objects.value.currentContinuationObject =
s3Objects.value.nextContinuationObject;
s3Objects.value.nextToken = ""; s3Objects.value.nextToken = "";
s3Objects.value.nextContinuationObject = ""; s3Objects.value.nextContinuationObject = "";
}; };
@@ -158,20 +171,28 @@ const fetchObjects = async () => {
isFetching.value = true; isFetching.value = true;
s3Objects.value.objects = []; s3Objects.value.objects = [];
try { try {
const {status, data} = await s3LinkControllerApi.listObjects({ const { status, data } = await s3LinkControllerApi.listObjects({
policyName: policyName.value, policyName: policyName.value,
pageSize: size.value, pageSize: size.value,
continuationToken: s3Objects.value.currentToken, continuationToken: s3Objects.value.currentToken,
continuationObject: s3Objects.value.currentContinuationObject, continuationObject: s3Objects.value.currentContinuationObject,
unlinked: selectedLinkedStatusItem.value, unlinked: selectedLinkedStatusItem.value,
filePrefix: filePrefix.value filePrefix: filePrefix.value,
}); });
if (status === 200) { if (status === 200) {
s3Objects.value = data; s3Objects.value = data;
if (s3Objects.value.objects?.length === 0 && s3Objects.value.hasMore && s3Objects.value.nextToken) { if (
s3Objects.value.objects?.length === 0 &&
s3Objects.value.hasMore &&
s3Objects.value.nextToken
) {
changeNextTokenAndObject(); changeNextTokenAndObject();
await fetchObjects(); await fetchObjects();
} else if (s3Objects.value.objects?.length === 0 && !s3Objects.value.hasMore && page.value > 1) { } else if (
s3Objects.value.objects?.length === 0 &&
!s3Objects.value.hasMore &&
page.value > 1
) {
page.value = 1; page.value = 1;
clearTokenAndObject(); clearTokenAndObject();
await fetchObjects(); await fetchObjects();
@@ -200,15 +221,15 @@ const handleLink = async () => {
policyName: policyName.value, policyName: policyName.value,
objectKeys: selectedFiles.value, objectKeys: selectedFiles.value,
groupName: selectedGroup.value, groupName: selectedGroup.value,
} },
}); });
const items = linkResult.data.items || []; const items = linkResult.data.items || [];
const successCount = items.filter(item => item.success).length; const successCount = items.filter((item) => item.success).length;
const failedCount = items.filter(item => !item.success).length; const failedCount = items.filter((item) => !item.success).length;
linkTips.value = `关联成功${successCount}个文件,关联失败${failedCount}个文件`; linkTips.value = `关联成功${successCount}个文件,关联失败${failedCount}个文件`;
if (failedCount > 0) { if (failedCount > 0) {
linkFailedTable.value = items.filter(item => !item.success); linkFailedTable.value = items.filter((item) => !item.success);
} }
isLinking.value = false; isLinking.value = false;
}; };
@@ -245,7 +266,7 @@ const handleModalClose = () => {
}; };
const fetchCustomGroups = async () => { const fetchCustomGroups = async () => {
const {status, data} = await coreApiClient.storage.group.listGroup({ const { status, data } = await coreApiClient.storage.group.listGroup({
labelSelector: ["!halo.run/hidden"], labelSelector: ["!halo.run/hidden"],
sort: ["metadata.creationTimestamp,asc"], sort: ["metadata.creationTimestamp,asc"],
}); });
@@ -260,19 +281,20 @@ onMounted(() => {
}); });
watch(selectedFiles, (newValue) => { watch(selectedFiles, (newValue) => {
checkedAll.value = s3Objects.value.objects?.filter(file => !file.isLinked) checkedAll.value =
.filter(file => !newValue.includes(file.key || "")).length === 0 s3Objects.value.objects
&& s3Objects.value.objects?.length !== 0; ?.filter((file) => !file.isLinked)
.filter((file) => !newValue.includes(file.key || "")).length === 0 &&
s3Objects.value.objects?.length !== 0;
}); });
watch(selectedLinkedStatusItem, handleFirstPage); watch(selectedLinkedStatusItem, handleFirstPage);
</script> </script>
<template> <template>
<VPageHeader title="关联S3文件"> <VPageHeader title="关联S3文件">
<template #icon> <template #icon>
<CarbonFolderDetailsReference class="mr-2 self-center"/> <CarbonFolderDetailsReference class="mr-2 self-center" />
</template> </template>
</VPageHeader> </VPageHeader>
<div class="m-0 md:m-4"> <div class="m-0 md:m-4">
@@ -285,7 +307,6 @@ watch(selectedLinkedStatusItem, handleFirstPage);
<div class="hidden items-center sm:flex"> <div class="hidden items-center sm:flex">
<input <input
v-model="checkedAll" v-model="checkedAll"
class="h-4 w-4 rounded border-gray-300 text-indigo-600"
type="checkbox" type="checkbox"
@change="handleCheckAllChange" @change="handleCheckAllChange"
/> />
@@ -299,14 +320,14 @@ watch(selectedLinkedStatusItem, handleFirstPage);
<FormKit <FormKit
id="policyChoose" id="policyChoose"
outer-class="!p-0" outer-class="!p-0"
style="min-width: 10rem;" style="min-width: 10rem"
v-model="policyName" v-model="policyName"
name="policyName" name="policyName"
type="select" type="select"
:options="policyOptions" :options="policyOptions"
@change="handleFirstPage" @change="handleFirstPage"
></FormKit> ></FormKit>
<icon-error-warning v-if="!policyName" class="text-red-500"/> <icon-error-warning v-if="!policyName" class="text-red-500" />
<SearchInput <SearchInput
v-model="filePrefixBind" v-model="filePrefixBind"
v-if="policyName" v-if="policyName"
@@ -315,9 +336,7 @@ watch(selectedLinkedStatusItem, handleFirstPage);
></SearchInput> ></SearchInput>
</div> </div>
<VSpace v-else> <VSpace v-else>
<VButton type="primary" @click="handleLink"> <VButton type="primary" @click="handleLink"> 关联 </VButton>
关联
</VButton>
</VSpace> </VSpace>
</div> </div>
<VSpace spacing="lg" class="flex-wrap"> <VSpace spacing="lg" class="flex-wrap">
@@ -339,8 +358,8 @@ watch(selectedLinkedStatusItem, handleFirstPage);
<IconRefreshLine <IconRefreshLine
v-tooltip="$t('core.common.buttons.refresh')" v-tooltip="$t('core.common.buttons.refresh')"
:class="{ :class="{
'animate-spin text-gray-900': isFetching, 'animate-spin text-gray-900': isFetching,
}" }"
class="h-4 w-4 text-gray-600 group-hover:text-gray-900" class="h-4 w-4 text-gray-600 group-hover:text-gray-900"
/> />
</div> </div>
@@ -350,33 +369,35 @@ watch(selectedLinkedStatusItem, handleFirstPage);
</div> </div>
</template> </template>
<VLoading v-if="isFetching"/> <VLoading v-if="isFetching" />
<Transition v-else-if="!s3Objects.objects?.length" appear name="fade"> <Transition v-else-if="!s3Objects.objects?.length" appear name="fade">
<VEmpty <VEmpty message="空空如也" :title="emptyTips"> </VEmpty>
message="空空如也"
:title="emptyTips"
>
</VEmpty>
</Transition> </Transition>
<Transition v-else appear name="fade"> <Transition v-else appear name="fade">
<ul <div class="box-border h-full w-full">
class="box-border h-full w-full divide-y divide-gray-100" <div style="padding: 0.5rem 1rem 0">
role="list" <span class="ml-1 mb-1 block text-sm text-gray-500">
> 关联后所加入的分组
<li style="padding: 0.5rem 1rem 0"> </span>
<span class="ml-1 mb-1 block text-sm text-gray-500">关联后所加入的分组</span> <div
<div class="mb-5 grid grid-cols-2 gap-x-2 gap-y-3 md:grid-cols-3 lg:grid-cols-4 2xl:grid-cols-6"> class="mb-5 grid grid-cols-2 gap-x-2 gap-y-3 md:grid-cols-3 lg:grid-cols-4 2xl:grid-cols-6"
>
<button <button
type="button" type="button"
class="inline-flex h-full w-full items-center gap-2 rounded-md border border-gray-200 bg-white px-3 py-2.5 text-sm font-medium text-gray-800 hover:bg-gray-50 hover:shadow-sm" class="inline-flex h-full w-full items-center gap-2 rounded-md border border-gray-200 bg-white px-3 py-2.5 text-sm font-medium text-gray-800 hover:bg-gray-50 hover:shadow-sm"
v-for="(group, index) in [defaultGroup, ...customGroups]" v-for="(group, index) in [defaultGroup, ...customGroups]"
:key="index" :key="index"
:class="{ '!bg-gray-100 shadow-sm': group.metadata.name === selectedGroup }" :class="{
'!bg-gray-100 shadow-sm':
group.metadata.name === selectedGroup,
}"
@click="selectedGroup = group.metadata.name" @click="selectedGroup = group.metadata.name"
> >
<div class="inline-flex w-full flex-1 gap-x-2 break-all text-left"> <div
class="inline-flex w-full flex-1 gap-x-2 break-all text-left"
>
<slot name="text"> <slot name="text">
{{ group?.spec.displayName }} {{ group?.spec.displayName }}
</slot> </slot>
@@ -395,17 +416,17 @@ watch(selectedLinkedStatusItem, handleFirstPage);
</div> </div>
</button> </button>
</div> </div>
</li> </div>
<li v-for="(file, index) in s3Objects.objects" :key="index"> <VEntityContainer>
<VEntity :is-selected="checkSelection(file)"> <VEntity
<template v-for="(file, index) in s3Objects.objects"
#checkbox :key="index"
> :is-selected="checkSelection(file)"
>
<template #checkbox>
<input <input
v-model="selectedFiles" v-model="selectedFiles"
:value="file.key || ''" :value="file.key || ''"
class="h-4 w-4 rounded border-gray-300 text-indigo-600"
name="post-checkbox"
:disabled="file.isLinked" :disabled="file.isLinked"
type="checkbox" type="checkbox"
/> />
@@ -429,10 +450,8 @@ watch(selectedLinkedStatusItem, handleFirstPage);
<template #end> <template #end>
<VEntityField> <VEntityField>
<template #description> <template #description>
<VTag :theme="file.isLinked ? 'default':'primary'"> <VTag :theme="file.isLinked ? 'default' : 'primary'">
{{ {{ file.isLinked ? "已关联" : "未关联" }}
file.isLinked ? '已关联' : '未关联'
}}
</VTag> </VTag>
</template> </template>
</VEntityField> </VEntityField>
@@ -448,23 +467,32 @@ watch(selectedLinkedStatusItem, handleFirstPage);
</VEntityField> </VEntityField>
</template> </template>
</VEntity> </VEntity>
</li> </VEntityContainer>
</ul> </div>
</Transition> </Transition>
<template #footer> <template #footer>
<div class="bg-white sm:flex sm:items-center justify-between"> <div class="bg-white sm:flex sm:items-center justify-between">
<div class="inline-flex items-center gap-5"> <div class="inline-flex items-center gap-5">
<span class="text-xs text-gray-500 hidden md:flex"> {{ s3Objects.objects?.length }} 项数据</span> <span class="text-xs text-gray-500 hidden md:flex"
<span class="text-xs text-gray-500 hidden md:flex">已自动过滤文件夹对象页面实际显示数量少为正常现象</span> > {{ s3Objects.objects?.length }} 项数据</span
>
<span class="text-xs text-gray-500 hidden md:flex"
>已自动过滤文件夹对象页面实际显示数量少为正常现象</span
>
</div> </div>
<div class="inline-flex items-center gap-5"> <div class="inline-flex items-center gap-5">
<div class="inline-flex items-center gap-2"> <div class="inline-flex items-center gap-2">
<VButton @click="handleFirstPage" :disabled="!policyName">返回第一页</VButton> <VButton @click="handleFirstPage" :disabled="!policyName"
>返回第一页</VButton
>
<span class="text-sm text-gray-500"> {{ page }} </span> <span class="text-sm text-gray-500"> {{ page }} </span>
<VButton @click="handleNextPage" :disabled="!s3Objects.hasMore || isFetching || !policyName"> <VButton
@click="handleNextPage"
:disabled="!s3Objects.hasMore || isFetching || !policyName"
>
下一页 下一页
</VButton> </VButton>
</div> </div>
@@ -499,11 +527,7 @@ watch(selectedLinkedStatusItem, handleFirstPage);
> >
<template #footer> <template #footer>
<VSpace> <VSpace>
<VButton <VButton :loading="isLinking" type="primary" @click="handleModalClose">
:loading="isLinking"
type="primary"
@click="handleModalClose"
>
确定 确定
</VButton> </VButton>
</VSpace> </VSpace>
@@ -516,8 +540,12 @@ watch(selectedLinkedStatusItem, handleFirstPage);
<th class="border border-black font-normal">失败原因</th> <th class="border border-black font-normal">失败原因</th>
</tr> </tr>
<tr v-for="failedInfo in linkFailedTable" :key="failedInfo.objectKey"> <tr v-for="failedInfo in linkFailedTable" :key="failedInfo.objectKey">
<th class="border border-black font-normal">{{ failedInfo.objectKey }}</th> <th class="border border-black font-normal">
<th class="border border-black font-normal">{{ failedInfo.message }}</th> {{ failedInfo.objectKey }}
</th>
<th class="border border-black font-normal">
{{ failedInfo.message }}
</th>
</tr> </tr>
</table> </table>
</div> </div>

Binary file not shown.

View File

@@ -1,7 +1,7 @@
distributionBase=GRADLE_USER_HOME distributionBase=GRADLE_USER_HOME
distributionPath=wrapper/dists distributionPath=wrapper/dists
distributionUrl=https\://services.gradle.org/distributions/gradle-8.8-bin.zip distributionUrl=https\://services.gradle.org/distributions/gradle-8.14-bin.zip
networkTimeout=10000 networkTimeout=10000
validateDistributionUrl=true validateDistributionUrl=true
zipStoreBase=GRADLE_USER_HOME zipStoreBase=GRADLE_USER_HOME
zipStorePath=wrapper/dists zipStorePath=wrapper/dists

47
gradlew vendored
View File

@@ -15,6 +15,8 @@
# See the License for the specific language governing permissions and # See the License for the specific language governing permissions and
# limitations under the License. # limitations under the License.
# #
# SPDX-License-Identifier: Apache-2.0
#
############################################################################## ##############################################################################
# #
@@ -55,7 +57,7 @@
# Darwin, MinGW, and NonStop. # Darwin, MinGW, and NonStop.
# #
# (3) This script is generated from the Groovy template # (3) This script is generated from the Groovy template
# https://github.com/gradle/gradle/blob/master/subprojects/plugins/src/main/resources/org/gradle/api/internal/plugins/unixStartScript.txt # https://github.com/gradle/gradle/blob/HEAD/platforms/jvm/plugins-application/src/main/resources/org/gradle/api/internal/plugins/unixStartScript.txt
# within the Gradle project. # within the Gradle project.
# #
# You can find Gradle at https://github.com/gradle/gradle/. # You can find Gradle at https://github.com/gradle/gradle/.
@@ -80,13 +82,11 @@ do
esac esac
done done
APP_HOME=$( cd "${APP_HOME:-./}" && pwd -P ) || exit # This is normally unused
# shellcheck disable=SC2034
APP_NAME="Gradle"
APP_BASE_NAME=${0##*/} APP_BASE_NAME=${0##*/}
# Discard cd standard output in case $CDPATH is set (https://github.com/gradle/gradle/issues/25036)
# Add default JVM options here. You can also use JAVA_OPTS and GRADLE_OPTS to pass JVM options to this script. APP_HOME=$( cd -P "${APP_HOME:-./}" > /dev/null && printf '%s\n' "$PWD" ) || exit
DEFAULT_JVM_OPTS='"-Xmx64m" "-Xms64m"'
# Use the maximum available, or set MAX_FD != -1 to use that value. # Use the maximum available, or set MAX_FD != -1 to use that value.
MAX_FD=maximum MAX_FD=maximum
@@ -114,7 +114,7 @@ case "$( uname )" in #(
NONSTOP* ) nonstop=true ;; NONSTOP* ) nonstop=true ;;
esac esac
CLASSPATH=$APP_HOME/gradle/wrapper/gradle-wrapper.jar CLASSPATH="\\\"\\\""
# Determine the Java command to use to start the JVM. # Determine the Java command to use to start the JVM.
@@ -133,22 +133,29 @@ location of your Java installation."
fi fi
else else
JAVACMD=java JAVACMD=java
which java >/dev/null 2>&1 || die "ERROR: JAVA_HOME is not set and no 'java' command could be found in your PATH. if ! command -v java >/dev/null 2>&1
then
die "ERROR: JAVA_HOME is not set and no 'java' command could be found in your PATH.
Please set the JAVA_HOME variable in your environment to match the Please set the JAVA_HOME variable in your environment to match the
location of your Java installation." location of your Java installation."
fi
fi fi
# Increase the maximum file descriptors if we can. # Increase the maximum file descriptors if we can.
if ! "$cygwin" && ! "$darwin" && ! "$nonstop" ; then if ! "$cygwin" && ! "$darwin" && ! "$nonstop" ; then
case $MAX_FD in #( case $MAX_FD in #(
max*) max*)
# In POSIX sh, ulimit -H is undefined. That's why the result is checked to see if it worked.
# shellcheck disable=SC2039,SC3045
MAX_FD=$( ulimit -H -n ) || MAX_FD=$( ulimit -H -n ) ||
warn "Could not query maximum file descriptor limit" warn "Could not query maximum file descriptor limit"
esac esac
case $MAX_FD in #( case $MAX_FD in #(
'' | soft) :;; #( '' | soft) :;; #(
*) *)
# In POSIX sh, ulimit -n is undefined. That's why the result is checked to see if it worked.
# shellcheck disable=SC2039,SC3045
ulimit -n "$MAX_FD" || ulimit -n "$MAX_FD" ||
warn "Could not set maximum file descriptor limit to $MAX_FD" warn "Could not set maximum file descriptor limit to $MAX_FD"
esac esac
@@ -193,18 +200,28 @@ if "$cygwin" || "$msys" ; then
done done
fi fi
# Collect all arguments for the java command;
# * $DEFAULT_JVM_OPTS, $JAVA_OPTS, and $GRADLE_OPTS can contain fragments of # Add default JVM options here. You can also use JAVA_OPTS and GRADLE_OPTS to pass JVM options to this script.
# shell script including quotes and variable substitutions, so put them in DEFAULT_JVM_OPTS='"-Xmx64m" "-Xms64m"'
# double quotes to make sure that they get re-expanded; and
# * put everything else in single quotes, so that it's not re-expanded. # Collect all arguments for the java command:
# * DEFAULT_JVM_OPTS, JAVA_OPTS, and optsEnvironmentVar are not allowed to contain shell fragments,
# and any embedded shellness will be escaped.
# * For example: A user cannot expect ${Hostname} to be expanded, as it is an environment variable and will be
# treated as '${Hostname}' itself on the command line.
set -- \ set -- \
"-Dorg.gradle.appname=$APP_BASE_NAME" \ "-Dorg.gradle.appname=$APP_BASE_NAME" \
-classpath "$CLASSPATH" \ -classpath "$CLASSPATH" \
org.gradle.wrapper.GradleWrapperMain \ -jar "$APP_HOME/gradle/wrapper/gradle-wrapper.jar" \
"$@" "$@"
# Stop when "xargs" is not available.
if ! command -v xargs >/dev/null 2>&1
then
die "xargs is not available"
fi
# Use "xargs" to parse quoted args. # Use "xargs" to parse quoted args.
# #
# With -n1 it outputs one arg per line, with the quotes and backslashes removed. # With -n1 it outputs one arg per line, with the quotes and backslashes removed.

41
gradlew.bat vendored
View File

@@ -13,8 +13,10 @@
@rem See the License for the specific language governing permissions and @rem See the License for the specific language governing permissions and
@rem limitations under the License. @rem limitations under the License.
@rem @rem
@rem SPDX-License-Identifier: Apache-2.0
@rem
@if "%DEBUG%" == "" @echo off @if "%DEBUG%"=="" @echo off
@rem ########################################################################## @rem ##########################################################################
@rem @rem
@rem Gradle startup script for Windows @rem Gradle startup script for Windows
@@ -25,7 +27,8 @@
if "%OS%"=="Windows_NT" setlocal if "%OS%"=="Windows_NT" setlocal
set DIRNAME=%~dp0 set DIRNAME=%~dp0
if "%DIRNAME%" == "" set DIRNAME=. if "%DIRNAME%"=="" set DIRNAME=.
@rem This is normally unused
set APP_BASE_NAME=%~n0 set APP_BASE_NAME=%~n0
set APP_HOME=%DIRNAME% set APP_HOME=%DIRNAME%
@@ -40,13 +43,13 @@ if defined JAVA_HOME goto findJavaFromJavaHome
set JAVA_EXE=java.exe set JAVA_EXE=java.exe
%JAVA_EXE% -version >NUL 2>&1 %JAVA_EXE% -version >NUL 2>&1
if "%ERRORLEVEL%" == "0" goto execute if %ERRORLEVEL% equ 0 goto execute
echo. echo. 1>&2
echo ERROR: JAVA_HOME is not set and no 'java' command could be found in your PATH. echo ERROR: JAVA_HOME is not set and no 'java' command could be found in your PATH. 1>&2
echo. echo. 1>&2
echo Please set the JAVA_HOME variable in your environment to match the echo Please set the JAVA_HOME variable in your environment to match the 1>&2
echo location of your Java installation. echo location of your Java installation. 1>&2
goto fail goto fail
@@ -56,32 +59,34 @@ set JAVA_EXE=%JAVA_HOME%/bin/java.exe
if exist "%JAVA_EXE%" goto execute if exist "%JAVA_EXE%" goto execute
echo. echo. 1>&2
echo ERROR: JAVA_HOME is set to an invalid directory: %JAVA_HOME% echo ERROR: JAVA_HOME is set to an invalid directory: %JAVA_HOME% 1>&2
echo. echo. 1>&2
echo Please set the JAVA_HOME variable in your environment to match the echo Please set the JAVA_HOME variable in your environment to match the 1>&2
echo location of your Java installation. echo location of your Java installation. 1>&2
goto fail goto fail
:execute :execute
@rem Setup the command line @rem Setup the command line
set CLASSPATH=%APP_HOME%\gradle\wrapper\gradle-wrapper.jar set CLASSPATH=
@rem Execute Gradle @rem Execute Gradle
"%JAVA_EXE%" %DEFAULT_JVM_OPTS% %JAVA_OPTS% %GRADLE_OPTS% "-Dorg.gradle.appname=%APP_BASE_NAME%" -classpath "%CLASSPATH%" org.gradle.wrapper.GradleWrapperMain %* "%JAVA_EXE%" %DEFAULT_JVM_OPTS% %JAVA_OPTS% %GRADLE_OPTS% "-Dorg.gradle.appname=%APP_BASE_NAME%" -classpath "%CLASSPATH%" -jar "%APP_HOME%\gradle\wrapper\gradle-wrapper.jar" %*
:end :end
@rem End local scope for the variables with windows NT shell @rem End local scope for the variables with windows NT shell
if "%ERRORLEVEL%"=="0" goto mainEnd if %ERRORLEVEL% equ 0 goto mainEnd
:fail :fail
rem Set variable GRADLE_EXIT_CONSOLE if you need the _script_ return code instead of rem Set variable GRADLE_EXIT_CONSOLE if you need the _script_ return code instead of
rem the _cmd.exe /c_ return code! rem the _cmd.exe /c_ return code!
if not "" == "%GRADLE_EXIT_CONSOLE%" exit 1 set EXIT_CODE=%ERRORLEVEL%
exit /b 1 if %EXIT_CODE% equ 0 set EXIT_CODE=1
if not ""=="%GRADLE_EXIT_CONSOLE%" exit %EXIT_CODE%
exit /b %EXIT_CODE%
:mainEnd :mainEnd
if "%OS%"=="Windows_NT" endlocal if "%OS%"=="Windows_NT" endlocal

View File

@@ -1,6 +1,5 @@
pluginManagement { pluginManagement {
repositories { repositories {
maven { url 'https://s01.oss.sonatype.org/content/repositories/snapshots' }
mavenCentral() mavenCentral()
maven { url 'https://maven.aliyun.com/repository/gradle-plugin' } maven { url 'https://maven.aliyun.com/repository/gradle-plugin' }
maven { url 'https://maven.aliyun.com/repository/spring-plugin' } maven { url 'https://maven.aliyun.com/repository/spring-plugin' }
@@ -9,4 +8,3 @@ pluginManagement {
} }
} }
rootProject.name = 'plugin-s3' rootProject.name = 'plugin-s3'

View File

@@ -67,7 +67,7 @@ public class S3LinkServiceImpl implements S3LinkService {
return client.fetch(ConfigMap.class, configMapName); return client.fetch(ConfigMap.class, configMapName);
}) })
.flatMap((configMap) -> { .flatMap((configMap) -> {
var properties = handler.getProperties(configMap); var properties = S3OsProperties.convertFrom(configMap);
var finalLocation = FilePathUtils.getFilePathByPlaceholder(properties.getLocation()); var finalLocation = FilePathUtils.getFilePathByPlaceholder(properties.getLocation());
return Mono.using(() -> handler.buildS3Client(properties), return Mono.using(() -> handler.buildS3Client(properties),
// 执行 listObjects // 执行 listObjects
@@ -231,7 +231,7 @@ public class S3LinkServiceImpl implements S3LinkService {
return client.fetch(ConfigMap.class, configMapName); return client.fetch(ConfigMap.class, configMapName);
}) })
.flatMap(configMap -> { .flatMap(configMap -> {
var properties = handler.getProperties(configMap); var properties = S3OsProperties.convertFrom(configMap);
return Mono.using(() -> handler.buildS3Client(properties), return Mono.using(() -> handler.buildS3Client(properties),
(s3Client) -> Mono.fromCallable( (s3Client) -> Mono.fromCallable(
() -> s3Client.headObject( () -> s3Client.headObject(

View File

@@ -3,7 +3,6 @@ package run.halo.s3os;
import java.net.URI; import java.net.URI;
import java.net.URISyntaxException; import java.net.URISyntaxException;
import java.nio.ByteBuffer; import java.nio.ByteBuffer;
import java.nio.charset.StandardCharsets;
import java.nio.file.FileAlreadyExistsException; import java.nio.file.FileAlreadyExistsException;
import java.time.Duration; import java.time.Duration;
import java.util.HashMap; import java.util.HashMap;
@@ -23,7 +22,6 @@ import org.springframework.http.MediaTypeFactory;
import org.springframework.lang.Nullable; import org.springframework.lang.Nullable;
import org.springframework.web.server.ServerErrorException; import org.springframework.web.server.ServerErrorException;
import org.springframework.web.server.ServerWebInputException; import org.springframework.web.server.ServerWebInputException;
import org.springframework.web.util.UriUtils;
import reactor.core.Exceptions; import reactor.core.Exceptions;
import reactor.core.publisher.Flux; import reactor.core.publisher.Flux;
import reactor.core.publisher.Mono; import reactor.core.publisher.Mono;
@@ -38,7 +36,6 @@ import run.halo.app.core.extension.attachment.endpoint.AttachmentHandler;
import run.halo.app.extension.ConfigMap; import run.halo.app.extension.ConfigMap;
import run.halo.app.extension.Metadata; import run.halo.app.extension.Metadata;
import run.halo.app.extension.MetadataUtil; import run.halo.app.extension.MetadataUtil;
import run.halo.app.infra.utils.JsonUtils;
import software.amazon.awssdk.auth.credentials.AwsBasicCredentials; import software.amazon.awssdk.auth.credentials.AwsBasicCredentials;
import software.amazon.awssdk.awscore.presigner.SdkPresigner; import software.amazon.awssdk.awscore.presigner.SdkPresigner;
import software.amazon.awssdk.core.SdkResponse; import software.amazon.awssdk.core.SdkResponse;
@@ -47,16 +44,7 @@ import software.amazon.awssdk.http.SdkHttpResponse;
import software.amazon.awssdk.regions.Region; import software.amazon.awssdk.regions.Region;
import software.amazon.awssdk.services.s3.S3Client; import software.amazon.awssdk.services.s3.S3Client;
import software.amazon.awssdk.services.s3.S3Configuration; import software.amazon.awssdk.services.s3.S3Configuration;
import software.amazon.awssdk.services.s3.model.CompleteMultipartUploadRequest; import software.amazon.awssdk.services.s3.model.*;
import software.amazon.awssdk.services.s3.model.CompletedMultipartUpload;
import software.amazon.awssdk.services.s3.model.CompletedPart;
import software.amazon.awssdk.services.s3.model.CreateMultipartUploadRequest;
import software.amazon.awssdk.services.s3.model.DeleteObjectRequest;
import software.amazon.awssdk.services.s3.model.GetObjectRequest;
import software.amazon.awssdk.services.s3.model.HeadObjectRequest;
import software.amazon.awssdk.services.s3.model.HeadObjectResponse;
import software.amazon.awssdk.services.s3.model.NoSuchKeyException;
import software.amazon.awssdk.services.s3.model.UploadPartRequest;
import software.amazon.awssdk.services.s3.presigner.S3Presigner; import software.amazon.awssdk.services.s3.presigner.S3Presigner;
import software.amazon.awssdk.services.s3.presigner.model.GetObjectPresignRequest; import software.amazon.awssdk.services.s3.presigner.model.GetObjectPresignRequest;
import software.amazon.awssdk.utils.SdkAutoCloseable; import software.amazon.awssdk.utils.SdkAutoCloseable;
@@ -79,7 +67,7 @@ public class S3OsAttachmentHandler implements AttachmentHandler {
public Mono<Attachment> upload(UploadContext uploadContext) { public Mono<Attachment> upload(UploadContext uploadContext) {
return Mono.just(uploadContext).filter(context -> this.shouldHandle(context.policy())) return Mono.just(uploadContext).filter(context -> this.shouldHandle(context.policy()))
.flatMap(context -> { .flatMap(context -> {
final var properties = getProperties(context.configMap()); final var properties = S3OsProperties.convertFrom(context.configMap());
return upload(context, properties) return upload(context, properties)
.subscribeOn(Schedulers.boundedElastic()) .subscribeOn(Schedulers.boundedElastic())
.map(objectDetail -> this.buildAttachment(properties, objectDetail)) .map(objectDetail -> this.buildAttachment(properties, objectDetail))
@@ -89,41 +77,46 @@ public class S3OsAttachmentHandler implements AttachmentHandler {
@Override @Override
public Mono<Attachment> delete(DeleteContext deleteContext) { public Mono<Attachment> delete(DeleteContext deleteContext) {
return Mono.just(deleteContext).filter(context -> this.shouldHandle(context.policy())) return Mono.just(deleteContext)
.filter(context -> this.shouldHandle(context.policy()))
.flatMap(context -> { .flatMap(context -> {
var objectKey = getObjectKey(context.attachment()); var objectKey = getObjectKey(context.attachment());
if (objectKey == null) { if (objectKey == null) {
log.warn( log.warn(
"Cannot obtain object key from attachment {}, skip deleting object from S3.", "Cannot obtain object key from attachment {}, skip deleting object from S3.",
context.attachment().getMetadata().getName()); context.attachment().getMetadata().getName());
return Mono.just(context); return Mono.just(context.attachment());
} else if (MetadataUtil.nullSafeAnnotations(context.attachment()) } else if (MetadataUtil.nullSafeAnnotations(context.attachment())
.containsKey(SKIP_REMOTE_DELETION_ANNO)) { .containsKey(SKIP_REMOTE_DELETION_ANNO)) {
log.info("Skip deleting object {} from S3.", objectKey); log.info("Skip deleting object {} from S3.", objectKey);
return Mono.just(context); return Mono.just(context.attachment());
} }
var properties = getProperties(deleteContext.configMap()); var properties = S3OsProperties.convertFrom(deleteContext.configMap());
return Mono.using(() -> buildS3Client(properties), return Mono.using(
() -> buildS3Client(properties),
client -> Mono.fromCallable( client -> Mono.fromCallable(
() -> client.deleteObject(DeleteObjectRequest.builder() () -> client.deleteObject(DeleteObjectRequest.builder()
.bucket(properties.getBucket()) .bucket(properties.getBucket())
.key(objectKey) .key(objectKey)
.build())).subscribeOn(Schedulers.boundedElastic()), .build())),
S3Client::close) S3Client::close
)
.subscribeOn(Schedulers.boundedElastic())
.doOnNext(response -> { .doOnNext(response -> {
checkResult(response, "delete object"); checkResult(response, "delete object");
log.info("Delete object {} from bucket {} successfully", log.info("Delete object {} from bucket {} successfully",
objectKey, properties.getBucket()); objectKey, properties.getBucket());
}) })
.thenReturn(context); // ignore when the object does not exist
}) .onErrorComplete(NoSuchKeyException.class::isInstance)
.onErrorMap(S3ExceptionHandler::map) .onErrorMap(S3ExceptionHandler::map)
.map(DeleteContext::attachment); .thenReturn(context.attachment());
});
} }
@Override @Override
public Mono<URI> getSharedURL(Attachment attachment, Policy policy, ConfigMap configMap, public Mono<URI> getSharedURL(Attachment attachment, Policy policy, ConfigMap configMap,
Duration ttl) { Duration ttl) {
if (!this.shouldHandle(policy)) { if (!this.shouldHandle(policy)) {
return Mono.empty(); return Mono.empty();
} }
@@ -132,7 +125,7 @@ public class S3OsAttachmentHandler implements AttachmentHandler {
return Mono.error(new IllegalArgumentException( return Mono.error(new IllegalArgumentException(
"Cannot obtain object key from attachment " + attachment.getMetadata().getName())); "Cannot obtain object key from attachment " + attachment.getMetadata().getName()));
} }
var properties = getProperties(configMap); var properties = S3OsProperties.convertFrom(configMap);
return Mono.using(() -> buildS3Presigner(properties), return Mono.using(() -> buildS3Presigner(properties),
s3Presigner -> { s3Presigner -> {
@@ -168,8 +161,8 @@ public class S3OsAttachmentHandler implements AttachmentHandler {
// fallback to default handler for backward compatibility // fallback to default handler for backward compatibility
return Mono.empty(); return Mono.empty();
} }
var properties = getProperties(configMap); var properties = S3OsProperties.convertFrom(configMap);
var objectURL = getObjectURL(properties, objectKey); var objectURL = properties.toObjectURL(objectKey);
var urlSuffix = getUrlSuffixAnnotation(attachment); var urlSuffix = getUrlSuffixAnnotation(attachment);
if (StringUtils.isNotBlank(urlSuffix)) { if (StringUtils.isNotBlank(urlSuffix)) {
objectURL += urlSuffix; objectURL += urlSuffix;
@@ -195,13 +188,8 @@ public class S3OsAttachmentHandler implements AttachmentHandler {
return annotations.get(URL_SUFFIX_ANNO_KEY); return annotations.get(URL_SUFFIX_ANNO_KEY);
} }
S3OsProperties getProperties(ConfigMap configMap) {
var settingJson = configMap.getData().getOrDefault("default", "{}");
return JsonUtils.jsonToObject(settingJson, S3OsProperties.class);
}
Attachment buildAttachment(S3OsProperties properties, ObjectDetail objectDetail) { Attachment buildAttachment(S3OsProperties properties, ObjectDetail objectDetail) {
String externalLink = getObjectURL(properties, objectDetail.uploadState.objectKey); String externalLink = properties.toObjectURL(objectDetail.uploadState.objectKey);
var urlSuffix = UrlUtils.findUrlSuffix(properties.getUrlSuffixes(), var urlSuffix = UrlUtils.findUrlSuffix(properties.getUrlSuffixes(),
objectDetail.uploadState.fileName); objectDetail.uploadState.fileName);
@@ -229,22 +217,6 @@ public class S3OsAttachmentHandler implements AttachmentHandler {
return attachment; return attachment;
} }
String getObjectURL(S3OsProperties properties, String objectKey) {
String objectURL;
if (StringUtils.isBlank(properties.getDomain())) {
String host;
if (properties.getEnablePathStyleAccess()) {
host = properties.getEndpoint() + "/" + properties.getBucket();
} else {
host = properties.getBucket() + "." + properties.getEndpoint();
}
objectURL = properties.getProtocol() + "://" + host + "/" + objectKey;
} else {
objectURL = properties.getProtocol() + "://" + properties.getDomain() + "/" + objectKey;
}
return UriUtils.encodePath(objectURL, StandardCharsets.UTF_8);
}
S3Client buildS3Client(S3OsProperties properties) { S3Client buildS3Client(S3OsProperties properties) {
return S3Client.builder() return S3Client.builder()
.region(Region.of(properties.getRegion())) .region(Region.of(properties.getRegion()))

View File

@@ -1,16 +1,17 @@
package run.halo.s3os; package run.halo.s3os;
import java.nio.charset.StandardCharsets;
import java.util.List; import java.util.List;
import lombok.AllArgsConstructor; import lombok.AllArgsConstructor;
import lombok.Data; import lombok.Data;
import lombok.NoArgsConstructor; import lombok.NoArgsConstructor;
import lombok.RequiredArgsConstructor;
import org.springframework.util.StringUtils; import org.springframework.util.StringUtils;
import org.springframework.web.util.UriUtils;
import java.time.LocalDate; import run.halo.app.extension.ConfigMap;
import run.halo.app.infra.utils.JsonUtils;
@Data @Data
class S3OsProperties { public class S3OsProperties {
private String bucket; private String bucket;
@@ -49,6 +50,8 @@ class S3OsProperties {
private List<urlSuffixItem> urlSuffixes; private List<urlSuffixItem> urlSuffixes;
private String thumbnailParamPattern;
@Data @Data
@AllArgsConstructor @AllArgsConstructor
@NoArgsConstructor @NoArgsConstructor
@@ -103,14 +106,14 @@ class S3OsProperties {
if (length >= 4 && length <= 16) { if (length >= 4 && length <= 16) {
this.randomStringLength = length; this.randomStringLength = length;
} }
} catch (NumberFormatException ignored) {
} }
catch (NumberFormatException ignored) { }
} }
public void setRegion(String region) { public void setRegion(String region) {
if (!StringUtils.hasText(region)) { if (!StringUtils.hasText(region)) {
this.region = "Auto"; this.region = "Auto";
}else { } else {
this.region = region; this.region = region;
} }
} }
@@ -118,4 +121,25 @@ class S3OsProperties {
public void setEndpoint(String endpoint) { public void setEndpoint(String endpoint) {
this.endpoint = UrlUtils.removeHttpPrefix(endpoint); this.endpoint = UrlUtils.removeHttpPrefix(endpoint);
} }
public String toObjectURL(String objectKey) {
String objectURL;
if (!StringUtils.hasText(this.getDomain())) {
String host;
if (this.getEnablePathStyleAccess()) {
host = this.getEndpoint() + "/" + this.getBucket();
} else {
host = this.getBucket() + "." + this.getEndpoint();
}
objectURL = this.getProtocol() + "://" + host + "/" + objectKey;
} else {
objectURL = this.getProtocol() + "://" + this.getDomain() + "/" + objectKey;
}
return UriUtils.encodePath(objectURL, StandardCharsets.UTF_8);
}
public static S3OsProperties convertFrom(ConfigMap configMap) {
var settingJson = configMap.getData().getOrDefault("default", "{}");
return JsonUtils.jsonToObject(settingJson, S3OsProperties.class);
}
} }

View File

@@ -0,0 +1,106 @@
package run.halo.s3os;
import java.net.URI;
import java.net.URL;
import java.util.Map;
import com.google.common.cache.Cache;
import com.google.common.cache.CacheBuilder;
import lombok.Builder;
import lombok.RequiredArgsConstructor;
import org.apache.commons.lang3.StringUtils;
import org.springframework.stereotype.Component;
import org.springframework.web.util.UriComponentsBuilder;
import reactor.core.publisher.Flux;
import reactor.core.publisher.Mono;
import run.halo.app.core.attachment.ThumbnailProvider;
import run.halo.app.core.attachment.ThumbnailSize;
import run.halo.app.extension.ConfigMap;
import run.halo.app.extension.ReactiveExtensionClient;
@Component
@RequiredArgsConstructor
public class S3ThumbnailProvider implements ThumbnailProvider {
static final String WIDTH_PLACEHOLDER = "{width}";
private final Cache<String, S3PropsCacheValue> s3PropsCache = CacheBuilder.newBuilder()
.maximumSize(50)
.build();
private final ReactiveExtensionClient client;
private final S3LinkService s3LinkService;
@Override
public Mono<URI> generate(ThumbnailContext thumbnailContext) {
var url = thumbnailContext.getImageUrl().toString();
var size = thumbnailContext.getSize();
return getCacheValue(url)
.mapNotNull(cacheValue -> placedPattern(cacheValue.pattern(), size))
.map(param -> {
if (param.startsWith("?")) {
return UriComponentsBuilder.fromHttpUrl(url)
.queryParam(param.substring(1))
.build()
.toString();
}
return url + param;
})
.map(URI::create);
}
private static String placedPattern(String pattern, ThumbnailSize size) {
return StringUtils.replace(pattern, WIDTH_PLACEHOLDER, String.valueOf(size.getWidth()));
}
@Override
public Mono<Void> delete(URL url) {
// do nothing for s3
return Mono.empty();
}
@Override
public Mono<Boolean> supports(ThumbnailContext thumbnailContext) {
var url = thumbnailContext.getImageUrl().toString();
return getCacheValue(url).hasElement();
}
private Mono<S3PropsCacheValue> getCacheValue(String imageUrl) {
return Flux.fromIterable(s3PropsCache.asMap().entrySet())
.filter(entry -> imageUrl.startsWith(entry.getKey()))
.next()
.map(Map.Entry::getValue)
.switchIfEmpty(Mono.defer(() -> listAllS3ObjectDomain()
.filter(entry -> imageUrl.startsWith(entry.getKey()))
.map(Map.Entry::getValue)
.next()
));
}
@Builder
record S3PropsCacheValue(String pattern, String configMapName) {
}
private Flux<Map.Entry<String, S3PropsCacheValue>> listAllS3ObjectDomain() {
return s3LinkService.listS3Policies()
.flatMap(s3Policy -> {
var s3ConfigMapName = s3Policy.getSpec().getConfigMapName();
return fetchS3PropsByConfigMapName(s3ConfigMapName)
.mapNotNull(properties -> {
var thumbnailParam = properties.getThumbnailParamPattern();
if (StringUtils.isBlank(thumbnailParam)) {
return null;
}
var objectDomain = properties.toObjectURL("");
var cacheValue = S3PropsCacheValue.builder()
.pattern(thumbnailParam)
.configMapName(s3ConfigMapName)
.build();
return Map.entry(objectDomain, cacheValue);
});
})
.doOnNext(cache -> s3PropsCache.put(cache.getKey(), cache.getValue()));
}
private Mono<S3OsProperties> fetchS3PropsByConfigMapName(String name) {
return client.fetch(ConfigMap.class, name)
.map(S3OsProperties::convertFrom);
}
}

View File

@@ -0,0 +1,9 @@
apiVersion: plugin.halo.run/v1alpha1
kind: ExtensionDefinition
metadata:
name: s3os-thumbnail-provider
spec:
className: run.halo.s3os.S3ThumbnailProvider
extensionPointName: thumbnail-provider
displayName: "S3 协议 OSS 缩略图生成"
description: "为上传到支持 S3 协议的 OSS 的图片生成缩略图"

View File

@@ -144,4 +144,28 @@ spec:
name: urlSuffix name: urlSuffix
label: 网址后缀 label: 网址后缀
placeholder: 例如:?imageMogr2/format/webp placeholder: 例如:?imageMogr2/format/webp
validation: required validation: required
- $formkit: select
name: thumbnailParamPattern
label: 缩略图参数
allowCreate: true
searchable: true
value: ""
help: |
请根据您的对象存储服务商选择对应的缩略图参数或自定义参数,{width} 为宽度占位符将被替换为所需缩略图宽度值,
如: 400参数需要以 ? 开头,间隔符除外
options:
- label:
value: ""
- label: 腾讯云 COS / 七牛云 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}"

View File

@@ -4,7 +4,7 @@ metadata:
name: PluginS3ObjectStorage name: PluginS3ObjectStorage
spec: spec:
enabled: true enabled: true
requires: ">=2.17.0" requires: ">=2.21.0"
author: author:
name: Halo name: Halo
website: https://github.com/halo-dev website: https://github.com/halo-dev