Added visibility toggle to stash tile. Collapsed stash page directory structure.
This commit is contained in:
17
src/users.js
17
src/users.js
@@ -25,20 +25,20 @@ export function curateUser(user, assets = {}) {
|
||||
}
|
||||
|
||||
function whereUser(builder, userId, options = {}) {
|
||||
if (typeof userId === 'number') {
|
||||
builder.where('users.id', userId);
|
||||
}
|
||||
|
||||
if (typeof userId === 'string') {
|
||||
if (Number.isNaN(Number(userId))) {
|
||||
builder.where(knex.raw('lower(users.username)'), userId.toLowerCase());
|
||||
|
||||
if (options.email) {
|
||||
builder.orWhere(knex.raw('lower(users.email)'), userId.toLowerCase());
|
||||
}
|
||||
|
||||
return;
|
||||
}
|
||||
|
||||
builder.where('users.id', Number(userId));
|
||||
}
|
||||
|
||||
export async function fetchUser(userId, options = {}) {
|
||||
export async function fetchUser(userId, options = {}, reqUser) {
|
||||
const user = await knex('users')
|
||||
.select(knex.raw('users.*, users_roles.abilities as role_abilities'))
|
||||
.modify((builder) => whereUser(builder, userId, options))
|
||||
@@ -52,6 +52,11 @@ export async function fetchUser(userId, options = {}) {
|
||||
|
||||
const stashes = await knex('stashes')
|
||||
.where('user_id', user.id)
|
||||
.modify((builder) => {
|
||||
if (reqUser?.id !== user.id) {
|
||||
builder.where('public', true);
|
||||
}
|
||||
})
|
||||
.leftJoin('stashes_meta', 'stashes_meta.stash_id', 'stashes.id');
|
||||
|
||||
if (options.raw) {
|
||||
|
||||
@@ -24,6 +24,10 @@ import {
|
||||
signupApi,
|
||||
} from './auth.js';
|
||||
|
||||
import {
|
||||
fetchUserApi
|
||||
} from './users.js';
|
||||
|
||||
import {
|
||||
createStashApi,
|
||||
removeStashApi,
|
||||
@@ -96,6 +100,7 @@ export default async function initServer() {
|
||||
router.delete('/api/session', logoutApi);
|
||||
|
||||
// USERS
|
||||
router.get('/api/users/:userId', fetchUserApi);
|
||||
router.post('/api/users', signupApi);
|
||||
|
||||
// STASHES
|
||||
|
||||
7
src/web/users.js
Normal file
7
src/web/users.js
Normal file
@@ -0,0 +1,7 @@
|
||||
import { fetchUser } from '../users.js';
|
||||
|
||||
export async function fetchUserApi(req, res) {
|
||||
const user = await fetchUser(req.params.userId, {}, req.user);
|
||||
|
||||
res.send(user);
|
||||
}
|
||||
Reference in New Issue
Block a user