texte buttons änderungen an sensoren

This commit is contained in:
marco committed 2026-10-28 16:30:59 +01:00
1 parent edbf560e22
commit 58338ee07c
53 files changed
+1290 -141

No files matched your search

+38
View File
@@ -0,0 +1,38 @@
'use server';
import { revalidatePath } from 'next/cache';
import type { TextTable, TextComparison } from '@/types/texte';
const url = 'http://localhost:3000/rk2/texte';
async function request(init?: RequestInit): Promise<TextTable> {
const response = await fetch(url, { cache: 'no-store', ...init });
const data = await response.json();
if (!response.ok) throw new Error(Array.isArray(data.message) ? data.message.join(', ') : data.message ?? 'Texte konnten nicht geladen werden.');
return data;
}
export async function api_texte() { return request(); }
export async function api_cleanupTexts(anlageId: string, version: number): Promise<{ deleted: number; unused: number; duplicates: number; kept: number }> {
const response = await fetch(url + '/cleanup', { method: 'POST', cache: 'no-store', headers: { 'Content-Type': 'application/json' }, body: JSON.stringify({ anlageId, version }) });
const result = await response.json();
if (!response.ok) throw new Error(Array.isArray(result.message) ? result.message.join(', ') : result.message ?? 'Textbereinigung fehlgeschlagen');
revalidatePath('/texte'); revalidatePath('/procon/positionen'); revalidatePath('/visualisierung');
return result;
}
export async function api_compareText(id: string): Promise<TextComparison> {
const response = await fetch(url + '/' + encodeURIComponent(id) + '/sync', { cache: 'no-store' });
const result = await response.json();
if (!response.ok) throw new Error(Array.isArray(result.message) ? result.message.join(', ') : result.message ?? 'Vergleich fehlgeschlagen');
return result;
}
export async function api_syncText(id: string, input: Pick<TextComparison, 'anlageId' | 'verbindungId' | 'version'> & {
direction: 'toLocal' | 'toProcon'; fields: boolean; layout: boolean;
}): Promise<TextTable> {
const response = await fetch(url + '/' + encodeURIComponent(id) + '/sync', { method: 'POST', cache: 'no-store', headers: { 'Content-Type': 'application/json' }, body: JSON.stringify(input) });
const result = await response.json();
if (!response.ok) throw new Error(Array.isArray(result.message) ? result.message.join(', ') : result.message ?? 'Synchronisierung fehlgeschlagen');
revalidatePath('/texte'); revalidatePath('/visualisierung'); return result;
}
export async function api_saveTexts(table: TextTable) {
const body = JSON.stringify(table);
if (new TextEncoder().encode(body).length > 9 * 1024 * 1024) throw new Error('Die Tabelle ist zu groß (maximal 9 MB).');
const saved = await request({ method: 'PUT', headers: { 'Content-Type': 'application/json' }, body });
revalidatePath('/texte'); return saved;
}