pisse aus meinem arsch

This commit is contained in:
2026-08-07 22:18:32 +02:00
parent c9f5dc02fa
commit c22ae5bde0
4 changed files with 104 additions and 95 deletions

View File

@@ -758,8 +758,8 @@ export default router => {
} }
} }
// Broadcast new_item event for live grid updates (only if auto-approved) // Broadcast new_item event for live grid updates (only if auto-approved and public)
if (!isApprovalRequired) { if (!isApprovalRequired && targetVisibility === 0) {
try { try {
await db`SELECT pg_notify('new_item', ${JSON.stringify({ await db`SELECT pg_notify('new_item', ${JSON.stringify({
id: itemid, id: itemid,
@@ -775,8 +775,8 @@ export default router => {
} }
} }
// Push to Matrix Channel (only if auto-approved) // Push to Matrix Channel (only if auto-approved and public)
if (!isApprovalRequired) { if (!isApprovalRequired && targetVisibility === 0) {
try { try {
const self = router.self; const self = router.self;
const matrixCfg = cfg.clients?.find(c => c.type === 'matrix'); const matrixCfg = cfg.clients?.find(c => c.type === 'matrix');

View File

@@ -114,7 +114,7 @@ export default (router, tpl) => {
} }
const f0ck = await db` const f0ck = await db`
select i.dest, i.mime, i.username, i.id, ta.tag_id select i.dest, i.mime, i.username, i.id, i.visibility, ta.tag_id
from "items" i from "items" i
left join tags_assign ta on ta.item_id = i.id and ta.tag_id in (1, 2) left join tags_assign ta on ta.item_id = i.id and ta.tag_id in (1, 2)
where i.id = ${id} and i.active = false where i.id = ${id} and i.active = false
@@ -156,65 +156,69 @@ export default (router, tpl) => {
console.error('[MOD APPROVE] Failed to notify user:', err); console.error('[MOD APPROVE] Failed to notify user:', err);
} }
// Push to Discord Webhook (Direct) const isPublic = (f0ck[0].visibility || 0) === 0;
try {
const discordClient = cfg.clients.find(c => c.type === 'discord');
if (discordClient && discordClient.webhook_url) {
const message = `${f0ck[0].username} uploaded a new video ${cfg.main.url.full}/${id}`;
const payload = JSON.stringify({ content: message });
const url = new URL(discordClient.webhook_url);
const options = {
hostname: url.hostname,
path: url.pathname + url.search,
method: 'POST',
headers: {
'Content-Type': 'application/json',
'Content-Length': Buffer.byteLength(payload)
}
};
const reqDiscord = https.request(options, (resDiscord) => {
if (resDiscord.statusCode >= 400) {
console.error(`[MOD APPROVE] Webhook returned status ${resDiscord.statusCode}`);
}
});
reqDiscord.on('error', (err) => {
console.error('[MOD APPROVE] Webhook failed:', err);
});
reqDiscord.write(payload);
reqDiscord.end();
}
} catch (err) {
console.error('[MOD APPROVE] Discord Webhook error:', err);
}
// Push to Matrix Channel if (isPublic) {
try { // Push to Discord Webhook (Direct)
const matrixCfg = cfg.clients.find(c => c.type === 'matrix'); try {
if (matrixCfg?.notification_channel_id && router.self?.bot?.clients) { const discordClient = cfg.clients.find(c => c.type === 'discord');
const clients = await Promise.all(router.self.bot.clients); if (discordClient && discordClient.webhook_url) {
const matrixWrapper = clients.find(c => c.type === 'matrix');
if (matrixWrapper?.client) {
const message = `${f0ck[0].username} uploaded a new video ${cfg.main.url.full}/${id}`; const message = `${f0ck[0].username} uploaded a new video ${cfg.main.url.full}/${id}`;
await matrixWrapper.client.send(matrixCfg.notification_channel_id, message); const payload = JSON.stringify({ content: message });
console.log(`[MOD APPROVE] Matrix notification sent for item ${id}`); const url = new URL(discordClient.webhook_url);
const options = {
hostname: url.hostname,
path: url.pathname + url.search,
method: 'POST',
headers: {
'Content-Type': 'application/json',
'Content-Length': Buffer.byteLength(payload)
}
};
const reqDiscord = https.request(options, (resDiscord) => {
if (resDiscord.statusCode >= 400) {
console.error(`[MOD APPROVE] Webhook returned status ${resDiscord.statusCode}`);
}
});
reqDiscord.on('error', (err) => {
console.error('[MOD APPROVE] Webhook failed:', err);
});
reqDiscord.write(payload);
reqDiscord.end();
} }
} catch (err) {
console.error('[MOD APPROVE] Discord Webhook error:', err);
} }
} catch (err) {
console.error('[MOD APPROVE] Matrix notification error:', err);
}
// Broadcast new_item event for live grid updates // Push to Matrix Channel
try { try {
await db`SELECT pg_notify('new_item', ${JSON.stringify({ const matrixCfg = cfg.clients.find(c => c.type === 'matrix');
id: id, if (matrixCfg?.notification_channel_id && router.self?.bot?.clients) {
dest: f0ck[0].dest, const clients = await Promise.all(router.self.bot.clients);
mime: f0ck[0].mime, const matrixWrapper = clients.find(c => c.type === 'matrix');
username: f0ck[0].username, if (matrixWrapper?.client) {
tag_id: f0ck[0].tag_id, const message = `${f0ck[0].username} uploaded a new video ${cfg.main.url.full}/${id}`;
is_oc: !!f0ck[0].is_oc await matrixWrapper.client.send(matrixCfg.notification_channel_id, message);
})})`; console.log(`[MOD APPROVE] Matrix notification sent for item ${id}`);
} catch (err) { }
console.error('[MOD APPROVE] new_item notify failed:', err); }
} catch (err) {
console.error('[MOD APPROVE] Matrix notification error:', err);
}
// Broadcast new_item event for live grid updates
try {
await db`SELECT pg_notify('new_item', ${JSON.stringify({
id: id,
dest: f0ck[0].dest,
mime: f0ck[0].mime,
username: f0ck[0].username,
tag_id: f0ck[0].tag_id,
is_oc: !!f0ck[0].is_oc
})})`;
} catch (err) {
console.error('[MOD APPROVE] new_item notify failed:', err);
}
} }
} }

View File

@@ -211,6 +211,7 @@ db.listen('motd', (payload) => {
db.listen('new_item', (payload) => { db.listen('new_item', (payload) => {
try { try {
const data = JSON.parse(payload); const data = JSON.parse(payload);
if (data.visibility && data.visibility !== 0) return;
console.log(`[SSE] Broadcasting new_item (id: ${data.id}) to ${clients.size} clients`); console.log(`[SSE] Broadcasting new_item (id: ${data.id}) to ${clients.size} clients`);
for (const client of clients) { for (const client of clients) {
client.send({ type: 'new_item', data }); client.send({ type: 'new_item', data });

View File

@@ -717,33 +717,35 @@ export const handleUpload = async (req, res, self) => {
// Auto-tagging from embedded metadata was removed — the user must select suggestions explicitly. // Auto-tagging from embedded metadata was removed — the user must select suggestions explicitly.
// Discord Webhook // Discord Webhook (only for public uploads)
try { if (targetVisibility === 0) {
const discordClient = cfg.clients.find(c => c.type === 'discord'); try {
if (discordClient && discordClient.webhook_url) { const discordClient = cfg.clients.find(c => c.type === 'discord');
const message = `${req.session.user} uploaded a new ${actualMime.split('/')[0]}: ${cfg.main.url.full}/${itemid}`; if (discordClient && discordClient.webhook_url) {
const payload = JSON.stringify({ content: message }); const message = `${req.session.user} uploaded a new ${actualMime.split('/')[0]}: ${cfg.main.url.full}/${itemid}`;
const url = new URL(discordClient.webhook_url); const payload = JSON.stringify({ content: message });
const options = { const url = new URL(discordClient.webhook_url);
hostname: url.hostname, const options = {
path: url.pathname + url.search, hostname: url.hostname,
method: 'POST', path: url.pathname + url.search,
headers: { method: 'POST',
'Content-Type': 'application/json', headers: {
'Content-Length': Buffer.byteLength(payload) 'Content-Type': 'application/json',
} 'Content-Length': Buffer.byteLength(payload)
}; }
const reqDiscord = https.request(options, (resDiscord) => { }); };
reqDiscord.on('error', (err) => console.error('[UPLOAD] Discord Webhook failed:', err)); const reqDiscord = https.request(options, (resDiscord) => { });
reqDiscord.write(payload); reqDiscord.on('error', (err) => console.error('[UPLOAD] Discord Webhook failed:', err));
reqDiscord.end(); reqDiscord.write(payload);
reqDiscord.end();
}
} catch (err) {
console.error(`[BACKGROUND ERROR] Discord notification failed:`, err);
} }
} catch (err) {
console.error(`[BACKGROUND ERROR] Discord notification failed:`, err);
} }
// Broadcast new_item event for live grid updates (only if auto-approved) // Broadcast new_item event for live grid updates (only if auto-approved and public)
if (!manualApproval) { if (!manualApproval && targetVisibility === 0) {
try { try {
await db`SELECT pg_notify('new_item', ${JSON.stringify({ await db`SELECT pg_notify('new_item', ${JSON.stringify({
id: itemid, id: itemid,
@@ -759,20 +761,22 @@ export const handleUpload = async (req, res, self) => {
} }
} }
// Push to Matrix Channel // Push to Matrix Channel (only if auto-approved and public)
try { if (!manualApproval && targetVisibility === 0) {
const matrixCfg = cfg.clients.find(c => c.type === 'matrix'); try {
if (matrixCfg?.notification_channel_id && self?.bot?.clients) { const matrixCfg = cfg.clients.find(c => c.type === 'matrix');
const clients = await Promise.all(self.bot.clients); if (matrixCfg?.notification_channel_id && self?.bot?.clients) {
const matrixWrapper = clients.find(c => c.type === 'matrix'); const clients = await Promise.all(self.bot.clients);
if (matrixWrapper?.client) { const matrixWrapper = clients.find(c => c.type === 'matrix');
const message = `${req.session.user} uploaded a new item ${cfg.main.url.full}/${itemid}`; if (matrixWrapper?.client) {
await matrixWrapper.client.send(matrixCfg.notification_channel_id, message); const message = `${req.session.user} uploaded a new item ${cfg.main.url.full}/${itemid}`;
console.log(`[UPLOAD] Matrix notification sent for item ${itemid}`); await matrixWrapper.client.send(matrixCfg.notification_channel_id, message);
console.log(`[UPLOAD] Matrix notification sent for item ${itemid}`);
}
} }
} catch (err) {
console.error('[UPLOAD] Matrix notification error:', err);
} }
} catch (err) {
console.error('[UPLOAD] Matrix notification error:', err);
} }
// Staff Notifications // Staff Notifications