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({
|
serve({
|
||||||
port: 5000,
|
port: 5000,
|
||||||
fetch(request) {
|
async fetch(request) {
|
||||||
console.log(`${request.method}: ${request.url}`);
|
console.log(`${request.method}: ${request.url}`);
|
||||||
if (request.method === 'POST') {
|
if (request.method === 'POST') {
|
||||||
const url = new URL(request.url);
|
const url = new URL(request.url);
|
||||||
let json;
|
let json;
|
||||||
if (url.pathname === '/GetSVGLayoutConfiguration') {
|
if (url.pathname === '/GetSVGLayoutConfiguration') {
|
||||||
json = JSON.stringify(GetSVGLayoutConfiguration());
|
json = GetSVGLayoutConfiguration();
|
||||||
} else if (url.pathname === '/FillHoleWithChassis') {
|
} else if (url.pathname === '/ApplicationState') {
|
||||||
json = JSON.stringify(FillHoleWithChassis(request));
|
const bodyParsed = await request.json();
|
||||||
} else if (url.pathname === '/SplitRemplissage') {
|
console.log(bodyParsed);
|
||||||
json = JSON.stringify(SplitRemplissage(request));
|
switch (bodyParsed.Action) {
|
||||||
|
case 'FillHoleWithChassis':
|
||||||
|
json = FillHoleWithChassis(bodyParsed);
|
||||||
|
break;
|
||||||
|
case 'SplitRemplissage':
|
||||||
|
json = SplitRemplissage(bodyParsed);
|
||||||
|
break;
|
||||||
|
default:
|
||||||
|
break;
|
||||||
|
}
|
||||||
} else {
|
} else {
|
||||||
// TODO: Return 404 rather than this
|
// TODO: Return 404 rather than this
|
||||||
json = JSON.stringify(GetSVGLayoutConfiguration());
|
json = GetSVGLayoutConfiguration();
|
||||||
}
|
}
|
||||||
return new Response(json, {
|
return new Response(JSON.stringify(json), {
|
||||||
status: 200,
|
status: 200,
|
||||||
headers: {
|
headers: {
|
||||||
'Content-Type': 'application/json',
|
'Content-Type': 'application/json',
|
||||||
|
@ -108,18 +117,18 @@ const GetSVGLayoutConfiguration = () => {
|
||||||
|
|
||||||
const FillHoleWithChassis = (request) => {
|
const FillHoleWithChassis = (request) => {
|
||||||
const maxWidthChassis = 3000;
|
const maxWidthChassis = 3000;
|
||||||
const nbChassis = Math.ceil(request.ContainerActions.Width / maxWidthChassis);
|
const nbChassis = Math.ceil(request.ContainerAction.Width / maxWidthChassis);
|
||||||
const lstModels = [];
|
const lstModels = [];
|
||||||
for (let i = 0; i <= nbChassis; i++) {
|
for (let i = 0; i <= nbChassis; i++) {
|
||||||
if (i === 1 && request.ContainerAction.ExistOnBefore) {
|
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) {
|
if (i < nbChassis) {
|
||||||
lstModels.Add({ Type: 'Dilatation' });
|
lstModels.push({ Type: 'Dilatation' });
|
||||||
}
|
}
|
||||||
if (i === nbChassis && request.ContainerAction.ExistOnAfter) {
|
if (i === nbChassis && request.ContainerAction.ExistOnAfter) {
|
||||||
lstModels.Add({ Type: 'Dilatation' });
|
lstModels.push({ Type: 'Dilatation' });
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
return {
|
return {
|
||||||
|
|
Loading…
Add table
Add a link
Reference in a new issue