Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Live release 27 April 2024 #686

Merged
merged 12 commits into from
Apr 27, 2024
Merged
10 changes: 9 additions & 1 deletion README.md
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,7 @@ Node JS based backend for the [elmaonline site](https://elma.online). The fronte

## Get started

1. Install if needed nodejs (v16.15.0 or later) and yarn (3.x)
1. Install if needed nodejs (v16.15 or later, tested with up to v20.12) and yarn (3.x)

- If you install node using nvm you might need to install corepack manually
`npm install -g corepack`
Expand Down Expand Up @@ -61,6 +61,14 @@ Node JS based backend for the [elmaonline site](https://elma.online). The fronte
├── /upload.js # Endpoints for uploads
```

## Imports

Be aware of newer nodejs versions requiring imports done with file extensions.
- Importing a relative path should always have the extensions: `import { func } from '../utils/funcs.js'`
- index files have to be written explicitly: `import { func } from '../utils/index.js`
- Imports done using aliases doesn't require this as the file extension is added in the alias: `import { func } from '#utils/funcs'`
- See and add aliases in `package.json`

## Setup editor

The project is configured to use eslint and prettier to ensure good coding practices. Make sure you install relevant plugins for your editor.
Expand Down
14 changes: 8 additions & 6 deletions package.json
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@
"packageManager": "[email protected]",
"main": "src/index.js",
"scripts": {
"start": "nodemon --es-module-specifier-resolution=node --no-warnings",
"start": "nodemon --no-warnings",
"lint": "eslint --ignore-path .gitignore --ignore-pattern \"!**/.*\" .",
"commit": "git-cz"
},
Expand Down Expand Up @@ -49,11 +49,13 @@
"prettier": "2.7.1"
},
"imports": {
"#api/*": "./src/api/*",
"#constants/*": "./src/constants/*",
"#data/*": "./src/data/*",
"#middlewares/*": "./src/middlewares/*",
"#utils/*": "./src/utils/*"
"#api/*": "./src/api/*.js",
"#constants/*": "./src/constants/*.js",
"#data/*": "./src/data/*.js",
"#data/models": "./src/data/models/index.js",
"#middlewares/*": "./src/middlewares/*.js",
"#utils/*": "./src/utils/*.js",
"#okevalidator/*": "./src/okevalidator/*.js"
},
"config": {
"commitizen": {
Expand Down
2 changes: 1 addition & 1 deletion src/api/allfinished.js
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,7 @@ import {
Team,
TimeFile,
Time,
} from '../data/models';
} from '#data/models';

const router = express.Router();

Expand Down
4 changes: 2 additions & 2 deletions src/api/battle.js
Original file line number Diff line number Diff line change
Expand Up @@ -12,8 +12,8 @@ import {
Multitime,
Time,
TimeFile,
} from '../data/models';
import { battle2Rec } from './replay';
} from '#data/models';
import { battle2Rec } from './replay.js';

const router = express.Router();

Expand Down
2 changes: 1 addition & 1 deletion src/api/battleleague.js
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,7 @@ import {
Battle,
Level,
Battletime,
} from '../data/models';
} from '#data/models';

const router = express.Router();

Expand Down
2 changes: 1 addition & 1 deletion src/api/besttime.js
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,7 @@ import {
BestMultitime,
LegacyBesttime,
TimeFile,
} from '../data/models';
} from '#data/models';

const router = express.Router();

Expand Down
2 changes: 1 addition & 1 deletion src/api/country.js
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
import express from 'express';
import { Country } from '../data/models';
import { Country } from '#data/models';

const router = express.Router();

Expand Down
8 changes: 4 additions & 4 deletions src/api/crippled.js
Original file line number Diff line number Diff line change
Expand Up @@ -2,10 +2,10 @@ import express from 'express';
import { authContext } from '#utils/auth';
import sequelize, { Op } from 'sequelize';
import { orderBy, invert, groupBy, omit, mapValues } from 'lodash-es';
import { Crippled, Kuski, Level, Time } from '../data/models';
import { getCrippledTypes } from '../data/models/Crippled';
import { query } from '../utils/sequelize';
import { getPackByName } from './levelpack';
import { Crippled, Kuski, Level, Time } from '#data/models';
import { getCrippledTypes } from '#data/models/Crippled';
import { query } from '#utils/sequelize';
import { getPackByName } from './levelpack.js';

const router = express.Router();

Expand Down
6 changes: 3 additions & 3 deletions src/api/cups.js
Original file line number Diff line number Diff line change
Expand Up @@ -2,14 +2,14 @@ import express from 'express';
import neoAsync from 'neo-async';
const { eachSeries } = neoAsync;
import { forEach } from 'lodash-es';
import { dbquery } from '../data/sequelize';
import { dbquery } from '../data/sequelize.js';
import { authContext } from '#utils/auth';
import { format } from 'date-fns';
import moment from 'moment';
import { filterResults, generateEvent, admins } from '#utils/cups';
import { zeroPad } from '#utils/calcs';
import { sendMessage } from '#utils/discord';
import config from '../config';
import config from '../config.js';
import {
SiteCupGroup,
SiteCup,
Expand All @@ -18,7 +18,7 @@ import {
SiteCupTime,
SiteCupBlog,
Team,
} from '../data/models';
} from '#data/models';

