Compare commits

...

15 Commits

3 changed files with 65 additions and 113 deletions

View File

@@ -45,70 +45,6 @@ function getAverage(items) {
return Math.round(items.reduce((acc, item) => acc + item, 0) / items.length) || null; return Math.round(items.reduce((acc, item) => acc + item, 0) / items.length) || null;
} }
function curateProfileEntry(profile) {
if (!profile.id) {
return null;
}
const curatedProfileEntry = {
...(profile.update !== false && { id: profile.update }),
actor_id: profile.id,
entity_id: profile.entity?.id || null,
date_of_birth: profile.dateOfBirth,
date_of_death: profile.dateOfDeath,
age: profile.age,
url: profile.url,
gender: profile.gender,
orientation: profile.orientation,
ethnicity: profile.ethnicity,
description: profile.description,
description_hash: profile.descriptionHash,
birth_city: profile.placeOfBirth?.city || null,
birth_state: profile.placeOfBirth?.state || null,
birth_country_alpha2: profile.placeOfBirth?.country || null,
residence_city: profile.placeOfResidence?.city || null,
residence_state: profile.placeOfResidence?.state || null,
residence_country_alpha2: profile.placeOfResidence?.country || null,
cup: profile.cup,
bust: profile.bust,
waist: profile.waist,
leg: profile.leg,
thigh: profile.thigh,
foot: profile.foot,
hip: profile.hip,
penis_length: profile.penisLength,
penis_girth: profile.penisGirth,
circumcised: profile.circumcised,
natural_boobs: profile.naturalBoobs,
boobs_volume: profile.boobsVolume,
boobs_implant: profile.boobsImplant,
boobs_placement: profile.boobsPlacement,
boobs_incision: profile.boobsIncision,
boobs_surgeon: profile.boobsSurgeon,
natural_butt: profile.naturalButt,
butt_volume: profile.buttVolume,
butt_implant: profile.buttImplant,
natural_lips: profile.naturalLips,
lips_volume: profile.lipsVolume,
natural_labia: profile.naturalLabia,
height: profile.height,
weight: profile.weight,
shoe_size: profile.shoeSize,
hair_color: profile.hairColor,
hair_type: profile.hairType,
eyes: profile.eyes,
has_tattoos: profile.hasTattoos,
has_piercings: profile.hasPiercings,
piercings: profile.piercings,
tattoos: profile.tattoos,
agency: profile.agency,
blood_type: profile.bloodType,
avatar_media_id: profile.avatarMediaId || null,
};
return curatedProfileEntry;
}
async function fetchProfiles(actorIdsOrNames, { knex }) { async function fetchProfiles(actorIdsOrNames, { knex }) {
return knex('actors_profiles') return knex('actors_profiles')
.select(knex.raw('actors_profiles.*, actors.name, row_to_json(media) as avatar')) .select(knex.raw('actors_profiles.*, actors.name, row_to_json(media) as avatar'))
@@ -143,6 +79,8 @@ function mergeMainProfile(profile, mainProfile) {
export async function interpolateProfiles(actorIdsOrNames, context, options = {}) { export async function interpolateProfiles(actorIdsOrNames, context, options = {}) {
const profiles = await fetchProfiles(actorIdsOrNames, context); const profiles = await fetchProfiles(actorIdsOrNames, context);
const columns = await context.knex.table('actors').columnInfo().then((table) => Object.keys(table));
const preservedKeys = ['id', 'name', 'slug', 'entity_id', 'entry_id'];
const profilesByActorId = profiles.reduce((acc, profile) => ({ const profilesByActorId = profiles.reduce((acc, profile) => ({
...acc, ...acc,
@@ -155,6 +93,16 @@ export async function interpolateProfiles(actorIdsOrNames, context, options = {}
context.logger.info(`Interpolating ${profiles.length} profiles from ${Object.keys(profilesByActorId).length} actors`); context.logger.info(`Interpolating ${profiles.length} profiles from ${Object.keys(profilesByActorId).length} actors`);
const interpolatedProfiles = Object.entries(profilesByActorId).map(([actorId, actorProfiles]) => { const interpolatedProfiles = Object.entries(profilesByActorId).map(([actorId, actorProfiles]) => {
const mainProfile = actorProfiles.find((actorProfile) => actorProfile.entity_id === null);
if (mainProfile && actorProfiles.length === 1) {
// no other profiles to interpolate
return {
...Object.fromEntries(columns.map((key) => [key, mainProfile[key]])),
id: actorId,
};
}
// group values from each profile // group values from each profile
const valuesByProperty = actorProfiles const valuesByProperty = actorProfiles
.filter((profile) => profile.entity_id !== null) // main profile is interpolated separately at the end .filter((profile) => profile.entity_id !== null) // main profile is interpolated separately at the end
@@ -180,47 +128,8 @@ export async function interpolateProfiles(actorIdsOrNames, context, options = {}
}].filter((location) => Object.keys(location).length > 0), }].filter((location) => Object.keys(location).length > 0),
}), {}); }), {});
const mostFrequentValues = [
'gender',
'orientation',
'ethnicity',
'cup',
'bust',
'waist',
'hip',
'leg',
'thigh',
'foot',
'shoe_size',
'penis_length',
'penis_girth',
'circumcised',
'natural_boobs',
'boobs_volume',
'boobs_implant',
'boobs_incision',
'boobs_placement',
'boobs_surgeon',
'natural_butt',
'butt_volume',
'butt_implant',
'natural_lips',
'lips_volume',
'natural_labia',
'hair_color',
'eyes',
'has_tattoos',
'has_piercings',
'agency',
'blood_type',
].reduce((acc, property) => ({
...acc,
[property]: getMostFrequent(valuesByProperty[property], context),
}), {});
const profile = { const profile = {
id: actorId, id: actorId,
...mostFrequentValues,
}; };
profile.height = getMostFrequent(valuesByProperty.height.filter((height) => height > 50 && height < 300), context); // remove unlikely values profile.height = getMostFrequent(valuesByProperty.height.filter((height) => height > 50 && height < 300), context); // remove unlikely values
@@ -255,18 +164,23 @@ export async function interpolateProfiles(actorIdsOrNames, context, options = {}
profile.avatar_media_id = actorProfiles profile.avatar_media_id = actorProfiles
.map((actorProfile) => actorProfile.avatar) .map((actorProfile) => actorProfile.avatar)
.filter((avatar) => avatar && (avatar.entropy === null || avatar.entropy > 5.5)) .filter((avatar) => avatar && (avatar.entropy === null || avatar.entropy > 5.5) && !options.avoidAvatarCredits?.includes(avatar.credit) && !options.excludeAvatarCredits?.includes(avatar.credit))
.sort((avatarA, avatarB) => avatarB.height - avatarA.height)[0]?.id || null; .sort((avatarA, avatarB) => avatarB.height - avatarA.height)[0]?.id || null;
if (!profile.avatar_media_id) { if (!profile.avatar_media_id) {
// try to settle for low quality avatar // try to settle for low quality avatar
profile.avatar_media_id = actorProfiles profile.avatar_media_id = actorProfiles
.map((actorProfile) => actorProfile.avatar) .map((actorProfile) => actorProfile.avatar)
.filter((avatar) => avatar) .filter((avatar) => !!avatar && !options?.excludeAvatarCredits?.includes(avatar.credit))
.sort((avatarA, avatarB) => avatarB.height - avatarA.height)[0]?.id || null; .sort((avatarA, avatarB) => avatarB.height - avatarA.height)[0]?.id || null;
} }
const mainProfile = actorProfiles.find((actorProfile) => actorProfile.entity_id === null); columns.forEach((key) => {
// generic handling for remaining properties
if (Object.hasOwn(valuesByProperty, key) && !Object.hasOwn(profile, key) && !preservedKeys.includes(key)) {
profile[key] = getMostFrequent(valuesByProperty[key], context);
}
});
return mergeMainProfile(profile, mainProfile); return mergeMainProfile(profile, mainProfile);
}); });
@@ -274,9 +188,7 @@ export async function interpolateProfiles(actorIdsOrNames, context, options = {}
const transaction = await context.knex.transaction(); const transaction = await context.knex.transaction();
// clear existing interpolated data // clear existing interpolated data
const emptyProfile = Object const emptyProfile = Object.fromEntries(columns.filter((key) => !preservedKeys.includes(key)).map((key) => [key, null]));
.keys(context.omit(curateProfileEntry({ id: 1 }), ['id', 'actor_id', 'entity_id', 'url', 'description_hash']))
.reduce((acc, key) => ({ ...acc, [key]: null }), {});
await context.knex('actors') await context.knex('actors')
.modify((modifyBuilder) => { .modify((modifyBuilder) => {
@@ -301,9 +213,49 @@ export async function interpolateProfiles(actorIdsOrNames, context, options = {}
await Promise.all(queries) await Promise.all(queries)
.then(transaction.commit) .then(transaction.commit)
.catch(transaction.rollback); .catch(async (error) => {
context.logger.error(error);
return transaction.rollback();
});
if (options.refreshView) { if (options.refreshView) {
await context.knex.schema.refreshMaterializedView('actors_meta'); await context.knex.schema.refreshMaterializedView('actors_meta');
} }
} }
export const socials = {
urls: {
cashapp: 'https://cash.app/${handle}', // eslint-disable-line no-template-curly-in-string
fansly: 'https://fansly.com/{handle}',
instagram: 'https://www.instagram.com/{handle}',
linktree: 'https://linktr.ee/{handle}',
loyalfans: 'https://www.loyalfans.com/{handle}',
manyvids: 'https://{handle}.manyvids.com',
onlyfans: 'https://onlyfans.com/{handle}',
pornhub: 'https://www.pornhub.com/model/{handle}',
reddit: 'https://www.reddit.com/u/{handle}',
twitter: 'https://x.com/{handle}',
},
prefix: {
default: '@',
cashapp: '$',
reddit: 'u/',
},
};
export const platformsByHostname = {
...Object.fromEntries(Object.entries(socials.urls).map(([platform, url]) => {
const { hostname, pathname } = new URL(url);
return [hostname, {
platform,
pathname: decodeURIComponent(pathname),
url,
}];
})),
'twitter.com': {
platform: 'twitter',
pathname: '/{handle}',
url: 'https://twitter.com/{handle}',
},
};

4
package-lock.json generated
View File

@@ -1,12 +1,12 @@
{ {
"name": "traxxx-utils", "name": "traxxx-utils",
"version": "1.2.7", "version": "1.3.3",
"lockfileVersion": 2, "lockfileVersion": 2,
"requires": true, "requires": true,
"packages": { "packages": {
"": { "": {
"name": "traxxx-utils", "name": "traxxx-utils",
"version": "1.2.7", "version": "1.3.3",
"license": "ISC", "license": "ISC",
"devDependencies": { "devDependencies": {
"@babel/cli": "^7.25.7", "@babel/cli": "^7.25.7",

View File

@@ -1,6 +1,6 @@
{ {
"name": "traxxx-common", "name": "traxxx-common",
"version": "1.2.7", "version": "1.3.3",
"description": "Common utilities for traxxx core and web.", "description": "Common utilities for traxxx core and web.",
"main": "src/app.js", "main": "src/app.js",
"scripts": { "scripts": {