Skip to content

Commit

Permalink
Fix eslint errors (#55)
Browse files Browse the repository at this point in the history
This PR fixes the errors with eslint.

---------

Signed-off-by: dependabot[bot] <[email protected]>
Co-authored-by: dependabot[bot] <49699333+dependabot[bot]@users.noreply.github.com>
  • Loading branch information
larsenv and dependabot[bot] authored Oct 11, 2023
1 parent 9ebf64a commit ec5441f
Show file tree
Hide file tree
Showing 8 changed files with 74 additions and 82 deletions.
2 changes: 1 addition & 1 deletion package-lock.json

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

2 changes: 1 addition & 1 deletion package.json
Original file line number Diff line number Diff line change
Expand Up @@ -56,7 +56,7 @@
"gulp": "^4.0.2",
"iron-session": "6.3.1",
"lru-cache": "7.14.1",
"next": "^13.1.1",
"next": "^13.5.4",
"next-connect": "0.13.0",
"next-seo": "5.15.0",
"nextjs-progressbar": "0.0.16",
Expand Down
3 changes: 1 addition & 2 deletions src/components/shared/AppFooter.jsx
Original file line number Diff line number Diff line change
Expand Up @@ -14,8 +14,7 @@ function AppFooter() {
href="https://rc24.xyz"
rel="external noopener noreferrer"
target="_blank"
>
</a>{' '}
/>{' '}
-{' '}
<Link href="/credits" className="text-muted">
Credits
Expand Down
2 changes: 1 addition & 1 deletion src/components/user/UserInformationCard.jsx
Original file line number Diff line number Diff line change
Expand Up @@ -25,7 +25,7 @@ function UserInformationCard({ user, isLoggedIn }) {
<li>
<strong>Name:</strong> {user.name_on_riitag}
</li>
{dayjs(user.created_at).format(DATE_FORMAT) !== "4th August 2022" ? (<li><strong>Registered:</strong>{' '} {dayjs(user.created_at).format(DATE_FORMAT)}</li>) : ("")}
{dayjs(user.created_at).format(DATE_FORMAT) === "4th August 2022" ? ("") : (<li><strong>Registered:</strong>{' '} {dayjs(user.created_at).format(DATE_FORMAT)}</li>)}
<li>
<strong>Overlay:</strong>{' '}
{OVERLAYS.find((overlay) => overlay.value === user.overlay).label}
Expand Down
44 changes: 18 additions & 26 deletions src/lib/riitag/cover.js
Original file line number Diff line number Diff line change
Expand Up @@ -2,13 +2,10 @@ import fs from 'node:fs';
import path from 'node:path';
import COVER_TYPE from '@/lib/constants/coverType';
import CONSOLE from '@/lib/constants/console';
import { CACHE } from '@/lib/constants/filePaths';
import { DATA } from '@/lib/constants/filePaths';
import { CACHE, DATA } from '@/lib/constants/filePaths';
import { exists, saveFile } from '@/lib/utils/fileUtils';
import { isBlank } from '@/lib/utils/utils';
import logger from '@/lib/logger';
import { getUserByRandKey } from '@/lib/utils/databaseUtils';
const xml2js = require('xml2js');
import xml2js from 'xml2js';

function getCoverUrl(gameConsole, coverType, region, gameId, extension) {
return `https://art.gametdb.com/${gameConsole}/${coverType}/${region}/${gameId}.${extension}`;
Expand Down Expand Up @@ -67,21 +64,27 @@ function get3DSGameRegion(gameId) {
}
}

export async function getSwitchGameRegion(gameId) {
const ids = JSON.parse(
await fs.promises.readFile(path.resolve(DATA.IDS, 'switchtdb.json'), 'utf8')
);
async function findRegionByGameId(games, gameId) {
let regions = null;
games.forEach(game => {
if (game.id[0] === gameId) {
regions = game.region[0].split(',').map(region => region.trim());
}
});
return regions;
}

export async function getSwitchGameRegion(gameId) {
try {
const data = await fs.promises.readFile(
path.resolve(DATA.IDS, 'switchtdb.xml'),
'utf-8'
'utf8'
);

const result = await new Promise((resolve, reject) => {
xml2js.parseString(data, (parseErr, parseResult) => {
if (parseErr) {
reject(parseErr);
xml2js.parseString(data, (parseError, parseResult) => {
if (parseError) {
reject(parseError);
} else {
resolve(parseResult);
}
Expand All @@ -90,17 +93,7 @@ export async function getSwitchGameRegion(gameId) {

const games = result.datafile.game;

async function findRegionByGameId(gameId) {
let regions = null;
games.forEach(game => {
if (game.id[0] === gameId) {
regions = game.region[0].split(',').map(region => region.trim());
}
});
return regions;
}

const region = await findRegionByGameId(gameId);
const region = await findRegionByGameId(games, gameId);

for (const gameRegion of region) {
// Europe
Expand Down Expand Up @@ -142,8 +135,7 @@ export async function getSwitchGameRegion(gameId) {
}

return null; // Game ID not found
} catch (error) {
console.error(error);
} catch {
return null;
}
}
Expand Down
14 changes: 6 additions & 8 deletions src/lib/utils/downloadSwitchTDB.js
Original file line number Diff line number Diff line change
@@ -1,15 +1,13 @@
import axios from 'axios';
import AdmZip from 'adm-zip';
import xml2js from 'xml2js';
import fs from 'fs-extra';
import path from 'path';
import path from 'node:path';
import { DATA } from '@/lib/constants/filePaths';

export async function downloadSwitchTDB(req, res) {
export async function downloadSwitchTDB() {
const response = await fetch('https://www.gametdb.com/switchtdb.zip');

if (response.status !== 200) {
logger.error(`Failed downloading ${txtname}.txt`);
return Promise.reject();
}

Expand All @@ -30,11 +28,9 @@ export async function downloadSwitchTDB(req, res) {
const gameData = jsonData.datafile.game;
const gameMap = {};

console.log(gameData);

gameData.forEach((game) => {
const name = game["$"].name.replace(/ \(EN\)$/, '');
const id = game.id;
const name = game.$.name.replace(/ \(EN\)$/, '');
const { id } = game;
if (!gameMap[name]) {
gameMap[name] = [];
}
Expand All @@ -53,4 +49,6 @@ export async function downloadSwitchTDB(req, res) {
path.resolve(DATA.IDS, 'switchtdb.json'),
JSON.stringify(sortedGameMap, null, 2)
);

return null;
}
61 changes: 32 additions & 29 deletions src/lib/utils/riitagUtils.js
Original file line number Diff line number Diff line change
Expand Up @@ -4,15 +4,27 @@ import readline from 'node:readline';
import prisma from '@/lib/db';
import { DATA } from '@/lib/constants/filePaths';
import { exists } from '@/lib/utils/fileUtils';
const xml2js = require('xml2js');
import xml2js from 'xml2js';

const removePunctuation = key => key.replace(/[^\s\w]/g, '').replace(//g, ''); // Remove punctuation from key


function findRegionByGameId(games, gameId) {
let regions = null;
games.forEach(game => {
if (game.id[0] === gameId) {
regions = game.region[0].split(',').map(region => region.trim());
}
});
return regions;
}

function findSimilarKeys(targetKey, keys) {
const removePunctuation = key => key.replace(/[^\w\s]/g, '').replace(//g, ''); // Remove punctuation from key
const targetKeyWithoutPunctuation = removePunctuation(targetKey.toLowerCase());

return keys.filter(key => {
const keyWithoutPunctuation = removePunctuation(key.toLowerCase());
return keyWithoutPunctuation == targetKeyWithoutPunctuation;
return keyWithoutPunctuation === targetKeyWithoutPunctuation;
});
}

Expand Down Expand Up @@ -59,17 +71,19 @@ export async function getWiiUGameName(gameId) {
}

export function getSimilarKeys(ids, gameName, keys) {
let similarKeys = findSimilarKeys(gameName, keys);
const similarKeys = findSimilarKeys(gameName, keys);

for (const key of similarKeys) {
let foundIds = ids[key];
const foundIds = ids[key];
if (foundIds) {
return foundIds;
}
}

return null;
}

export async function getSwitchGameIdByNameAndRegion(gameName, region) {
export async function getSwitchGameIdByNameAndRegion(gameName) {
const ids = JSON.parse(
await fs.promises.readFile(path.resolve(DATA.IDS, 'switchtdb.json'), 'utf8')
);
Expand All @@ -87,13 +101,13 @@ export async function getSwitchGameIdByNameAndRegion(gameName, region) {
try {
const data = await fs.promises.readFile(
path.resolve(DATA.IDS, 'switchtdb.xml'),
'utf-8'
'utf8'
);

const result = await new Promise((resolve, reject) => {
xml2js.parseString(data, (parseErr, parseResult) => {
if (parseErr) {
reject(parseErr);
xml2js.parseString(data, (parseError, parseResult) => {
if (parseError) {
reject(parseError);
} else {
resolve(parseResult);
}
Expand All @@ -102,18 +116,8 @@ export async function getSwitchGameIdByNameAndRegion(gameName, region) {

const games = result.datafile.game;

function findRegionByGameId(gameId) {
let regions = null;
games.forEach(game => {
if (game.id[0] === gameId) {
regions = game.region[0].split(',').map(region => region.trim());
}
});
return regions;
}

for (const gameId of foundIds) {
const region = findRegionByGameId(gameId);
const region = findRegionByGameId(games, gameId);

for (const gameRegion of region) {
// Europe
Expand Down Expand Up @@ -156,28 +160,27 @@ export async function getSwitchGameIdByNameAndRegion(gameName, region) {
}

return null; // Game ID not found
} catch (error) {
console.error(error);
} catch {
return null;
}
}

export async function get3DSGameIdByNameAndRegion(gameName, region) {
const ids = JSON.parse(
const threeds_ids = JSON.parse(
await fs.promises.readFile(path.resolve(DATA.IDS, 'citra.json'), 'utf8')
);

let foundIds = ids[gameName];
let foundIds = threeds_ids[gameName];

if (!foundIds) {
foundIds = getSimilarKeys(ids, gameName, Object.keys(ids));
foundIds = getSimilarKeys(threeds_ids, gameName, Object.keys(threeds_ids));

if (!foundIds) {
const ids = JSON.parse(
const threeds_ids1 = JSON.parse(
await fs.promises.readFile(path.resolve(DATA.IDS, '3dstdb.json'), 'utf8')
);

foundIds = getSimilarKeys(ids, gameName, Object.keys(ids));
foundIds = getSimilarKeys(threeds_ids1, gameName, Object.keys(threeds_ids1));

if (!foundIds) {
return null;
Expand Down Expand Up @@ -261,7 +264,7 @@ export async function get3DSGameIdByNameAndRegion(gameName, region) {
}

// In case nothing was found, return the first ID.
return ids[gameName][0];
return threeds_ids[gameName][0];
}

export async function getWiiUGameIdByNameAndRegion(gameName, region) {
Expand Down
28 changes: 14 additions & 14 deletions src/pages/game-leaderboard.jsx
Original file line number Diff line number Diff line change
Expand Up @@ -22,12 +22,12 @@ export async function getServerSideProps({ query }) {
// Add logic for the search handler
let leaderboard;
let totalGames;
if (search != "null") {
// Call your search function here and pass the search parameter
[totalGames, leaderboard] = await getGameLeaderboardSearch(page, limit, search);
} else {
if (search == "null") {
// Call the game leaderboard function here
[totalGames, leaderboard] = await getGameLeaderboard(page, limit);
} else {
// Call your search function here and pass the search parameter
[totalGames, leaderboard] = await getGameLeaderboardSearch(page, limit, search);
}

const totalPages = Math.ceil(totalGames / limit);
Expand All @@ -48,27 +48,27 @@ function GameLeaderboardPage({ page, totalPages, leaderboard }) {

const handlePageClick = async (event) => {
const newPage = event.selected + 1;
const searchParams = new URLSearchParams(window.location.search);
const searchQuery = searchParams.get("search");
const searchParameters = new URLSearchParams(window.location.search);
const searchQuery = searchParameters.get("search");

updateURLPageParameter(newPage, searchQuery);
};

const [searchQuery, setSearchQuery] = useState('');

const updateURLParameter = (query) => {
const params = new URLSearchParams(window.location.search);
params.set('search', query);
const newURL = window.location.pathname + '?' + params.toString();
const parameters = new URLSearchParams(window.location.search);
parameters.set('search', query);
const newURL = `${window.location.pathname }?${ parameters.toString()}`;
window.history.replaceState({}, '', newURL);
window.location.reload();
};

const updateURLPageParameter = (page, search) => {
const params = new URLSearchParams(window.location.search);
params.set('page', page);
params.set('search', search);
const newURL = window.location.pathname + '?' + params.toString();
const parameters = new URLSearchParams(window.location.search);
parameters.set('page', page);
parameters.set('search', search);
const newURL = `${window.location.pathname }?${ parameters.toString()}`;
window.history.replaceState({}, '', newURL);
window.location.reload();
};
Expand Down Expand Up @@ -107,7 +107,7 @@ function GameLeaderboardPage({ page, totalPages, leaderboard }) {
</Col>
</Row>

<br></br>
<br />

{games.length === 0 ? (
<Row>
Expand Down

0 comments on commit ec5441f

Please sign in to comment.