Added basic release and actor API.

This commit is contained in:
2020-05-20 01:11:32 +02:00
parent 6973d39cbd
commit 057362d011
18 changed files with 347 additions and 39 deletions

View File

@@ -130,6 +130,73 @@ function toBaseActors(actorsOrNames, release) {
});
}
function curateActor(actor) {
if (!actor) {
return null;
}
const curatedActor = {
id: actor.id,
name: actor.name,
slug: actor.slug,
gender: actor.gender,
alias: actor.alias && {
id: actor.alias.id,
name: actor.alias.name,
gender: actor.alias.gender,
},
network: actor.network && {
id: actor.network.id,
name: actor.network.name,
slug: actor.network.slug,
},
dateOfBirth: actor.date_of_birth,
dateOfDeath: actor.date_of_death,
cup: actor.cup,
bust: actor.bust,
waist: actor.waist,
hip: actor.hip,
naturalBoobs: actor.natural_boobs,
height: actor.height,
weight: actor.weight,
eyes: actor.eyes,
hair: actor.hair,
hasTattoos: actor.has_tattoos,
hasPiercings: actor.has_piercings,
tattoos: actor.tattoos,
piercings: actor.piercings,
description: actor.description,
origin: actor.birth_country && {
country: {
alpha2: actor.birth_country.alpha2,
name: actor.birth_country.name,
alias: actor.birth_country.alias,
},
state: actor.birth_state,
city: actor.birth_city,
},
residence: actor.residence_country && {
country: {
alpha2: actor.residence_country.alpha2,
name: actor.residence_country.name,
alias: actor.residence_country.alias,
},
state: actor.residence_state,
city: actor.residence_city,
},
avatar: actor.avatar && {
id: actor.avatar.id,
path: actor.avatar.path,
width: actor.avatar.width,
height: actor.avatar.height,
size: actor.avatar.size,
source: actor.avatar.source,
},
};
return curatedActor;
}
function curateActorEntry(baseActor, batchId) {
return {
name: baseActor.name,
@@ -196,7 +263,7 @@ async function curateProfile(profile) {
update: profile.update,
};
curatedProfile.description = domPurify.sanitize(profile.description.replace(/\s+/g, ' '), { ALLOWED_TAGS: [] }).trim() || null;
curatedProfile.description = domPurify.sanitize(profile.description?.replace(/\s+/g, ' '), { ALLOWED_TAGS: [] }).trim() || null;
const hasher = curatedProfile.description && blake2
.createHash('blake2b')
@@ -632,7 +699,36 @@ async function associateActors(releases, batchId) {
return actors;
}
async function fetchActor(actorId) {
const actor = await knex('actors')
.select(knex.raw(`
actors.*,
row_to_json(networks) as network,
row_to_json(actor_alias) as alias,
row_to_json(birth_country) as birth_country,
row_to_json(residence_country) as residence_country,
row_to_json(media) as avatar
`))
.modify((queryBuilder) => {
if (Number.isNaN(Number(actorId))) {
queryBuilder.where('actors.slug', actorId);
return;
}
queryBuilder.where('actors.id', actorId);
})
.leftJoin('actors as actor_alias', 'actor_alias.id', 'actors.alias_for')
.leftJoin('networks', 'networks.id', 'actors.network_id')
.leftJoin('countries as birth_country', 'birth_country.alpha2', 'actors.birth_country_alpha2')
.leftJoin('countries as residence_country', 'residence_country.alpha2', 'actors.residence_country_alpha2')
.leftJoin('media', 'media.id', 'actors.avatar_media_id')
.first();
return curateActor(actor);
}
module.exports = {
associateActors,
fetchActor,
scrapeActors,
};