live update banner udpates
This commit is contained in:
@@ -193,6 +193,14 @@ export const handleBannerUpload = async (req, res) => {
|
||||
banner_size = ${parts.banner_size || 'cover'}
|
||||
where user_id = ${+req.session.id}
|
||||
`;
|
||||
const payloadStr = JSON.stringify({
|
||||
user_id: +req.session.id,
|
||||
user: req.session.user,
|
||||
banner_file: finalFilename,
|
||||
banner_position: parts.banner_position || 'center',
|
||||
banner_size: parts.banner_size || 'cover'
|
||||
});
|
||||
await db`select pg_notify('profile_update', ${payloadStr})`;
|
||||
} catch (dbErr) {
|
||||
console.error('[BANNER HANDLER] DB update failed:', dbErr.message);
|
||||
await fs.unlink(finalPath).catch(() => {});
|
||||
@@ -265,6 +273,12 @@ export const handleBannerDelete = async (req, res) => {
|
||||
set banner_file = null
|
||||
where user_id = ${+req.session.id}
|
||||
`;
|
||||
const payloadStr = JSON.stringify({
|
||||
user_id: +req.session.id,
|
||||
user: req.session.user,
|
||||
banner_file: null
|
||||
});
|
||||
await db`select pg_notify('profile_update', ${payloadStr})`;
|
||||
|
||||
console.log('[BANNER HANDLER] Delete complete');
|
||||
return sendJson(res, { success: true, msg: 'Custom banner removed' }, 200);
|
||||
|
||||
@@ -94,6 +94,17 @@ db.listen('profile_update', (payload) => {
|
||||
if (data.do_not_disturb !== undefined) client.do_not_disturb = data.do_not_disturb;
|
||||
|
||||
client.send({ type: 'profile_update', data });
|
||||
} else {
|
||||
// For other users, only send public profile fields (so their DOM can live-update)
|
||||
const publicData = {
|
||||
user_id: data.user_id,
|
||||
user: data.user,
|
||||
display_name: data.display_name,
|
||||
banner_file: data.banner_file,
|
||||
banner_position: data.banner_position,
|
||||
banner_size: data.banner_size
|
||||
};
|
||||
client.send({ type: 'profile_update', data: publicData });
|
||||
}
|
||||
}
|
||||
} catch (e) {
|
||||
|
||||
Reference in New Issue
Block a user