fix(web): ignore inactive application attachments

This commit is contained in:
nyan404 committed 2026-08-25 04:16:27 +03:00
1 parent 2a21723237
commit e6473c280f
2 files changed
+6 -4

No files matched your search

+1
View File
@@ -87,6 +87,7 @@
- 2026-08-25: report copy now uses a plural construction for several kittens, normative `провёл(-ла)` for lessons, and a readable empty-resource line instead of a standalone `0`. - 2026-08-25: report copy now uses a plural construction for several kittens, normative `провёл(-ла)` for lessons, and a readable empty-resource line instead of a standalone `0`.
- 2026-08-25: free-form inspection parsing now distinguishes a labelled count (or a count immediately after the place) from date fragments and character IDs; it also understands explicit character labels and both `+N ресурс` and legacy `ресурс=N` loot notation. - 2026-08-25: free-form inspection parsing now distinguishes a labelled count (or a count immediately after the place) from date fragments and character IDs; it also understands explicit character labels and both `+N ресурс` and legacy `ресурс=N` loot notation.
- 2026-08-25: the explicit `/осмотр` command now accepts both natural orders for its first fields: `дупло 6` and `6 дупло`. - 2026-08-25: the explicit `/осмотр` command now accepts both natural orders for its first fields: `дупло 6` and `6 дупло`.
- 2026-08-25: the legacy `/applications` page now disables inactive type-specific controls, matching the embedded `/belki` form and preventing hidden previously selected files from being uploaded after a type switch.
- 2026-08-25: explicit `/лу` and `/зу` commands accept a time range with a dash and written Russian dates in their schedule segment, while still requiring exactly two valid clock values. - 2026-08-25: explicit `/лу` and `/зу` commands accept a time range with a dash and written Russian dates in their schedule segment, while still requiring exactly two valid clock values.
- 2026-08-25: free-form coaching input additionally normalizes Russian written month names and common abbreviations (for example, `24 августа` and `1-го сент`) into the existing `ДД.ММ` date field. - 2026-08-25: free-form coaching input additionally normalizes Russian written month names and common abbreviations (for example, `24 августа` and `1-го сент`) into the existing `ДД.ММ` date field.
- 2026-08-25: `/api/admin/auth` now permits five password attempts per source in a rolling 15-minute window and clears that local budget after a successful sign-in. Edge rate limiting and TLS remain required deployment controls. - 2026-08-25: `/api/admin/auth` now permits five password attempts per source in a rolling 15-minute window and clears that local budget after a successful sign-in. Edge rate limiting and TLS remain required deployment controls.
+5 -4
View File
@@ -37,9 +37,10 @@
</main><script> </main><script>
const form=document.querySelector('#form'), error=document.querySelector('#error'); let active='feather_donation'; const form=document.querySelector('#form'), error=document.querySelector('#error'); let active='feather_donation';
function addFeather(data={}){const row=document.createElement('div');row.className='feather';row.innerHTML='<label>Количество<input data-field="amount" type="number" min="1" required></label><label>Цвет<input data-field="color" placeholder="например, синие" required></label><label>Источник добычи<input data-field="source" placeholder="личные запасы, осмотр дупла…" required></label><button class="remove" type="button">Убрать</button>';Object.entries(data).forEach(([k,v])=>{const el=row.querySelector(`[data-field="${k}"]`);if(el)el.value=v});row.querySelector('.remove').onclick=()=>row.remove();document.querySelector('#feathers').append(row)} addFeather();document.querySelector('#addFeather').onclick=()=>addFeather(); function addFeather(data={}){const row=document.createElement('div');row.className='feather';row.innerHTML='<label>Количество<input data-field="amount" type="number" min="1" required></label><label>Цвет<input data-field="color" placeholder="например, синие" required></label><label>Источник добычи<input data-field="source" placeholder="личные запасы, осмотр дупла…" required></label><button class="remove" type="button">Убрать</button>';Object.entries(data).forEach(([k,v])=>{const el=row.querySelector(`[data-field="${k}"]`);if(el)el.value=v});row.querySelector('.remove').onclick=()=>row.remove();document.querySelector('#feathers').append(row)} addFeather();document.querySelector('#addFeather').onclick=()=>addFeather();
function sync(){document.querySelector('#featherFields').classList.toggle('hidden',active!=='feather_donation');document.querySelector('#kittenFields').classList.toggle('hidden',active!=='kitten');document.querySelector('#curatorFields').classList.toggle('hidden',active!=='curator');document.querySelector('#flyingFields').classList.toggle('hidden',active!=='flying_squirrel');document.querySelector('#vkField').classList.toggle('hidden',active!=='flying_squirrel');document.querySelectorAll('.type').forEach(x=>x.classList.toggle('active',x.dataset.type===active))} document.querySelectorAll('.type').forEach(b=>b.onclick=()=>{active=b.dataset.type;sync()});sync(); function setVisible(selector,visible){const section=document.querySelector(selector);section.classList.toggle('hidden',!visible);section.querySelectorAll('input,select,textarea,button').forEach(field=>field.disabled=!visible)}
document.querySelector('[name="practiced_before"]').onchange=e=>document.querySelector('#practiceLink').classList.toggle('hidden',e.target.value!=='yes'); function sync(){setVisible('#featherFields',active==='feather_donation');setVisible('#kittenFields',active==='kitten');setVisible('#curatorFields',active==='curator');setVisible('#flyingFields',active==='flying_squirrel');setVisible('#vkField',active==='flying_squirrel');const practiced=document.querySelector('[name="practiced_before"]');setVisible('#practiceLink',active==='flying_squirrel'&&practiced.value==='yes');document.querySelectorAll('.type').forEach(x=>x.classList.toggle('active',x.dataset.type===active))} document.querySelectorAll('.type').forEach(b=>b.onclick=()=>{active=b.dataset.type;sync()});sync();
document.querySelector('[name="practiced_before"]').onchange=()=>sync();
document.querySelectorAll('.screenshots').forEach(input=>input.onchange=()=>{const list=input.closest('section').querySelector('.files');list.replaceChildren(...[...input.files].map(file=>{const li=document.createElement('li');li.textContent=file.name;return li}))}); document.querySelectorAll('.screenshots').forEach(input=>input.onchange=()=>{const list=input.closest('section').querySelector('.files');list.replaceChildren(...[...input.files].map(file=>{const li=document.createElement('li');li.textContent=file.name;return li}))});
async function uploads(){const items=[];for(const file of [...document.querySelectorAll('.screenshots')].flatMap(x=>[...x.files])){const data=await new Promise((resolve,reject)=>{const reader=new FileReader();reader.onload=()=>resolve(reader.result);reader.onerror=reject;reader.readAsDataURL(file)});const r=await fetch('/api/web/upload',{method:'POST',headers:{'Content-Type':'application/json'},body:JSON.stringify({name:file.name,type:file.type,data})});const d=await r.json();if(!r.ok)throw new Error(d.error||`Не удалось загрузить ${file.name}`);items.push({type:'photo',url:d.url,name:file.name})}return items} async function uploads(){const items=[];for(const file of [...document.querySelectorAll('.screenshots:not(:disabled)')].flatMap(x=>[...x.files])){const data=await new Promise((resolve,reject)=>{const reader=new FileReader();reader.onload=()=>resolve(reader.result);reader.onerror=reject;reader.readAsDataURL(file)});const r=await fetch('/api/web/upload',{method:'POST',headers:{'Content-Type':'application/json'},body:JSON.stringify({name:file.name,type:file.type,data})});const d=await r.json();if(!r.ok)throw new Error(d.error||`Не удалось загрузить ${file.name}`);items.push({type:'photo',url:d.url,name:file.name})}return items}
form.addEventListener('submit',async e=>{e.preventDefault();error.textContent='';try{const data=Object.fromEntries(new FormData(form).entries());data.type=active;data.character_id=Number(data.character_id);data.attachments=await uploads();if(active==='flying_squirrel'){data.practiced_before=data.practiced_before==='yes'}if(active==='feather_donation')data.feathers=[...document.querySelectorAll('.feather')].map(row=>({amount:Number(row.querySelector('[data-field="amount"]').value),color:row.querySelector('[data-field="color"]').value,source:row.querySelector('[data-field="source"]').value}));const r=await fetch('/api/applications',{method:'POST',headers:{'Content-Type':'application/json'},body:JSON.stringify(data)});const d=await r.json();if(!r.ok)throw new Error(d.error||'Не удалось отправить заявку');const success=document.querySelector('#success');success.textContent=`Заявка №${d.id} отправлена на рассмотрение.`;success.classList.remove('hidden');form.reset();document.querySelector('#feathers').replaceChildren();addFeather()}catch(err){error.textContent=err.message}}); form.addEventListener('submit',async e=>{e.preventDefault();error.textContent='';try{const data=Object.fromEntries(new FormData(form).entries());data.type=active;data.character_id=Number(data.character_id);data.attachments=await uploads();if(active==='flying_squirrel'){data.practiced_before=data.practiced_before==='yes'}if(active==='feather_donation')data.feathers=[...document.querySelectorAll('.feather')].map(row=>({amount:Number(row.querySelector('[data-field="amount"]').value),color:row.querySelector('[data-field="color"]').value,source:row.querySelector('[data-field="source"]').value}));const r=await fetch('/api/applications',{method:'POST',headers:{'Content-Type':'application/json'},body:JSON.stringify(data)});const d=await r.json();if(!r.ok)throw new Error(d.error||'Не удалось отправить заявку');const success=document.querySelector('#success');success.textContent=`Заявка №${d.id} отправлена на рассмотрение.`;success.classList.remove('hidden');form.reset();document.querySelector('#feathers').replaceChildren();addFeather();sync()}catch(err){error.textContent=err.message}});
</script></body></html> </script></body></html>