Let's use AI to Earn!
TypeScript auto-publishdouyindouyin-apielectron-appelectron-reactkuaishoukwaipublishedshipinhaotoolxiaohongshu
feat: 添加参数校验: 1. 描述字数限制。 2. 标题字数限制校验。 3. 描述必填校验。 4. 图片数量校验。 5. facebook和instagram的类型校验(1. instagram post只能发图片 + 描述,reel只能发视频+描述,story只能发图片或者视频。 2. facebook post 图片+描述 或者视频+描述,reel只能发视频+描述,story只能发图片或者视频)
gaoSirbaade98a5fc9
diff --git a/@types/resources.d.ts b/@types/resources.d.tsindex 3efabef9..75eae7fa 100644--- a/@types/resources.d.ts+++ b/@types/resources.d.ts@@ -36,6 +36,29 @@ interface Resources {"selectAtLeastOne": "请至少选择一个页面"}},+ "cgmaterial": {+ "createMaterial": "创建素材",+ "selectMediaGroup": "选择媒体组",+ "selectMediaGroupDesc": "选择一个媒体组来获取其中的图片和视频资源",+ "mediaGroupType": {+ "img": "图片组",+ "video": "视频组",+ "mixed": "混合组"+ },+ "selectCover": "选择封面(单选)",+ "selectMaterials": "选择素材(多选)",+ "title": "标题",+ "titlePlaceholder": "请输入标题",+ "description": "简介",+ "descriptionPlaceholder": "请输入简介",+ "location": "地理位置",+ "locationPlaceholder": "请输入地理位置坐标",+ "create": "创建",+ "cancel": "取消",+ "mediaCount": "{{count}}个资源",+ "noMediaGroups": "暂无媒体组",+ "noMediaInGroup": "该媒体组暂无资源"+ },"common": {"profile": "个人中心","logout": "退出登录",@@ -385,10 +408,11 @@ interface Resources {},"material": {"aiGenerate": {- "title": "标题",+ "title": "AI生成","backToAlbum": "返回相册","textToImage": "文生图","fireflyCard": "Firefly卡片",+ "videoGeneration": "视频生成","prompt": "提示词","promptPlaceholder": "请输入提示词","width": "宽度",@@ -400,21 +424,7 @@ interface Resources {"titlePlaceholder": "请输入标题","template": "模板","uploadToMediaGroup": "上传到媒体组",- "videoGeneration": "视频生成",- "videoPromptPlaceholder": "请输入视频提示词",- "videoSize": "视频尺寸",- "videoDuration": "视频时长",- "videoFPS": "视频帧率",- "videoBitrate": "视频码率",- "videoQuality": "视频质量",- "videoMode": "视频模式",- "imageUrlPlaceholder": "请输入图片URL","selectMediaGroup": "选择媒体组",- "taskStatus": "任务状态",- "taskSubmitted": "任务已提交",- "taskProcessing": "任务处理中",- "taskCompleted": "任务已完成",- "taskFailed": "任务失败","selectMediaGroupPlaceholder": "请选择媒体组","upload": "上传","uploading": "上传中...",@@ -424,7 +434,42 @@ interface Resources {"pleaseEnterPrompt": "请输入提示词","pleaseSelectMediaGroup": "请选择媒体组","pleaseEnterContent": "请输入内容",- "pleaseEnterTitle": "请输入标题"+ "pleaseEnterTitle": "请输入标题",+ "selectSize": "选择尺寸",+ "generateCount": "生成数量",+ "imageQuality": "图片质量",+ "imageStyle": "图片风格",+ "selectModel": "选择模型",+ "standard": "标准",+ "hd": "高清",+ "vivid": "生动",+ "natural": "自然",+ "goldCardTemplate": "金卡模板",+ "memoTemplate": "备忘录模板",+ "simpleTemplate": "简约模板",+ "blackSunTemplate": "黑日模板",+ "templateE": "模板 E",+ "writingTemplate": "写作模板",+ "codeTemplate": "代码模板",+ "templateD": "模板 D",+ "videoPromptPlaceholder": "请输入视频描述",+ "videoDuration": "视频时长",+ "videoSize": "视频尺寸",+ "videoMode": "生成模式",+ "uploadImage": "上传图片",+ "imageUrlPlaceholder": "图片URL或base64",+ "taskStatus": "任务状态",+ "taskSubmitted": "任务已提交",+ "taskProcessing": "任务处理中",+ "taskCompleted": "任务完成",+ "taskFailed": "任务失败",+ "checkStatus": "检查状态",+ "videoGenerationFailed": "视频生成失败",+ "videoGenerationSuccess": "视频生成成功",+ "pleaseEnterVideoPrompt": "请输入视频描述",+ "pleaseSelectVideoModel": "请选择视频模型",+ "videoUploadSuccess": "视频上传成功",+ "videoUploadFailed": "视频上传失败"}},"pinterest": {@@ -636,19 +681,19 @@ interface Resources {"publish": {"title": "发布作品","confirmClose": {- "title": "放弃更改?",- "content": "您所做的任何更改都将永久丢失"+ "title": "确认关闭",+ "content": "关闭后,已填写的内容将丢失,是否确认关闭?"},"buttons": {- "customizePerAccount": "针对每个账户进行定制",+ "customizePerAccount": "自定义每个账户","cancelPublish": "取消发布",- "schedulePublish": "立即发布",+ "schedulePublish": "定时发布","publishNow": "立即发布","copyLink": "复制链接","delete": "删除"},"tips": {- "workSaved": "你的工作被保存了,选择一个账号来创建一个帖子。"+ "workSaved": "请选择要发布的账户"},"status": {"publishFailed": "发布失败",@@ -684,6 +729,15 @@ interface Resources {"dragAndSelect": "拖放 & 选择图片或视频"},"validation": {+ "facebookStoryNoDes": "Facebook Story不支持填写描述",+ "facebookReelNoImage": "Facebook Reel不支持上传图片",+ "instagramStoryNoDes": "Instagram Story不支持填写描述",+ "instagramReelNoImage": "Instagram Reel不支持上传图片",+ "instagramPostNoVideo": "Instagram post不支持上传视频",+ "titleMaxExceeded": "{{platformName}}标题最多{{maxCount}}字",+ "descriptionMaxExceeded": "{{platformName}}描述最多{{maxCount}}字",+ "descriptionRequired": "描述是必须的",+ "imageMaxExceeded": "{{platformName}}图片最多不能超过{{maxCount}}张","uploadImageOrVideo": "请上传图片或视频","topicMaxExceeded": "{{platformName}}话题最多不能超过{{maxCount}}个","topicFormatError": "描述中的话题必须使用空格分割,如:\"#话题1 #话题2\"",@@ -697,6 +751,24 @@ interface Resources {"preview": {"title": "预览","emptyDescription": "在这里看到你的作品预览"+ },+ "draft": {+ "selectDraft": "选择草稿",+ "selectDraftGroup": "选择草稿箱组",+ "selectDraftItem": "选择草稿",+ "noDraftGroups": "暂无草稿箱组",+ "noDrafts": "该组暂无草稿",+ "backToGroups": "返回草稿箱组",+ "selectDraftSuccess": "草稿已应用",+ "imageGroup": "图文组",+ "videoGroup": "视频组",+ "selectLibrary": "选择素材库",+ "selectLibraryItem": "选择素材",+ "selectLibraryGroup": "选择素材库组",+ "noLibraryGroups": "暂无素材库组",+ "backToLibraryGroups": "返回素材库组",+ "noLibraryItems": "该组暂无素材",+ "selectLibrarySuccess": "素材已应用"}},"route": {diff --git a/src/app/config/platConfig.ts b/src/app/config/platConfig.tsindex 3238a0f8..0c3a5d41 100644--- a/src/app/config/platConfig.ts+++ b/src/app/config/platConfig.ts@@ -8,8 +8,7 @@ import twitterSvg from "@/assets/svgs/plat/twtter.svg";import facebookSvg from "@/assets/svgs/plat/facebook.svg";import instagramSvg from "@/assets/svgs/plat/instagram.svg";import threadsSvg from "@/assets/svgs/plat/xiancheng.svg";-import wxGzhSvg from "@/assets/svgs/plat/wx-gzh.svg";-import wxSphSvg from "@/assets/svgs/plat/wx-sph.svg";+import wxGzhSvg from "@/assets/svgs/plat/wx-gzh.svg";import pinterestSvg from "@/assets/svgs/plat/pinterest.svg";// 平台类型@@ -50,10 +49,10 @@ export interface IAccountPlatInfo {titleMax?: number;// 话题数量限制topicMax: number;- // 仅图文发布的限制参数- imgTextConfig?: {- imagesMax: number;- };+ // 描述字数限制+ desMax: number;+ // 图片数量限制+ imagesMax?: number;};// 是否在PC端不显示pcNoThis?: boolean;@@ -68,7 +67,7 @@ export interface IAccountPlatInfo {// 各个平台的信息export const AccountPlatInfoMap = new Map<PlatType, IAccountPlatInfo>([- [+ [PlatType.Tiktok,{name: "TikTok",@@ -77,7 +76,8 @@ export const AccountPlatInfoMap = new Map<PlatType, IAccountPlatInfo>([pubTypes: new Set([PubType.VIDEO, PubType.ImageText]),commonPubParamsConfig: {titleMax: 16,- topicMax: 10,+ topicMax: 100,+ desMax: 4000,},themeColor: "black",},@@ -90,7 +90,9 @@ export const AccountPlatInfoMap = new Map<PlatType, IAccountPlatInfo>([url: "https://www.douyin.com/",pubTypes: new Set([PubType.VIDEO]),commonPubParamsConfig: {- topicMax: 4,+ titleMax: 30,+ topicMax: 5,+ desMax: 1000,},themeColor: "#FF4D00",pcNoThis: true,@@ -105,6 +107,7 @@ export const AccountPlatInfoMap = new Map<PlatType, IAccountPlatInfo>([pubTypes: new Set([PubType.VIDEO]),commonPubParamsConfig: {topicMax: 4,+ desMax: 500,},themeColor: "#FF4D00",},@@ -119,6 +122,7 @@ export const AccountPlatInfoMap = new Map<PlatType, IAccountPlatInfo>([commonPubParamsConfig: {topicMax: 10,titleMax: 80,+ desMax: 2000,},themeColor: "blue",},@@ -131,8 +135,9 @@ export const AccountPlatInfoMap = new Map<PlatType, IAccountPlatInfo>([url: "https://www.youtube.com/",pubTypes: new Set([PubType.VIDEO]),commonPubParamsConfig: {- titleMax: 16,- topicMax: 10,+ titleMax: 100,+ topicMax: 100,+ desMax: 5000,},themeColor: "blue",},@@ -146,7 +151,9 @@ export const AccountPlatInfoMap = new Map<PlatType, IAccountPlatInfo>([pubTypes: new Set([PubType.VIDEO, PubType.ImageText, PubType.Article]),commonPubParamsConfig: {titleMax: 16,- topicMax: 10,+ topicMax: 100,+ desMax: 280,+ imagesMax: 4,},themeColor: "blue",},@@ -159,8 +166,10 @@ export const AccountPlatInfoMap = new Map<PlatType, IAccountPlatInfo>([url: "https://www.facebook.com/",pubTypes: new Set([PubType.VIDEO, PubType.ImageText]),commonPubParamsConfig: {- titleMax: 16,- topicMax: 10,+ titleMax: 80,+ topicMax: 100,+ desMax: 5000,+ imagesMax: 10,},themeColor: "blue",},@@ -175,6 +184,7 @@ export const AccountPlatInfoMap = new Map<PlatType, IAccountPlatInfo>([commonPubParamsConfig: {titleMax: 16,topicMax: 10,+ desMax: 2200,},themeColor: "green",},@@ -187,8 +197,10 @@ export const AccountPlatInfoMap = new Map<PlatType, IAccountPlatInfo>([url: "https://www.instagram.com/",pubTypes: new Set([PubType.VIDEO, PubType.ImageText]),commonPubParamsConfig: {- titleMax: 16,- topicMax: 10,+ titleMax: 80,+ topicMax: 100,+ desMax: 2200,+ imagesMax: 10,},themeColor: "blue",},@@ -201,8 +213,10 @@ export const AccountPlatInfoMap = new Map<PlatType, IAccountPlatInfo>([url: "https://www.threads.net/",pubTypes: new Set([PubType.VIDEO, PubType.ImageText, PubType.Article]),commonPubParamsConfig: {- titleMax: 16,- topicMax: 10,+ titleMax: 80,+ topicMax: 100,+ desMax: 500,+ imagesMax: 20,},themeColor: "blue",},@@ -217,6 +231,7 @@ export const AccountPlatInfoMap = new Map<PlatType, IAccountPlatInfo>([commonPubParamsConfig: {titleMax: 16,topicMax: 10,+ desMax: 2200,},themeColor: "#CC2025",},diff --git a/src/app/i18n/locales/en/publish.json b/src/app/i18n/locales/en/publish.jsonindex 1dec59f5..ff8747f7 100644--- a/src/app/i18n/locales/en/publish.json+++ b/src/app/i18n/locales/en/publish.json@@ -49,6 +49,15 @@"dragAndSelect": "Drag & select image or video"},"validation": {+ "facebookStoryNoDes": "Facebook Story does not support description",+ "facebookReelNoImage": "Facebook Reel does not support image upload",+ "instagramStoryNoDes": "Instagram Story does not support description",+ "instagramReelNoImage": "Instagram Reel does not support image upload",+ "instagramPostNoVideo": "Instagram post does not support video upload",+ "titleMaxExceeded": "{{platformName}} title cannot exceed {{maxCount}} characters",+ "descriptionMaxExceeded": "{{platformName}} description cannot exceed {{maxCount}} characters",+ "descriptionRequired": "Description is required",+ "imageMaxExceeded": "{{platformName}} images cannot exceed {{maxCount}}","uploadImageOrVideo": "Please upload image or video","topicMaxExceeded": "{{platformName}} topics cannot exceed {{maxCount}}","topicFormatError": "Topics in description must be separated by spaces, such as: \"#topic1 #topic2\"",diff --git a/src/app/i18n/locales/zh-CN/publish.json b/src/app/i18n/locales/zh-CN/publish.jsonindex c7cd3315..d15545b8 100644--- a/src/app/i18n/locales/zh-CN/publish.json+++ b/src/app/i18n/locales/zh-CN/publish.json@@ -49,6 +49,15 @@"dragAndSelect": "拖放 & 选择图片或视频"},"validation": {+ "facebookStoryNoDes": "Facebook Story不支持填写描述",+ "facebookReelNoImage": "Facebook Reel不支持上传图片",+ "instagramStoryNoDes": "Instagram Story不支持填写描述",+ "instagramReelNoImage": "Instagram Reel不支持上传图片",+ "instagramPostNoVideo": "Instagram post不支持上传视频",+ "titleMaxExceeded": "{{platformName}}标题最多{{maxCount}}字",+ "descriptionMaxExceeded": "{{platformName}}描述最多{{maxCount}}字",+ "descriptionRequired": "描述是必须的",+ "imageMaxExceeded": "{{platformName}}图片最多不能超过{{maxCount}}张","uploadImageOrVideo": "请上传图片或视频","topicMaxExceeded": "{{platformName}}话题最多不能超过{{maxCount}}个","topicFormatError": "描述中的话题必须使用空格分割,如:\"#话题1 #话题2\"",diff --git a/src/components/PublishDialog/compoents/PlatParamsSetting/plats/FacebookParams.tsx b/src/components/PublishDialog/compoents/PlatParamsSetting/plats/FacebookParams.tsxindex 76705a18..fd725f55 100644--- a/src/components/PublishDialog/compoents/PlatParamsSetting/plats/FacebookParams.tsx+++ b/src/components/PublishDialog/compoents/PlatParamsSetting/plats/FacebookParams.tsx@@ -27,7 +27,7 @@ const FacebookParams = memo(...option,facebook: {...option.facebook,- content_category: 'video',+ content_category: "post",},},},@@ -47,9 +47,14 @@ const FacebookParams = memo(className={styles.commonTitleInput}style={{ marginTop: "10px" }}>- <div className="platParamsSetting-label">{t("form.type")}</div>+ <div className="platParamsSetting-label">+ {t("form.type")}+ </div><Radio.Group- value={pubItem.params.option.facebook?.content_category || 'video'}+ value={+ pubItem.params.option.facebook?.content_category ||+ "video"+ }onChange={(e) => {const option = pubItem.params.option;setOnePubParams(@@ -80,4 +85,4 @@ const FacebookParams = memo(),);-export default FacebookParams;\ No newline at end of file+export default FacebookParams;diff --git a/src/components/PublishDialog/compoents/PlatParamsSetting/plats/InstagramParams.tsx b/src/components/PublishDialog/compoents/PlatParamsSetting/plats/InstagramParams.tsxindex 84f26dff..075afe42 100644--- a/src/components/PublishDialog/compoents/PlatParamsSetting/plats/InstagramParams.tsx+++ b/src/components/PublishDialog/compoents/PlatParamsSetting/plats/InstagramParams.tsx@@ -31,7 +31,7 @@ const InstagramParams = memo(...option,instagram: {...option.instagram,- content_category: "video",+ content_category: "post",},},},@@ -93,4 +93,4 @@ const InstagramParams = memo(),);-export default InstagramParams;+export default InstagramParams;\ No newline at end of filediff --git a/src/components/PublishDialog/compoents/PubParmasTextarea/index.tsx b/src/components/PublishDialog/compoents/PubParmasTextarea/index.tsxindex 8ccb37bc..fd65053a 100644--- a/src/components/PublishDialog/compoents/PubParmasTextarea/index.tsx+++ b/src/components/PublishDialog/compoents/PubParmasTextarea/index.tsx@@ -116,7 +116,7 @@ const PubParmasTextarea = memo(return AccountPlatInfoMap.get(platType)! || {};}, [platType]);const imageMax = useMemo(() => {- return platConfig.commonPubParamsConfig.imgTextConfig?.imagesMax || 10;+ return platConfig.commonPubParamsConfig?.imagesMax || 10;}, [platConfig]);// 动态accept类型diff --git a/src/components/PublishDialog/hooks/usePubParamsVerify.tsx b/src/components/PublishDialog/hooks/usePubParamsVerify.tsxindex 4e98bd1c..3d8205fc 100644--- a/src/components/PublishDialog/hooks/usePubParamsVerify.tsx+++ b/src/components/PublishDialog/hooks/usePubParamsVerify.tsx@@ -4,6 +4,7 @@ import { AccountPlatInfoMap, PlatType } from "@/app/config/platConfig";import { PubItem } from "@/components/PublishDialog/publishDialog.type";import { Alert } from "antd";import { useTransClient } from "@/app/i18n/client";+import { PubType } from "@/app/config/publishConfig";export interface ErrPubParamsItem {// 参数错误提示消息@@ -40,11 +41,70 @@ export default function usePubParamsVerify(data: PubItem[]) {(() => {// ------------------------ 通用参数校验 ------------------------- // 图片或者视频校验,视频和图片必须要上传一个- if (v.params.images?.length === 0 && !v.params.video) {- return setErrorMsg(t("validation.uploadImageOrVideo"));+ // 描述校验+ if (+ (v.account.type === PlatType.Threads ||+ v.account.type === PlatType.Twitter) &&+ !v.params.des+ ) {+ return setErrorMsg(t("validation.descriptionRequired"));}- // 话题校验++ // 标题字数校验+ if (+ v.params.title &&+ v.params.title.length > platInfo.commonPubParamsConfig.titleMax!+ ) {+ return setErrorMsg(+ t("validation.titleMaxExceeded", {+ platformName: platInfo.name,+ maxCount: platInfo.commonPubParamsConfig.titleMax,+ }),+ );+ }++ // 描述字数校验+ if (+ v.params.des &&+ v.params.des.length > platInfo.commonPubParamsConfig.desMax+ ) {+ return setErrorMsg(+ t("validation.descriptionMaxExceeded", {+ platformName: platInfo.name,+ maxCount: platInfo.commonPubParamsConfig.desMax,+ }),+ );+ }++ // 图片数量校验+ if (+ platInfo.pubTypes.has(PubType.ImageText) &&+ (v.params.images?.length || 0) > 1 &&+ v.params.images!.length > platInfo.commonPubParamsConfig.imagesMax!+ ) {+ return setErrorMsg(+ t("validation.imageMaxExceeded", {+ platformName: platInfo.name,+ maxCount: platInfo.commonPubParamsConfig.imagesMax,+ }),+ );+ }++ if (+ v.params.option.instagram?.content_category !== "story" &&+ v.params.option.facebook?.content_category !== "story"+ ) {+ // 图片或者视频校验,视频和图片必须要上传一个+ if (+ !platInfo.pubTypes.has(PubType.Article) &&+ v.params.images?.length === 0 &&+ !v.params.video+ ) {+ return setErrorMsg(t("validation.uploadImageOrVideo"));+ }+ }++ // 话题数量校验if (topicsAll.length > topicMax) {return setErrorMsg(t("validation.topicMaxExceeded", {@@ -53,6 +113,7 @@ export default function usePubParamsVerify(data: PubItem[]) {}),);}+// 判断描述中的话题中间是否用空格分割,如:#话题1#话题2#话题3 这种格式错误if (descTopicRegex.test(v.params.des || "")) {return setErrorMsg(t("validation.topicFormatError"));@@ -81,14 +142,45 @@ export default function usePubParamsVerify(data: PubItem[]) {}}- // 快手的强制校验- if (v.account.type === PlatType.KWAI) {- if (- v.params.video?.cover &&- (v.params.video.cover.width < 400 ||- v.params.video.cover.height < 400)- ) {- return setErrorMsg(t("validation.coverSizeError"));+ // facebook的强制校验+ if (v.account.type === PlatType.Facebook) {+ switch (v.params.option.instagram?.content_category) {+ case "reel":+ // facebook reel 不支持图片,只支持视频 + 描述+ if (v.params.video) {+ return setErrorMsg(t("validation.facebookReelNoImage"));+ }+ break;+ case "story":+ // facebook story 只能选择图片、视频,不能有描述+ if (v.params.des) {+ return setErrorMsg(t("validation.facebookStoryNoDes"));+ }+ break;+ }+ }++ // instagram的强制校验+ if (v.account.type === PlatType.Instagram) {+ switch (v.params.option.instagram?.content_category) {+ case "post":+ // instagram post不能上传视频,必须上传图片+ if (v.params.video) {+ return setErrorMsg(t("validation.instagramPostNoVideo"));+ }+ break;+ case "reel":+ // instagram reel 不能上传图片,必须上传视频+ if (v.params.video) {+ return setErrorMsg(t("validation.instagramReelNoImage"));+ }+ break;+ case "story":+ // instagram story 只能选择图片、视频,不能有描述+ if (v.params.des) {+ return setErrorMsg(t("validation.instagramStoryNoDes"));+ }+ break;}}})();diff --git a/src/components/PublishDialog/publishDialog.type.ts b/src/components/PublishDialog/publishDialog.type.tsindex 3a711bf3..056416d2 100644--- a/src/components/PublishDialog/publishDialog.type.ts+++ b/src/components/PublishDialog/publishDialog.type.ts@@ -48,11 +48,11 @@ export interface IPlatOption {facebook?: {// 页面ID,由获取Facebook页面信息接口得到page_id?: string;- // 内容类型:video(Post)、reel(Reel)、story(Story)+ // 内容类型:post(Post)、reel(Reel)、story(Story)content_category?: string;};instagram?: {- // 内容类型:video(Post)、reel(Reel)、story(Story)+ // 内容类型:post(Post)、reel(Reel)、story(Story)content_category?: string;};youtube?: {