add guild info in post, report and edit button

This commit is contained in:
Yusur 2025-10-11 20:14:07 +02:00
parent cd92a4b12e
commit c33ab48225
4 changed files with 27 additions and 7 deletions

View file

@ -1,12 +1,11 @@
import { backend } from '$lib/backend.js';
import { backend, type GuildEntry } from '$lib/backend.js';
import { error } from '@sveltejs/kit';
export async function load(event) {
const { params } = event;
const { id } = params;
const resp = await backend.withEvent(event).fetch('post/' + encodeURIComponent(id));
@ -14,18 +13,30 @@ export async function load(event) {
error(404);
}
let post;
try{
const respJ = await resp.json();
let { posts } = respJ;
return posts[id];
post = posts[id];
//return {};
if (post?.to && post.to.type === 'guild') {
const guild: GuildEntry = post.to;
const guildResp = await backend.withEvent(event).fetch('guild/' + encodeURIComponent(guild.id));
const guildJson = await guildResp.json();
const guildInfo = guildJson?.guilds?.[guild.id];
guildInfo.type = 'guild';
post.to = guildInfo || guild;
console.log(post.to);
}
}
catch (e) {
console.error(e);
error(502);
}
return post;
}