adds privacy settings

This commit is contained in:
Christian Beutel
2024-12-17 00:53:27 +01:00
parent 43b6be8fb2
commit 92f0b033fa
25 changed files with 2025 additions and 28 deletions

View File

@@ -1,4 +1,8 @@
import type { Follow } from "$lib/models/follow";
import type { Settings } from "$lib/models/settings";
import type { UserAnonymous } from "$lib/models/user";
import { follows_a_b, follows_counts, follows_index } from "$lib/stores/follow_store";
import { settings_show } from "$lib/stores/settings_store";
import { users_show } from "$lib/stores/user_store";
import { error, type ServerLoad } from "@sveltejs/kit";
import { ClientResponseError } from "pocketbase";
@@ -11,20 +15,24 @@ export const load: ServerLoad = async ({ params, locals, fetch }) => {
try {
const user = await users_show(params.id, fetch);
if(user.private && locals.user.id != params.id) {
error(401, {
message: "Profile is private"
})
}
const isOwnProfile = params.id === locals.user?.id;
const follow = await follows_a_b(locals.user?.id, params.id, fetch) ?? null
const followCounts = await follows_counts(params.id, fetch)
return { user, isOwnProfile, ...followCounts, follow: follow }
} catch (e) {
if (e instanceof ClientResponseError && e.status == 404) {
error(404, {
message: 'Not found'
});
} else {
throw e
}
throw e
}
};