Added stash creation. Added dialog framework.

This commit is contained in:
2024-03-26 04:14:42 +01:00
parent 9de289a0fb
commit 68b9658ba6
9 changed files with 377 additions and 82 deletions

View File

@@ -47,6 +47,7 @@ export async function login(credentials, userIp) {
const { user, stashes } = await fetchUser(credentials.username.trim(), {
email: true,
raw: true,
includeStashes: true,
}).catch(() => {
throw new HttpError('Username or password incorrect', 401);
});

View File

@@ -22,9 +22,9 @@ export function curateStash(stash, assets = {}) {
primary: stash.primary,
public: stash.public,
createdAt: stash.created_at,
stashedScenes: stash.stashed_scenes || null,
stashedMovies: stash.stashed_movies || null,
stashedActors: stash.stashed_actors || null,
stashedScenes: stash.stashed_scenes ?? null,
stashedMovies: stash.stashed_movies ?? null,
stashedActors: stash.stashed_actors ?? null,
user: assets.user ? {
id: assets.user.id,
username: assets.user.username,
@@ -99,6 +99,22 @@ export async function createStash(newStash, sessionUser) {
throw new HttpError('You are not authenthicated', 401);
}
if (!newStash.name) {
throw new HttpError('Stash name required', 400);
}
if (newStash.name.length < config.stashes.nameLength[0]) {
throw new HttpError('Stash name is too short', 400);
}
if (newStash.name.length > config.stashes.nameLength[1]) {
throw new HttpError('Stash name is too long', 400);
}
if (!config.stashes.namePattern.test(newStash.name)) {
throw new HttpError('Stash name contains invalid characters', 400);
}
try {
const stash = await knex('stashes')
.insert(curateStashEntry(newStash, sessionUser))

View File

@@ -53,7 +53,7 @@ export async function fetchUser(userId, options = {}, reqUser) {
const stashes = await knex('stashes')
.where('user_id', user.id)
.modify((builder) => {
if (reqUser?.id !== user.id) {
if (reqUser?.id !== user.id && !options.includeStashes) {
builder.where('public', true);
}
})

View File

@@ -25,7 +25,7 @@ import {
} from './auth.js';
import {
fetchUserApi
fetchUserApi,
} from './users.js';
import {