forked from ppfun/pixelplanet
fix 75 eslint warnings,
rename files with jsx code to .jsx, fix ChatModal export
This commit is contained in:
parent
2c9b2c64a9
commit
11a9c11631
|
@ -3,6 +3,11 @@
|
||||||
"plugin:flowtype/recommended",
|
"plugin:flowtype/recommended",
|
||||||
"airbnb"
|
"airbnb"
|
||||||
],
|
],
|
||||||
|
"parserOptions": {
|
||||||
|
"ecmaFeatures": {
|
||||||
|
"jsx": true
|
||||||
|
}
|
||||||
|
},
|
||||||
"plugins": [
|
"plugins": [
|
||||||
"flowtype",
|
"flowtype",
|
||||||
"react",
|
"react",
|
||||||
|
|
|
@ -11,10 +11,9 @@
|
||||||
"scripts": {
|
"scripts": {
|
||||||
"build": "babel-node tools/run build",
|
"build": "babel-node tools/run build",
|
||||||
"clean": "babel-node tools/run clean",
|
"clean": "babel-node tools/run clean",
|
||||||
"lint:js": "eslint src",
|
"lint": "eslint --ext .jsx --ext .js src",
|
||||||
"lint:css": "stylelint \"src/**/*.{css,less,scss,sss}\"",
|
"lint:css": "stylelint \"src/**/*.{css,less,scss,sss}\"",
|
||||||
"lint:staged": "lint-staged",
|
"lint:staged": "lint-staged"
|
||||||
"lint": "yarn run lint:js && yarn run lint:css"
|
|
||||||
},
|
},
|
||||||
"author": "HF <hf@example.com>",
|
"author": "HF <hf@example.com>",
|
||||||
"browserslist": [
|
"browserslist": [
|
||||||
|
|
|
@ -57,6 +57,6 @@ export type Action =
|
||||||
|
|
||||||
|
|
||||||
export type PromiseAction = Promise<Action>;
|
export type PromiseAction = Promise<Action>;
|
||||||
|
export type ThunkAction = (dispatch: Dispatch, getState: GetState) => any;
|
||||||
export type Dispatch = (action: Action | ThunkAction | PromiseAction | Array<Action>) => any;
|
export type Dispatch = (action: Action | ThunkAction | PromiseAction | Array<Action>) => any;
|
||||||
export type GetState = () => State;
|
export type GetState = () => State;
|
||||||
export type ThunkAction = (dispatch: Dispatch, getState: GetState) => any;
|
|
||||||
|
|
|
@ -1,5 +1,7 @@
|
||||||
/*
|
/*
|
||||||
* Chat input field
|
* Chat input field
|
||||||
|
*
|
||||||
|
* @flow
|
||||||
*/
|
*/
|
||||||
|
|
||||||
import React from 'react';
|
import React from 'react';
|
|
@ -4,13 +4,10 @@
|
||||||
*/
|
*/
|
||||||
|
|
||||||
import React from 'react';
|
import React from 'react';
|
||||||
import { connect } from 'react-redux';
|
|
||||||
|
|
||||||
import Modal from './Modal';
|
import Modal from './Modal';
|
||||||
import Chat from './Chat';
|
import Chat from './Chat';
|
||||||
|
|
||||||
import type { State } from '../reducers';
|
|
||||||
|
|
||||||
|
|
||||||
const textStyle = {
|
const textStyle = {
|
||||||
color: 'hsla(218, 5%, 47%, .6)',
|
color: 'hsla(218, 5%, 47%, .6)',
|
||||||
|
@ -36,3 +33,4 @@ const ChatModal = () => (
|
||||||
</Modal>
|
</Modal>
|
||||||
);
|
);
|
||||||
|
|
||||||
|
export default ChatModal;
|
|
@ -9,7 +9,7 @@ import HelpButton from './HelpButton';
|
||||||
import SettingsButton from './SettingsButton';
|
import SettingsButton from './SettingsButton';
|
||||||
import LogInButton from './LogInButton';
|
import LogInButton from './LogInButton';
|
||||||
import DownloadButton from './DownloadButton';
|
import DownloadButton from './DownloadButton';
|
||||||
import MinecraftTPButton from './MinecraftTPButton.js';
|
import MinecraftTPButton from './MinecraftTPButton';
|
||||||
import MinecraftButton from './MinecraftButton';
|
import MinecraftButton from './MinecraftButton';
|
||||||
|
|
||||||
const Menu = ({ menuOpen, minecraftname, messages, canvasId }) => (
|
const Menu = ({ menuOpen, minecraftname, messages, canvasId }) => (
|
|
@ -17,7 +17,7 @@ export const TILE_FOLDER = path.join(__dirname, `./${TILE_FOLDER_REL}`);
|
||||||
export const ASSET_SERVER = process.env.ASSET_SERVER || '.';
|
export const ASSET_SERVER = process.env.ASSET_SERVER || '.';
|
||||||
|
|
||||||
// Proxycheck
|
// Proxycheck
|
||||||
export const USE_PROXYCHECK = parseInt(process.env.USE_PROXYCHECK) || false;
|
export const USE_PROXYCHECK = parseInt(process.env.USE_PROXYCHECK, 10) || false;
|
||||||
|
|
||||||
export const REDIS_URL = process.env.REDIS_URL || 'redis://localhost:6380';
|
export const REDIS_URL = process.env.REDIS_URL || 'redis://localhost:6380';
|
||||||
// Database
|
// Database
|
||||||
|
@ -80,7 +80,7 @@ export const ads = {
|
||||||
export const RECAPTCHA_SECRET = process.env.RECAPTCHA_SECRET || false;
|
export const RECAPTCHA_SECRET = process.env.RECAPTCHA_SECRET || false;
|
||||||
export const RECAPTCHA_SITEKEY = process.env.RECAPTCHA_SITEKEY || false;
|
export const RECAPTCHA_SITEKEY = process.env.RECAPTCHA_SITEKEY || false;
|
||||||
// time on which to display captcha in minutes
|
// time on which to display captcha in minutes
|
||||||
export const RECAPTCHA_TIME = parseInt(process.env.RECAPTCHA_TIME) || 30;
|
export const RECAPTCHA_TIME = parseInt(process.env.RECAPTCHA_TIME, 10) || 30;
|
||||||
|
|
||||||
export const SESSION_SECRET = process.env.SESSION_SECRET || 'dummy';
|
export const SESSION_SECRET = process.env.SESSION_SECRET || 'dummy';
|
||||||
|
|
||||||
|
|
|
@ -43,7 +43,7 @@ export function setPixel(
|
||||||
*/
|
*/
|
||||||
async function draw(
|
async function draw(
|
||||||
user: User,
|
user: User,
|
||||||
canvasId: string,
|
canvasId: number,
|
||||||
x: number,
|
x: number,
|
||||||
y: number,
|
y: number,
|
||||||
color: ColorIndex,
|
color: ColorIndex,
|
||||||
|
|
|
@ -32,7 +32,7 @@ class CanvasUpdater {
|
||||||
firstZoomtileWidth: number;
|
firstZoomtileWidth: number;
|
||||||
canvasTileFolder: string;
|
canvasTileFolder: string;
|
||||||
|
|
||||||
constructor(id) {
|
constructor(id: number) {
|
||||||
this.updateZoomlevelTiles = this.updateZoomlevelTiles.bind(this);
|
this.updateZoomlevelTiles = this.updateZoomlevelTiles.bind(this);
|
||||||
|
|
||||||
this.TileLoadingQueues = [];
|
this.TileLoadingQueues = [];
|
||||||
|
@ -162,7 +162,7 @@ export function startAllCanvasLoops() {
|
||||||
if (!fs.existsSync(`${TILE_FOLDER}`)) fs.mkdirSync(`${TILE_FOLDER}`);
|
if (!fs.existsSync(`${TILE_FOLDER}`)) fs.mkdirSync(`${TILE_FOLDER}`);
|
||||||
const ids = Object.keys(canvases);
|
const ids = Object.keys(canvases);
|
||||||
for (let i = 0; i < ids.length; i += 1) {
|
for (let i = 0; i < ids.length; i += 1) {
|
||||||
const updater = new CanvasUpdater(ids[i]);
|
const updater = new CanvasUpdater(parseInt(ids[i], 10));
|
||||||
CanvasUpdaters[ids[i]] = updater;
|
CanvasUpdaters[ids[i]] = updater;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
|
@ -15,6 +15,13 @@ export function mod(n: number, m: number): number {
|
||||||
return ((n % m) + m) % m;
|
return ((n % m) + m) % m;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
export function sum(values: Array<number>): number {
|
||||||
|
let total = 0;
|
||||||
|
// TODO map reduce
|
||||||
|
values.forEach(value => total += value);
|
||||||
|
return total;
|
||||||
|
}
|
||||||
|
|
||||||
export function distMax([x1, y1]: Cell, [x2, y2]: Cell): number {
|
export function distMax([x1, y1]: Cell, [x2, y2]: Cell): number {
|
||||||
return Math.max(Math.abs(x1 - x2), Math.abs(y1 - y2));
|
return Math.max(Math.abs(x1 - x2), Math.abs(y1 - y2));
|
||||||
}
|
}
|
||||||
|
|
|
@ -72,7 +72,7 @@ router.use('/', express.static(TILE_FOLDER, {
|
||||||
/*
|
/*
|
||||||
* catch File Not Found: Send empty tile
|
* catch File Not Found: Send empty tile
|
||||||
*/
|
*/
|
||||||
router.use('/:c([0-9]+)/:z([0-9]+)/:x([0-9]+)/:y([0-9]+).png', async (req: Request, res: Response, next) => {
|
router.use('/:c([0-9]+)/:z([0-9]+)/:x([0-9]+)/:y([0-9]+).png', async (req: Request, res: Response) => {
|
||||||
const { c: paramC } = req.params;
|
const { c: paramC } = req.params;
|
||||||
const c = parseInt(paramC, 10);
|
const c = parseInt(paramC, 10);
|
||||||
res.set({
|
res.set({
|
||||||
|
|
|
@ -2,6 +2,8 @@
|
||||||
* save the chat history
|
* save the chat history
|
||||||
* TODO:
|
* TODO:
|
||||||
* This should really be saved in redis
|
* This should really be saved in redis
|
||||||
|
*
|
||||||
|
* @flow
|
||||||
*/
|
*/
|
||||||
|
|
||||||
class ChatHistory {
|
class ChatHistory {
|
||||||
|
|
|
@ -1,5 +1,6 @@
|
||||||
/*
|
/*
|
||||||
* keypress actions
|
* keypress actions
|
||||||
|
* @flow
|
||||||
*/
|
*/
|
||||||
import keycode from 'keycode';
|
import keycode from 'keycode';
|
||||||
|
|
||||||
|
|
|
@ -1,11 +0,0 @@
|
||||||
/**
|
|
||||||
*
|
|
||||||
* @flow
|
|
||||||
*/
|
|
||||||
|
|
||||||
export function sum(values: Array<number>): number {
|
|
||||||
let total = 0;
|
|
||||||
// TODO map reduce
|
|
||||||
values.forEach(value => total += value);
|
|
||||||
return total;
|
|
||||||
}
|
|
|
@ -1,7 +1,20 @@
|
||||||
|
/*
|
||||||
|
* check if IP is from cloudflare
|
||||||
|
* @flow
|
||||||
|
*/
|
||||||
|
|
||||||
// 3rd
|
import { Address4, Address6 } from 'ip-address';
|
||||||
const Address4 = require('ip-address').Address4;
|
|
||||||
const Address6 = require('ip-address').Address6;
|
// returns undefined | Address4 | Address6
|
||||||
|
function intoAddress(str) {
|
||||||
|
if (typeof str === 'string') str = str.trim();
|
||||||
|
let ip = new Address6(str);
|
||||||
|
if (ip.v4 && !ip.valid) {
|
||||||
|
ip = new Address4(str);
|
||||||
|
}
|
||||||
|
if (!ip.valid) return null;
|
||||||
|
return ip;
|
||||||
|
}
|
||||||
|
|
||||||
const cloudflareIps = [
|
const cloudflareIps = [
|
||||||
'103.21.244.0/22',
|
'103.21.244.0/22',
|
||||||
|
@ -27,21 +40,12 @@ const cloudflareIps = [
|
||||||
'2a06:98c0::/29',
|
'2a06:98c0::/29',
|
||||||
].map(intoAddress);
|
].map(intoAddress);
|
||||||
|
|
||||||
// returns undefined | Address4 | Address6
|
|
||||||
function intoAddress(str) {
|
|
||||||
if (typeof str === 'string') str = str.trim();
|
|
||||||
let ip = new Address6(str);
|
|
||||||
if (ip.v4 && !ip.valid) {
|
|
||||||
ip = new Address4(str);
|
|
||||||
}
|
|
||||||
if (!ip.valid) return;
|
|
||||||
return ip;
|
|
||||||
}
|
|
||||||
|
|
||||||
// returns bool
|
// returns bool
|
||||||
export function isCloudflareIp(testIpString: string): boolean {
|
function isCloudflareIp(testIpString: string): boolean {
|
||||||
if (!testIpString) return false;
|
if (!testIpString) return false;
|
||||||
const testIp = intoAddress(testIpString);
|
const testIp = intoAddress(testIpString);
|
||||||
if (!testIp) return false;
|
if (!testIp) return false;
|
||||||
return cloudflareIps.some(cf => testIp.isInSubnet(cf));
|
return cloudflareIps.some(cf => testIp.isInSubnet(cf));
|
||||||
}
|
}
|
||||||
|
|
||||||
|
export default isCloudflareIp;
|
||||||
|
|
|
@ -4,7 +4,7 @@
|
||||||
* hook it up to some timer function that causes the least load
|
* hook it up to some timer function that causes the least load
|
||||||
* @flow
|
* @flow
|
||||||
*/
|
*/
|
||||||
import { HOUR, MINUTE } from '../core/constants';
|
import { HOUR } from '../core/constants';
|
||||||
|
|
||||||
import logger from '../core/logger';
|
import logger from '../core/logger';
|
||||||
|
|
||||||
|
|
|
@ -3,9 +3,7 @@
|
||||||
* @flow
|
* @flow
|
||||||
*/
|
*/
|
||||||
|
|
||||||
import dns from 'dns';
|
import isCloudflareIp from './cloudflareip';
|
||||||
import { isCloudflareIp } from './cloudflareip';
|
|
||||||
import nodeIp from 'ip';
|
|
||||||
|
|
||||||
import logger from '../core/logger';
|
import logger from '../core/logger';
|
||||||
|
|
||||||
|
|
|
@ -23,10 +23,14 @@ const config = {
|
||||||
pathinfo: isVerbose,
|
pathinfo: isVerbose,
|
||||||
},
|
},
|
||||||
|
|
||||||
|
resolve: {
|
||||||
|
extensions: ['.js', '.jsx', '.json'],
|
||||||
|
},
|
||||||
|
|
||||||
module: {
|
module: {
|
||||||
rules: [
|
rules: [
|
||||||
{
|
{
|
||||||
test: /\.jsx?$/,
|
test: /\.(js|jsx)$/,
|
||||||
loader: 'babel-loader',
|
loader: 'babel-loader',
|
||||||
include: [
|
include: [
|
||||||
path.resolve(__dirname, '../src'),
|
path.resolve(__dirname, '../src'),
|
||||||
|
|
Loading…
Reference in New Issue
Block a user