mirror of
https://gitlab1.ptb.de/waltem01/Matrix
synced 2024-12-25 03:31:44 +00:00
instruction set types
This commit is contained in:
parent
c6907466ef
commit
5eea23daa7
@ -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!');
|
||||
|
Loading…
Reference in New Issue
Block a user