feat: add supports for delete own posts in uc

Signed-off-by: Ryan Wang <i@ryanc.cc>
pull/6729/head
Ryan Wang 2024-09-29 17:42:10 +08:00
parent cd90771bb7
commit 944d0a5cb4
7 changed files with 185 additions and 1 deletions

View File

@ -15117,6 +15117,38 @@
]
}
},
"/apis/uc.api.content.halo.run/v1alpha1/posts/{name}/recycle": {
"delete": {
"description": "Move my post to recycle bin.",
"operationId": "RecycleMyPost",
"parameters": [
{
"description": "Post name",
"in": "path",
"name": "name",
"required": true,
"schema": {
"type": "string"
}
}
],
"responses": {
"default": {
"content": {
"*/*": {
"schema": {
"$ref": "#/components/schemas/Post"
}
}
},
"description": "default response"
}
},
"tags": [
"PostV1alpha1Uc"
]
}
},
"/apis/uc.api.content.halo.run/v1alpha1/posts/{name}/unpublish": {
"put": {
"description": "Unpublish my post.",

View File

@ -412,6 +412,38 @@
]
}
},
"/apis/uc.api.content.halo.run/v1alpha1/posts/{name}/recycle": {
"delete": {
"description": "Move my post to recycle bin.",
"operationId": "RecycleMyPost",
"parameters": [
{
"description": "Post name",
"in": "path",
"name": "name",
"required": true,
"schema": {
"type": "string"
}
}
],
"responses": {
"default": {
"content": {
"*/*": {
"schema": {
"$ref": "#/components/schemas/Post"
}
}
},
"description": "default response"
}
},
"tags": [
"PostV1alpha1Uc"
]
}
},
"/apis/uc.api.content.halo.run/v1alpha1/posts/{name}/unpublish": {
"put": {
"description": "Unpublish my post.",

View File

@ -270,6 +270,47 @@ export const PostV1alpha1UcApiAxiosParamCreator = function (configuration?: Conf
setSearchParams(localVarUrlObj, localVarQueryParameter);
let headersFromBaseOptions = baseOptions && baseOptions.headers ? baseOptions.headers : {};
localVarRequestOptions.headers = {...localVarHeaderParameter, ...headersFromBaseOptions, ...options.headers};
return {
url: toPathString(localVarUrlObj),
options: localVarRequestOptions,
};
},
/**
* Move my post to recycle bin.
* @param {string} name Post name
* @param {*} [options] Override http request option.
* @throws {RequiredError}
*/
recycleMyPost: async (name: string, options: RawAxiosRequestConfig = {}): Promise<RequestArgs> => {
// verify required parameter 'name' is not null or undefined
assertParamExists('recycleMyPost', 'name', name)
const localVarPath = `/apis/uc.api.content.halo.run/v1alpha1/posts/{name}/recycle`
.replace(`{${"name"}}`, encodeURIComponent(String(name)));
// use dummy base URL string because the URL constructor only accepts absolute URLs.
const localVarUrlObj = new URL(localVarPath, DUMMY_BASE_URL);
let baseOptions;
if (configuration) {
baseOptions = configuration.baseOptions;
}
const localVarRequestOptions = { method: 'DELETE', ...baseOptions, ...options};
const localVarHeaderParameter = {} as any;
const localVarQueryParameter = {} as any;
// authentication basicAuth required
// http basic authentication required
setBasicAuthToObject(localVarRequestOptions, configuration)
// authentication bearerAuth required
// http bearer authentication required
await setBearerAuthToObject(localVarHeaderParameter, configuration)
setSearchParams(localVarUrlObj, localVarQueryParameter);
let headersFromBaseOptions = baseOptions && baseOptions.headers ? baseOptions.headers : {};
localVarRequestOptions.headers = {...localVarHeaderParameter, ...headersFromBaseOptions, ...options.headers};
@ -488,6 +529,18 @@ export const PostV1alpha1UcApiFp = function(configuration?: Configuration) {
const localVarOperationServerBasePath = operationServerMap['PostV1alpha1UcApi.publishMyPost']?.[localVarOperationServerIndex]?.url;
return (axios, basePath) => createRequestFunction(localVarAxiosArgs, globalAxios, BASE_PATH, configuration)(axios, localVarOperationServerBasePath || basePath);
},
/**
* Move my post to recycle bin.
* @param {string} name Post name
* @param {*} [options] Override http request option.
* @throws {RequiredError}
*/
async recycleMyPost(name: string, options?: RawAxiosRequestConfig): Promise<(axios?: AxiosInstance, basePath?: string) => AxiosPromise<Post>> {
const localVarAxiosArgs = await localVarAxiosParamCreator.recycleMyPost(name, options);
const localVarOperationServerIndex = configuration?.serverIndex ?? 0;
const localVarOperationServerBasePath = operationServerMap['PostV1alpha1UcApi.recycleMyPost']?.[localVarOperationServerIndex]?.url;
return (axios, basePath) => createRequestFunction(localVarAxiosArgs, globalAxios, BASE_PATH, configuration)(axios, localVarOperationServerBasePath || basePath);
},
/**
* Unpublish my post.
* @param {string} name Post name
@ -581,6 +634,15 @@ export const PostV1alpha1UcApiFactory = function (configuration?: Configuration,
publishMyPost(requestParameters: PostV1alpha1UcApiPublishMyPostRequest, options?: RawAxiosRequestConfig): AxiosPromise<Post> {
return localVarFp.publishMyPost(requestParameters.name, options).then((request) => request(axios, basePath));
},
/**
* Move my post to recycle bin.
* @param {PostV1alpha1UcApiRecycleMyPostRequest} requestParameters Request parameters.
* @param {*} [options] Override http request option.
* @throws {RequiredError}
*/
recycleMyPost(requestParameters: PostV1alpha1UcApiRecycleMyPostRequest, options?: RawAxiosRequestConfig): AxiosPromise<Post> {
return localVarFp.recycleMyPost(requestParameters.name, options).then((request) => request(axios, basePath));
},
/**
* Unpublish my post.
* @param {PostV1alpha1UcApiUnpublishMyPostRequest} requestParameters Request parameters.
@ -737,6 +799,20 @@ export interface PostV1alpha1UcApiPublishMyPostRequest {
readonly name: string
}
/**
* Request parameters for recycleMyPost operation in PostV1alpha1UcApi.
* @export
* @interface PostV1alpha1UcApiRecycleMyPostRequest
*/
export interface PostV1alpha1UcApiRecycleMyPostRequest {
/**
* Post name
* @type {string}
* @memberof PostV1alpha1UcApiRecycleMyPost
*/
readonly name: string
}
/**
* Request parameters for unpublishMyPost operation in PostV1alpha1UcApi.
* @export
@ -855,6 +931,17 @@ export class PostV1alpha1UcApi extends BaseAPI {
return PostV1alpha1UcApiFp(this.configuration).publishMyPost(requestParameters.name, options).then((request) => request(this.axios, this.basePath));
}
/**
* Move my post to recycle bin.
* @param {PostV1alpha1UcApiRecycleMyPostRequest} requestParameters Request parameters.
* @param {*} [options] Override http request option.
* @throws {RequiredError}
* @memberof PostV1alpha1UcApi
*/
public recycleMyPost(requestParameters: PostV1alpha1UcApiRecycleMyPostRequest, options?: RawAxiosRequestConfig) {
return PostV1alpha1UcApiFp(this.configuration).recycleMyPost(requestParameters.name, options).then((request) => request(this.axios, this.basePath));
}
/**
* Unpublish my post.
* @param {PostV1alpha1UcApiUnpublishMyPostRequest} requestParameters Request parameters.

View File

@ -1790,6 +1790,9 @@ core:
cancel_publish:
description: Are you sure you want to cancel publishing?
title: Cancel publish
delete:
title: Delete post
description: This action will move the post to the recycle bin, where it will be managed by the site administrator.
publish_modal:
title: Publish post
setting_modal:

View File

@ -256,6 +256,9 @@ core:
cancel_publish:
title: 取消发布
description: 确定要取消发布吗?
delete:
title: 删除文章
description: 该操作会将文章放入回收站,后续由网站管理员进行管理。
post_editor:
title: 文章编辑
untitled: 未命名文章

View File

@ -1656,6 +1656,9 @@ core:
cancel_publish:
description: 確定要取消發布嗎?
title: 取消發布
delete:
title: 刪除文章
description: 該操作會將文章放入回收站,後續由網站管理員進行管理。
publish_modal:
title: 發布文章
setting_modal:

View File

@ -92,6 +92,25 @@ function handleUnpublish() {
},
});
}
function handleDelete() {
Dialog.warning({
title: t("core.uc_post.operations.delete.title"),
description: t("core.uc_post.operations.delete.description"),
confirmType: "danger",
confirmText: t("core.common.buttons.confirm"),
cancelText: t("core.common.buttons.cancel"),
async onConfirm() {
await ucApiClient.content.post.recycleMyPost({
name: props.post.post.metadata.name,
});
Toast.success(t("core.common.toast.delete_success"));
queryClient.invalidateQueries({ queryKey: ["my-posts"] });
},
});
}
</script>
<template>
@ -246,11 +265,16 @@ function handleUnpublish() {
{{ $t("core.common.buttons.edit") }}
</VDropdownItem>
<HasPermission v-if="!isPublished" :permissions="['uc:posts:publish']">
<VDropdownDivider />
<VDropdownItem type="danger" @click="handleUnpublish">
{{ $t("core.common.buttons.cancel_publish") }}
</VDropdownItem>
</HasPermission>
<HasPermission :permissions="['uc:posts:recycle']">
<VDropdownDivider />
<VDropdownItem type="danger" @click="handleDelete">
{{ $t("core.common.buttons.delete") }}
</VDropdownItem>
</HasPermission>
</template>
</VEntity>
</template>