Let's use AI to Earn!
TypeScript auto-publishdouyindouyin-apielectron-appelectron-reactkuaishoukwaipublishedshipinhaotoolxiaohongshu
feat: 抖音调试之前
gaoSir0ebe8e46d9ec
diff --git a/electron/db/models/workData.ts b/electron/db/models/workData.tsindex f02481dd..ae317e0a 100644--- a/electron/db/models/workData.ts+++ b/electron/db/models/workData.ts@@ -195,4 +195,5 @@ export class WorkData extends TempModel {mentionedUserInfo!: ILableValue[];cookies?: CookiesType;+ proxyIp?: string;}diff --git a/electron/main/plat/platforms/Kwai/index.ts b/electron/main/plat/platforms/Kwai/index.tsindex d6b1c7c0..c5bf94f3 100644--- a/electron/main/plat/platforms/Kwai/index.ts+++ b/electron/main/plat/platforms/Kwai/index.ts@@ -89,6 +89,7 @@ export class Kwai extends PlatformBase {return new Promise(async (resolve) => {const result = await kwaiPub.pubVideo({+ proxy: params.proxyIp || '',publishTime: params.timingTime?.getTime(),mentions: params.mentionedUserInfo.map((v) => v.label),topics: params.topics || [],diff --git a/electron/main/plat/platforms/wxSph/index.ts b/electron/main/plat/platforms/wxSph/index.tsindex cb724f6b..0dc4081f 100644--- a/electron/main/plat/platforms/wxSph/index.ts+++ b/electron/main/plat/platforms/wxSph/index.ts@@ -346,6 +346,7 @@ export class WxSph extends PlatformBase {params.cookies!,params.videoPath!,{+ proxy: params.proxyIp || '',mixInfo: params.mixInfo? {mixId: `${params.mixInfo.value}`,diff --git a/electron/main/plat/platforms/xhs/index.ts b/electron/main/plat/platforms/xhs/index.tsindex 68ec73fa..1c68e370 100644--- a/electron/main/plat/platforms/xhs/index.ts+++ b/electron/main/plat/platforms/xhs/index.ts@@ -590,6 +590,7 @@ export class Xhs extends PlatformBase {pubParamsParse(params: WorkDataModel): XSLPlatformSettingType {return {+ proxy: params.proxyIp || '',cover: params.coverPath || '',desc: params.desc,title: params.title,diff --git a/electron/main/plat/pub/PubItemImgText.ts b/electron/main/plat/pub/PubItemImgText.tsindex 3fb136eb..51e36cdb 100644--- a/electron/main/plat/pub/PubItemImgText.ts+++ b/electron/main/plat/pub/PubItemImgText.ts@@ -67,6 +67,7 @@ export class PubItemImgText extends PubItemBase {* 更新图文记录*/async uploadRecord() {+ this.imgTextModel.proxyIp = undefined;EtEvent.emit('ET_PUBLISH_UPDATE_IMG_TEXT_PUL', this.imgTextModel);}}diff --git a/electron/main/plat/pub/PubItemVideo.ts b/electron/main/plat/pub/PubItemVideo.tsindex c61c5ff9..058a0e25 100644--- a/electron/main/plat/pub/PubItemVideo.ts+++ b/electron/main/plat/pub/PubItemVideo.ts@@ -92,6 +92,7 @@ export class PubItemVideo extends PubItemBase {* 更新视频记录*/async uploadRecord() {+ this.videoModel.proxyIp = undefined;EtEvent.emit('ET_PUBLISH_UPDATE_VIDEO_PUL', this.videoModel);}}diff --git a/electron/main/publish/imgText/controller.ts b/electron/main/publish/imgText/controller.tsindex b8fb99ab..29bcf277 100644--- a/electron/main/publish/imgText/controller.ts+++ b/electron/main/publish/imgText/controller.ts@@ -61,6 +61,16 @@ export class ImgTextPubController {imgTextModels.map((v) => v.accountId),);+ // 获取代理IP+ const groupModels = await this.accountService.getAccountGroup();+ for (let i = 0; i < accountList.length; i++) {+ const account = accountList[i];+ const group = groupModels.find((v) => v.id === account.groupId);+ if (group && group.proxyIp) {+ imgTextModels[i].proxyIp = group.proxyIp;+ }+ }+// 发布const pubRes = await platController.imgTextPublish(imgTextModels,diff --git a/electron/main/publish/video/controller.ts b/electron/main/publish/video/controller.tsindex 94824c18..8ac7482f 100644--- a/electron/main/publish/video/controller.ts+++ b/electron/main/publish/video/controller.ts@@ -70,6 +70,17 @@ export class VideoPubController {const accountList = await this.accountService.getAccountsByIds(videoList.map((v) => v.accountId),);++ // 获取代理IP+ const groupModels = await this.accountService.getAccountGroup();+ for (let i = 0; i < accountList.length; i++) {+ const account = accountList[i];+ const group = groupModels.find((v) => v.id === account.groupId);+ if (group && group.proxyIp) {+ videoList[i].proxyIp = group.proxyIp;+ }+ }+// 发布const pubRes = await platController.videoPublish(videoList, accountList);diff --git a/electron/plat/Kwai/index.ts b/electron/plat/Kwai/index.tsindex 598adb2f..e8bbe9c4 100644--- a/electron/plat/Kwai/index.ts+++ b/electron/plat/Kwai/index.ts@@ -89,6 +89,7 @@ class KwaiPub {body: {uploadType: 1,},+ proxy: params.proxy,});console.log('创建视频:', preRes);if (!preRes.data.data) {@@ -130,6 +131,7 @@ class KwaiPub {body: {uploadType: 1,},+ proxy: params.proxy,});console.log(`分片上传完成:`, completeRes.data);@@ -144,6 +146,7 @@ class KwaiPub {fileType: `video/${suffix}`,fileLength: filePartInfo.fileSize,},+ proxy: params.proxy,});if (finishRes.data.result !== 1)throw new Error(finishRes.data.message);@@ -161,6 +164,7 @@ class KwaiPub {url: '/rest/cp/works/v2/video/pc/upload/cover/upload',method: 'POST',cookie: params.cookies,+ proxy: params.proxy,});console.log('上传封面结果:', coverRes.data);@@ -206,6 +210,7 @@ class KwaiPub {method: 'POST',cookie: params.cookies,body: submitParams,+ proxy: params.proxy,});console.log(`视频发布完成:`, submitRes.data);console.log(submitRes.data.result);diff --git a/electron/plat/Kwai/kwai.type.ts b/electron/plat/Kwai/kwai.type.tsindex 95e91fcc..f0c1610a 100644--- a/electron/plat/Kwai/kwai.type.ts+++ b/electron/plat/Kwai/kwai.type.ts@@ -167,6 +167,8 @@ export interface IKwaiPubVideoParams {mentions?: string[];// 定时发布日期,时间戳,毫秒publishTime?: number;+ // 代理地址+ proxy: string;}// 登录返回参数diff --git a/electron/plat/requestNet.ts b/electron/plat/requestNet.tsindex 0d43a51e..f1ea72fe 100644--- a/electron/plat/requestNet.ts+++ b/electron/plat/requestNet.ts@@ -21,7 +21,7 @@ export interface IRequestNetParams {proxy?: string;}-const convertToProxyFormat = (url: string): string => {+export const convertToProxyFormat = (url: string): string => {const urlPattern = /^(https?):\/\/([^:\/]+(:\d+)?)(\/.*)?$/; // 匹配协议、域名/IP 和端口号const ipPattern = /^\d{1,3}(\.\d{1,3}){3}(:\d+)?$/; // 匹配 IP 地址格式以及可选端口号@@ -49,41 +49,47 @@ const requestNet = <T = any>({}: IRequestNetParams): Promise<IRequestNetResult<T>> => {return new Promise(async (resolve, reject) => {try {- const customSession: Session = session.fromPartition(- `persist:proxy-session-${Date.now()}`,- );+ // let customSession: Session;// 如果传入了代理配置,动态设置代理- if (proxy) {- const proxyFormat = convertToProxyFormat(proxy);- console.log('代理地址:', proxyFormat);- await customSession.setProxy({ proxyRules: proxyFormat });- }+ // if (proxy) {+ // const proxyFormat = convertToProxyFormat(proxy);+ // console.log('代理地址:', proxyFormat);+ // customSession = session.fromPartition(+ // `persist:proxy-session-${Date.now()}`,+ // );+ // await customSession.setProxy({ proxyRules: proxyFormat });+ //+ // headers = {+ // ...(headers ? headers : {}),+ // ...(proxy+ // ? {+ // 'x-forwarded-for': proxy,+ // }+ // : {}),+ // };+ // }+ //+ // if (formData) {+ // headers = {+ // ...(headers ? headers : {}),+ // ...formData.getHeaders(),+ // };+ // }const req = net.request({method: method || 'GET',url,// 如果有代理,使用自定义 session- session: proxy ? customSession : undefined,+ // session: proxy ? customSession! : undefined,+ headers,});- if (formData) {- headers = {- ...(headers ? headers : {}),- ...formData.getHeaders(),- ...(proxy- ? {- 'x-forwarded-for': proxy,- }- : {}),- };- }-// 设置请求头if (headers) {- Object.entries(headers).forEach(([key, value]) => {- req.setHeader(key, value as string);- });+ // Object.entries(headers).forEach(([key, value]) => {+ // req.setHeader(key, value as string);+ // });}// 处理响应@@ -123,24 +129,28 @@ const requestNet = <T = any>({reject(error);});- if (formData) {- formData.pipe(req as any);- const cReq = formData.submit(url!, (err, res) => {- cReq.end();- });- } else {- if (isFile) {- req.setHeader('Content-Type', 'application/octet-stream');- req.write(body);- } else {- // 发送请求体- if (body) {- req.setHeader('Content-Type', 'application/json');- req.write(typeof body === 'string' ? body : JSON.stringify(body));- }- }- req.end();+ if (body) {+ req.write(typeof body === 'string' ? body : JSON.stringify(body));+ // if (formData) {+ // formData.pipe(req as any);+ // const cReq = formData.submit(url!, (err, res) => {+ // cReq.end();+ // });+ // } else {+ // if (isFile) {+ // req.setHeader('Content-Type', 'application/octet-stream');+ // req.write(body);+ // } else {+ // // 发送请求体+ // if (body) {+ // req.setHeader('Content-Type', 'application/json');+ // req.write(typeof body === 'string' ? body : JSON.stringify(body));+ // }+ // }+ // }}++ req.end();} catch (error) {reject(error);}diff --git a/electron/plat/shipinhao/index.ts b/electron/plat/shipinhao/index.tsindex ef486c7e..0a0fa69f 100644--- a/electron/plat/shipinhao/index.ts+++ b/electron/plat/shipinhao/index.ts@@ -1,4 +1,4 @@-import { screen, BrowserWindow, net, session } from 'electron';+import { screen, BrowserWindow, session } from 'electron';import { CommonUtils } from '../../util/common';import path from 'path';import { FileUtils } from '../../util/file';@@ -119,15 +119,19 @@ export class ShipinhaoService {return new Promise(async (resolve, reject) => {const cookieString = CommonUtils.convertCookieToJson(cookies);try {- const res = await this.makeRequest(this.getUserInfoUrl, {- method: 'POST',- headers: {- Origin: 'https://channels.weixin.qq.com',- Referer: 'https://channels.weixin.qq.com/platform',- Cookie: cookieString,+ const res = await this.makeRequest(+ this.getUserInfoUrl,+ {+ method: 'POST',+ headers: {+ Origin: 'https://channels.weixin.qq.com',+ Referer: 'https://channels.weixin.qq.com/platform',+ Cookie: cookieString,+ },+ timeout: 15000,},- timeout: 15000,- });+ '',+ );if (res.errCode === 0) {resolve({authorId: res.data.finderUser.uniqId ?? '',@@ -194,22 +198,26 @@ export class ShipinhaoService {).toString();try {- const res = await this.makeRequest(this.getDashboardUrl, {- method: 'POST',- headers: {- 'Content-Type': 'application/json',- Origin: 'https://channels.weixin.qq.com',- Referer: 'https://channels.weixin.qq.com/platform',- Cookie: cookieString,- },- timeout: 15000,- data: {- endTs,- interval: 3,- startTs,- timestamp: new Date().getTime(),+ const res = await this.makeRequest(+ this.getDashboardUrl,+ {+ method: 'POST',+ headers: {+ 'Content-Type': 'application/json',+ Origin: 'https://channels.weixin.qq.com',+ Referer: 'https://channels.weixin.qq.com/platform',+ Cookie: cookieString,+ },+ timeout: 15000,+ data: {+ endTs,+ interval: 3,+ startTs,+ timestamp: new Date().getTime(),+ },},- });+ '',+ );if (res.errCode === 0) {if (endDate && startDate) {@@ -462,15 +470,19 @@ export class ShipinhaoService {async checkLoginStatus(cookies: string): Promise<boolean> {const cookieString = CommonUtils.convertCookieToJson(cookies);try {- const res = await this.makeRequest(this.getUserInfoUrl, {- method: 'POST',- headers: {- Origin: 'https://channels.weixin.qq.com',- Referer: 'https://channels.weixin.qq.com/platform',- Cookie: cookieString,+ const res = await this.makeRequest(+ this.getUserInfoUrl,+ {+ method: 'POST',+ headers: {+ Origin: 'https://channels.weixin.qq.com',+ Referer: 'https://channels.weixin.qq.com/platform',+ Cookie: cookieString,+ },+ timeout: 15000,},- timeout: 15000,- });+ '',+ );return res.errCode === 0;} catch (err) {console.log('-------- checkLoginStatus error ---', err);@@ -481,44 +493,24 @@ export class ShipinhaoService {/*** 通用请求方法*/- private async makeRequest(url: string, options: any): Promise<any> {- return new Promise((resolve, reject) => {- const request = net.request({- method: options.method,- url: url,- headers: options.headers,- });-- // 发送请求体- if (options.data) {- request.write(- typeof options.data === 'string'- ? options.data- : JSON.stringify(options.data),- );- }-- request.on('response', (response) => {- let data = '';- response.on('data', (chunk) => {- data += chunk;- });- response.on('end', () => {- const result = JSON.parse(data);- if (result) {- resolve(result);- } else {- console.error('Request failed:', result);- reject(new Error(result.msg || 'Request failed'));- }+ private async makeRequest(+ url: string,+ options: any,+ proxy: string,+ ): Promise<any> {+ return new Promise(async (resolve, reject) => {+ try {+ const res = await requestNet({+ url: url,+ method: options.method,+ headers: options.headers,+ body: options.data,+ proxy,});- });-- request.on('error', (error) => {- console.error('Request error:', error);- reject(error);- });- request.end();+ resolve(res.data);+ } catch (e) {+ reject(e);+ }});}@@ -528,49 +520,29 @@ export class ShipinhaoService {* @param fileContent 文件内容* @param headers 请求头* @param method HTTP 方法+ * @param proxy*/private async uploadFile(url: string,fileContent: Buffer,headers: any,method: string = 'PUT',+ proxy: string,): Promise<any> {- return new Promise((resolve, reject) => {- const request = net.request({- method: method,- url: url,- headers: headers,- });-- request.on('response', (response) => {- let data = '';- response.on('data', (chunk) => {- data += chunk;- });-- response.on('end', () => {- try {- const result = data ? JSON.parse(data) : {};- resolve(result);- } catch (err) {- console.error('解析响应数据失败:', err);- resolve(response);- }- });- });-- request.on('error', (error) => {- console.error('请求出错:', error);- reject(error);- });-- // 写入请求体+ return new Promise(async (resolve, reject) => {try {- request.write(fileContent);- request.end();- } catch (err) {- console.error('写入请求体时出错:', err);- reject(err);+ const res = await requestNet({+ url: url,+ method: method as 'POST',+ isFile: true,+ headers: headers,+ body: fileContent,+ proxy,+ });+ resolve(res.data);+ } catch (e) {+ console.error('上传文件失败:', e);+ reject(e);}});}@@ -592,8 +564,12 @@ export class ShipinhaoService {/*** 获取发布TraceKey* @param cookieString+ * @param proxy*/- private async getPublishTraceKey(cookieString: string): Promise<string> {+ private async getPublishTraceKey(+ cookieString: string,+ proxy: string,+ ): Promise<string> {const requestParams = {objectId: '',pluginSessionId: null,@@ -602,13 +578,17 @@ export class ShipinhaoService {scene: 7,};- const res = await this.makeRequest(this.getPublishTraceKeyUrl, {- method: 'POST',- headers: {- Cookie: cookieString,+ const res = await this.makeRequest(+ this.getPublishTraceKeyUrl,+ {+ method: 'POST',+ headers: {+ Cookie: cookieString,+ },+ body: requestParams,},- body: requestParams,- });+ proxy,+ );if (res.errCode === 0) {return res.data.traceKey;@@ -620,20 +600,28 @@ export class ShipinhaoService {/*** 获取发布上传参数* @param cookieString+ * @param proxy*/- private async getPublishUploadParams(cookieString: string): Promise<any> {+ private async getPublishUploadParams(+ cookieString: string,+ proxy: string,+ ): Promise<any> {const requestParams = {reqScene: 7,scene: 7,};- const res = await this.makeRequest(this.getPublishUploadParamsUrl, {- method: 'POST',- headers: {- Cookie: cookieString,+ const res = await this.makeRequest(+ this.getPublishUploadParamsUrl,+ {+ method: 'POST',+ headers: {+ Cookie: cookieString,+ },+ body: requestParams,},- body: requestParams,- });+ proxy,+ );if (res.errCode === 0) {return res.data;@@ -647,11 +635,13 @@ export class ShipinhaoService {* @param filePath* @param uploadParams* @param filePartInfo+ * @param proxy*/private async uploadVideoFile(filePath: string,uploadParams: any,filePartInfo: any,+ proxy: string,): Promise<string> {try {// 拼接请求参数@@ -684,6 +674,8 @@ export class ShipinhaoService {'Content-Type': 'application/json','X-Arguments': uploadArgumentsString,},+ undefined,+ proxy,);if (!uploadIdRes.UploadID) {@@ -715,11 +707,17 @@ export class ShipinhaoService {// 开始上传const uploadUrl = `${this.uploadpartdfsUrl}?UploadID=${uploadId}&PartNumber=${i + 1}&QuickUpload=2`;- const uploadPartRes = await this.uploadFile(uploadUrl, chunkContent, {- Authorization: uploadParams.authKey,- 'X-Arguments': uploadArgumentsString,- 'Content-Type': 'application/octet-stream',- });+ const uploadPartRes = await this.uploadFile(+ uploadUrl,+ chunkContent,+ {+ Authorization: uploadParams.authKey,+ 'X-Arguments': uploadArgumentsString,+ 'Content-Type': 'application/octet-stream',+ },+ undefined,+ proxy,+ );if (!uploadPartRes?.ETag) {errorMsg =@@ -755,6 +753,8 @@ export class ShipinhaoService {'Content-Type': 'application/json','X-Arguments': uploadArgumentsString,},+ undefined,+ proxy,);if (!uploadCompleteRes.DownloadURL) {@@ -779,6 +779,7 @@ export class ShipinhaoService {private async uploadCoverFile(filePath: string,uploadParams: any,+ proxy: string,): Promise<string> {try {const fileRes = await getFileContent(filePath);@@ -816,6 +817,8 @@ export class ShipinhaoService {'Content-Type': 'application/json','X-Arguments': uploadArgumentsString,},+ undefined,+ proxy,);if (!uploadIdRes.UploadID) {@@ -834,6 +837,8 @@ export class ShipinhaoService {'X-Arguments': uploadArgumentsString,'Content-Type': 'application/octet-stream',},+ undefined,+ proxy,);if (!uploadPartRes.ETag) {@@ -865,6 +870,8 @@ export class ShipinhaoService {'Content-Type': 'application/json','X-Arguments': uploadArgumentsString,},+ undefined,+ proxy,);if (!uploadCompleteRes.DownloadURL) {@@ -889,6 +896,7 @@ export class ShipinhaoService {fileInfo: any,filePartInfo: any,cookieString: string,+ proxy: string,): Promise<any> {return new Promise(async (resolve, reject) => {try {@@ -910,44 +918,48 @@ export class ShipinhaoService {reject('提交剪辑失败,失败原因:视频时长不能小于3秒!');return;}- const postClipVideoRes = await this.makeRequest(this.postClipVideoUrl, {- method: 'POST',- headers: {- Cookie: cookieString,- 'Content-Type': 'application/json',- },- data: {- clipOriginVideoInfo: {+ const postClipVideoRes = await this.makeRequest(+ this.postClipVideoUrl,+ {+ method: 'POST',+ headers: {+ Cookie: cookieString,+ 'Content-Type': 'application/json',+ },+ data: {+ clipOriginVideoInfo: {+ width: videoInfos.width,+ height: videoInfos.height,+ fileSize: fileInfo.format.size ?? 0,+ duration: videoInfos.duration,+ },+ cropDuration: 0,width: videoInfos.width,height: videoInfos.height,- fileSize: fileInfo.format.size ?? 0,- duration: videoInfos.duration,- },- cropDuration: 0,- width: videoInfos.width,- height: videoInfos.height,- pluginSessionId: null,- rawKeyBuff: null,- reqScene: 7,- scene: 7,- targetWidth: videoInfos.height,- targetHeight: videoInfos.width,- timeStart: 0,- timestamp: Date.now(),- traceInfo: {- traceKey: traceKey,- uploadCdnStart: startUploadTime,- uploadCdnEnd: endUploadTime,+ pluginSessionId: null,+ rawKeyBuff: null,+ reqScene: 7,+ scene: 7,+ targetWidth: videoInfos.height,+ targetHeight: videoInfos.width,+ timeStart: 0,+ timestamp: Date.now(),+ traceInfo: {+ traceKey: traceKey,+ uploadCdnStart: startUploadTime,+ uploadCdnEnd: endUploadTime,+ },+ type: 4,+ url: remoteFileUrl,+ useAstraThumbCover: 0,+ x: 0,+ y: 0,},- type: 4,- url: remoteFileUrl,- useAstraThumbCover: 0,- x: 0,- y: 0,+ dataType: 'json',+ timeout: 15000,},- dataType: 'json',- timeout: 15000,- });+ proxy,+ );if (postClipVideoRes.errCode !== 0) {reject('提交剪辑失败,失败原因:' + postClipVideoRes.errMsg);return;@@ -985,6 +997,7 @@ export class ShipinhaoService {endUploadTime: number,clipResult: any,platformSetting: any,+ proxy: string,): Promise<{lastPublishId: string;previewVideoLink: string;@@ -1114,16 +1127,20 @@ export class ShipinhaoService {);}// 发起请求- const createRes = await this.makeRequest(this.postCreateVideoUrl, {- method: 'POST',- headers: {- Cookie: cookieString,- 'Content-Type': 'application/json',+ const createRes = await this.makeRequest(+ this.postCreateVideoUrl,+ {+ method: 'POST',+ headers: {+ Cookie: cookieString,+ 'Content-Type': 'application/json',+ },+ data: JSON.stringify(requestData),+ dataType: 'json',+ timeout: 15000,},- data: JSON.stringify(requestData),- dataType: 'json',- timeout: 15000,- });+ proxy,+ );if (createRes.errCode !== 0) {reject('发布失败,失败原因:' + createRes.errMsg);return;@@ -1158,21 +1175,25 @@ export class ShipinhaoService {lastPublishId: string;previewVideoLink: string;}> {- const workListRes = await this.makeRequest(this.getUserWorkListUrl, {- method: 'POST',- headers: {- Cookie: cookieString,- 'Content-Type': 'application/json',- },- data: {- pageSize: 20,- currentPage: 1,- rawKeyBuff: null,- pluginSessionId: null,- scene: 7,- reqScene: 7,+ const workListRes = await this.makeRequest(+ this.getUserWorkListUrl,+ {+ method: 'POST',+ headers: {+ Cookie: cookieString,+ 'Content-Type': 'application/json',+ },+ data: {+ pageSize: 20,+ currentPage: 1,+ rawKeyBuff: null,+ pluginSessionId: null,+ scene: 7,+ reqScene: 7,+ },},- });+ '',+ );let work;if (workListRes.errCode === 0) {@@ -1196,6 +1217,7 @@ export class ShipinhaoService {nonceId: work.objectNonce,},},+ '',);return {@@ -1242,6 +1264,7 @@ export class ShipinhaoService {};// 0=非原创 1=原创postFlag: 0 | 1;+ proxy: string;},callback: (progress: number, msg?: string) => void,): Promise<{@@ -1259,9 +1282,15 @@ export class ShipinhaoService {callback(10);const cookieString = CommonUtils.convertCookieToJson(cookies);callback(15);- const traceKey = await this.getPublishTraceKey(cookieString);+ const traceKey = await this.getPublishTraceKey(+ cookieString,+ platformSetting.proxy,+ );callback(20);- const uploadParams = await this.getPublishUploadParams(cookieString);+ const uploadParams = await this.getPublishUploadParams(+ cookieString,+ platformSetting.proxy,+ );callback(26);const filePartInfo = await FileUtils.getFilePartInfo(filePath,@@ -1272,6 +1301,7 @@ export class ShipinhaoService {filePath,uploadParams,filePartInfo,+ platformSetting.proxy,);callback(30);const endUploadTime = Math.floor(Date.now() / 1000);@@ -1285,11 +1315,13 @@ export class ShipinhaoService {fileInfo,filePartInfo,cookieString,+ platformSetting.proxy,);callback(60, '正在上传封面...');platformSetting.cover = await this.uploadCoverFile(platformSetting.cover,uploadParams,+ platformSetting.proxy,);callback(80, '正在发布视频...');@@ -1307,6 +1339,7 @@ export class ShipinhaoService {endUploadTime,clipResult,lastParams,+ platformSetting.proxy,);callback(100);diff --git a/electron/plat/xiaohongshu/index.ts b/electron/plat/xiaohongshu/index.tsindex bfdb3d38..6a00d689 100644--- a/electron/plat/xiaohongshu/index.ts+++ b/electron/plat/xiaohongshu/index.ts@@ -43,6 +43,7 @@ export type XSLPlatformSettingType = {cover: string;// 0 公共 1 私密 4 好友visibility_type: 0 | 1 | 4;+ proxy: string;};const esec_token = 'ABrmhLmsdmsu9bCQ80qvGPN2CYSjEqwi5G1l2dirNUjaw%3D';@@ -234,21 +235,29 @@ export class XiaohongshuService {.map((cookie) => `${cookie.name}=${cookie.value}`).join('; ');- const userInfo = await this.makeRequest(this.getUserInfoUrl, {- method: 'GET',- headers: {- Cookie: cookieString,- Referer: this.loginUrl,+ const userInfo = await this.makeRequest(+ this.getUserInfoUrl,+ {+ method: 'GET',+ headers: {+ Cookie: cookieString,+ Referer: this.loginUrl,+ },},- });+ '',+ );- const fansInfo = await this.makeRequest(this.getFansInfoUrl, {- method: 'GET',- headers: {- Cookie: cookieString,- Referer: this.loginUrl,+ const fansInfo = await this.makeRequest(+ this.getFansInfoUrl,+ {+ method: 'GET',+ headers: {+ Cookie: cookieString,+ Referer: this.loginUrl,+ },},- });+ '',+ );return {authorId: userInfo.data.user_id || '',@@ -284,18 +293,22 @@ export class XiaohongshuService {a1: cookie_a1,});- const userInfo = await this.makeRequest(this.getDashboardUrl, {- method: 'GET',- headers: {- 'Content-Type': 'application/json;charset=UTF-8',- Cookie: cookieString,- Referer: 'https://creator.xiaohongshu.com/statistics/account',- userAgent:- 'Mozilla/5.0 (Windows NT 10.0; Win64; x64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/100.0.4896.75 Safari/537.36 Edg/100.0.1185.36',- 'X-S': reverseRes['X-s'],- 'X-T': reverseRes['X-t'],+ const userInfo = await this.makeRequest(+ this.getDashboardUrl,+ {+ method: 'GET',+ headers: {+ 'Content-Type': 'application/json;charset=UTF-8',+ Cookie: cookieString,+ Referer: 'https://creator.xiaohongshu.com/statistics/account',+ userAgent:+ 'Mozilla/5.0 (Windows NT 10.0; Win64; x64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/100.0.4896.75 Safari/537.36 Edg/100.0.1185.36',+ 'X-S': reverseRes['X-s'],+ 'X-T': reverseRes['X-t'],+ },},- });+ '',+ );if (userInfo.code == 0) {if (startDate && endDate) {@@ -380,45 +393,24 @@ export class XiaohongshuService {/*** 通用请求方法*/- private async makeRequest(url: string, options: any): Promise<any> {- return new Promise((resolve, reject) => {- const request = net.request({- method: options.method,- url: url,- headers: options.headers,- });-- // 发送请求体- if (options.data) {- // request.setHeader('Content-Type', 'application/json');- request.write(- typeof options.data === 'string'- ? options.data- : JSON.stringify(options.data),- );- }-- request.on('response', (response) => {- let data = '';- response.on('data', (chunk) => {- data += chunk;- });- response.on('end', () => {- const result = JSON.parse(data);- if (result) {- resolve(result);- } else {- console.error('Request failed:', result);- reject(new Error(result.msg || 'Request failed'));- }+ private async makeRequest(+ url: string,+ options: any,+ proxy: string,+ ): Promise<any> {+ return new Promise(async (resolve, reject) => {+ try {+ const res = await requestNet({+ url: url,+ method: options.method,+ headers: options.headers,+ body: options.data,+ proxy,});- });-- request.on('error', (error) => {- console.error('Request error:', error);- reject(error);- });- request.end();+ resolve(res.data);+ } catch (e) {+ reject(e);+ }});}@@ -427,7 +419,7 @@ export class XiaohongshuService {* @param cookieString* @param scene*/- async getUploadPermit(cookieString: string, scene: string) {+ async getUploadPermit(cookieString: string, scene: string, proxy: string) {return new Promise(async (resolve, reject) => {try {const permitRes = await this.makeRequest(@@ -440,6 +432,7 @@ export class XiaohongshuService {Referer: this.loginUrl,},},+ proxy,);if (permitRes.code !== 0) {@@ -467,29 +460,29 @@ export class XiaohongshuService {* @param url 上传地址* @param fileContent 文件内容* @param headers 请求头+ * @param proxy*/private async uploadFile(url: string,fileContent: Buffer,headers: any,+ proxy: string,): Promise<any> {- return new Promise((resolve, reject) => {- const request = net.request({- method: 'PUT',- url: url,- headers: headers,- });-- request.on('response', (response) => {- resolve(response);- });-- request.on('error', (error) => {- reject(error);- });-- request.write(fileContent);- request.end();+ return new Promise(async (resolve, reject) => {+ try {+ const res = await requestNet({+ url: url,+ method: 'PUT',+ headers: headers,+ isFile: true,+ body: fileContent,+ proxy,+ });+ resolve(res);+ } catch (e) {+ console.error('上传文件失败:', e);+ reject(e);+ }});}@@ -501,6 +494,7 @@ export class XiaohongshuService {async uploadCoverFile(cookieString: string,filePath: string,+ proxy: string,): Promise<{coverUploadFileId: string;coverDimensions: any;@@ -512,6 +506,7 @@ export class XiaohongshuService {const uploadPermit: any = await this.getUploadPermit(cookieString,'image',+ proxy,);const coverUploadFileId = uploadPermit[0].fileIds[0];const uploadAddr = uploadPermit[0].uploadAddr;@@ -525,10 +520,15 @@ export class XiaohongshuService {const coverDimensions = sizeOf(fileContent);// 直接上传- let uploadRes = await this.uploadFile(uploadBaseUrl, fileContent, {- Referer: this.loginUrl,- 'X-Cos-Security-Token': uploadToken,- });+ let uploadRes = await this.uploadFile(+ uploadBaseUrl,+ fileContent,+ {+ Referer: this.loginUrl,+ 'X-Cos-Security-Token': uploadToken,+ },+ proxy,+ );uploadRes = uploadRes.headers;@@ -612,6 +612,7 @@ export class XiaohongshuService {filePath: string,filePartInfo: any,fileInfo: any,+ proxy: string,): Promise<{uploadFileId: string;remotePreviewUrl: string;@@ -623,6 +624,7 @@ export class XiaohongshuService {const uploadPermit: any = await this.getUploadPermit(cookieString,'video',+ proxy,);const uploadFileId = uploadPermit[0].fileIds[0];const uploadAddr = uploadPermit[0].uploadAddr;@@ -640,11 +642,16 @@ export class XiaohongshuService {filePartInfo.fileSize - 1,);// 直接上传- let uploadRes = await this.uploadFile(uploadBaseUrl, fileContent, {- 'Content-Type': fileInfo.mimeType,- Referer: this.loginUrl,- 'X-Cos-Security-Token': uploadToken,- });+ let uploadRes = await this.uploadFile(+ uploadBaseUrl,+ fileContent,+ {+ 'Content-Type': fileInfo.mimeType,+ Referer: this.loginUrl,+ 'X-Cos-Security-Token': uploadToken,+ },+ proxy,+ );uploadRes = uploadRes.headers;if (@@ -716,6 +723,7 @@ export class XiaohongshuService {Referer: this.loginUrl,'X-Cos-Security-Token': uploadToken,},+ proxy,);const headers = uploadPartRes.headers;@@ -821,7 +829,11 @@ export class XiaohongshuService {const uploadImgRet = [];for (const imgUrl of imagePath) {// 上传图片, 获取远程Url- const imgRet = await this.uploadCoverFile(cookieString, imgUrl);+ const imgRet = await this.uploadCoverFile(+ cookieString,+ imgUrl,+ platformSetting.proxy,+ );// 添加到成功列表uploadImgRet.push(imgRet);}@@ -848,6 +860,7 @@ export class XiaohongshuService {'image',uploadResult,platformSetting,+ platformSetting.proxy,)) as any;// 返回信息resolve({@@ -868,6 +881,7 @@ export class XiaohongshuService {* @param publishType* @param uploadResult {uploadFileId, uploadCoverId, coverDimensions, fileInfo}* @param platformSetting+ * @param proxy* @returns {Promise<unknown>}*/async postCreateVideo(@@ -876,6 +890,7 @@ export class XiaohongshuService {publishType: 'video' | 'image',uploadResult: any,platformSetting: any,+ proxy: string,) {return new Promise(async (resolve, reject) => {try {@@ -1129,19 +1144,23 @@ export class XiaohongshuService {a1: cookie_a1,});// 发起请求- const createRes = await this.makeRequest(this.postCreateVideoUrl, {- method: 'POST',- headers: {- 'Content-Type': 'application/json;charset=UTF-8',- Cookie: cookieString,- Referer: this.loginUrl,- Origin: this.loginUrl,- 'X-S': reverseRes['X-s'],- 'X-T': reverseRes['X-t'],+ const createRes = await this.makeRequest(+ this.postCreateVideoUrl,+ {+ method: 'POST',+ headers: {+ 'Content-Type': 'application/json;charset=UTF-8',+ Cookie: cookieString,+ Referer: this.loginUrl,+ Origin: this.loginUrl,+ 'X-S': reverseRes['X-s'],+ 'X-T': reverseRes['X-t'],+ },+ data: JSON.stringify(requestData),+ timeout: 15000,},- data: JSON.stringify(requestData),- timeout: 15000,- });+ platformSetting.proxy,+ );// 处理结果if (createRes.hasOwnProperty('code') && createRes.code === -1) {@@ -1225,12 +1244,17 @@ export class XiaohongshuService {filePath,filePartInfo,fileInfo,+ platformSetting.proxy,);callback(60, '正在上传封面...');// 上传封面,获取远程Urlconst { coverDimensions, coverUploadFileId } =- await this.uploadCoverFile(cookieString, platformSetting['cover']);+ await this.uploadCoverFile(+ cookieString,+ platformSetting['cover'],+ platformSetting.proxy,+ );const cookieObject = JSON.parse(cookies);let cookie_a1 = null;for (const cookieItem of cookieObject) {@@ -1259,9 +1283,11 @@ export class XiaohongshuService {'video',uploadResult,platformSetting,+ platformSetting.proxy,).catch((err) => {reject(err);});+ console.log(result);// 返回信息resolve({publishTime: Math.floor(Date.now() / 1000),@@ -1299,14 +1325,18 @@ export class XiaohongshuService {*/getReverseResult(args: any) {return new Promise(async (resolve, reject) => {- const permitRes = await this.makeRequest('http://116.62.154.231:7879', {- method: 'POST',- headers: {- 'Content-Type': 'application/json;charset=UTF-8',+ const permitRes = await this.makeRequest(+ 'http://116.62.154.231:7879',+ {+ method: 'POST',+ headers: {+ 'Content-Type': 'application/json;charset=UTF-8',+ },+ data: args,+ timeout: 15000,},- data: args,- timeout: 15000,- });+ '',+ );resolve(permitRes);});}