Skip to content

Commit

Permalink
Merge branch 'develop' into better-multi-domain
Browse files Browse the repository at this point in the history
  • Loading branch information
TurtIeSocks committed Jan 2, 2024
2 parents 3b314ca + d0a8919 commit 9d1c0d9
Show file tree
Hide file tree
Showing 30 changed files with 607 additions and 131 deletions.
2 changes: 1 addition & 1 deletion package.json
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
{
"name": "reactmap",
"version": "1.27.2",
"version": "1.28.0",
"private": true,
"description": "React based frontend map.",
"license": "MIT",
Expand Down
2 changes: 1 addition & 1 deletion packages/config/.configref
Original file line number Diff line number Diff line change
@@ -1 +1 @@
23123
23527
11 changes: 10 additions & 1 deletion packages/locales/lib/human/de.json
Original file line number Diff line number Diff line change
Expand Up @@ -657,5 +657,14 @@
"load_from_autosave": "Aus Autosave laden",
"done": "Erledigt",
"fast": "Sofort",
"charged": "Lade"
"charged": "Lade",
"offline_mode": "offline Modus",
"include_sponsored": "einschließlich gesponserte",
"showcase_color": "Showcasefarbe",
"partner_color": "Partnerfarbe",
"disable": "deaktivieren {{- name}}",
"profiling": "Profilbearbeitung",
"showcase_block": "Gesperrt wegen eines Showcase",
"signed_in_as": "eingeloggt als",
"missing_map_perm": "Du hast keine Berechtigung, die Karte anzuzeigen."
}
26 changes: 24 additions & 2 deletions packages/locales/lib/human/en.json
Original file line number Diff line number Diff line change
Expand Up @@ -327,6 +327,20 @@
"invasion_icons": "Invasion Icons",
"spawnpoint_icons": "Spawnpoint Icons",
"device_icons": "Device Icons",
"pokemon_audio": "Pokémon Audio",
"pokestop_audio": "PokéStop Audio",
"gym_audio": "Gym Audio",
"team_audio": "Team Audio",
"egg_audio": "Egg Audio",
"raid_audio": "Raid Audio",
"nest_audio": "Nest Audio",
"reward_audio": "Reward Audio",
"type_audio": "Type Audio",
"weather_audio": "Weather Audio",
"misc_audio": "Misc Audio",
"invasion_audio": "Invasion Audio",
"spawnpoint_audio": "Spawnpoint Audio",
"device_audio": "Device Audio",
"pokemon_timers": "All Pokemon Timers",
"show_dex_num_in_popup": "Show Pokedex # in Popup",
"popup": "Popup",
Expand Down Expand Up @@ -679,5 +693,13 @@
"profiling": "Profiling",
"showcase_block": "Blocked due to a showcase",
"signed_in_as": "Signed In As",
"missing_map_perm": "You do not have permission to view the map."
}
"missing_map_perm": "You do not have permission to view the map.",
"access_denied": "Access Denied",
"audio": "Audio",
"desktop_notifications": "Desktop Notifications",
"notifications_options": "Notification Options",
"audio_always_on": "Audio Always Plays",
"volume_level": "Volume Level",
"notifications_status": "Notifications Status",
"granted": "granted"
}
5 changes: 3 additions & 2 deletions packages/locales/lib/human/pl.json
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
{
"signed_in_as": "Zalogowano jako",
"missing_map_perm": "Nie masz uprawnień by wyświetlić mapę."
}
"missing_map_perm": "Nie masz uprawnień by wyświetlić mapę.",
"access_denied": "Brak dostępu"
}
5 changes: 3 additions & 2 deletions packages/types/lib/client.d.ts
Original file line number Diff line number Diff line change
@@ -1,13 +1,14 @@
import * as React from 'react'
import { Config } from './config'
import UIcons from '@services/Icons'
import UAssets from '@services/Icons'
import { ButtonProps } from '@mui/material'

declare global {
declare const CONFIG: Config<true>

interface Window {
uicons?: UIcons
uicons?: UAssets
uaudio?: UAssets
}
}

Expand Down
2 changes: 1 addition & 1 deletion packages/types/lib/general.d.ts
Original file line number Diff line number Diff line change
Expand Up @@ -94,7 +94,7 @@ export interface UICONS {
weather: UiconImage[]
}

export type UIconsClient = Config['icons']['styles'][number] & { data: UICONS }
export type UAssetsClient = Config['icons']['styles'][number] & { data: UICONS }

