diff --git a/src/app.ts b/src/app.ts index 7dd4964..35e6dca 100644 --- a/src/app.ts +++ b/src/app.ts @@ -1,7 +1,6 @@ import express from "express"; - import routes from "./routes/routes"; -import minecraft_routes from "./routes/minecraft/minecraft_routes"; +import minecraft_routes from "./routes/public/minecraft/minecraft_routes"; class App { public server; diff --git a/src/minecraft/1.12.2/minecraft_distribution.ts b/src/minecraft/1.12.2/minecraft_distribution.ts deleted file mode 100644 index 5fb6f1f..0000000 --- a/src/minecraft/1.12.2/minecraft_distribution.ts +++ /dev/null @@ -1,3 +0,0 @@ -import { IMinecraftServer } from './helios_distribution' - -export Min \ No newline at end of file diff --git a/src/minecraft/1.12.2/helios_distribution.ts b/src/modules/minecraft/1.12.2/helios_distribution.ts similarity index 56% rename from src/minecraft/1.12.2/helios_distribution.ts rename to src/modules/minecraft/1.12.2/helios_distribution.ts index 9da2d62..1aef7b7 100644 --- a/src/minecraft/1.12.2/helios_distribution.ts +++ b/src/modules/minecraft/1.12.2/helios_distribution.ts @@ -1,7 +1,9 @@ +import { type } from "os" import internal from "stream" import { Url } from "url" +//import {mongoose} from "mongoose" -interface HeliosDistribution{ +export interface IHeliosDistribution{ version:string //servers:Minecraft_1_12_2_server } @@ -13,20 +15,20 @@ export interface IMinecraftServer{ icon:string version:string address:string - /*minecraftVersion:string - mainServer:boolean - autoconnect:boolean - share_required_mods:ForgeMod[] - client_required_mods:ForgeMod[] - client_optional_mods:ForgeMod[]*/ + minecraftVersion:string + // mainServer:boolean + // autoconnect:boolean + share_required_mods:IForgeMod[] + // client_required_mods:ForgeMod[] + // client_optional_mods:ForgeMod[] } -interface ForgeMod{ +export interface IForgeMod{ id:ForgeModId name:string type:string artifact:ForgeModArtifact - sub_modules:ForgeMod[] + sub_modules:IForgeMod[] } interface ForgeModId{ @@ -41,6 +43,4 @@ interface ForgeModArtifact{ url:Url } -export default HeliosDistribution{ - -} \ No newline at end of file +export type ForgeMod = IForgeMod diff --git a/src/modules/minecraft/1.12.2/minecraft_distribution.ts b/src/modules/minecraft/1.12.2/minecraft_distribution.ts new file mode 100644 index 0000000..fbce14e --- /dev/null +++ b/src/modules/minecraft/1.12.2/minecraft_distribution.ts @@ -0,0 +1,54 @@ +import {IHeliosDistribution, IMinecraftServer} from "./helios_distribution" +import { Schema, model, connect, Model } from 'mongoose'; + +const SolFileSchema = new Schema({ + id:{ type: String, required: true } + }) + +const minecraftServerSchema = new Schema({ + id: { type: String, required: true }, + name: { type: String, required: true }, + description: { type: String, required: true }, + icon: { type: String, required: true }, + minecraftVersion: { type: String, required: true }, + address: { type: String, required: true }, + share_required_mods:[ SolFileSchema ] + }); + +const MinecraftServer = model('Server', minecraftServerSchema) + +export default class Minecraft{ + constructor(){ + this.getDistribution = this.getDistribution.bind(this) + } + + public async getDistribution(){ + var servers_string = {id:"asd"} + await connect('mongodb://172.17.0.2:27017/minecraft'); + + var servers = await MinecraftServer.find() + console.log(servers) + servers_string = servers[0].toObject() + return servers_string + } + + public async writeServer(){ + await connect('mongodb://172.17.0.2:27017/minecraft'); + const newSrv = new MinecraftServer({ + id: 'kek', + name: 'shmek', + description: 'omg', + icon: 'asldka;lskd', + minecraftVersion: '1.12.2', + address: '123465', + }) + await newSrv.save() + } + + private async getServers(): Promise{ + var servers:IMinecraftServer[] = [] + await connect('mongodb://172.17.0.2:27017/minecraft'); + return servers + } +} + diff --git a/src/modules/mongoose/db_connect.ts b/src/modules/mongoose/db_connect.ts new file mode 100644 index 0000000..f8658a8 --- /dev/null +++ b/src/modules/mongoose/db_connect.ts @@ -0,0 +1,51 @@ +import { url } from 'inspector'; +import { Schema, model, connect } from 'mongoose'; +import { IMinecraftServer, IForgeMod } from "../minecraft/1.12.2/helios_distribution" + +const forgeModSchema = new Schema({ + id:{type: String, required: true} +}) + +// 2. Create a Schema corresponding to the document interface. +const serverSchema = new Schema({ + id: { type: String, required: true }, + name: { type: String, required: true }, + description: { type: String, required: true }, + icon: { type: String, required: true }, + minecraftVersion: { type: String, required: true }, + address: { type: String, required: true }, + share_required_mods: forgeModSchema +}); + + + +// 3. Create a Model. +const Server = model('helios', serverSchema); + +async function run() { + // 4. Connect to MongoDB + await connect('mongodb://172.17.0.2:27017/minecraft'); + + const server = new Server({ + id:"WesterosCraft-1.12.2", + name:"WesterosCraft 1.12.2 Production Server", + description:"New 1.12.2 production server.", + icon:"http://mc.westeroscraft.com/WesterosCraftLauncher/files/server-prod.png", + version:"4.6.5", + address:"mc.westeroscraft.com:25565", + minecraftVersion:"1.12.2", + }); + await server.save(); +} + +export default class GetMinecraftServers +{ + constructor(){ + this.writeTestModel = this.writeTestModel.bind(this) + } + + public writeTestModel(){ + run() + } + +} \ No newline at end of file diff --git a/src/mongoose/db_connect.ts b/src/mongoose/db_connect.ts deleted file mode 100644 index baf2f88..0000000 --- a/src/mongoose/db_connect.ts +++ /dev/null @@ -1,44 +0,0 @@ -import { Schema, model, connect } from 'mongoose'; - -// 1. Create an interface representing a document in MongoDB. -interface IUser { - name: string; - email: string; - avatar?: string; -} - -// 2. Create a Schema corresponding to the document interface. -const userSchema = new Schema({ - name: { type: String, required: true }, - email: { type: String, required: true }, - avatar: String -}); - -// 3. Create a Model. -const User = model('User', userSchema); - -async function run() { - // 4. Connect to MongoDB - await connect('mongodb://172.17.0.2:27017/test'); - - const user = new User({ - name: 'Bill', - email: 'bill@initech.com', - avatar: 'https://i.imgur.com/dM7Thhn.png' - }); - await user.save(); - - console.log(user.email); // 'bill@initech.com' -} - -export default class GetMinecraftServers -{ - constructor(){ - this.writeTestModel = this.writeTestModel.bind(this) - } - - public writeTestModel(){ - run() - } - -} \ No newline at end of file diff --git a/src/routes/minecraft/1_12_2/routes.ts b/src/routes/minecraft/1_12_2/routes.ts deleted file mode 100644 index ee8000c..0000000 --- a/src/routes/minecraft/1_12_2/routes.ts +++ /dev/null @@ -1,23 +0,0 @@ -import { Router } from "express"; -import Minecraft from "../../../minecraft/1.12.2/helios_distribution" - -import GetMinecraftServers from "../../../mongoose/db_connect" - -const minecraft = new Minecraft //Is this right? -const routes = Router(); -const test_db = new GetMinecraftServers -routes.get("/", (req, res) => { - return res.json({ message: "yes" }); -}); - -routes.get("/distribution", (req, res) =>{ - res.send(minecraft.generateDistribution()) -}); - -routes.get("/test", (req, res) =>{ - res.send(test_db.writeTestModel()) -}); - -export default routes; - - diff --git a/src/routes/minecraft/minecraft_routes.ts b/src/routes/minecraft/minecraft_routes.ts deleted file mode 100644 index dd5cf46..0000000 --- a/src/routes/minecraft/minecraft_routes.ts +++ /dev/null @@ -1,11 +0,0 @@ -import { Router } from "express"; -import minecraft_1_12_2_routes from './1_12_2/routes' - -const routes = Router(); - -routes.get("/", (req, res) => { - return res.json({ message: "Hello World" }); -}); -routes.use -routes.use('/1.12.2', minecraft_1_12_2_routes) -export default routes; diff --git a/src/routes/public/minecraft/1_12_2/routes.ts b/src/routes/public/minecraft/1_12_2/routes.ts index eb24ab8..617093e 100644 --- a/src/routes/public/minecraft/1_12_2/routes.ts +++ b/src/routes/public/minecraft/1_12_2/routes.ts @@ -1,17 +1,25 @@ import { Router } from "express"; -import Minecraft from "../../../../minecraft/1.12.2/helios_distribution" +import Minecraft from "../../../../modules/minecraft/1.12.2/minecraft_distribution" + +import GetMinecraftServers from "../../../../modules/mongoose/db_connect" const minecraft = new Minecraft //Is this right? const routes = Router(); - +const test_db = new GetMinecraftServers routes.get("/", (req, res) => { return res.json({ message: "yes" }); }); routes.get("/distribution", (req, res) =>{ - res.send(minecraft.generateDistribution()) + res.send(minecraft.getDistribution()) }); -export default routes; +routes.get("/writeServer", (req, res) =>{ + res.send(minecraft.writeServer()) +}); +routes.get("/test", (req, res) =>{ + res.send(test_db.writeTestModel()) +}); +export default routes; \ No newline at end of file diff --git a/src/routes/public/minecraft/minecraft_routes.ts b/src/routes/public/minecraft/minecraft_routes.ts index dd5cf46..454add8 100644 --- a/src/routes/public/minecraft/minecraft_routes.ts +++ b/src/routes/public/minecraft/minecraft_routes.ts @@ -1,5 +1,5 @@ import { Router } from "express"; -import minecraft_1_12_2_routes from './1_12_2/routes' +import minecraft_1_12_2_routes from "./1_12_2/routes" const routes = Router();