const router = express.Router();

Expand Down
56 changes: 29 additions & 27 deletions src/api/index.js
Original file line number Diff line number Diff line change
@@ -1,30 +1,31 @@
import express from 'express';
import ReplayComment from './replay_comment';
import ReplayRating from './replay_rating';
import Replay from './replay';
import Country from './country';
import Register from './register';
import ChatLog from './chatlog';
import Cups from './cups';
import KuskiMap from './kuskimap';
import AllFinished from './allfinished';
import LevelPack from './levelpack';
import Besttime from './besttime';
import Battle from './battle';
import BattleLeague from './battleleague';
import Player from './player';
import Teams from './teams';
import Level from './level';
import Ranking from './ranking';
import Mod from './mod';
import News from './news';
import Donate from './donate';
import Upload from './upload';
import Tag from './tag';
import Notification from './notification';
import LevelStats from './levelstats';
import Crippled from './crippled';
import Recap from './recap';
import ReplayComment from './replay_comment.js';
import ReplayRating from './replay_rating.js';
import Replay from './replay.js';
import Country from './country.js';
import Register from './register.js';
import ChatLog from './chatlog.js';
import Cups from './cups.js';
import KuskiMap from './kuskimap.js';
import AllFinished from './allfinished.js';
import LevelPack from './levelpack.js';
import Besttime from './besttime.js';
import Battle from './battle.js';
import BattleLeague from './battleleague.js';
import Player from './player.js';
import Teams from './teams.js';
import Level from './level.js';
import Ranking from './ranking.js';
import Mod from './mod.js';
import TasWr from './taswr.js';
import News from './news.js';
import Donate from './donate.js';
import Upload from './upload.js';
import Tag from './tag.js';
import Notification from './notification.js';
import LevelStats from './levelstats.js';
import Crippled from './crippled.js';
import Recap from './recap.js';

const router = express.Router();

Expand Down Expand Up @@ -57,6 +58,7 @@ router
.use('/notification', Notification)
.use('/levelstats', LevelStats)
.use('/crippled', Crippled)
.use('/recap', Recap);
.use('/recap', Recap)
.use('/taswr', TasWr);

export default router;
2 changes: 1 addition & 1 deletion src/api/kuskimap.js
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
import express from 'express';
import { authContext } from '#utils/auth';
import { KuskiMap, Kuski } from '../data/models';
import { KuskiMap, Kuski } from '#data/models';

const router = express.Router();

Expand Down
4 changes: 2 additions & 2 deletions src/api/level.js
Original file line number Diff line number Diff line change
Expand Up @@ -11,8 +11,8 @@ import {
Tag,
LevelPackLevel,
Kuski,
} from '../data/models';
import connection from '../data/sequelize';
} from '#data/models';
import connection from '#data/sequelize';
import { fromToTime, searchLimit, searchOffset, like } from '#utils/database';

const router = express.Router();
Expand Down
16 changes: 8 additions & 8 deletions src/api/levelpack.js
Original file line number Diff line number Diff line change
Expand Up @@ -36,14 +36,14 @@ import {
LegacyBesttime,
Battle,
Tag,
} from '../data/models';
import Admin from './levelpack_admin';
import Favourite from './levelpack_favourite';
import Collection from './levelpack_collection';
import { checkSchemaAndBail } from '../middlewares/validate';
import sequelize from '../data/sequelize';
import { query as sqlQuery } from '../utils/sequelize';
import { parseTimeDriven } from '../data/models/PlayStats';
} from '#data/models';
import Admin from './levelpack_admin.js';
import Favourite from './levelpack_favourite.js';
import Collection from './levelpack_collection.js';
import { checkSchemaAndBail } from '#middlewares/validate';
import sequelize from '#data/sequelize';
import { query as sqlQuery } from '#utils/sequelize';
import { parseTimeDriven } from '#data/models/PlayStats';

const router = express.Router();

Expand Down
2 changes: 1 addition & 1 deletion src/api/levelpack_admin.js
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@ import { forEach } from 'lodash-es';
import neoAsync from 'neo-async';
const { eachSeries } = neoAsync;
import { firstEntry, lastEntry, inBetween } from '#utils/sort';
import { LevelPackLevel, LevelPack, Level } from '../data/models';
import { LevelPackLevel, LevelPack, Level } from '#data/models';

const router = express.Router();

