refactor /data directory
This commit is contained in:
parent
40be1ad522
commit
4e45058d46
|
@ -11,7 +11,7 @@ import http from 'http';
|
|||
import url from 'url';
|
||||
import ppfunCaptcha from 'ppfun-captcha';
|
||||
|
||||
import { connect as connectRedis } from './data/redis';
|
||||
import { connect as connectRedis } from './data/redis/client';
|
||||
import { getIPFromRequest } from './utils/ip';
|
||||
import { setCaptchaSolution } from './utils/captcha';
|
||||
import { getRandomString } from './core/utils';
|
||||
|
|
|
@ -8,8 +8,8 @@ import {
|
|||
getData,
|
||||
setStatus,
|
||||
getStatus,
|
||||
} from '../data/models/CanvasCleaner';
|
||||
import RedisCanvas from '../data/models/RedisCanvas';
|
||||
} from '../data/redis/CanvasCleaner';
|
||||
import RedisCanvas from '../data/redis/RedisCanvas';
|
||||
import {
|
||||
getChunkOfPixel,
|
||||
getCornerOfChunk,
|
||||
|
|
|
@ -7,7 +7,7 @@
|
|||
import Sequelize from 'sequelize';
|
||||
import logger from './logger';
|
||||
|
||||
import { Message, Channel } from '../data/models';
|
||||
import { Message, Channel } from '../data/sql';
|
||||
|
||||
const MAX_BUFFER_TIME = 120000;
|
||||
|
||||
|
|
|
@ -3,12 +3,12 @@
|
|||
*/
|
||||
import { Op } from 'sequelize';
|
||||
import logger from './logger';
|
||||
import redis from '../data/redis';
|
||||
import redis from '../data/redis/client';
|
||||
import User from '../data/User';
|
||||
import RateLimiter from '../utils/RateLimiter';
|
||||
import {
|
||||
Channel, RegUser, UserChannel, Message,
|
||||
} from '../data/models';
|
||||
} from '../data/sql';
|
||||
import ChatMessageBuffer from './ChatMessageBuffer';
|
||||
import socketEvents from '../socket/SocketEvents';
|
||||
import { cheapDetector } from './isProxy';
|
||||
|
|
|
@ -7,7 +7,7 @@
|
|||
// Tile creation is allowed to be slow
|
||||
/* eslint-disable no-await-in-loop */
|
||||
|
||||
import RedisCanvas from '../data/models/RedisCanvas';
|
||||
import RedisCanvas from '../data/redis/RedisCanvas';
|
||||
import logger from './logger';
|
||||
import { getChunkOfPixel } from './utils';
|
||||
import { TILE_SIZE } from './constants';
|
||||
|
|
|
@ -14,7 +14,7 @@ import {
|
|||
getEventArea,
|
||||
clearOldEvent,
|
||||
CANVAS_ID,
|
||||
} from '../data/models/Event';
|
||||
} from '../data/redis/Event';
|
||||
import { setCoolDownFactor } from './draw';
|
||||
import Void from './Void';
|
||||
import { protectCanvasArea } from './Image';
|
||||
|
|
|
@ -12,7 +12,7 @@
|
|||
import sharp from 'sharp';
|
||||
import fs from 'fs';
|
||||
|
||||
import RedisCanvas from '../data/models/RedisCanvas';
|
||||
import RedisCanvas from '../data/redis/RedisCanvas';
|
||||
import Palette from './Palette';
|
||||
import { getMaxTiledZoom } from './utils';
|
||||
import { TILE_SIZE, TILE_ZOOM_LEVEL } from './constants';
|
||||
|
|
|
@ -9,7 +9,7 @@ import socketEvents from '../socket/SocketEvents';
|
|||
import PixelUpdate from '../socket/packets/PixelUpdateServer';
|
||||
import { setPixelByOffset } from './setPixel';
|
||||
import { TILE_SIZE } from './constants';
|
||||
import { CANVAS_ID } from '../data/models/Event';
|
||||
import { CANVAS_ID } from '../data/redis/Event';
|
||||
// eslint-disable-next-line import/no-unresolved
|
||||
import canvases from './canvases.json';
|
||||
|
||||
|
|
|
@ -7,12 +7,12 @@
|
|||
|
||||
import sharp from 'sharp';
|
||||
import Sequelize from 'sequelize';
|
||||
import redis from '../data/redis';
|
||||
import redis from '../data/redis/client';
|
||||
|
||||
import { getIPv6Subnet } from '../utils/ip';
|
||||
import { validateCoorRange } from '../utils/validation';
|
||||
import CanvasCleaner from './CanvasCleaner';
|
||||
import { Blacklist, Whitelist, RegUser } from '../data/models';
|
||||
import { Blacklist, Whitelist, RegUser } from '../data/sql';
|
||||
// eslint-disable-next-line import/no-unresolved
|
||||
import canvases from './canvases.json';
|
||||
import {
|
||||
|
|
|
@ -6,7 +6,7 @@ import {
|
|||
getPixelFromChunkOffset,
|
||||
} from './utils';
|
||||
import logger, { pixelLogger } from './logger';
|
||||
import RedisCanvas from '../data/models/RedisCanvas';
|
||||
import RedisCanvas from '../data/redis/RedisCanvas';
|
||||
import {
|
||||
setPixelByOffset,
|
||||
setPixelByCoords,
|
||||
|
|
|
@ -4,9 +4,9 @@
|
|||
|
||||
import fetch from '../utils/proxiedFetch';
|
||||
|
||||
import redis from '../data/redis';
|
||||
import redis from '../data/redis/client';
|
||||
import { getIPv6Subnet } from '../utils/ip';
|
||||
import { Blacklist, Whitelist } from '../data/models';
|
||||
import { Blacklist, Whitelist } from '../data/sql';
|
||||
import { proxyLogger as logger } from './logger';
|
||||
|
||||
import { USE_PROXYCHECK } from './config';
|
||||
|
|
|
@ -12,7 +12,7 @@ import { DailyCron, HourlyCron } from '../utils/cron';
|
|||
import { getTTag } from './ttag';
|
||||
import { GMAIL_USER, GMAIL_PW } from './config';
|
||||
|
||||
import RegUser from '../data/models/RegUser';
|
||||
import { RegUser } from '../data/sql';
|
||||
|
||||
|
||||
/*
|
||||
|
|
|
@ -15,7 +15,7 @@ import { OAuth2Strategy as GoogleStrategy } from 'passport-google-oauth';
|
|||
import logger from './logger';
|
||||
import { sanitizeName } from '../utils/validation';
|
||||
|
||||
import { RegUser } from '../data/models';
|
||||
import { RegUser } from '../data/sql';
|
||||
import User, { regUserQueryInclude as include } from '../data/User';
|
||||
import { auth } from './config';
|
||||
import { compareToHash } from '../utils/hash';
|
||||
|
|
|
@ -4,9 +4,9 @@
|
|||
*/
|
||||
|
||||
import Sequelize from 'sequelize';
|
||||
import Model from '../data/sequelize';
|
||||
import RegUser from '../data/models/RegUser';
|
||||
import { saveDailyTop, loadDailyTop } from '../data/models/prevDayTop';
|
||||
import sequelize from '../data/sql/sequelize';
|
||||
import RegUser from '../data/sql/RegUser';
|
||||
import { saveDailyTop, loadDailyTop } from '../data/redis/PrevDayTop';
|
||||
import logger from './logger';
|
||||
|
||||
import { MINUTE } from './constants';
|
||||
|
@ -34,11 +34,11 @@ class Ranks {
|
|||
async updateRanking() {
|
||||
logger.info('Update pixel rankings');
|
||||
// recalculate ranking column
|
||||
await Model.query(
|
||||
await sequelize.query(
|
||||
// eslint-disable-next-line max-len
|
||||
'SET @r=0; UPDATE Users SET ranking= @r:= (@r + 1) ORDER BY totalPixels DESC;',
|
||||
);
|
||||
await Model.query(
|
||||
await sequelize.query(
|
||||
// eslint-disable-next-line max-len
|
||||
'SET @r=0; UPDATE Users SET dailyRanking= @r:= (@r + 1) ORDER BY dailyTotalPixels DESC;',
|
||||
);
|
||||
|
|
|
@ -11,7 +11,7 @@ import fs from 'fs';
|
|||
import path from 'path';
|
||||
import sharp from 'sharp';
|
||||
|
||||
import RedisCanvas from '../data/models/RedisCanvas';
|
||||
import RedisCanvas from '../data/redis/RedisCanvas';
|
||||
import logger from './logger';
|
||||
import { getChunkOfPixel } from './utils';
|
||||
import Palette from './Palette';
|
||||
|
|
|
@ -4,12 +4,12 @@
|
|||
import expressSession from 'express-session';
|
||||
import RedisStore from '../utils/connectRedis';
|
||||
|
||||
import redis from '../data/redis';
|
||||
import client from '../data/redis/client';
|
||||
import { HOUR, COOKIE_SESSION_NAME } from './constants';
|
||||
import { SESSION_SECRET } from './config';
|
||||
|
||||
|
||||
export const store = new RedisStore({ client: redis });
|
||||
export const store = new RedisStore({ client });
|
||||
|
||||
const session = expressSession({
|
||||
name: COOKIE_SESSION_NAME,
|
||||
|
|
|
@ -2,7 +2,7 @@
|
|||
* Set pixels on canvas.
|
||||
* Pixels get collected in a cache for 5ms and sent to players at once.
|
||||
* */
|
||||
import RedisCanvas from '../data/models/RedisCanvas';
|
||||
import RedisCanvas from '../data/redis/RedisCanvas';
|
||||
import {
|
||||
getChunkOfPixel,
|
||||
getOffsetOfPixel,
|
||||
|
|
|
@ -9,7 +9,7 @@ import { Worker } from 'worker_threads';
|
|||
import logger from './logger';
|
||||
// eslint-disable-next-line import/no-unresolved
|
||||
import canvases from './canvases.json';
|
||||
import RedisCanvas from '../data/models/RedisCanvas';
|
||||
import RedisCanvas from '../data/redis/RedisCanvas';
|
||||
|
||||
import { TILE_FOLDER } from './config';
|
||||
import {
|
||||
|
|
|
@ -8,11 +8,11 @@
|
|||
* */
|
||||
|
||||
import Sequelize from 'sequelize';
|
||||
import redis from './redis';
|
||||
import redis from './redis/client';
|
||||
import logger from '../core/logger';
|
||||
|
||||
import Model from './sequelize';
|
||||
import { RegUser, Channel, UserBlock } from './models';
|
||||
import sequelize from './sql/sequelize';
|
||||
import { RegUser, Channel, UserBlock } from './sql';
|
||||
import { getIPv6Subnet } from '../utils/ip';
|
||||
import { ADMIN_IDS } from '../core/config';
|
||||
|
||||
|
@ -95,13 +95,15 @@ class User {
|
|||
|
||||
static async name2Id(name: string) {
|
||||
try {
|
||||
const userq = await Model.query('SELECT id FROM Users WHERE name = $1',
|
||||
const userq = await sequelize.query(
|
||||
'SELECT id FROM Users WHERE name = $1',
|
||||
{
|
||||
bind: [name],
|
||||
type: Sequelize.QueryTypes.SELECT,
|
||||
raw: true,
|
||||
plain: true,
|
||||
});
|
||||
},
|
||||
);
|
||||
return userq.id;
|
||||
} catch {
|
||||
return null;
|
||||
|
@ -202,9 +204,9 @@ class User {
|
|||
}
|
||||
|
||||
async getWait(canvasId: number): Promise<?number> {
|
||||
let ttl: number = await redis.pTTL(`cd:${canvasId}:ip:${this.ipSub}`);
|
||||
let ttl = await redis.pTTL(`cd:${canvasId}:ip:${this.ipSub}`);
|
||||
if (this.id != null) {
|
||||
const ttlid: number = await redis.pTTL(
|
||||
const ttlid = await redis.pTTL(
|
||||
`cd:${canvasId}:id:${this.id}`,
|
||||
);
|
||||
ttl = Math.max(ttl, ttlid);
|
||||
|
@ -238,7 +240,7 @@ class User {
|
|||
return this.regUser.totalPixels;
|
||||
}
|
||||
try {
|
||||
const userq = await Model.query(
|
||||
const userq = await sequelize.query(
|
||||
'SELECT totalPixels FROM Users WHERE id = $1',
|
||||
{
|
||||
bind: [id],
|
||||
|
|
|
@ -2,7 +2,7 @@
|
|||
* storing Event data
|
||||
*/
|
||||
|
||||
import redis from '../redis';
|
||||
import client from './client';
|
||||
import logger from '../../core/logger';
|
||||
|
||||
const DATA_KEY = 'clr:dat';
|
||||
|
@ -14,7 +14,7 @@ const STAT_KEY = 'clr:sta';
|
|||
* (check core/CanvasCleaner for the meaning)
|
||||
*/
|
||||
export async function getData() {
|
||||
const data = await redis.get(DATA_KEY);
|
||||
const data = await client.get(DATA_KEY);
|
||||
if (data) {
|
||||
const parsedData = data.toString().split(':');
|
||||
for (let i = 0; i < parsedData.length - 1; i += 1) {
|
||||
|
@ -56,7 +56,7 @@ export async function setData(canvasId, x, y, u, v, methodName) {
|
|||
);
|
||||
return null;
|
||||
}
|
||||
return redis.set(DATA_KEY, dataStr);
|
||||
return client.set(DATA_KEY, dataStr);
|
||||
}
|
||||
|
||||
/*
|
||||
|
@ -66,7 +66,7 @@ export async function setData(canvasId, x, y, u, v, methodName) {
|
|||
* running: boolean if filter is running
|
||||
*/
|
||||
export async function getStatus() {
|
||||
const stat = await redis.get(STAT_KEY);
|
||||
const stat = await client.get(STAT_KEY);
|
||||
if (stat) {
|
||||
const parsedStat = stat.toString().split(':');
|
||||
if (parsedStat.length !== 2) {
|
||||
|
@ -103,5 +103,5 @@ export async function setStatus(cIter, running) {
|
|||
);
|
||||
return null;
|
||||
}
|
||||
return redis.set(STAT_KEY, statString);
|
||||
return client.set(STAT_KEY, statString);
|
||||
}
|
|
@ -8,7 +8,7 @@ import { commandOptions } from 'redis';
|
|||
// its ok if its slow
|
||||
/* eslint-disable no-await-in-loop */
|
||||
|
||||
import redis from '../redis';
|
||||
import client from './client';
|
||||
import logger from '../../core/logger';
|
||||
import RedisCanvas from './RedisCanvas';
|
||||
|
||||
|
@ -27,10 +27,10 @@ export const CANVAS_ID = '0';
|
|||
* 2 = lost
|
||||
*/
|
||||
export function setSuccess(success) {
|
||||
return redis.set(EVENT_SUCCESS_KEY, success);
|
||||
return client.set(EVENT_SUCCESS_KEY, success);
|
||||
}
|
||||
export async function getSuccess() {
|
||||
const success = await redis.get(EVENT_SUCCESS_KEY);
|
||||
const success = await client.get(EVENT_SUCCESS_KEY);
|
||||
return (success) ? parseInt(success, 10) : 0;
|
||||
}
|
||||
|
||||
|
@ -38,7 +38,7 @@ export async function getSuccess() {
|
|||
* @return time till next event in seconds
|
||||
*/
|
||||
export async function nextEvent() {
|
||||
const timestamp = await redis.get(EVENT_TIMESTAMP_KEY);
|
||||
const timestamp = await client.get(EVENT_TIMESTAMP_KEY);
|
||||
if (timestamp) {
|
||||
return Number(timestamp.toString());
|
||||
}
|
||||
|
@ -49,7 +49,7 @@ export async function nextEvent() {
|
|||
* @return cell of chunk coordinates of event
|
||||
*/
|
||||
export async function getEventArea() {
|
||||
const pos = await redis.get(EVENT_POSITION_KEY);
|
||||
const pos = await client.get(EVENT_POSITION_KEY);
|
||||
if (pos) {
|
||||
return pos.toString().split(':').map((z) => Number(z));
|
||||
}
|
||||
|
@ -69,7 +69,7 @@ export async function clearOldEvent() {
|
|||
for (let ic = i - 1; ic <= i + 1; ic += 1) {
|
||||
try {
|
||||
const chunkKey = `${EVENT_BACKUP_PREFIX}:${ic}:${jc}`;
|
||||
const chunk = await redis.get(
|
||||
const chunk = await client.get(
|
||||
commandOptions({ returnBuffers: true }),
|
||||
chunkKey,
|
||||
);
|
||||
|
@ -92,7 +92,7 @@ export async function clearOldEvent() {
|
|||
);
|
||||
await RedisCanvas.setChunk(ic, jc, chunk, CANVAS_ID);
|
||||
}
|
||||
await redis.del(chunkKey);
|
||||
await client.del(chunkKey);
|
||||
} catch (error) {
|
||||
logger.error(
|
||||
// eslint-disable-next-line max-len
|
||||
|
@ -101,7 +101,7 @@ export async function clearOldEvent() {
|
|||
}
|
||||
}
|
||||
}
|
||||
await redis.del(EVENT_POSITION_KEY);
|
||||
await client.del(EVENT_POSITION_KEY);
|
||||
}
|
||||
}
|
||||
|
||||
|
@ -128,10 +128,10 @@ export async function setNextEvent(minutes, i, j) {
|
|||
chunk = Buffer.allocUnsafe(1);
|
||||
}
|
||||
const chunkKey = `${EVENT_BACKUP_PREFIX}:${ic}:${jc}`;
|
||||
await redis.set(chunkKey, chunk);
|
||||
await client.set(chunkKey, chunk);
|
||||
}
|
||||
}
|
||||
await redis.set(EVENT_POSITION_KEY, `${i}:${j}`);
|
||||
await client.set(EVENT_POSITION_KEY, `${i}:${j}`);
|
||||
const timestamp = Date.now() + minutes * 60 * 1000;
|
||||
await redis.set(EVENT_TIMESTAMP_KEY, timestamp);
|
||||
await client.set(EVENT_TIMESTAMP_KEY, timestamp);
|
||||
}
|
|
@ -2,7 +2,7 @@
|
|||
* saving and loading the top 10 of the previous day
|
||||
*/
|
||||
|
||||
import redis from '../redis';
|
||||
import client from './client';
|
||||
import logger from '../../core/logger';
|
||||
|
||||
const PREV_DAILY_TOP_KEY = 'prevtop';
|
||||
|
@ -15,7 +15,7 @@ export async function saveDailyTop(dailyRanking) {
|
|||
const top10 = dailyRanking.slice(0, 10).map((user) => user.id);
|
||||
const jsonTop = JSON.stringify(top10);
|
||||
logger.info(`Saving current daily top 10 into redis: ${jsonTop}`);
|
||||
await redis.set(PREV_DAILY_TOP_KEY, jsonTop);
|
||||
await client.set(PREV_DAILY_TOP_KEY, jsonTop);
|
||||
return top10;
|
||||
}
|
||||
|
||||
|
@ -24,7 +24,7 @@ export async function saveDailyTop(dailyRanking) {
|
|||
* @return Promis<Array> Array of user IDs of the top 10
|
||||
*/
|
||||
export async function loadDailyTop() {
|
||||
const jsonTop = await redis.get(PREV_DAILY_TOP_KEY);
|
||||
const jsonTop = await client.get(PREV_DAILY_TOP_KEY);
|
||||
logger.info(`Loaded current daily top 10 into redis: ${jsonTop}`);
|
||||
return (jsonTop) ? JSON.parse(jsonTop) : [];
|
||||
}
|
|
@ -4,7 +4,7 @@
|
|||
import { commandOptions } from 'redis';
|
||||
|
||||
import { getChunkOfPixel, getOffsetOfPixel } from '../../core/utils';
|
||||
import redis from '../redis';
|
||||
import client from './client';
|
||||
|
||||
|
||||
const UINT_SIZE = 'u8';
|
||||
|
@ -38,7 +38,7 @@ class RedisCanvas {
|
|||
// this key is also hardcoded into
|
||||
// core/tilesBackup.js
|
||||
const key = `ch:${canvasId}:${i}:${j}`;
|
||||
let chunk = await redis.get(
|
||||
let chunk = await client.get(
|
||||
commandOptions({ returnBuffers: true }),
|
||||
key,
|
||||
);
|
||||
|
@ -51,14 +51,14 @@ class RedisCanvas {
|
|||
|
||||
static async setChunk(i, j, chunk, canvasId) {
|
||||
const key = `ch:${canvasId}:${i}:${j}`;
|
||||
await redis.set(key, Buffer.from(chunk.buffer));
|
||||
await client.set(key, Buffer.from(chunk.buffer));
|
||||
RedisCanvas.execChunkChangeCallback(canvasId, [i, j]);
|
||||
return true;
|
||||
}
|
||||
|
||||
static async delChunk(i, j, canvasId) {
|
||||
const key = `ch:${canvasId}:${i}:${j}`;
|
||||
await redis.del(key);
|
||||
await client.del(key);
|
||||
RedisCanvas.execChunkChangeCallback(canvasId, [i, j]);
|
||||
return true;
|
||||
}
|
||||
|
@ -76,7 +76,7 @@ class RedisCanvas {
|
|||
* TODO what if chunk does not exist?
|
||||
*/
|
||||
if (!RedisCanvas.multi) {
|
||||
RedisCanvas.multi = redis.multi();
|
||||
RedisCanvas.multi = client.multi();
|
||||
setTimeout(RedisCanvas.flushPixels, 100);
|
||||
}
|
||||
RedisCanvas.multi.addCommand(
|
||||
|
@ -124,7 +124,7 @@ class RedisCanvas {
|
|||
UINT_SIZE,
|
||||
`#${offset}`,
|
||||
];
|
||||
const result = await redis.sendCommand(args);
|
||||
const result = await client.sendCommand(args);
|
||||
if (!result) return null;
|
||||
const color = result[0];
|
||||
return color;
|
|
@ -5,9 +5,9 @@
|
|||
|
||||
import { createClient } from 'redis';
|
||||
|
||||
import { REDIS_URL } from '../core/config';
|
||||
import { REDIS_URL } from '../../core/config';
|
||||
|
||||
const redis = createClient(REDIS_URL.startsWith('redis://')
|
||||
const client = createClient(REDIS_URL.startsWith('redis://')
|
||||
? {
|
||||
url: REDIS_URL,
|
||||
}
|
||||
|
@ -21,7 +21,7 @@ const redis = createClient(REDIS_URL.startsWith('redis://')
|
|||
export const connect = async () => {
|
||||
// eslint-disable-next-line no-console
|
||||
console.log(`Connecting to redis server at ${REDIS_URL}`);
|
||||
await redis.connect();
|
||||
await client.connect();
|
||||
};
|
||||
|
||||
export default redis;
|
||||
export default client;
|
|
@ -2,17 +2,16 @@
|
|||
*
|
||||
* https://github.com/sequelize/sequelize/issues/1485#issuecomment-243822779
|
||||
*
|
||||
* @flow
|
||||
*/
|
||||
|
||||
import DataType from 'sequelize';
|
||||
import Model from '../sequelize';
|
||||
import { DataTypes } from 'sequelize';
|
||||
import sequelize from './sequelize';
|
||||
|
||||
|
||||
const Blacklist = Model.define('Blacklist', {
|
||||
const Blacklist = sequelize.define('Blacklist', {
|
||||
|
||||
ip: {
|
||||
type: DataType.CHAR(39),
|
||||
type: DataTypes.CHAR(39),
|
||||
allowNull: false,
|
||||
primaryKey: true,
|
||||
},
|
|
@ -2,25 +2,23 @@
|
|||
*
|
||||
* Database layout for Chat Channels
|
||||
*
|
||||
* @flow
|
||||
*
|
||||
*/
|
||||
|
||||
import DataType from 'sequelize';
|
||||
import { DataTypes, Utils } from 'sequelize';
|
||||
|
||||
import Model from '../sequelize';
|
||||
import sequelize from './sequelize';
|
||||
import RegUser from './RegUser';
|
||||
|
||||
const Channel = Model.define('Channel', {
|
||||
const Channel = sequelize.define('Channel', {
|
||||
// Channel ID
|
||||
id: {
|
||||
type: DataType.INTEGER.UNSIGNED,
|
||||
type: DataTypes.INTEGER.UNSIGNED,
|
||||
autoIncrement: true,
|
||||
primaryKey: true,
|
||||
},
|
||||
|
||||
name: {
|
||||
type: `${DataType.CHAR(32)} CHARSET utf8mb4 COLLATE utf8mb4_unicode_ci`,
|
||||
type: `${DataTypes.CHAR(32)} CHARSET utf8mb4 COLLATE utf8mb4_unicode_ci`,
|
||||
allowNull: true,
|
||||
},
|
||||
|
||||
|
@ -31,14 +29,14 @@ const Channel = Model.define('Channel', {
|
|||
* 3: faction (not implemented)
|
||||
*/
|
||||
type: {
|
||||
type: DataType.TINYINT,
|
||||
type: DataTypes.TINYINT,
|
||||
allowNull: false,
|
||||
defaultValue: 0,
|
||||
},
|
||||
|
||||
lastMessage: {
|
||||
type: DataType.DATE,
|
||||
defaultValue: DataType.literal('CURRENT_TIMESTAMP'),
|
||||
type: DataTypes.DATE,
|
||||
defaultValue: new Utils.Literal('CURRENT_TIMESTAMP'),
|
||||
allowNull: false,
|
||||
},
|
||||
}, {
|
|
@ -4,33 +4,33 @@
|
|||
*
|
||||
*/
|
||||
|
||||
import DataType from 'sequelize';
|
||||
import Model from '../sequelize';
|
||||
import { DataTypes } from 'sequelize';
|
||||
import sequelize from './sequelize';
|
||||
import Channel from './Channel';
|
||||
import RegUser from './RegUser';
|
||||
|
||||
const Message = Model.define('Message', {
|
||||
const Message = sequelize.define('Message', {
|
||||
// Message ID
|
||||
id: {
|
||||
type: DataType.INTEGER.UNSIGNED,
|
||||
type: DataTypes.INTEGER.UNSIGNED,
|
||||
autoIncrement: true,
|
||||
primaryKey: true,
|
||||
},
|
||||
|
||||
name: {
|
||||
type: `${DataType.CHAR(32)} CHARSET utf8mb4 COLLATE utf8mb4_unicode_ci`,
|
||||
type: `${DataTypes.CHAR(32)} CHARSET utf8mb4 COLLATE utf8mb4_unicode_ci`,
|
||||
defaultValue: 'mx',
|
||||
allowNull: false,
|
||||
},
|
||||
|
||||
flag: {
|
||||
type: DataType.CHAR(2),
|
||||
type: DataTypes.CHAR(2),
|
||||
defaultValue: 'xx',
|
||||
allowNull: false,
|
||||
},
|
||||
|
||||
message: {
|
||||
type: `${DataType.CHAR(200)} CHARSET utf8mb4 COLLATE utf8mb4_unicode_ci`,
|
||||
type: `${DataTypes.CHAR(200)} CHARSET utf8mb4 COLLATE utf8mb4_unicode_ci`,
|
||||
allowNull: false,
|
||||
},
|
||||
}, {
|
|
@ -3,107 +3,106 @@
|
|||
*
|
||||
* This is the database of the data for registered Users
|
||||
*
|
||||
* @flow
|
||||
*/
|
||||
|
||||
import DataType from 'sequelize';
|
||||
import Model from '../sequelize';
|
||||
import { DataTypes } from 'sequelize';
|
||||
import sequelize from './sequelize';
|
||||
|
||||
import { generateHash } from '../../utils/hash';
|
||||
|
||||
|
||||
const RegUser = Model.define('User', {
|
||||
const RegUser = sequelize.define('User', {
|
||||
id: {
|
||||
type: DataType.INTEGER.UNSIGNED,
|
||||
type: DataTypes.INTEGER.UNSIGNED,
|
||||
autoIncrement: true,
|
||||
primaryKey: true,
|
||||
},
|
||||
|
||||
email: {
|
||||
type: DataType.CHAR(40),
|
||||
type: DataTypes.CHAR(40),
|
||||
allowNull: true,
|
||||
},
|
||||
|
||||
name: {
|
||||
type: `${DataType.CHAR(32)} CHARSET utf8mb4 COLLATE utf8mb4_unicode_ci`,
|
||||
type: `${DataTypes.CHAR(32)} CHARSET utf8mb4 COLLATE utf8mb4_unicode_ci`,
|
||||
allowNull: false,
|
||||
},
|
||||
|
||||
// currently just moderator
|
||||
roles: {
|
||||
type: DataType.TINYINT,
|
||||
type: DataTypes.TINYINT,
|
||||
allowNull: false,
|
||||
defaultValue: 0,
|
||||
},
|
||||
|
||||
// null if external oauth authentification
|
||||
password: {
|
||||
type: DataType.CHAR(60),
|
||||
type: DataTypes.CHAR(60),
|
||||
allowNull: true,
|
||||
},
|
||||
|
||||
totalPixels: {
|
||||
type: DataType.INTEGER.UNSIGNED,
|
||||
type: DataTypes.INTEGER.UNSIGNED,
|
||||
allowNull: false,
|
||||
defaultValue: 0,
|
||||
},
|
||||
|
||||
dailyTotalPixels: {
|
||||
type: DataType.INTEGER.UNSIGNED,
|
||||
type: DataTypes.INTEGER.UNSIGNED,
|
||||
allowNull: false,
|
||||
defaultValue: 0,
|
||||
},
|
||||
|
||||
ranking: {
|
||||
type: DataType.INTEGER.UNSIGNED,
|
||||
type: DataTypes.INTEGER.UNSIGNED,
|
||||
allowNull: true,
|
||||
},
|
||||
|
||||
dailyRanking: {
|
||||
type: DataType.INTEGER.UNSIGNED,
|
||||
type: DataTypes.INTEGER.UNSIGNED,
|
||||
allowNull: true,
|
||||
},
|
||||
|
||||
// mail and Minecraft verified
|
||||
verified: {
|
||||
type: DataType.TINYINT,
|
||||
type: DataTypes.TINYINT,
|
||||
allowNull: false,
|
||||
defaultValue: false,
|
||||
},
|
||||
|
||||
// currently just blockDm
|
||||
blocks: {
|
||||
type: DataType.TINYINT,
|
||||
type: DataTypes.TINYINT,
|
||||
allowNull: false,
|
||||
defaultValue: 0,
|
||||
},
|
||||
|
||||
discordid: {
|
||||
type: DataType.CHAR(18),
|
||||
type: DataTypes.CHAR(18),
|
||||
allowNull: true,
|
||||
},
|
||||
|
||||
redditid: {
|
||||
type: DataType.CHAR(10),
|
||||
type: DataTypes.CHAR(10),
|
||||
allowNull: true,
|
||||
},
|
||||
|
||||
// when mail verification got requested,
|
||||
// used for purging unverified accounts
|
||||
verificationReqAt: {
|
||||
type: DataType.DATE,
|
||||
type: DataTypes.DATE,
|
||||
allowNull: true,
|
||||
},
|
||||
|
||||
// flag == country code
|
||||
flag: {
|
||||
type: DataType.CHAR(2),
|
||||
type: DataTypes.CHAR(2),
|
||||
defaultValue: 'xx',
|
||||
allowNull: false,
|
||||
},
|
||||
|
||||
lastLogIn: {
|
||||
type: DataType.DATE,
|
||||
type: DataTypes.DATE,
|
||||
allowNull: true,
|
||||
},
|
||||
}, {
|
|
@ -3,13 +3,11 @@
|
|||
* Junction table for User -> Blocked User
|
||||
* Relations defined in ./index.js
|
||||
*
|
||||
* @flow
|
||||
*
|
||||
*/
|
||||
|
||||
import Model from '../sequelize';
|
||||
import sequelize from './sequelize';
|
||||
|
||||
const UserBlock = Model.define('UserBlock', {
|
||||
const UserBlock = sequelize.define('UserBlock', {
|
||||
}, {
|
||||
timestamps: false,
|
||||
});
|
|
@ -4,16 +4,14 @@
|
|||
* A channel can be anything,
|
||||
* Group, Public Chat, DM, etc.
|
||||
*
|
||||
* @flow
|
||||
*
|
||||
*/
|
||||
|
||||
import DataType from 'sequelize';
|
||||
import Model from '../sequelize';
|
||||
import { DataTypes } from 'sequelize';
|
||||
import sequelize from './sequelize';
|
||||
|
||||
const UserChannel = Model.define('UserChannel', {
|
||||
const UserChannel = sequelize.define('UserChannel', {
|
||||
lastRead: {
|
||||
type: DataType.DATE,
|
||||
type: DataTypes.DATE,
|
||||
allowNull: true,
|
||||
},
|
||||
}, {
|
|
@ -2,18 +2,16 @@
|
|||
* Created by HF
|
||||
*
|
||||
* https://github.com/sequelize/sequelize/issues/1485#issuecomment-243822779
|
||||
*
|
||||
* @flow
|
||||
*/
|
||||
|
||||
import DataType from 'sequelize';
|
||||
import Model from '../sequelize';
|
||||
import { DataTypes } from 'sequelize';
|
||||
import sequelize from './sequelize';
|
||||
|
||||
|
||||
const Whitelist = Model.define('Whitelist', {
|
||||
const Whitelist = sequelize.define('Whitelist', {
|
||||
|
||||
ip: {
|
||||
type: DataType.CHAR(39),
|
||||
type: DataTypes.CHAR(39),
|
||||
allowNull: false,
|
||||
primaryKey: true,
|
||||
},
|
|
@ -1,4 +1,3 @@
|
|||
import sequelize from '../sequelize';
|
||||
import Blacklist from './Blacklist';
|
||||
import Whitelist from './Whitelist';
|
||||
import RegUser from './RegUser';
|
||||
|
@ -36,11 +35,6 @@ RegUser.belongsToMany(RegUser, {
|
|||
foreignKey: 'buid',
|
||||
});
|
||||
|
||||
function sync(...args) {
|
||||
return sequelize.sync(...args);
|
||||
}
|
||||
|
||||
export default { sync };
|
||||
export {
|
||||
Whitelist,
|
||||
Blacklist,
|
|
@ -1,14 +1,13 @@
|
|||
/**
|
||||
*
|
||||
* @flow
|
||||
*/
|
||||
|
||||
import Sequelize from 'sequelize';
|
||||
|
||||
import logger from '../core/logger';
|
||||
import logger from '../../core/logger';
|
||||
import {
|
||||
MYSQL_HOST, MYSQL_DATABASE, MYSQL_USER, MYSQL_PW, LOG_MYSQL,
|
||||
} from '../core/config';
|
||||
} from '../../core/config';
|
||||
|
||||
const sequelize = new Sequelize(MYSQL_DATABASE, MYSQL_USER, MYSQL_PW, {
|
||||
host: MYSQL_HOST,
|
|
@ -1,7 +1,7 @@
|
|||
import express from 'express';
|
||||
|
||||
import logger from '../core/logger';
|
||||
import RegUser from '../data/models/RegUser';
|
||||
import { RegUser } from '../data/sql';
|
||||
import { getIPFromRequest } from '../utils/ip';
|
||||
import { compareToHash } from '../utils/hash';
|
||||
import { APISOCKET_KEY } from '../core/config';
|
||||
|
|
|
@ -7,7 +7,7 @@
|
|||
import type { Request, Response } from 'express';
|
||||
|
||||
import socketEvents from '../../../socket/SocketEvents';
|
||||
import { RegUser } from '../../../data/models';
|
||||
import { RegUser } from '../../../data/sql';
|
||||
import { validateName } from '../../../utils/validation';
|
||||
|
||||
async function validate(oldname, name) {
|
||||
|
|
|
@ -6,7 +6,7 @@
|
|||
|
||||
import type { Request, Response } from 'express';
|
||||
|
||||
import { RegUser } from '../../../data/models';
|
||||
import { RegUser } from '../../../data/sql';
|
||||
import { validatePassword } from '../../../utils/validation';
|
||||
import { compareToHash } from '../../../utils/hash';
|
||||
|
||||
|
|
|
@ -8,7 +8,7 @@ import type { Request, Response } from 'express';
|
|||
import Sequelize from 'sequelize';
|
||||
|
||||
import logger from '../../../core/logger';
|
||||
import { RegUser } from '../../../data/models';
|
||||
import { RegUser } from '../../../data/sql';
|
||||
import mailProvider from '../../../core/mail';
|
||||
import getMe from '../../../core/me';
|
||||
import { getIPFromRequest, getHostFromRequest } from '../../../utils/ip';
|
||||
|
|
|
@ -9,7 +9,7 @@ import type { Request, Response } from 'express';
|
|||
|
||||
import logger from '../../core/logger';
|
||||
import socketEvents from '../../socket/SocketEvents';
|
||||
import { RegUser, UserBlock, Channel } from '../../data/models';
|
||||
import { RegUser, UserBlock, Channel } from '../../data/sql';
|
||||
|
||||
async function block(req: Request, res: Response) {
|
||||
let userId = parseInt(req.body.userId, 10);
|
||||
|
|
|
@ -9,8 +9,8 @@ import type { Request, Response } from 'express';
|
|||
|
||||
import logger from '../../core/logger';
|
||||
import { ChatProvider } from '../../core/ChatProvider';
|
||||
import { Channel, RegUser } from '../../data/models';
|
||||
import { isUserBlockedBy } from '../../data/models/UserBlock';
|
||||
import { Channel, RegUser } from '../../data/sql';
|
||||
import { isUserBlockedBy } from '../../data/sql/UserBlock';
|
||||
|
||||
async function startDm(req: Request, res: Response) {
|
||||
let userId = parseInt(req.body.userId, 10);
|
||||
|
|
|
@ -5,7 +5,7 @@
|
|||
*/
|
||||
|
||||
import etag from 'etag';
|
||||
import RedisCanvas from '../data/models/RedisCanvas';
|
||||
import RedisCanvas from '../data/redis/RedisCanvas';
|
||||
import logger from '../core/logger';
|
||||
|
||||
const chunkEtags = new Map();
|
||||
|
|
|
@ -12,7 +12,7 @@ import logger from '../core/logger';
|
|||
import getPasswordResetHtml from '../ssr-components/PasswordReset';
|
||||
|
||||
import mailProvider from '../core/mail';
|
||||
import { RegUser } from '../data/models';
|
||||
import { RegUser } from '../data/sql';
|
||||
|
||||
|
||||
const router = express.Router();
|
||||
|
|
|
@ -11,8 +11,8 @@ import http from 'http';
|
|||
import forceGC from './core/forceGC';
|
||||
import logger from './core/logger';
|
||||
import rankings from './core/ranking';
|
||||
import models from './data/models';
|
||||
import { connect as connectRedis } from './data/redis';
|
||||
import sequelize from './data/sql/sequelize';
|
||||
import { connect as connectRedis } from './data/redis/client';
|
||||
import routes from './routes';
|
||||
import chatProvider from './core/ChatProvider';
|
||||
import RpgEvent from './core/RpgEvent';
|
||||
|
@ -85,9 +85,9 @@ const rpgEvent = new RpgEvent();
|
|||
// ip config
|
||||
// -----------------------------------------------------------------------------
|
||||
// sync sql models
|
||||
models.sync({ alter: { drop: false } })
|
||||
sequelize.sync({ alter: { drop: false } })
|
||||
// connect to redis
|
||||
.then(() => connectRedis())
|
||||
.then(connectRedis)
|
||||
.then(() => {
|
||||
rankings.initialize();
|
||||
chatProvider.initialize();
|
||||
|
|
|
@ -12,7 +12,7 @@ import WebSocket from 'ws';
|
|||
|
||||
import socketEvents from './SocketEvents';
|
||||
import chatProvider from '../core/ChatProvider';
|
||||
import RegUser from '../data/models/RegUser';
|
||||
import { RegUser } from '../data/sql';
|
||||
import { getIPFromRequest } from '../utils/ip';
|
||||
import { setPixelByCoords } from '../core/setPixel';
|
||||
import logger from '../core/logger';
|
||||
|
|
|
@ -4,7 +4,7 @@
|
|||
*/
|
||||
|
||||
import logger from '../core/logger';
|
||||
import redis from '../data/redis';
|
||||
import redis from '../data/redis/client';
|
||||
import { getIPv6Subnet } from './ip';
|
||||
import {
|
||||
CAPTCHA_URL,
|
||||
|
|
|
@ -6,7 +6,7 @@
|
|||
|
||||
import { isMainThread, parentPort } from 'worker_threads';
|
||||
|
||||
import { connect as connectRedis } from '../data/redis';
|
||||
import { connect as connectRedis } from '../data/redis/client';
|
||||
import {
|
||||
createZoomTileFromChunk,
|
||||
createZoomedTile,
|
||||
|
|
Loading…
Reference in New Issue
Block a user