This commit is contained in:
parent
cf1a3a7eec
commit
8fdf75019f
1 changed files with 22 additions and 13 deletions
|
@ -3,22 +3,31 @@ import { serve } from 'bun';
|
|||
|
||||
serve({
|
||||
port: 5000,
|
||||
fetch(request) {
|
||||
async fetch(request) {
|
||||
console.log(`${request.method}: ${request.url}`);
|
||||
if (request.method === 'POST') {
|
||||
const url = new URL(request.url);
|
||||
let json;
|
||||
if (url.pathname === '/GetSVGLayoutConfiguration') {
|
||||
json = JSON.stringify(GetSVGLayoutConfiguration());
|
||||
} else if (url.pathname === '/FillHoleWithChassis') {
|
||||
json = JSON.stringify(FillHoleWithChassis(request));
|
||||
} else if (url.pathname === '/SplitRemplissage') {
|
||||
json = JSON.stringify(SplitRemplissage(request));
|
||||
json = GetSVGLayoutConfiguration();
|
||||
} else if (url.pathname === '/ApplicationState') {
|
||||
const bodyParsed = await request.json();
|
||||
console.log(bodyParsed);
|
||||
switch (bodyParsed.Action) {
|
||||
case 'FillHoleWithChassis':
|
||||
json = FillHoleWithChassis(bodyParsed);
|
||||
break;
|
||||
case 'SplitRemplissage':
|
||||
json = SplitRemplissage(bodyParsed);
|
||||
break;
|
||||
default:
|
||||
break;
|
||||
}
|
||||
} else {
|
||||
// TODO: Return 404 rather than this
|
||||
json = JSON.stringify(GetSVGLayoutConfiguration());
|
||||
json = GetSVGLayoutConfiguration();
|
||||
}
|
||||
return new Response(json, {
|
||||
return new Response(JSON.stringify(json), {
|
||||
status: 200,
|
||||
headers: {
|
||||
'Content-Type': 'application/json',
|
||||
|
@ -108,18 +117,18 @@ const GetSVGLayoutConfiguration = () => {
|
|||
|
||||
const FillHoleWithChassis = (request) => {
|
||||
const maxWidthChassis = 3000;
|
||||
const nbChassis = Math.ceil(request.ContainerActions.Width / maxWidthChassis);
|
||||
const nbChassis = Math.ceil(request.ContainerAction.Width / maxWidthChassis);
|
||||
const lstModels = [];
|
||||
for (let i = 0; i <= nbChassis; i++) {
|
||||
if (i === 1 && request.ContainerAction.ExistOnBefore) {
|
||||
lstModels.Add({ Type: 'Dilatation' });
|
||||
lstModels.push({ Type: 'Dilatation' });
|
||||
}
|
||||
lstModels.Add({ Type: 'Chassis' });
|
||||
lstModels.push({ Type: 'Chassis' });
|
||||
if (i < nbChassis) {
|
||||
lstModels.Add({ Type: 'Dilatation' });
|
||||
lstModels.push({ Type: 'Dilatation' });
|
||||
}
|
||||
if (i === nbChassis && request.ContainerAction.ExistOnAfter) {
|
||||
lstModels.Add({ Type: 'Dilatation' });
|
||||
lstModels.push({ Type: 'Dilatation' });
|
||||
}
|
||||
}
|
||||
return {
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue