Added various tag photos and descriptions.
This commit is contained in:
@@ -67,7 +67,7 @@ async function signup(credentials) {
|
||||
const hashedPassword = (await scrypt(credentials.password, salt, 64)).toString('hex');
|
||||
const storedPassword = `${salt}/${hashedPassword}`;
|
||||
|
||||
const [user] = await knex('users')
|
||||
const [userId] = await knex('users')
|
||||
.insert({
|
||||
username: credentials.username,
|
||||
email: credentials.email,
|
||||
@@ -76,13 +76,13 @@ async function signup(credentials) {
|
||||
.returning('id');
|
||||
|
||||
await knex('stashes').insert({
|
||||
user_id: user.id,
|
||||
user_id: userId,
|
||||
name: 'Favorites',
|
||||
slug: 'favorites',
|
||||
public: false,
|
||||
});
|
||||
|
||||
return fetchUser(user.id);
|
||||
return fetchUser(userId);
|
||||
}
|
||||
|
||||
module.exports = {
|
||||
|
||||
@@ -4,6 +4,10 @@ const knex = require('./knex');
|
||||
const { HttpError } = require('./errors');
|
||||
|
||||
function curateStash(stash) {
|
||||
if (!stash) {
|
||||
return null;
|
||||
}
|
||||
|
||||
const curatedStash = {
|
||||
id: stash.id,
|
||||
name: stash.name,
|
||||
@@ -52,12 +56,22 @@ async function stashScene(sceneId, stashId, sessionUser) {
|
||||
});
|
||||
}
|
||||
|
||||
async function stashMovie(movieId, stashId, sessionUser) {
|
||||
const stash = await fetchStash(stashId, sessionUser);
|
||||
|
||||
await knex('stashes_movies')
|
||||
.insert({
|
||||
stash_id: stash.id,
|
||||
movie_id: movieId,
|
||||
});
|
||||
}
|
||||
|
||||
async function unstashActor(actorId, stashId, sessionUser) {
|
||||
await knex
|
||||
.from('stashes_actors AS deletable')
|
||||
.where('deletable.actor_id', actorId)
|
||||
.where('deletable.stash_id', stashId)
|
||||
.whereExists(knex('stashes_actors') // verify user owns this stash
|
||||
.whereExists(knex('stashes_actors') // verify user owns this stash, complimentary to row-level security
|
||||
.leftJoin('stashes', 'stashes.id', 'stashes_actors.stash_id')
|
||||
.where('stashes_actors.stash_id', knex.raw('deletable.stash_id'))
|
||||
.where('stashes.user_id', sessionUser.id))
|
||||
@@ -69,17 +83,31 @@ async function unstashScene(sceneId, stashId, sessionUser) {
|
||||
.from('stashes_scenes AS deletable')
|
||||
.where('deletable.scene_id', sceneId)
|
||||
.where('deletable.stash_id', stashId)
|
||||
.whereExists(knex('stashes_scenes') // verify user owns this stash
|
||||
.whereExists(knex('stashes_scenes') // verify user owns this stash, complimentary to row-level security
|
||||
.leftJoin('stashes', 'stashes.id', 'stashes_scenes.stash_id')
|
||||
.where('stashes_scenes.stash_id', knex.raw('deletable.stash_id'))
|
||||
.where('stashes.user_id', sessionUser.id))
|
||||
.delete();
|
||||
}
|
||||
|
||||
async function unstashMovie(movieId, stashId, sessionUser) {
|
||||
await knex
|
||||
.from('stashes_movies AS deletable')
|
||||
.where('deletable.movie_id', movieId)
|
||||
.where('deletable.stash_id', stashId)
|
||||
.whereExists(knex('stashes_movies') // verify user owns this stash, complimentary to row-level security
|
||||
.leftJoin('stashes', 'stashes.id', 'stashes_movies.stash_id')
|
||||
.where('stashes_movies.stash_id', knex.raw('deletable.stash_id'))
|
||||
.where('stashes.user_id', sessionUser.id))
|
||||
.delete();
|
||||
}
|
||||
|
||||
module.exports = {
|
||||
curateStash,
|
||||
stashActor,
|
||||
stashScene,
|
||||
stashMovie,
|
||||
unstashScene,
|
||||
unstashActor,
|
||||
unstashMovie,
|
||||
};
|
||||
|
||||
@@ -18,7 +18,7 @@ function curateUser(user) {
|
||||
identityVerified: user.identity_verified,
|
||||
ability,
|
||||
createdAt: user.created_at,
|
||||
stashes: user.stashes?.map(stash => curateStash(stash)) || [],
|
||||
stashes: user.stashes?.filter(Boolean).map(stash => curateStash(stash)) || [],
|
||||
};
|
||||
|
||||
return curatedUser;
|
||||
@@ -26,7 +26,7 @@ function curateUser(user) {
|
||||
|
||||
async function fetchUser(userId, raw) {
|
||||
const user = await knex('users')
|
||||
.select(knex.raw('users.*, users_roles.abilities as role_abilities, json_agg(stashes) as stashes'))
|
||||
.select(knex.raw('users.*, users_roles.abilities as role_abilities, COALESCE(json_agg(stashes) FILTER (WHERE stashes.id IS NOT NULL), \'[]\') as stashes'))
|
||||
.modify((builder) => {
|
||||
if (typeof userId === 'number') {
|
||||
builder.where('users.id', userId);
|
||||
|
||||
@@ -1,10 +1,15 @@
|
||||
'use strict';
|
||||
|
||||
const argv = require('../argv');
|
||||
const logger = require('../logger')(__filename);
|
||||
|
||||
function errorHandler(error, req, res, _next) {
|
||||
logger.warn(`Failed to fulfill request to ${req.path}: ${error.message}`);
|
||||
|
||||
if (argv.debug) {
|
||||
logger.error(error);
|
||||
}
|
||||
|
||||
if (error.httpCode) {
|
||||
res.status(error.httpCode).send(error.message);
|
||||
|
||||
|
||||
@@ -46,8 +46,10 @@ const {
|
||||
const {
|
||||
stashActor,
|
||||
stashScene,
|
||||
stashMovie,
|
||||
unstashActor,
|
||||
unstashScene,
|
||||
unstashMovie,
|
||||
} = require('./stashes');
|
||||
|
||||
async function initServer() {
|
||||
@@ -83,9 +85,11 @@ async function initServer() {
|
||||
|
||||
router.post('/api/stashes/:stashId/actors', stashActor);
|
||||
router.post('/api/stashes/:stashId/scenes', stashScene);
|
||||
router.post('/api/stashes/:stashId/movies', stashMovie);
|
||||
|
||||
router.delete('/api/stashes/:stashId/actors/:actorId', unstashActor);
|
||||
router.delete('/api/stashes/:stashId/scenes/:sceneId', unstashScene);
|
||||
router.delete('/api/stashes/:stashId/movies/:movieId', unstashMovie);
|
||||
|
||||
router.get('/api/scenes', fetchScenes);
|
||||
router.get('/api/scenes/:releaseId', fetchScene);
|
||||
|
||||
@@ -1,6 +1,13 @@
|
||||
'use strict';
|
||||
|
||||
const { stashActor, stashScene, unstashActor, unstashScene } = require('../stashes');
|
||||
const {
|
||||
stashActor,
|
||||
stashScene,
|
||||
stashMovie,
|
||||
unstashActor,
|
||||
unstashScene,
|
||||
unstashMovie,
|
||||
} = require('../stashes');
|
||||
|
||||
async function stashActorApi(req, res) {
|
||||
await stashActor(req.body.actorId, req.params.stashId, req.session.user);
|
||||
@@ -14,6 +21,12 @@ async function stashSceneApi(req, res) {
|
||||
res.status(201).send();
|
||||
}
|
||||
|
||||
async function stashMovieApi(req, res) {
|
||||
await stashMovie(req.body.movieId, req.params.stashId, req.session.user);
|
||||
|
||||
res.status(201).send();
|
||||
}
|
||||
|
||||
async function unstashActorApi(req, res) {
|
||||
await unstashActor(req.params.actorId, req.params.stashId, req.session.user);
|
||||
|
||||
@@ -26,9 +39,17 @@ async function unstashSceneApi(req, res) {
|
||||
res.status(204).send();
|
||||
}
|
||||
|
||||
async function unstashMovieApi(req, res) {
|
||||
await unstashMovie(req.params.movieId, req.params.stashId, req.session.user);
|
||||
|
||||
res.status(204).send();
|
||||
}
|
||||
|
||||
module.exports = {
|
||||
stashActor: stashActorApi,
|
||||
stashScene: stashSceneApi,
|
||||
stashMovie: stashMovieApi,
|
||||
unstashActor: unstashActorApi,
|
||||
unstashScene: unstashSceneApi,
|
||||
unstashMovie: unstashMovieApi,
|
||||
};
|
||||
|
||||
Reference in New Issue
Block a user