2024-02-29 05:00:12 +00:00
|
|
|
import { render } from 'vike/abort'; /* eslint-disable-line import/extensions */
|
|
|
|
|
2024-02-29 04:08:54 +00:00
|
|
|
import { fetchUser } from '#/src/users.js';
|
2024-08-26 04:15:22 +00:00
|
|
|
import { fetchUserStashes } from '#/src/stashes.js';
|
2024-05-19 03:07:35 +00:00
|
|
|
import { fetchAlerts } from '#/src/alerts.js';
|
2024-10-06 00:45:56 +00:00
|
|
|
import { fetchSceneRevisions } from '#/src/scenes.js';
|
2024-10-22 23:28:54 +00:00
|
|
|
import { fetchActorRevisions } from '#/src/actors.js';
|
|
|
|
|
|
|
|
async function fetchRevisions(pageContext) {
|
|
|
|
if (pageContext.routeParams.username !== pageContext.user?.username) {
|
|
|
|
return {};
|
|
|
|
}
|
|
|
|
|
|
|
|
if (pageContext.routeParams.section === 'revisions' && pageContext.routeParams.domain === 'scenes') {
|
|
|
|
return fetchSceneRevisions(null, {
|
|
|
|
userId: pageContext.user.id,
|
|
|
|
limit: 100,
|
|
|
|
}, pageContext.user);
|
|
|
|
}
|
|
|
|
|
|
|
|
if (pageContext.routeParams.section === 'revisions' && pageContext.routeParams.domain === 'actors') {
|
|
|
|
return fetchActorRevisions(null, {
|
|
|
|
userId: pageContext.user.id,
|
|
|
|
limit: 100,
|
|
|
|
}, pageContext.user);
|
|
|
|
}
|
|
|
|
|
|
|
|
return {};
|
|
|
|
}
|
2024-02-29 04:08:54 +00:00
|
|
|
|
|
|
|
export async function onBeforeRender(pageContext) {
|
2024-10-06 00:45:56 +00:00
|
|
|
const [profile, alerts, userRevisions] = await Promise.all([
|
2024-05-19 03:07:35 +00:00
|
|
|
fetchUser(pageContext.routeParams.username, {}, pageContext.user),
|
2024-10-22 23:28:54 +00:00
|
|
|
pageContext.routeParams.section === 'alerts' && pageContext.routeParams.username === pageContext.user?.username
|
2024-05-19 03:07:35 +00:00
|
|
|
? fetchAlerts(pageContext.user)
|
|
|
|
: [],
|
2024-10-22 23:28:54 +00:00
|
|
|
fetchRevisions(pageContext),
|
2024-05-19 03:07:35 +00:00
|
|
|
]);
|
2024-02-29 04:08:54 +00:00
|
|
|
|
2024-02-29 05:00:12 +00:00
|
|
|
if (!profile) {
|
|
|
|
throw render(404, `Cannot find user '${pageContext.routeParams.username}'.`);
|
|
|
|
}
|
|
|
|
|
2024-10-06 00:45:56 +00:00
|
|
|
const {
|
|
|
|
revisions,
|
|
|
|
actors,
|
|
|
|
tags,
|
|
|
|
movies,
|
2024-10-22 23:28:54 +00:00
|
|
|
avatars,
|
2024-10-06 00:45:56 +00:00
|
|
|
} = userRevisions;
|
|
|
|
|
2024-10-22 23:28:54 +00:00
|
|
|
console.log(userRevisions);
|
|
|
|
|
2024-08-26 04:15:22 +00:00
|
|
|
const stashes = await fetchUserStashes(profile.id, pageContext.user);
|
|
|
|
|
2024-02-29 04:08:54 +00:00
|
|
|
return {
|
|
|
|
pageContext: {
|
|
|
|
title: profile.username,
|
|
|
|
pageProps: {
|
|
|
|
profile, // differentiate from authed 'user'
|
2024-08-26 04:15:22 +00:00
|
|
|
stashes,
|
2024-05-19 03:07:35 +00:00
|
|
|
alerts,
|
2024-10-06 00:45:56 +00:00
|
|
|
revisions,
|
|
|
|
actors,
|
|
|
|
tags,
|
|
|
|
movies,
|
2024-10-22 23:28:54 +00:00
|
|
|
avatars,
|
2024-02-29 04:08:54 +00:00
|
|
|
},
|
|
|
|
},
|
|
|
|
};
|
|
|
|
}
|