Prevents PyTorch/Docling pipeline crashes on HF Spaces CPU by: - Reducing max file size from 50 MB to 5 MB - Adding configurable MAX_PAGE_COUNT setting (env var, default unlimited) - Increasing conversion timeout from 600s to 900s - Adding frontend upload validation with explicit error messages - Exposing maxPageCount via /api/health for dynamic UI hints
65 lines
1.8 KiB
TypeScript
65 lines
1.8 KiB
TypeScript
import { defineStore } from 'pinia'
|
|
import { ref } from 'vue'
|
|
import type { Document } from '../../shared/types'
|
|
import * as api from './api'
|
|
|
|
const MAX_FILE_SIZE = 5 * 1024 * 1024 // 5 MB
|
|
|
|
export const useDocumentStore = defineStore('document', () => {
|
|
const documents = ref<Document[]>([])
|
|
const selectedId = ref<string | null>(null)
|
|
const uploading = ref(false)
|
|
const error = ref<string | null>(null)
|
|
|
|
function clearError(): void {
|
|
error.value = null
|
|
}
|
|
|
|
async function load(): Promise<void> {
|
|
try {
|
|
error.value = null
|
|
documents.value = await api.fetchDocuments()
|
|
} catch (e) {
|
|
error.value = (e as Error).message || 'Failed to load documents'
|
|
console.error('Failed to load documents', e)
|
|
}
|
|
}
|
|
|
|
async function upload(file: File): Promise<Document> {
|
|
if (file.size > MAX_FILE_SIZE) {
|
|
error.value = 'File too large (max 5 MB)'
|
|
throw new Error(error.value)
|
|
}
|
|
uploading.value = true
|
|
error.value = null
|
|
try {
|
|
const doc = await api.uploadDocument(file)
|
|
documents.value.unshift(doc)
|
|
selectedId.value = doc.id
|
|
return doc
|
|
} catch (e) {
|
|
error.value = (e as Error).message || 'Failed to upload document'
|
|
console.error('Failed to upload document', e)
|
|
throw e
|
|
} finally {
|
|
uploading.value = false
|
|
}
|
|
}
|
|
|
|
async function remove(id: string): Promise<void> {
|
|
try {
|
|
await api.deleteDocument(id)
|
|
documents.value = documents.value.filter((d) => d.id !== id)
|
|
if (selectedId.value === id) selectedId.value = null
|
|
} catch (e) {
|
|
error.value = (e as Error).message || 'Failed to delete document'
|
|
console.error('Failed to delete document', e)
|
|
}
|
|
}
|
|
|
|
function select(id: string): void {
|
|
selectedId.value = id
|
|
}
|
|
|
|
return { documents, selectedId, uploading, error, clearError, load, upload, remove, select }
|
|
})
|