@posty5/social-publisher-post 2.0.0
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/README.md +957 -0
- package/dist/index.d.mts +835 -0
- package/dist/index.d.ts +835 -0
- package/dist/index.js +444 -0
- package/dist/index.js.map +1 -0
- package/dist/index.mjs +442 -0
- package/dist/index.mjs.map +1 -0
- package/package.json +62 -0
package/dist/index.js
ADDED
|
@@ -0,0 +1,444 @@
|
|
|
1
|
+
'use strict';
|
|
2
|
+
|
|
3
|
+
var core = require('@posty5/core');
|
|
4
|
+
|
|
5
|
+
// src/social-publisher-post.client.ts
|
|
6
|
+
var SocialPublisherPostClient = class {
|
|
7
|
+
constructor(http) {
|
|
8
|
+
this.basePath = "/api/social-publisher-post";
|
|
9
|
+
this.http = http;
|
|
10
|
+
this.maxVideoUploadSizeBytes = 2147483648;
|
|
11
|
+
this.maxImageUploadSizeBytes = 1073741824;
|
|
12
|
+
}
|
|
13
|
+
/**
|
|
14
|
+
* Search posts
|
|
15
|
+
* @param params - Search parameters (optional)
|
|
16
|
+
* @param pagination - Pagination parameters
|
|
17
|
+
*/
|
|
18
|
+
async list(params, pagination) {
|
|
19
|
+
const response = await this.http.get(this.basePath, {
|
|
20
|
+
params: {
|
|
21
|
+
...params,
|
|
22
|
+
...pagination
|
|
23
|
+
}
|
|
24
|
+
});
|
|
25
|
+
return response.result;
|
|
26
|
+
}
|
|
27
|
+
/**
|
|
28
|
+
* Get default settings
|
|
29
|
+
*/
|
|
30
|
+
async getDefaultSettings() {
|
|
31
|
+
const response = await this.http.get(`${this.basePath}/default-settings`);
|
|
32
|
+
return response.result;
|
|
33
|
+
}
|
|
34
|
+
/**
|
|
35
|
+
* Get post status
|
|
36
|
+
* @param id - Post ID
|
|
37
|
+
*/
|
|
38
|
+
async getStatus(id) {
|
|
39
|
+
const response = await this.http.get(`${this.basePath}/${id}/status`);
|
|
40
|
+
return response.result;
|
|
41
|
+
}
|
|
42
|
+
/**
|
|
43
|
+
* Generate upload signed URLs for video and thumbnail
|
|
44
|
+
* @param data - File information
|
|
45
|
+
*/
|
|
46
|
+
async generateUploadUrls(data) {
|
|
47
|
+
const response = await this.http.post(`${this.basePath}/generate-upload-urls`, data);
|
|
48
|
+
return response.result;
|
|
49
|
+
}
|
|
50
|
+
/**
|
|
51
|
+
* Get next and previous post IDs
|
|
52
|
+
* @param id - Current Post ID
|
|
53
|
+
*/
|
|
54
|
+
async getNextAndPrevious(id) {
|
|
55
|
+
const response = await this.http.get(`${this.basePath}/${id}/next-previous`);
|
|
56
|
+
return response.result;
|
|
57
|
+
}
|
|
58
|
+
/**
|
|
59
|
+
* Create a new post (publish video)
|
|
60
|
+
* @param data - Post creation data
|
|
61
|
+
* @param id - Optional ID for updating/retrying? (Based on route :id?)
|
|
62
|
+
*/
|
|
63
|
+
async createToWorkspaceByFile(data, id) {
|
|
64
|
+
const url = id ? `${this.basePath}/short-video/workspace/by-file/${id}` : `${this.basePath}/short-video/workspace/by-file`;
|
|
65
|
+
const response = await this.http.post(url, {
|
|
66
|
+
...data,
|
|
67
|
+
createdFrom: "npmPackage"
|
|
68
|
+
});
|
|
69
|
+
return response.result?._id;
|
|
70
|
+
}
|
|
71
|
+
/**
|
|
72
|
+
* Create a new post (publish video)
|
|
73
|
+
* @param data - Post creation data
|
|
74
|
+
* @param id - Optional ID for updating/retrying? (Based on route :id?)
|
|
75
|
+
*/
|
|
76
|
+
async createToWorkspaceByURL(data, id) {
|
|
77
|
+
const url = id ? `${this.basePath}/short-video/workspace/by-url/${id}` : `${this.basePath}/short-video/workspace/by-url`;
|
|
78
|
+
const response = await this.http.post(url, {
|
|
79
|
+
...data,
|
|
80
|
+
createdFrom: "npmPackage"
|
|
81
|
+
});
|
|
82
|
+
return response.result?._id;
|
|
83
|
+
}
|
|
84
|
+
/**
|
|
85
|
+
* Create a new post (publish video to account)
|
|
86
|
+
* @param data - Post creation data
|
|
87
|
+
* @param id - Optional ID for updating/retrying?
|
|
88
|
+
*/
|
|
89
|
+
async createToAccountByFile(data, id) {
|
|
90
|
+
const url = id ? `${this.basePath}/short-video/account/by-file/${id}` : `${this.basePath}/short-video/account/by-file`;
|
|
91
|
+
const response = await this.http.post(url, {
|
|
92
|
+
...data,
|
|
93
|
+
createdFrom: "npmPackage"
|
|
94
|
+
});
|
|
95
|
+
return response.result?._id;
|
|
96
|
+
}
|
|
97
|
+
/**
|
|
98
|
+
* Create a new post (publish video to account)
|
|
99
|
+
* @param data - Post creation data
|
|
100
|
+
* @param id - Optional ID for updating/retrying?
|
|
101
|
+
*/
|
|
102
|
+
async createToAccountByURL(data, id) {
|
|
103
|
+
const url = id ? `${this.basePath}/short-video/account/by-url/${id}` : `${this.basePath}/short-video/account/by-url`;
|
|
104
|
+
const response = await this.http.post(url, {
|
|
105
|
+
...data,
|
|
106
|
+
createdFrom: "npmPackage"
|
|
107
|
+
});
|
|
108
|
+
return response.result?._id;
|
|
109
|
+
}
|
|
110
|
+
/**
|
|
111
|
+
* Handle thumbnail upload - accepts either File or URL string
|
|
112
|
+
* @param thumb - Thumbnail as File (will be uploaded) or URL string (will be passed directly)
|
|
113
|
+
* @returns Thumbnail URL or undefined
|
|
114
|
+
*/
|
|
115
|
+
async handleThumbnailUpload(thumb, uploadUrlsResponse) {
|
|
116
|
+
if (!thumb) {
|
|
117
|
+
return void 0;
|
|
118
|
+
}
|
|
119
|
+
if (typeof thumb === "string") {
|
|
120
|
+
const urlPattern = /(http:\/\/)..*|(https:\/\/)..*/gi;
|
|
121
|
+
if (!urlPattern.test(thumb)) {
|
|
122
|
+
throw new Error("Invalid thumbnail URL format");
|
|
123
|
+
}
|
|
124
|
+
return { thumbFileURL: thumb, postId: void 0 };
|
|
125
|
+
}
|
|
126
|
+
if (thumb instanceof File) {
|
|
127
|
+
if (thumb.size > this.maxImageUploadSizeBytes) {
|
|
128
|
+
throw new Error(`Thumbnail file size (${thumb.size} bytes) exceeds maximum allowed size (${this.maxImageUploadSizeBytes} bytes)`);
|
|
129
|
+
}
|
|
130
|
+
if (!uploadUrlsResponse) {
|
|
131
|
+
uploadUrlsResponse = await this.generateUploadUrls({
|
|
132
|
+
thumbFileType: thumb.type
|
|
133
|
+
});
|
|
134
|
+
}
|
|
135
|
+
if (uploadUrlsResponse.thumb.uploadFileURL) {
|
|
136
|
+
await core.uploadToR2(uploadUrlsResponse.thumb.uploadFileURL, thumb, {
|
|
137
|
+
contentType: thumb.type
|
|
138
|
+
});
|
|
139
|
+
return { thumbFileURL: uploadUrlsResponse.thumb.fileURL, postId: uploadUrlsResponse.postId };
|
|
140
|
+
}
|
|
141
|
+
}
|
|
142
|
+
return void 0;
|
|
143
|
+
}
|
|
144
|
+
/**
|
|
145
|
+
* Publish a short video by uploading a video file and optional thumbnail
|
|
146
|
+
* @param settings - Post creation settings
|
|
147
|
+
* @param video - Video file to upload (.mp4, .mov, .avi, .mkv, .webm)
|
|
148
|
+
* @param thumb - Optional thumbnail image file or URL string
|
|
149
|
+
* @returns Created post response
|
|
150
|
+
*/
|
|
151
|
+
async publishShortVideoToWorkspaceByFile(settings, video, thumb) {
|
|
152
|
+
if (video.size > this.maxVideoUploadSizeBytes) {
|
|
153
|
+
throw new Error(`Video file size (${video.size} bytes) exceeds maximum allowed size (${this.maxVideoUploadSizeBytes} bytes)`);
|
|
154
|
+
}
|
|
155
|
+
const allowedVideoTypes = [".mp4", ".mov", ".avi", ".mkv", ".webm"];
|
|
156
|
+
const videoExtension = "." + video.name.split(".").pop()?.toLowerCase();
|
|
157
|
+
if (!allowedVideoTypes.includes(videoExtension)) {
|
|
158
|
+
throw new Error(`Invalid video file type. Allowed types: ${allowedVideoTypes.join(", ")}`);
|
|
159
|
+
}
|
|
160
|
+
const uploadUrlsResponse = await this.generateUploadUrls({
|
|
161
|
+
videoFileType: video.type,
|
|
162
|
+
thumbFileType: thumb instanceof File ? thumb.type : void 0
|
|
163
|
+
});
|
|
164
|
+
await core.uploadToR2(uploadUrlsResponse.video.uploadFileURL, video, {
|
|
165
|
+
contentType: video.type
|
|
166
|
+
});
|
|
167
|
+
const uploadThumb = await this.handleThumbnailUpload(thumb, uploadUrlsResponse);
|
|
168
|
+
const postSettings = {
|
|
169
|
+
...settings,
|
|
170
|
+
videoURL: uploadUrlsResponse.video.fileURL,
|
|
171
|
+
thumbURL: uploadThumb?.thumbFileURL
|
|
172
|
+
};
|
|
173
|
+
return await this.createToWorkspaceByFile(postSettings, uploadUrlsResponse.postId);
|
|
174
|
+
}
|
|
175
|
+
/**
|
|
176
|
+
* Publish a short video by providing a video URL and optional thumbnail
|
|
177
|
+
* @param settings - Post creation settings
|
|
178
|
+
* @param videoURL - Video URL (.mp4, .mov, .avi, .mkv, .webm)
|
|
179
|
+
* @param thumb - Optional thumbnail image file or URL string
|
|
180
|
+
* @returns Created post response
|
|
181
|
+
*/
|
|
182
|
+
async publishShortVideoToWorkspaceByURL(settings, videoURL, thumb) {
|
|
183
|
+
const uploadThumb = await this.handleThumbnailUpload(thumb);
|
|
184
|
+
const postSettings = {
|
|
185
|
+
...settings,
|
|
186
|
+
videoURL,
|
|
187
|
+
thumbURL: uploadThumb?.thumbFileURL
|
|
188
|
+
};
|
|
189
|
+
return await this.createToWorkspaceByURL(postSettings, uploadThumb?.postId);
|
|
190
|
+
}
|
|
191
|
+
/**
|
|
192
|
+
* Publish a repost video from TikTok
|
|
193
|
+
* @param settings - Post creation settings
|
|
194
|
+
* @param videoURL - TikTok video URL (tiktok.com, vm.tiktok.com)
|
|
195
|
+
* @param thumb - Optional thumbnail image file or URL string
|
|
196
|
+
* @returns Created post response
|
|
197
|
+
*/
|
|
198
|
+
async publishRepostVideoToWorkspace(settings, videoURL, thumb) {
|
|
199
|
+
const uploadThumb = await this.handleThumbnailUpload(thumb);
|
|
200
|
+
const postSettings = {
|
|
201
|
+
...settings,
|
|
202
|
+
postURL: videoURL,
|
|
203
|
+
thumbURL: uploadThumb?.thumbFileURL
|
|
204
|
+
};
|
|
205
|
+
return await this.createToWorkspaceByURL(postSettings, uploadThumb?.postId);
|
|
206
|
+
}
|
|
207
|
+
/**
|
|
208
|
+
* Publish a short video to account by uploading a video file
|
|
209
|
+
*/
|
|
210
|
+
async publishShortVideoToAccountByFile(settings, video, thumb) {
|
|
211
|
+
if (video.size > this.maxVideoUploadSizeBytes) {
|
|
212
|
+
throw new Error(`Video file size (${video.size} bytes) exceeds maximum allowed size (${this.maxVideoUploadSizeBytes} bytes)`);
|
|
213
|
+
}
|
|
214
|
+
const allowedVideoTypes = [".mp4", ".mov", ".avi", ".mkv", ".webm"];
|
|
215
|
+
const videoExtension = "." + video.name.split(".").pop()?.toLowerCase();
|
|
216
|
+
if (!allowedVideoTypes.includes(videoExtension)) {
|
|
217
|
+
throw new Error(`Invalid video file type. Allowed types: ${allowedVideoTypes.join(", ")}`);
|
|
218
|
+
}
|
|
219
|
+
const uploadUrlsResponse = await this.generateUploadUrls({
|
|
220
|
+
videoFileType: video.type,
|
|
221
|
+
thumbFileType: thumb instanceof File ? thumb.type : void 0
|
|
222
|
+
});
|
|
223
|
+
await core.uploadToR2(uploadUrlsResponse.video.uploadFileURL, video, {
|
|
224
|
+
contentType: video.type
|
|
225
|
+
});
|
|
226
|
+
const uploadThumb = await this.handleThumbnailUpload(thumb, uploadUrlsResponse);
|
|
227
|
+
const postSettings = {
|
|
228
|
+
...settings,
|
|
229
|
+
videoURL: uploadUrlsResponse.video.fileURL,
|
|
230
|
+
thumbURL: uploadThumb?.thumbFileURL
|
|
231
|
+
};
|
|
232
|
+
return await this.createToAccountByFile(postSettings, uploadUrlsResponse.postId);
|
|
233
|
+
}
|
|
234
|
+
/**
|
|
235
|
+
* Publish a short video to account by URL
|
|
236
|
+
*/
|
|
237
|
+
async publishShortVideoToAccountByURL(settings, videoURL, thumb) {
|
|
238
|
+
const uploadThumb = await this.handleThumbnailUpload(thumb);
|
|
239
|
+
const postSettings = {
|
|
240
|
+
...settings,
|
|
241
|
+
videoURL,
|
|
242
|
+
thumbURL: uploadThumb?.thumbFileURL
|
|
243
|
+
};
|
|
244
|
+
return await this.createToAccountByURL(postSettings, uploadThumb?.postId);
|
|
245
|
+
}
|
|
246
|
+
/**
|
|
247
|
+
* Publish a repost video to account
|
|
248
|
+
*/
|
|
249
|
+
async publishRepostVideoToAccount(settings, videoURL, thumb) {
|
|
250
|
+
const uploadThumb = await this.handleThumbnailUpload(thumb);
|
|
251
|
+
const postSettings = {
|
|
252
|
+
...settings,
|
|
253
|
+
postURL: videoURL,
|
|
254
|
+
thumbURL: uploadThumb?.thumbFileURL
|
|
255
|
+
};
|
|
256
|
+
return await this.createToAccountByURL(postSettings, uploadThumb?.postId);
|
|
257
|
+
}
|
|
258
|
+
/**
|
|
259
|
+
* Publish a video to multiple social media platforms with auto-detection
|
|
260
|
+
* This is the recommended method for most use cases.
|
|
261
|
+
*
|
|
262
|
+
* @param options - Simplified publishing options
|
|
263
|
+
* @returns Created post response
|
|
264
|
+
*
|
|
265
|
+
* @example
|
|
266
|
+
* ```typescript
|
|
267
|
+
* // Publish video file to YouTube
|
|
268
|
+
* await client.publish({
|
|
269
|
+
* workspaceId: 'workspace-123',
|
|
270
|
+
* video: videoFile,
|
|
271
|
+
* thumbnail: thumbFile,
|
|
272
|
+
* platforms: ['youtube'],
|
|
273
|
+
* youtube: {
|
|
274
|
+
* title: 'My Video',
|
|
275
|
+
* description: 'Description',
|
|
276
|
+
* tags: ['tag1', 'tag2']
|
|
277
|
+
* }
|
|
278
|
+
* });
|
|
279
|
+
*
|
|
280
|
+
* // Publish to multiple platforms
|
|
281
|
+
* await client.publish({
|
|
282
|
+
* workspaceId: 'workspace-123',
|
|
283
|
+
* video: 'https://example.com/video.mp4',
|
|
284
|
+
* thumbnail: 'https://example.com/thumb.jpg',
|
|
285
|
+
* platforms: ['youtube', 'tiktok'],
|
|
286
|
+
* youtube: { title: 'Video', description: 'Desc', tags: [] },
|
|
287
|
+
* tiktok: { caption: 'Caption', privacy_level: 'public', disable_duet: false, disable_stitch: false, disable_comment: false }
|
|
288
|
+
* });
|
|
289
|
+
*
|
|
290
|
+
* // Repost from Facebook (auto-detected)
|
|
291
|
+
* await client.publish({
|
|
292
|
+
* workspaceId: 'workspace-123',
|
|
293
|
+
* video: 'https://facebook.com/video/12345',
|
|
294
|
+
* platforms: ['youtube'],
|
|
295
|
+
* youtube: { title: 'Reposted', description: 'From FB', tags: [] }
|
|
296
|
+
* });
|
|
297
|
+
* ```
|
|
298
|
+
*/
|
|
299
|
+
async publishShortVideoToWorkspace(options) {
|
|
300
|
+
if (!options.workspaceId) {
|
|
301
|
+
throw new Error("workspaceId is required");
|
|
302
|
+
}
|
|
303
|
+
if (!options.video) {
|
|
304
|
+
throw new Error("video is required");
|
|
305
|
+
}
|
|
306
|
+
if (!options.platforms || options.platforms.length === 0) {
|
|
307
|
+
throw new Error("At least one platform must be specified");
|
|
308
|
+
}
|
|
309
|
+
if (options.platforms.includes("youtube") && !options.youtube) {
|
|
310
|
+
throw new Error("YouTube configuration is required when publishing to YouTube");
|
|
311
|
+
}
|
|
312
|
+
if (options.platforms.includes("tiktok") && !options.tiktok) {
|
|
313
|
+
throw new Error("TikTok configuration is required when publishing to TikTok");
|
|
314
|
+
}
|
|
315
|
+
if (options.platforms.includes("facebook") && !options.facebook) {
|
|
316
|
+
throw new Error("Facebook configuration is required when publishing to Facebook");
|
|
317
|
+
}
|
|
318
|
+
if (options.platforms.includes("instagram") && !options.instagram) {
|
|
319
|
+
throw new Error("Instagram configuration is required when publishing to Instagram");
|
|
320
|
+
}
|
|
321
|
+
const settings = {
|
|
322
|
+
workspaceId: options.workspaceId,
|
|
323
|
+
isAllowYouTube: options.platforms.includes("youtube"),
|
|
324
|
+
isAllowTiktok: options.platforms.includes("tiktok"),
|
|
325
|
+
isAllowFacebookPage: options.platforms.includes("facebook"),
|
|
326
|
+
isAllowInstagram: options.platforms.includes("instagram"),
|
|
327
|
+
youtube: options.youtube,
|
|
328
|
+
tiktok: options.tiktok,
|
|
329
|
+
facebook: options.facebook,
|
|
330
|
+
instagram: options.instagram,
|
|
331
|
+
schedule: options.schedule ? {
|
|
332
|
+
type: options.schedule === "now" ? "now" : "schedule",
|
|
333
|
+
scheduledAt: options.schedule instanceof Date ? options.schedule : void 0
|
|
334
|
+
} : void 0,
|
|
335
|
+
source: "video-file"
|
|
336
|
+
};
|
|
337
|
+
const source = this.detectVideoSource(options.video);
|
|
338
|
+
switch (source) {
|
|
339
|
+
case "file": {
|
|
340
|
+
return this.publishShortVideoToWorkspaceByFile(settings, options.video, options.thumbnail);
|
|
341
|
+
}
|
|
342
|
+
case "url": {
|
|
343
|
+
return this.publishShortVideoToWorkspaceByURL(settings, options.video, options.thumbnail);
|
|
344
|
+
}
|
|
345
|
+
case "repost": {
|
|
346
|
+
return this.publishRepostVideoToWorkspace(settings, options.video, options.thumbnail);
|
|
347
|
+
}
|
|
348
|
+
default:
|
|
349
|
+
throw new Error(`Unknown video source type: ${source}`);
|
|
350
|
+
}
|
|
351
|
+
}
|
|
352
|
+
/**
|
|
353
|
+
* Publish a video to multiple social media platforms with auto-detection (Account)
|
|
354
|
+
*
|
|
355
|
+
* @param options - Simplified publishing options for account
|
|
356
|
+
* @returns Created post response
|
|
357
|
+
*/
|
|
358
|
+
async publishShortVideoToAccount(options) {
|
|
359
|
+
if (!options.accountId) {
|
|
360
|
+
throw new Error("accountId is required");
|
|
361
|
+
}
|
|
362
|
+
if (!options.video) {
|
|
363
|
+
throw new Error("video is required");
|
|
364
|
+
}
|
|
365
|
+
if (!options.platforms || options.platforms.length === 0) {
|
|
366
|
+
throw new Error("At least one platform must be specified");
|
|
367
|
+
}
|
|
368
|
+
if (options.platforms.includes("youtube") && !options.youtube) {
|
|
369
|
+
throw new Error("YouTube configuration is required when publishing to YouTube");
|
|
370
|
+
}
|
|
371
|
+
if (options.platforms.includes("tiktok") && !options.tiktok) {
|
|
372
|
+
throw new Error("TikTok configuration is required when publishing to TikTok");
|
|
373
|
+
}
|
|
374
|
+
if (options.platforms.includes("facebook") && !options.facebook) {
|
|
375
|
+
throw new Error("Facebook configuration is required when publishing to Facebook");
|
|
376
|
+
}
|
|
377
|
+
if (options.platforms.includes("instagram") && !options.instagram) {
|
|
378
|
+
throw new Error("Instagram configuration is required when publishing to Instagram");
|
|
379
|
+
}
|
|
380
|
+
const source = this.detectVideoSource(options.video);
|
|
381
|
+
const settings = {
|
|
382
|
+
accountId: options.accountId,
|
|
383
|
+
isAllowYouTube: options.platforms.includes("youtube"),
|
|
384
|
+
isAllowTiktok: options.platforms.includes("tiktok"),
|
|
385
|
+
isAllowFacebookPage: options.platforms.includes("facebook"),
|
|
386
|
+
isAllowInstagram: options.platforms.includes("instagram"),
|
|
387
|
+
youtube: options.youtube,
|
|
388
|
+
tiktok: options.tiktok,
|
|
389
|
+
facebook: options.facebook,
|
|
390
|
+
instagram: options.instagram,
|
|
391
|
+
schedule: options.schedule ? {
|
|
392
|
+
type: options.schedule === "now" ? "now" : "schedule",
|
|
393
|
+
scheduledAt: options.schedule instanceof Date ? options.schedule : void 0
|
|
394
|
+
} : void 0,
|
|
395
|
+
source: "video-file"
|
|
396
|
+
};
|
|
397
|
+
switch (source) {
|
|
398
|
+
case "file": {
|
|
399
|
+
return this.publishShortVideoToAccountByFile(settings, options.video, options.thumbnail);
|
|
400
|
+
}
|
|
401
|
+
case "url": {
|
|
402
|
+
return this.publishShortVideoToAccountByURL(settings, options.video, options.thumbnail);
|
|
403
|
+
}
|
|
404
|
+
case "repost": {
|
|
405
|
+
return this.publishRepostVideoToAccount(settings, options.video, options.thumbnail);
|
|
406
|
+
}
|
|
407
|
+
default:
|
|
408
|
+
throw new Error(`Unknown video source type: ${source}`);
|
|
409
|
+
}
|
|
410
|
+
}
|
|
411
|
+
/**
|
|
412
|
+
* @deprecated Use publishShortVideoToWorkspace instead
|
|
413
|
+
*/
|
|
414
|
+
async publishShortVideo(options) {
|
|
415
|
+
return this.publishShortVideoToWorkspace(options);
|
|
416
|
+
}
|
|
417
|
+
/**
|
|
418
|
+
* Auto-detect video source type
|
|
419
|
+
* @param video - File or URL string
|
|
420
|
+
* @returns Detected source type and video
|
|
421
|
+
*/
|
|
422
|
+
detectVideoSource(video) {
|
|
423
|
+
if (video instanceof File) {
|
|
424
|
+
return "file";
|
|
425
|
+
}
|
|
426
|
+
if (typeof video === "string") {
|
|
427
|
+
if (/^https?:\/\/(www\.)?(facebook\.com|fb\.watch)\/(reel|watch|.*\/videos)\/.*/i.test(video)) {
|
|
428
|
+
return "repost";
|
|
429
|
+
}
|
|
430
|
+
if (/^https?:\/\/(www\.)?(tiktok\.com\/@[^\/]+\/video\/\d+|vm\.tiktok\.com\/\w+|vt\.tiktok\.com\/\w+)/i.test(video)) {
|
|
431
|
+
return "repost";
|
|
432
|
+
}
|
|
433
|
+
if (/^https?:\/\/(www\.)?(youtube\.com\/shorts\/|youtu\.be\/)[A-Za-z0-9_-]+/i.test(video)) {
|
|
434
|
+
return "repost";
|
|
435
|
+
}
|
|
436
|
+
return "url";
|
|
437
|
+
}
|
|
438
|
+
throw new Error("Invalid video type. Must be File or string URL");
|
|
439
|
+
}
|
|
440
|
+
};
|
|
441
|
+
|
|
442
|
+
exports.SocialPublisherPostClient = SocialPublisherPostClient;
|
|
443
|
+
//# sourceMappingURL=index.js.map
|
|
444
|
+
//# sourceMappingURL=index.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"sources":["../src/social-publisher-post.client.ts"],"names":["uploadToR2"],"mappings":";;;;;AAoBO,IAAM,4BAAN,MAAgC;AAAA,EAMrC,YAAY,IAAA,EAAkB;AAJ9B,IAAA,IAAA,CAAQ,QAAA,GAAW,4BAAA;AAKjB,IAAA,IAAA,CAAK,IAAA,GAAO,IAAA;AACZ,IAAA,IAAA,CAAK,uBAAA,GAA0B,UAAA;AAC/B,IAAA,IAAA,CAAK,uBAAA,GAA0B,UAAA;AAAA,EACjC;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA,EAOA,MAAM,IAAA,CAAK,MAAA,EAAsB,UAAA,EAA6E;AAC5G,IAA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AAA;AAAA;AAC1D,EACF;AAAA;AAAA;AAAA;AAAA,EAKA,MAAM,kBAAkB,OAAA,EAA2C;AACjE,IAAA,OAAO,IAAA,CAAK,6BAA6B,OAAO,CAAA;AAAA,EAClD;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA,EAOQ,kBAAkB,KAAA,EAAiD;AAEzE,IAAA,IAAI,iBAAiB,IAAA,EAAM;AACzB,MAAA,OAAO,MAAA;AAAA,IACT;AAGA,IAAA,IAAI,OAAO,UAAU,QAAA,EAAU;AAE7B,MAAA,IAAI,6EAAA,CAA8E,IAAA,CAAK,KAAK,CAAA,EAAG;AAC7F,QAAA,OAAO,QAAA;AAAA,MACT;AAGA,MAAA,IAAI,mGAAA,CAAoG,IAAA,CAAK,KAAK,CAAA,EAAG;AACnH,QAAA,OAAO,QAAA;AAAA,MACT;AAGA,MAAA,IAAI,yEAAA,CAA0E,IAAA,CAAK,KAAK,CAAA,EAAG;AACzF,QAAA,OAAO,QAAA;AAAA,MACT;AAGA,MAAA,OAAO,KAAA;AAAA,IACT;AAEA,IAAA,MAAM,IAAI,MAAM,gDAAgD,CAAA;AAAA,EAClE;AACF","file":"index.js","sourcesContent":["import { HttpClient, IPaginationParams, uploadToR2 } from \"@posty5/core\";\r\nimport {\r\n ICreateSocialPublisherPostRequest,\r\n IGenerateUploadUrlsRequest,\r\n IGenerateUploadUrlsResponse,\r\n ISearchSocialPublisherPostResponse,\r\n ISocialPublisherPostNextPreviousResponse,\r\n ISocialPublisherPostStatusResponse,\r\n IDefaultSettingsResponse,\r\n IPostSetting,\r\n IPublishOptions,\r\n IListParams,\r\n ICreateSocialPublisherAccountPostRequest,\r\n IAccountPostSetting,\r\n IPublishToAccountOptions,\r\n} from \"./interfaces\";\r\n\r\n/**\r\n * Social Publisher Post Client\r\n */\r\nexport class SocialPublisherPostClient {\r\n private http: HttpClient;\r\n private basePath = \"/api/social-publisher-post\";\r\n public readonly maxVideoUploadSizeBytes: number;\r\n public readonly maxImageUploadSizeBytes: number;\r\n\r\n constructor(http: HttpClient) {\r\n this.http = http;\r\n this.maxVideoUploadSizeBytes = 2147483648; //2GB default\r\n this.maxImageUploadSizeBytes = 1073741824; // 1GB default\r\n }\r\n\r\n /**\r\n * Search posts\r\n * @param params - Search parameters (optional)\r\n * @param pagination - Pagination parameters\r\n */\r\n async list(params?: IListParams, pagination?: IPaginationParams): Promise<ISearchSocialPublisherPostResponse> {\r\n const response = await this.http.get<ISearchSocialPublisherPostResponse>(this.basePath, {\r\n params: {\r\n ...params,\r\n ...pagination,\r\n },\r\n });\r\n return response.result!;\r\n }\r\n\r\n /**\r\n * Get default settings\r\n */\r\n async getDefaultSettings(): Promise<IDefaultSettingsResponse> {\r\n const response = await this.http.get<IDefaultSettingsResponse>(`${this.basePath}/default-settings`);\r\n return response.result!;\r\n }\r\n\r\n /**\r\n * Get post status\r\n * @param id - Post ID\r\n */\r\n async getStatus(id: string): Promise<ISocialPublisherPostStatusResponse> {\r\n const response = await this.http.get<ISocialPublisherPostStatusResponse>(`${this.basePath}/${id}/status`);\r\n return response.result!;\r\n }\r\n\r\n /**\r\n * Generate upload signed URLs for video and thumbnail\r\n * @param data - File information\r\n */\r\n private async generateUploadUrls(data: IGenerateUploadUrlsRequest): Promise<IGenerateUploadUrlsResponse> {\r\n const response = await this.http.post<IGenerateUploadUrlsResponse>(`${this.basePath}/generate-upload-urls`, data);\r\n return response.result!;\r\n }\r\n\r\n /**\r\n * Get next and previous post IDs\r\n * @param id - Current Post ID\r\n */\r\n async getNextAndPrevious(id: string): Promise<ISocialPublisherPostNextPreviousResponse> {\r\n const response = await this.http.get<ISocialPublisherPostNextPreviousResponse>(`${this.basePath}/${id}/next-previous`);\r\n return response.result!;\r\n }\r\n\r\n /**\r\n * Create a new post (publish video)\r\n * @param data - Post creation data\r\n * @param id - Optional ID for updating/retrying? (Based on route :id?)\r\n */\r\n private async createToWorkspaceByFile(data: ICreateSocialPublisherPostRequest, id?: string): Promise<string> {\r\n const url = id ? `${this.basePath}/short-video/workspace/by-file/${id}` : `${this.basePath}/short-video/workspace/by-file`;\r\n const response = await this.http.post<{ _id: string }>(url, {\r\n ...data,\r\n createdFrom: \"npmPackage\",\r\n });\r\n return response.result?._id!;\r\n }\r\n\r\n /**\r\n * Create a new post (publish video)\r\n * @param data - Post creation data\r\n * @param id - Optional ID for updating/retrying? (Based on route :id?)\r\n */\r\n private async createToWorkspaceByURL(data: ICreateSocialPublisherPostRequest, id?: string): Promise<string> {\r\n const url = id ? `${this.basePath}/short-video/workspace/by-url/${id}` : `${this.basePath}/short-video/workspace/by-url`;\r\n const response = await this.http.post<{ _id: string }>(url, {\r\n ...data,\r\n createdFrom: \"npmPackage\",\r\n });\r\n return response.result?._id!;\r\n }\r\n\r\n /**\r\n * Create a new post (publish video to account)\r\n * @param data - Post creation data\r\n * @param id - Optional ID for updating/retrying?\r\n */\r\n private async createToAccountByFile(data: ICreateSocialPublisherAccountPostRequest, id?: string): Promise<string> {\r\n const url = id ? `${this.basePath}/short-video/account/by-file/${id}` : `${this.basePath}/short-video/account/by-file`;\r\n const response = await this.http.post<{ _id: string }>(url, {\r\n ...data,\r\n createdFrom: \"npmPackage\",\r\n });\r\n return response.result?._id!;\r\n }\r\n\r\n /**\r\n * Create a new post (publish video to account)\r\n * @param data - Post creation data\r\n * @param id - Optional ID for updating/retrying?\r\n */\r\n private async createToAccountByURL(data: ICreateSocialPublisherAccountPostRequest, id?: string): Promise<string> {\r\n const url = id ? `${this.basePath}/short-video/account/by-url/${id}` : `${this.basePath}/short-video/account/by-url`;\r\n const response = await this.http.post<{ _id: string }>(url, {\r\n ...data,\r\n createdFrom: \"npmPackage\",\r\n });\r\n return response.result?._id!;\r\n }\r\n\r\n /**\r\n * Handle thumbnail upload - accepts either File or URL string\r\n * @param thumb - Thumbnail as File (will be uploaded) or URL string (will be passed directly)\r\n * @returns Thumbnail URL or undefined\r\n */\r\n private async handleThumbnailUpload(thumb?: File | string, uploadUrlsResponse?: IGenerateUploadUrlsResponse) {\r\n if (!thumb) {\r\n return undefined;\r\n }\r\n\r\n // If thumb is a string (URL), validate and return it directly\r\n if (typeof thumb === \"string\") {\r\n const urlPattern = /(http:\\/\\/)..*|(https:\\/\\/)..*/gi;\r\n if (!urlPattern.test(thumb)) {\r\n throw new Error(\"Invalid thumbnail URL format\");\r\n }\r\n return { thumbFileURL: thumb, postId: undefined };\r\n }\r\n\r\n // If thumb is a File, upload it\r\n if (thumb instanceof File) {\r\n // Validate thumbnail file size\r\n if (thumb.size > this.maxImageUploadSizeBytes) {\r\n throw new Error(`Thumbnail file size (${thumb.size} bytes) exceeds maximum allowed size (${this.maxImageUploadSizeBytes} bytes)`);\r\n }\r\n\r\n // Generate upload URL\r\n if (!uploadUrlsResponse) {\r\n uploadUrlsResponse = await this.generateUploadUrls({\r\n thumbFileType: thumb.type,\r\n });\r\n }\r\n\r\n if (uploadUrlsResponse.thumb.uploadFileURL) {\r\n // Upload to R2 using uploadToR2 utility\r\n await uploadToR2(uploadUrlsResponse.thumb.uploadFileURL, thumb, {\r\n contentType: thumb.type,\r\n });\r\n\r\n return { thumbFileURL: uploadUrlsResponse.thumb.fileURL, postId: uploadUrlsResponse.postId };\r\n }\r\n }\r\n\r\n return undefined;\r\n }\r\n\r\n /**\r\n * Publish a short video by uploading a video file and optional thumbnail\r\n * @param settings - Post creation settings\r\n * @param video - Video file to upload (.mp4, .mov, .avi, .mkv, .webm)\r\n * @param thumb - Optional thumbnail image file or URL string\r\n * @returns Created post response\r\n */\r\n private async publishShortVideoToWorkspaceByFile(settings: IPostSetting, video: File, thumb?: File | string): Promise<string> {\r\n // Validate video size\r\n if (video.size > this.maxVideoUploadSizeBytes) {\r\n throw new Error(`Video file size (${video.size} bytes) exceeds maximum allowed size (${this.maxVideoUploadSizeBytes} bytes)`);\r\n }\r\n\r\n // Validate video file type\r\n const allowedVideoTypes = [\".mp4\", \".mov\", \".avi\", \".mkv\", \".webm\"];\r\n const videoExtension = \".\" + video.name.split(\".\").pop()?.toLowerCase();\r\n if (!allowedVideoTypes.includes(videoExtension)) {\r\n throw new Error(`Invalid video file type. Allowed types: ${allowedVideoTypes.join(\", \")}`);\r\n }\r\n\r\n // Step 1: Generate upload URLs for video\r\n const uploadUrlsResponse = await this.generateUploadUrls({\r\n videoFileType: video.type,\r\n thumbFileType: thumb instanceof File ? thumb.type : undefined,\r\n });\r\n\r\n // Step 2: Upload video using uploadToR2 utility\r\n await uploadToR2(uploadUrlsResponse.video.uploadFileURL!, video, {\r\n contentType: video.type,\r\n });\r\n\r\n // Step 3: Handle thumbnail upload (File or URL)\r\n const uploadThumb = await this.handleThumbnailUpload(thumb, uploadUrlsResponse);\r\n\r\n // Step 4: Create post with uploaded file URLs\r\n const postSettings: ICreateSocialPublisherPostRequest = {\r\n ...settings,\r\n videoURL: uploadUrlsResponse.video.fileURL,\r\n thumbURL: uploadThumb?.thumbFileURL,\r\n };\r\n\r\n return await this.createToWorkspaceByFile(postSettings, uploadUrlsResponse.postId);\r\n }\r\n\r\n /**\r\n * Publish a short video by providing a video URL and optional thumbnail\r\n * @param settings - Post creation settings\r\n * @param videoURL - Video URL (.mp4, .mov, .avi, .mkv, .webm)\r\n * @param thumb - Optional thumbnail image file or URL string\r\n * @returns Created post response\r\n */\r\n private async publishShortVideoToWorkspaceByURL(settings: IPostSetting, videoURL: string, thumb?: File | string): Promise<string> {\r\n // Handle thumbnail upload (File or URL)\r\n const uploadThumb = await this.handleThumbnailUpload(thumb);\r\n\r\n // Create post with video URL\r\n const postSettings: ICreateSocialPublisherPostRequest = {\r\n ...settings,\r\n videoURL,\r\n thumbURL: uploadThumb?.thumbFileURL,\r\n };\r\n\r\n return await this.createToWorkspaceByURL(postSettings, uploadThumb?.postId);\r\n }\r\n\r\n /**\r\n * Publish a repost video from TikTok\r\n * @param settings - Post creation settings\r\n * @param videoURL - TikTok video URL (tiktok.com, vm.tiktok.com)\r\n * @param thumb - Optional thumbnail image file or URL string\r\n * @returns Created post response\r\n */\r\n private async publishRepostVideoToWorkspace(settings: IPostSetting, videoURL: string, thumb?: File | string): Promise<string> {\r\n // Handle thumbnail upload (File or URL)\r\n const uploadThumb = await this.handleThumbnailUpload(thumb);\r\n\r\n // Create post with TikTok video URL\r\n const postSettings: ICreateSocialPublisherPostRequest = {\r\n ...settings,\r\n postURL: videoURL,\r\n thumbURL: uploadThumb?.thumbFileURL,\r\n };\r\n\r\n return await this.createToWorkspaceByURL(postSettings, uploadThumb?.postId);\r\n }\r\n\r\n /**\r\n * Publish a short video to account by uploading a video file\r\n */\r\n private async publishShortVideoToAccountByFile(settings: IAccountPostSetting, video: File, thumb?: File | string): Promise<string> {\r\n // Validate video size\r\n if (video.size > this.maxVideoUploadSizeBytes) {\r\n throw new Error(`Video file size (${video.size} bytes) exceeds maximum allowed size (${this.maxVideoUploadSizeBytes} bytes)`);\r\n }\r\n\r\n // Validate video file type\r\n const allowedVideoTypes = [\".mp4\", \".mov\", \".avi\", \".mkv\", \".webm\"];\r\n const videoExtension = \".\" + video.name.split(\".\").pop()?.toLowerCase();\r\n if (!allowedVideoTypes.includes(videoExtension)) {\r\n throw new Error(`Invalid video file type. Allowed types: ${allowedVideoTypes.join(\", \")}`);\r\n }\r\n\r\n // Step 1: Generate upload URLs for video\r\n const uploadUrlsResponse = await this.generateUploadUrls({\r\n videoFileType: video.type,\r\n thumbFileType: thumb instanceof File ? thumb.type : undefined,\r\n });\r\n\r\n // Step 2: Upload video using uploadToR2 utility\r\n await uploadToR2(uploadUrlsResponse.video.uploadFileURL!, video, {\r\n contentType: video.type,\r\n });\r\n\r\n // Step 3: Handle thumbnail upload (File or URL)\r\n const uploadThumb = await this.handleThumbnailUpload(thumb, uploadUrlsResponse);\r\n\r\n // Step 4: Create post with uploaded file URLs\r\n const postSettings: ICreateSocialPublisherAccountPostRequest = {\r\n ...settings,\r\n videoURL: uploadUrlsResponse.video.fileURL,\r\n thumbURL: uploadThumb?.thumbFileURL,\r\n };\r\n\r\n return await this.createToAccountByFile(postSettings, uploadUrlsResponse.postId);\r\n }\r\n\r\n /**\r\n * Publish a short video to account by URL\r\n */\r\n private async publishShortVideoToAccountByURL(settings: IAccountPostSetting, videoURL: string, thumb?: File | string): Promise<string> {\r\n // Handle thumbnail upload (File or URL)\r\n const uploadThumb = await this.handleThumbnailUpload(thumb);\r\n\r\n // Create post with video URL\r\n const postSettings: ICreateSocialPublisherAccountPostRequest = {\r\n ...settings,\r\n videoURL,\r\n thumbURL: uploadThumb?.thumbFileURL,\r\n };\r\n\r\n return await this.createToAccountByURL(postSettings, uploadThumb?.postId);\r\n }\r\n\r\n /**\r\n * Publish a repost video to account\r\n */\r\n private async publishRepostVideoToAccount(settings: IAccountPostSetting, videoURL: string, thumb?: File | string): Promise<string> {\r\n // Handle thumbnail upload (File or URL)\r\n const uploadThumb = await this.handleThumbnailUpload(thumb);\r\n\r\n // Create post with TikTok video URL\r\n const postSettings: ICreateSocialPublisherAccountPostRequest = {\r\n ...settings,\r\n postURL: videoURL,\r\n thumbURL: uploadThumb?.thumbFileURL,\r\n };\r\n\r\n return await this.createToAccountByURL(postSettings, uploadThumb?.postId);\r\n }\r\n\r\n /**\r\n * Publish a video to multiple social media platforms with auto-detection\r\n * This is the recommended method for most use cases.\r\n *\r\n * @param options - Simplified publishing options\r\n * @returns Created post response\r\n *\r\n * @example\r\n * ```typescript\r\n * // Publish video file to YouTube\r\n * await client.publish({\r\n * workspaceId: 'workspace-123',\r\n * video: videoFile,\r\n * thumbnail: thumbFile,\r\n * platforms: ['youtube'],\r\n * youtube: {\r\n * title: 'My Video',\r\n * description: 'Description',\r\n * tags: ['tag1', 'tag2']\r\n * }\r\n * });\r\n *\r\n * // Publish to multiple platforms\r\n * await client.publish({\r\n * workspaceId: 'workspace-123',\r\n * video: 'https://example.com/video.mp4',\r\n * thumbnail: 'https://example.com/thumb.jpg',\r\n * platforms: ['youtube', 'tiktok'],\r\n * youtube: { title: 'Video', description: 'Desc', tags: [] },\r\n * tiktok: { caption: 'Caption', privacy_level: 'public', disable_duet: false, disable_stitch: false, disable_comment: false }\r\n * });\r\n *\r\n * // Repost from Facebook (auto-detected)\r\n * await client.publish({\r\n * workspaceId: 'workspace-123',\r\n * video: 'https://facebook.com/video/12345',\r\n * platforms: ['youtube'],\r\n * youtube: { title: 'Reposted', description: 'From FB', tags: [] }\r\n * });\r\n * ```\r\n */\r\n async publishShortVideoToWorkspace(options: IPublishOptions): Promise<string> {\r\n // Validate required fields\r\n if (!options.workspaceId) {\r\n throw new Error(\"workspaceId is required\");\r\n }\r\n if (!options.video) {\r\n throw new Error(\"video is required\");\r\n }\r\n if (!options.platforms || options.platforms.length === 0) {\r\n throw new Error(\"At least one platform must be specified\");\r\n }\r\n\r\n // Validate platform configurations\r\n if (options.platforms.includes(\"youtube\") && !options.youtube) {\r\n throw new Error(\"YouTube configuration is required when publishing to YouTube\");\r\n }\r\n if (options.platforms.includes(\"tiktok\") && !options.tiktok) {\r\n throw new Error(\"TikTok configuration is required when publishing to TikTok\");\r\n }\r\n if (options.platforms.includes(\"facebook\") && !options.facebook) {\r\n throw new Error(\"Facebook configuration is required when publishing to Facebook\");\r\n }\r\n if (options.platforms.includes(\"instagram\") && !options.instagram) {\r\n throw new Error(\"Instagram configuration is required when publishing to Instagram\");\r\n }\r\n\r\n // Build IPostSetting from simplified options\r\n const settings: IPostSetting = {\r\n workspaceId: options.workspaceId,\r\n isAllowYouTube: options.platforms.includes(\"youtube\"),\r\n isAllowTiktok: options.platforms.includes(\"tiktok\"),\r\n isAllowFacebookPage: options.platforms.includes(\"facebook\"),\r\n isAllowInstagram: options.platforms.includes(\"instagram\"),\r\n youtube: options.youtube,\r\n tiktok: options.tiktok,\r\n facebook: options.facebook,\r\n instagram: options.instagram,\r\n schedule: options.schedule\r\n ? {\r\n type: options.schedule === \"now\" ? \"now\" : \"schedule\",\r\n scheduledAt: options.schedule instanceof Date ? options.schedule : undefined,\r\n }\r\n : undefined,\r\n source: \"video-file\",\r\n };\r\n\r\n // Auto-detect video source type\r\n const source = this.detectVideoSource(options.video);\r\n\r\n // Route to appropriate method based on detected source\r\n switch (source) {\r\n case \"file\": {\r\n return this.publishShortVideoToWorkspaceByFile(settings, options.video as File, options.thumbnail);\r\n }\r\n\r\n case \"url\": {\r\n return this.publishShortVideoToWorkspaceByURL(settings, options.video as string, options.thumbnail);\r\n }\r\n case \"repost\": {\r\n return this.publishRepostVideoToWorkspace(settings, options.video as string, options.thumbnail);\r\n }\r\n default:\r\n throw new Error(`Unknown video source type: ${source}`);\r\n }\r\n }\r\n\r\n /**\r\n * Publish a video to multiple social media platforms with auto-detection (Account)\r\n *\r\n * @param options - Simplified publishing options for account\r\n * @returns Created post response\r\n */\r\n async publishShortVideoToAccount(options: IPublishToAccountOptions): Promise<string> {\r\n // Validate required fields\r\n if (!options.accountId) {\r\n throw new Error(\"accountId is required\");\r\n }\r\n if (!options.video) {\r\n throw new Error(\"video is required\");\r\n }\r\n if (!options.platforms || options.platforms.length === 0) {\r\n throw new Error(\"At least one platform must be specified\");\r\n }\r\n\r\n // Validate platform configurations\r\n if (options.platforms.includes(\"youtube\") && !options.youtube) {\r\n throw new Error(\"YouTube configuration is required when publishing to YouTube\");\r\n }\r\n if (options.platforms.includes(\"tiktok\") && !options.tiktok) {\r\n throw new Error(\"TikTok configuration is required when publishing to TikTok\");\r\n }\r\n if (options.platforms.includes(\"facebook\") && !options.facebook) {\r\n throw new Error(\"Facebook configuration is required when publishing to Facebook\");\r\n }\r\n if (options.platforms.includes(\"instagram\") && !options.instagram) {\r\n throw new Error(\"Instagram configuration is required when publishing to Instagram\");\r\n }\r\n\r\n // Auto-detect video source type\r\n const source = this.detectVideoSource(options.video);\r\n\r\n // Build IAccountPostSetting from simplified options\r\n const settings: IAccountPostSetting = {\r\n accountId: options.accountId,\r\n isAllowYouTube: options.platforms.includes(\"youtube\"),\r\n isAllowTiktok: options.platforms.includes(\"tiktok\"),\r\n isAllowFacebookPage: options.platforms.includes(\"facebook\"),\r\n isAllowInstagram: options.platforms.includes(\"instagram\"),\r\n youtube: options.youtube,\r\n tiktok: options.tiktok,\r\n facebook: options.facebook,\r\n instagram: options.instagram,\r\n schedule: options.schedule\r\n ? {\r\n type: options.schedule === \"now\" ? \"now\" : \"schedule\",\r\n scheduledAt: options.schedule instanceof Date ? options.schedule : undefined,\r\n }\r\n : undefined,\r\n source: \"video-file\",\r\n };\r\n\r\n // Route to appropriate method based on detected source\r\n switch (source) {\r\n case \"file\": {\r\n return this.publishShortVideoToAccountByFile(settings, options.video as File, options.thumbnail);\r\n }\r\n\r\n case \"url\": {\r\n return this.publishShortVideoToAccountByURL(settings, options.video as string, options.thumbnail);\r\n }\r\n case \"repost\": {\r\n return this.publishRepostVideoToAccount(settings, options.video as string, options.thumbnail);\r\n }\r\n default:\r\n throw new Error(`Unknown video source type: ${source}`);\r\n }\r\n }\r\n\r\n /**\r\n * @deprecated Use publishShortVideoToWorkspace instead\r\n */\r\n async publishShortVideo(options: IPublishOptions): Promise<string> {\r\n return this.publishShortVideoToWorkspace(options);\r\n }\r\n\r\n /**\r\n * Auto-detect video source type\r\n * @param video - File or URL string\r\n * @returns Detected source type and video\r\n */\r\n private detectVideoSource(video: File | string): \"file\" | \"url\" | \"repost\" {\r\n // Check if it's a File object\r\n if (video instanceof File) {\r\n return \"file\";\r\n }\r\n\r\n // Check for platform-specific URLs\r\n if (typeof video === \"string\") {\r\n // Facebook video URL\r\n if (/^https?:\\/\\/(www\\.)?(facebook\\.com|fb\\.watch)\\/(reel|watch|.*\\/videos)\\/.*/i.test(video)) {\r\n return \"repost\";\r\n }\r\n\r\n // TikTok video URL\r\n if (/^https?:\\/\\/(www\\.)?(tiktok\\.com\\/@[^\\/]+\\/video\\/\\d+|vm\\.tiktok\\.com\\/\\w+|vt\\.tiktok\\.com\\/\\w+)/i.test(video)) {\r\n return \"repost\";\r\n }\r\n\r\n // YouTube Shorts URL\r\n if (/^https?:\\/\\/(www\\.)?(youtube\\.com\\/shorts\\/|youtu\\.be\\/)[A-Za-z0-9_-]+/i.test(video)) {\r\n return \"repost\";\r\n }\r\n\r\n // Generic video URL\r\n return \"url\";\r\n }\r\n\r\n throw new Error(\"Invalid video type. Must be File or string URL\");\r\n }\r\n}\r\n"]}
|