Persist client document read failures with stale-state protection
This commit is contained in:
@@ -1064,6 +1064,19 @@ const server = http.createServer(async (req, res) => {
|
||||
return json(res, 200, { success: true, belgeler: store.listDocuments(user.email) });
|
||||
} catch (e) { return json(res, 400, { success: false, error: e.message }); }
|
||||
}
|
||||
if (url.pathname === '/api/me/documents/read-error' && req.method === 'POST') {
|
||||
const user = userFromAuthHeader(req.headers['authorization']);
|
||||
if (!user) return json(res,401,{success:false,error:'oturum yok'});
|
||||
try {
|
||||
const body = await readBody(req,8192);
|
||||
const rec = body.id && store.getDocument(user.email,String(body.id));
|
||||
if (!rec || rec.tur !== 'ihale') return json(res,404,{success:false,error:'ihale dokümanı bulunamadı'});
|
||||
if (!Object.hasOwn(body,'expectedProcessing')) return json(res,400,{success:false,error:'işleme sürümü gerekli'});
|
||||
if (!store.reportDocumentReadError(user.email,rec.id,body.expectedProcessing))
|
||||
return json(res,409,{success:false,error:'Belge işleme durumu değişti. Listeyi yeniden yükleyin.'});
|
||||
return json(res,200,{success:true});
|
||||
} catch (e) { return json(res,400,{success:false,error:e.message}); }
|
||||
}
|
||||
// Belge metni — docx/xlsx/zip için. PDF tarayıcıda (pdfjs) okunuyor;
|
||||
// bu türler için tarayıcıda çözücü yok, baytlar zaten burada duruyor.
|
||||
if (url.pathname === '/api/me/documents/text') {
|
||||
|
||||
@@ -284,6 +284,12 @@ export function setDocumentProcessing(email,id,processing) {
|
||||
.run(JSON.stringify({...processing,updatedAt:now()}),id,email).changes>0);
|
||||
}
|
||||
|
||||
export function reportDocumentReadError(email,id,expectedProcessing) {
|
||||
const processing={status:'error',error:'Dosya metni okunamadı. Dosya biçimini ve bütünlüğünü kontrol edip yeniden deneyin.',updatedAt:now()};
|
||||
return withDb(db=>db.prepare("UPDATE belgeler SET isleme=? WHERE id=? AND email=? AND tur='ihale' AND isleme IS ?")
|
||||
.run(JSON.stringify(processing),id,email,expectedProcessing == null ? null : JSON.stringify(expectedProcessing)).changes>0);
|
||||
}
|
||||
|
||||
export function getDocument(email, id) {
|
||||
return withDb((db) => db.prepare('SELECT * FROM belgeler WHERE id=? AND email=?').get(id, email) || null);
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user