Let's use AI to Earn!
TypeScript auto-publishdouyindouyin-apielectron-appelectron-reactkuaishoukwaipublishedshipinhaotoolxiaohongshu
feat: 抖音、小红书、视频号展示上传进度优化:将视频分片上传的进度做了展示,让用户更直观的看到视频上传的进度
gaoSirb7da89005c1e
diff --git a/electron/main/plat/platforms/xhs/index.ts b/electron/main/plat/platforms/xhs/index.tsindex a756dbc8..a0e16cc6 100644--- a/electron/main/plat/platforms/xhs/index.ts+++ b/electron/main/plat/platforms/xhs/index.ts@@ -546,7 +546,7 @@ export class Xhs extends PlatformBase {? 0: params.visibleType === VisibleTypeEnum.Private? 1- : 2,+ : 4,// 位置poiInfo: params.location? {diff --git a/electron/plat/douyin/index.ts b/electron/plat/douyin/index.tsindex 84c999da..83aa99b8 100644--- a/electron/plat/douyin/index.ts+++ b/electron/plat/douyin/index.ts@@ -89,6 +89,7 @@ export class DouyinService {private windowMap: { [key: number]: BrowserWindow } = {};private fileBlockSize = 3145728;private app: any;+ private callback?: (progress: number, msg?: string) => void;/*** 授权|预览@@ -545,7 +546,7 @@ export class DouyinService {console.log('视频文件路径:', filePath);callback(30, '正在上传视频...');const videoId = await this.uploadVideo(filePath, cookieString, userUid);- callback(50, '视频上传完成');+ callback(60, '视频上传完成');console.log('获取到的视频ID:', videoId);// 发布视频参数@@ -553,7 +554,7 @@ export class DouyinService {const publishVideoParams =this.getPublishPublicParamsV2(platformSetting);console.log('发布参数:', publishVideoParams);- callback(55, '参数获取完成');+ callback(65, '参数获取完成');// 拼接视频封面内容publishVideoParams.item.common.video_id = videoId;@@ -1473,6 +1474,11 @@ export class DouyinService {// 开始上传for (const i in filePartInfo.blockInfo) {+ if (this.callback)+ this.callback(+ 50,+ `上传视频(${i}/${filePartInfo.blockInfo.length})`,+ );console.log(`开始上传第 ${parseInt(i) + 1} 个分片...`);// 设置当前文件分片信息const nowUploadParams = JSON.parse(JSON.stringify(uploadParams));diff --git a/electron/plat/shipinhao/index.ts b/electron/plat/shipinhao/index.tsindex 6145adb8..6f67f3fd 100644--- a/electron/plat/shipinhao/index.ts+++ b/electron/plat/shipinhao/index.ts@@ -70,6 +70,7 @@ export class ShipinhaoService {private cookieCheckField = 'sessionid';private cookieIntervalList: { [key: string]: NodeJS.Timeout } = {};private windowMap: { [key: number]: BrowserWindow } = {}; // 添加窗口引用存储+ private callback?: (progress: number, msg?: string) => void;/*** 获取网站登录cookie@@ -695,6 +696,11 @@ export class ShipinhaoService {// 分片上传文件for (let i = 0; i < filePartInfo.blockInfo.length; i++) {+ if (this.callback)+ this.callback(+ 50,+ `上传视频(${i}/${filePartInfo.blockInfo.length})`,+ );console.log(`开始上传第 ${i + 1}/${filePartInfo.blockInfo.length} 个分片`,);@@ -1229,6 +1235,7 @@ export class ShipinhaoService {publishId: string;shareLink: string;}> {+ this.callback = callback;console.log('platformSetting:', platformSetting);callback(5, '加载中...');const fileInfo = await FileUtils.getFileInfo(filePath);diff --git a/electron/plat/xiaohongshu/index.ts b/electron/plat/xiaohongshu/index.tsindex 18a0733e..e89b2359 100644--- a/electron/plat/xiaohongshu/index.ts+++ b/electron/plat/xiaohongshu/index.ts@@ -39,8 +39,8 @@ export type XSLPlatformSettingType = {poiAddress: string;};cover: string;- // 0 公共 1 私密 2 好友- visibility_type: 0 | 1 | 2;+ // 0 公共 1 私密 4 好友+ visibility_type: 0 | 1 | 4;};const esec_token = 'ABrmhLmsdmsu9bCQ80qvGPN2CYSjEqwi5G1l2dirNUjaw%3D';@@ -65,6 +65,7 @@ export class XiaohongshuService {private cookieIntervalList: { [key: string]: NodeJS.Timer } = {};private prev_web_session = '';private win?: BrowserWindow;+ private callback?: (progress: number, msg?: string) => void;/*** 授权|预览@@ -714,7 +715,14 @@ export class XiaohongshuService {// 分片上传文件const uploadPartInfo = [];+for (const i in filePartInfo.blockInfo) {+ if (this.callback)+ this.callback(+ 50,+ `上传视频(${filePartInfo.blockInfo}/${filePartInfo.blockInfo.length})`,+ );+const chunkStart =i === '0' ? 0 : filePartInfo.blockInfo[parseInt(i) - 1];const chunkEnd = filePartInfo.blockInfo[i] - 1;@@ -824,7 +832,6 @@ export class XiaohongshuService {try {// 初始化cookieconst cookieString = CommonUtils.convertCookieToJson(cookies);- console.log('cookieString', cookieString);// 上传图片const uploadImgRet = [];for (const imgUrl of imagePath) {@@ -1167,9 +1174,16 @@ export class XiaohongshuService {reject('创建作品失败,失败原因:' + createRes.msg || '未知');return;}++ if (this.callback) this.callback(80, '发布完成,正在查询结果...');+ const worksList = await this.getWorks(cookieString);+ const works = worksList.data.data.notes.find(+ (v) => v.id === createRes.data.id,+ );+ console.log('works:', works);// 返回结果resolve({- shareLink: createRes.share_link ?? '',+ shareLink: `https://www.xiaohongshu.com/explore/${createRes.data.id}?xsec_token=${works!.xsec_token}&xsec_source=${works!.xsec_source}`,publishId: createRes.data.id,});} catch (err: any) {@@ -1205,6 +1219,7 @@ export class XiaohongshuService {}> {return new Promise(async (resolve, reject) => {try {+ this.callback = callback;callback(5, '正在加载...');// 获取文件信息const fileInfo = await FileUtils.getFileInfo(filePath);@@ -1227,7 +1242,7 @@ export class XiaohongshuService {fileInfo,);- callback(40, '正在上传封面...');+ callback(60, '正在上传封面...');// 上传封面,获取远程Urlconst { coverDimensions, coverUploadFileId } =await this.uploadCoverFile(cookieString, platformSetting['cover']);@@ -1257,20 +1272,11 @@ export class XiaohongshuService {).catch((err) => {reject(err);});- callback(80, '发布完成,正在查询结果...');-- const worksList = await this.getWorks(JSON.parse(cookies));- console.log(worksList);- const works = worksList.data.data.notes.find(- (v) => v.id === result.publishId,- );- console.log(works);- callback(100);// 返回信息resolve({publishTime: Math.floor(Date.now() / 1000),publishId: result.publishId,- shareLink: `https://www.xiaohongshu.com/explore/${result.publishId}?xsec_token=${works!.xsec_token}&xsec_source=${works!.xsec_source}`,+ shareLink: result.shareLink,});} catch (err) {console.warn(err);@@ -1371,17 +1377,17 @@ export class XiaohongshuService {}// 获取作品列表- async getWorks(cookie: Electron.Cookie[], page: number = 0) {+ async getWorks(cookie: string, page: number = 0) {const url = `/web_api/sns/v5/creator/note/user/posted?tab=0&page=${page}`;const reverseRes: any = await this.getReverseResult({url,- a1: CookieToString(cookie),+ a1: cookie,});const res = await requestNet<IXHSGetWorksResponse>({url: `https://edith.xiaohongshu.com${url}`,headers: {- cookie: CookieToString(cookie),+ cookie: cookie,Referer: this.loginUrl,origin: this.loginUrl,'X-S': reverseRes['X-s'],diff --git a/src/views/publish/children/pubRecord/components/PubRecordDetails.tsx b/src/views/publish/children/pubRecord/components/PubRecordDetails.tsxindex 5bd106ae..c7aee0ed 100644--- a/src/views/publish/children/pubRecord/components/PubRecordDetails.tsx+++ b/src/views/publish/children/pubRecord/components/PubRecordDetails.tsx@@ -165,10 +165,6 @@ const PubRecordDetails = memo(type="link"onClick={async () => {if (!v.dataId) return;- const videoFile = await getVideoFile(- (v as VideoModel).videoPath!,- );-const newState: IExamineVideo = {jsCode: '',open: true,@@ -176,6 +172,9 @@ const PubRecordDetails = memo(account,};if (account?.type === AccountType.WxSph) {+ const videoFile = await getVideoFile(+ (v as VideoModel).videoPath!,+ );newState['videoSrc'] = videoFile.videoUrl;} else {newState['url'] = v.previewVideoLink || '';