1
0
mirror of https://github.com/shiroikitsu8/Bayshore_6r_legacy.git synced 2025-01-19 12:18:39 +01:00

remove api (for now)

This commit is contained in:
ghkkk090 2022-09-18 13:01:12 +07:00
parent ed6250ca24
commit cc366455be
2 changed files with 1 additions and 221 deletions

View File

@ -1,207 +0,0 @@
import express, { Application } from "express";
import { prisma } from ".";
import { Module } from "./module";
export default class ApiModule extends Module {
register(app: Application): void {
app.use(express.urlencoded({
type: '*/*',
extended: true
}));
app.use(express.json({
type: '*/*'
}));
// API Get Requests
// Get Current Bayshore Version
app.get('/api/bayshore_version', async (req, res) => {
let message: any = {
error: null,
version: null
};
let myJSON = '{'+
'"version": "v1.0.0",'+
'"log":'+
'['+
'"• Fix ghost play count when retiring ocm",'+
'"• API for ocm ranking",'+
'"• Fix unlimited ghost stamp return (hopefully no more of this)",'+
'"• Fix give meter reward bug if playCount still 0",'+
'"• Hopefully fix ocm HoF bug"'+
'"• Fix duplicate id in carOrder"'+
'"• Fix OCM HoF wrong shopName"'+
'"• More OCM Data (old event before mt6 and dev ghost)"'+
']'+
'}';
message.version = JSON.parse(myJSON);
// Send the response to the client
res.send(message);
})
// Get Lastest Competition Id
app.get('/api/get_competition_id', async (req, res) => {
// Get current date
let date = Math.floor(new Date().getTime() / 1000);
// Message Response
let message: any = {
error: null,
competitionId: 1 // default
};
// Get current / previous active OCM Event
let ocmEventDate = await prisma.oCMEvent.findFirst({
where: {
// qualifyingPeriodStartAt is less than current date
qualifyingPeriodStartAt: { lte: date },
// competitionEndAt is greater than current date
competitionEndAt: { gte: date },
},
orderBy: [
{
dbId: 'desc'
},
{
competitionEndAt: 'desc',
},
],
select:{
competitionId: true
}
});
if(ocmEventDate)
{
message.competitionId = ocmEventDate.competitionId;
}
else{
ocmEventDate = await prisma.oCMEvent.findFirst({
orderBy: {
competitionId: 'desc'
},
select:{
competitionId: true
}
});
message.competitionId = ocmEventDate!.competitionId;
}
// Send the response to the client
res.send(message);
});
// Get Competition Ranking
app.get('/api/get_competition_ranking', async (req, res) => {
// Get url query
let competitionId = Number(req.query.competitionId);
// Message Response
let message: any = {
error: null,
cars: [],
lastPlayedPlace: 'Bayshore',
rankType: null
};
// Get current date
let date = Math.floor(new Date().getTime() / 1000);
// Get current / previous active OCM Event
let ocmEventDate = await prisma.oCMEvent.findFirst({
where:{
competitionId: competitionId
}
});
// Current date is OCM main draw and so on
if(ocmEventDate!.competitionStartAt < date)
{
// Get all of the cars matching the query
message.cars = await prisma.oCMTally.findMany({
where:{
competitionId: competitionId
},
orderBy: {
result: 'desc'
},
include:{
car: {
select:{
carId: true,
name: true,
defaultColor: true,
visualModel: true,
level: true,
title: true,
regionId: true,
}
},
}
});
let getLastPlayedPlace = await prisma.oCMGhostBattleRecord.findFirst({
where:{
carId: message.cars[0].carId,
competitionId: competitionId
}
})
message.lastPlayedPlace = getLastPlayedPlace?.playedShopName;
message.rankType = 'MainDraw';
}
// Current date is OCM qualifying day
else if(ocmEventDate!.qualifyingPeriodStartAt < date && ocmEventDate!.qualifyingPeriodCloseAt > date)
{
// Get all of the cars matching the query
message.cars = await prisma.oCMGhostBattleRecord.findMany({
where:{
competitionId: competitionId,
ocmMainDraw: false
},
orderBy: {
result: 'desc'
},
include:{
car: {
select:{
carId: true,
name: true,
defaultColor: true,
visualModel: true,
level: true,
title: true,
regionId: true,
}
},
}
});
let getLastPlayedPlace = await prisma.oCMGhostBattleRecord.findFirst({
where:{
carId: message.cars[0].carId,
competitionId: competitionId
}
})
message.lastPlayedPlace = getLastPlayedPlace?.playedShopName;
message.rankType = 'Qualifying';
}
// Send the response to the client
res.send(message);
});
}
}

View File

@ -9,7 +9,6 @@ import fs from 'fs';
import bodyParser from 'body-parser';
import AllnetModule from './allnet';
import MuchaModule from './mucha';
import ApiModule from './api';
import { Config } from './config';
import process from 'process';
import * as Sentry from '@sentry/node';
@ -36,7 +35,6 @@ const PORT_API = 9003;
const app = express();
const muchaApp = express();
const allnetApp = express();
const apiApp = express();
app.use(bodyParser.raw({
type: '*/*'
@ -80,11 +78,6 @@ allnetApp.use((req, res, next) => {
next()
});
/*apiApp.use((req, res, next) => {
console.log(timestamp+` [ API] ${req.method} ${req.url}`);
next()
});*/
// Get all of the files in the modules directory
let dirs = fs.readdirSync('dist/modules');
// Loop over the files
@ -116,7 +109,6 @@ app.all('*', (req, res) => {
// Register the ALL.NET / Mucha Server
new AllnetModule().register(allnetApp);
new MuchaModule().register(muchaApp);
new ApiModule().register(apiApp);
// Sentry is in use
if (useSentry)
@ -149,9 +141,4 @@ https.createServer({key, cert}, muchaApp).listen(PORT_MUCHA, '0.0.0.0', 511, ()
// Create the game server
https.createServer({key, cert}, app).listen(PORT_BNGI, '0.0.0.0', 511, () => {
console.log(`Game server listening on port ${PORT_BNGI}!`);
})
// Create the API server
http.createServer(apiApp).listen(PORT_API, '0.0.0.0', 4369, () => {
console.log(`API server listening on port ${PORT_API}!`);
})
})