Objekte direkt in Directus speichern + neuer Annotationsworkflow
- DirectusObject Typ + CanvasObject Interface in types.ts - DrawCanvas nutzt CanvasObject (generisch, nicht mehr ObjectMeta-gebunden) - Flask: /api/directus/objects (GET/POST), /api/directus/objects/<id> (PATCH/DELETE) - Flask: /api/directus/setup-m2m (einmalig: m2m für categories/questions) - api.ts: getDirectusObjects, createDirectusObject, updateDirectusObject, deleteDirectusObject - DrawIt: Objekte werden in Directus gespeichert (mit picture, bbox/polygon, user_notes, parent) - DrawIt: Linke Sidebar zeigt Objektliste mit Notizen-Editor und Löschen-Button - DrawIt: Rechte Sidebar: Modus, user_notes Textarea, Parent-Dropdown, Auswahlen - Directus: user_notes Feld (textarea), action/resolution/confidence/media versteckt Co-Authored-By: Claude Sonnet 4.6 <noreply@anthropic.com>
This commit is contained in:
@@ -32,6 +32,57 @@ export function directusAssetUrl(mediaId: string, token: string): string {
|
||||
return `${DIRECTUS_URL}/assets/${mediaId}?access_token=${token}`
|
||||
}
|
||||
|
||||
import type { DirectusObject, BBox, Point } from './types'
|
||||
|
||||
export async function getDirectusObjects(pictureId: string, token: string): Promise<DirectusObject[]> {
|
||||
const res = await fetch(`/api/directus/objects?picture_id=${pictureId}`, {
|
||||
headers: { Authorization: `Bearer ${token}` },
|
||||
})
|
||||
if (!res.ok) throw new Error('Fehler beim Laden der Objekte')
|
||||
const data = await res.json()
|
||||
return data.data as DirectusObject[]
|
||||
}
|
||||
|
||||
export async function createDirectusObject(payload: {
|
||||
picture: string
|
||||
bbox: BBox | null
|
||||
polygon: Point[] | null
|
||||
user_notes: string | null
|
||||
parent: string | null
|
||||
}, token: string): Promise<DirectusObject> {
|
||||
const res = await fetch('/api/directus/objects', {
|
||||
method: 'POST',
|
||||
headers: { 'Content-Type': 'application/json', Authorization: `Bearer ${token}` },
|
||||
body: JSON.stringify({ ...payload, status: 'draft' }),
|
||||
})
|
||||
const data = await res.json()
|
||||
if (!res.ok) throw new Error(data.errors?.[0]?.message || 'Fehler beim Speichern')
|
||||
return data.data as DirectusObject
|
||||
}
|
||||
|
||||
export async function updateDirectusObject(
|
||||
objId: string,
|
||||
payload: Partial<Pick<DirectusObject, 'user_notes' | 'parent'>>,
|
||||
token: string
|
||||
): Promise<DirectusObject> {
|
||||
const res = await fetch(`/api/directus/objects/${objId}`, {
|
||||
method: 'PATCH',
|
||||
headers: { 'Content-Type': 'application/json', Authorization: `Bearer ${token}` },
|
||||
body: JSON.stringify(payload),
|
||||
})
|
||||
const data = await res.json()
|
||||
if (!res.ok) throw new Error(data.errors?.[0]?.message || 'Fehler beim Aktualisieren')
|
||||
return data.data as DirectusObject
|
||||
}
|
||||
|
||||
export async function deleteDirectusObject(objId: string, token: string): Promise<void> {
|
||||
const res = await fetch(`/api/directus/objects/${objId}`, {
|
||||
method: 'DELETE',
|
||||
headers: { Authorization: `Bearer ${token}` },
|
||||
})
|
||||
if (!res.ok) throw new Error('Fehler beim Löschen')
|
||||
}
|
||||
|
||||
export async function getImages(mode: 'draw' | 'generate'): Promise<string[]> {
|
||||
const res = await fetch(`/api/images?mode=${mode}`)
|
||||
if (!res.ok) throw new Error('Fehler beim Laden der Bilder')
|
||||
|
||||
Reference in New Issue
Block a user