Added elaborate template switching.

This commit is contained in:
2024-08-26 06:15:22 +02:00
parent fa991c0294
commit 80d8a8109a
29 changed files with 617 additions and 180 deletions

View File

@@ -24,7 +24,7 @@ export function curateStash(stash, assets = {}) {
name: stash.name,
slug: stash.slug,
isPrimary: stash.primary,
public: stash.public,
isPublic: stash.public,
createdAt: stash.created_at,
stashedScenes: stash.stashed_scenes ?? null,
stashedMovies: stash.stashed_movies ?? null,
@@ -45,7 +45,7 @@ function curateStashEntry(stash, user) {
user_id: user?.id || undefined,
name: stash.name || undefined,
slug: slugify(stash.name) || undefined,
public: stash.public ?? false,
public: stash.isPublic ?? false,
};
return curatedStashEntry;
@@ -86,7 +86,21 @@ export async function fetchStashByUsernameAndSlug(username, stashSlug, sessionUs
return curateStash(stash, { user });
}
export async function fetchStashes(domain, itemId, sessionUser) {
export async function fetchUserStashes(userId, reqUser) {
const stashes = await knex('stashes')
.select('stashes.*', 'stashes_meta.*')
.leftJoin('stashes_meta', 'stashes_meta.stash_id', 'stashes.id')
.where('user_id', userId)
.modify((builder) => {
if (userId !== reqUser?.id) {
builder.where('public', true);
}
});
return stashes.map((stash) => curateStash(stash, { user: reqUser }));
}
export async function fetchDomainStashes(domain, itemId, sessionUser) {
const stashes = await knex(`stashes_${domain}s`)
.select('stashes.*')
.leftJoin('stashes', 'stashes.id', `stashes_${domain}s.stash_id`)
@@ -233,7 +247,7 @@ export async function stashActor(actorId, stashId, sessionUser) {
refreshView('actors');
return fetchStashes('actor', actorId, sessionUser);
return fetchDomainStashes('actor', actorId, sessionUser);
}
export async function unstashActor(actorId, stashId, sessionUser) {
@@ -268,7 +282,7 @@ export async function unstashActor(actorId, stashId, sessionUser) {
refreshView('actors');
return fetchStashes('actor', actorId, sessionUser);
return fetchDomainStashes('actor', actorId, sessionUser);
}
export async function stashScene(sceneId, stashId, sessionUser) {
@@ -297,7 +311,7 @@ export async function stashScene(sceneId, stashId, sessionUser) {
refreshView('scenes');
return fetchStashes('scene', sceneId, sessionUser);
return fetchDomainStashes('scene', sceneId, sessionUser);
}
export async function unstashScene(sceneId, stashId, sessionUser) {
@@ -328,7 +342,7 @@ export async function unstashScene(sceneId, stashId, sessionUser) {
refreshView('scenes');
return fetchStashes('scene', sceneId, sessionUser);
return fetchDomainStashes('scene', sceneId, sessionUser);
}
export async function stashMovie(movieId, stashId, sessionUser) {
@@ -356,7 +370,7 @@ export async function stashMovie(movieId, stashId, sessionUser) {
refreshView('movies');
return fetchStashes('movie', movieId, sessionUser);
return fetchDomainStashes('movie', movieId, sessionUser);
}
export async function unstashMovie(movieId, stashId, sessionUser) {
@@ -387,7 +401,7 @@ export async function unstashMovie(movieId, stashId, sessionUser) {
refreshView('movies');
return fetchStashes('movie', movieId, sessionUser);
return fetchDomainStashes('movie', movieId, sessionUser);
}
CronJob.from({