fix: preserve bid drafts and align tender source data
This commit is contained in:
+13
-4
@@ -1,3 +1,5 @@
|
||||
import { exchangeRates } from './exchange-rates.mjs';
|
||||
import { uniqueTenders, announcementFields } from './tender-quality.mjs';
|
||||
/**
|
||||
* ihaleist API Proxy — ilan.gov.tr canlı ihale verisi
|
||||
*
|
||||
@@ -582,7 +584,7 @@ async function getDetail(ilanId) {
|
||||
if (cache.detail.has(ilanId)) return cache.detail.get(ilanId);
|
||||
const raw = await ilanDetail(ilanId);
|
||||
const text = htmlToText(raw.content || '');
|
||||
const detail = { aciklama: text.slice(0, 4000), adNo: raw.adNo || null };
|
||||
const detail = { ...announcementFields(text), adNo: raw.adNo || null };
|
||||
cache.detail.set(ilanId, detail);
|
||||
if (cache.detail.size > 500) cache.detail.delete(cache.detail.keys().next().value);
|
||||
return detail;
|
||||
@@ -661,22 +663,28 @@ async function tendersPayload(force = false) {
|
||||
console.warn('[kalem] özet uygulanamadı:', e.message);
|
||||
}
|
||||
|
||||
const combined = uniqueTenders([...dt.tenders, ...c.tenders, ...hist.tenders]);
|
||||
return {
|
||||
success: true,
|
||||
source: sources.join(' + '),
|
||||
fetchedAt: new Date(c.fetchedAt).toLocaleString('tr-TR'),
|
||||
totalCount: c.totalCount + dt.totalCount + hist.totalCount,
|
||||
ilanCount: c.totalCount,
|
||||
todayCount: c.todayCount,
|
||||
todayCount: bugunEklenenSayisi(combined),
|
||||
loadedUniqueCount: combined.length,
|
||||
dtCount: dt.totalCount,
|
||||
historyCount: hist.totalCount,
|
||||
tenders: [...dt.tenders, ...c.tenders, ...hist.tenders],
|
||||
tenders: combined,
|
||||
};
|
||||
}
|
||||
|
||||
const server = http.createServer(async (req, res) => {
|
||||
const url = new URL(req.url, `http://localhost:${PORT}`);
|
||||
try {
|
||||
if (url.pathname === '/api/exchange-rates') {
|
||||
try { return json(res,200,{success:true,...await exchangeRates()}); }
|
||||
catch(e) { return json(res,503,{success:false,error:e.message}); }
|
||||
}
|
||||
// --- Google ile Giriş ---
|
||||
if (url.pathname === '/api/auth/google/config') {
|
||||
return json(res, 200, { clientId: process.env.GOOGLE_CLIENT_ID || null });
|
||||
@@ -1507,7 +1515,8 @@ const server = http.createServer(async (req, res) => {
|
||||
}
|
||||
});
|
||||
|
||||
server.listen(PORT, () => {
|
||||
server.listen(PORT, process.env.NODE_ENV === 'test' ? '127.0.0.1' : undefined, () => {
|
||||
if (process.env.NODE_ENV === 'test') return;
|
||||
// Gömme modeli soğuk yüklemesi ~45 sn; ilk kullanıcı beklemesin diye arka planda ısıt.
|
||||
arkaPlandaIsit();
|
||||
console.log(`[ihaleist-api] http://localhost:${PORT} — canlı veri: ilan.gov.tr`);
|
||||
|
||||
Reference in New Issue
Block a user