Added network to profile context when site is available.

This commit is contained in:
ThePendulum 2020-05-18 03:34:41 +02:00
parent 885aa4f627
commit 003e07491d
3 changed files with 14 additions and 5 deletions

View File

@ -14,6 +14,7 @@ const logger = require('./logger')(__filename);
const { toBaseReleases } = require('./deep'); const { toBaseReleases } = require('./deep');
const { associateAvatars } = require('./media'); const { associateAvatars } = require('./media');
const { curateSite } = require('./sites');
const slugify = require('./utils/slugify'); const slugify = require('./utils/slugify');
const capitalize = require('./utils/capitalize'); const capitalize = require('./utils/capitalize');
@ -369,7 +370,7 @@ async function scrapeProfiles(actor, sources, networksBySlug, sitesBySlug) {
const scraper = scrapers[scraperSlug]; const scraper = scrapers[scraperSlug];
const context = { const context = {
site: sitesBySlug[scraperSlug] || null, site: sitesBySlug[scraperSlug] || null,
network: networksBySlug[scraperSlug] || null, network: networksBySlug[scraperSlug] || sitesBySlug[scraperSlug]?.network || null,
scraper: scraperSlug, scraper: scraperSlug,
}; };
@ -418,7 +419,13 @@ async function scrapeActors(actorNames) {
const [networks, sites, existingActorEntries] = await Promise.all([ const [networks, sites, existingActorEntries] = await Promise.all([
knex('networks').whereIn('slug', siteSlugs), knex('networks').whereIn('slug', siteSlugs),
knex('sites').whereIn('slug', siteSlugs), knex('sites')
.select(
'sites.*',
'networks.name as network_name', 'networks.slug as network_slug', 'networks.url as network_url', 'networks.description as network_description', 'networks.parameters as network_parameters',
)
.whereIn('sites.slug', siteSlugs)
.leftJoin('networks', 'sites.network_id', 'networks.id'),
knex('actors') knex('actors')
.select(['id', 'name', 'slug']) .select(['id', 'name', 'slug'])
.whereIn('slug', baseActors.map(baseActor => baseActor.slug)) .whereIn('slug', baseActors.map(baseActor => baseActor.slug))
@ -428,7 +435,7 @@ async function scrapeActors(actorNames) {
const existingActorEntriesBySlug = existingActorEntries.reduce((acc, actorEntry) => ({ ...acc, [actorEntry.slug]: actorEntry }), {}); const existingActorEntriesBySlug = existingActorEntries.reduce((acc, actorEntry) => ({ ...acc, [actorEntry.slug]: actorEntry }), {});
const networksBySlug = networks.reduce((acc, network) => ({ ...acc, [network.slug]: network }), {}); const networksBySlug = networks.reduce((acc, network) => ({ ...acc, [network.slug]: network }), {});
const sitesBySlug = sites.reduce((acc, site) => ({ ...acc, [site.slug]: site }), {}); const sitesBySlug = sites.reduce((acc, site) => ({ ...acc, [site.slug]: curateSite(site) }), {});
const newBaseActors = baseActors.filter(baseActor => !existingActorEntriesBySlug[baseActor.slug]); const newBaseActors = baseActors.filter(baseActor => !existingActorEntriesBySlug[baseActor.slug]);

View File

@ -615,7 +615,7 @@ async function associateAvatars(profiles) {
? { ? {
...profile, ...profile,
avatarBaseMedia: toBaseMedias([profile.avatar], 'avatars', { avatarBaseMedia: toBaseMedias([profile.avatar], 'avatars', {
copyright: profile.network?.name || null, copyright: profile.network?.name || profile.site?.name || null,
scraper: profile.scraper || null, scraper: profile.scraper || null,
})[0], })[0],
} }

View File

@ -7,7 +7,7 @@ const argv = require('./argv');
const knex = require('./knex'); const knex = require('./knex');
const whereOr = require('./utils/where-or'); const whereOr = require('./utils/where-or');
async function curateSite(site, includeParameters = false, includeTags = true) { function curateSite(site, includeParameters = false) {
const curatedSite = { const curatedSite = {
id: site.id, id: site.id,
name: site.name, name: site.name,
@ -26,12 +26,14 @@ async function curateSite(site, includeParameters = false, includeTags = true) {
}, },
}; };
/*
if (includeTags) { if (includeTags) {
curatedSite.tags = await knex('sites_tags') curatedSite.tags = await knex('sites_tags')
.select('tags.*', 'sites_tags.inherit') .select('tags.*', 'sites_tags.inherit')
.where('site_id', site.id) .where('site_id', site.id)
.join('tags', 'tags.id', 'sites_tags.tag_id'); .join('tags', 'tags.id', 'sites_tags.tag_id');
} }
*/
return curatedSite; return curatedSite;
} }