UNPKG

instagram-private-api

Version:

Instagram private API wrapper for full access to instagram

128 lines 5.44 kB
"use strict"; Object.defineProperty(exports, "__esModule", { value: true }); const lodash_1 = require("lodash"); const luxon_1 = require("luxon"); const repository_1 = require("../core/repository"); const Chance = require("chance"); class MediaRepository extends repository_1.Repository { async delete({ mediaId, mediaType = 'PHOTO', }) { const { body } = await this.client.request.send({ url: `/api/v1/media/${mediaId}/delete/`, method: 'POST', qs: { media_type: mediaType, }, form: this.client.request.sign({ igtv_feed_preview: false, media_id: mediaId, _csrftoken: this.client.state.cookieCsrfToken, _uid: this.client.state.cookieUserId, _uuid: this.client.state.uuid, }), }); return body; } async likeAction(options) { const signedFormData = this.client.request.sign(Object.assign({ module_name: options.moduleInfo.module_name, media_id: options.mediaId, _csrftoken: this.client.state.cookieCsrfToken }, lodash_1.omit(options.moduleInfo, 'module_name'), { radio_type: this.client.state.radioType, _uid: this.client.state.cookieUserId, device_id: this.client.state.deviceId, _uuid: this.client.state.uuid })); const { body } = await this.client.request.send({ url: `/api/v1/media/${options.mediaId}/${options.action}/`, method: 'POST', form: Object.assign({}, signedFormData, { d: options.d }), }); return body; } async like(options) { return this.likeAction(Object.assign({ action: 'like' }, options)); } async unlike(options) { return this.likeAction(Object.assign({ action: 'unlike' }, options)); } async comment({ mediaId, text, module = 'self_comments_v2', }) { const { body } = await this.client.request.send({ url: `/api/v1/media/${mediaId}/comment/`, method: 'POST', form: this.client.request.sign({ user_breadcrumb: this.client.request.userBreadcrumb(text.length), idempotence_token: new Chance().guid(), _csrftoken: this.client.state.cookieCsrfToken, radio_type: this.client.state.radioType, _uid: this.client.state.cookieUserId, device_id: this.client.state.deviceId, _uuid: this.client.state.uuid, comment_text: text, containermodule: module, }), }); return body.comment; } async likers(id) { const { body } = await this.client.request.send({ url: `/api/v1/media/${id}/likers/`, }); return body; } async blocked() { const { body } = await this.client.request.send({ url: `/api/v1/media/blocked/`, }); return body.media_ids; } async uploadFinish(options) { const { body } = await this.client.request.send({ url: '/api/v1/media/upload_finish/', method: 'POST', headers: { retry_context: JSON.stringify({ num_step_auto_retry: 0, num_reupload: 0, num_step_manual_retry: 0 }), }, form: this.client.request.sign({ timezone_offset: this.client.state.timezoneOffset, _csrftoken: this.client.state.cookieCsrfToken, source_type: options.source_type, _uid: this.client.state.cookieUserId, device_id: this.client.state.deviceId, _uuid: this.client.state.uuid, upload_id: options.upload_id, device: this.client.state.devicePayload, }), }); return body; } async configure(options) { const devicePayload = this.client.state.devicePayload; const now = luxon_1.DateTime.local().toFormat('yyyy:mm:dd HH:mm:ss'); const width = options.width || 1520; const height = options.height || 2048; const form = lodash_1.defaultsDeep(options, { date_time_digitalized: now, camera_model: devicePayload.model, scene_capture_type: 'standard', timezone_offset: this.client.state.timezoneOffset, _csrftoken: this.client.state.cookieCsrfToken, media_folder: 'Camera', source_type: '4', _uid: this.client.state.cookieUserId, device_id: this.client.state.deviceId, _uuid: this.client.state.uuid, creation_logger_session_id: this.client.state.clientSessionId, caption: '', date_time_original: now, software: '1', camera_make: devicePayload.manufacturer, device: devicePayload, edits: { crop_original_size: [width, height], crop_center: [0.0, -0.0], crop_zoom: lodash_1.random(1.01, 1.99).toFixed(7), }, extra: { source_width: width, source_height: height }, }); const { body } = await this.client.request.send({ url: '/api/v1/media/configure/', method: 'POST', form: this.client.request.sign(form), }); return body; } } exports.MediaRepository = MediaRepository; //# sourceMappingURL=media.repository.js.map