Expand Down
2 changes: 1 addition & 1 deletion src/api/levelpack_collection.js
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,7 @@ import {
LevelPackCollection,
LevelPackCollectionPack,
LevelPack,
} from '../data/models';
} from '#data/models';

const router = express.Router();

Expand Down
2 changes: 1 addition & 1 deletion src/api/levelpack_favourite.js
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
import express from 'express';
import { authContext } from '#utils/auth';
import { LevelPackFavourite } from '../data/models';
import { LevelPackFavourite } from '#data/models';

const router = express.Router();

Expand Down
2 changes: 1 addition & 1 deletion src/api/levelstats.js
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@ import express from 'express';
import sequelize from '#data/sequelize';
import { mapValues, isEqual } from 'lodash-es';
import { log } from '#utils/database';
import { LevelStats, Level, Time } from '../data/models';
import { LevelStats, Level, Time } from '#data/models';

const router = express.Router();

Expand Down
4 changes: 2 additions & 2 deletions src/api/mod.js
Original file line number Diff line number Diff line change
Expand Up @@ -14,8 +14,8 @@ import {
ActionLogs,
Error,
Logs,
} from '../data/models';
import config from '../config';
} from '#data/models';
import config from '../config.js';

const router = express.Router();

Expand Down
2 changes: 1 addition & 1 deletion src/api/notification.js
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
import express from 'express';
import { authContext } from '#utils/auth';
import sequelize from 'sequelize';
import { Notification } from '../data/models';
import { Notification } from '#data/models';

const router = express.Router();

Expand Down
2 changes: 1 addition & 1 deletion src/api/player.js
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,7 @@ import {
LevelStats,
Level,
Setting,
} from '../data/models';
} from '#data/models';

const router = express.Router();

Expand Down
2 changes: 1 addition & 1 deletion src/api/ranking.js
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,7 @@ import {
RankingWeekly,
RankingDaily,
RankingHistory,
} from '../data/models';
} from '#data/models';

const router = express.Router();

Expand Down
4 changes: 2 additions & 2 deletions src/api/register.js
Original file line number Diff line number Diff line change
Expand Up @@ -6,8 +6,8 @@ import { Team, Kuski, SiteSetting } from '#data/models';
import { confirmMail, resetMail } from '#utils/email';
import { authContext } from '#utils/auth';
import { sendMessage } from '#utils/discord';
import Discord from './register_discord';
import config from '../config';
import Discord from './register_discord.js';
import config from '../config.js';

const router = express.Router();

Expand Down
4 changes: 2 additions & 2 deletions src/api/register_discord.js
Original file line number Diff line number Diff line change
@@ -1,8 +1,8 @@
import express from 'express';
import { authContext } from '#utils/auth';
import OAuthClient from 'disco-oauth';
import { Setting } from '../data/models';
import config from '../config';
import { Setting } from '#data/models';
import config from '../config.js';

const router = express.Router();
const client = new OAuthClient(
Expand Down
12 changes: 8 additions & 4 deletions src/api/replay.js
Original file line number Diff line number Diff line change
Expand Up @@ -20,8 +20,8 @@ import {
Battletime,
SiteCupTime,
ReplayLog,
} from '../data/models';
import sequelize from '../data/sequelize';
} from '#data/models';
import sequelize from '../data/sequelize.js';

const router = express.Router();

Expand Down Expand Up @@ -582,7 +582,11 @@ const getReplayByUUID = async (replayUUID, Fingerprint, KuskiIndex) => {
}
updateViews(replays, Fingerprint, KuskiIndex, listData);
return replays
.map(uuid => uuid.includes('c-') ? `${uuid.split('-')[0]}-${uuid.split('-')[1]}` : uuid)
.map(uuid =>
uuid.includes('c-')
? `${uuid.split('-')[0]}-${uuid.split('-')[1]}`
: uuid,
)
.map(uuid => combined.find(rec => rec.UUID === uuid));
};

Expand Down Expand Up @@ -711,7 +715,7 @@ const getReplaysByLevelIndex = async LevelIndex => {
const replays = await Replay.findAll({
attributes,
where: { LevelIndex, Unlisted: 0 },
limit: 100,
limit: 1000,
order: [['ReplayIndex', 'DESC']],
include: [
{
Expand Down
2 changes: 1 addition & 1 deletion src/api/replay_rating.js
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
import express from 'express';
import { authContext } from '#utils/auth';
import { omit } from 'lodash-es';
import { ReplayRating } from '../data/models';
import { ReplayRating } from '#data/models';

const router = express.Router();

Expand Down
4 changes: 2 additions & 2 deletions src/api/tag.js
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
import { UniqueConstraintError, ForeignKeyConstraintError } from 'sequelize';
import express from 'express';
import { Tag } from '../data/models';
import requireMod from '../middlewares/requireMod';
import { Tag } from '#data/models';
import requireMod from '#middlewares/requireMod';

const router = express.Router();

Expand Down
Loading