This commit is contained in:
IDONTSUDO 2024-06-19 15:23:01 +03:00
parent 53fe9bf51a
commit 81238c5182
74 changed files with 8646 additions and 52 deletions

View file

@ -21,3 +21,4 @@ export class RobossemblerAssets {
return this;
}
}

View file

@ -1,4 +1,5 @@
export enum StaticFiles {
robossembler_assets = "robossembler_assets.json",
assets = "/assets/assets.json",
parts = '/assets/parts.json'
}

View file

@ -2,11 +2,9 @@ import { Result } from "../helpers/result";
import { FileSystemRepository } from "../repository/file_system_repository";
export class ReadFileAndParseJsonUseCase {
fileSystemRepository: FileSystemRepository;
fileSystemRepository: FileSystemRepository = new FileSystemRepository();
constructor() {
this.fileSystemRepository = new FileSystemRepository();
}
async call<T>(path: string): Promise<Result<string, T>> {
try {
if (RegExp(path).test("^(.+)/([^/]+)$")) {

View file

@ -3,7 +3,7 @@ import { Result } from "../../../core/helpers/result";
import { SearchOneDataBaseModelUseCase } from "../../../core/usecases/search_database_model_usecase";
import { IProjectModel, ProjectDBModel } from "../models/project_model_database_model";
export class GetActiveProjectScenario extends CallbackStrategyWithEmpty {
export class GetActiveProjectIdScenario extends CallbackStrategyWithEmpty {
async call(): Promise<Result<any, { id: string }>> {
return (
await new SearchOneDataBaseModelUseCase<IProjectModel>(ProjectDBModel).call({ isActive: true }, "no active projects")

View file

@ -1,33 +1,34 @@
import { CallbackStrategyWithEmpty, ResponseBase } from "../../../core/controllers/http_controller";
import { Result } from "../../../core/helpers/result";
import { RobossemblerAssets } from "../../../core/models/robossembler_assets";
import { StaticFiles } from "../../../core/models/static_files";
import { ReadingJsonFileAndConvertingToInstanceClassScenario } from "../../../core/scenarios/read_file_and_json_to_plain_instance_class_scenario";
import { GetServerAddressUseCase } from "../../../core/usecases/get_server_address_usecase";
import { ProjectDBModel } from "../models/project_model_database_model";
import { ReadFileAndParseJsonUseCase } from "../../../core/usecases/read_file_and_parse_json";
import { SearchManyDataBaseModelUseCase } from "../../../core/usecases/search_many_database_model_usecase";
import { IProjectModel, ProjectDBModel } from "../models/project_model_database_model";
export interface Parts {
name: string;
part_path: string;
material_path: string;
httpUrl?: string;
}
export class RobossemblerAssetsNetworkMapperScenario extends CallbackStrategyWithEmpty {
async call(): ResponseBase {
const projectDbModel = await ProjectDBModel.findOne({ isActive: true });
if (projectDbModel === null) {
return Result.error("is dont active projects");
}
const { rootDir } = projectDbModel;
call = async (): ResponseBase => (await new SearchManyDataBaseModelUseCase<IProjectModel>(ProjectDBModel).call({ isActive: true }, 'is dont active projects')).map((projectModel) => {
const { rootDir } = projectModel[0];
return new GetServerAddressUseCase().call().map(async (address) =>
(
await new ReadingJsonFileAndConvertingToInstanceClassScenario<RobossemblerAssets>(RobossemblerAssets).call(
rootDir + StaticFiles.assets
await new ReadFileAndParseJsonUseCase().call<Parts[]>(
rootDir + StaticFiles.parts
)
).map((model) => {
return Result.ok(
model.convertLocalPathsToServerPaths(
`${address}/${
rootDir.match(new RegExp(/[0-9a-f]{8}-[0-9a-f]{4}-[0-9a-f]{4}-[0-9a-f]{4}-[0-9a-f]{12}/gm))[0]
}/assets`
)
);
model.map((el) => {
el.httpUrl = address + '/' + rootDir.match(new RegExp(/[0-9a-f]{8}-[0-9a-f]{4}-[0-9a-f]{4}-[0-9a-f]{4}-[0-9a-f]{12}/gm))[0] + '/assets/libs/objects/' + el.name + '.glb'
// server/build/public/0ddbb777-8002-4424-a3b0-d869783cca97/assets/libs/objects/planet_gear.glb
return el
})
return Result.ok(model);
})
);
}
})
}

View file

@ -1,6 +1,6 @@
import { CrudController } from "../../core/controllers/crud_controller";
import { CreateNewProjectInstanceScenario, ProjectValidationModel } from "./domain/create_new_project_scenario";
import { GetActiveProjectScenario } from "./domain/get_active_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";
@ -21,10 +21,11 @@ export class ProjectsPresentation extends CrudController<ProjectValidationModel,
subUrl: "set/active/project",
fn: new SetActiveProjectScenario(),
});
this.subRoutes.push({
method: "GET",
subUrl: "get/active/project/id",
fn: new GetActiveProjectScenario(),
fn: new GetActiveProjectIdScenario(),
});
this.subRoutes.push({
method: "POST",
@ -36,5 +37,6 @@ export class ProjectsPresentation extends CrudController<ProjectValidationModel,
subUrl: "assets",
fn: new RobossemblerAssetsNetworkMapperScenario(),
});
}
}

View file

@ -1,11 +1,11 @@
import { ResponseBase } from "../../../core/controllers/http_controller";
import { SearchManyDataBaseModelUseCase } from "../../../core/usecases/search_many_database_model_usecase";
import { GetActiveProjectScenario } from "../../projects/domain/get_active_project_scenario";
import { GetActiveProjectIdScenario } from "../../projects/domain/get_active_project_id_scenario";
import { IWeightModel, WeightDBModel } from "../models/weights_validation_model";
export class GetAllWeightsActiveProjectScenarios {
call = async (): ResponseBase =>
(await new GetActiveProjectScenario().call()).map(
(await new GetActiveProjectIdScenario().call()).map(
async (model) => await new SearchManyDataBaseModelUseCase<IWeightModel>(WeightDBModel).call({ project: model.id })
);
}