add guild info in post, report and edit button
This commit is contained in:
parent
cd92a4b12e
commit
c33ab48225
4 changed files with 27 additions and 7 deletions
|
|
@ -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;
|
||||
|
||||
|
||||
}
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue