Redirecting aliased actors and tags.

This commit is contained in:
2026-07-07 01:05:18 +02:00
parent a94c24581f
commit 1f5bbb6ce5
7 changed files with 21 additions and 7 deletions

View File

@@ -47,6 +47,10 @@ export async function onBeforeRender(pageContext) {
throw render(404, `Cannot find actor '${pageContext.routeParams.actorId}'.`);
}
if (actor.alias && !Object.hasOwn(pageContext.urlParsed.search, 'inspect')) {
throw redirect(`/actor/${actor.alias.id}/${actor.alias.slug}`);
}
const [actorReleases, campaigns, countries] = await Promise.all([
fetchReleases(pageContext),
getRandomCampaigns([

View File

@@ -60,7 +60,7 @@
>
<td class="actor-id ellipsis">
<a
:href="`/actor/${actor.id}/${actor.slug}`"
:href="`/actor/${actor.id}/${actor.slug}?inspect`"
target="_blank"
class="nolink"
>{{ actor.id }}</a>

View File

@@ -1,3 +1,4 @@
import { redirect } from 'vike/abort'; /* eslint-disable-line import/extensions */
import markdownIt from 'markdown-it';
import markdownItClass from '@toycode/markdown-it-class';
@@ -42,9 +43,13 @@ async function fetchReleases(pageContext) {
export async function onBeforeRender(pageContext) {
const tagSlug = pageContext.routeParams.tagSlug;
const [tag] = await fetchTagsById([tagSlug], {}, pageContext.user, { restriction: pageContext.restriction });
const [[tag], tagReleases, campaigns] = await Promise.all([
fetchTagsById([tagSlug], {}, pageContext.user, { restriction: pageContext.restriction }),
if (tag.aliasFor) {
throw redirect(`/tag/${tag.aliasFor}`);
}
const [tagReleases, campaigns] = await Promise.all([
fetchReleases(pageContext),
getRandomCampaigns([
{ tagSlugs: [tagSlug], minRatio: 0.75, maxRatio: 1.25 },

View File

@@ -254,10 +254,12 @@ export async function fetchActorsById(actorIds, options = {}, reqUser) {
knex.raw('row_to_json(sfw_media) as sfw_avatar'),
// knex.raw('json_agg(aliases) filter (where aliases.id is not null) as aliases'),
knex.raw('json_agg(row_to_json(aliases)::jsonb || jsonb_build_object(\'entity\', row_to_json(alias_entities))) filter (where aliases.id is not null) as aliases'),
knex.raw('row_to_json(aliased) as alias'),
knex.raw('row_to_json(media_biometrics) as biometrics'),
)
.leftJoin('actors_meta', 'actors_meta.actor_id', 'actors.id')
.leftJoin('actors as aliases', 'aliases.alias_for', 'actors.id')
.leftJoin('actors as aliased', 'aliased.id', 'actors.alias_for')
.leftJoin('entities as alias_entities', 'alias_entities.id', 'aliases.entity_id')
.leftJoin('countries as birth_countries', 'birth_countries.alpha2', 'actors.birth_country_alpha2')
.leftJoin('countries as residence_countries', 'residence_countries.alpha2', 'actors.residence_country_alpha2')
@@ -265,7 +267,7 @@ export async function fetchActorsById(actorIds, options = {}, reqUser) {
.leftJoin('media as sfw_media', 'sfw_media.id', 'avatars.sfw_media_id')
.leftJoin('media_biometrics', 'media_biometrics.media_id', 'actors.avatar_media_id')
.leftJoin('entities', 'entities.id', 'actors.entity_id')
.groupBy('actors.id', 'avatars.id', 'sfw_media.id', 'media_biometrics.id', 'entities.id', 'actors_meta.stashed', 'birth_countries.alpha2', 'residence_countries.alpha2');
.groupBy('actors.id', 'aliased.id', 'avatars.id', 'sfw_media.id', 'media_biometrics.id', 'entities.id', 'actors_meta.stashed', 'birth_countries.alpha2', 'residence_countries.alpha2');
}
}),
knex('actors_profiles')

View File

@@ -422,7 +422,7 @@ export async function fetchMovies(filters, rawOptions, reqUser, context) {
const [aggActors, aggTags, aggChannels] = await Promise.all([
options.aggregateActors ? fetchActorsById(result.aggregations.actorIds.map((bucket) => bucket.key), { shadllow: true, order: ['slug', 'asc'], append: actorCounts }, reqUser) : [],
options.aggregateTags ? fetchTagsById(result.aggregations.tagIds.map((bucket) => bucket.key), { order: [knex.raw('lower(name)'), 'asc'], append: tagCounts }, reqUser, context) : [],
options.aggregateTags ? fetchTagsById(result.aggregations.tagIds.map((bucket) => bucket.key), { order: [knex.raw('lower(tags.name)'), 'asc'], append: tagCounts }, reqUser, context) : [],
options.aggregateChannels ? fetchEntitiesById(result.aggregations.channelIds.map((bucket) => bucket.key), { order: ['slug', 'asc'], append: channelCounts }, reqUser, context) : [],
]);

View File

@@ -689,8 +689,8 @@ export async function fetchScenes(filters, rawOptions, reqUser, context) {
const [aggActors, aggTags, aggActorTags, aggChannels] = await Promise.all([
options.aggregateActors ? fetchActorsById(result.aggregations.actorIds.map((bucket) => bucket.key), { shallow: true, order: ['slug', 'asc'], append: actorCounts }, reqUser) : [],
options.aggregateTags ? fetchTagsById(result.aggregations.tagIds.map((bucket) => bucket.key), { order: [knex.raw('lower(name)'), 'asc'], append: tagCounts }, reqUser, context) : [],
options.aggregateTags ? fetchTagsById(result.aggregations.actorTagIds.map((bucket) => bucket.key), { order: [knex.raw('lower(name)'), 'asc'], append: tagCounts }, reqUser, context) : [],
options.aggregateTags ? fetchTagsById(result.aggregations.tagIds.map((bucket) => bucket.key), { order: [knex.raw('lower(tags.name)'), 'asc'], append: tagCounts }, reqUser, context) : [],
options.aggregateTags ? fetchTagsById(result.aggregations.actorTagIds.map((bucket) => bucket.key), { order: [knex.raw('lower(tags.name)'), 'asc'], append: tagCounts }, reqUser, context) : [],
options.aggregateChannels ? fetchEntitiesById(entityIds.map((bucket) => bucket.key), { order: ['slug', 'asc'], append: channelCounts }, reqUser, context) : [],
]);

View File

@@ -16,6 +16,7 @@ function curateTag(tag, context = {}) {
priority: tag.priority,
poster: tag.poster && curateMedia(tag.poster),
photos: tag.photos?.map((photo) => curateMedia(photo)) || [],
aliasFor: tag.alias_slug,
alerts: {
only: context?.alerts?.filter((alert) => alert.is_only).flatMap((alert) => alert.alert_ids) || [],
multi: context?.alerts?.filter((alert) => !alert.is_only).flatMap((alert) => alert.alert_ids) || [],
@@ -76,6 +77,8 @@ export async function fetchTags(options = {}, context = {}) {
export async function fetchTagsById(tagIds, options = {}, reqUser, context = {}) {
const [tags, posters, photos, alerts] = await Promise.all([
knex('tags')
.select('tags.*', 'aliases.slug as alias_slug')
.leftJoin('tags as aliases', 'aliases.id', 'tags.alias_for')
.whereIn('tags.id', tagIds.filter((tagId) => typeof tagId === 'number'))
.orWhereIn('tags.slug', tagIds.filter((tagId) => typeof tagId === 'string'))
.modify((builder) => {