feat(config): add OCR URL configuration and improve image node handling
- Add VITE_OCR_URL environment variable with fallback URL construction - Define IMAGE_NODE_TYPES constant to support 'image', 'image-block', and 'imageBlock' node types - Add helper functions for safer image attribute access (getImageSrc, isImageNodeWithSrc, getImageLabel) - Improve OCR error handling with HTTP status checking and error details - Wrap OCR context in HTML comments to prevent prompt injection issues - Update MilkdownEditor to use centralized OCR_URL configuration
This commit is contained in:
@@ -1,2 +1,18 @@
|
||||
export const DEBUG = import.meta.env.DEV
|
||||
export const API_URL = import.meta.env.VITE_API_URL || 'http://localhost:8000/v1/completions'
|
||||
|
||||
const buildDefaultOcrUrl = (apiUrl) => {
|
||||
if (typeof window === 'undefined') {
|
||||
return 'http://localhost:8000/v1/ocr'
|
||||
}
|
||||
|
||||
try {
|
||||
const url = new URL(apiUrl, window.location.origin)
|
||||
url.pathname = '/v1/ocr'
|
||||
return url.toString()
|
||||
} catch {
|
||||
return 'http://localhost:8000/v1/ocr'
|
||||
}
|
||||
}
|
||||
|
||||
export const OCR_URL = import.meta.env.VITE_OCR_URL || buildDefaultOcrUrl(API_URL)
|
||||
|
||||
Reference in New Issue
Block a user