Compare commits

...

25 Commits

Author SHA1 Message Date
1374f90397 1.3.3 2026-02-07 17:19:22 +01:00
33733720c5 Added avatar credit exclusion to profile interpolation. 2026-02-07 17:19:20 +01:00
ec4b15ce33 1.3.2 2026-01-09 02:09:21 +01:00
3f6f3ed038 Removed slugify. 2026-01-09 02:09:19 +01:00
ee23dc0358 1.3.1 2026-01-09 01:51:47 +01:00
b2305966ed Using CommonJS for slugify. 2026-01-09 01:51:45 +01:00
0c9917fc27 1.3.0 2026-01-09 01:49:37 +01:00
fda6f5cb93 Added slugify. 2026-01-09 01:49:28 +01:00
c45852d693 Added twitter.com to socials hostname index. 2025-12-28 05:59:14 +01:00
4b90a5feec 1.2.10 2025-12-28 05:37:27 +01:00
b9ee4e1c90 Added socials config. 2025-12-28 05:37:21 +01:00
dc00c3d58a 1.2.9 2024-11-03 03:28:10 +01:00
721f5b91d8 Fixed entity ID inherited from profile. 2024-11-03 03:28:08 +01:00
97d7e9cfd0 1.2.8 2024-11-03 00:21:24 +01:00
c69e876aa2 Fixed actor key determination. 2024-11-03 00:21:22 +01:00
1122b4198f Fixed unprint response property. 2024-10-31 03:24:30 +01:00
7a39529e2c Replaced config dependency with options argument. 2024-10-31 03:18:27 +01:00
83294ec6f4 Replaced argv dependency with options argument. 2024-10-31 03:12:10 +01:00
4316b69a43 1.2.7 2024-10-31 02:50:20 +01:00
b2d040dc3c Added location resolver. 2024-10-31 02:50:13 +01:00
3bf8ce6e23 1.2.6 2024-10-24 22:08:29 +02:00
c63e495516 Not refreshing actors meta view by default. 2024-10-24 22:08:25 +02:00
c068c759b2 Added incision and labia to most frequent interpolation list. 2024-10-24 21:21:43 +02:00
f4732e81be 1.2.5 2024-10-24 21:01:59 +02:00
fc02d5c41b Added boobs incision and labia fields. 2024-10-24 21:01:57 +02:00
4 changed files with 141 additions and 111 deletions

View File

