fix: separate private company documents from shared tender item imports

This commit is contained in:
2026-09-06 09:30:37 +03:00
parent 5e9f17969c
commit ece623d86c
8 changed files with 52 additions and 14 deletions
+8 -2
View File
@@ -746,6 +746,9 @@ const server = http.createServer(async (req, res) => {
try {
const body = await readBody(req, 4 * 1024 * 1024);
if (!body.ikn) return json(res, 400, { success: false, error: 'ikn gerekli' });
const sourceDocument = body.documentId && store.getDocument(user.email,String(body.documentId));
if (!sourceDocument || sourceDocument.tur !== 'ihale' || sourceDocument.ikn !== String(body.ikn))
return json(res,403,{success:false,error:'Kalem aktarımı için bu ihaleye bağlı, size ait ihale dokümanı gerekli. Firma belgeleri ortak havuza aktarılamaz.'});
const { kalemler, yontem } = kalemleriCikar(body.metin || '');
if (!kalemler.length) {
return json(res, 200, { success: true, kalemler: [], yontem, not: 'Metinde teklif cetveli tablosu bulunamadı.' });
@@ -954,6 +957,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 documentType = body.documentType ?? 'firma';
if (!['firma','ihale'].includes(documentType)) throw new Error('Geçersiz belge türü.');
const metadata = documentMetadataPatch(body);
const buf = decodeDocumentUpload(body.icerikBase64);
const kullanimDurumu = store.documentUsage(user.email);
@@ -967,20 +972,21 @@ const server = http.createServer(async (req, res) => {
let ofisMetni = null;
if (sunucuOkuyabilir(body.ad)) {
try { ofisMetni = arsivMetni(String(body.ad), buf); } catch { /* metin çıkmazsa devam */ }
if (!ikn && body.otoIkn && ofisMetni) ikn = iknCikar(ofisMetni);
if (documentType === 'ihale' && !ikn && body.otoIkn && ofisMetni) ikn = iknCikar(ofisMetni);
}
const id = store.saveDocumentFile(user.email, {
ad: String(body.ad).slice(0, 200),
kategori: metadata.kategori || null,
mime: body.mime || null,
sonKullanma: metadata.sonKullanma || null,
tur: documentType,
ikn, // ihaleye bağlı belge
}, buf);
// Yükleme anında otomatik kalem çıkarımı — AI kullanmaz, kullanıcıdan
// tıklama beklemez. PDF'ler tarayıcıda çözüldüğü için istemci
// metni /api/kalem/cikar'a gönderir.
let kalemBilgi = null;
if (ikn && ofisMetni) {
if (documentType === 'ihale' && ikn && ofisMetni) {
try {
const { kalemler, yontem } = kalemleriCikar(ofisMetni);
if (kalemler.length) {