fix: validate document uploads and allow clearing expiry dates

This commit is contained in:
2026-09-06 09:14:43 +03:00
parent 0d2cf584e7
commit 43dc4feb31
5 changed files with 62 additions and 10 deletions
+6 -6
View File
@@ -1,3 +1,4 @@
import { documentMetadataPatch, decodeDocumentUpload } from './document-metadata.mjs';
import { deadlineInfo } from '../src/services/tenderCalendar.js';
import { exchangeRates } from './exchange-rates.mjs';
import { uniqueTenders, announcementFields } from './tender-quality.mjs';
@@ -953,7 +954,8 @@ const server = http.createServer(async (req, res) => {
if (!body.ad || !body.icerikBase64) {
return json(res, 400, { success: false, error: 'ad ve icerikBase64 gerekli' });
}
const buf = Buffer.from(body.icerikBase64, 'base64');
const metadata = documentMetadataPatch(body);
const buf = decodeDocumentUpload(body.icerikBase64);
const kullanimDurumu = store.documentUsage(user.email);
kotaKontrol(user.email, 'belgeAdet', kullanimDurumu.adet, 1, opts);
kotaKontrol(user.email, 'belgeBayt', kullanimDurumu.bayt, buf.length, opts);
@@ -971,11 +973,11 @@ const server = http.createServer(async (req, res) => {
fs.writeFileSync(path.join(store.BELGE_DIR, dosyaAdi), buf);
const id = store.addDocument(user.email, {
ad: String(body.ad).slice(0, 200),
kategori: body.kategori || null,
kategori: metadata.kategori || null,
boyut: buf.length, // GERÇEK bayt — rastgele değil
mime: body.mime || null,
dosya: dosyaAdi,
sonKullanma: body.sonKullanma || null,
sonKullanma: metadata.sonKullanma || null,
ikn, // ihaleye bağlı belge
});
// Yükleme anında otomatik kalem çıkarımı — AI kullanmaz, kullanıcıdan
@@ -1037,9 +1039,7 @@ const server = http.createServer(async (req, res) => {
try {
const body = await readBody(req);
if (!body.id) return json(res, 400, { success: false, error: 'id gerekli' });
const sonKullanma = body.sonKullanma ? String(body.sonKullanma).slice(0, 10) : null;
if (sonKullanma && !/^\d{4}-\d{2}-\d{2}$/.test(sonKullanma)) return json(res, 400, { success: false, error: 'tarih YYYY-AA-GG olmalı' });
const ok = store.updateDocument(user.email, String(body.id), { sonKullanma, kategori: body.kategori ? String(body.kategori).slice(0, 60) : null });
const ok = store.updateDocument(user.email, String(body.id), documentMetadataPatch(body));
if (!ok) return json(res, 404, { success: false, error: 'belge bulunamadı' });
return json(res, 200, { success: true, belgeler: store.listDocuments(user.email) });
} catch (e) { return json(res, 400, { success: false, error: e.message }); }