@@ -45,68 +45,6 @@ function getAverage(items) {
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_surgeon: profile.boobsSurgeon,
natural_butt: profile.naturalButt,
butt_volume: profile.buttVolume,
butt_implant: profile.buttImplant,
natural_lips: profile.naturalLips,
lips_volume: profile.lipsVolume,
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 }) {
return knex('actors_profiles')
.select(knex.raw('actors_profiles.*, actors.name, row_to_json(media) as avatar'))
@@ -139,8 +77,10 @@ function mergeMainProfile(profile, mainProfile) {
return mergedProfile;
}
export async function interpolateProfiles(actorIdsOrNames, context) {
export async function interpolateProfiles(actorIdsOrNames, context, options = {}) {
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) => ({
...acc,
@@ -153,6 +93,16 @@ export async function interpolateProfiles(actorIdsOrNames, context) {
context.logger.info(`Interpolating ${profiles.length} profiles from ${Object.keys(profilesByActorId).length} actors`);
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
const valuesByProperty = actorProfiles
.filter((profile) => profile.entity_id !== null) // main profile is interpolated separately at the end
@@ -178,45 +128,8 @@ export async function interpolateProfiles(actorIdsOrNames, context) {
}].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_placement',
'boobs_surgeon',
'natural_butt',
'butt_volume',
'butt_implant',
'natural_lips',
'lips_volume',
'hair_color',
'eyes',
'has_tattoos',
'has_piercings',
'agency',
'blood_type',
].reduce((acc, property) => ({
...acc,
[property]: getMostFrequent(valuesByProperty[property], context),
}), {});
const profile = {
id: actorId,
...mostFrequentValues,
};
profile.height = getMostFrequent(valuesByProperty.height.filter((height) => height > 50 && height < 300), context); // remove unlikely values
@@ -251,18 +164,23 @@ export async function interpolateProfiles(actorIdsOrNames, context) {
profile.avatar_media_id = actorProfiles
.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;
if (!profile.avatar_media_id) {
// try to settle for low quality avatar
profile.avatar_media_id = actorProfiles
.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;
}
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);
});
@@ -270,9 +188,7 @@ export async function interpolateProfiles(actorIdsOrNames, context) {
const transaction = await context.knex.transaction();
// clear existing interpolated data
const emptyProfile = Object
.keys(context.omit(curateProfileEntry({ id: 1 }), ['id', 'actor_id', 'entity_id', 'url', 'description_hash']))
.reduce((acc, key) => ({ ...acc, [key]: null }), {});
const emptyProfile = Object.fromEntries(columns.filter((key) => !preservedKeys.includes(key)).map((key) => [key, null]));
await context.knex('actors')
.modify((modifyBuilder) => {
@@ -297,7 +213,49 @@ export async function interpolateProfiles(actorIdsOrNames, context) {
await Promise.all(queries)
.then(transaction.commit)
.catch(transaction.rollback);
.catch(async (error) => {
context.logger.error(error);
return transaction.rollback();
});
await context.knex.schema.refreshMaterializedView('actors_meta');
if (options.refreshView) {
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}',
},
};

72
geo.mjs Normal file
View File

@@ -0,0 +1,72 @@
export async function resolvePlace(query, context, options = {}) {
if (!query) {
return null;
}
const cacheKey = `place-${context.slugify(query)}`;
const cachedPlace = await context.redis.hGetAll(cacheKey);
if (options.useCache !== false && await context.redis.exists(cacheKey)) {
await context.redis.expire(cacheKey, 3600 * 24 * 30);
context.logger.debug(`Using cached place '${cacheKey}' for query '${query}': ${JSON.stringify(cachedPlace)}`);
return cachedPlace;
}
// query is a nationality, lookup would get weird results (British resolves to British, Northern Ireland)
const country = await context.knex('countries')
.where('nationality', 'ilike', `%${query}%`)
.orWhere('alpha3', 'ilike', `%${query}%`)
.orWhere('alpha2', 'ilike', `%${query}%`)
.orderBy('priority', 'desc')
.first();
if (country) {
return {
country: country.alpha2,
};
}
try {
// https://operations.osmfoundation.org/policies/nominatim/
const res = await context.unprint.get(`https://nominatim.openstreetmap.org/search?q=${encodeURI(query)}&format=json&accept-language=en&addressdetails=1`, {
headers: {
'User-Agent': options.userAgent,
},
interval: 1000,
concurrency: 1,
});
const [item] = res.data;
if (item && item.address) {
const rawPlace = item.address;
const place = {};
if (item.class === 'place' || item.class === 'boundary') {
const location = rawPlace[item.type] || rawPlace.city || rawPlace.place || rawPlace.town;
if (location) {
place.place = location;
place.city = rawPlace.city || location;
}
}
if (rawPlace.state) place.state = rawPlace.state;
if (rawPlace.country_code) place.country = rawPlace.country_code.toUpperCase();
if (rawPlace.continent) place.continent = rawPlace.continent;
context.logger.debug(`Resolved place '${query}' to ${JSON.stringify(place)}`);
await context.redis.hSet(cacheKey, place);
await context.redis.expire(cacheKey, 3600 * 24 * 30);
return place;
}
} catch (error) {
context.logger.error(`Failed to resolve place '${query}': ${error.message}`);
}
return null;
}

4
package-lock.json generated
View File

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

View File

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