refactor: extended map popup - use /api/v2
ci/woodpecker/push/test Pipeline was successful
Details
ci/woodpecker/push/test Pipeline was successful
Details
This commit is contained in:
parent
93fa246f14
commit
a2fb6425a0
2
.env
2
.env
|
@ -1 +1 @@
|
|||
TWHELP_API_BASE_URL=https://twhelp.app
|
||||
TWHELP_API_BASE_URL=https://twhelp.app/api
|
||||
|
|
10
package.json
10
package.json
|
@ -4,7 +4,7 @@
|
|||
"license": "MIT",
|
||||
"scripts": {
|
||||
"prepare": "husky install",
|
||||
"generate-client": "openapi --input ./src/lib/twhelpv2/openapi3.json --output ./src/lib/twhelpv2 --name TWHelpV2 --useOptions --client axios",
|
||||
"generate-client": "openapi --input ./src/lib/twhelpv2/openapi3.json --output ./src/lib/twhelpv2 --name TWHelpV2Client --useOptions --client axios",
|
||||
"build": "rm -rf dist && yarn generate-client && parcel build ./src/*.user.ts ./src/*.quickbar.ts",
|
||||
"postbuild": "PUBLIC_URL=https://scripts.twhelp.app node postbuild.js",
|
||||
"lint": "eslint src/**/*.ts"
|
||||
|
@ -21,13 +21,13 @@
|
|||
"url": "https://dwysokinski.me/"
|
||||
},
|
||||
"browserslist": [
|
||||
"since 2017-06"
|
||||
"since 2020-01"
|
||||
],
|
||||
"devDependencies": {
|
||||
"@commitlint/cli": "^18.0.0",
|
||||
"@commitlint/config-conventional": "^18.0.0",
|
||||
"@parcel/validator-eslint": "^2.9.1",
|
||||
"@parcel/validator-typescript": "^2.9.1",
|
||||
"@parcel/validator-eslint": "^2.12.0",
|
||||
"@parcel/validator-typescript": "^2.12.0",
|
||||
"@types/jquery": "^3.5.14",
|
||||
"@types/lodash": "^4.14.191",
|
||||
"@types/node": "^20.0.0",
|
||||
|
@ -38,7 +38,7 @@
|
|||
"eslint-config-prettier": "^9.0.0",
|
||||
"husky": "^8.0.3",
|
||||
"openapi-typescript-codegen": "^0.28.0",
|
||||
"parcel": "^2.9.1",
|
||||
"parcel": "^2.12.0",
|
||||
"prettier": "^3.0.0",
|
||||
"typescript": "^5.0.0"
|
||||
},
|
||||
|
|
10
postbuild.js
10
postbuild.js
|
@ -9,7 +9,7 @@ const metadata = {
|
|||
// @name Extended player profile
|
||||
// @version 1.1.6
|
||||
// @description Adds additional info and actions on a player overview.
|
||||
// @author Dawid Wysokiński - Kichiyaki - contact@dwysokinski.me
|
||||
// @author Dawid Wysokiński - Kichiyaki - contact@twhelp.app
|
||||
// @match https://*/game.php?*screen=info_player*
|
||||
// @downloadURL ${process.env.PUBLIC_URL}/extended-player-profile.user.js
|
||||
// @updateURL ${process.env.PUBLIC_URL}/extended-player-profile.user.js
|
||||
|
@ -19,9 +19,9 @@ const metadata = {
|
|||
// ==/UserScript==`,
|
||||
'extended-map-popup': `// ==UserScript==
|
||||
// @name Extended map popup
|
||||
// @version 1.0.5
|
||||
// @version 1.1.0
|
||||
// @description Extends the map popup with additional info.
|
||||
// @author Dawid Wysokiński - Kichiyaki - contact@dwysokinski.me
|
||||
// @author Dawid Wysokiński - Kichiyaki - contact@twhelp.app
|
||||
// @match https://*/game.php?*screen=map*
|
||||
// @downloadURL ${process.env.PUBLIC_URL}/extended-map-popup.user.js
|
||||
// @updateURL ${process.env.PUBLIC_URL}/extended-map-popup.user.js
|
||||
|
@ -33,7 +33,7 @@ const metadata = {
|
|||
// @name Extended village profile
|
||||
// @version 1.0.4
|
||||
// @description Adds additional info and actions on a village overview.
|
||||
// @author Dawid Wysokiński - Kichiyaki - contact@dwysokinski.me
|
||||
// @author Dawid Wysokiński - Kichiyaki - contact@twhelp.app
|
||||
// @match https://*/game.php?*screen=info_village*
|
||||
// @downloadURL ${process.env.PUBLIC_URL}/extended-village-profile.user.js
|
||||
// @updateURL ${process.env.PUBLIC_URL}/extended-village-profile.user.js
|
||||
|
@ -45,7 +45,7 @@ const metadata = {
|
|||
// @name Extended tribe profile
|
||||
// @version 1.0.4
|
||||
// @description Adds additional info and actions on a tribe overview.
|
||||
// @author Dawid Wysokiński - Kichiyaki - contact@dwysokinski.me
|
||||
// @author Dawid Wysokiński - Kichiyaki - contact@twhelp.app
|
||||
// @match https://*/game.php?*screen=info_ally*
|
||||
// @downloadURL ${process.env.PUBLIC_URL}/extended-tribe-profile.user.js
|
||||
// @updateURL ${process.env.PUBLIC_URL}/extended-tribe-profile.user.js
|
||||
|
|
|
@ -1,13 +1,13 @@
|
|||
import addSeconds from 'date-fns/addSeconds';
|
||||
import {
|
||||
Ennoblement,
|
||||
ServerConfig,
|
||||
TWHelpClient,
|
||||
UnitInfo,
|
||||
} from './lib/twhelp';
|
||||
import { Cache, InMemoryStorage } from './lib/cache';
|
||||
import { calcDistance, calcLoyalty } from './lib/tw';
|
||||
import { createTranslationFunc } from './utils';
|
||||
import {
|
||||
TWHelpV2Client,
|
||||
Ennoblement,
|
||||
UnitInfo,
|
||||
ServerConfig,
|
||||
} from './lib/twhelpv2';
|
||||
|
||||
declare global {
|
||||
interface Window {
|
||||
|
@ -43,25 +43,38 @@ const t = createTranslationFunc({
|
|||
|
||||
class TWHelpConnector {
|
||||
private static readonly SERVER_CONFIG_CACHE_KEY =
|
||||
'extended_map_popup_server_config';
|
||||
private static readonly UNIT_INFO_CACHE_KEY = 'extended_map_popup_unit_info';
|
||||
'extended_map_popup_server_config_v2';
|
||||
private static readonly UNIT_INFO_CACHE_KEY =
|
||||
'extended_map_popup_unit_info_v2';
|
||||
private static readonly VILLAGE_CACHE_KEY_PREFIX =
|
||||
'extended_map_popup_village_';
|
||||
'extended_map_popup_village_v2_';
|
||||
|
||||
private readonly localStorageCache = new Cache(localStorage);
|
||||
private readonly inMemoryCache = new Cache(new InMemoryStorage());
|
||||
|
||||
private readonly client: TWHelpV2Client;
|
||||
|
||||
constructor(
|
||||
private readonly client: TWHelpClient,
|
||||
private readonly baseUrl: string,
|
||||
private readonly version: string,
|
||||
private readonly server: string
|
||||
) {}
|
||||
) {
|
||||
this.client = new TWHelpV2Client({
|
||||
BASE: baseUrl,
|
||||
});
|
||||
}
|
||||
|
||||
serverConfig() {
|
||||
return this.localStorageCache.load(
|
||||
TWHelpConnector.SERVER_CONFIG_CACHE_KEY,
|
||||
3600,
|
||||
() => {
|
||||
return this.client.serverConfig(this.version, this.server);
|
||||
async () => {
|
||||
return (
|
||||
await this.client.servers.getServerConfig({
|
||||
serverKey: this.server,
|
||||
versionCode: this.version,
|
||||
})
|
||||
).data;
|
||||
}
|
||||
);
|
||||
}
|
||||
|
@ -70,8 +83,13 @@ class TWHelpConnector {
|
|||
return this.localStorageCache.load(
|
||||
TWHelpConnector.UNIT_INFO_CACHE_KEY,
|
||||
3600,
|
||||
() => {
|
||||
return this.client.unitInfo(this.version, this.server);
|
||||
async () => {
|
||||
return (
|
||||
await this.client.servers.getUnitInfo({
|
||||
serverKey: this.server,
|
||||
versionCode: this.version,
|
||||
})
|
||||
).data;
|
||||
}
|
||||
);
|
||||
}
|
||||
|
@ -84,15 +102,14 @@ class TWHelpConnector {
|
|||
}
|
||||
|
||||
return this.inMemoryCache.load(key, 86400, async () => {
|
||||
const ennoblements = await this.client.villageEnnoblements(
|
||||
this.version,
|
||||
this.server,
|
||||
id,
|
||||
{
|
||||
limit: 1,
|
||||
const ennoblements =
|
||||
await this.client.ennoblements.listVillageEnnoblements({
|
||||
versionCode: this.version,
|
||||
serverKey: this.server,
|
||||
sort: ['createdAt:DESC'],
|
||||
}
|
||||
);
|
||||
villageId: id,
|
||||
limit: 1,
|
||||
});
|
||||
return ennoblements.data.length > 0 ? ennoblements.data[0] : null;
|
||||
});
|
||||
}
|
||||
|
@ -245,9 +262,9 @@ class Popup {
|
|||
|
||||
class ExtendedMapPopup {
|
||||
connector: TWHelpConnector;
|
||||
constructor(client: TWHelpClient) {
|
||||
constructor(baseApiUrl: string) {
|
||||
this.connector = new TWHelpConnector(
|
||||
client,
|
||||
baseApiUrl,
|
||||
window.game_data.market,
|
||||
window.game_data.world
|
||||
);
|
||||
|
@ -273,9 +290,7 @@ class ExtendedMapPopup {
|
|||
return;
|
||||
}
|
||||
|
||||
await new ExtendedMapPopup(
|
||||
new TWHelpClient(process.env.TWHELP_API_BASE_URL ?? '')
|
||||
)
|
||||
await new ExtendedMapPopup(process.env.TWHELP_API_BASE_URL ?? '')
|
||||
.run()
|
||||
.catch((err) => {
|
||||
console.log(err);
|
||||
|
|
Loading…
Reference in New Issue