<commit_before>import * as _ from 'lodash';
import * as Bluebird from 'bluebird';
import { plainToClass } from 'class-transformer';
import { User } from '../models/user';
import { Request, Session, IGAccountNotFoundError, RequestError } from '../core';
import { Helpers } from '../helpers';

export class Account {
  static async getById(session: Session, id: string | number): Promise<User> {
    const data = await new Request(session)
      .setMethod('GET')
      .setResource('userInfo', { id })
      .send();
    return plainToClass(User, data.user as User);
  }

  static async search(session: Session, username: string): Promise<User[]> {
    const uid = await session.getAccountId();
    const rankToken = Helpers.buildRankToken(uid);
    const data = await new Request(session)
      .setMethod('GET')
      .setResource('accountsSearch', {
        query: username,
        rankToken,
      })
      .send();
    return plainToClass(User, data.users);
  }

  static async searchForUser(session: Session, username: string): Promise<User> {
    const accounts = await Account.search(session, username);
    const account = accounts.find(account => account.username === username);
    if (!account) throw new IGAccountNotFoundError();
    return account;
  }

  static async setProfilePicture(session: Session, streamOrPath: any): Promise<User> {
    const stream = Helpers.pathToStream(streamOrPath);
    const request = new Request(session);
    const data = await request
      .setMethod('POST')
      .setResource('changeProfilePicture')
      .generateUUID()
      .signPayload()
      .transform(opts => {
        opts.formData.profile_pic = {
          value: stream,
          options: {
            filename: 'profile_pic',<commit_msg>(account) force username.toLowerCase in searchForUser method Because all instagram usernames are lowercased<commit_after>import * as _ from 'lodash';
import * as Bluebird from 'bluebird';
import { plainToClass } from 'class-transformer';
import { User } from '../models/user';
import { Request, Session, IGAccountNotFoundError, RequestError } from '../core';
import { Helpers } from '../helpers';

export class Account {
  static async getById(session: Session, id: string | number): Promise<User> {
    const data = await new Request(session)
      .setMethod('GET')
      .setResource('userInfo', { id })
      .send();
    return plainToClass(User, data.user as User);
  }

  static async search(session: Session, username: string): Promise<User[]> {
    const uid = await session.getAccountId();
    const rankToken = Helpers.buildRankToken(uid);
    const data = await new Request(session)
      .setMethod('GET')
      .setResource('accountsSearch', {
        query: username,
        rankToken,
      })
      .send();
    return plainToClass(User, data.users);
  }

  static async searchForUser(session: Session, username: string): Promise<User> {
    username = username.toLowerCase();
    const accounts = await Account.search(session, username);
    const account = accounts.find(account => account.username === username);
    if (!account) throw new IGAccountNotFoundError();
    return account;
  }

  static async setProfilePicture(session: Session, streamOrPath: any): Promise<User> {
    const stream = Helpers.pathToStream(streamOrPath);
    const request = new Request(session);
    const data = await request
      .setMethod('POST')
      .setResource('changeProfilePicture')
      .generateUUID()
      .signPayload()
      .transform(opts => {
        opts.formData.profile_pic = {
          value: stream,
          options: {
            filename: 'profile_pic',
{'fraction_non_alphanumeric': 0.12201154163231658, 'fraction_numerical': 0.0, 'mean_word_length': 3.4014510278113663, 'pattern_counts': {'":': 0, '<': 11, '<?xml version=': 0, '>': 15, 'https://': 0, 'lorem ipsum': 0, 'www.': 0, 'xml': 0}, 'pii_count': 0, 'substrings_counts': 0, 'word_list_counts': {'cursed_substrings.json': 0, 'profanity_word_list.json': 0, 'sexual_word_list.json': 0, 'zh_pornsignals.json': 0}}
{'dir': 'git-commits-cleaned', 'id': '6769004', 'n_tokens_mistral': 995, 'n_tokens_neox': 995, 'n_words': 280}