mongoose experiments
This commit is contained in:
parent
218450fcb5
commit
b1bc2b10f6
@ -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;
|
||||
|
@ -1,3 +0,0 @@
|
||||
import { IMinecraftServer } from './helios_distribution'
|
||||
|
||||
export Min
|
@ -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{
|
||||
|
||||
}
|
||||
export type ForgeMod = IForgeMod
|
54
src/modules/minecraft/1.12.2/minecraft_distribution.ts
Normal file
54
src/modules/minecraft/1.12.2/minecraft_distribution.ts
Normal file
@ -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<IMinecraftServer[]>{
|
||||
var servers:IMinecraftServer[] = []
|
||||
await connect('mongodb://172.17.0.2:27017/minecraft');
|
||||
return servers
|
||||
}
|
||||
}
|
||||
|
51
src/modules/mongoose/db_connect.ts
Normal file
51
src/modules/mongoose/db_connect.ts
Normal file
@ -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<IForgeMod>({
|
||||
id:{type: String, required: true}
|
||||
})
|
||||
|
||||
// 2. Create a Schema corresponding to the document interface.
|
||||
const serverSchema = new Schema<IMinecraftServer>({
|
||||
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<IMinecraftServer>('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()
|
||||
}
|
||||
|
||||
}
|
@ -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<IUser>({
|
||||
name: { type: String, required: true },
|
||||
email: { type: String, required: true },
|
||||
avatar: String
|
||||
});
|
||||
|
||||
// 3. Create a Model.
|
||||
const User = model<IUser>('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()
|
||||
}
|
||||
|
||||
}
|
@ -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;
|
||||
|
||||
|
@ -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;
|
@ -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;
|
@ -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();
|
||||
|
||||
|
Loading…
Reference in New Issue
Block a user