Skip to content

Commit

Permalink
(Prettier) reformat /src folder
Browse files Browse the repository at this point in the history
  • Loading branch information
dilame committed Apr 4, 2019
1 parent c14ad5d commit ba56dd4
Show file tree
Hide file tree
Showing 44 changed files with 316 additions and 310 deletions.
14 changes: 7 additions & 7 deletions src/core/cookies/cookie-file-storage.ts
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,7 @@ const path = require('path');
const fs = require('fs');

export class CookieFileStorage extends CookieStorage {
constructor (cookiePath) {
constructor(cookiePath) {
cookiePath = path.resolve(cookiePath);
CookieFileStorage.ensureExistenceOfJSONFilePath(cookiePath);
const store = new FileCookieStore(cookiePath);
Expand All @@ -20,12 +20,7 @@ export class CookieFileStorage extends CookieStorage {
super(store);
}

destroy () {
// @ts-ignore
fs.unlinkSync(this.storage.filePath);
}

static ensureExistenceOfJSONFilePath(path){
static ensureExistenceOfJSONFilePath(path) {
try {
touch.sync(path);
JSON.parse(fs.readFileSync(path));
Expand All @@ -34,4 +29,9 @@ export class CookieFileStorage extends CookieStorage {
}
touch.sync(path);
}

destroy() {
// @ts-ignore
fs.unlinkSync(this.storage.filePath);
}
}
4 changes: 2 additions & 2 deletions src/core/cookies/cookie-memory-storage.ts
Original file line number Diff line number Diff line change
Expand Up @@ -2,9 +2,9 @@ import { MemoryCookieStore } from 'tough-cookie/lib/memstore';
import { CookieStorage } from './cookie-storage';

export class CookieMemoryStorage extends CookieStorage {
constructor () {
constructor() {
super(new MemoryCookieStore());
}

destroy () {}
destroy() {}
}
17 changes: 8 additions & 9 deletions src/core/cookies/cookie-storage.ts
Original file line number Diff line number Diff line change
Expand Up @@ -5,10 +5,9 @@ import { CookieNotValidError } from '../exceptions';
import { Store } from 'tough-cookie';

export class CookieStorage {
constructor(public storage: Store) {
}
constructor(public storage: Store) {}

get store () {
get store() {
return this.storage;
}

Expand All @@ -22,11 +21,11 @@ export class CookieStorage {
});
}

putCookie (cookie) {
putCookie(cookie) {
return Bluebird.fromCallback(cb => this.storage.putCookie(cookie, cb));
}

getCookies () {
getCookies() {
return new Bluebird((resolve, reject) => {
this.storage.findCookies(TLD, '/', (err, cookies) => {
if (err) return reject(err);
Expand All @@ -35,7 +34,7 @@ export class CookieStorage {
});
}

getAccountId (): Bluebird<number> {
getAccountId(): Bluebird<number> {
return this.getCookieValue('ds_user_id').then(cookie => {
const id = parseInt(cookie.value);
if (_.isNumber(id) && !_.isNaN(id)) {
Expand All @@ -46,7 +45,7 @@ export class CookieStorage {
});
}

getSessionId () {
getSessionId() {
const currentTime = new Date().getTime();
return this.getCookieValue('sessionid').then(cookie => {
const acceptable = cookie.expires instanceof Date && cookie.expires.getTime() > currentTime;
Expand All @@ -55,7 +54,7 @@ export class CookieStorage {
});
}

removeCheckpointStep () {
removeCheckpointStep() {
return new Bluebird((resolve, reject) => {
this.storage.removeCookie(TLD, '/', 'checkpoint_step', err => {
if (err) return reject(err);
Expand All @@ -64,7 +63,7 @@ export class CookieStorage {
});
}

destroy () {
destroy() {
throw new Error('Method destroy is not implemented');
}
}
2 changes: 1 addition & 1 deletion src/core/devices/device.ts
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@ import * as builds from './builds.json';
import * as CONSTANTS from '../../constants/constants';
import * as _ from 'lodash';
import { IAppCredentials, IDevicePayload } from './device.interface';
import {pruned} from '../../v1/json-pruned';
import { pruned } from '../../v1/json-pruned';
import hmac = require('crypto-js/hmac-sha256');

export class Device {
Expand Down
1 change: 0 additions & 1 deletion src/core/exceptions.ts
Original file line number Diff line number Diff line change
Expand Up @@ -175,7 +175,6 @@ export class NotPossibleToResolveChallenge extends APIError {
}
}


export class NoChallengeRequired extends APIError {
constructor() {
super('No challenge is required to use account!');
Expand Down
6 changes: 5 additions & 1 deletion src/core/session.ts
Original file line number Diff line number Diff line change
Expand Up @@ -28,7 +28,11 @@ export class Session {
public loginAttemptCount = 0;
private jar: any;

constructor(public device: Device, public cookieStore: CookieStorage = new CookieMemoryStorage(), proxy: string = null) {
constructor(
public device: Device,
public cookieStore: CookieStorage = new CookieMemoryStorage(),
proxy: string = null,
) {
this.jar = Request.jar(cookieStore.store);
this.proxyUrl = proxy;
}
Expand Down
19 changes: 11 additions & 8 deletions src/feeds/abstract.feed.ts
Original file line number Diff line number Diff line change
Expand Up @@ -34,16 +34,19 @@ export abstract class AbstractFeed<T> extends EventEmitter {
this.rankToken = chance.guid();
}

abstract async get(...parameters: any[]): Promise<T[]>
abstract async get(...parameters: any[]): Promise<T[]>;

all(parameters: Partial<IBaseFeedAllOptions> = {}) {
parameters = Object.assign({
delay: 1500,
every: 200,
pause: 30000,
maxErrors: 9,
limit: this.limit || Infinity,
}, parameters);
parameters = Object.assign(
{
delay: 1500,
every: 200,
pause: 30000,
maxErrors: 9,
limit: this.limit || Infinity,
},
parameters,
);
// every N requests we take a pause
const delay =
this.iteration === 0 ? 0 : this.iteration % parameters.every !== 0 ? parameters.delay : parameters.pause;
Expand Down
11 changes: 5 additions & 6 deletions src/feeds/inbox-pending.feed.ts
Original file line number Diff line number Diff line change
@@ -1,21 +1,21 @@
import { AbstractFeed } from './abstract.feed';
import { Request } from '../core/request';
import {Thread} from '../v1/thread';

import { Thread } from '../v1/thread';

export class InboxPendingFeed extends AbstractFeed<any> {
pendingRequestsTotal: any;
constructor (session, limit) {

constructor(session, limit) {
super(session);
this.limit = parseInt(limit) || null;
this.pendingRequestsTotal = null;
}

getPendingRequestsTotal () {
getPendingRequestsTotal() {
return this.pendingRequestsTotal;
}

get (): any {
get(): any {
const that = this;
return new Request(this.session)
.setMethod('GET')
Expand All @@ -31,4 +31,3 @@ export class InboxPendingFeed extends AbstractFeed<any> {
});
}
}

2 changes: 1 addition & 1 deletion src/feeds/inbox.feed.ts
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
import { Request, Session } from '../core';
import { AbstractFeed } from './abstract.feed';
import {Thread} from '../v1/thread';
import { Thread } from '../v1/thread';

export class InboxFeed extends AbstractFeed<any> {
public pendingRequestsTotal: null;
Expand Down
30 changes: 15 additions & 15 deletions src/feeds/index.ts
Original file line number Diff line number Diff line change
@@ -1,15 +1,15 @@
export * from './account-followers.feed'
export * from './account-following.feed'
export * from './inbox.feed'
export * from './inbox-pending.feed'
export * from './location-media.feed'
export * from './media-comments.feed'
export * from './saved-media.feed'
export * from './self-liked.feed'
export * from './story-tray.feed'
export * from './story-viewers.feed'
export * from './tagged-media.feed'
export * from './thread-items.feed'
export * from './timeline.feed'
export * from './user-media.feed'
export * from './user-story.feed'
export * from './account-followers.feed';
export * from './account-following.feed';
export * from './inbox.feed';
export * from './inbox-pending.feed';
export * from './location-media.feed';
export * from './media-comments.feed';
export * from './saved-media.feed';
export * from './self-liked.feed';
export * from './story-tray.feed';
export * from './story-viewers.feed';
export * from './tagged-media.feed';
export * from './thread-items.feed';
export * from './timeline.feed';
export * from './user-media.feed';
export * from './user-story.feed';
4 changes: 1 addition & 3 deletions src/feeds/location-media.feed.ts
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,6 @@ import { Request } from '../core/request';
import { OnlyRankedItemsError, ParseError, PlaceNotFound } from '../core/exceptions';
import { MediaResponse } from '../responses/media.response';


export class LocationMediaFeed extends AbstractFeed<MediaResponse> {
constructor(session, public locationId: string | number, public limit = Infinity) {
super(session);
Expand All @@ -25,8 +24,7 @@ export class LocationMediaFeed extends AbstractFeed<MediaResponse> {
throw new PlaceNotFound();
});
this.moreAvailable = data.more_available && !!data.next_max_id;
if (!this.moreAvailable && !_.isEmpty(data.ranked_items) && !this.getCursor())
throw new OnlyRankedItemsError();
if (!this.moreAvailable && !_.isEmpty(data.ranked_items) && !this.getCursor()) throw new OnlyRankedItemsError();
if (this.moreAvailable) this.setCursor(data.next_max_id);
return plainToClass(MediaResponse, data.items);
}
Expand Down
1 change: 0 additions & 1 deletion src/feeds/saved-media.feed.ts
Original file line number Diff line number Diff line change
Expand Up @@ -25,4 +25,3 @@ export class SavedMediaFeed extends AbstractFeed<MediaResponse> {
return plainToClass(MediaResponse, data.items.map(i => i.media));
}
}

3 changes: 1 addition & 2 deletions src/feeds/story-tray.feed.ts
Original file line number Diff line number Diff line change
Expand Up @@ -4,8 +4,7 @@ import { plainToClass } from 'class-transformer';
import { Request } from '../core/request';

export class StoryTrayFeed {
constructor(private session) {
}
constructor(private session) {}

async get() {
const { tray } = await new Request(this.session)
Expand Down
5 changes: 1 addition & 4 deletions src/feeds/tagged-media.feed.ts
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,6 @@ import { MediaResponse } from '../responses/media.response';
import { Request } from '../core/request';
import { OnlyRankedItemsError } from '../core/exceptions';


export class TaggedMediaFeed extends AbstractFeed<MediaResponse> {
constructor(session, public tag: string, public limit = Infinity) {
super(session);
Expand All @@ -27,8 +26,7 @@ export class TaggedMediaFeed extends AbstractFeed<MediaResponse> {

async get(): Promise<MediaResponse[]> {
const data = await this.getRawResponse();
if (!this.moreAvailable && !_.isEmpty(data.ranked_items) && !this.getCursor())
throw new OnlyRankedItemsError();
if (!this.moreAvailable && !_.isEmpty(data.ranked_items) && !this.getCursor()) throw new OnlyRankedItemsError();
return plainToClass(MediaResponse, data.items);
}

Expand All @@ -37,4 +35,3 @@ export class TaggedMediaFeed extends AbstractFeed<MediaResponse> {
return plainToClass(MediaResponse, data.ranked_items);
}
}

6 changes: 3 additions & 3 deletions src/feeds/thread-items.feed.ts
Original file line number Diff line number Diff line change
@@ -1,17 +1,17 @@
import { AbstractFeed } from './abstract.feed';
import { Request } from '../core/request';
import {ThreadItem} from '../v1/thread-item';
import { ThreadItem } from '../v1/thread-item';

export class ThreadItemsFeed extends AbstractFeed<any> {
threadId: any;

constructor (session, threadId, limit) {
constructor(session, threadId, limit) {
super(session);
this.threadId = threadId;
this.limit = parseInt(limit) || null;
}

get (): any {
get(): any {
return new Request(this.session)
.setMethod('GET')
.setResource('threadsShow', {
Expand Down
3 changes: 1 addition & 2 deletions src/feeds/user-story.feed.ts
Original file line number Diff line number Diff line change
Expand Up @@ -3,8 +3,7 @@ import { MediaResponse } from '../responses/media.response';
import { plainToClass } from 'class-transformer';

export class UserStoryFeed {
constructor(public session: Session, public userIds: (string | number)[]) {
}
constructor(public session: Session, public userIds: (string | number)[]) {}

async get(): Promise<MediaResponse[]> {
const data = await new Request(this.session)
Expand Down
10 changes: 5 additions & 5 deletions src/finder.ts
Original file line number Diff line number Diff line change
Expand Up @@ -4,13 +4,14 @@ let USERNAMETOFIND;
let COMMENTTOFIND;

import Client from './v1';

const path = require('path');

const { urlSegmentToInstagramId } = require('instagram-id-to-url-segment');

let MediaComments;

export function main (usernameToFind, commentToFind, postUrl) {
export function main(usernameToFind, commentToFind, postUrl) {
return new Promise(async (resolve, reject) => {
USERNAMETOFIND = usernameToFind;
COMMENTTOFIND = commentToFind;
Expand Down Expand Up @@ -38,7 +39,7 @@ export function main (usernameToFind, commentToFind, postUrl) {
});
}

async function loop (cb) {
async function loop(cb) {
const Comments = await get();

if (!Comments) {
Expand All @@ -55,7 +56,7 @@ async function loop (cb) {
setTimeout(loop, 5000, cb);
}

async function get () {
async function get() {
if (MediaComments.iteration == 0) {
return await MediaComments.get();
} else if (MediaComments.moreAvailable) {
Expand All @@ -65,7 +66,7 @@ async function get () {
}
}

function process (Comments) {
function process(Comments) {
for (let idx = 0; idx < Comments.length; idx++) {
if (Comments[idx]._params.user.username == USERNAMETOFIND) {
if (Comments[idx]._params.text == COMMENTTOFIND) {
Expand All @@ -77,7 +78,6 @@ function process (Comments) {
return false;
}


// https://www.instagram.com/p/BjU_XzGAQaW/?taken-by=kennethaharris
// 1789333664312657558
// 15247386
Expand Down
Loading

0 comments on commit ba56dd4

Please sign in to comment.