alexander add env
This commit is contained in:
parent
50d0c4c12b
commit
b5750b12ef
12 changed files with 301 additions and 40 deletions
|
@ -29,6 +29,10 @@ export abstract class CallbackStrategyWithFileUpload {
|
|||
abstract idValidationExpression: CoreValidation;
|
||||
abstract call(file: File, id: string): ResponseBase;
|
||||
}
|
||||
export abstract class CallbackStrategyWithFilesUploads {
|
||||
abstract chuckingFileExpressions: RegExp[];
|
||||
abstract call(files: File[]): ResponseBase;
|
||||
}
|
||||
|
||||
interface ISubSetFeatureRouter<T> {
|
||||
method: HttpMethodType;
|
||||
|
@ -38,7 +42,8 @@ interface ISubSetFeatureRouter<T> {
|
|||
| CallbackStrategyWithEmpty
|
||||
| CallbackStrategyWithIdQuery
|
||||
| CallBackStrategyWithQueryPage
|
||||
| CallbackStrategyWithFileUpload;
|
||||
| CallbackStrategyWithFileUpload
|
||||
| CallbackStrategyWithFilesUploads;
|
||||
}
|
||||
|
||||
abstract class ICoreHttpController {
|
||||
|
@ -105,6 +110,7 @@ export class CoreHttpController<V> implements ICoreHttpController {
|
|||
await this.responseHelper(res, el.fn.call(req["files"]["file"]));
|
||||
}
|
||||
}
|
||||
|
||||
if (el.fn instanceof CallBackStrategyWithQueryPage) {
|
||||
throw Error("needs to be implimed");
|
||||
}
|
||||
|
@ -112,7 +118,7 @@ export class CoreHttpController<V> implements ICoreHttpController {
|
|||
await this.responseHelper(res, el.fn.call());
|
||||
return;
|
||||
}
|
||||
|
||||
|
||||
if (el.fn instanceof CallbackStrategyWithFileUpload) {
|
||||
if (req["files"] === undefined) {
|
||||
res.status(400).json("need files to form-data request");
|
||||
|
@ -143,6 +149,7 @@ export class CoreHttpController<V> implements ICoreHttpController {
|
|||
return;
|
||||
}
|
||||
}
|
||||
|
||||
await this.responseHelper(res, el.fn.call(req["files"]["file"], req.query.id));
|
||||
}
|
||||
});
|
||||
|
|
|
@ -0,0 +1,61 @@
|
|||
import { CallbackStrategyWithFilesUploads, ResponseBase } from "../../../core/controllers/http_controller";
|
||||
import { Result } from "../../../core/helpers/result";
|
||||
import { CreateFileUseCase } from "../../../core/usecases/create_file_usecase";
|
||||
import { ReadFileAndParseJsonUseCase } from "../../../core/usecases/read_file_and_parse_json";
|
||||
export interface Parts {
|
||||
name: string;
|
||||
part_path: string;
|
||||
material_path: string;
|
||||
mass: number;
|
||||
inertia: {
|
||||
ixx: number;
|
||||
ixy: number;
|
||||
ixz: number;
|
||||
iyy: number;
|
||||
iyz: number;
|
||||
izz: number;
|
||||
};
|
||||
visual: string;
|
||||
collision: string;
|
||||
type: string;
|
||||
}
|
||||
export class UploadNewEnvScenario {
|
||||
call = async (
|
||||
files: { name: string; file?: Buffer }[],
|
||||
name: string,
|
||||
inertia: number,
|
||||
mass: number,
|
||||
projectPath: string
|
||||
): ResponseBase => {
|
||||
await files.map(
|
||||
async (el) => await new CreateFileUseCase().call(projectPath + `/assets/libs/objects/${name}.${el.name}`, el.file)
|
||||
);
|
||||
// "part_path": "parts/objects/body_down.stl",
|
||||
await new CreateFileUseCase().call(
|
||||
projectPath + `/parts/objects/${name}.${files.find((el) => el.name.isEqual("stl")).name}`,
|
||||
files.find((el) => el.name.isEqual("stl")).file
|
||||
);
|
||||
return (await new ReadFileAndParseJsonUseCase().call<Parts[]>(projectPath + "/assets/parts.json")).map(
|
||||
async (el) => {
|
||||
el.push({
|
||||
name,
|
||||
inertia: {
|
||||
ixx: 0.1,
|
||||
ixy: 0,
|
||||
ixz: 0,
|
||||
iyy: 0.1,
|
||||
iyz: 0,
|
||||
izz: 0.1,
|
||||
},
|
||||
mass,
|
||||
visual: `/assets/libs/objects/${name}.dae`,
|
||||
collision: `/assets/libs/objects/${name}.stl`,
|
||||
type: "env",
|
||||
material_path: "",
|
||||
part_path: `/libs/objects/${name}.stl`,
|
||||
});
|
||||
await new CreateFileUseCase().call(projectPath + "/assets/parts.json", Buffer.from(JSON.stringify(el), "utf8"));
|
||||
}
|
||||
);
|
||||
};
|
||||
}
|
|
@ -1,11 +1,13 @@
|
|||
import { CrudController } from "../../core/controllers/crud_controller";
|
||||
import { CreateNewProjectInstanceScenario, ProjectValidationModel } from "./domain/create_new_project_scenario";
|
||||
import { SearchManyDataBaseModelUseCase } from "../../core/usecases/search_many_database_model_usecase";
|
||||
import { CreateNewProjectInstanceScenario, ProjectValidationModel } from "./domain/create_new_project_scenario";
|
||||
import { GetActiveProjectIdScenario } from "./domain/get_active_project_id_scenario";
|
||||
import { RobossemblerAssetsNetworkMapperScenario } from "./domain/robossembler_assets_network_mapper_scenario";
|
||||
import { SetActiveProjectScenario } from "./domain/set_active_project_use_scenario";
|
||||
import { UploadCadFileToProjectScenario } from "./domain/upload_file_to_to_project_scenario";
|
||||
import { ProjectDBModel } from "./models/project_model_database_model";
|
||||
|
||||
import { UploadNewEnvScenario } from "./domain/upload_new_env_scenario";
|
||||
import { IProjectModel, ProjectDBModel } from "./models/project_model_database_model";
|
||||
|
||||
export class ProjectsPresentation extends CrudController<ProjectValidationModel, typeof ProjectDBModel> {
|
||||
constructor() {
|
||||
super({
|
||||
|
@ -37,6 +39,42 @@ export class ProjectsPresentation extends CrudController<ProjectValidationModel,
|
|||
subUrl: "assets",
|
||||
fn: new RobossemblerAssetsNetworkMapperScenario(),
|
||||
});
|
||||
|
||||
// this.subRoutes.push({
|
||||
// method: "POST",
|
||||
// subUrl: "upload/env",
|
||||
// fn: new UploadNewEnvScenario(),
|
||||
// });
|
||||
this.router.post("/projects/upload/env", async (req, res) => {
|
||||
try {
|
||||
} catch (error) {}
|
||||
(
|
||||
await new SearchManyDataBaseModelUseCase<IProjectModel>(ProjectDBModel).call(
|
||||
{ isActive: true },
|
||||
"is dont active projects"
|
||||
)
|
||||
).map(async (projectModel) => {
|
||||
const { rootDir } = projectModel[0];
|
||||
const files: { name: string; file?: Buffer }[] = [
|
||||
{ name: "blend" },
|
||||
{ name: "fbx" },
|
||||
{ name: "ply" },
|
||||
{ name: "glb" },
|
||||
{ name: "dae" },
|
||||
{ name: "fbx" },
|
||||
{ name: "png" },
|
||||
{ name: "stl" },
|
||||
];
|
||||
// @ts-ignore
|
||||
const reqFiles = req.files;
|
||||
|
||||
files.forEach((el) => {
|
||||
reqFiles[el.name].data;
|
||||
el.file = reqFiles[el.name].data;
|
||||
});
|
||||
|
||||
await new UploadNewEnvScenario().call(files, req.body.name, req.body.inertia, req.body.mass, rootDir);
|
||||
return res.status(200).json("");
|
||||
});
|
||||
});
|
||||
}
|
||||
}
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue