From 4f946bd9b429e2bb4bb8d6c30ee735b2818a7b54 Mon Sep 17 00:00:00 2001 From: Azka Nahya Amanta Date: Tue, 1 Aug 2023 16:24:01 +0700 Subject: [PATCH] feature: Add Clips Upload --- src/repositories/media.repository.ts | 21 +++++++++------------ src/repositories/upload.repository.ts | 3 +++ src/services/publish.service.ts | 7 ++++++- src/types/media.configure-video.options.ts | 3 +++ src/types/posting.video.options.ts | 2 ++ src/types/upload.video.options.ts | 1 + 6 files changed, 24 insertions(+), 13 deletions(-) diff --git a/src/repositories/media.repository.ts b/src/repositories/media.repository.ts index 46ee8dc95..dd6bfb5da 100644 --- a/src/repositories/media.repository.ts +++ b/src/repositories/media.repository.ts @@ -362,7 +362,7 @@ export class MediaRepository extends Repository { return body; } - public async configureVideo(options: MediaConfigureTimelineVideoOptions) { + public async configureVideo(options: MediaConfigureTimelineVideoOptions, isClips: boolean) { const now = DateTime.local().toFormat('yyyy:mm:dd HH:mm:ss'); const form = this.applyConfigureDefaults(options, { @@ -388,7 +388,7 @@ export class MediaRepository extends Repository { } const { body } = await this.client.request.send({ - url: '/api/v1/media/configure/', + url: '/api/v1/media/configure' + (isClips ? '_to_clips/' : '/'), method: 'POST', qs: { video: '1', @@ -682,10 +682,10 @@ export class MediaRepository extends Repository { * save a media, or save it to collection if you pass the collection ids in array * @param {string} mediaId - The mediaId of the post * @param {string[]} [collection_ids] - Optional, The array of collection ids if you want to save the media to a specific collection - * Example: + * Example: * save("2524149952724070925_1829855275") save media * save("2524149952724070925_1829855275", ["17865977635619975"]) save media to 1 collection - * save("2524149952724070925_1829855275", ["17865977635619975", "17845997638619928"]) save media to 2 collection + * save("2524149952724070925_1829855275", ["17865977635619975", "17845997638619928"]) save media to 2 collection */ public async save(mediaId: string, collection_ids?: string[]) { const { body } = await this.client.request.send({ @@ -795,27 +795,24 @@ export class MediaRepository extends Repository { }); return body; } - - private async storyCountdownAction( - countdownId: string | number, - action: string, - ): Promise { + + private async storyCountdownAction(countdownId: string | number, action: string): Promise { const { body } = await this.client.request.send({ url: `/api/v1/media/${countdownId}/${action}/`, method: 'POST', form: this.client.request.sign({ _csrftoken: this.client.state.cookieCsrfToken, _uid: this.client.state.cookieUserId, - _uuid: this.client.state.uuid + _uuid: this.client.state.uuid, }), }); return body; } - + public async storyCountdownFollow(countdownId: string | number) { return this.storyCountdownAction(countdownId, 'follow_story_countdown'); } - + public async storyCountdownUnfollow(countdownId: string | number) { return this.storyCountdownAction(countdownId, 'unfollow_story_countdown'); } diff --git a/src/repositories/upload.repository.ts b/src/repositories/upload.repository.ts index d0e7b1aeb..ea78a6857 100644 --- a/src/repositories/upload.repository.ts +++ b/src/repositories/upload.repository.ts @@ -247,6 +247,9 @@ export class UploadRepository extends Repository { if (options.isDirectVoice) { ruploadParams.is_direct_voice = '1'; } + if (options.isClipVideo) { + ruploadParams.is_clips_video = '1'; + } return ruploadParams; } } diff --git a/src/services/publish.service.ts b/src/services/publish.service.ts index 7b55e3ec7..6fa0facec 100644 --- a/src/services/publish.service.ts +++ b/src/services/publish.service.ts @@ -158,6 +158,7 @@ export class PublishService extends Repository { await Bluebird.try(() => this.regularVideo({ video: options.video, + isClipVideo: options.isClip, uploadId, ...videoInfo, }), @@ -196,9 +197,13 @@ export class PublishService extends Repository { configureOptions.usertags = options.usertags; } + if (typeof options.clipsPreviewToFeed) { + configureOptions.clips_share_preview_to_feed = options.clipsPreviewToFeed ? '1' : '0'; + } + for (let i = 0; i < 6; i++) { try { - return await this.client.media.configureVideo(configureOptions); + return await this.client.media.configureVideo(configureOptions, options.isClip); } catch (e) { if (i >= 5 || e.response.statusCode >= 400) { throw new IgConfigureVideoError(e.response, configureOptions); diff --git a/src/types/media.configure-video.options.ts b/src/types/media.configure-video.options.ts index c66988aba..dfcfc3d93 100644 --- a/src/types/media.configure-video.options.ts +++ b/src/types/media.configure-video.options.ts @@ -16,6 +16,9 @@ export interface MediaConfigureVideoOptions { posting_longitude?: string; media_latitude?: string; media_longitude?: string; + + isClipsVideo?: boolean; + clips_share_preview_to_feed?: string; } export interface MediaConfigureTimelineVideoOptions extends MediaConfigureVideoOptions { diff --git a/src/types/posting.video.options.ts b/src/types/posting.video.options.ts index aaf69bb81..f24368a9c 100644 --- a/src/types/posting.video.options.ts +++ b/src/types/posting.video.options.ts @@ -7,6 +7,8 @@ export interface PostingVideoOptions { usertags?: PostingUsertags; location?: PostingLocation; transcodeDelay?: number; + isClip?: boolean; + clipsPreviewToFeed?: boolean; } export interface PostingStoryVideoOptions extends PostingStoryOptions { diff --git a/src/types/upload.video.options.ts b/src/types/upload.video.options.ts index 9488b9097..eb1e66073 100644 --- a/src/types/upload.video.options.ts +++ b/src/types/upload.video.options.ts @@ -16,6 +16,7 @@ export interface UploadVideoOptions { waterfallId?: string; uploadName?: string; offset?: number; + isClipVideo?: boolean; } export interface UploadVideoSegmentInitOptions {