feat(schedule-tasks): support auto-publish via media accounts
Replace the legacy target_platform string on schedule tasks with a workspace-aware auto-publish payload (auto_publish + publish_account_ids JSONB + cover_asset_url + cover_image_asset_id) and migrate the schema, sqlc queries, generated models, domain struct, ScheduleTaskService DTOs, and dispatch worker to round-trip the new fields. PromptRuleGeneration gains a WithPublishJobService hook so executeGeneration can enqueue an auto-publish job once the article is ready, and worker-generate wires the publish-job service in. On the admin-web side, extract PublishArticleModal's account-card builders into a shared publish-account-cards module, rebuild GenerateTaskDrawer's schedule mode around account selection plus a CoverPickerModal, and surface the new "auto publish" column on ScheduleTaskTab. Shared types and i18n strings cover the new fields. Co-Authored-By: Claude Opus 4.7 (1M context) <noreply@anthropic.com>
This commit is contained in:
@@ -3,20 +3,20 @@ import { PlusOutlined } from "@ant-design/icons-vue";
|
||||
import { useMutation, useQuery, useQueryClient } from "@tanstack/vue-query";
|
||||
import { message } from "ant-design-vue";
|
||||
import type { PromptRuleSimple, ScheduleTask } from "@geo/shared-types";
|
||||
import { computed, onBeforeUnmount, reactive, ref, watch } from "vue";
|
||||
import { computed, reactive, ref, watch } from "vue";
|
||||
import { useI18n } from "vue-i18n";
|
||||
|
||||
import CoverPickerModal from "@/components/CoverPickerModal.vue";
|
||||
import PromptRuleModal from "@/components/PromptRuleModal.vue";
|
||||
import PublishPlatformSelector from "@/components/PublishPlatformSelector.vue";
|
||||
import { generateApi, mediaApi, promptRulesApi, schedulesApi, tenantAccountsApi } from "@/lib/api";
|
||||
import { generateApi, imagesApi, mediaApi, promptRulesApi, resolveApiURL, schedulesApi, tenantAccountsApi } from "@/lib/api";
|
||||
import { coverUploadRequired, deriveCoverFileName } from "@/lib/cover-requirements";
|
||||
import { formatError } from "@/lib/errors";
|
||||
import { IMAGE_UPLOAD_ACCEPT, useImageUploadProgress, validateImageUploadFile } from "@/lib/image-webp";
|
||||
import {
|
||||
buildPublishPlatformOptions,
|
||||
normalizePublishPlatformIds,
|
||||
parseTargetPlatforms,
|
||||
serializeTargetPlatforms,
|
||||
} from "@/lib/publish-platforms";
|
||||
buildPublishAccountCards,
|
||||
buildPublishPlatformMap,
|
||||
publishStatusShortLabel,
|
||||
type PublishAccountCard,
|
||||
} from "@/lib/publish-account-cards";
|
||||
|
||||
const props = defineProps<{
|
||||
open: boolean;
|
||||
@@ -30,17 +30,19 @@ const emit = defineEmits<{
|
||||
|
||||
const queryClient = useQueryClient();
|
||||
const { t } = useI18n();
|
||||
const imageUploadProgress = useImageUploadProgress();
|
||||
|
||||
const promptDrawerOpen = ref(false);
|
||||
const coverPreviewUrl = ref("");
|
||||
const coverFileName = ref("");
|
||||
const coverPickerOpen = ref(false);
|
||||
|
||||
const form = reactive({
|
||||
name: "",
|
||||
promptRuleId: undefined as number | undefined,
|
||||
platformIds: [] as string[],
|
||||
coverEnabled: true,
|
||||
autoPublish: false,
|
||||
publishAccountIds: [] as string[],
|
||||
coverEnabled: false,
|
||||
coverAssetUrl: "",
|
||||
coverFileName: "",
|
||||
coverImageAssetId: null as number | null,
|
||||
enableWebSearch: false,
|
||||
generateCount: 1,
|
||||
scheduleTime: "08:00:00",
|
||||
@@ -48,31 +50,25 @@ const form = reactive({
|
||||
|
||||
const isSchedule = computed(() => props.mode === "schedule");
|
||||
|
||||
const rulesQuery = useQuery({
|
||||
queryKey: ["promptRules", "simple"],
|
||||
queryFn: () => promptRulesApi.listSimple(),
|
||||
});
|
||||
|
||||
const schedulePublishQueryEnabled = computed(() => props.open && isSchedule.value);
|
||||
|
||||
const platformsQuery = useQuery({
|
||||
queryKey: ["media", "platforms", "task-drawer"],
|
||||
enabled: computed(() => props.open),
|
||||
queryKey: ["media", "platforms", "schedule-task-drawer"],
|
||||
enabled: schedulePublishQueryEnabled,
|
||||
queryFn: () => mediaApi.platforms(),
|
||||
});
|
||||
|
||||
const accountsQuery = useQuery({
|
||||
queryKey: ["tenant", "desktop-accounts", "task-drawer"],
|
||||
enabled: computed(() => props.open),
|
||||
queryKey: ["tenant", "desktop-accounts", "schedule-task-drawer"],
|
||||
enabled: schedulePublishQueryEnabled,
|
||||
queryFn: () => tenantAccountsApi.list(),
|
||||
});
|
||||
|
||||
const allPlatforms = computed(() =>
|
||||
buildPublishPlatformOptions(platformsQuery.data.value ?? [], accountsQuery.data.value),
|
||||
);
|
||||
|
||||
const platformsLoading = computed(
|
||||
() => platformsQuery.isPending.value || accountsQuery.isPending.value,
|
||||
);
|
||||
|
||||
const rulesQuery = useQuery({
|
||||
queryKey: ["promptRules", "simple"],
|
||||
queryFn: () => promptRulesApi.listSimple(),
|
||||
});
|
||||
|
||||
const promptOptions = computed(() =>
|
||||
(rulesQuery.data.value ?? []).map((rule: PromptRuleSimple) => ({
|
||||
label: rule.name,
|
||||
@@ -80,6 +76,40 @@ const promptOptions = computed(() =>
|
||||
})),
|
||||
);
|
||||
|
||||
const platformMap = computed(() => buildPublishPlatformMap(platformsQuery.data.value ?? []));
|
||||
|
||||
const schedulePublishAccounts = computed<PublishAccountCard[]>(() =>
|
||||
buildPublishAccountCards(accountsQuery.data.value ?? [], platformMap.value),
|
||||
);
|
||||
|
||||
const schedulePublishLoading = computed(
|
||||
() => platformsQuery.isPending.value || accountsQuery.isPending.value,
|
||||
);
|
||||
|
||||
const selectedSchedulePublishPlatformIds = computed(() => {
|
||||
const selected = new Set(form.publishAccountIds);
|
||||
return Array.from(
|
||||
new Set(
|
||||
schedulePublishAccounts.value
|
||||
.filter((account) => selected.has(account.id))
|
||||
.map((account) => account.platformId),
|
||||
),
|
||||
);
|
||||
});
|
||||
|
||||
const scheduleCoverRequired = computed(() => coverUploadRequired(selectedSchedulePublishPlatformIds.value));
|
||||
const effectiveScheduleCoverEnabled = computed(() => scheduleCoverRequired.value || form.coverEnabled);
|
||||
|
||||
watch(
|
||||
scheduleCoverRequired,
|
||||
(required) => {
|
||||
if (required) {
|
||||
form.coverEnabled = true;
|
||||
}
|
||||
},
|
||||
{ immediate: true },
|
||||
);
|
||||
|
||||
const drawerTitle = computed(() => {
|
||||
if (isSchedule.value) {
|
||||
return props.task?.id ? t("custom.schedule.editTitle") : t("custom.schedule.createTitle");
|
||||
@@ -99,16 +129,10 @@ watch(
|
||||
(open) => {
|
||||
if (open) {
|
||||
hydrateForm();
|
||||
return;
|
||||
}
|
||||
resetCoverState();
|
||||
},
|
||||
);
|
||||
|
||||
onBeforeUnmount(() => {
|
||||
resetCoverState();
|
||||
});
|
||||
|
||||
const createScheduleMutation = useMutation({
|
||||
mutationFn: () =>
|
||||
schedulesApi.create(buildSchedulePayload()),
|
||||
@@ -151,94 +175,101 @@ const submitLoading = computed(
|
||||
updateScheduleMutation.isPending.value ||
|
||||
instantGenerateMutation.isPending.value,
|
||||
);
|
||||
const imageUploadBusy = computed(() => imageUploadProgress.visible);
|
||||
|
||||
function hydrateForm(): void {
|
||||
form.name = props.task?.name ?? "";
|
||||
form.promptRuleId = props.task?.prompt_rule_id ?? undefined;
|
||||
form.platformIds = parseTargetPlatforms(props.task?.target_platform);
|
||||
form.coverEnabled = true;
|
||||
form.autoPublish = isSchedule.value ? Boolean(props.task?.auto_publish) : false;
|
||||
form.publishAccountIds = isSchedule.value ? [...(props.task?.publish_account_ids ?? [])] : [];
|
||||
form.coverAssetUrl = isSchedule.value ? resolveApiURL(props.task?.cover_asset_url) : "";
|
||||
form.coverFileName = deriveCoverFileName(form.coverAssetUrl);
|
||||
form.coverImageAssetId = isSchedule.value ? props.task?.cover_image_asset_id ?? null : null;
|
||||
form.coverEnabled = Boolean(form.coverAssetUrl);
|
||||
form.enableWebSearch = props.task?.enable_web_search ?? false;
|
||||
form.generateCount = props.task?.generate_count ?? 1;
|
||||
form.scheduleTime = parseCronToDailyTime(props.task?.cron_expr);
|
||||
resetCoverState();
|
||||
}
|
||||
|
||||
function getSelectedPlatformIds(): string[] {
|
||||
return normalizePublishPlatformIds(form.platformIds);
|
||||
}
|
||||
|
||||
function buildSchedulePayload() {
|
||||
const coverEnabled = form.autoPublish && effectiveScheduleCoverEnabled.value;
|
||||
const coverAssetUrl = coverEnabled ? form.coverAssetUrl.trim() : "";
|
||||
|
||||
return {
|
||||
name: form.name.trim(),
|
||||
prompt_rule_id: form.promptRuleId!,
|
||||
cron_expr: buildDailyCron(form.scheduleTime),
|
||||
target_platform: serializeTargetPlatforms(getSelectedPlatformIds()),
|
||||
auto_publish: form.autoPublish,
|
||||
publish_account_ids: form.autoPublish ? form.publishAccountIds : [],
|
||||
cover_asset_url: coverAssetUrl || null,
|
||||
cover_image_asset_id: coverAssetUrl ? form.coverImageAssetId : null,
|
||||
enable_web_search: form.enableWebSearch,
|
||||
generate_count: form.generateCount,
|
||||
};
|
||||
}
|
||||
|
||||
function buildInstantPayload() {
|
||||
const platformIds = getSelectedPlatformIds();
|
||||
|
||||
return {
|
||||
prompt_rule_id: form.promptRuleId!,
|
||||
target_platform: serializeTargetPlatforms(platformIds),
|
||||
extra_params: {
|
||||
task_name: form.name.trim(),
|
||||
generation_mode: "instant",
|
||||
enable_web_search: form.enableWebSearch,
|
||||
generate_count: form.generateCount,
|
||||
target_platforms: platformIds,
|
||||
cover_file_name: coverFileName.value || null,
|
||||
},
|
||||
};
|
||||
}
|
||||
|
||||
function resetCoverState(): void {
|
||||
if (coverPreviewUrl.value) {
|
||||
URL.revokeObjectURL(coverPreviewUrl.value);
|
||||
}
|
||||
coverPreviewUrl.value = "";
|
||||
coverFileName.value = "";
|
||||
}
|
||||
|
||||
function handleCoverChange(event: Event): void {
|
||||
if (imageUploadBusy.value) {
|
||||
(event.target as HTMLInputElement).value = "";
|
||||
return;
|
||||
}
|
||||
|
||||
const input = event.target as HTMLInputElement;
|
||||
const file = input.files?.[0];
|
||||
input.value = "";
|
||||
|
||||
if (!file) {
|
||||
return;
|
||||
}
|
||||
|
||||
try {
|
||||
validateImageUploadFile(file);
|
||||
} catch (error) {
|
||||
message.warning(formatError(error));
|
||||
return;
|
||||
}
|
||||
|
||||
if (coverPreviewUrl.value) {
|
||||
URL.revokeObjectURL(coverPreviewUrl.value);
|
||||
}
|
||||
|
||||
coverFileName.value = file.name;
|
||||
coverPreviewUrl.value = URL.createObjectURL(file);
|
||||
}
|
||||
|
||||
function handlePromptSaved(ruleId: number): void {
|
||||
form.promptRuleId = ruleId;
|
||||
promptDrawerOpen.value = false;
|
||||
void queryClient.invalidateQueries({ queryKey: ["promptRules", "simple"] });
|
||||
}
|
||||
|
||||
function toggleSchedulePublishAccount(account: PublishAccountCard): void {
|
||||
if (!account.selectable) {
|
||||
return;
|
||||
}
|
||||
if (form.publishAccountIds.includes(account.id)) {
|
||||
form.publishAccountIds = form.publishAccountIds.filter((id) => id !== account.id);
|
||||
return;
|
||||
}
|
||||
form.publishAccountIds = [...form.publishAccountIds, account.id];
|
||||
}
|
||||
|
||||
function isSchedulePublishAccountSelected(accountId: string): boolean {
|
||||
return form.publishAccountIds.includes(accountId);
|
||||
}
|
||||
|
||||
async function uploadScheduleCover(file: File): Promise<{ url: string; fileName: string; assetId?: number | null }> {
|
||||
const uploaded = await imagesApi.upload(file);
|
||||
return {
|
||||
url: uploaded.url,
|
||||
fileName: uploaded.name,
|
||||
assetId: uploaded.id,
|
||||
};
|
||||
}
|
||||
|
||||
function handleScheduleCoverPicked(payload: { url: string; fileName: string; assetId?: number | null }): void {
|
||||
form.coverAssetUrl = payload.url;
|
||||
form.coverFileName = payload.fileName;
|
||||
form.coverImageAssetId = payload.assetId ?? null;
|
||||
form.coverEnabled = true;
|
||||
}
|
||||
|
||||
function handleRemoveScheduleCover(): void {
|
||||
form.coverAssetUrl = "";
|
||||
form.coverFileName = "";
|
||||
form.coverImageAssetId = null;
|
||||
}
|
||||
|
||||
function handleScheduleCoverToggle(checked: boolean): void {
|
||||
if (scheduleCoverRequired.value) {
|
||||
form.coverEnabled = true;
|
||||
return;
|
||||
}
|
||||
form.coverEnabled = checked;
|
||||
}
|
||||
|
||||
function validateForm(): boolean {
|
||||
if (!form.name.trim()) {
|
||||
message.warning(t("custom.messages.missingTaskName"));
|
||||
@@ -260,6 +291,17 @@ function validateForm(): boolean {
|
||||
return false;
|
||||
}
|
||||
|
||||
if (isSchedule.value && form.autoPublish) {
|
||||
if (form.publishAccountIds.length === 0) {
|
||||
message.warning(t("custom.messages.missingPublishAccounts"));
|
||||
return false;
|
||||
}
|
||||
if (scheduleCoverRequired.value && !form.coverAssetUrl.trim()) {
|
||||
message.warning(t("custom.messages.missingScheduleCover"));
|
||||
return false;
|
||||
}
|
||||
}
|
||||
|
||||
return true;
|
||||
}
|
||||
|
||||
@@ -368,48 +410,123 @@ function padTime(value: string): string {
|
||||
</div>
|
||||
</div>
|
||||
|
||||
<div class="generate-task-drawer__field">
|
||||
<label class="generate-task-drawer__label">{{ t("custom.task.platforms") }}:</label>
|
||||
<p class="generate-task-drawer__hint">{{ t("custom.task.platformsHint") }}</p>
|
||||
<a-skeleton
|
||||
v-if="platformsLoading"
|
||||
active
|
||||
:title="false"
|
||||
:paragraph="{ rows: 4 }"
|
||||
/>
|
||||
<PublishPlatformSelector
|
||||
v-else
|
||||
v-model="form.platformIds"
|
||||
:platforms="allPlatforms"
|
||||
/>
|
||||
</section>
|
||||
|
||||
<section v-if="isSchedule" class="generate-task-drawer__panel generate-task-drawer__panel--bordered">
|
||||
<div class="generate-task-drawer__section-head">
|
||||
<div class="generate-task-drawer__section-marker"></div>
|
||||
<h3>{{ t("custom.task.publishSection") }}</h3>
|
||||
</div>
|
||||
|
||||
<div class="generate-task-drawer__field">
|
||||
<label class="generate-task-drawer__label">{{ t("custom.task.cover") }}:</label>
|
||||
<p class="generate-task-drawer__hint">{{ t("custom.task.coverHint") }}</p>
|
||||
<div class="generate-task-drawer__field generate-task-drawer__field--inline">
|
||||
<div>
|
||||
<label class="generate-task-drawer__label">{{ t("custom.task.autoPublish") }}:</label>
|
||||
<p class="generate-task-drawer__hint generate-task-drawer__hint--compact">
|
||||
{{ t("custom.task.autoPublishHint") }}
|
||||
</p>
|
||||
</div>
|
||||
<a-switch v-model:checked="form.autoPublish" />
|
||||
</div>
|
||||
|
||||
<label
|
||||
class="generate-task-drawer__cover"
|
||||
:class="{ 'generate-task-drawer__cover--disabled': !form.coverEnabled || imageUploadBusy }"
|
||||
>
|
||||
<input
|
||||
type="file"
|
||||
:accept="IMAGE_UPLOAD_ACCEPT"
|
||||
hidden
|
||||
:disabled="!form.coverEnabled || imageUploadBusy"
|
||||
@change="handleCoverChange"
|
||||
<template v-if="form.autoPublish">
|
||||
<div class="generate-task-drawer__field">
|
||||
<label class="generate-task-drawer__label generate-task-drawer__label--required">
|
||||
{{ t("custom.task.publishAccounts") }}:
|
||||
</label>
|
||||
<p class="generate-task-drawer__hint">{{ t("custom.task.publishAccountsHint") }}</p>
|
||||
|
||||
<a-skeleton
|
||||
v-if="schedulePublishLoading"
|
||||
active
|
||||
:title="false"
|
||||
:paragraph="{ rows: 4 }"
|
||||
/>
|
||||
<div v-else-if="schedulePublishAccounts.length" class="generate-task-drawer__account-grid">
|
||||
<button
|
||||
v-for="account in schedulePublishAccounts"
|
||||
:key="account.id"
|
||||
type="button"
|
||||
class="generate-task-drawer__account"
|
||||
:class="{
|
||||
'generate-task-drawer__account--active': isSchedulePublishAccountSelected(account.id),
|
||||
'generate-task-drawer__account--disabled': !account.selectable,
|
||||
}"
|
||||
@click="toggleSchedulePublishAccount(account)"
|
||||
>
|
||||
<span class="generate-task-drawer__account-check">
|
||||
<span v-if="isSchedulePublishAccountSelected(account.id)"></span>
|
||||
</span>
|
||||
<span class="generate-task-drawer__account-logo" :style="{ '--account-accent': account.platformAccent }">
|
||||
<img
|
||||
v-if="account.platformLogoUrl"
|
||||
:src="account.platformLogoUrl"
|
||||
:alt="account.platformName"
|
||||
referrerpolicy="no-referrer"
|
||||
/>
|
||||
<span v-else>{{ account.platformShortName }}</span>
|
||||
</span>
|
||||
<span class="generate-task-drawer__account-copy">
|
||||
<strong>{{ account.displayName }}</strong>
|
||||
<small>{{ account.platformName }} · {{ account.platformUid }}</small>
|
||||
</span>
|
||||
<a-tooltip :title="account.statusText" placement="top">
|
||||
<span
|
||||
class="generate-task-drawer__account-status"
|
||||
:class="`generate-task-drawer__account-status--${account.publishState}`"
|
||||
>
|
||||
{{ publishStatusShortLabel(account.publishState) }}
|
||||
</span>
|
||||
</a-tooltip>
|
||||
</button>
|
||||
</div>
|
||||
<div v-else class="generate-task-drawer__empty">
|
||||
<strong>{{ t("custom.task.publishAccountEmptyTitle") }}</strong>
|
||||
<p>{{ t("custom.task.publishAccountEmptyHint") }}</p>
|
||||
</div>
|
||||
</div>
|
||||
|
||||
<template v-if="coverPreviewUrl">
|
||||
<img :src="coverPreviewUrl" alt="cover preview" />
|
||||
</template>
|
||||
<template v-else>
|
||||
<span class="generate-task-drawer__cover-plus">+</span>
|
||||
<strong>{{ t("custom.task.coverUpload") }}</strong>
|
||||
<small>{{ coverFileName || t("custom.task.coverUploadHint") }}</small>
|
||||
</template>
|
||||
</label>
|
||||
</div>
|
||||
<div class="generate-task-drawer__field">
|
||||
<div class="generate-task-drawer__cover-head">
|
||||
<label
|
||||
class="generate-task-drawer__label"
|
||||
:class="{ 'generate-task-drawer__label--required': scheduleCoverRequired }"
|
||||
>
|
||||
{{ t("custom.task.cover") }}:
|
||||
</label>
|
||||
<a-switch
|
||||
:checked="effectiveScheduleCoverEnabled"
|
||||
:disabled="scheduleCoverRequired"
|
||||
@change="handleScheduleCoverToggle"
|
||||
/>
|
||||
</div>
|
||||
<p class="generate-task-drawer__hint">
|
||||
{{ scheduleCoverRequired ? t("custom.task.scheduleCoverRequiredHint") : t("custom.task.scheduleCoverHint") }}
|
||||
</p>
|
||||
|
||||
<div v-if="effectiveScheduleCoverEnabled" class="generate-task-drawer__cover-row">
|
||||
<button type="button" class="generate-task-drawer__cover" @click="coverPickerOpen = true">
|
||||
<template v-if="form.coverAssetUrl">
|
||||
<img :src="form.coverAssetUrl" alt="cover preview" />
|
||||
</template>
|
||||
<template v-else>
|
||||
<span class="generate-task-drawer__cover-plus">+</span>
|
||||
<strong>{{ t("custom.task.coverUpload") }}</strong>
|
||||
<small>{{ t("custom.task.scheduleCoverUploadHint") }}</small>
|
||||
</template>
|
||||
</button>
|
||||
|
||||
<div v-if="form.coverAssetUrl" class="generate-task-drawer__cover-meta">
|
||||
<strong>{{ form.coverFileName || t("custom.task.cover") }}</strong>
|
||||
<a-button size="small" @click="coverPickerOpen = true">
|
||||
{{ t("article.editor.coverReplace") }}
|
||||
</a-button>
|
||||
<a-button size="small" danger @click="handleRemoveScheduleCover">
|
||||
{{ t("article.editor.coverRemove") }}
|
||||
</a-button>
|
||||
</div>
|
||||
</div>
|
||||
</div>
|
||||
</template>
|
||||
</section>
|
||||
|
||||
<section class="generate-task-drawer__panel generate-task-drawer__panel--bordered">
|
||||
@@ -462,6 +579,17 @@ function padTime(value: string): string {
|
||||
</template>
|
||||
|
||||
<PromptRuleModal v-model:open="promptDrawerOpen" @saved="handlePromptSaved" />
|
||||
|
||||
<CoverPickerModal
|
||||
v-model:open="coverPickerOpen"
|
||||
:article-id="null"
|
||||
:platform-ids="selectedSchedulePublishPlatformIds"
|
||||
:current-url="form.coverAssetUrl"
|
||||
:current-file-name="form.coverFileName"
|
||||
:current-asset-id="form.coverImageAssetId"
|
||||
:upload-handler="uploadScheduleCover"
|
||||
@confirmed="handleScheduleCoverPicked"
|
||||
/>
|
||||
</a-drawer>
|
||||
</template>
|
||||
|
||||
@@ -581,6 +709,179 @@ function padTime(value: string): string {
|
||||
color: #355dff;
|
||||
}
|
||||
|
||||
.generate-task-drawer__account-grid {
|
||||
display: grid;
|
||||
grid-template-columns: repeat(auto-fit, minmax(260px, 1fr));
|
||||
gap: 12px;
|
||||
}
|
||||
|
||||
.generate-task-drawer__account {
|
||||
display: grid;
|
||||
grid-template-columns: 20px 36px minmax(0, 1fr);
|
||||
gap: 12px;
|
||||
align-items: center;
|
||||
min-height: 76px;
|
||||
padding: 12px 14px;
|
||||
border: 1px solid #e1e8f2;
|
||||
border-radius: 8px;
|
||||
background: #fff;
|
||||
text-align: left;
|
||||
cursor: pointer;
|
||||
transition: border-color 0.2s ease, background 0.2s ease, box-shadow 0.2s ease;
|
||||
}
|
||||
|
||||
.generate-task-drawer__account:hover {
|
||||
border-color: #b7c7ec;
|
||||
background: #fbfdff;
|
||||
}
|
||||
|
||||
.generate-task-drawer__account--active {
|
||||
border-color: #355dff;
|
||||
background: #f4f7ff;
|
||||
box-shadow: 0 4px 12px rgba(53, 93, 255, 0.08);
|
||||
}
|
||||
|
||||
.generate-task-drawer__account--disabled {
|
||||
cursor: not-allowed;
|
||||
opacity: 0.55;
|
||||
}
|
||||
|
||||
.generate-task-drawer__account-check {
|
||||
display: inline-flex;
|
||||
align-items: center;
|
||||
justify-content: center;
|
||||
width: 18px;
|
||||
height: 18px;
|
||||
border: 1px solid #d0d7e5;
|
||||
border-radius: 4px;
|
||||
background: #fff;
|
||||
}
|
||||
|
||||
.generate-task-drawer__account--active .generate-task-drawer__account-check {
|
||||
border-color: #355dff;
|
||||
background: #355dff;
|
||||
}
|
||||
|
||||
.generate-task-drawer__account-check span {
|
||||
width: 6px;
|
||||
height: 6px;
|
||||
border-radius: 1px;
|
||||
background: #fff;
|
||||
}
|
||||
|
||||
.generate-task-drawer__account-logo {
|
||||
display: inline-flex;
|
||||
align-items: center;
|
||||
justify-content: center;
|
||||
width: 36px;
|
||||
height: 36px;
|
||||
border-radius: 8px;
|
||||
border: 1px solid #e4e9f2;
|
||||
background: #fff;
|
||||
color: var(--account-accent);
|
||||
font-size: 12px;
|
||||
font-weight: 800;
|
||||
overflow: hidden;
|
||||
}
|
||||
|
||||
.generate-task-drawer__account-logo img {
|
||||
width: 24px;
|
||||
height: 24px;
|
||||
object-fit: contain;
|
||||
}
|
||||
|
||||
.generate-task-drawer__account-logo span {
|
||||
display: inline-flex;
|
||||
align-items: center;
|
||||
justify-content: center;
|
||||
width: 100%;
|
||||
height: 100%;
|
||||
background: color-mix(in srgb, var(--account-accent) 10%, #ffffff);
|
||||
}
|
||||
|
||||
.generate-task-drawer__account-copy {
|
||||
display: flex;
|
||||
min-width: 0;
|
||||
flex-direction: column;
|
||||
gap: 4px;
|
||||
}
|
||||
|
||||
.generate-task-drawer__account-copy strong,
|
||||
.generate-task-drawer__cover-meta strong {
|
||||
overflow: hidden;
|
||||
color: #1f2937;
|
||||
font-size: 14px;
|
||||
font-weight: 700;
|
||||
text-overflow: ellipsis;
|
||||
white-space: nowrap;
|
||||
}
|
||||
|
||||
.generate-task-drawer__account-copy small,
|
||||
.generate-task-drawer__account-status {
|
||||
overflow: hidden;
|
||||
color: #667085;
|
||||
font-size: 12px;
|
||||
line-height: 1.4;
|
||||
text-overflow: ellipsis;
|
||||
white-space: nowrap;
|
||||
}
|
||||
|
||||
.generate-task-drawer__account-status {
|
||||
grid-column: 3;
|
||||
color: #355dff;
|
||||
}
|
||||
|
||||
.generate-task-drawer__account-status--immediate {
|
||||
color: #039855;
|
||||
}
|
||||
|
||||
.generate-task-drawer__account-status--queued {
|
||||
color: #dc6803;
|
||||
}
|
||||
|
||||
.generate-task-drawer__account-status--unavailable {
|
||||
color: #d92d20;
|
||||
}
|
||||
|
||||
.generate-task-drawer__cover-head {
|
||||
display: flex;
|
||||
align-items: center;
|
||||
justify-content: space-between;
|
||||
gap: 12px;
|
||||
}
|
||||
|
||||
.generate-task-drawer__cover-head .generate-task-drawer__label {
|
||||
margin-bottom: 0;
|
||||
}
|
||||
|
||||
.generate-task-drawer__empty {
|
||||
padding: 18px 20px;
|
||||
border: 1px dashed #cfd9e8;
|
||||
border-radius: 8px;
|
||||
background: #fbfcff;
|
||||
}
|
||||
|
||||
.generate-task-drawer__empty strong {
|
||||
display: block;
|
||||
color: #1f2937;
|
||||
font-size: 15px;
|
||||
font-weight: 700;
|
||||
}
|
||||
|
||||
.generate-task-drawer__empty p {
|
||||
margin: 6px 0 0;
|
||||
color: #667085;
|
||||
font-size: 13px;
|
||||
line-height: 1.7;
|
||||
}
|
||||
|
||||
.generate-task-drawer__cover-row {
|
||||
display: flex;
|
||||
align-items: center;
|
||||
gap: 16px;
|
||||
flex-wrap: wrap;
|
||||
}
|
||||
|
||||
.generate-task-drawer__cover {
|
||||
display: flex;
|
||||
flex-direction: column;
|
||||
@@ -589,16 +890,20 @@ function padTime(value: string): string {
|
||||
gap: 8px;
|
||||
width: 228px;
|
||||
min-height: 172px;
|
||||
padding: 0;
|
||||
border: 1px dashed #cfd9e8;
|
||||
border-radius: 20px;
|
||||
background:
|
||||
radial-gradient(circle at top, rgba(53, 93, 255, 0.08), transparent 48%),
|
||||
#fbfcff;
|
||||
border-radius: 8px;
|
||||
background: #fbfcff;
|
||||
color: #1f2937;
|
||||
cursor: pointer;
|
||||
overflow: hidden;
|
||||
}
|
||||
|
||||
.generate-task-drawer__cover:hover {
|
||||
border-color: #9db7ff;
|
||||
background: #f7faff;
|
||||
}
|
||||
|
||||
.generate-task-drawer__cover img {
|
||||
width: 100%;
|
||||
height: 172px;
|
||||
@@ -615,11 +920,6 @@ function padTime(value: string): string {
|
||||
font-size: 13px;
|
||||
}
|
||||
|
||||
.generate-task-drawer__cover--disabled {
|
||||
opacity: 0.55;
|
||||
cursor: not-allowed;
|
||||
}
|
||||
|
||||
.generate-task-drawer__cover-plus {
|
||||
display: inline-flex;
|
||||
align-items: center;
|
||||
@@ -633,6 +933,15 @@ function padTime(value: string): string {
|
||||
line-height: 1;
|
||||
}
|
||||
|
||||
.generate-task-drawer__cover-meta {
|
||||
display: flex;
|
||||
min-width: 220px;
|
||||
max-width: 360px;
|
||||
flex-direction: column;
|
||||
align-items: flex-start;
|
||||
gap: 8px;
|
||||
}
|
||||
|
||||
.generate-task-drawer__time-wrapper {
|
||||
display: flex;
|
||||
align-items: center;
|
||||
|
||||
@@ -2,61 +2,29 @@
|
||||
import { MinusCircleFilled } from "@ant-design/icons-vue";
|
||||
import { useMutation, useQuery, useQueryClient } from "@tanstack/vue-query";
|
||||
import { message, notification } from "ant-design-vue";
|
||||
import type { ArticleDetail, DesktopAccountInfo, MediaPlatform } from "@geo/shared-types";
|
||||
import type { ArticleDetail } from "@geo/shared-types";
|
||||
import { computed, ref, watch, watchEffect } from "vue";
|
||||
import { useI18n } from "vue-i18n";
|
||||
|
||||
import CoverPickerModal from "@/components/CoverPickerModal.vue";
|
||||
import { articlesApi, mediaApi, publishJobsApi, resolveApiURL, tenantAccountsApi } from "@/lib/api";
|
||||
import { coverUploadRequired, deriveCoverFileName } from "@/lib/cover-requirements";
|
||||
import { resolveAccountCheckedAt, resolveAccountHealth } from "@/lib/desktop-account-runtime";
|
||||
import { formatError } from "@/lib/errors";
|
||||
import {
|
||||
getPublishPlatformMeta,
|
||||
isPublishPlatformId,
|
||||
normalizePublishPlatformId,
|
||||
accountInitial,
|
||||
buildPublishAccountCards,
|
||||
buildPublishPlatformMap,
|
||||
clientStatusColor,
|
||||
clientStatusLabel,
|
||||
healthColor,
|
||||
healthLabel,
|
||||
publishStateLabel,
|
||||
type PublishAccountCard,
|
||||
} from "@/lib/publish-account-cards";
|
||||
import {
|
||||
normalizePublishPlatformIds,
|
||||
} from "@/lib/publish-platforms";
|
||||
|
||||
type PublishState = "immediate" | "queued" | "unavailable";
|
||||
|
||||
const platformLogoCatalog: Record<string, string> = {
|
||||
toutiaohao: "/logos/logo_toutiao.png",
|
||||
baijiahao: "/logos/logo_baijiahao.png",
|
||||
sohuhao: "/logos/logo_souhu.png",
|
||||
qiehao: "/logos/logo_qiehao.png",
|
||||
zhihu: "/logos/logo_zhihu.png",
|
||||
wangyihao: "/logos/logo_wangyihao.png",
|
||||
jianshu: "/logos/logo_jianshu.svg",
|
||||
bilibili: "/logos/logo_bilibili.png",
|
||||
juejin: "/logos/logo_juejin.png",
|
||||
smzdm: "/logos/logo_smzdm.svg",
|
||||
weixin_gzh: "/logos/logo_weixin_gzh.svg",
|
||||
zol: "/logos/logo_zol.png",
|
||||
dongchedi: "/logos/logo_dongchedi.svg",
|
||||
};
|
||||
|
||||
interface PublishAccountCard {
|
||||
id: string;
|
||||
platformId: string;
|
||||
platformName: string;
|
||||
platformShortName: string;
|
||||
platformAccent: string;
|
||||
platformLogoUrl: string | null;
|
||||
displayName: string;
|
||||
platformUid: string;
|
||||
avatarUrl: string | null;
|
||||
health: DesktopAccountInfo["health"];
|
||||
verifiedAt: string | null;
|
||||
clientId: string | null;
|
||||
clientOnline: boolean | null;
|
||||
clientDeviceName: string | null;
|
||||
clientLastSeenAt: string | null;
|
||||
publishState: PublishState;
|
||||
selectable: boolean;
|
||||
statusText: string;
|
||||
}
|
||||
|
||||
const props = defineProps<{
|
||||
open: boolean;
|
||||
articleId: number | null;
|
||||
@@ -123,77 +91,13 @@ watch(
|
||||
{ immediate: true },
|
||||
);
|
||||
|
||||
const platformMap = computed<Map<string, MediaPlatform>>(() => {
|
||||
return new Map(
|
||||
(platformsQuery.data.value ?? []).map((platform: MediaPlatform) => [
|
||||
normalizePublishPlatformId(platform.platform_id),
|
||||
platform,
|
||||
]),
|
||||
);
|
||||
});
|
||||
|
||||
const publishAccounts = computed(() => {
|
||||
return (accountsQuery.data.value ?? []).filter((account) => {
|
||||
if (account.deleted_at) {
|
||||
return false;
|
||||
}
|
||||
|
||||
const platformId = normalizePublishPlatformId(account.platform);
|
||||
return platformMap.value.has(platformId) || isPublishPlatformId(platformId);
|
||||
});
|
||||
});
|
||||
const platformMap = computed(() => buildPublishPlatformMap(platformsQuery.data.value ?? []));
|
||||
|
||||
const articlePlatformIds = computed(() => normalizePublishPlatformIds(detailQuery.data.value?.platforms ?? []));
|
||||
|
||||
const accountCards = computed<PublishAccountCard[]>(() => {
|
||||
const preferredPlatforms = new Set(articlePlatformIds.value);
|
||||
|
||||
return [...publishAccounts.value]
|
||||
.map((account) => {
|
||||
const platformId = normalizePublishPlatformId(account.platform);
|
||||
const platform = platformMap.value.get(platformId);
|
||||
const fallback = getPublishPlatformMeta(platformId);
|
||||
const publishState = resolvePublishState(account);
|
||||
const health = resolveAccountHealth(account);
|
||||
|
||||
return {
|
||||
id: account.id,
|
||||
platformId,
|
||||
platformName: platform?.name || fallback.name,
|
||||
platformShortName: platform?.short_name || fallback.shortName,
|
||||
platformAccent: platform?.accent_color || fallback.accent,
|
||||
platformLogoUrl: resolvePlatformLogoUrl(platformId, platform?.logo_url),
|
||||
displayName: account.display_name,
|
||||
platformUid: normalizePlatformUid(account.platform_uid),
|
||||
avatarUrl: resolveApiURL(account.avatar_url),
|
||||
health,
|
||||
verifiedAt: resolveAccountCheckedAt(account),
|
||||
clientId: account.client_id,
|
||||
clientOnline: account.client_online,
|
||||
clientDeviceName: account.client_device_name,
|
||||
clientLastSeenAt: account.client_last_seen_at,
|
||||
publishState,
|
||||
selectable: publishState !== "unavailable",
|
||||
statusText: resolveStatusText(account, publishState),
|
||||
};
|
||||
})
|
||||
.sort((left, right) => {
|
||||
const preferredGap =
|
||||
Number(preferredPlatforms.has(right.platformId)) - Number(preferredPlatforms.has(left.platformId));
|
||||
if (preferredGap !== 0) {
|
||||
return preferredGap;
|
||||
}
|
||||
|
||||
const publishGap = publishRank(left.publishState) - publishRank(right.publishState);
|
||||
if (publishGap !== 0) {
|
||||
return publishGap;
|
||||
}
|
||||
|
||||
const leftVerifiedAt = Date.parse(left.verifiedAt ?? "") || 0;
|
||||
const rightVerifiedAt = Date.parse(right.verifiedAt ?? "") || 0;
|
||||
return rightVerifiedAt - leftVerifiedAt;
|
||||
});
|
||||
});
|
||||
const accountCards = computed<PublishAccountCard[]>(() =>
|
||||
buildPublishAccountCards(accountsQuery.data.value ?? [], platformMap.value, articlePlatformIds.value),
|
||||
);
|
||||
|
||||
watch(
|
||||
accountCards,
|
||||
@@ -391,112 +295,6 @@ function handleRemoveCover(): void {
|
||||
coverImageAssetId.value = null;
|
||||
}
|
||||
|
||||
function resolvePublishState(account: DesktopAccountInfo): PublishState {
|
||||
if (resolveAccountHealth(account) !== "live") {
|
||||
return "unavailable";
|
||||
}
|
||||
if (!account.client_id) {
|
||||
return "unavailable";
|
||||
}
|
||||
return account.client_online === true ? "immediate" : "queued";
|
||||
}
|
||||
|
||||
function resolveStatusText(account: DesktopAccountInfo, publishState: PublishState): string {
|
||||
if (publishState === "immediate") {
|
||||
return "客户端在线,RabbitMQ 会立即唤醒桌面端开始发布。";
|
||||
}
|
||||
if (publishState === "queued") {
|
||||
return "客户端当前离线,任务会先落库排队,等桌面端上线后自动继续发布。";
|
||||
}
|
||||
if (resolveAccountHealth(account) !== "live") {
|
||||
return "该账号授权状态异常,请先在桌面端重新校验或重新授权。";
|
||||
}
|
||||
return "该账号还没有绑定桌面客户端,当前不能进入发布队列。";
|
||||
}
|
||||
|
||||
function publishRank(state: PublishState): number {
|
||||
switch (state) {
|
||||
case "immediate":
|
||||
return 0;
|
||||
case "queued":
|
||||
return 1;
|
||||
default:
|
||||
return 2;
|
||||
}
|
||||
}
|
||||
|
||||
function publishStateLabel(state: PublishState): string {
|
||||
switch (state) {
|
||||
case "immediate":
|
||||
return "立即发布";
|
||||
case "queued":
|
||||
return "离线排队";
|
||||
default:
|
||||
return "不可发布";
|
||||
}
|
||||
}
|
||||
|
||||
function healthLabel(health: DesktopAccountInfo["health"]): string {
|
||||
switch (health) {
|
||||
case "live":
|
||||
return "授权正常";
|
||||
case "captcha":
|
||||
return "待处理";
|
||||
case "risk":
|
||||
return "风险观察";
|
||||
default:
|
||||
return "授权异常";
|
||||
}
|
||||
}
|
||||
|
||||
function healthColor(health: DesktopAccountInfo["health"]): string {
|
||||
switch (health) {
|
||||
case "live":
|
||||
return "green";
|
||||
case "captcha":
|
||||
return "orange";
|
||||
case "risk":
|
||||
return "gold";
|
||||
default:
|
||||
return "red";
|
||||
}
|
||||
}
|
||||
|
||||
function clientStatusLabel(card: PublishAccountCard): string {
|
||||
if (!card.clientId) {
|
||||
return "未绑定客户端";
|
||||
}
|
||||
return card.clientOnline ? "客户端在线" : "客户端离线";
|
||||
}
|
||||
|
||||
function clientStatusColor(card: PublishAccountCard): string {
|
||||
if (!card.clientId) {
|
||||
return "default";
|
||||
}
|
||||
return card.clientOnline ? "green" : "gold";
|
||||
}
|
||||
|
||||
function accountInitial(card: PublishAccountCard): string {
|
||||
const trimmed = card.displayName.trim();
|
||||
return trimmed ? trimmed.slice(0, 1).toUpperCase() : card.platformShortName;
|
||||
}
|
||||
|
||||
function resolvePlatformLogoUrl(platformId: string, remoteLogoUrl?: string | null): string | null {
|
||||
const localLogoUrl = platformLogoCatalog[platformId];
|
||||
if (localLogoUrl) {
|
||||
return localLogoUrl;
|
||||
}
|
||||
const resolvedRemoteLogoUrl = resolveApiURL(remoteLogoUrl);
|
||||
return resolvedRemoteLogoUrl || null;
|
||||
}
|
||||
|
||||
function normalizePlatformUid(value?: string | null): string {
|
||||
let normalized = String(value ?? "").trim();
|
||||
while (normalized.toLowerCase().startsWith("platform:")) {
|
||||
normalized = normalized.slice("platform:".length).trim();
|
||||
}
|
||||
return normalized || "--";
|
||||
}
|
||||
</script>
|
||||
|
||||
<template>
|
||||
|
||||
@@ -16,7 +16,6 @@ import ScheduleTaskModal from "@/components/ScheduleTaskModal.vue";
|
||||
import { promptRulesApi, schedulesApi } from "@/lib/api";
|
||||
import { formatCronExecutionTime, formatDateTime } from "@/lib/display";
|
||||
import { formatError } from "@/lib/errors";
|
||||
import { formatPublishPlatformSummary } from "@/lib/publish-platforms";
|
||||
|
||||
const queryClient = useQueryClient();
|
||||
const { t } = useI18n();
|
||||
@@ -85,7 +84,7 @@ const columns = computed<TableColumnsType<ScheduleTask>>(() => [
|
||||
{ title: t("custom.schedule.rule"), dataIndex: "prompt_rule_name", key: "prompt_rule_name", width: 180 },
|
||||
{ title: t("custom.instant.executionStatus"), dataIndex: "status", key: "status", width: 140 },
|
||||
{ title: t("custom.instant.executionTime"), dataIndex: "cron_expr", key: "cron_expr", width: 170 },
|
||||
{ title: t("custom.schedule.platform"), dataIndex: "target_platform", key: "target_platform", width: 220 },
|
||||
{ title: t("custom.schedule.autoPublish"), dataIndex: "auto_publish", key: "auto_publish", width: 160 },
|
||||
{ title: t("custom.task.generateCount"), dataIndex: "generate_count", key: "generate_count", width: 120 },
|
||||
{ title: t("custom.instant.createdTime"), dataIndex: "created_at", key: "created_at", width: 170 },
|
||||
{ title: t("common.actions"), key: "actions", width: 140, fixed: "right", align: "right" },
|
||||
@@ -223,8 +222,14 @@ function handleTableChange(nextPage: number, nextPageSize: number): void {
|
||||
<template v-else-if="column.key === 'cron_expr'">
|
||||
{{ formatCronExecutionTime(record.cron_expr) }}
|
||||
</template>
|
||||
<template v-else-if="column.key === 'target_platform'">
|
||||
{{ formatPublishPlatformSummary(record.target_platform) }}
|
||||
<template v-else-if="column.key === 'auto_publish'">
|
||||
<a-tag :color="record.auto_publish ? 'blue' : 'default'">
|
||||
{{
|
||||
record.auto_publish
|
||||
? t("custom.schedule.autoPublishAccountCount", { count: record.publish_account_ids?.length ?? 0 })
|
||||
: t("custom.schedule.manualPublish")
|
||||
}}
|
||||
</a-tag>
|
||||
</template>
|
||||
<template v-else-if="column.key === 'generate_count'">
|
||||
{{ record.generate_count || 1 }}
|
||||
|
||||
@@ -1254,10 +1254,20 @@ const enUS = {
|
||||
platformUnauthorized: "Unauthorized",
|
||||
platformEmptyTitle: "No publish platforms",
|
||||
platformEmptyHint: "No platform data is available yet. Please verify the Media Management setup first.",
|
||||
publishSection: "Publish Settings",
|
||||
autoPublish: "Auto publish",
|
||||
autoPublishHint: "When enabled, scheduled articles enter the publish queue after generation.",
|
||||
publishAccounts: "Media accounts",
|
||||
publishAccountsHint: "Choose specific accounts. Offline clients queue first and continue after reconnecting.",
|
||||
publishAccountEmptyTitle: "No media accounts",
|
||||
publishAccountEmptyHint: "Bind media accounts in the desktop client before configuring auto publish.",
|
||||
cover: "Cover image",
|
||||
coverHint: "Keep the cover clear, complete, and visually polished.",
|
||||
scheduleCoverHint: "Cover is off by default. Enable it to save a cover to generated articles for publishing.",
|
||||
scheduleCoverRequiredHint: "A selected account platform requires a cover image before publishing.",
|
||||
coverUpload: "Upload cover image",
|
||||
coverUploadHint: "Local preview only for now",
|
||||
scheduleCoverUploadHint: "Choose from local files or the asset library",
|
||||
scheduleTime: "Schedule article generation",
|
||||
scheduleEveryDay: "Every day",
|
||||
enableWebSearch: "Enable web search for generation",
|
||||
@@ -1276,7 +1286,9 @@ const enUS = {
|
||||
name: "Task name",
|
||||
rule: "Prompt rule",
|
||||
cron: "Frequency",
|
||||
platform: "Target platform",
|
||||
autoPublish: "Auto publish",
|
||||
manualPublish: "Manual publish",
|
||||
autoPublishAccountCount: "Auto · {count} accounts",
|
||||
nextRun: "Next run",
|
||||
startAt: "Start time",
|
||||
endAt: "End time",
|
||||
@@ -1341,6 +1353,8 @@ const enUS = {
|
||||
missingPromptRule: "Choose a prompt first.",
|
||||
invalidGenerateCount: "Article count must be at least 1.",
|
||||
invalidScheduleTime: "Choose a valid schedule time.",
|
||||
missingPublishAccounts: "Choose at least one media account when auto publish is enabled.",
|
||||
missingScheduleCover: "A selected media account platform requires a cover image.",
|
||||
missingPromptName: "Enter a prompt name first.",
|
||||
missingPromptContent: "Enter prompt content first.",
|
||||
},
|
||||
|
||||
@@ -91,6 +91,7 @@ const zhCN = {
|
||||
},
|
||||
auth: {
|
||||
welcomeBack: "欢迎回来",
|
||||
tenantAdminLogin: "租户后台登录",
|
||||
loginAndEnter: "登录并进入工作台",
|
||||
email: "邮箱",
|
||||
loginIdentifier: "手机号 / 邮箱",
|
||||
@@ -597,7 +598,7 @@ const zhCN = {
|
||||
publishing: "发布中",
|
||||
success: "发布成功",
|
||||
failed: "发布失败",
|
||||
partial_success: "部分成功",
|
||||
partial_success: "部分发布",
|
||||
published: "发布成功",
|
||||
publish_success: "发布成功",
|
||||
publish_failed: "发布失败",
|
||||
@@ -1263,10 +1264,20 @@ const zhCN = {
|
||||
platformUnauthorized: "未授权",
|
||||
platformEmptyTitle: "暂无发布平台",
|
||||
platformEmptyHint: "当前还没有可用的平台数据,请先检查媒体管理配置。",
|
||||
publishSection: "发布设置",
|
||||
autoPublish: "是否自动发布",
|
||||
autoPublishHint: "开启后,定时生成完成的文章会使用指定媒体账号自动进入发布队列。",
|
||||
publishAccounts: "媒体账号",
|
||||
publishAccountsHint: "请选择具体账号。客户端离线时会先排队,上线后继续发布。",
|
||||
publishAccountEmptyTitle: "暂无可选媒体账号",
|
||||
publishAccountEmptyHint: "请先在桌面端绑定媒体账号,再回到这里配置自动发布。",
|
||||
cover: "封面图",
|
||||
coverHint: "请保证封面清晰、美观和完整",
|
||||
scheduleCoverHint: "默认不设置封面。需要时可单独指定,生成完成后会写入文章并用于发布。",
|
||||
scheduleCoverRequiredHint: "已选账号的平台要求发布封面,请先选择封面图。",
|
||||
coverUpload: "上传封面图",
|
||||
coverUploadHint: "当前仅做本地预览",
|
||||
scheduleCoverUploadHint: "从本地或素材库选择",
|
||||
scheduleTime: "定时生成文章",
|
||||
scheduleEveryDay: "每天",
|
||||
enableWebSearch: "生成文章联网搜索",
|
||||
@@ -1285,7 +1296,9 @@ const zhCN = {
|
||||
name: "任务名称",
|
||||
rule: "关联规则",
|
||||
cron: "执行频率",
|
||||
platform: "目标平台",
|
||||
autoPublish: "自动发布",
|
||||
manualPublish: "手动发布",
|
||||
autoPublishAccountCount: "自动 · {count} 个账号",
|
||||
nextRun: "下次执行",
|
||||
startAt: "开始时间",
|
||||
endAt: "结束时间",
|
||||
@@ -1350,6 +1363,8 @@ const zhCN = {
|
||||
missingPromptRule: "请先选择 Prompt",
|
||||
invalidGenerateCount: "生成篇数至少为 1",
|
||||
invalidScheduleTime: "请选择有效的定时时间",
|
||||
missingPublishAccounts: "开启自动发布后,请至少选择一个媒体账号",
|
||||
missingScheduleCover: "已选媒体账号的平台要求封面图,请先设置封面",
|
||||
missingPromptName: "请先填写 Prompt 名称",
|
||||
missingPromptContent: "请先填写 Prompt 内容",
|
||||
},
|
||||
|
||||
@@ -0,0 +1,241 @@
|
||||
import type { DesktopAccountInfo, MediaPlatform } from "@geo/shared-types";
|
||||
|
||||
import { resolveApiURL } from "@/lib/api";
|
||||
import { resolveAccountCheckedAt, resolveAccountHealth } from "@/lib/desktop-account-runtime";
|
||||
import {
|
||||
getPublishPlatformMeta,
|
||||
isPublishPlatformId,
|
||||
normalizePublishPlatformId,
|
||||
} from "@/lib/publish-platforms";
|
||||
|
||||
export type PublishState = "immediate" | "queued" | "unavailable";
|
||||
|
||||
export interface PublishAccountCard {
|
||||
id: string;
|
||||
platformId: string;
|
||||
platformName: string;
|
||||
platformShortName: string;
|
||||
platformAccent: string;
|
||||
platformLogoUrl: string | null;
|
||||
displayName: string;
|
||||
platformUid: string;
|
||||
avatarUrl: string | null;
|
||||
health: DesktopAccountInfo["health"];
|
||||
verifiedAt: string | null;
|
||||
clientId: string | null;
|
||||
clientOnline: boolean | null;
|
||||
clientDeviceName: string | null;
|
||||
clientLastSeenAt: string | null;
|
||||
publishState: PublishState;
|
||||
selectable: boolean;
|
||||
statusText: string;
|
||||
}
|
||||
|
||||
const platformLogoCatalog: Record<string, string> = {
|
||||
toutiaohao: "/logos/logo_toutiao.png",
|
||||
baijiahao: "/logos/logo_baijiahao.png",
|
||||
sohuhao: "/logos/logo_souhu.png",
|
||||
qiehao: "/logos/logo_qiehao.png",
|
||||
zhihu: "/logos/logo_zhihu.png",
|
||||
wangyihao: "/logos/logo_wangyihao.png",
|
||||
jianshu: "/logos/logo_jianshu.svg",
|
||||
bilibili: "/logos/logo_bilibili.png",
|
||||
juejin: "/logos/logo_juejin.png",
|
||||
smzdm: "/logos/logo_smzdm.svg",
|
||||
weixin_gzh: "/logos/logo_weixin_gzh.svg",
|
||||
zol: "/logos/logo_zol.png",
|
||||
dongchedi: "/logos/logo_dongchedi.svg",
|
||||
};
|
||||
|
||||
export function buildPublishPlatformMap(platforms: MediaPlatform[]): Map<string, MediaPlatform> {
|
||||
return new Map(
|
||||
platforms.map((platform) => [
|
||||
normalizePublishPlatformId(platform.platform_id),
|
||||
platform,
|
||||
]),
|
||||
);
|
||||
}
|
||||
|
||||
export function buildPublishAccountCards(
|
||||
accounts: DesktopAccountInfo[],
|
||||
platformMap: Map<string, MediaPlatform>,
|
||||
preferredPlatformIds: string[] = [],
|
||||
): PublishAccountCard[] {
|
||||
const preferredPlatforms = new Set(preferredPlatformIds.map(normalizePublishPlatformId));
|
||||
|
||||
return accounts
|
||||
.filter((account) => {
|
||||
if (account.deleted_at) {
|
||||
return false;
|
||||
}
|
||||
const platformId = normalizePublishPlatformId(account.platform);
|
||||
return platformMap.has(platformId) || isPublishPlatformId(platformId);
|
||||
})
|
||||
.map((account) => buildPublishAccountCard(account, platformMap))
|
||||
.sort((left, right) => {
|
||||
const preferredGap =
|
||||
Number(preferredPlatforms.has(right.platformId)) - Number(preferredPlatforms.has(left.platformId));
|
||||
if (preferredGap !== 0) {
|
||||
return preferredGap;
|
||||
}
|
||||
|
||||
const publishGap = publishRank(left.publishState) - publishRank(right.publishState);
|
||||
if (publishGap !== 0) {
|
||||
return publishGap;
|
||||
}
|
||||
|
||||
const leftVerifiedAt = Date.parse(left.verifiedAt ?? "") || 0;
|
||||
const rightVerifiedAt = Date.parse(right.verifiedAt ?? "") || 0;
|
||||
return rightVerifiedAt - leftVerifiedAt;
|
||||
});
|
||||
}
|
||||
|
||||
export function buildPublishAccountCard(
|
||||
account: DesktopAccountInfo,
|
||||
platformMap: Map<string, MediaPlatform>,
|
||||
): PublishAccountCard {
|
||||
const platformId = normalizePublishPlatformId(account.platform);
|
||||
const platform = platformMap.get(platformId);
|
||||
const fallback = getPublishPlatformMeta(platformId);
|
||||
const publishState = resolvePublishState(account);
|
||||
const health = resolveAccountHealth(account);
|
||||
|
||||
return {
|
||||
id: account.id,
|
||||
platformId,
|
||||
platformName: platform?.name || fallback.name,
|
||||
platformShortName: platform?.short_name || fallback.shortName,
|
||||
platformAccent: platform?.accent_color || fallback.accent,
|
||||
platformLogoUrl: resolvePlatformLogoUrl(platformId, platform?.logo_url),
|
||||
displayName: account.display_name,
|
||||
platformUid: normalizePlatformUid(account.platform_uid),
|
||||
avatarUrl: resolveApiURL(account.avatar_url),
|
||||
health,
|
||||
verifiedAt: resolveAccountCheckedAt(account),
|
||||
clientId: account.client_id,
|
||||
clientOnline: account.client_online,
|
||||
clientDeviceName: account.client_device_name,
|
||||
clientLastSeenAt: account.client_last_seen_at,
|
||||
publishState,
|
||||
selectable: publishState !== "unavailable",
|
||||
statusText: resolvePublishStatusText(account, publishState),
|
||||
};
|
||||
}
|
||||
|
||||
export function resolvePublishState(account: DesktopAccountInfo): PublishState {
|
||||
if (resolveAccountHealth(account) !== "live") {
|
||||
return "unavailable";
|
||||
}
|
||||
if (!account.client_id) {
|
||||
return "unavailable";
|
||||
}
|
||||
return account.client_online === true ? "immediate" : "queued";
|
||||
}
|
||||
|
||||
export function publishRank(state: PublishState): number {
|
||||
switch (state) {
|
||||
case "immediate":
|
||||
return 0;
|
||||
case "queued":
|
||||
return 1;
|
||||
default:
|
||||
return 2;
|
||||
}
|
||||
}
|
||||
|
||||
export function publishStateLabel(state: PublishState): string {
|
||||
switch (state) {
|
||||
case "immediate":
|
||||
return "立即发布";
|
||||
case "queued":
|
||||
return "离线排队";
|
||||
default:
|
||||
return "不可发布";
|
||||
}
|
||||
}
|
||||
|
||||
export function publishStatusShortLabel(state: PublishState): string {
|
||||
switch (state) {
|
||||
case "immediate":
|
||||
return "客户端在线";
|
||||
case "queued":
|
||||
return "离线可排队";
|
||||
default:
|
||||
return "不可发布";
|
||||
}
|
||||
}
|
||||
|
||||
export function healthLabel(health: DesktopAccountInfo["health"]): string {
|
||||
switch (health) {
|
||||
case "live":
|
||||
return "授权正常";
|
||||
case "captcha":
|
||||
return "待处理";
|
||||
case "risk":
|
||||
return "风险观察";
|
||||
default:
|
||||
return "授权异常";
|
||||
}
|
||||
}
|
||||
|
||||
export function healthColor(health: DesktopAccountInfo["health"]): string {
|
||||
switch (health) {
|
||||
case "live":
|
||||
return "green";
|
||||
case "captcha":
|
||||
return "orange";
|
||||
case "risk":
|
||||
return "gold";
|
||||
default:
|
||||
return "red";
|
||||
}
|
||||
}
|
||||
|
||||
export function clientStatusLabel(card: PublishAccountCard): string {
|
||||
if (!card.clientId) {
|
||||
return "未绑定客户端";
|
||||
}
|
||||
return card.clientOnline ? "客户端在线" : "客户端离线";
|
||||
}
|
||||
|
||||
export function clientStatusColor(card: PublishAccountCard): string {
|
||||
if (!card.clientId) {
|
||||
return "default";
|
||||
}
|
||||
return card.clientOnline ? "green" : "gold";
|
||||
}
|
||||
|
||||
export function accountInitial(card: Pick<PublishAccountCard, "displayName" | "platformShortName">): string {
|
||||
const trimmed = card.displayName.trim();
|
||||
return trimmed ? trimmed.slice(0, 1).toUpperCase() : card.platformShortName;
|
||||
}
|
||||
|
||||
export function resolvePlatformLogoUrl(platformId: string, remoteLogoUrl?: string | null): string | null {
|
||||
const localLogoUrl = platformLogoCatalog[platformId];
|
||||
if (localLogoUrl) {
|
||||
return localLogoUrl;
|
||||
}
|
||||
const resolvedRemoteLogoUrl = resolveApiURL(remoteLogoUrl);
|
||||
return resolvedRemoteLogoUrl || null;
|
||||
}
|
||||
|
||||
function resolvePublishStatusText(account: DesktopAccountInfo, publishState: PublishState): string {
|
||||
if (publishState === "immediate") {
|
||||
return "客户端在线,RabbitMQ 会立即唤醒桌面端开始发布。";
|
||||
}
|
||||
if (publishState === "queued") {
|
||||
return "客户端当前离线,任务会先落库排队,等桌面端上线后自动继续发布。";
|
||||
}
|
||||
if (resolveAccountHealth(account) !== "live") {
|
||||
return "该账号授权状态异常,请先在桌面端重新校验或重新授权。";
|
||||
}
|
||||
return "该账号还没有绑定桌面客户端,当前不能进入发布队列。";
|
||||
}
|
||||
|
||||
function normalizePlatformUid(value?: string | null): string {
|
||||
let normalized = String(value ?? "").trim();
|
||||
while (normalized.toLowerCase().startsWith("platform:")) {
|
||||
normalized = normalized.slice("platform:".length).trim();
|
||||
}
|
||||
return normalized || "--";
|
||||
}
|
||||
Reference in New Issue
Block a user