mirror of
https://github.com/maxswa/osrs-json-hiscores.git
synced 2025-10-15 10:19:04 +00:00
Compare commits
15 Commits
Author | SHA1 | Date | |
---|---|---|---|
![]() |
175f945ab8 | ||
![]() |
6b31e8b08c | ||
![]() |
d097567a3c | ||
![]() |
be5c093cf7 | ||
![]() |
db72f0c57d | ||
![]() |
bd2ea21980 | ||
![]() |
d67837c161 | ||
![]() |
4aa6ad2752 | ||
![]() |
2f788fabf6 | ||
![]() |
0f5aea795c | ||
![]() |
7acb84e310 | ||
![]() |
9619bd2a2b | ||
![]() |
55abd9f800 | ||
![]() |
cf8a4cc26e | ||
![]() |
ae47df31f1 |
18
.github/workflows/main.yml
vendored
Normal file
18
.github/workflows/main.yml
vendored
Normal file
@@ -0,0 +1,18 @@
|
||||
name: CI
|
||||
|
||||
on: [push, pull_request]
|
||||
|
||||
jobs:
|
||||
build:
|
||||
runs-on: ubuntu-latest
|
||||
steps:
|
||||
- uses: actions/checkout@v2
|
||||
- uses: borales/actions-yarn@v2.0.0
|
||||
with:
|
||||
cmd: install
|
||||
- uses: borales/actions-yarn@v2.0.0
|
||||
with:
|
||||
cmd: build
|
||||
- uses: borales/actions-yarn@v2.0.0
|
||||
with:
|
||||
cmd: test
|
@@ -152,6 +152,7 @@ Activities consist of all levels of clue scrolls as well as minigames and bosses
|
||||
| Sarachnis | `sarachnis` |
|
||||
| Scorpia | `scorpia` |
|
||||
| Skotizo | `skotizo` |
|
||||
| Tempoross | `tempoross` |
|
||||
| Gauntlet | `gauntlet` |
|
||||
| Corrupted Gauntlet | `corruptedGauntlet` |
|
||||
| Theatre Of Blood | `theatreOfBlood` |
|
||||
|
@@ -32,9 +32,9 @@ test('Parse CSV to json', () => {
|
||||
169,99,43127930
|
||||
810,99,37688883
|
||||
92,99,32005622
|
||||
-1,-1
|
||||
-1,-1
|
||||
-1,-1
|
||||
23423,478
|
||||
99831,23
|
||||
89912,37
|
||||
32,12148
|
||||
3105,76
|
||||
1997,505
|
||||
@@ -76,6 +76,7 @@ test('Parse CSV to json', () => {
|
||||
201,1101
|
||||
82,3404
|
||||
5085,61
|
||||
18823,23
|
||||
63,375
|
||||
2870,6
|
||||
6984,138
|
||||
@@ -116,10 +117,10 @@ test('Parse CSV to json', () => {
|
||||
hunter: { rank: 810, level: 99, xp: 37688883 },
|
||||
construction: { rank: 92, level: 99, xp: 32005622 },
|
||||
},
|
||||
leaguePoints: { rank: -1, score: -1 },
|
||||
leaguePoints: { rank: 23423, score: 478 },
|
||||
bountyHunter: {
|
||||
rogue: { rank: -1, score: -1 },
|
||||
hunter: { rank: -1, score: -1 },
|
||||
hunter: { rank: 99831, score: 23 },
|
||||
rogue: { rank: 89912, score: 37 },
|
||||
},
|
||||
lastManStanding: { rank: 4814, score: 898 },
|
||||
soulWarsZeal: { rank: 37, score: 225 },
|
||||
@@ -165,6 +166,7 @@ test('Parse CSV to json', () => {
|
||||
sarachnis: { rank: 201, score: 1101 },
|
||||
scorpia: { rank: 82, score: 3404 },
|
||||
skotizo: { rank: 5085, score: 61 },
|
||||
tempoross: { rank: 18823, score: 23 },
|
||||
gauntlet: { rank: 63, score: 375 },
|
||||
corruptedGauntlet: { rank: 2870, score: 6 },
|
||||
theatreOfBlood: { rank: 6984, score: 138 },
|
||||
|
13
package.json
13
package.json
@@ -1,6 +1,6 @@
|
||||
{
|
||||
"name": "osrs-json-hiscores",
|
||||
"version": "2.3.0",
|
||||
"version": "2.4.0",
|
||||
"description": "The Oldschool Runescape API wrapper that does more!",
|
||||
"main": "lib/index.js",
|
||||
"types": "lib/index.d.ts",
|
||||
@@ -37,15 +37,16 @@
|
||||
"homepage": "https://github.com/maxswa/osrs-json-hiscores#readme",
|
||||
"dependencies": {
|
||||
"axios": "^0.21.1",
|
||||
"jsdom": "^16.3.0"
|
||||
"jsdom": "^16.3.0",
|
||||
"useragent-generator": "^1.1.0"
|
||||
},
|
||||
"devDependencies": {
|
||||
"@types/jest": "^24.0.14",
|
||||
"@types/jest": "^26.0.20",
|
||||
"@types/jsdom": "^16.2.3",
|
||||
"jest": "^24.8.0",
|
||||
"np": "^5.0.3",
|
||||
"jest": "^26.6.3",
|
||||
"np": "6.5.0",
|
||||
"prettier": "^1.19.1",
|
||||
"ts-jest": "^24.0.2",
|
||||
"ts-jest": "^26.4.4",
|
||||
"tslint": "^5.17.0",
|
||||
"tslint-config-airbnb": "^5.11.1",
|
||||
"tslint-config-prettier": "^1.18.0",
|
||||
|
51
src/@types/useragent-generator.d.ts
vendored
Normal file
51
src/@types/useragent-generator.d.ts
vendored
Normal file
@@ -0,0 +1,51 @@
|
||||
declare module 'useragent-generator' {
|
||||
/********************
|
||||
* Google Chrome *
|
||||
/*******************/
|
||||
export function chrome(opt: number | string | { version: string, os?: string }): string;
|
||||
export namespace chrome {
|
||||
function androidPhone(opt: number | string | { version: string, androidVersion?: string, device?: string }): string;
|
||||
function androidTablet(opt: number | string | { version: string, androidVersion?: string, device?: string })
|
||||
: string;
|
||||
function androidWebview(opt: number | string | { androidVersion: string, chromeVersion?: string, device?: string })
|
||||
: string;
|
||||
function chromecast(opt: number | string | { version: string }): string;
|
||||
function iOS(opt: number | string | { iOSVersion: string, chromeVersion?: string, device?: string }): string;
|
||||
}
|
||||
export function chromium(opt: number | string | { version: string, os?: string }): string;
|
||||
/***************
|
||||
* Firefox *
|
||||
/*************/
|
||||
export function firefox(opt: number | string | { version: string, os?: string }): string;
|
||||
export namespace firefox {
|
||||
function androidPhone(opt: number | string | { version: string, androidVersion?: string, device?: string }): string;
|
||||
function androidTablet(opt: number | string | { version: string, androidVersion?: string, device?: string })
|
||||
: string;
|
||||
function iOS(opt: number | string | { iOSVersion: string, device?: string }): string;
|
||||
}
|
||||
/**************
|
||||
* Safari *
|
||||
/************/
|
||||
export function safari(opt: number | string | { version: string, os?: string }): string;
|
||||
export namespace safari {
|
||||
function iOS(opt: number | string | { iOSVersion: string, safariVersion?: string, device?: string }): string;
|
||||
function iOSWebview(opt: number | string | { iOSVersion: string, safariVersion?: string, device?: string }): string;
|
||||
}
|
||||
/***********************
|
||||
* Internet Explorer *
|
||||
/*********************/
|
||||
export function ie(opt: number | string | { version: string, os?: string }): string;
|
||||
export namespace ie {
|
||||
function windowsPhone(opt: number | string | { version: string, device?: string }): string;
|
||||
}
|
||||
/**********************
|
||||
* Microsoft Edge *
|
||||
/********************/
|
||||
export function edge(opt: number | string | { version: string, chromeVersion?: string, os?: string }): string;
|
||||
/************************
|
||||
* Search Engine Bots *
|
||||
/**********************/
|
||||
export function googleBot(opt?: number | string | { version?: string }): string;
|
||||
export function bingBot(opt?: number | string | { version?: string }): string;
|
||||
export function yahooBot(): string;
|
||||
}
|
@@ -1,4 +1,3 @@
|
||||
import axios from 'axios';
|
||||
import {
|
||||
Player,
|
||||
Activity,
|
||||
@@ -26,6 +25,7 @@ import {
|
||||
numberFromElement,
|
||||
rsnFromElement,
|
||||
getActivityPageURL,
|
||||
httpGet,
|
||||
BOSSES,
|
||||
} from './utils';
|
||||
import { JSDOM } from 'jsdom';
|
||||
@@ -39,12 +39,12 @@ export async function getStats(rsn: string): Promise<Player> {
|
||||
throw Error('RSN must be between 1 and 12 characters');
|
||||
}
|
||||
|
||||
const mainRes = await axios(getStatsURL('main', rsn));
|
||||
const mainRes = await httpGet(getStatsURL('main', rsn));
|
||||
if (mainRes.status === 200) {
|
||||
const otherResponses = await Promise.all([
|
||||
axios(getStatsURL('ironman', rsn)).catch(err => err),
|
||||
axios(getStatsURL('hardcore', rsn)).catch(err => err),
|
||||
axios(getStatsURL('ultimate', rsn)).catch(err => err),
|
||||
httpGet(getStatsURL('ironman', rsn)).catch(err => err),
|
||||
httpGet(getStatsURL('hardcore', rsn)).catch(err => err),
|
||||
httpGet(getStatsURL('ultimate', rsn)).catch(err => err),
|
||||
getRSNFormat(rsn).catch(() => undefined),
|
||||
]);
|
||||
|
||||
@@ -120,7 +120,7 @@ export async function getStatsByGamemode(
|
||||
} else if (!GAMEMODES.includes(mode)) {
|
||||
throw Error('Invalid game mode');
|
||||
}
|
||||
const response = await axios(getStatsURL(mode, rsn));
|
||||
const response = await httpGet(getStatsURL(mode, rsn));
|
||||
if (response.status !== 200) {
|
||||
throw Error('Player not found');
|
||||
}
|
||||
@@ -143,7 +143,7 @@ export async function getSkillPage(
|
||||
}
|
||||
const url = getSkillPageURL(mode, skill, page);
|
||||
|
||||
const response = await axios(url);
|
||||
const response = await httpGet(url);
|
||||
const dom = new JSDOM(response.data);
|
||||
const playersHTML = dom.window.document.querySelectorAll(
|
||||
'.personal-hiscores__row'
|
||||
@@ -183,7 +183,7 @@ export async function getActivityPage(
|
||||
}
|
||||
const url = getActivityPageURL(mode, activity, page);
|
||||
|
||||
const response = await axios(url);
|
||||
const response = await httpGet(url);
|
||||
const dom = new JSDOM(response.data);
|
||||
const playersHTML = dom.window.document.querySelectorAll(
|
||||
'.personal-hiscores__row'
|
||||
@@ -218,7 +218,7 @@ export async function getRSNFormat(rsn: string): Promise<string> {
|
||||
|
||||
const url = getPlayerTableURL('main', rsn);
|
||||
try {
|
||||
const response = await axios(url);
|
||||
const response = await httpGet(url);
|
||||
const dom = new JSDOM(response.data);
|
||||
const spans = dom.window.document.querySelectorAll(
|
||||
'span[style="color:#AA0022;"]'
|
||||
|
@@ -94,6 +94,7 @@ export type Boss =
|
||||
| 'sarachnis'
|
||||
| 'scorpia'
|
||||
| 'skotizo'
|
||||
| 'tempoross'
|
||||
| 'gauntlet'
|
||||
| 'corruptedGauntlet'
|
||||
| 'theatreOfBlood'
|
||||
|
@@ -59,7 +59,7 @@ export const CLUES: ClueType[] = [
|
||||
'elite',
|
||||
'master',
|
||||
];
|
||||
export const BH_MODES: BHType[] = ['rogue', 'hunter'];
|
||||
export const BH_MODES: BHType[] = ['hunter', 'rogue'];
|
||||
export const GAMEMODES: Gamemode[] = [
|
||||
'main',
|
||||
'ironman',
|
||||
@@ -102,6 +102,7 @@ export const BOSSES: Boss[] = [
|
||||
'sarachnis',
|
||||
'scorpia',
|
||||
'skotizo',
|
||||
'tempoross',
|
||||
'gauntlet',
|
||||
'corruptedGauntlet',
|
||||
'theatreOfBlood',
|
||||
@@ -168,6 +169,7 @@ export const FORMATTED_BOSS_NAMES: FormattedBossNames = {
|
||||
sarachnis: 'Sarachnis',
|
||||
scorpia: 'Scorpia',
|
||||
skotizo: 'Skotizo',
|
||||
tempoross: 'Tempoross',
|
||||
gauntlet: 'The Gauntlet',
|
||||
corruptedGauntlet: 'The Corrupted Gauntlet',
|
||||
theatreOfBlood: 'Theatre of Blood',
|
||||
|
@@ -1,3 +1,5 @@
|
||||
import axios from 'axios';
|
||||
import * as ua from 'useragent-generator';
|
||||
import { Gamemode, SkillName, ActivityName } from '../types';
|
||||
import {
|
||||
GAMEMODE_URL,
|
||||
@@ -45,3 +47,12 @@ export const rsnFromElement = (el: Element | null) => {
|
||||
const { innerHTML } = el || {};
|
||||
return innerHTML?.replace(/\uFFFD/g, ' ') || '';
|
||||
};
|
||||
|
||||
export const httpGet = (url: string) => {
|
||||
return axios.get(url, {
|
||||
headers: {
|
||||
// without User-Agent header requests may be rejected by DDoS protection mechanism
|
||||
'User-Agent': ua.firefox(80)
|
||||
}
|
||||
});
|
||||
};
|
||||
|
Reference in New Issue
Block a user