Added descriptions to actor profile page, using profiles for secondary photos.

This commit is contained in:
DebaucheryLibrarian 2024-06-07 05:20:13 +02:00
parent e691aedc73
commit c33ea6064e
5 changed files with 35 additions and 55 deletions

View File

@ -244,25 +244,25 @@
<div class="descriptions-container">
<div
v-if="actor.descriptions && actor.descriptions.length > 0"
v-if="descriptions.length > 0"
class="descriptions"
>
<p
v-for="description in actor.descriptions"
v-for="description in descriptions"
:key="`description-${description.entity.id}`"
class="description"
>
{{ description.text }}
<a :href="`/${description.entity.type}/${description.entity.slug}`">
<img
v-if="description.entity.type === 'network' || !description.entity.parent || description.entity.independent"
:src="`/img/logos/${description.entity.slug}/thumbs/network.png`"
v-if="description.entity.type === 'network' || !description.entity.parent || description.entity.isIndependent"
:src="`/logos/${description.entity.slug}/thumbs/network.png`"
class="description-logo"
>
<img
v-else
:src="`/img/logos/${description.entity.parent.slug}/thumbs/${description.entity.slug}.png`"
:src="`/logos/${description.entity.parent.slug}/thumbs/${description.entity.slug}.png`"
class="description-logo"
>
</a>
@ -325,6 +325,13 @@ const showExpand = [
'waist',
'weight',
].some((attribute) => !!props.actor[attribute]);
const descriptions = Object.values(Object.fromEntries(props.actor.profiles
.filter((profile) => !!profile.description)
.map((profile) => [profile.descriptionHash, {
text: profile.description,
entity: profile.entity,
}])));
</script>
<style>

View File

@ -72,13 +72,12 @@ const pageContext = inject('pageContext');
const { pageProps } = pageContext;
const { actor } = pageProps;
const photos = [
actor.avatar && {
...actor.avatar,
isAvatar: true,
},
...actor.photos,
].filter(Boolean);
const photos = actor.profiles
.filter((profile) => !!profile.avatar)
.map((profile) => ({
...profile.avatar,
isAvatar: profile.avatar.id === actor.avatar.id,
}));
</script>
<style scoped>

View File

@ -6,6 +6,8 @@ import { knexOwner as knex, knexManticore } from './knex.js';
import { utilsApi } from './manticore.js';
import { HttpError } from './errors.js';
import { fetchCountriesByAlpha2 } from './countries.js';
import { curateEntity } from './entities.js';
import { curateMedia } from './media.js';
import { curateStash } from './stashes.js';
import escape from '../utils/escape-manticore.js';
import slugify from '../utils/slugify.js';
@ -53,25 +55,13 @@ export function curateActor(actor, context = {}) {
alias: actor.residence_country_alias,
},
},
avatar: actor.avatar && {
id: actor.avatar.id,
path: actor.avatar.path,
thumbnail: actor.avatar.thumbnail,
lazy: actor.avatar.lazy,
width: actor.avatar.width,
height: actor.avatar.height,
isS3: actor.avatar.is_s3,
credit: actor.avatar.credit,
},
photos: context.photos?.map((photo) => ({
id: photo.id,
path: photo.path,
thumbnail: photo.thumbnail,
lazy: photo.lazy,
width: photo.width,
height: photo.height,
isS3: photo.is_s3,
credit: photo.credit,
avatar: curateMedia(actor.avatar),
profiles: context.profiles?.map((profile) => ({
id: profile.id,
description: profile.description,
descriptionHash: profile.description_hash,
entity: curateEntity({ ...profile.entity, parent: profile.parent_entity }),
avatar: curateMedia(profile.avatar),
})),
createdAt: actor.created_at,
updatedAt: actor.updated_at,
@ -109,7 +99,7 @@ export function sortActorsByGender(actors, context = {}) {
}
export async function fetchActorsById(actorIds, options = {}, reqUser) {
const [actors, photos, stashes] = await Promise.all([
const [actors, profiles, stashes] = await Promise.all([
knex('actors')
.select(
'actors.*',
@ -129,13 +119,13 @@ export async function fetchActorsById(actorIds, options = {}, reqUser) {
}
}),
knex('actors_profiles')
.select('actors_profiles.actor_id', 'media.*')
.select('actors_profiles.*', knex.raw('row_to_json(entities) as entity'), knex.raw('row_to_json(parents) as parent_entity'), knex.raw('row_to_json(media) as avatar'))
.leftJoin('actors', 'actors.id', 'actors_profiles.actor_id')
.leftJoin('entities', 'entities.id', 'actors_profiles.entity_id')
.leftJoin('entities as parents', 'parents.id', 'entities.parent_id')
.leftJoin('media', 'media.id', 'actors_profiles.avatar_media_id')
.whereIn('actor_id', actorIds)
.whereNotNull('actors_profiles.avatar_media_id')
.whereNot('actors_profiles.avatar_media_id', knex.raw('actors.avatar_media_id')) // don't include main avatar as photo
.groupBy('actors_profiles.actor_id', 'media.id', 'media.hash'),
.groupBy('actors_profiles.id', 'entities.id', 'parents.id', 'media.id'),
reqUser
? knex('stashes_actors')
.leftJoin('stashes', 'stashes.id', 'stashes_actors.stash_id')
@ -161,7 +151,7 @@ export async function fetchActorsById(actorIds, options = {}, reqUser) {
return curateActor(actor, {
stashes: stashes.filter((stash) => stash.actor_id === actor.id),
photos: photos.filter((photo) => photo.actor_id === actor.id),
profiles: profiles.filter((profile) => profile.actor_id === actor.id),
append: options.append,
});
}).filter(Boolean);

View File

@ -11,5 +11,6 @@ export function curateMedia(media) {
isS3: media.is_s3,
width: media.width,
height: media.height,
index: media.index,
};
}

View File

@ -8,27 +8,10 @@ import { fetchActorsById, curateActor, sortActorsByGender } from './actors.js';
import { fetchTagsById } from './tags.js';
import { fetchEntitiesById } from './entities.js';
import { curateStash } from './stashes.js';
import { curateMedia } from './media.js';
import escape from '../utils/escape-manticore.js';
import promiseProps from '../utils/promise-props.js';
function curateMedia(media) {
if (!media) {
return null;
}
return {
id: media.id,
path: media.path,
thumbnail: media.thumbnail,
lazy: media.lazy,
hash: media.hash,
isS3: media.is_s3,
width: media.width,
height: media.height,
index: media.index,
};
}
function curateScene(rawScene, assets) {
if (!rawScene) {
return null;