Compare commits
25 Commits
f69e343d89
...
main
| Author | SHA1 | Date | |
|---|---|---|---|
| 1374f90397 | |||
| 33733720c5 | |||
| ec4b15ce33 | |||
| 3f6f3ed038 | |||
| ee23dc0358 | |||
| b2305966ed | |||
| 0c9917fc27 | |||
| fda6f5cb93 | |||
| c45852d693 | |||
| 4b90a5feec | |||
| b9ee4e1c90 | |||
| dc00c3d58a | |||
| 721f5b91d8 | |||
| 97d7e9cfd0 | |||
| c69e876aa2 | |||
| 1122b4198f | |||
| 7a39529e2c | |||
| 83294ec6f4 | |||
| 4316b69a43 | |||
| b2d040dc3c | |||
| 3bf8ce6e23 | |||
| c63e495516 | |||
| c068c759b2 | |||
| f4732e81be | |||
| fc02d5c41b |
174
actors.mjs
174
actors.mjs
@@ -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
72
geo.mjs
Normal 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
4
package-lock.json
generated
@@ -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",
|
||||
|
||||
@@ -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": {
|
||||
|
||||
Reference in New Issue
Block a user