'use strict'; const unprint = require('unprint'); const slugify = require('../src/utils/slugify'); const limit = Number(process.env.MV_LIMIT) || 1000; async function fetchCreators(page = 1, acc = []) { console.log(`Fetching creators ${acc.length}/${limit}`); // size seems to be capped at 70 const res = await unprint.get(`https://api.manyvids.com/search/creators/list?contentPref=1,2,3&sort=top&size=50&from=${(page - 1) * 50}`); if (res.ok && res.data?.creators) { const creators = acc.concat(res.data.creators.map((creator) => ({ name: creator.stageName, slug: `mv.${slugify(creator.slug, '')}`, url: `https://www.manyvids.com/Profile/${creator.id}/${creator.slug}/`, emblem: creator.avatar?.url || null, }))); if (creators.length >= limit) { return creators; } return fetchCreators(page + 1, creators); } return acc; } exports.seed = async function (knex) { const channels = await fetchCreators(); const manyvidsNetwork = await knex('entities') .where('slug', 'manyvids') .where('type', 'network') .first(); if (!manyvidsNetwork) { throw new Error('ManyVids found, did the network migration run?'); } await knex('entities') .insert(channels.map((channel) => ({ name: channel.name, slug: channel.slug, url: channel.url, parent_id: manyvidsNetwork.id, has_logo: false, }))) .onConflict(['slug', 'type']) .merge(['name', 'url']); console.log(`Done! ${channels.length} ManyVids creators added as channels`); };