Update http request and move versions to core #483

Merged
Sirherobrine23 merged 5 commits from internalServerVersion into main 2022-11-06 15:42:15 +00:00
5 changed files with 0 additions and 70 deletions
Showing only changes of commit 4d88e8b443 - Show all commits

View File

@ -1,7 +1,5 @@
import mongoose from "mongoose";
import connection from "./connect";
import { Router } from "express";
export const app = Router();
export type bedrockSchema = {
version: string,
@ -27,12 +25,3 @@ export const bedrock = connection.model<bedrockSchema>("bedrock", new mongoose.S
}
}));
app.get("/", ({res}) => bedrock.find().lean().then(data => res.json(data)));
app.get("/latest", async ({res}) => res.json(await bedrock.findOne({latest: true}).lean()));
app.get("/search", async (req, res) => {
let version = req.query.version as string;
if (!version) return res.status(400).json({error: "No version specified"});
const versionFinded = await bedrock.findOne({version}).lean();
if (!versionFinded) return res.status(404).json({error: "Version not found"});
return res.json(versionFinded);
});

View File

@ -1,7 +1,5 @@
import mongoose from "mongoose";
import connection from "./connect";
import { Router } from "express";
export const app = Router();
export type javaSchema = {
version: string,
@ -22,12 +20,3 @@ export const java = connection.model<javaSchema>("java", new mongoose.Schema<jav
}));
export default java;
app.get("/", ({res}) => java.find().lean().then(data => res.json(data)));
app.get("/latest", async ({res}) => res.json(await java.findOne({latest: true}).lean()));
app.get("/search", async (req, res) => {
let version = req.query.version as string;
if (!version) return res.status(400).json({error: "No version specified"});
const versionFinded = await java.findOne({version: version}).lean();
if (!versionFinded) return res.status(404).json({error: "Version not found"});
return res.json(versionFinded);
});

View File

@ -1,7 +1,5 @@
import mongoose from "mongoose";
import connection from "./connect";
import { Router } from "express";
export const app = Router();
export type paperSchema = {
version: string,
@ -19,24 +17,3 @@ export const paper = connection.model<paperSchema>("paper", new mongoose.Schema<
url: String
}));
app.get("/", ({res}) => paper.find().lean().then(data => res.json(data)));
app.get("/latest", ({res}) => paper.findOne({latest: true}).lean().then(data => res.json(data)));
app.get("/search", async (req, res) => {
let version = req.query.version as string;
if (!version) return res.status(400).json({erro: "Not allowd blank version"});
let build = parseInt(req.query.build as string);
if (isNaN(build)) build = undefined;
if (!!build) {
const info = await paper.findOne({
version,
build
});
if (!info) return res.status(400).json({error: "version and build not exists"});
return res.json(info);
}
const info = await paper.findOne({
version
});
if (!info) return res.status(400).json({error: "version not exists"});
return res.json(info);
});

View File

@ -1,7 +1,5 @@
import mongoose from "mongoose";
import connection from "./connect";
import { Router } from "express";
export const app = Router();
export type powernukkitSchema = {
version: string,
@ -24,14 +22,3 @@ export const powernukkit = connection.model<powernukkitSchema>("powernukkit", ne
variantType: String,
latest: Boolean
}));
app.get("/", ({res}) => powernukkit.find().lean().then(data => res.json(data)));
app.get("/latest", ({res}) => powernukkit.findOne({latest: true}).lean().then(data => res.json(data)));
app.get("/search", async (req, res) => {
let version = req.query.version as string;
let variant = (req.query.variant as string)||undefined;
if (!version) return res.status(400).json({error: "No version specified"});
const versionDB = await powernukkit.findOne({version, variant: {to: variant}}).lean();
if (!versionDB) return res.status(404).json({error: "Version not found"});
return res.json(versionDB);
});

View File

@ -1,7 +1,5 @@
import mongoose from "mongoose";
import connection from "./connect";
import { Router } from "express";
export const app = Router();
// Type to represent the spigot model
export type spigotSchema = {
@ -21,13 +19,3 @@ export const spigot = connection.model<spigotSchema>("spigot", new mongoose.Sche
latest: Boolean,
url: String
}));
app.get("/", ({res}) => spigot.find().lean().then(data => res.json(data)));
app.get("/latest", async ({res}) => res.json(await spigot.findOne({latest: true}).lean()));
app.get("/search", async (req, res) => {
let version = req.query.version as string;
if (!version) return res.status(400).json({error: "No version specified"});
const versionFinded = await spigot.findOne({version}).lean();
if (!versionFinded) return res.status(404).json({error: "Version not found"});
return res.json(versionFinded);
});