add game api and change minecraft api
This commit is contained in:
parent
b1bc2b10f6
commit
ea9397d2d5
@ -1,6 +1,6 @@
|
|||||||
import express from "express";
|
import express from "express";
|
||||||
import routes from "./routes/routes";
|
import games_routes from "./routes/public/games/games.route"
|
||||||
import minecraft_routes from "./routes/public/minecraft/minecraft_routes";
|
import minecraft_routes from "./routes/public/games/minecraft/minecraft_routes";
|
||||||
|
|
||||||
class App {
|
class App {
|
||||||
public server;
|
public server;
|
||||||
@ -17,7 +17,7 @@ class App {
|
|||||||
}
|
}
|
||||||
|
|
||||||
routes() {
|
routes() {
|
||||||
this.server.use(routes);
|
this.server.use('/games', games_routes);
|
||||||
this.server.use('/minecraft', minecraft_routes)
|
this.server.use('/minecraft', minecraft_routes)
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
30
src/modules/game.module.ts
Normal file
30
src/modules/game.module.ts
Normal file
@ -0,0 +1,30 @@
|
|||||||
|
import Game, { IGame, GameStatus, IPlatforms } from "../objects/game.object"
|
||||||
|
import { Schema, model, connect, Model } from 'mongoose';
|
||||||
|
|
||||||
|
export default class Games {
|
||||||
|
public async getGames() {
|
||||||
|
connect('mongodb://172.17.0.2:27017/game');
|
||||||
|
let games = await Game.find()
|
||||||
|
let games_list: IGame[] = []
|
||||||
|
games.forEach(game => {
|
||||||
|
games_list.push(game.toObject())
|
||||||
|
})
|
||||||
|
|
||||||
|
return games_list
|
||||||
|
}
|
||||||
|
|
||||||
|
public async writeNewGame(game_id:string, game_name:string, game_icon_url:string, game_backgrounds:string[], game_status:GameStatus, game_platforms:IPlatforms) {
|
||||||
|
await connect('mongodb://172.17.0.2:27017/game');
|
||||||
|
const newGame = new Game({
|
||||||
|
id: game_id,
|
||||||
|
name: game_name,
|
||||||
|
icon: game_icon_url,
|
||||||
|
backgrounds: game_backgrounds,
|
||||||
|
status: game_status,
|
||||||
|
platforms: game_platforms
|
||||||
|
})
|
||||||
|
|
||||||
|
console.log(newGame)
|
||||||
|
await newGame.save()
|
||||||
|
}
|
||||||
|
}
|
@ -1,38 +1,20 @@
|
|||||||
import {IHeliosDistribution, IMinecraftServer} from "./helios_distribution"
|
import { IHeliosDistribution, IMinecraftServer } from "./helios_distribution"
|
||||||
import { Schema, model, connect, Model } from 'mongoose';
|
import mongoose, { Schema, model, connect, Model } from 'mongoose';
|
||||||
|
import MinecraftServer from "./models";
|
||||||
|
|
||||||
const SolFileSchema = new Schema({
|
export default class Minecraft {
|
||||||
id:{ type: String, required: true }
|
public async getServers() {
|
||||||
})
|
connect('mongodb://172.17.0.2:27017/minecraft');
|
||||||
|
let servers = await MinecraftServer.find()
|
||||||
|
let servers_list: IMinecraftServer[] = []
|
||||||
|
servers.forEach(element => {
|
||||||
|
servers_list.push(element.toObject())
|
||||||
|
});
|
||||||
|
|
||||||
const minecraftServerSchema = new Schema({
|
return servers_list
|
||||||
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(){
|
public async writeServer() {
|
||||||
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');
|
await connect('mongodb://172.17.0.2:27017/minecraft');
|
||||||
const newSrv = new MinecraftServer({
|
const newSrv = new MinecraftServer({
|
||||||
id: 'kek',
|
id: 'kek',
|
||||||
@ -44,11 +26,5 @@ export default class Minecraft{
|
|||||||
})
|
})
|
||||||
await newSrv.save()
|
await newSrv.save()
|
||||||
}
|
}
|
||||||
|
|
||||||
private async getServers(): Promise<IMinecraftServer[]>{
|
|
||||||
var servers:IMinecraftServer[] = []
|
|
||||||
await connect('mongodb://172.17.0.2:27017/minecraft');
|
|
||||||
return servers
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
|
|
||||||
|
34
src/modules/minecraft/1.12.2/models.ts
Normal file
34
src/modules/minecraft/1.12.2/models.ts
Normal file
@ -0,0 +1,34 @@
|
|||||||
|
import { Document, Schema, model } from "mongoose"
|
||||||
|
|
||||||
|
export interface IMinecraftServer extends Document {
|
||||||
|
id: string
|
||||||
|
name: string
|
||||||
|
description: string
|
||||||
|
icon: string
|
||||||
|
minecraftVersion: string
|
||||||
|
address: string
|
||||||
|
}
|
||||||
|
|
||||||
|
export 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 }
|
||||||
|
})
|
||||||
|
|
||||||
|
MinecraftServerSchema.set('toObject', { // Delete mongoDB document fields
|
||||||
|
virtuals: true,
|
||||||
|
transform: function (doc, ret) {
|
||||||
|
delete ret._id;
|
||||||
|
delete ret.__v;
|
||||||
|
}
|
||||||
|
});
|
||||||
|
|
||||||
|
const SolFileSchema = new Schema({
|
||||||
|
id: { type: String, required: true }
|
||||||
|
})
|
||||||
|
|
||||||
|
const MinecraftServer = model<IMinecraftServer>('server', MinecraftServerSchema)
|
||||||
|
export default MinecraftServer;
|
40
src/objects/game.object.ts
Normal file
40
src/objects/game.object.ts
Normal file
@ -0,0 +1,40 @@
|
|||||||
|
import { Document, Schema, model } from "mongoose"
|
||||||
|
|
||||||
|
export enum GameStatus {
|
||||||
|
"active",
|
||||||
|
"inactive",
|
||||||
|
"pending"
|
||||||
|
}
|
||||||
|
|
||||||
|
export interface IPlatforms {
|
||||||
|
windows: boolean
|
||||||
|
linux: boolean,
|
||||||
|
macOS: boolean
|
||||||
|
}
|
||||||
|
|
||||||
|
export const platformsSchema = new Schema({
|
||||||
|
windows: { type: Schema.Types.Boolean, required: true, default: false },
|
||||||
|
linux: { type: Schema.Types.Boolean, required: true, default: false },
|
||||||
|
macOS: { type: Schema.Types.Boolean, required: true, default: false }
|
||||||
|
})
|
||||||
|
|
||||||
|
export interface IGame extends Document {
|
||||||
|
id: string,
|
||||||
|
name: string,
|
||||||
|
icon: URL,
|
||||||
|
backgrounds: string[],
|
||||||
|
status: GameStatus
|
||||||
|
platforms: IPlatforms
|
||||||
|
}
|
||||||
|
|
||||||
|
export const GameSchema = new Schema({
|
||||||
|
id: { type: String, required: true },
|
||||||
|
name: { type: String, required: true },
|
||||||
|
icon: { type: String, URL, required: true },
|
||||||
|
backgrounds: [{ type: String, required: true }],
|
||||||
|
status: { type: String, enum: Object.values(GameStatus), default: GameStatus.inactive, required: true },
|
||||||
|
platforms: platformsSchema
|
||||||
|
})
|
||||||
|
|
||||||
|
const Game = model<IGame>('game', GameSchema)
|
||||||
|
export default Game;
|
@ -1,7 +1,5 @@
|
|||||||
import express from "express";
|
import express from "express";
|
||||||
|
|
||||||
import routes from "./routes/public_routes";
|
import routes from "./routes/public_routes";
|
||||||
import minecraft_routes from "./routes/public/minecraft/minecraft_routes";
|
|
||||||
|
|
||||||
class PublicApi {
|
class PublicApi {
|
||||||
public server;
|
public server;
|
||||||
|
26
src/routes/public/games/games.route.ts
Normal file
26
src/routes/public/games/games.route.ts
Normal file
@ -0,0 +1,26 @@
|
|||||||
|
import { Router } from "express";
|
||||||
|
import { GameStatus, IPlatforms } from "../../../objects/game.object"
|
||||||
|
import Games from "../../../modules/game.module";
|
||||||
|
|
||||||
|
const games = new Games
|
||||||
|
const routes = Router();
|
||||||
|
|
||||||
|
routes.get("/", async (req, res) => {
|
||||||
|
|
||||||
|
let games_list = await games.getGames()
|
||||||
|
await res.json(games_list);
|
||||||
|
});
|
||||||
|
|
||||||
|
routes.get("/writeServer", async (req, res) => {
|
||||||
|
let game_id: string = 'test'
|
||||||
|
let game_name: string = 'Test'
|
||||||
|
let game_icon_url: string = 'http://1.jpg'
|
||||||
|
let game_backgrounds: string[] = ['http://bg1.jpg', 'http://bg2.jpg']
|
||||||
|
let game_status: GameStatus = GameStatus.active
|
||||||
|
let game_platforms: IPlatforms = { windows: true, linux: false, macOS: false }
|
||||||
|
await games.writeNewGame(game_id, game_name, game_icon_url, game_backgrounds, game_status, game_platforms)
|
||||||
|
await res.send("end")
|
||||||
|
});
|
||||||
|
|
||||||
|
routes.use
|
||||||
|
export default routes;
|
21
src/routes/public/games/minecraft/1_12_2/routes.ts
Normal file
21
src/routes/public/games/minecraft/1_12_2/routes.ts
Normal file
@ -0,0 +1,21 @@
|
|||||||
|
import { Router } from "express";
|
||||||
|
import Minecraft from "../../../../../modules/minecraft/1.12.2/minecraft_distribution"
|
||||||
|
|
||||||
|
const minecraft = new Minecraft //Is this right?
|
||||||
|
const routes = Router();
|
||||||
|
|
||||||
|
routes.get("/", (req, res) => {
|
||||||
|
return res.json({ message: "yes" });
|
||||||
|
});
|
||||||
|
|
||||||
|
routes.get("/distribution", async (req, res) =>{
|
||||||
|
let servers = await minecraft.getServers()
|
||||||
|
//console.log(kek)
|
||||||
|
res.send(servers)
|
||||||
|
});
|
||||||
|
|
||||||
|
routes.get("/writeServer", (req, res) =>{
|
||||||
|
res.send(minecraft.writeServer())
|
||||||
|
});
|
||||||
|
|
||||||
|
export default routes;
|
@ -1,25 +0,0 @@
|
|||||||
import { Router } from "express";
|
|
||||||
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.getDistribution())
|
|
||||||
});
|
|
||||||
|
|
||||||
routes.get("/writeServer", (req, res) =>{
|
|
||||||
res.send(minecraft.writeServer())
|
|
||||||
});
|
|
||||||
|
|
||||||
routes.get("/test", (req, res) =>{
|
|
||||||
res.send(test_db.writeTestModel())
|
|
||||||
});
|
|
||||||
|
|
||||||
export default routes;
|
|
@ -1,9 +0,0 @@
|
|||||||
import { Router } from "express";
|
|
||||||
|
|
||||||
const routes = Router();
|
|
||||||
|
|
||||||
routes.get("/", (req, res) => {
|
|
||||||
return res.json({ message: "Hello World" });
|
|
||||||
});
|
|
||||||
|
|
||||||
export default routes;
|
|
Loading…
Reference in New Issue
Block a user