Skip to content

Let's use AI to Earn!

feat: Access and delete works within the platform (#270)

Gaod5d2649d17ee
diff --git a/project/web/src/api/plat/publish.ts b/project/web/src/api/plat/publish.ts
index 36eec9ce..0297b1f9 100644
--- a/project/web/src/api/plat/publish.ts
+++ b/project/web/src/api/plat/publish.ts
@@ -71,6 +71,14 @@ export function deletePublishRecordApi(id: string) {
})
}
+// 删除平台的作品
+export function deletePlatWorkApi(accountId: string, dataId: string) {
+ return request({
+ url: `channel/${accountId}/post/${dataId}`,
+ method: 'DELETE',
+ })
+}
+
// 立即发布任务
export function nowPubTaskApi(id: string) {
return request({
diff --git a/project/web/src/api/plat/types/publish.types.ts b/project/web/src/api/plat/types/publish.types.ts
index 92fd9448..e254e7ff 100644
--- a/project/web/src/api/plat/types/publish.types.ts
+++ b/project/web/src/api/plat/types/publish.types.ts
@@ -43,6 +43,7 @@ export interface GetPublishListParams {
// 发布记录item数据
export interface PublishRecordItem {
+ option: any
userId: string
flowId: string
userTaskId: string
diff --git a/project/web/src/app/[lng]/accounts/components/CalendarTiming/CalendarTimingItem/components/RecordCore.tsx b/project/web/src/app/[lng]/accounts/components/CalendarTiming/CalendarTimingItem/components/RecordCore.tsx
index f69558e0..84151bed 100644
--- a/project/web/src/app/[lng]/accounts/components/CalendarTiming/CalendarTimingItem/components/RecordCore.tsx
+++ b/project/web/src/app/[lng]/accounts/components/CalendarTiming/CalendarTimingItem/components/RecordCore.tsx
@@ -30,7 +30,7 @@ import {
useState,
} from 'react'
import { useShallow } from 'zustand/react/shallow'
-import { deletePublishRecordApi, nowPubTaskApi } from '@/api/plat/publish'
+import { deletePlatWorkApi, deletePublishRecordApi, nowPubTaskApi } from '@/api/plat/publish'
import {
PublishStatus,
} from '@/api/plat/types/publish.types'
@@ -115,36 +115,88 @@ const RecordCore = memo(
const [nowPubLoading, setNowPubLoading] = useState(false)
const dropdownItems: MenuProps['items'] = useMemo(() => {
+ const dropdownItemsArr: MenuProps['items'] = []
+
if (publishRecord.workLink) {
- return [
- {
- key: '2',
- label: t('buttons.copyLink'),
- onClick: async () => {
- await navigator.clipboard.writeText(
- publishRecord?.workLink ?? '',
- )
- },
+ dropdownItemsArr.push({
+ key: '2',
+ label: t('buttons.copyLink'),
+ onClick: async () => {
+ await navigator.clipboard.writeText(
+ publishRecord?.workLink ?? '',
+ )
},
- ]
+ })
}
- if (publishRecord.status === PublishStatus.UNPUBLISH) {
- return [
- {
- key: '3',
- danger: true,
- label: t('buttons.delete'),
- onClick: async () => {
- setPopoverOpen(false)
- setListLoading(true)
- await deletePublishRecordApi(publishRecord.id)
- getPubRecord()
- },
+ /**
+ * 删除按钮显示逻辑:
+ * 1. 未发布的、发布失败的,直接显示删除按钮。
+ * 2. 已发布的,除了小红书、抖音、视频号、ins、tiktok之外,其他平台均显示删除按钮。
+ * 注意:Facebook 只有post类型显示删除按钮。
+ */
+ const shouldShowDelete = (() => {
+ // 规则1:未发布或发布失败的,显示删除按钮
+ if (
+ publishRecord.status === PublishStatus.UNPUBLISH
+ || publishRecord.status === PublishStatus.FAIL
+ ) {
+ return true
+ }
+
+ // 规则2:已发布的,根据平台判断
+ if (publishRecord.status === PublishStatus.RELEASED) {
+ // 不允许删除的平台列表
+ const noDeletablePlats = [
+ PlatType.Xhs, // 小红书
+ PlatType.Douyin, // 抖音
+ PlatType.WxSph, // 视频号
+ PlatType.Instagram, // ins
+ PlatType.Tiktok, // tiktok
+ ]
+
+ // 如果是不允许删除的平台,不显示删除按钮
+ if (noDeletablePlats.includes(publishRecord.accountType)) {
+ return false
+ }
+
+ // Facebook特殊处理:post类型不显示删除按钮
+ if (publishRecord.accountType === PlatType.Facebook) {
+ // 如果是post类型,不显示删除按钮
+ return publishRecord.option.facebook.content_category === 'post'
+ }
+
+ // 其他已发布的平台,显示删除按钮
+ return true
+ }
+
+ // 发布中的状态,不显示删除按钮
+ return false
+ })()
+
+ if (shouldShowDelete) {
+ dropdownItemsArr.push({
+ key: '3',
+ danger: true,
+ label: t('buttons.delete'),
+ onClick: async () => {
+ setPopoverOpen(false)
+ setListLoading(true)
+ if (publishRecord.status === PublishStatus.RELEASED) {
+ const res = await deletePlatWorkApi(publishRecord.accountId!, publishRecord.dataId)
+ if (!res) {
+ setListLoading(false)
+ return
+ }
+ }
+ await deletePublishRecordApi(publishRecord.id)
+ getPubRecord()
},
- ]
+ })
}
- }, [publishRecord])
+
+ return dropdownItemsArr
+ }, [publishRecord, t, setListLoading, getPubRecord])
const days = useMemo(() => {
return getDays(publishRecord.publishTime)
diff --git a/project/web/src/components/PublishDialog/index.tsx b/project/web/src/components/PublishDialog/index.tsx
index d3ce3b4f..81c4dac7 100644
--- a/project/web/src/components/PublishDialog/index.tsx
+++ b/project/web/src/components/PublishDialog/index.tsx
@@ -550,7 +550,7 @@ const PublishDialog = memo(
const pubClick = useCallback(async () => {
setCreateLoading(true)
const publishTime = getUtcDays(
- pubTime || getDays().add(6, 'minute'),
+ pubTime || getDays().add(5, 'second'),
).format()
for (const item of pubListChoosed) {
diff --git a/project/web/src/components/PublishDialog/usePublishDialog.ts b/project/web/src/components/PublishDialog/usePublishDialog.ts
index 57bfd66b..cd629aea 100644
--- a/project/web/src/components/PublishDialog/usePublishDialog.ts
+++ b/project/web/src/components/PublishDialog/usePublishDialog.ts
@@ -26,7 +26,7 @@ export interface IPublishDialogStore {
// 错误提示
errParamsMap?: ErrPubParamsMapType
warningParamsMap?: ErrPubParamsMapType
- // 发布时间
+ // 发布时间,为空则为立即发布
pubTime?: string
openLeft: boolean
}