mirror of
https://github.com/spchcap/speech.capital.git
synced 2026-02-04 02:47:55 +00:00
Fix: Await ntfy notifications to ensure delivery
This commit is contained in:
@@ -3,7 +3,7 @@ const cookie=c=>(c.match(/auth_user=([^;]+)/)?.[1]||null);
|
|||||||
const hash=c=>(c.match(/auth_hash=([^;]+)/)?.[1]||null);
|
const hash=c=>(c.match(/auth_hash=([^;]+)/)?.[1]||null);
|
||||||
const tsEq=(a,b)=>{if(!a||!b)return!1;let d=a.length^b.length;for(let i=0;i<a.length;i++)d|=a.charCodeAt(i)^b.charCodeAt(i);return d===0};
|
const tsEq=(a,b)=>{if(!a||!b)return!1;let d=a.length^b.length;for(let i=0;i<a.length;i++)d|=a.charCodeAt(i)^b.charCodeAt(i);return d===0};
|
||||||
const auth=async(req,db)=>{const c=req.headers.get('Cookie')||'',u=cookie(c),h=hash(c);if(!u||!h)return null;const user=await db.prepare('SELECT id,username,role,pass_hash,banned_until FROM users WHERE username=?').bind(u).first();if(!user||!tsEq(user.pass_hash,h)||(user.banned_until&&new Date(user.banned_until.replace(' ','T')+'Z')>new Date()))return null;return user};
|
const auth=async(req,db)=>{const c=req.headers.get('Cookie')||'',u=cookie(c),h=hash(c);if(!u||!h)return null;const user=await db.prepare('SELECT id,username,role,pass_hash,banned_until FROM users WHERE username=?').bind(u).first();if(!user||!tsEq(user.pass_hash,h)||(user.banned_until&&new Date(user.banned_until.replace(' ','T')+'Z')>new Date()))return null;return user};
|
||||||
const notify=(url,msg,prio=3)=>{if(!url)return;const target=url.startsWith('http')?url:`https://${url}`;fetch(target,{method:'POST',body:msg,headers:{'X-Priority':prio.toString()}}).catch(()=>{})};
|
const notify=async(url,msg,prio=3)=>{if(!url)return;const target=url.startsWith('http')?url:`https://${url}`;try{await fetch(target,{method:'POST',body:msg,headers:{'X-Priority':prio.toString()}})}catch(e){}};
|
||||||
|
|
||||||
export async function onRequest({request,env}){
|
export async function onRequest({request,env}){
|
||||||
if(request.method==='OPTIONS'){
|
if(request.method==='OPTIONS'){
|
||||||
@@ -47,7 +47,7 @@ export async function onRequestPost({request,env}){
|
|||||||
const aiText=modData.choices?.[0]?.message?.content?.trim().toLowerCase()||'no';
|
const aiText=modData.choices?.[0]?.message?.content?.trim().toLowerCase()||'no';
|
||||||
const isApproved=aiText.includes('yes');
|
const isApproved=aiText.includes('yes');
|
||||||
|
|
||||||
notify(env.NTFY_URL, `Comment Mod [${isApproved?'OK':'REJECT'}]: ${user.username} -> ${content.slice(0,100)}${content.length>100?'...':''} | AI: ${aiText}`, 3);
|
await notify(env.NTFY_URL, `Comment Mod [${isApproved?'OK':'REJECT'}]: ${user.username} -> ${content.slice(0,100)}${content.length>100?'...':''} | AI: ${aiText}`, 3);
|
||||||
|
|
||||||
if(!isApproved)return json({error:{message:`Comment rejected by ${env.AI_MODEL}.`}},{status:400},request);
|
if(!isApproved)return json({error:{message:`Comment rejected by ${env.AI_MODEL}.`}},{status:400},request);
|
||||||
|
|
||||||
|
|||||||
Reference in New Issue
Block a user