add history api
This commit is contained in:
parent
060540d23d
commit
8be7d8ce41
|
@ -10,7 +10,7 @@ import ReactDOM from 'react-dom/server';
|
||||||
|
|
||||||
import Html from './Html';
|
import Html from './Html';
|
||||||
import assets from './assets.json';
|
import assets from './assets.json';
|
||||||
import { ASSET_SERVER } from '../core/config';
|
import { ASSET_SERVER, BACKUP_URL } from '../core/config';
|
||||||
|
|
||||||
const data = {
|
const data = {
|
||||||
title: 'PixelPlanet.fun',
|
title: 'PixelPlanet.fun',
|
||||||
|
@ -35,7 +35,10 @@ const data = {
|
||||||
*/
|
*/
|
||||||
function generateMainPage(countryCoords: Cell): string {
|
function generateMainPage(countryCoords: Cell): string {
|
||||||
const [x, y] = countryCoords;
|
const [x, y] = countryCoords;
|
||||||
const code = `window.coordx=${x};window.coordy=${y};window.assetserver="${ASSET_SERVER}";`;
|
let code = `window.coordx=${x};window.coordy=${y};window.assetserver="${ASSET_SERVER}";`;
|
||||||
|
if (BACKUP_URL) {
|
||||||
|
code += `window.backupurl="${BACKUP_URL}";`;
|
||||||
|
}
|
||||||
const htmldata = { ...data, code };
|
const htmldata = { ...data, code };
|
||||||
const html = ReactDOM.renderToStaticMarkup(<Html {...htmldata} />);
|
const html = ReactDOM.renderToStaticMarkup(<Html {...htmldata} />);
|
||||||
|
|
||||||
|
|
|
@ -16,6 +16,9 @@ export const ASSET_SERVER = process.env.ASSET_SERVER || '.';
|
||||||
|
|
||||||
export const USE_XREALIP = process.env.USE_XREALIP || false;
|
export const USE_XREALIP = process.env.USE_XREALIP || false;
|
||||||
|
|
||||||
|
export const BACKUP_URL = process.env.BACKUP_URL || null;
|
||||||
|
export const BACKUP_DIR = process.env.BACKUP_DIR || null;
|
||||||
|
|
||||||
// Proxycheck
|
// Proxycheck
|
||||||
export const USE_PROXYCHECK = parseInt(process.env.USE_PROXYCHECK, 10) || false;
|
export const USE_PROXYCHECK = parseInt(process.env.USE_PROXYCHECK, 10) || false;
|
||||||
|
|
||||||
|
|
35
src/routes/api/history.js
Normal file
35
src/routes/api/history.js
Normal file
|
@ -0,0 +1,35 @@
|
||||||
|
/**
|
||||||
|
*
|
||||||
|
* @flow
|
||||||
|
*/
|
||||||
|
|
||||||
|
import fs from 'fs';
|
||||||
|
import type { Request, Response } from 'express';
|
||||||
|
|
||||||
|
import { BACKUP_DIR } from '../../core/config';
|
||||||
|
|
||||||
|
async function history(req: Request, res: Response) {
|
||||||
|
const { day, id } = req.query;
|
||||||
|
if (!BACKUP_DIR || !day || !id || day.includes('/') || day.includes('\\')) {
|
||||||
|
res.status(404).end();
|
||||||
|
}
|
||||||
|
const path = `${BACKUP_DIR}/${day}/${id}`;
|
||||||
|
|
||||||
|
try {
|
||||||
|
if (!fs.existsSync(path)) {
|
||||||
|
res.status(404).end();
|
||||||
|
}
|
||||||
|
|
||||||
|
const dirs = fs.readdirSync(path)
|
||||||
|
const filteredDir = dirs.filter(item => item !== 'tiles')
|
||||||
|
res.set({
|
||||||
|
'Cache-Control': `public, max-age=${60 * 60}`, // seconds
|
||||||
|
});
|
||||||
|
res.json(filteredDir);
|
||||||
|
|
||||||
|
} catch {
|
||||||
|
res.status(404).end();
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
export default history;
|
|
@ -23,6 +23,7 @@ import mctp from './mctp';
|
||||||
import pixel from './pixel';
|
import pixel from './pixel';
|
||||||
import auth from './auth';
|
import auth from './auth';
|
||||||
import ranking from './ranking';
|
import ranking from './ranking';
|
||||||
|
import history from './history';
|
||||||
|
|
||||||
|
|
||||||
const router = express.Router();
|
const router = express.Router();
|
||||||
|
@ -30,6 +31,8 @@ const router = express.Router();
|
||||||
// this route doesn't need passport
|
// this route doesn't need passport
|
||||||
router.get('/ranking', ranking);
|
router.get('/ranking', ranking);
|
||||||
|
|
||||||
|
router.get('/history', history);
|
||||||
|
|
||||||
/*
|
/*
|
||||||
* get user session
|
* get user session
|
||||||
*/
|
*/
|
||||||
|
|
Loading…
Reference in New Issue
Block a user