Skip to content

Commit

Permalink
Code Formatting
Browse files Browse the repository at this point in the history
  • Loading branch information
longjuan committed Nov 9, 2023
1 parent df4a182 commit c4de5ba
Show file tree
Hide file tree
Showing 4 changed files with 33 additions and 42 deletions.
15 changes: 8 additions & 7 deletions console/src/index.ts
Original file line number Diff line number Diff line change
@@ -1,11 +1,10 @@
import { definePlugin } from "@halo-dev/console-shared";
import type { PluginTab } from "@halo-dev/console-shared";
import type {PluginTab} from "@halo-dev/console-shared";
import {definePlugin} from "@halo-dev/console-shared";
import S3Link from "./views/S3Link.vue";
import S3Unlink from "./views/S3Unlink.vue"
import { markRaw } from "vue";

import type { Attachment } from "./interface";
import type { Ref } from "vue";
import type {Ref} from "vue";
import {markRaw} from "vue";
import type {Attachment} from "./interface";

export default definePlugin({
components: {},
Expand All @@ -16,6 +15,7 @@ export default definePlugin({
{
id: "s3-link",
label: "关联S3文件",
// @ts-ignore
component: markRaw(S3Link),
permissions: ["plugin:s3os:link"]
},
Expand All @@ -31,7 +31,8 @@ export default definePlugin({
props: {
"attachment": attachment,
},
hidden: !(attachment.value.metadata.annotations && attachment.value.metadata.annotations["s3os.plugin.halo.run/object-key"])
hidden: !(attachment.value.metadata.annotations
&& attachment.value.metadata.annotations["s3os.plugin.halo.run/object-key"])
},
];
},
Expand Down
21 changes: 8 additions & 13 deletions console/src/views/S3Unlink.vue
Original file line number Diff line number Diff line change
@@ -1,13 +1,8 @@
<script setup lang="ts">
import { deleteApisS3OsHaloRunV1Alpha1AttachmentsByName } from "@/controller";
import type { Attachment } from "@/interface";
import {
VDropdownDivider,
VDropdownItem,
Toast,
Dialog,
} from "@halo-dev/components";
import { useQueryClient } from "@tanstack/vue-query";
import {deleteApisS3OsHaloRunV1Alpha1AttachmentsByName} from "@/controller";
import type {Attachment} from "@/interface";
import {Dialog, Toast, VDropdownDivider, VDropdownItem} from "@halo-dev/components";
import {useQueryClient} from "@tanstack/vue-query";
const props = defineProps<{
attachment: Attachment;
Expand All @@ -23,20 +18,20 @@ const handleUnlink = () => {
cancelText: "取消",
onConfirm: async () => {
try {
await deleteApisS3OsHaloRunV1Alpha1AttachmentsByName({ name: props.attachment.metadata.name });
await deleteApisS3OsHaloRunV1Alpha1AttachmentsByName({name: props.attachment.metadata.name});
Toast.success("解除关联成功");
} catch (e) {
console.error("Failed to delete attachment", e);
} finally {
queryClient.invalidateQueries({ queryKey: ["attachments"] });
queryClient.invalidateQueries({queryKey: ["attachments"]});
}
},
});
}
</script>
<template>
<div>
<VDropdownDivider />
<VDropdownDivider/>
<VDropdownItem type="danger" @click="handleUnlink">解除 S3 关联</VDropdownItem>
</div>
</template>
</template>
3 changes: 1 addition & 2 deletions src/main/java/run/halo/s3os/S3UnlinkController.java
Original file line number Diff line number Diff line change
@@ -1,10 +1,9 @@
package run.halo.s3os;

import lombok.RequiredArgsConstructor;
import org.springframework.web.bind.annotation.DeleteMapping;
import org.springframework.web.bind.annotation.PathVariable;
import org.springframework.web.bind.annotation.RestController;

import lombok.RequiredArgsConstructor;
import reactor.core.publisher.Mono;
import run.halo.app.core.extension.attachment.Attachment;
import run.halo.app.plugin.ApiVersion;
Expand Down
36 changes: 16 additions & 20 deletions src/main/java/run/halo/s3os/S3UnlinkServiceImpl.java
Original file line number Diff line number Diff line change
@@ -1,10 +1,9 @@
package run.halo.s3os;

import org.springframework.stereotype.Service;
import org.springframework.web.server.ServerWebInputException;

import lombok.RequiredArgsConstructor;
import lombok.extern.slf4j.Slf4j;
import org.springframework.stereotype.Service;
import org.springframework.web.server.ServerWebInputException;
import reactor.core.publisher.Mono;
import run.halo.app.core.extension.attachment.Attachment;
import run.halo.app.core.extension.attachment.Constant;
Expand All @@ -14,28 +13,25 @@
@Service
@RequiredArgsConstructor
@Slf4j
public class S3UnlinkServiceImpl implements S3UnlinkService{
public class S3UnlinkServiceImpl implements S3UnlinkService {
private final ReactiveExtensionClient client;
private final S3OsAttachmentHandler handler;

@Override
public Mono<Attachment> unlink(String name) {
return client.get(Attachment.class, name)
.flatMap((attachment) -> {
return client.get(Policy.class, attachment.getSpec().getPolicyName())
.doOnNext((policy) -> {
if(!handler.shouldHandle(policy)) {
throw new ServerWebInputException("The policy to which this attachment belongs is not managed by plugin-s3.");
}
}).thenReturn(attachment);
})
.flatMap(attachment -> {
attachment.getMetadata().getFinalizers().remove(Constant.FINALIZER_NAME);
return client.update(attachment);
})
.flatMap(attachment -> {
return client.delete(attachment);
});
.flatMap((attachment) -> client.get(Policy.class, attachment.getSpec().getPolicyName())
.doOnNext((policy) -> {
if (!handler.shouldHandle(policy)) {
throw new ServerWebInputException(
"This attachment policy is not managed by plugin-s3.");
}
}).thenReturn(attachment))
.flatMap(attachment -> {
attachment.getMetadata().getFinalizers().remove(Constant.FINALIZER_NAME);
return client.update(attachment);
})
.flatMap(client::delete);
}

}

0 comments on commit c4de5ba

Please sign in to comment.