feat: извлекаю текст PDF через новый API

This commit is contained in:
Тимур Городецкий
2026-09-16 15:01:04 +05:00
parent b0c08bcc83
commit 7e403a8623
2 changed files with 26 additions and 0 deletions
@@ -240,6 +240,7 @@ export function useKpProcessing(
patchFile(entry.localId, { spId, status: 'extracting' });
const isWord = /\.(doc|docx|xls|xlsx)$/i.test(entry.file.name);
const isPdf = /\.pdf$/i.test(entry.file.name);
if (isWord) {
try {
await service.extractWordText(spId);
@@ -247,6 +248,13 @@ export function useKpProcessing(
patchFile(entry.localId, { status: 'error', error: `Ошибка извлечения текста Word: ${(err as Error).message}` });
continue;
}
} else if (isPdf) {
try {
await service.extractPDFText(spId);
} catch (err) {
patchFile(entry.localId, { status: 'error', error: `Ошибка извлечения текста PDF: ${(err as Error).message}` });
continue;
}
}
pollSyntex(entry.localId, spId, name, 0).catch(err => {
@@ -1406,6 +1406,24 @@ export class CtService {
throw new Error(`Ошибка извлечения текста Word: ${res.status}`);
}
async extractPDFText(itemId: number): Promise<void> {
const token = await this._getApiToken();
const res = await fetch(`${EXTERNAL_API}/Document/extractPDFText`, {
method: "POST",
headers: {
Authorization: `Bearer ${token}`,
"Content-Type": "application/json",
},
body: JSON.stringify({
siteUrl: this.baseUrl,
libraryName: KP_LIBRARY_DISPLAY_NAME,
itemId: String(itemId),
}),
});
if (!res.ok)
throw new Error(`Ошибка извлечения текста PDF: ${res.status}`);
}
async triggerFlow(
fileName: string,
fileId: number,