Secure your code as it's written. Use Snyk Code to scan source code in minutes - no build needed - and fix issues immediately.
const path = require('path')
const Client = require('instagram-private-api').V1
const settings = require('../src/lib/settings').actions.instagram
const cookiePath = path.join('/tmp', settings.account + '.json')
var device = new Client.Device(settings.account)
var storage = new Client.CookieFileStorage(cookiePath)
module.exports = {
run: (options) => {
return new Promise((resolve, reject) => {
if (options.media === undefined || options.media === '') {
return reject(new Error(JSON.stringify({
err: 'invalid request',
details: 'Error: No media in request'
})))
}
Client.Session.create(device, storage, settings.account, settings.password)
.then((session) => {
Client.Upload.photo(session, options.media)
.then((upload) => {
console.log('Uploading ' + path.basename(options.media))
const loadSession = async user => {
let path = utils.buildPath(user.hash)
let device = new api.Device(user.username)
let storage = new api.CookieFileStorage(path)
if (storage) {
return new api.Session(device, storage)
} else {
let file = await createSessionFile(user)
if (file) console.log('Session File Created')
return false
}
}
const createSession = async (user, password) => {
let path = utils.buildPath(user.hash)
let device = new api.Device(user.username)
let storage = new api.CookieFileStorage(path)
if (storage) {
try {
let conn = await api.Session.create(device, storage, user.username, password)
return conn
} catch (e) {
return e
}
} else {
try {
let file = await createSessionFile(user)
if (!file) {
console.log('error')
}
return false
} catch (e) {
console.log('here', e)
` argument must be a number. Instead it's a ${typeof argv.interval}`
);
let _username;
if (!argv.username) {
const { username } = await inquirer.prompt({
name: "username",
message: "Instagram Username: "
});
_username = username;
} else {
_username = argv.username;
}
device = new Client.Device(_username);
storage = new Client.CookieFileStorage(
__dirname + `/ig-cookie.${_username}.json`
);
let _password;
if (!argv.password) {
const { password } = await inquirer.prompt({
name: "password",
message: "Instagram password: ",
type: "password"
});
_password = password;
} else {
_password = argv.password;
}
const loginSpinner = ora(`Logging in as ${_username}`).start();
const loadSession = user => {
let path = utils.buildPath(user.hash)
let device = new api.Device(user.username)
let storage = new api.CookieFileStorage(path)
return new api.Session(device, storage)
}
};
let _username;
if (!argv.username) {
const { username } = await inquirer.prompt({
name: "username",
message: "Instagram Username: "
});
_username = username;
} else {
_username = argv.username;
}
device = new Client.Device(`instagram.com/${_username}`);
storage = argv.persist
? new Client.CookieFileStorage(
__dirname + ("/ig-cookie." + _username + ".json")
)
: new Client.CookieMemoryStorage();
let _password;
if (!argv.password) {
const { password } = await inquirer.prompt({
name: "password",
message: "Instagram password: ",
type: "password"
});
_password = password;
} else {
_password = argv.password;
}
const config = require('../config');
const findandLikeTag = require('./like-insta');
const findAndCommentTag = require('./comment-insta');
const { user, pass } = config.igauth;
const Client = require('instagram-private-api').V1;
const device = new Client.Device(user);
const storage = new Client.CookieFileStorage(`${global.base}/cookies/${user}.json`);
let session;
function createSession() {
if(!session) {
return Client.Session.create(device, storage, user, pass)
.then(ses => {
session = ses;
return session;
});
}
return Promise.resolve(session);
}
function likeOrCommentInsta() {
const rand = (Math.random() * 10);
const getCookieStorage = (filePath) => {
let storage;
let username;
if (canUseFileStorage()) {
if (!filePath && (username = guessUsername())) {
filePath = `${username}.json`
}
if (filePath) storage = new Client.CookieFileStorage(`${buildAndGetStoragePath()}/${filePath}`);
} else {
storage = new Client.CookieMemoryStorage();
}
return storage;
}