From 5eea23daa794a6f244e1956c4d8a5a09d5d51518 Mon Sep 17 00:00:00 2001 From: waltem01 Date: Fri, 15 Mar 2024 08:02:19 +0100 Subject: [PATCH] instruction set types --- Webserver/src/lib/client/httpRequests.ts | 75 ++++++++++++++++++++++++ 1 file changed, 75 insertions(+) diff --git a/Webserver/src/lib/client/httpRequests.ts b/Webserver/src/lib/client/httpRequests.ts index e59d0ad..c1c581e 100644 --- a/Webserver/src/lib/client/httpRequests.ts +++ b/Webserver/src/lib/client/httpRequests.ts @@ -1,5 +1,80 @@ import type { APIResponse } from '$lib/interfaces'; +// Upload instruction type +export interface UploadInstruction { + endpoint: 'upload'; + url: string; +} + +// Image instruction type +export interface ImageInstruction { + endpoint: 'image'; + x: number; + y: number; +} + +// Text instruction type +export interface TextInstruction { + endpoint: 'text'; + content: string; + x: number; + y: number; +} + +// Pixel instruction type +export interface PixelInstruction { + endpoint: 'pixel'; + x: number; + y: number; +} + +// Circle instruction type +export interface CircleInstruction { + endpoint: 'circle'; + x: number; + y: number; + r: number; +} + +// Rectangle instruction type +export interface RectangleInstruction { + endpoint: 'rectangle'; + x: number; + y: number; + w: number; + h: number; +} + +// Line instruction type +export interface LineInstruction { + endpoint: 'line'; + x1: number; + y1: number; + x2: number; + y2: number; +} + +// Color instruction type +export interface ColorInstruction { + endpoint: 'color'; + r: number; + g: number; + b: number; +} + +// Clear instruction type +export interface ClearInstruction { + endpoint: 'clear'; +} + +// Update instruction type +export interface UpdateInstruction { + endpoint: 'update'; +} + +// Define a discriminated union for all possible instruction types +export type Instruction = UploadInstruction | ImageInstruction | TextInstruction | PixelInstruction | CircleInstruction | RectangleInstruction | LineInstruction | ColorInstruction | ClearInstruction | UpdateInstruction; + export async function redirectAPI({ form, fdata }: { form?: HTMLFormElement; fdata?: FormData }) { if (!fdata && form) fdata = new FormData(form); else if (!fdata) throw new Error('No formdata provided!');