export type FullClientIcons = Omit<Config['icons'], 'styles'> & {
styles: (Config['icons']['styles'][number] & { data: UICONS })[]
Expand Down
41 changes: 41 additions & 0 deletions server/src/configs/custom-environment-variables.json
Original file line number Diff line number Diff line change
Expand Up @@ -855,6 +855,32 @@
},
"darkMapBorder": "CLIENT_SIDE_OPTIONS_WEATHER_DARK_MAP_BORDER",
"lightMapBorder": "CLIENT_SIDE_OPTIONS_WEATHER_LIGHT_MAP_BORDER"
},
"notifications": {
"enabled": {
"__name": "CLIENT_SIDE_OPTIONS_NOTIFICATIONS_ENABLED",
"__format": "boolean"
},
"audio": {
"__name": "CLIENT_SIDE_OPTIONS_NOTIFICATIONS_AUDIO",
"__format": "boolean"
},
"audioAlwaysOn": {
"__name": "CLIENT_SIDE_OPTIONS_NOTIFICATIONS_AUDIO_ALWAYS_ON",
"__format": "boolean"
},
"volumeLevel": {
"__name": "CLIENT_SIDE_OPTIONS_NOTIFICATIONS_VOLUME_LEVEL",
"__format": "number"
},
"pokemon": {
"__name": "CLIENT_SIDE_OPTIONS_NOTIFICATIONS_POKEMON",
"__format": "boolean"
},
"raids": {
"__name": "CLIENT_SIDE_OPTIONS_NOTIFICATIONS_RAIDS",
"__format": "boolean"
}
}
},
"defaultFilters": {
Expand Down Expand Up @@ -1896,6 +1922,21 @@
}
}
},
"audio": {
"cacheHrs": {
"__name": "AUDIO_CACHE_HRS",
"__format": "number"
},
"defaultAudio": {},
"customizable": {
"__name": "AUDIO_CUSTOMIZABLE",
"__format": "json"
},
"styles": {
"__name": "AUDIO_STYLES",
"__format": "json"
}
},
"rarity": {
"percents": {
"uncommon": {
Expand Down
19 changes: 19 additions & 0 deletions server/src/configs/default.json
Original file line number Diff line number Diff line change
Expand Up @@ -427,6 +427,14 @@
"clickableIcon": false,
"darkMapBorder": "#ff0000",
"lightMapBorder": "#246377"
},
"notifications": {
"enabled": false,
"audio": false,
"audioAlwaysOn": false,
"volumeLevel": 50,
"pokemon": false,
"raids": false
}
},
"defaultFilters": {
Expand Down Expand Up @@ -948,6 +956,17 @@
}
}
},
"audio": {
"cacheHrs": 1,
"defaultAudio": {},
"customizable": [],
"styles": [
{
"name": "Default",
"path": "https://raw.githubusercontent.com/WatWowMap/wwm-uaudio/main"
}
]
},
"rarity": {
"percents": {
"uncommon": 0.25,
Expand Down
4 changes: 4 additions & 0 deletions server/src/graphql/resolvers.js
Original file line number Diff line number Diff line change
Expand Up @@ -28,6 +28,10 @@ const resolvers = {
questConditions: perms.quests ? Db.questConditions : {},
masterfile: { ...Event.masterfile, invasions: Event.invasions },
filters: buildDefaultFilters(perms, Db),
audio: {
...config.getSafe('audio'),
styles: Event.uaudio,
},
icons: {
...config.getSafe('icons'),
styles: Event.uicons,
Expand Down
1 change: 1 addition & 0 deletions server/src/graphql/typeDefs/map.graphql
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,7 @@ type Available {
filters: JSON
questConditions: JSON
icons: JSON
audio: JSON
}

type Badge {
Expand Down
3 changes: 2 additions & 1 deletion server/src/index.js
Original file line number Diff line number Diff line change
Expand Up @@ -317,7 +317,8 @@ connection.migrate
Event.setAvailable('nests', 'Nest', Db),
])
await Promise.all([
Event.getUicons(config.getSafe('icons.styles')),
Event.getUniversalAssets(config.getSafe('icons.styles'), 'uicons'),
Event.getUniversalAssets(config.getSafe('audio.styles'), 'uaudio'),
Event.getMasterfile(Db.historical, Db.rarity),
Event.getInvasions(config.getSafe('api.pogoApiEndpoints.invasions')),
Event.getWebhooks(),
Expand Down
33 changes: 20 additions & 13 deletions server/src/services/EventManager.js
Original file line number Diff line number Diff line change
Expand Up @@ -19,7 +19,9 @@ class EventManager {
'invasions' in this.masterfile ? this.masterfile.invasions : {}
this.available = { gyms: [], pokestops: [], pokemon: [], nests: [] }
this.uicons = []
this.uaudio = []
this.uiconsBackup = {}
this.uaudioBackup = {}
this.baseUrl =
'https://raw.githubusercontent.com/WatWowMap/wwm-uicons-webp/main'

Expand Down Expand Up @@ -110,9 +112,13 @@ class EventManager {
}, 1000 * 60 * 60 * (config.getSafe('api.queryUpdateHours.quests') || 3))
}
setInterval(async () => {
await this.getUicons(config.getSafe('icons.styles'))
await this.getUniversalAssets(config.getSafe('icons.styles'), 'uicons')
await this.chatLog({ description: 'Refreshed UICONS indexes' })
}, 1000 * 60 * 60 * (config.getSafe('icons.cacheHrs') || 3))
setInterval(async () => {
await this.getUniversalAssets(config.getSafe('audio.styles'), 'uaudio')
await this.chatLog({ description: 'Refreshed UAUDIO indexes' })
}, 1000 * 60 * 60 * (config.getSafe('audio.cacheHrs') || 3))
if (config.getSafe('api.pogoApiEndpoints.invasions')) {
setInterval(async () => {
await this.getInvasions(
Expand Down Expand Up @@ -198,16 +204,17 @@ class EventManager {
/**
*
* @param {import("@rm/types").Config['icons']['styles']} styles
* @param {'uicons' | 'uaudio'} type
*/
async getUicons(styles) {
log.info(HELPERS.event, 'Fetching Latest UICONS')
async getUniversalAssets(styles, type) {
log.info(HELPERS.event, 'Fetching Latest', type.toUpperCase())
if (!styles.some((icon) => icon.path.includes('wwm'))) {
log.info(
HELPERS.event,
'Base uicons not found in config (either remotely or locally). This may be fine, but some things might be broken, such as items from the `misc` folder.',
`Base ${type} not found in config (either remotely or locally). This may be fine, but some things might be broken, such as items from the 'misc' folder.`,
)
}
const uicons = await Promise.allSettled(
const assets = await Promise.allSettled(
styles.map(async (style) => {
try {
const response = style.path.startsWith('http')
Expand All @@ -216,7 +223,7 @@ class EventManager {
await fs.readFile(
path.resolve(
__dirname,
`../../../public/images/uicons/${style.path}/index.json`,
`../../../public/images/${type}/${style.path}/index.json`,
),
'utf-8',
),
Expand All @@ -226,25 +233,25 @@ class EventManager {
} catch (e) {
log.warn(
HELPERS.event,
'Failed to generate latest uicons for:',
`Failed to generate latest ${type} for:`,
style,
'\n',
e,
)
log.warn(
HELPERS.event,
`Make sure the path follows one of these two formats: \n\tRemote: ${this.baseUrl}\n\tLocal: wwm-uicons (And the uicons folder is found at /public/images/uicons/wwm-uicons/)`,
`Make sure the path follows one of these two formats: \n\tRemote: ${this.baseUrl}\n\tLocal: wwm-${type} (And the ${type} folder is found at /public/images/${type}/wwm-uicons/)`,
)
}
}),
)
for (let i = 0; i < uicons.length; i += 1) {
const uicon = uicons[i]
if (uicon.status === 'fulfilled' && uicon.value) {
this.uiconsBackup[uicon.value.name] = uicon.value
for (let i = 0; i < assets.length; i += 1) {
const item = assets[i]
if (item.status === 'fulfilled' && item.value) {
this[`${type}Backup`][item.value.name] = item.value
}
}
this.uicons = Object.values(this.uiconsBackup)
this[type] = Object.values(this[`${type}Backup`])
}

/**
Expand Down
18 changes: 13 additions & 5 deletions server/src/services/api/scannerApi.js
Original file line number Diff line number Diff line change
Expand Up @@ -72,7 +72,10 @@ async function scannerApi(
default:
break
}
const payloadObj = {}
const payloadObj = /** @type {{ url: string, options: RequestInit }} */ ({
url: '',
options: {},
})
const cache = userCache.has(user.id)
? userCache.get(user.id)
: { coordinates: 0, requests: 0 }
Expand Down Expand Up @@ -211,10 +214,15 @@ async function scannerApi(
'Content-Type': 'application/json',
})
}
const scannerResponse = await fetch(payloadObj.url, {
...payloadObj.options,
signal: controller.signal,
})
const scannerResponse = await fetch(
`${payloadObj.url}${payloadObj.url.includes('?') ? '&' : '?'}username=${
user.username
}`,
{
...payloadObj.options,
signal: controller.signal,
},
)

if (!scannerResponse) {
throw new Error('No data returned from server')
Expand Down
Loading

0 comments on commit 9d1c0d9

Please sign in to comment.