mirror of
https://github.com/CherryHQ/cherry-studio.git
synced 2025-12-31 08:29:07 +08:00
feat(ocr): add api schemas and handlers for ocr providers
Implement API schemas and handlers for OCR providers endpoints Add TODO comments for future migration tasks Fix endpoint path in OcrImageSettings component
This commit is contained in:
parent
d366ec5932
commit
c780552197
@ -1,5 +1,7 @@
|
||||
// NOTE: Types are defined inline in the schema for simplicity
|
||||
// If needed, specific types can be imported from './apiModels'
|
||||
import type { OcrProvider } from '@types'
|
||||
|
||||
import type { BodyForPath, ConcreteApiPaths, QueryParamsForPath, ResponseForPath } from './apiPaths'
|
||||
import type { HttpMethod, PaginatedResponse, PaginationParams } from './apiTypes'
|
||||
|
||||
@ -345,6 +347,32 @@ export interface ApiSchemas {
|
||||
}>
|
||||
}
|
||||
}
|
||||
|
||||
'/ocr/providers': {
|
||||
GET: {
|
||||
response: OcrProvider[]
|
||||
}
|
||||
POST: {
|
||||
body: {
|
||||
// TODO
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
'/ocr/providers/:id': {
|
||||
GET: {
|
||||
response: OcrProvider
|
||||
}
|
||||
PATCH: {
|
||||
// TODO
|
||||
}
|
||||
PUT: {
|
||||
// TODO
|
||||
}
|
||||
DELETE: {
|
||||
// TODO
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
|
||||
@ -12,6 +12,7 @@ import { TestService } from '../services/TestService'
|
||||
// Service instances
|
||||
const testService = TestService.getInstance()
|
||||
|
||||
// Defining all handlers here feels a bit bloated; perhaps we should modularize things?
|
||||
/**
|
||||
* Complete API handlers implementation
|
||||
* Must implement every path+method combination from ApiSchemas
|
||||
@ -207,5 +208,31 @@ export const apiHandlers: ApiImplementation = {
|
||||
data: { executed: true, timestamp: new Date().toISOString() }
|
||||
}))
|
||||
}
|
||||
},
|
||||
|
||||
'/ocr/providers': {
|
||||
GET: async () => {
|
||||
// We should implement it when user data migration completed.
|
||||
// OcrProvider should be migrate to db, because the data objects contains user settings.
|
||||
throw new Error('Not implemented')
|
||||
},
|
||||
POST: async () => {
|
||||
throw new Error('Not implemented')
|
||||
}
|
||||
},
|
||||
|
||||
'/ocr/providers/:id': {
|
||||
GET: async () => {
|
||||
throw new Error('Not implemented')
|
||||
},
|
||||
PATCH: async () => {
|
||||
throw new Error('Not implemented')
|
||||
},
|
||||
PUT: async () => {
|
||||
throw new Error('Not implemented')
|
||||
},
|
||||
DELETE: async () => {
|
||||
throw new Error('Not implemented')
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
@ -18,6 +18,7 @@ import { useDispatch } from 'react-redux'
|
||||
const logger = loggerService.withContext('useOcrProvider')
|
||||
|
||||
export const useOcrProviders = () => {
|
||||
// TODO: migrate to useQuery
|
||||
const providers = useAppSelector((state) => state.ocr.providers)
|
||||
const imageProviders = providers.filter(isImageOcrProvider)
|
||||
const [imageProviderId, setImageProviderId] = usePreference('ocr.settings.image_provider_id')
|
||||
|
||||
@ -22,7 +22,7 @@ const OcrImageSettings = () => {
|
||||
return window.api.ocr.listProviders()
|
||||
}, [])
|
||||
|
||||
const { data: validProviders, isLoading, error } = useSWRImmutable('ocr/providers', fetcher)
|
||||
const { data: validProviders, isLoading, error } = useSWRImmutable('/ocr/providers', fetcher)
|
||||
|
||||
const imageProviders = providers.filter((p) => isImageOcrProvider(p))
|
||||
|
||||
|
||||
Loading…
Reference in New Issue
Block a user