Secure your code as it's written. Use Snyk Code to scan source code in minutes - no build needed - and fix issues immediately.
exports.isCheckpointError = (error) => {
return (error instanceof Client.Exceptions.CheckpointError)
}
exports.isCheckpointError = (error) => {
return (error instanceof Client.Exceptions.CheckpointError)
}
import path from 'path';
import fs from 'fs';
import crypto from 'crypto';
import micro, { json } from 'micro';
import { router, get, post } from 'microrouter';
import { V1 as Client } from 'instagram-private-api';
import { register, read } from './instapi';
const { CookieNotValidError, AuthenticationError } = Client.Exceptions;
const cors = require('micro-cors')();
const compose = (...fns) => fns.reduce((f, g) => (...args) => f(g(...args)));
const cookiesJar = path.join(__dirname, '/cookies');
if (!fs.existsSync(cookiesJar)) {
fs.mkdirSync(cookiesJar);
}
const paramError = {
error: {
name: 'ParameterError',
message: 'Both user and password are required.',
},
};
return new Promise((resolve, reject) => {
if (!session) {
const device = utils.getDevice();
const storage = utils.getCookieStorage();
if (!device || !storage) {
return resolve({ isLoggedIn: false });
}
session = new Client.Session(device, storage);
}
session.getAccountId()
.then(() => resolve({ isLoggedIn: true, session }))
.catch(Client.Exceptions.CookieNotValidError, () => resolve({ isLoggedIn: false }))
});
}
return new Promise((resolve, reject) => {
if (!session) {
const device = utils.getDevice();
const storage = utils.getCookieStorage();
if (!device || !storage) {
return resolve({ isLoggedIn: false });
}
session = new Client.Session(device, storage);
}
session.getAccountId()
.then(() => resolve({ isLoggedIn: true, session }))
.catch(Client.Exceptions.CookieNotValidError, () => resolve({ isLoggedIn: false }))
});
}