690601:0957 ADR-032-232 #03
This commit is contained in:
@@ -197,12 +197,29 @@ export class OcrService {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
/** แปลง local upload path เป็น path ที่ sidecar เห็นผ่าน CIFS mount */
|
/** แปลง local upload path เป็น path ที่ sidecar เห็นผ่าน CIFS/Windows bind mount */
|
||||||
private remapPath(localPath: string): string {
|
private remapPath(localPath: string): string {
|
||||||
if (this.localUploadBase && localPath.startsWith(this.localUploadBase)) {
|
if (!localPath) return localPath;
|
||||||
return localPath.replace(this.localUploadBase, this.sidecarUploadBase);
|
|
||||||
|
// แปลง Windows backslash ให้เป็น forward slash
|
||||||
|
const normalizedPath = localPath.replace(/\\/g, '/');
|
||||||
|
const normalizedLocalBase = this.localUploadBase.replace(/\\/g, '/');
|
||||||
|
|
||||||
|
// ตรวจสอบความเข้ากันได้ของ base path
|
||||||
|
if (normalizedLocalBase && normalizedPath.includes(normalizedLocalBase)) {
|
||||||
|
const relativePart = normalizedPath.substring(
|
||||||
|
normalizedPath.indexOf(normalizedLocalBase) + normalizedLocalBase.length
|
||||||
|
);
|
||||||
|
return `${this.sidecarUploadBase.replace(/\/$/, '')}${relativePart}`;
|
||||||
}
|
}
|
||||||
return localPath;
|
|
||||||
|
// กรณีพิเศษ: ถ้าเป็น Windows Path และมีคำว่า /uploads/ ให้แมปเข้ากับ sidecar base
|
||||||
|
const uploadsIndex = normalizedPath.indexOf('/uploads/');
|
||||||
|
if (uploadsIndex !== -1) {
|
||||||
|
return `${this.sidecarUploadBase.replace(/\/$/, '')}${normalizedPath.substring(uploadsIndex + 8)}`;
|
||||||
|
}
|
||||||
|
|
||||||
|
return normalizedPath;
|
||||||
}
|
}
|
||||||
|
|
||||||
/** ตรวจสอบสุขภาพและ latency ของ OCR sidecar (Tesseract) ผ่าน GET /health */
|
/** ตรวจสอบสุขภาพและ latency ของ OCR sidecar (Tesseract) ผ่าน GET /health */
|
||||||
|
|||||||
@@ -47,12 +47,29 @@ export class SandboxOcrEngineService {
|
|||||||
);
|
);
|
||||||
}
|
}
|
||||||
|
|
||||||
/** แปลง local upload path เป็น path ที่ sidecar เห็นผ่าน CIFS mount */
|
/** แปลง local upload path เป็น path ที่ sidecar เห็นผ่าน CIFS/Windows bind mount */
|
||||||
private remapPath(localPath: string): string {
|
private remapPath(localPath: string): string {
|
||||||
if (this.localUploadBase && localPath.startsWith(this.localUploadBase)) {
|
if (!localPath) return localPath;
|
||||||
return localPath.replace(this.localUploadBase, this.sidecarUploadBase);
|
|
||||||
|
// แปลง Windows backslash ให้เป็น forward slash
|
||||||
|
const normalizedPath = localPath.replace(/\\/g, '/');
|
||||||
|
const normalizedLocalBase = this.localUploadBase.replace(/\\/g, '/');
|
||||||
|
|
||||||
|
// ตรวจสอบความเข้ากันได้ของ base path
|
||||||
|
if (normalizedLocalBase && normalizedPath.includes(normalizedLocalBase)) {
|
||||||
|
const relativePart = normalizedPath.substring(
|
||||||
|
normalizedPath.indexOf(normalizedLocalBase) + normalizedLocalBase.length
|
||||||
|
);
|
||||||
|
return `${this.sidecarUploadBase.replace(/\/$/, '')}${relativePart}`;
|
||||||
}
|
}
|
||||||
return localPath;
|
|
||||||
|
// กรณีพิเศษ: ถ้าเป็น Windows Path และมีคำว่า /uploads/ ให้แมปเข้ากับ sidecar base
|
||||||
|
const uploadsIndex = normalizedPath.indexOf('/uploads/');
|
||||||
|
if (uploadsIndex !== -1) {
|
||||||
|
return `${this.sidecarUploadBase.replace(/\/$/, '')}${normalizedPath.substring(uploadsIndex + 8)}`;
|
||||||
|
}
|
||||||
|
|
||||||
|
return normalizedPath;
|
||||||
}
|
}
|
||||||
|
|
||||||
/** รัน OCR ตาม engine ที่เลือก โดย fallback กลับไป Tesseract baseline เมื่อ Typhoon ล้มเหลว */
|
/** รัน OCR ตาม engine ที่เลือก โดย fallback กลับไป Tesseract baseline เมื่อ Typhoon ล้มเหลว */
|
||||||
|
|||||||
Reference in New Issue
Block a user