import{a as e}from"./admin-auth-D6OxYqSG.js";import{n as t}from"./server-CQ_uNuZK.js";import{env as n}from"cloudflare:workers";var r=new Set([`image/jpeg`,`image/png`,`image/webp`,`image/gif`]);function i(){return n.MEDIA}async function a(n){if(!await e())return t.json({error:`unauthorized`},{status:401});let a=(await n.formData()).get(`file`);if(!(a instanceof File)||!r.has(a.type)||a.size>8*1024*1024)return t.json({error:`فایل تصویر معتبر نیست یا بیشتر از ۸ مگابایت است.`},{status:400});let o=a.name.split(`.`).pop()?.toLowerCase().replace(/[^a-z0-9]/g,``)||`jpg`,s=`news/${Date.now()}-${crypto.randomUUID()}.${o}`;return await i().put(s,await a.arrayBuffer(),{httpMetadata:{contentType:a.type,cacheControl:`public, max-age=31536000, immutable`},customMetadata:{originalName:a.name}}),t.json({url:`/api/media/${s}`,alt:a.name.replace(/\.[^.]+$/,``)})}export{a as POST};