Added rudimentary tags page. Improved social match behavior.

This commit is contained in:
2019-12-01 05:32:47 +01:00
parent bead69de49
commit cf81aa99e0
41 changed files with 495 additions and 104 deletions

View File

@@ -17,7 +17,8 @@ async function curateActor(actor) {
.where({ domain: 'actors', target_id: actor.id })
.orderBy('index'),
knex('social')
.where({ domain: 'actors', target_id: actor.id }),
.where({ domain: 'actors', target_id: actor.id })
.orderBy('platform', 'desc'),
]);
const curatedActor = {
@@ -128,11 +129,17 @@ function curateActorEntry(actor, scraped, scrapeSuccess) {
function curateSocialEntry(url, actorId) {
const platforms = [
// links supplied by PH often look like domain.com/domain.com/username
{
label: 'twitter',
pattern: 'http(s)\\://(*)twitter.com/:username(/)(?*)',
format: username => `https://www.twitter.com/${username}`,
},
{
label: 'youtube',
pattern: 'http(s)\\://(*)youtube.com/channel/:username(?*)',
format: username => `https://www.youtube.com/channel/${username}`,
},
{
label: 'instagram',
pattern: 'http(s)\\://(*)instagram.com/:username(/)(?*)',
@@ -148,11 +155,21 @@ function curateSocialEntry(url, actorId) {
pattern: 'http(s)\\://:username.tumblr.com(*)',
format: username => `https://${username}.tumblr.com`,
},
{
label: 'onlyfans',
pattern: 'http(s)\\://(*)onlyfans.com/:username(/)(?*)',
format: username => `https://www.onlyfans.com/${username}`,
},
{
label: 'fancentro',
pattern: 'http(s)\\://(www.)fancentro.com/:username(/)(?*)',
pattern: 'http(s)\\://(*)fancentro.com/:username(/)(?*)',
format: username => `https://www.fancentro.com/${username}`,
},
{
label: 'modelhub',
pattern: 'http(s)\\://(*)modelhub.com/:username(/)(?*)',
format: username => `https://www.modelhub.com/${username}`,
},
];
const match = platforms.reduce((acc, platform) => {
@@ -202,7 +219,7 @@ async function curateSocialEntries(urls, actorId) {
}, []);
}
async function fetchActors(queryObject) {
async function fetchActors(queryObject, limit = 100) {
const releases = await knex('actors')
.select(
'actors.*',
@@ -213,7 +230,7 @@ async function fetchActors(queryObject) {
.leftJoin('countries as residence_countries', 'actors.residence_country_alpha2', 'residence_countries.alpha2')
.orderBy(['actors.name', 'actors.gender'])
.where(builder => whereOr(queryObject, 'actors', builder))
.limit(100);
.limit(limit);
return curateActors(releases);
}

View File

@@ -9,6 +9,7 @@ async function curateTag(tag) {
return {
id: tag.id,
name: tag.name,
slug: tag.slug,
description: tag.description,
group: {
id: tag.group_id,
@@ -36,7 +37,7 @@ async function associateTags(release, releaseId) {
})));
}
async function fetchTags(queryObject) {
async function fetchTags(queryObject, limit = 100) {
const tags = await knex('tags')
.where(builder => whereOr(queryObject, 'tags', builder))
.andWhere({ 'tags.alias_for': null })
@@ -45,7 +46,8 @@ async function fetchTags(queryObject) {
'tags_groups.id as group_id', 'tags_groups.name as group_name', 'tags_groups.slug as group_slug', 'tags_groups.description as groups_description',
)
.leftJoin('tags_groups', 'tags.group_id', 'tags_groups.id')
.limit(100);
.orderBy('name')
.limit(limit);
return curateTags(tags);
}

View File

@@ -6,9 +6,17 @@ function whereOr(query, table, builder) {
}
Object.entries(query).forEach(([key, value]) => {
if (value !== undefined) {
builder.orWhere(`${table}.${key}`, value);
if (value === undefined) {
return builder;
}
if (Array.isArray(value)) {
builder.orWhereIn(`${table}.${key}`, value);
return builder;
}
builder.orWhere(`${table}.${key}`, value);
return builder;
});
return builder;

View File

@@ -21,7 +21,7 @@ async function fetchActorsApi(req, res) {
return;
}
const actors = await fetchActors();
const actors = await fetchActors(null, req.query.limit);
res.send(actors);
}

View File

@@ -6,10 +6,24 @@ async function fetchTagsApi(req, res) {
const tagId = typeof req.params.tagId === 'number' ? req.params.tagId : undefined; // null will literally include NULL results
const tagSlug = typeof req.params.tagId === 'string' ? req.params.tagId : undefined;
if (tagId || tagSlug) {
const tags = await fetchTags({
id: tagId,
slug: tagSlug,
}, req.query.limit);
if (tags.length > 0) {
res.send(tags[0]);
return;
}
res.status(404).send();
return;
}
const tags = await fetchTags({
id: tagId,
slug: tagSlug,
});
priority: req.query.priority.split(','),
}, req.query.limit);
res.send(tags);
}