2023-02-16 18:50:32 -05:00
var express = require ( 'express' ) ;
var router = express . Router ( ) ;
var fetch = require ( 'cross-fetch' ) ;
const sqlite3 = require ( 'sqlite3' ) . verbose ( ) ;
2023-05-07 01:20:04 -04:00
var config = require ( '../config.json' ) ;
let db = new sqlite3 . Database ( config . DXMemorialImageDirectory + '\\db.sqlite' ) ;
2023-02-16 18:50:32 -05:00
router . post ( '/getExtId/' , function ( req , res , next ) {
db . all ( 'SELECT * FROM sega_card' , ( err , rows ) => {
if ( err ) {
console . error ( err ) ;
// Return a Failed Message.
res . status ( 500 ) . json ( { error : err . message , status : "Failed" } ) ;
} else {
// Make the Request easier to get to.
var request = req . body ;
var mUser = undefined // Leave the Matched User undefined until the user is found.
for ( user of rows ) { // For Each User in Rows
if ( request . input === user . luid ) { // If the Access Code for the card is in the system,
mUser = user ; // set the Matched User Variable to the User, and break the for Loop.
break
}
}
// Return a Response with the whole identifiable user data. the EXT_ID will be used later to identify images and other things and match them to the user's profile.
res . status ( 200 ) . json ( { data : mUser , status : "Complete" } ) ;
}
} ) ;
} ) ;
2023-02-16 20:43:12 -05:00
router . post ( '/getUserData/' , function ( req , res , next ) {
2023-02-16 21:49:08 -05:00
db . all ( 'SELECT * FROM maimai2_user_detail' , ( err , rows ) => {
if ( err ) {
console . error ( err ) ;
// Return a Failed Message.
res . status ( 500 ) . json ( { error : err . message , status : "Failed" } ) ;
} else {
// Make the Request easier to get to.
var request = req . body ;
var mUser = undefined // Leave the Matched User undefined until the user is found.
for ( user of rows ) { // For Each User in Rows
if ( request . input === user . aime _card _id ) { // If the Access Code for the card is in the system,
mUser = user ; // set the Matched User Variable to the User, and break the for Loop.
break
}
}
// Return a Response with the whole identifiable user data. the EXT_ID will be used later to identify images and other things and match them to the user's profile.
res . status ( 200 ) . json ( { data : mUser , status : "Complete" } ) ;
}
} ) ;
2023-02-16 20:43:12 -05:00
} )
2023-02-18 05:19:30 -05:00
router . post ( '/getUserScores/' , function ( req , res , next ) {
db . all ( 'SELECT * FROM maimai2_user_playlog' , ( err , rows ) => {
if ( err ) {
console . error ( err ) ;
// Return a Failed Message.
res . status ( 500 ) . json ( { error : err . message , status : "Failed" } ) ;
} else {
// Make the Request easier to get to.
var request = req . body ;
var mUser = new Array ( ) ; // Leave the Matched User's Scores undefined until the user is found.
for ( score of rows ) { // For Each Score in Rows
if ( request . input == score . user _id ) { // If the inputed User ID and Score's User ID Matches,
mUser . push ( score ) // add that score into the array.
}
}
// Return a Response with all the Scores listed under that user.
res . status ( 200 ) . json ( { data : mUser , status : "Complete" } ) ;
}
} ) ;
} ) ;
2023-02-16 21:49:08 -05:00
2023-02-25 08:30:21 -05:00
router . post ( '/getUserArea/' , function ( req , res , next ) {
db . all ( 'SELECT * FROM maimai2_user_map' , ( err , rows ) => {
if ( err ) {
console . error ( err ) ;
// Return a Failed Message.
res . status ( 500 ) . json ( { error : err . message , status : "Failed" } ) ;
} else {
// Make the Request easier to get to.
var request = req . body ;
var mUser = new Array ( ) ; // Leave the Matched User's Areas undefined until the user is found.
for ( map of rows ) { // For Each Area in Rows
if ( request . input == map . user _id ) { // If the inputed User ID and Score's User ID Matches,
mUser . push ( map ) // add that Area into the array.
}
}
// Return a Response with all the Areas listed under that user.
res . status ( 200 ) . json ( { data : mUser , status : "Complete" } ) ;
}
} ) ;
} ) ;
2023-02-16 21:49:08 -05:00
2023-05-07 01:20:04 -04:00
router . post ( '/getuserbanned/' , function ( req , res , next ) {
var request = req . body ;
if ( request . input === undefined ) {
return res . status ( 500 ) . send ( 'Failed to update user ban state, insufficent paramaters' ) ;
}
db . run ( 'UPDATE maimai2_user_detail SET ban_state = ? WHERE id = ?' , [ 2 , request . input ] , function ( err ) {
if ( err ) {
console . error ( err . message ) ;
res . status ( 500 ) . send ( 'Failed to update user ban state' ) ;
} else {
res . send ( { "status" : "Success" , "message" : ` User ${ request . input } banned. ` } ) ;
}
} ) ;
} ) ;
router . post ( '/getuserunbanned/' , function ( req , res , next ) {
var request = req . body ;
if ( request . input === undefined ) {
return res . status ( 500 ) . send ( 'Failed to update user ban state, insufficent paramaters' ) ;
}
db . run ( 'UPDATE maimai2_user_detail SET ban_state = ? WHERE id = ?' , [ 0 , request . input ] , function ( err ) {
if ( err ) {
console . error ( err . message ) ;
res . status ( 500 ) . send ( 'Failed to update user ban state' ) ;
} else {
res . send ( { "status" : "Success" , "message" : ` User ${ request . input } unbanned. ` } ) ;
}
} ) ;
} ) ;
2023-02-16 18:50:32 -05:00
module . exports = router ;