Storing actor socials, improved Hush profile scraper.
This commit is contained in:
@@ -775,7 +775,41 @@ async function scrapeProfiles(actor, sources, entitiesBySlug, existingProfilesBy
|
||||
}
|
||||
|
||||
async function associateSocials(profiles) {
|
||||
console.log('profiles', profiles);
|
||||
const profileEntries = await knex('actors_profiles').whereIn(['actor_id', 'entity_id'], profiles.map((profile) => [profile.id, profile.entity.id]));
|
||||
|
||||
const profileEntriesByActorIdAndEntityId = profileEntries.reduce((acc, profileEntry) => {
|
||||
if (!acc[profileEntry.actor_id]) {
|
||||
acc[profileEntry.actor_id] = {};
|
||||
}
|
||||
|
||||
acc[profileEntry.actor_id][profileEntry.entity_id] = profileEntry.id;
|
||||
|
||||
return acc;
|
||||
}, {});
|
||||
|
||||
profiles.reduce(async (chain, profile) => {
|
||||
await chain;
|
||||
|
||||
if (!Array.isArray(profile.social) || profile.social.length === 0) {
|
||||
return;
|
||||
}
|
||||
|
||||
const profileId = profileEntriesByActorIdAndEntityId[profile.id]?.[profile.entity.id];
|
||||
|
||||
if (!profileId) {
|
||||
return;
|
||||
}
|
||||
|
||||
await knex('actors_social')
|
||||
.insert(profile.social.map((url) => ({
|
||||
url,
|
||||
platform: new URL(url).hostname.match(/([\w-]+)?\.(\w+)$/)?.[1],
|
||||
actor_id: profile.id,
|
||||
profile_id: profileId,
|
||||
})))
|
||||
.onConflict()
|
||||
.ignore();
|
||||
}, Promise.resolve());
|
||||
}
|
||||
|
||||
async function getActorNames(actorNames) {
|
||||
@@ -801,7 +835,7 @@ async function storeProfiles(profiles) {
|
||||
const profilesWithAvatarIds = await associateAvatars(profiles);
|
||||
const actorIds = Array.from(new Set(profiles.map((profile) => profile.id)));
|
||||
|
||||
// await associateSocials(profiles);
|
||||
await associateSocials(profiles);
|
||||
|
||||
await upsertProfiles(profilesWithAvatarIds);
|
||||
await interpolateProfiles(actorIds);
|
||||
|
||||
Reference in New Issue
Block a user