diff --git a/.prettierrc.json b/.prettierrc.json new file mode 100644 index 0000000..f0eb61e --- /dev/null +++ b/.prettierrc.json @@ -0,0 +1,6 @@ +{ + "trailingComma": "es5", + "tabWidth": 2, + "semi": true, + "singleQuote": false +} diff --git a/public/assets/swiped-events.min.js b/public/assets/swiped-events.min.js index f87c421..347748a 100644 --- a/public/assets/swiped-events.min.js +++ b/public/assets/swiped-events.min.js @@ -26,7 +26,7 @@ (u = 0), (i = 0); }, - !1, + !1 ), e.addEventListener( "touchmove", @@ -36,7 +36,7 @@ r = t.touches[0].clientY; (u = n - e), (i = a - r); }, - !1, + !1 ), e.addEventListener( "touchend", @@ -67,15 +67,15 @@ bubbles: !0, cancelable: !0, detail: b, - }), + }) ), s.dispatchEvent( - new CustomEvent(d, { bubbles: !0, cancelable: !0, detail: b }), + new CustomEvent(d, { bubbles: !0, cancelable: !0, detail: b }) ); } (n = null), (a = null), (r = null); }, - !1, + !1 ); var n = null, a = null, diff --git a/rollup.config.js b/rollup.config.js index 445e5f3..5b5da75 100644 --- a/rollup.config.js +++ b/rollup.config.js @@ -20,7 +20,7 @@ fs.writeFileSync( buildDate: new Date().toISOString().substr(0, 19).replace("T", " ") + " UTC", buildVersion, - }), + }) ); function serve() { @@ -39,7 +39,7 @@ function serve() { { stdio: ["ignore", "inherit", "inherit"], shell: true, - }, + } ); process.on("SIGTERM", toExit); @@ -104,7 +104,7 @@ export default [ fs.copyFileSync( path.resolve("./node_modules/comlink/dist/umd/comlink.min.js"), - path.resolve("./public/build/comlink.min.js"), + path.resolve("./public/build/comlink.min.js") ); }, }, @@ -150,7 +150,7 @@ export default [ fs.copyFileSync( path.resolve("./src/workers/stats-worker.js"), - path.resolve("./public/build/stats-worker.js"), + path.resolve("./public/build/stats-worker.js") ); }, }, diff --git a/src/components/Player/Charts/utils/legend-click-handler.js b/src/components/Player/Charts/utils/legend-click-handler.js index fe3caad..eb969d9 100644 --- a/src/components/Player/Charts/utils/legend-click-handler.js +++ b/src/components/Player/Charts/utils/legend-click-handler.js @@ -22,7 +22,7 @@ export const onLegendClick = (event, legendItem, legend) => { (ci?.config?.data?.datasets?.[a?.datasetIndex]?.axisOrder ?? a?.datasetIndex) - (ci?.config?.data?.datasets?.[b?.datasetIndex]?.axisOrder ?? - b?.datasetIndex), + b?.datasetIndex) ) .reduce( (cum, legendItem) => { @@ -44,7 +44,7 @@ export const onLegendClick = (event, legendItem, legend) => { return cum; }, - { first: null, second: null }, + { first: null, second: null } ); Object.keys(yAxes).forEach((currentAxisKey) => { diff --git a/src/components/Player/Charts/utils/regions-plugin.js b/src/components/Player/Charts/utils/regions-plugin.js index ae3b161..bdeaddd 100644 --- a/src/components/Player/Charts/utils/regions-plugin.js +++ b/src/components/Player/Charts/utils/regions-plugin.js @@ -39,7 +39,7 @@ export default { : left + 3, region?.position?.vertical === "bottom" ? top + 2 - : top - fontSize - 1, + : top - fontSize - 1 ); } } diff --git a/src/components/Player/utils/profile.js b/src/components/Player/utils/profile.js index cb185bd..e8d58f9 100644 --- a/src/components/Player/utils/profile.js +++ b/src/components/Player/utils/profile.js @@ -70,7 +70,7 @@ function updateScoresStats(playerData, playerStats) { bgColor: "var(--ppColour)", }, ] - : [], + : [] ) .filter((s) => s && (!playerStats || s.label !== "Average")); } diff --git a/src/components/Player/utils/service-param-manager.js b/src/components/Player/utils/service-param-manager.js index 5b4ee41..27048e7 100644 --- a/src/components/Player/utils/service-param-manager.js +++ b/src/components/Player/utils/service-param-manager.js @@ -74,7 +74,7 @@ export default () => { order: "desc", page: paramsArr[2] ?? serviceDefaultParams?.page, }, - service, + service ); case "accsaber": @@ -88,7 +88,7 @@ export default () => { : "desc", page: paramsArr[3] ?? serviceDefaultParams?.page, }, - service, + service ); case "scoresaber": @@ -102,7 +102,7 @@ export default () => { : "desc", page: paramsArr[2] ?? serviceDefaultParams?.page, }, - service, + service ); } }; diff --git a/src/db/cache.js b/src/db/cache.js index 00c66e0..22ccf72 100644 --- a/src/db/cache.js +++ b/src/db/cache.js @@ -5,19 +5,19 @@ export default (name, getObjKey) => { // update data cached on another node eventBus.on("cache-key-set-" + name, ({ key, value }, isLocal) => - !isLocal ? set(key, value, false) : null, + !isLocal ? set(key, value, false) : null ); eventBus.on("cache-all-set" + name, ({ data }, isLocal) => - !isLocal ? setAll(data, false) : null, + !isLocal ? setAll(data, false) : null ); eventBus.on("cache-merge-" + name, ({ data }, isLocal) => - !isLocal ? merge(data, false) : null, + !isLocal ? merge(data, false) : null ); eventBus.on("cache-key-forget-" + name, ({ key }, isLocal) => - !isLocal ? forget(key, false) : null, + !isLocal ? forget(key, false) : null ); eventBus.on("cache-flush-" + name, (_, isLocal) => - !isLocal ? flush(false) : null, + !isLocal ? flush(false) : null ); const set = (key, value, emitEvent = true) => { diff --git a/src/db/db.js b/src/db/db.js index d8cb351..594f269 100644 --- a/src/db/db.js +++ b/src/db/db.js @@ -27,7 +27,7 @@ async function openDatabase() { db = await openDB("ssr", SSR_DB_VERSION, { async upgrade(db, oldVersion, newVersion, transaction) { log.info( - `Converting database from version ${oldVersion} to version ${newVersion}`, + `Converting database from version ${oldVersion} to version ${newVersion}` ); dbNewVersion = newVersion; @@ -50,7 +50,7 @@ async function openDatabase() { playersHistory.createIndex( "players-history-timestamp", "timestamp", - { unique: false }, + { unique: false } ); const scoresStore = db.createObjectStore("scores", { @@ -89,17 +89,17 @@ async function openDatabase() { { keyPath: "_idbId", autoIncrement: true, - }, + } ); rankedsChangesStore.createIndex( "rankeds-changes-timestamp", "timestamp", - { unique: false }, + { unique: false } ); rankedsChangesStore.createIndex( "rankeds-changes-leaderboardId", "leaderboardId", - { unique: false }, + { unique: false } ); // no autoIncrement, no keyPath - key must be provided @@ -197,12 +197,12 @@ async function openDatabase() { { keyPath: "id", autoIncrement: false, - }, + } ); scoresUpdateQueue.createIndex( "scores-update-queue-fetchedAt", "fetchedAt", - { unique: false }, + { unique: false } ); case newVersion >= 8 && oldVersion <= 7: @@ -220,7 +220,7 @@ async function openDatabase() { playersHistoryStorev9.createIndex( "players-history-playerIdSsTimestamp", "playerIdSsTimestamp", - { unique: true }, + { unique: true } ); // NO break here @@ -246,17 +246,17 @@ async function openDatabase() { { keyPath: "id", autoIncrement: false, - }, + } ); accSaberPlayersStore.createIndex( "accsaber-players-playerId", "playerId", - { unique: false }, + { unique: false } ); accSaberPlayersStore.createIndex( "accsaber-players-category", "category", - { unique: false }, + { unique: false } ); // NO break here @@ -267,12 +267,12 @@ async function openDatabase() { { keyPath: "playerIdTimestamp", autoIncrement: false, - }, + } ); accSaberPlayersHistoryStore.createIndex( "accsaber-players-history-playerId", "playerId", - { unique: false }, + { unique: false } ); // NO break here @@ -307,7 +307,7 @@ async function openDatabase() { objectStores, closure, mode = "readwrite", - options = { durability: "strict" }, + options = { durability: "strict" } ) => { try { const tx = db.transaction(objectStores, mode, options); diff --git a/src/db/fix-data.js b/src/db/fix-data.js index d15320a..d508e89 100644 --- a/src/db/fix-data.js +++ b/src/db/fix-data.js @@ -41,7 +41,7 @@ const allFixes = { : []; allAppliedFixes.push(fixName); await keyValueStore.put(allAppliedFixes, FIXES_KEY); - }, + } ); }, }, @@ -75,14 +75,14 @@ const allFixes = { log.info( `Unable to convert, deleting a song`, "DBFix", - beatSaverSong, + beatSaverSong ); } } else { log.info( `No metadata characteristics, skipping a song`, "DBFix", - beatSaverSong, + beatSaverSong ); } @@ -99,7 +99,7 @@ const allFixes = { await keyValueStore.put(allAppliedFixes, FIXES_KEY); log.info(`${songCount} BeatSaver song(s) converted`, "DBFix"); - }, + } ); }, }, @@ -150,8 +150,8 @@ const allFixes = { lastUpdated: null, login: twitchLogin, playerId, - }), - ), + }) + ) ); await addAppliedFix(fixName); @@ -203,7 +203,7 @@ const allFixes = { : []; allAppliedFixes.push(fixName); await keyValueStore.put(allAppliedFixes, FIXES_KEY); - }, + } ); }, }, @@ -216,7 +216,7 @@ export default async () => { const neededFixes = Object.keys(allFixes).filter( (f) => !appliedFixes.includes(f) && - (!allFixes[f].validTo || allFixes[f].validTo > new Date()), + (!allFixes[f].validTo || allFixes[f].validTo > new Date()) ); if (!neededFixes.length) return; diff --git a/src/db/repository/generic.js b/src/db/repository/generic.js index c3c1067..670ce96 100644 --- a/src/db/repository/generic.js +++ b/src/db/repository/generic.js @@ -75,7 +75,7 @@ export default (storeName, inlineKeyName = undefined, indexesKeyNames = {}) => { const cacheKey = getCacheKeyFor(key); return repositoryCache.get(key, () => - resolvePromiseOrWaitForPending(cacheKey, () => db.get(storeName, key)), + resolvePromiseOrWaitForPending(cacheKey, () => db.get(storeName, key)) ); }; @@ -89,7 +89,7 @@ export default (storeName, inlineKeyName = undefined, indexesKeyNames = {}) => { const getFromDb = () => resolvePromiseOrWaitForPending(cacheKey, () => - db.getFromIndex(storeName, indexName, query), + db.getFromIndex(storeName, indexName, query) ); if (query && query instanceof IDBKeyRange) return getFromDb(); @@ -114,7 +114,7 @@ export default (storeName, inlineKeyName = undefined, indexesKeyNames = {}) => { isIndexDataAvailable(cacheKey) || isIndexDataAvailable(fullIndexCacheKey) ? filterItems - : null, + : null ); }; @@ -134,7 +134,7 @@ export default (storeName, inlineKeyName = undefined, indexesKeyNames = {}) => { const data = convertArrayToObjectByKey(await getFromDb(), inlineKeyName); const ret = Object.values(repositoryCache.setAll(data)).filter( - filterUndefined, + filterUndefined ); setAllDataAvailabilityStatus(); @@ -148,7 +148,7 @@ export default (storeName, inlineKeyName = undefined, indexesKeyNames = {}) => { const getAllFromIndex = async ( indexName, query = undefined, - refreshCache = false, + refreshCache = false ) => { if (hasOutOfLineKey()) throw `getAllFromIndex() is not available for stores with out-of-line key`; @@ -159,7 +159,7 @@ export default (storeName, inlineKeyName = undefined, indexesKeyNames = {}) => { const getFromDb = async () => resolvePromiseOrWaitForPending(cacheKey, () => - db.getAllFromIndex(storeName, indexName, query), + db.getAllFromIndex(storeName, indexName, query) ); if (query && query instanceof IDBKeyRange) return getFromDb(); diff --git a/src/main.js b/src/main.js index 7e1d6e7..22fbc21 100644 --- a/src/main.js +++ b/src/main.js @@ -62,7 +62,7 @@ let app = null; "InvalidStateError: A mutation operation was attempted on a database that did not allow mutations." ) error = new Error( - "Firefox in private mode does not support the database. Please run the site in normal mode.", + "Firefox in private mode does not support the database. Please run the site in normal mode." ); app = new ErrorComponent({ diff --git a/src/network/cache.js b/src/network/cache.js index 5b98d44..56cdfeb 100644 --- a/src/network/cache.js +++ b/src/network/cache.js @@ -24,7 +24,7 @@ export default (size = DEFAULT_CACHE_SIZE, expiryIn = MINUTE) => { cum[key] = value; return cum; }, - {}, + {} ); } @@ -43,7 +43,7 @@ export default (size = DEFAULT_CACHE_SIZE, expiryIn = MINUTE) => { if (value.headers) { const headers = new Headers(); Object.keys(value.headers).map((k) => - headers.append(k, value.headers[k]), + headers.append(k, value.headers[k]) ); newValue.headers = headers; } diff --git a/src/network/clients/accsaber/api-player-rank-history.js b/src/network/clients/accsaber/api-player-rank-history.js index 15e507f..9be78c9 100644 --- a/src/network/clients/accsaber/api-player-rank-history.js +++ b/src/network/clients/accsaber/api-player-rank-history.js @@ -30,7 +30,7 @@ const get = async ({ const response = await queue.ACCSABER.playerRankHistory( playerId, priority, - queueOptions, + queueOptions ); return { diff --git a/src/network/clients/accsaber/api-ranking.js b/src/network/clients/accsaber/api-ranking.js index 1978bd0..bb9a8ca 100644 --- a/src/network/clients/accsaber/api-ranking.js +++ b/src/network/clients/accsaber/api-ranking.js @@ -23,7 +23,7 @@ const get = async ({ category, page, priority, - queueOptions, + queueOptions ); return { diff --git a/src/network/clients/accsaber/api-scores.js b/src/network/clients/accsaber/api-scores.js index d4982b0..d799d9e 100644 --- a/src/network/clients/accsaber/api-scores.js +++ b/src/network/clients/accsaber/api-scores.js @@ -85,7 +85,7 @@ const get = async ({ playerId, page, priority, - queueOptions, + queueOptions ); return { diff --git a/src/network/clients/generic.js b/src/network/clients/generic.js index 2a99025..87ff226 100644 --- a/src/network/clients/generic.js +++ b/src/network/clients/generic.js @@ -23,7 +23,7 @@ export default (get, process) => { const response = await clientGet({ ...getOptions, priority, fullResponse }); const processedResponse = process( - fullResponse ? getResponseBody(response) : response, + fullResponse ? getResponseBody(response) : response ); return fullResponse diff --git a/src/network/clients/scoresaber/leaderboard/page-leaderboard.js b/src/network/clients/scoresaber/leaderboard/page-leaderboard.js index a9afbb6..fd43d0a 100644 --- a/src/network/clients/scoresaber/leaderboard/page-leaderboard.js +++ b/src/network/clients/scoresaber/leaderboard/page-leaderboard.js @@ -56,7 +56,7 @@ const get = async ({ leaderboardId, page, priority, - queueOptions, + queueOptions ); const client = createClient(get, process); diff --git a/src/network/clients/scoresaber/player/page.js b/src/network/clients/scoresaber/player/page.js index eb6bc89..a5cca8f 100644 --- a/src/network/clients/scoresaber/player/page.js +++ b/src/network/clients/scoresaber/player/page.js @@ -5,7 +5,7 @@ import createClient from "../../generic"; const process = (response) => { const apiProcessedResponse = api.process( - response && response.player ? response.player : null, + response && response.player ? response.player : null ); if (!opt(apiProcessedResponse, "player.playerInfo")) return null; @@ -20,7 +20,7 @@ const process = (response) => { const externalProfileUrl = opt( response, - "player.playerInfo.externalProfileUrl", + "player.playerInfo.externalProfileUrl" ); if (externalProfileUrl) { apiProcessedResponse.playerInfo.externalProfileUrl = externalProfileUrl; diff --git a/src/network/command-processor.js b/src/network/command-processor.js index bb3fe4d..7004a1b 100644 --- a/src/network/command-processor.js +++ b/src/network/command-processor.js @@ -27,7 +27,7 @@ export default (dlManager) => { if (!playerId) return; await playerService.remove(playerId, purgeScores); - }, + } ); eventBus.on("dl-manager-pause-cmd", () => { diff --git a/src/network/download-manager.js b/src/network/download-manager.js index 3ce8c26..643f4e4 100644 --- a/src/network/download-manager.js +++ b/src/network/download-manager.js @@ -39,7 +39,7 @@ const enqueue = async ( type, force = false, data = null, - then = null, + then = null ) => { if (!type || !type.name || !Number.isFinite(type.priority)) { log.warn(`Unknown type enqueued.`, "DlManager", type); @@ -49,9 +49,9 @@ const enqueue = async ( log.debug( `Try to enqueue type ${type.name}. Forced: ${force}, data: ${JSON.stringify( - data, + data )}`, - "DlManager", + "DlManager" ); const priority = force ? PRIORITY.HIGHEST : type.priority; @@ -78,13 +78,13 @@ const enqueue = async ( queue, { ...TYPES.ACTIVE_PLAYERS, priority: PRIORITY.HIGHEST }, force, - { playerId: mainPlayerId }, + { playerId: mainPlayerId } ), enqueue( queue, { ...TYPES.PLAYER_SCORES, priority: PRIORITY.HIGHEST }, force, - { playerId: mainPlayerId }, + { playerId: mainPlayerId } ), ]); } @@ -98,9 +98,9 @@ const enqueue = async ( processThen( queue.add( async () => rankedsStore.refresh(force, networkPriority), - priority, + priority ), - then, + then ).then((_) => log.debug("Enqueued rankeds processed.", "DlManager")); break; @@ -112,32 +112,32 @@ const enqueue = async ( processThen( queue.add( async () => playerService.add(data.playerId, networkPriority), - priority, + priority ), - then, + then ).then((_) => - log.debug("Enqueued active players processed.", "DlManager"), + log.debug("Enqueued active players processed.", "DlManager") ); else processThen( queue.add( async () => playerService.refresh(data.playerId, force, networkPriority), - priority, + priority ), - then, + then ).then((_) => - log.debug("Enqueued active players processed.", "DlManager"), + log.debug("Enqueued active players processed.", "DlManager") ); } else processThen( queue.add( async () => playerService.refreshAll(force, networkPriority), - priority, + priority ), - then, + then ).then((_) => - log.debug("Enqueued active players processed.", "DlManager"), + log.debug("Enqueued active players processed.", "DlManager") ); break; @@ -149,21 +149,21 @@ const enqueue = async ( queue.add( async () => scoresService.refresh(data.playerId, force, networkPriority), - priority, + priority ), - then, + then ).then((_) => - log.debug("Enqueued players scores processed.", "DlManager"), + log.debug("Enqueued players scores processed.", "DlManager") ); else processThen( queue.add( async () => scoresService.refreshAll(force, networkPriority), - priority, + priority ), - then, + then ).then((_) => - log.debug("Enqueued players scores processed.", "DlManager"), + log.debug("Enqueued players scores processed.", "DlManager") ); break; @@ -173,9 +173,9 @@ const enqueue = async ( processThen( queue.add( async () => beatSaviorService.refreshAll(force, networkPriority), - priority, + priority ), - then, + then ).then((_) => log.debug("Enqueued Beat Savior processed.", "DlManager")); break; @@ -186,14 +186,14 @@ const enqueue = async ( processThen( queue.add( async () => scoresService.updateRankAndPpFromTheQueue(), - priority, + priority ), - then, + then ).then((_) => log.debug( "Enqueued player scores rank & pp updates processed.", - "DlManager", - ), + "DlManager" + ) ); break; @@ -203,9 +203,9 @@ const enqueue = async ( processThen( queue.add(async () => accSaberService.refreshAll(), priority), - then, + then ).then((_) => - log.debug("Enqueued AccSaber updates processed.", "DlManager"), + log.debug("Enqueued AccSaber updates processed.", "DlManager") ); break; @@ -271,7 +271,7 @@ export default async () => { const nodeId = eventBus.getNodeId(); log.info( `Node ${nodeId} is a leader, queue processing enabled`, - "DlManager", + "DlManager" ); await startSyncing(queue); @@ -284,7 +284,7 @@ export default async () => { TYPES.ACTIVE_PLAYERS, true, { playerId, add: true }, - async () => enqueue(queue, TYPES.PLAYER_SCORES, true, { playerId }), + async () => enqueue(queue, TYPES.PLAYER_SCORES, true, { playerId }) ); }; diff --git a/src/network/errors.js b/src/network/errors.js index 66aea9b..7ac9c2a 100644 --- a/src/network/errors.js +++ b/src/network/errors.js @@ -33,7 +33,7 @@ export class SsrHttpResponseError extends SsrNetworkError { `HTTP Error Response: ${ response && response.status ? response.status : "None" } ${response && response.statusText ? response.statusText : ""}`, - ...args, + ...args ); this.name = "SsrHttpResponseError"; diff --git a/src/network/fetch.js b/src/network/fetch.js index a034a28..e214f3f 100644 --- a/src/network/fetch.js +++ b/src/network/fetch.js @@ -97,12 +97,12 @@ export async function fetchUrl(url, options = {}, cors = true) { export async function fetchJson( url, - { cacheTtl = null, maxAge = null, ...restOptions } = {}, + { cacheTtl = null, maxAge = null, ...restOptions } = {} ) { const options = getOptionsWithCacheKey( url, { cacheTtl, maxAge, ...restOptions }, - "json", + "json" ); const { @@ -129,7 +129,7 @@ export async function fetchJson( body, }, fetchCacheKey, - fetchCacheTtl, + fetchCacheTtl ); }) .catch((err) => { @@ -141,12 +141,12 @@ export async function fetchJson( export async function fetchHtml( url, - { cacheTtl = null, maxAge = null, ...restOptions } = {}, + { cacheTtl = null, maxAge = null, ...restOptions } = {} ) { const options = getOptionsWithCacheKey( url, { cacheTtl, maxAge, ...restOptions }, - "json", + "json" ); const { @@ -172,7 +172,7 @@ export async function fetchHtml( body: new DOMParser().parseFromString(body, "text/html"), }, fetchCacheKey, - fetchCacheTtl, + fetchCacheTtl ); }); } diff --git a/src/network/queues/accsaber/api-queue.js b/src/network/queues/accsaber/api-queue.js index e7ee0f9..2caa309 100644 --- a/src/network/queues/accsaber/api-queue.js +++ b/src/network/queues/accsaber/api-queue.js @@ -21,54 +21,54 @@ export default (options = {}) => { category = "overall", page = 1, priority = PRIORITY.FG_LOW, - options = {}, + options = {} ) => fetchJson( substituteVars(RANKING_URL, { category, page }), options, - priority, + priority ); const scores = async ( playerId, page = 1, priority = PRIORITY.FG_LOW, - options = {}, + options = {} ) => fetchJson( substituteVars(PLAYER_SCORES_URL, { playerId, page }), options, - priority, + priority ); const playerRankHistory = async ( playerId, priority = PRIORITY.FG_LOW, - options = {}, + options = {} ) => fetchJson( substituteVars(PLAYER_RANK_HISTORY, { playerId }), options, - priority, + priority ); const leaderboard = async ( leaderboardId, page = 1, priority = PRIORITY.FG_LOW, - options = {}, + options = {} ) => fetchJson( substituteVars(LEADERBOARD_URL, { leaderboardId, page }), options, - priority, + priority ); const leaderboardInfo = async ( leaderboardId, priority = PRIORITY.FG_LOW, - options = {}, + options = {} ) => fetchJson( substituteVars(LEADERBOARD_INFO_URL, { leaderboardId }), options, - priority, + priority ); return { diff --git a/src/network/queues/http-queue.js b/src/network/queues/http-queue.js index 0f9214b..94d76df 100644 --- a/src/network/queues/http-queue.js +++ b/src/network/queues/http-queue.js @@ -78,7 +78,7 @@ export default (options = {}) => { fetchFunc, url, options, - priority = PRIORITY.FG_LOW, + priority = PRIORITY.FG_LOW ) => { for (let i = 0; i <= retries; i++) { try { @@ -140,11 +140,11 @@ export default (options = {}) => { const queuedFetchJson = async (url, options, priority = PRIORITY.FG_LOW) => resolvePromiseOrWaitForPending(url, () => - retriedFetch(fetchJson, url, options, priority), + retriedFetch(fetchJson, url, options, priority) ); const queuedFetchHtml = async (url, options, priority = PRIORITY.FG_LOW) => resolvePromiseOrWaitForPending(url, () => - retriedFetch(fetchHtml, url, options, priority), + retriedFetch(fetchHtml, url, options, priority) ); const getRateLimit = () => currentRateLimit; diff --git a/src/network/queues/queues.js b/src/network/queues/queues.js index 7ffa958..315a500 100644 --- a/src/network/queues/queues.js +++ b/src/network/queues/queues.js @@ -63,10 +63,10 @@ const initQueue = (queue) => { export default { SCORESABER_API: initQueue( - createScoreSaberApiQueue({ concurrency: 3, timeout: 95000 }), + createScoreSaberApiQueue({ concurrency: 3, timeout: 95000 }) ), SCORESABER_PAGE: initQueue( - createScoreSaberPageQueue({ concurrency: 3, timeout: 30000 }), + createScoreSaberPageQueue({ concurrency: 3, timeout: 30000 }) ), BEATMAPS: initQueue( createBeatMapsApiQueue({ @@ -74,7 +74,7 @@ export default { timeout: 10000, intervalCap: 10, interval: 1000, - }), + }) ), BEATSAVIOR: initQueue( createBeatSaviorApiQueue({ @@ -82,7 +82,7 @@ export default { timeout: 10000, intervalCap: 60, interval: 60000, - }), + }) ), TWITCH: initQueue( createTwitchApiQueue({ @@ -90,10 +90,10 @@ export default { timeout: 8000, intervalCap: 800, interval: 60000, - }), + }) ), ACCSABER: initQueue( - createAccSaberApiQueue({ concurrency: 2, timeout: 10000 }), + createAccSaberApiQueue({ concurrency: 2, timeout: 10000 }) ), PRIORITY, }; diff --git a/src/network/queues/scoresaber/api-queue.js b/src/network/queues/scoresaber/api-queue.js index b400532..26b959c 100644 --- a/src/network/queues/scoresaber/api-queue.js +++ b/src/network/queues/scoresaber/api-queue.js @@ -27,7 +27,7 @@ export default (options = {}) => { playerId, page = 1, priority = PRIORITY.FG_LOW, - options = {}, + options = {} ) => fetchJson(substituteVars(baseUrl, { playerId, page }), options, priority); @@ -35,21 +35,21 @@ export default (options = {}) => { fetchJson( substituteVars(SS_API_PLAYER_INFO_URL, { playerId }), options, - priority, + priority ); const recentScores = async ( playerId, page = 1, priority = PRIORITY.FG_LOW, - options = {}, + options = {} ) => fetchScores(SS_API_RECENT_SCORES_URL, playerId, page, priority, options); const topScores = async ( playerId, page = 1, priority = PRIORITY.FG_LOW, - options = {}, + options = {} ) => fetchScores(SS_API_TOP_SCORES_URL, playerId, page, priority, options); const findPlayer = async (query, priority = PRIORITY.FG_LOW, options = {}) => @@ -58,18 +58,18 @@ export default (options = {}) => { query: encodeURIComponent(query), }), options, - priority, + priority ); const rankingGlobal = async ( page = 1, priority = PRIORITY.FG_LOW, - options = {}, + options = {} ) => fetchJson( substituteVars(SS_API_RANKING_GLOBAL_URL, { page }), options, - priority, + priority ); const rankingGlobalPages = async (priority = PRIORITY.FG_LOW, options = {}) => diff --git a/src/network/queues/scoresaber/page-queue.js b/src/network/queues/scoresaber/page-queue.js index b7104ea..ed097e5 100644 --- a/src/network/queues/scoresaber/page-queue.js +++ b/src/network/queues/scoresaber/page-queue.js @@ -24,7 +24,7 @@ export const parseSsInt = (text) => { export const parseSsFloat = (text) => text ? parseFloat( - getFirstRegexpMatch(/([0-9,.]+)\s*$/, text.replace(/[^\d.]/g, "")), + getFirstRegexpMatch(/([0-9,.]+)\s*$/, text.replace(/[^\d.]/g, "")) ) : null; @@ -78,32 +78,32 @@ export default (options = {}) => { const rankeds = async ( page = 1, priority = PRIORITY.BG_NORMAL, - options = {}, + options = {} ) => fetchJson(substituteVars(RANKEDS_URL, { page }), options, priority).then( (r) => { r.body = processRankeds(r.body); return r; - }, + } ); const processPlayerProfile = (playerId, doc) => { cfDecryptEmail(doc); let avatar = getImgUrl( - opt(doc.querySelector(".column.avatar img"), "src", null), + opt(doc.querySelector(".column.avatar img"), "src", null) ); let playerName = opt( doc.querySelector(".content .column:not(.avatar) .title a"), - "innerText", + "innerText" ); playerName = playerName ? playerName.trim() : null; let country = getFirstRegexpMatch( /^.*?\/flags\/([^.]+)\..*$/, - opt(doc.querySelector(".content .column .title img"), "src"), + opt(doc.querySelector(".content .column .title img"), "src") ); country = country ? country.toUpperCase() : null; @@ -111,8 +111,8 @@ export default (options = {}) => { opt( doc.querySelector(".pagination .pagination-list li a.is-current"), "innerText", - null, - ), + null + ) ); pageNum = !isNaN(pageNum) ? pageNum : null; @@ -120,8 +120,8 @@ export default (options = {}) => { opt( doc.querySelector(".pagination .pagination-list li:last-of-type"), "innerText", - null, - ), + null + ) ); pageQty = !isNaN(pageQty) ? pageQty : null; @@ -130,31 +130,31 @@ export default (options = {}) => { /^\s*(?:[^:]+)\s*:?\s*<\/strong>\s*(.*)$/, opt( doc.querySelector( - ".columns .column:not(.is-narrow) ul li:nth-of-type(3)", + ".columns .column:not(.is-narrow) ul li:nth-of-type(3)" ), - "innerHTML", - ), - ), + "innerHTML" + ) + ) ); totalItems = !isNaN(totalItems) ? totalItems : 0; let playerRank = parseSsInt( opt( doc.querySelector( - ".content .column ul li:first-of-type a:first-of-type", + ".content .column ul li:first-of-type a:first-of-type" ), - "innerText", - ), + "innerText" + ) ); playerRank = !isNaN(playerRank) ? playerRank : null; let countryRank = parseSsInt( opt( doc.querySelector( - '.content .column ul li:first-of-type a[href^="/global?country="]', + '.content .column ul li:first-of-type a[href^="/global?country="]' ), - "innerText", - ), + "innerText" + ) ); countryRank = !isNaN(countryRank) ? countryRank : null; @@ -170,7 +170,7 @@ export default (options = {}) => { [...doc.querySelectorAll(".content .column ul li")] .map((li) => { const matches = li.innerHTML.match( - /^\s*([^:]+)\s*:?\s*<\/strong>\s*(.*)$/, + /^\s*([^:]+)\s*:?\s*<\/strong>\s*(.*)$/ ); if (!matches) return null; @@ -219,7 +219,7 @@ export default (options = {}) => { const item = mapping.find((m) => m.key === matches[1]); return item ? { ...item, value } : { label: matches[1], value }; }) - .filter((s) => s), + .filter((s) => s) ) .reduce( (cum, item) => { @@ -255,7 +255,7 @@ export default (options = {}) => { return cum; }, - { inactiveAccount: false, bannedAccount: false }, + { inactiveAccount: false, bannedAccount: false } ); const scores = [...doc.querySelectorAll("table.ranking tbody tr")].map( @@ -274,7 +274,7 @@ export default (options = {}) => { if (song) { const leaderboardId = parseInt( getFirstRegexpMatch(/leaderboard\/(\d+)/, song.href), - 10, + 10 ); ret.leaderboardId = leaderboardId ? leaderboardId : null; } else { @@ -293,7 +293,7 @@ export default (options = {}) => { .replace(/&/g, "&") .replace( /\[email protected]<\/span>/g, - "", + "" ) .match(/^(.*?)\s*]+>(.*?)<\/span>/) : null; @@ -328,7 +328,7 @@ export default (options = {}) => { ret.timeSet = songDate ? dateFromString(songDate.title) : null; const pp = parseSsFloat( - opt(tr.querySelector("th.score .scoreTop.ppValue"), "innerText"), + opt(tr.querySelector("th.score .scoreTop.ppValue"), "innerText") ); ret.pp = !isNaN(pp) ? pp : null; @@ -337,9 +337,9 @@ export default (options = {}) => { /^\(([0-9.]+)pp\)$/, opt( tr.querySelector("th.score .scoreTop.ppWeightedValue"), - "innerText", - ), - ), + "innerText" + ) + ) ); ret.ppWeighted = !isNaN(ppWeighted) ? ppWeighted : null; @@ -380,7 +380,7 @@ export default (options = {}) => { } return ret; - }, + } ); const recentPlay = scores && scores.length && scores[0].timeSet ? scores[0].timeSet : null; @@ -394,18 +394,18 @@ export default (options = {}) => { externalProfileUrl: opt( doc.querySelector(".content .column:not(.avatar) .title a"), "href", - null, + null ), history: getFirstRegexpMatch( /data:\s*\[([0-9,]+)\]/, - doc.body.innerHTML, + doc.body.innerHTML ), country, badges: [...doc.querySelectorAll(".column.avatar center img")].map( (img) => ({ image: getImgUrl(img.src), description: img.title, - }), + }) ), rank: stats.rank ? stats.rank : null, countryRank: stats.countryRank ? stats.countryRank : null, @@ -435,7 +435,7 @@ export default (options = {}) => { fetchHtml( substituteVars(PLAYER_PROFILE_URL, { playerId }), options, - priority, + priority ).then((r) => { r.body = processPlayerProfile(playerId, r.body); @@ -451,17 +451,17 @@ export default (options = {}) => { const id = getFirstRegexpMatch(/\/(\d+)$/, a.href); const avatar = getImgUrl( - opt(tr.querySelector("td.picture img"), "src", null), + opt(tr.querySelector("td.picture img"), "src", null) ); let country = getFirstRegexpMatch( /^.*?\/flags\/([^.]+)\..*$/, - opt(tr.querySelector("td.player img"), "src", null), + opt(tr.querySelector("td.player img"), "src", null) ); country = country ? country.toUpperCase() : null; let difference = parseSsInt( - opt(tr.querySelector("td.diff"), "innerText", null), + opt(tr.querySelector("td.diff"), "innerText", null) ); difference = !isNaN(difference) ? difference : null; @@ -469,15 +469,15 @@ export default (options = {}) => { playerName = playerName || playerName === "" ? playerName.trim() : null; let pp = parseSsFloat( - opt(tr.querySelector("td.pp .scoreTop.ppValue"), "innerText"), + opt(tr.querySelector("td.pp .scoreTop.ppValue"), "innerText") ); pp = !isNaN(pp) ? pp : null; let rank = parseSsInt( getFirstRegexpMatch( /^\s*#(\d+)\s*$/, - opt(tr.querySelector("td.rank"), "innerText", null), - ), + opt(tr.querySelector("td.rank"), "innerText", null) + ) ); rank = !isNaN(rank) ? rank : null; @@ -491,7 +491,7 @@ export default (options = {}) => { pp, rank, }; - }, + } ); return { players: data }; @@ -501,12 +501,12 @@ export default (options = {}) => { country, page = 1, priority = PRIORITY.FG_LOW, - options = {}, + options = {} ) => fetchHtml( substituteVars(COUNTRY_RANKING_URL, { country, page }), options, - priority, + priority ).then((r) => { r.body = processCountryRanking(country, r.body); @@ -529,11 +529,11 @@ export default (options = {}) => { }; ret.player.playerInfo.avatar = getImgUrl( - opt(tr.querySelector(".picture img"), "src", null), + opt(tr.querySelector(".picture img"), "src", null) ); ret.score.rank = parseSsInt( - opt(tr.querySelector("td.rank"), "innerText"), + opt(tr.querySelector("td.rank"), "innerText") ); if (isNaN(ret.score.rank)) ret.score.rank = null; @@ -541,7 +541,7 @@ export default (options = {}) => { if (player) { let country = getFirstRegexpMatch( /^.*?\/flags\/([^.]+)\..*$/, - opt(player.querySelector("img"), "src", ""), + opt(player.querySelector("img"), "src", "") ); country = country ? country.toUpperCase() : null; if (country) { @@ -551,14 +551,14 @@ export default (options = {}) => { ret.player.name = opt( player.querySelector("span.songTop.pp"), - "innerText", + "innerText" ); ret.player.name = ret.player.name ? ret.player.name.trim().replace("'", "'") : null; ret.player.playerId = getFirstRegexpMatch( /\/u\/(\d+)((\?|&|#).*)?$/, - opt(player, "href", ""), + opt(player, "href", "") ); ret.player.playerId = ret.player.playerId ? ret.player.playerId.trim() @@ -574,7 +574,7 @@ export default (options = {}) => { ret.score.timeSetString = opt( tr.querySelector("td.timeset"), "innerText", - null, + null ); if (ret.score.timeSetString) ret.score.timeSetString = ret.score.timeSetString.trim(); @@ -602,7 +602,7 @@ export default (options = {}) => { const diffs = [...doc.querySelectorAll(".tabs ul li a")].map((a) => { let leaderboardId = parseInt( getFirstRegexpMatch(/leaderboard\/(\d+)$/, a.href), - 10, + 10 ); if (isNaN(leaderboardId)) leaderboardId = null; @@ -615,7 +615,7 @@ export default (options = {}) => { const currentDiffHuman = opt( doc.querySelector(".tabs li.is-active a span"), "innerText", - null, + null ); let diff = null; @@ -628,20 +628,20 @@ export default (options = {}) => { const songName = opt( doc.querySelector( - ".column.is-one-third-desktop .box:first-of-type .title a", + ".column.is-one-third-desktop .box:first-of-type .title a" ), "innerText", - null, + null ); const imageUrl = getImgUrl( opt( doc.querySelector( - ".column.is-one-third-desktop .box:first-of-type .columns .column.is-one-quarter img", + ".column.is-one-third-desktop .box:first-of-type .columns .column.is-one-quarter img" ), "src", - null, - ), + null + ) ); const songInfo = [ @@ -656,13 +656,13 @@ export default (options = {}) => { ] .map((sid) => { let songInfoBox = doc.querySelector( - ".column.is-one-third-desktop .box:first-of-type", + ".column.is-one-third-desktop .box:first-of-type" ); return { ...sid, value: songInfoBox ? songInfoBox.innerHTML.match( - new RegExp(sid.label + ":\\s*(.*?)", "i"), + new RegExp(sid.label + ":\\s*(.*?)", "i") ) : null, }; @@ -708,7 +708,7 @@ export default (options = {}) => { return cum; }, - { imageUrl, stats: {} }, + { imageUrl, stats: {} } ); const { stats, ...song } = songInfo; @@ -718,9 +718,9 @@ export default (options = {}) => { opt( doc.querySelector(".pagination .pagination-list li:last-of-type"), "innerText", - null, + null ), - 10, + 10 ); if (isNaN(pageQty)) pageQty = null; @@ -736,7 +736,7 @@ export default (options = {}) => { let diffChartText = getFirstRegexpMatch( /'difficulty',\s*([0-9.,\s]+)\s*\]/, - doc.body.innerHTML, + doc.body.innerHTML ); let diffChart = (diffChartText ? diffChartText : "") .split(",") @@ -758,12 +758,12 @@ export default (options = {}) => { leaderboardId, page = 1, priority = PRIORITY.FG_LOW, - options = {}, + options = {} ) => fetchHtml( substituteVars(LEADERBOARD_URL, { leaderboardId, page }), options, - priority, + priority ).then((r) => { r.body = processLeaderboard(leaderboardId, page, r.body); diff --git a/src/network/queues/twitch/api-queue.js b/src/network/queues/twitch/api-queue.js index bd495f7..dab6267 100644 --- a/src/network/queues/twitch/api-queue.js +++ b/src/network/queues/twitch/api-queue.js @@ -7,7 +7,7 @@ const CLIENT_ID = "u0swxz56n4iumc634at1osoqdk31qt"; const TWITCH_AUTH_URL = "https://id.twitch.tv/oauth2"; const AUTHORIZATION_URL = `${TWITCH_AUTH_URL}/authorize?client_id=${CLIENT_ID}&redirect_uri=${encodeURIComponent( - ssrConfig.domain + "/twitch", + ssrConfig.domain + "/twitch" )}&response_type=token` + "&scope=${scopes}&state=${state}"; const VALIDATE_URL = `${TWITCH_AUTH_URL}/validate`; @@ -26,7 +26,7 @@ export default (options = {}) => { url, accessToken, priority = PRIORITY.FG_LOW, - options = {}, + options = {} ) => fetchJson( url, @@ -37,7 +37,7 @@ export default (options = {}) => { Authorization: `Bearer ${accessToken}`, }, }, - priority, + priority ); const getAuthUrl = (state = "", scopes = "") => @@ -49,25 +49,25 @@ export default (options = {}) => { const validateToken = async ( accessToken, priority = PRIORITY.FG_LOW, - options = {}, + options = {} ) => fetchJson( VALIDATE_URL, { ...options, headers: { Authorization: `OAuth ${accessToken}` } }, - priority, + priority ); const profile = async ( accessToken, login, priority = PRIORITY.FG_LOW, - options = {}, + options = {} ) => fetchApi( substituteVars(PROFILE_URL, { login: encodeURIComponent(login) }), accessToken, priority, - options, + options ); const videos = async ( @@ -75,7 +75,7 @@ export default (options = {}) => { userId, type = "archive", priority = PRIORITY.FG_LOW, - options = {}, + options = {} ) => fetchApi( substituteVars(VIDEOS_URL, { @@ -84,20 +84,20 @@ export default (options = {}) => { }), accessToken, priority, - options, + options ); const streams = async ( accessToken, userId, priority = PRIORITY.FG_LOW, - options = {}, + options = {} ) => fetchApi( substituteVars(STREAMS_URL, { userId: encodeURIComponent(userId) }), accessToken, priority, - options, + options ); return { diff --git a/src/services/accsaber.js b/src/services/accsaber.js index 2096ede..98a6389 100644 --- a/src/services/accsaber.js +++ b/src/services/accsaber.js @@ -43,7 +43,7 @@ export default () => { const getCategories = async () => { const categories = await resolvePromiseOrWaitForPending( `accSaberCategories`, - () => accSaberCategoriesRepository().getAll(), + () => accSaberCategoriesRepository().getAll() ); const getIdx = (category) => { @@ -58,25 +58,25 @@ export default () => { resolvePromiseOrWaitForPending(`accSaberPlayer/${playerId}`, () => accSaberPlayersRepository().getAllFromIndex( "accsaber-players-playerId", - playerId, - ), + playerId + ) ); const getRanking = async (category = "overall") => accSaberPlayersRepository().getAllFromIndex( "accsaber-players-category", - category, + category ); const getPlayerHistory = async (playerId) => resolvePromiseOrWaitForPending(`accSaberPlayerHistory/${playerId}`, () => accSaberPlayersHistoryRepository().getAllFromIndex( "accsaber-players-history-playerId", - playerId, - ), + playerId + ) ); const isDataForPlayerAvailable = async (playerId) => (await Promise.all([getPlayer(playerId), getCategories()])).every( - (d) => d?.length, + (d) => d?.length ); const getPlayerGain = (playerHistory, daysAgo = 1, maxDaysAgo = 7) => @@ -85,7 +85,7 @@ export default () => { toAccSaberMidnight, "accSaberDate", daysAgo, - maxDaysAgo, + maxDaysAgo ); const getLastUpdatedKey = (type) => `accSaber${capitalize(type)}LastUpdated`; @@ -100,9 +100,9 @@ export default () => { if (lastUpdated && lastUpdated > new Date() - REFRESH_INTERVAL) { log.debug( `Refresh interval for ${type} not yet expired, skipping. Next refresh on ${formatDate( - addToDate(REFRESH_INTERVAL, lastUpdated), + addToDate(REFRESH_INTERVAL, lastUpdated) )}`, - "AccSaberService", + "AccSaberService" ); return false; @@ -116,7 +116,7 @@ export default () => { playerId, page = 1, priority = PRIORITY.FG_LOW, - { ...options } = {}, + { ...options } = {} ) => { if (!options) options = {}; if (!options.hasOwnProperty("cacheTtl")) @@ -124,7 +124,7 @@ export default () => { const categoriesByDisplayName = convertArrayToObjectByKey( await getCategories(), - "displayName", + "displayName" ); return ( @@ -136,7 +136,7 @@ export default () => { playerId, page, priority, - }), + }) ) ).map((s) => ({ ...s, @@ -150,7 +150,7 @@ export default () => { }; const getScoresHistogramDefinition = ( - serviceParams = { type: "overall", sort: "ap", order: "desc" }, + serviceParams = { type: "overall", sort: "ap", order: "desc" } ) => { const scoreType = serviceParams?.type ?? "overall"; const sort = serviceParams?.sort ?? "ap"; @@ -258,7 +258,7 @@ export default () => { const getPlayerScoresPage = async ( playerId, - serviceParams = { sort: "recent", order: "desc", page: 1 }, + serviceParams = { sort: "recent", order: "desc", page: 1 } ) => { let page = serviceParams?.page ?? 1; if (page < 1) page = 1; @@ -290,7 +290,7 @@ export default () => { const fetchPlayerRankHistory = async ( playerId, priority = PRIORITY.FG_LOW, - { ...options } = {}, + { ...options } = {} ) => { if (!options) options = {}; if (!options.hasOwnProperty("cacheTtl")) @@ -306,13 +306,13 @@ export default () => { const refreshCategories = async ( forceUpdate = false, priority = queues.PRIORITY.BG_NORMAL, - throwErrors = false, + throwErrors = false ) => { log.debug( `Starting AccSaber categories refreshing${ forceUpdate ? " (forced)" : "" }...`, - "AccSaberService", + "AccSaberService" ); try { @@ -327,7 +327,7 @@ export default () => { log.trace( `Fetching current categories from AccSaber...`, - "AccSaberService", + "AccSaberService" ); let categories = await accSaberCategoriesApiClient.getProcessed({ @@ -352,13 +352,13 @@ export default () => { const dbCategoriesNames = dbCategories.map((c) => c.name); const newCategories = categories.filter( - (c) => !dbCategories || !dbCategoriesNames.includes(c.name), + (c) => !dbCategories || !dbCategoriesNames.includes(c.name) ); if (newCategories && newCategories.length) log.debug( `${newCategories.length} new categories found`, - "AccSaberService", + "AccSaberService" ); await db.runInTransaction( @@ -385,14 +385,14 @@ export default () => { log.trace(`Updating categories in DB...`, "AccSaberService"); await Promise.all( - categories.map(async (c) => accSaberCategoriesStore.put(c)), + categories.map(async (c) => accSaberCategoriesStore.put(c)) ); log.trace(`Categories updated`, "AccSaberService"); log.trace( `Updating categories last update date in DB...`, - "AccSaberService", + "AccSaberService" ); await tx @@ -400,13 +400,13 @@ export default () => { .put(new Date(), getLastUpdatedKey("categories")); log.debug(`Categories last update date updated`, "AccSaberService"); - }, + } ); accSaberCategoriesRepository().addToCache(categories); keyValueRepository().setCache( getLastUpdatedKey("categories"), - new Date(), + new Date() ); log.debug(`Categories refreshing completed`, "AccSaberService"); @@ -427,7 +427,7 @@ export default () => { try { log.debug( `Updating player ${player.playerId} history`, - "AccSaberService", + "AccSaberService" ); const accSaberDate = toAccSaberMidnight(new Date()); @@ -441,9 +441,9 @@ export default () => { `Refresh interval for player ${ player.playerId } history not yet expired, skipping. Next refresh on ${formatDate( - addToDate(REFRESH_INTERVAL, lastUpdated), + addToDate(REFRESH_INTERVAL, lastUpdated) )}`, - "AccSaberService", + "AccSaberService" ); return; @@ -452,7 +452,7 @@ export default () => { const categories = (await getCategories())?.map((c) => c.name) ?? null; if (!categories) { log.trace( - `No categories found, skip updating player ${player.playerId} history.`, + `No categories found, skip updating player ${player.playerId} history.` ); return; } @@ -460,7 +460,7 @@ export default () => { let accStats = {}; for (const category of categories) { const playerAccInfo = ((await getRanking(category)) ?? []).find( - (p) => p.playerId === player.playerId, + (p) => p.playerId === player.playerId ); if (!playerAccInfo) continue; @@ -492,7 +492,7 @@ export default () => { } else { log.trace( `No Acc Saber data for player ${player.playerId}, skipping history updating.`, - "AccSaberService", + "AccSaberService" ); return; @@ -503,7 +503,7 @@ export default () => { log.debug( `Player ${player.playerId} history updating error.`, "AccSaberService", - e, + e ); } }; @@ -512,13 +512,13 @@ export default () => { category = "overall", forceUpdate = false, priority = queues.PRIORITY.BG_NORMAL, - throwErrors = false, + throwErrors = false ) => { log.debug( `Starting AccSaber ${category} ranking refreshing${ forceUpdate ? " (forced)" : "" }...`, - "AccSaberService", + "AccSaberService" ); try { @@ -535,7 +535,7 @@ export default () => { log.trace( `Fetching current ${category} ranking from AccSaber...`, - "AccSaberService", + "AccSaberService" ); const ranking = await accSaberRankingApiClient.getProcessed({ @@ -545,7 +545,7 @@ export default () => { if (!ranking || !ranking.length) { log.warn( `AccSaber returned empty ${category} ranking`, - "AccSaberService", + "AccSaberService" ); return null; @@ -554,7 +554,7 @@ export default () => { log.trace( `${capitalize(category)} ranking fetched`, "AccSaberService", - ranking, + ranking ); log.trace(`Updating ${category} ranking...`, "AccSaberService"); @@ -570,7 +570,7 @@ export default () => { log.trace( `Remove old players from DB for category ${category}`, - "AccSaberService", + "AccSaberService" ); while (cursor) { @@ -589,14 +589,14 @@ export default () => { log.trace(`Updating players in DB...`, "AccSaberService"); await Promise.all( - ranking.map(async (p) => accSaberPlayersStore.put(p)), + ranking.map(async (p) => accSaberPlayersStore.put(p)) ); log.trace(`Players updated`, "AccSaberService"); log.trace( `Updating players last update date in DB...`, - "AccSaberService", + "AccSaberService" ); await tx @@ -604,7 +604,7 @@ export default () => { .put(new Date(), getLastUpdatedKey(rankingType)); log.debug(`Players last update date updated`, "AccSaberService"); - }, + } ); accSaberPlayersRepository().addToCache(ranking); @@ -612,7 +612,7 @@ export default () => { log.debug( `${capitalize(category)} ranking refreshing completed`, - "AccSaberService", + "AccSaberService" ); return ranking.sort((a, b) => a.rank - b.rank); @@ -622,7 +622,7 @@ export default () => { log.debug( ` ${capitalize(category)} ranking refreshing error`, "AccSaberService", - e, + e ); return null; @@ -633,13 +633,13 @@ export default () => { category = "overall", forceUpdate = false, priority = queues.PRIORITY.BG_NORMAL, - throwErrors = false, + throwErrors = false ) => { log.trace( `Starting AccSaber all data refreshing${ forceUpdate ? " (forced)" : "" }...`, - "AccSaberService", + "AccSaberService" ); try { @@ -650,7 +650,7 @@ export default () => { const allRankings = await Promise.all( dbCategories.all .map((c) => c.name) - .map(async (category) => refreshRanking(category)), + .map(async (category) => refreshRanking(category)) ); log.debug(`All data refreshing completed.`, "AccSaberService"); @@ -665,8 +665,8 @@ export default () => { Promise.all( (await playerService.getAllActive()).map(async (player) => - updatePlayerHistory(player), - ), + updatePlayerHistory(player) + ) ).then((_) => _); return dbCategories.all.map((c) => ({ diff --git a/src/services/beatmaps.js b/src/services/beatmaps.js index b24c364..3973808 100644 --- a/src/services/beatmaps.js +++ b/src/services/beatmaps.js @@ -52,7 +52,7 @@ export default () => { suspension.activeTo = addToDate( Math.pow(2, suspension.count) * HOUR, - suspension.activeTo, + suspension.activeTo ); suspension.count++; @@ -97,7 +97,7 @@ export default () => { si.diffs.forEach((d) => { const newNotesCnt = INVALID_NOTES_COUNT_FIXES[hash].find( - (f) => f.type === d?.characteristic && f.diff === d?.difficulty, + (f) => f.type === d?.characteristic && f.diff === d?.difficulty ); if (!newNotesCnt) return; @@ -114,7 +114,7 @@ export default () => { forceUpdate = false, cacheOnly = false, errSongId = "", - hash = null, + hash = null ) => { if (!forceUpdate && songInfo) return fixInvalidNotesCount(hash, songInfo); @@ -158,7 +158,7 @@ export default () => { forceUpdate = false, cacheOnly = false, signal = null, - priority = PRIORITY.FG_LOW, + priority = PRIORITY.FG_LOW ) => { hash = hash.toLowerCase(); @@ -170,7 +170,7 @@ export default () => { forceUpdate, cacheOnly, hash, - hash, + hash ); }; @@ -179,13 +179,13 @@ export default () => { forceUpdate = false, cacheOnly = false, signal = null, - priority = PRIORITY.FG_LOW, + priority = PRIORITY.FG_LOW ) => { key = key.toLowerCase(); const songInfo = await songsBeatMapsRepository().getFromIndex( "songs-beatmaps-key", - key, + key ); return fetchSong( @@ -193,7 +193,7 @@ export default () => { () => keyApiClient.getProcessed({ key, signal, priority }), forceUpdate, cacheOnly, - key, + key ); }; @@ -254,7 +254,7 @@ export default () => { }, stars: null, }; - }), + }) ) .filter((diff) => diff); }, []); diff --git a/src/services/beatsavior.js b/src/services/beatsavior.js index 268c5bf..1229033 100644 --- a/src/services/beatsavior.js +++ b/src/services/beatsavior.js @@ -40,7 +40,7 @@ export default () => { const getPlayerScores = async (playerId) => resolvePromiseOrWaitForPending(`getPlayerScores/${playerId}`, () => - beatSaviorRepository().getAllFromIndex("beat-savior-playerId", playerId), + beatSaviorRepository().getAllFromIndex("beat-savior-playerId", playerId) ); const getPlayerScoresWithScoreSaber = async (playerId) => { @@ -50,8 +50,8 @@ export default () => { scoresService.getPlayerScoresAsObject( playerId, (score) => score?.leaderboard?.song?.hash?.toLowerCase() ?? null, - true, - ), + true + ) ), ]); @@ -61,7 +61,7 @@ export default () => { const ssScore = playerScores[bsData.hash.toLowerCase()].find((ssScore) => - isScoreMatchingBsData(ssScore, bsData, true), + isScoreMatchingBsData(ssScore, bsData, true) ) ?? null; return { @@ -101,7 +101,7 @@ export default () => { }; const getScoresHistogramDefinition = ( - serviceParams = { sort: "recent", order: "desc" }, + serviceParams = { sort: "recent", order: "desc" } ) => { const sort = serviceParams?.sort ?? "recent"; const order = serviceParams?.order ?? "desc"; @@ -188,7 +188,7 @@ export default () => { const getPlayerScoresPage = async ( playerId, - serviceParams = { sort: "recent", order: "desc", page: 1 }, + serviceParams = { sort: "recent", order: "desc", page: 1 } ) => { let page = serviceParams?.page ?? 1; if (page < 1) page = 1; @@ -250,14 +250,14 @@ export default () => { const updateData = async (playerId, data) => { log.debug( `Updating Beat Savior data for player "${playerId}"...`, - "BeatSaviorService", + "BeatSaviorService" ); await Promise.all(data.map(async (d) => beatSaviorRepository().set(d))); log.debug( `Update player "${playerId}" Beat Savior last refresh date...`, - "BeatSaviorService", + "BeatSaviorService" ); await beatSaviorPlayersRepository().set({ @@ -267,7 +267,7 @@ export default () => { log.debug( `Beat Savior data for player "${playerId}" updated.`, - "BeatSaviorService", + "BeatSaviorService" ); return data; @@ -277,7 +277,7 @@ export default () => { try { log.debug( `Fetching Beat Savior data for player "${playerId}"...`, - "BeatSaviorService", + "BeatSaviorService" ); const data = await beatSaviorApiClient.getProcessed({ @@ -287,7 +287,7 @@ export default () => { if (!data) { log.debug( `No Beat Savior data for player "${playerId}"`, - "BeatSaviorService", + "BeatSaviorService" ); return null; @@ -298,7 +298,7 @@ export default () => { log.trace( `Beat Savior data for player "${playerId}" fetched`, "BeatSaviorService", - data, + data ); return updateData(playerId, data); @@ -313,13 +313,13 @@ export default () => { playerId, force = false, priority = PRIORITY.BG_NORMAL, - throwErrors = false, + throwErrors = false ) => { log.trace( `Starting refreshing BeatSavior for player "${playerId}" ${ force ? " (forced)" : "" }...`, - "BeatSaviorService", + "BeatSaviorService" ); try { @@ -339,9 +339,9 @@ export default () => { if (!force && bsPlayerInfo && nextUpdate > new Date()) { log.debug( `Beat Savior data is still fresh, skipping. Next refresh on ${formatDate( - nextUpdate, + nextUpdate )}`, - "BeatSaviorService", + "BeatSaviorService" ); return null; @@ -349,7 +349,7 @@ export default () => { if (player) { log.trace( `Player "${playerId}" is a cached one, checking recent play date`, - "BeatSaviorService", + "BeatSaviorService" ); if ( @@ -358,7 +358,7 @@ export default () => { ) { log.debug( `Beat Savior data for player "${playerId}" was refreshed after recent play, skipping`, - "BeatSaviorService", + "BeatSaviorService" ); return null; @@ -367,7 +367,7 @@ export default () => { } return resolvePromiseOrWaitForPending(`refresh/${playerId}`, () => - fetchPlayer(playerId, priority), + fetchPlayer(playerId, priority) ); } catch (e) { if (throwErrors) throw e; @@ -377,7 +377,7 @@ export default () => { e.toString ? `: ${e.toString()}` : "" }`, "BeatSaviorService", - e, + e ); return null; @@ -387,13 +387,13 @@ export default () => { const refreshAll = async ( force = false, priority = PRIORITY.BG_NORMAL, - throwErrors = false, + throwErrors = false ) => { log.trace( `Starting refreshing Beat Savior data for all players${ force ? " (forced)" : "" }...`, - "BeatSaviorService", + "BeatSaviorService" ); const allPlayers = await playerService.getAll(); @@ -409,15 +409,15 @@ export default () => { player.playerId, force, priority, - throwErrors, + throwErrors ), - })), + })) ); log.trace( `Beat Savior data for all players refreshed.`, "BeatSaviorService", - allRefreshed, + allRefreshed ); return allRefreshed; @@ -430,7 +430,7 @@ export default () => { if (!playerBsData || !playerBsData.length) return null; const bsData = playerBsData.find((bsData) => - isScoreMatchingBsData(score, bsData, true), + isScoreMatchingBsData(score, bsData, true) ); return bsData ? bsData : null; @@ -439,7 +439,7 @@ export default () => { const isDataForPlayerAvailable = async (playerId) => (await beatSaviorRepository().getFromIndex( "beat-savior-playerId", - playerId, + playerId )) !== undefined; const destroyService = () => { diff --git a/src/services/scoresaber/leaderboard.js b/src/services/scoresaber/leaderboard.js index 8d2be98..0aed512 100644 --- a/src/services/scoresaber/leaderboard.js +++ b/src/services/scoresaber/leaderboard.js @@ -33,7 +33,7 @@ export default () => { page = 1, priority = PRIORITY.FG_LOW, signal = null, - force = false, + force = false ) => resolvePromiseOrWaitForPending( `pageClient/leaderboard/${leaderboardId}/${page}`, @@ -44,7 +44,7 @@ export default () => { signal, priority, cacheTtl: MINUTE, - }), + }) ); const fetchAccSaberPage = async ( @@ -52,7 +52,7 @@ export default () => { page = 1, priority = PRIORITY.FG_LOW, signal = null, - force = false, + force = false ) => { if (page < 1) page = 1; @@ -65,7 +65,7 @@ export default () => { signal, priority, cacheTtl: ACCSABER_LEADERBOARD_NETWORK_TTL, - }), + }) ); if (!data || !data.scores) return data; @@ -77,7 +77,7 @@ export default () => { ...data, scores: data.scores.slice( startIdx, - startIdx + ACCSABER_LEADERBOARD_SCORES_PER_PAGE, + startIdx + ACCSABER_LEADERBOARD_SCORES_PER_PAGE ), }; }; @@ -85,7 +85,7 @@ export default () => { const getFriendsLeaderboard = async ( leaderboardId, priority = PRIORITY.FG_LOW, - signal = null, + signal = null ) => { const leaderboard = await resolvePromiseOrWaitForPending( `pageClient/leaderboard/${leaderboardId}/1`, @@ -96,7 +96,7 @@ export default () => { signal, priority, cacheTtl: MINUTE, - }), + }) ); const friends = convertArrayToObjectByKey(await friendsPromise, "playerId"); diff --git a/src/services/scoresaber/player.js b/src/services/scoresaber/player.js index c0e2de8..4522dfe 100644 --- a/src/services/scoresaber/player.js +++ b/src/services/scoresaber/player.js @@ -51,7 +51,7 @@ export default () => { const getFriends = async () => (await getAll()) .filter( - (player) => player && player.playerId && !isPlayerMain(player.playerId), + (player) => player && player.playerId && !isPlayerMain(player.playerId) ) .map((p) => p.playerId); @@ -64,7 +64,7 @@ export default () => { player && player.playerInfo && !player.playerInfo.inactive && - !player.playerInfo.banned, + !player.playerInfo.banned ); }; @@ -107,13 +107,13 @@ export default () => { const updatePlayer = async ( player, waitForSaving = true, - forceAdd = false, + forceAdd = false ) => { if (!player || !player.playerId) { log.warn( `Can not update player, empty playerId`, "PlayerService", - player, + player ); } @@ -135,8 +135,8 @@ export default () => { resolvePromiseOrWaitForPending(`playerHistory/${playerId}`, () => playersHistoryRepository().getAllFromIndex( "players-history-playerId", - playerId, - ), + playerId + ) ); const getPlayerGain = (playerHistory, daysAgo = 1, maxDaysAgo = 7) => @@ -145,7 +145,7 @@ export default () => { toSsMidnight, "ssDate", daysAgo, - maxDaysAgo, + maxDaysAgo ); const updatePlayerHistory = async (player) => { @@ -196,7 +196,7 @@ export default () => { if (badges?.length) accStats.accBadges = badges.reduce( (cum, b) => ({ ...cum, [b.label]: b.value }), - {}, + {} ); } @@ -241,7 +241,7 @@ export default () => { const updatePlayerRecentPlay = async ( playerId, recentPlay, - recentPlayLastUpdated = new Date(), + recentPlayLastUpdated = new Date() ) => { let player; @@ -277,19 +277,19 @@ export default () => { try { const player = await resolvePromiseOrWaitForPending( `pageClient/${playerId}`, - () => playerPageClient.getProcessed({ playerId }), + () => playerPageClient.getProcessed({ playerId }) ); const recentPlay = opt(player, "playerInfo.recentPlay"); const recentPlayLastUpdated = opt( player, - "playerInfo.recentPlayLastUpdated", + "playerInfo.recentPlayLastUpdated" ); if (!recentPlay || !recentPlayLastUpdated) return null; return updatePlayerRecentPlay( playerId, recentPlay, - recentPlayLastUpdated, + recentPlayLastUpdated ); } catch (err) { // swallow error @@ -304,7 +304,7 @@ export default () => { const fetchPlayer = async ( playerId, priority = PRIORITY.FG_LOW, - { fullResponse = false, ...options } = {}, + { fullResponse = false, ...options } = {} ) => resolvePromiseOrWaitForPending( `apiClient/${playerId}/${fullResponse}`, @@ -314,13 +314,13 @@ export default () => { playerId, priority, fullResponse, - }), + }) ); const findPlayer = async ( query, priority = PRIORITY.FG_LOW, - { fullResponse = false, ...options } = {}, + { fullResponse = false, ...options } = {} ) => resolvePromiseOrWaitForPending( `apiClient/find/${query}/${fullResponse}`, @@ -330,7 +330,7 @@ export default () => { query, priority, fullResponse, - }), + }) ); const fetchPlayerOrGetFromCache = async ( @@ -338,7 +338,7 @@ export default () => { refreshInterval = MINUTE, priority = PRIORITY.FG_LOW, signal = null, - force = false, + force = false ) => { const player = await getPlayer(playerId); @@ -358,7 +358,7 @@ export default () => { ...getDataFromResponse(fetchedPlayerResponse), profileLastUpdated: new Date(), }, - false, + false ).then((player) => { fetchPlayerAndUpdateRecentPlay(player.playerId); @@ -376,17 +376,17 @@ export default () => { force = false, priority = PRIORITY.BG_NORMAL, throwErrors = false, - addIfNotExists = false, + addIfNotExists = false ) => { log.trace( `Starting refreshing player "${playerId}" ${force ? " (forced)" : ""}...`, - "PlayerService", + "PlayerService" ); if (!playerId) { log.warn( `Can not refresh player if an empty playerId is given`, - "PlayerService", + "PlayerService" ); return null; @@ -407,9 +407,9 @@ export default () => { if (profileFreshnessDate > new Date()) { log.debug( `Profile is still fresh, skipping. Next refresh on ${formatDate( - profileFreshnessDate, + profileFreshnessDate )}`, - "PlayerService", + "PlayerService" ); return player; @@ -418,7 +418,7 @@ export default () => { log.trace( `Fetching player ${playerId} from ScoreSaber...`, - "PlayerService", + "PlayerService" ); const fetchedPlayer = await fetchPlayer(playerId, priority); @@ -432,7 +432,7 @@ export default () => { ) { log.warn( `ScoreSaber returned empty info for player ${playerId}`, - "PlayerService", + "PlayerService" ); return null; @@ -443,7 +443,7 @@ export default () => { player = await updatePlayer( { ...fetchedPlayer, profileLastUpdated: new Date() }, true, - addIfNotExists, + addIfNotExists ); updatePlayerHistory(player).then((_) => _); @@ -457,7 +457,7 @@ export default () => { log.debug( `Player refreshing error${e.toString ? `: ${e.toString()}` : ""}`, "PlayerService", - e, + e ); return null; @@ -467,11 +467,11 @@ export default () => { const refreshAll = async ( force = false, priority = PRIORITY.BG_NORMAL, - throwErrors = false, + throwErrors = false ) => { log.trace( `Starting refreshing all players${force ? " (forced)" : ""}...`, - "PlayerService", + "PlayerService" ); const allPlayers = await getAll(); @@ -482,8 +482,8 @@ export default () => { const allRefreshed = await Promise.all( allPlayers.map((player) => - refresh(player.playerId, force, priority, throwErrors), - ), + refresh(player.playerId, force, priority, throwErrors) + ) ); log.trace(`All players refreshed.`, "PlayerService", allRefreshed); diff --git a/src/services/scoresaber/pp.js b/src/services/scoresaber/pp.js index d1349a7..f29e1c3 100644 --- a/src/services/scoresaber/pp.js +++ b/src/services/scoresaber/pp.js @@ -18,7 +18,7 @@ export default () => { scores .filter((s) => s.pp > 0) .map((s) => s.pp) - .sort((a, b) => b - a), + .sort((a, b) => b - a) ) : null; @@ -26,10 +26,10 @@ export default () => { getTotalPp( Object.values({ ...(await resolvePromiseOrWaitForPending(`scores/${playerId}`, () => - scoresService.getPlayerScoresAsObject(playerId), + scoresService.getPlayerScoresAsObject(playerId) )), ...modifiedScores, - }), + }) ); async function getWhatIfScore(playerId, leaderboardId, pp = 0) { diff --git a/src/services/scoresaber/rankeds.js b/src/services/scoresaber/rankeds.js index aeee8fe..4f4f240 100644 --- a/src/services/scoresaber/rankeds.js +++ b/src/services/scoresaber/rankeds.js @@ -35,11 +35,11 @@ export default () => { const refreshRankeds = async ( forceUpdate = false, priority = queues.PRIORITY.BG_NORMAL, - throwErrors = false, + throwErrors = false ) => { log.trace( `Starting rankeds refreshing${forceUpdate ? " (forced)" : ""}...`, - "RankedsService", + "RankedsService" ); try { @@ -50,9 +50,9 @@ export default () => { if (lastUpdated && lastUpdated > new Date() - REFRESH_INTERVAL) { log.debug( `Refresh interval not yet expired, skipping. Next refresh on ${formatDate( - addToDate(REFRESH_INTERVAL, lastUpdated), + addToDate(REFRESH_INTERVAL, lastUpdated) )}`, - "RankedsService", + "RankedsService" ); return null; @@ -61,7 +61,7 @@ export default () => { log.trace( `Fetching current rankeds from ScoreSaber...`, - "RankedsService", + "RankedsService" ); fetchedRankedSongs = await rankedsPageClient.getProcessed({ priority }); if (!fetchedRankedSongs || !fetchedRankedSongs.length) { @@ -84,13 +84,13 @@ export default () => { return { ...s, firstSeen, oldStars: null }; }), - "leaderboardId", + "leaderboardId" ); // find differences between old and new ranked songs const newRankeds = arrayDifference( Object.keys(fetchedRankedSongs), - Object.keys(oldRankedSongs), + Object.keys(oldRankedSongs) ).map((leaderboardId) => ({ leaderboardId: parseInt(leaderboardId, 10), oldStars: null, @@ -110,20 +110,20 @@ export default () => { s.stars !== (fetchedRankedSongs[s.leaderboardId] ? opt(fetchedRankedSongs[s.leaderboardId], "stars", null) - : null), + : null) ) .map((s) => ({ leaderboardId: s.leaderboardId, oldStars: s.stars, stars: opt(fetchedRankedSongs[s.leaderboardId], "stars", null), timestamp: Date.now(), - })), + })) ); if (newRankeds && changed && changed.length - newRankeds.length > 0) log.debug( `${changed.length - newRankeds.length} changed ranked(s) found`, - "RankedsService", + "RankedsService" ); const changedLeaderboards = changed @@ -150,16 +150,16 @@ export default () => { async (tx) => { await Promise.all( changedLeaderboards.map(async (ranked) => - rankedsRepository().set(ranked, undefined, tx), - ), + rankedsRepository().set(ranked, undefined, tx) + ) ); await Promise.all( changed.map(async (rc) => - rankedsChangesRepository().set(rc, undefined, tx), - ), + rankedsChangesRepository().set(rc, undefined, tx) + ) ); await setLastUpdated(new Date()); - }, + } ); log.trace("Rankeds saved", "RankedsService"); diff --git a/src/services/scoresaber/ranking.js b/src/services/scoresaber/ranking.js index e88cb91..6fd57cc 100644 --- a/src/services/scoresaber/ranking.js +++ b/src/services/scoresaber/ranking.js @@ -15,17 +15,17 @@ export default () => { const fetchGlobal = async ( page = 1, priority = PRIORITY.FG_LOW, - signal = null, + signal = null ) => resolvePromiseOrWaitForPending(`apiClient/ranking/global/${page}`, () => - playersGlobalRankingApiClient.getProcessed({ page, signal, priority }), + playersGlobalRankingApiClient.getProcessed({ page, signal, priority }) ); const fetchCountry = async ( country, page = 1, priority = PRIORITY.FG_LOW, - signal = null, + signal = null ) => resolvePromiseOrWaitForPending( `pageClient/ranking/${country}/${page}`, @@ -35,17 +35,17 @@ export default () => { page, signal, priority, - }), + }) ); const fetchGlobalPages = async (priority = PRIORITY.FG_LOW, signal = null) => resolvePromiseOrWaitForPending(`apiClient/rankingGlobalPages`, () => - playersGlobalRankingPagesApiClient.getProcessed({ signal, priority }), + playersGlobalRankingPagesApiClient.getProcessed({ signal, priority }) ); const fetchGlobalCount = async ( priority = PRIORITY.FG_LOW, - signal = null, + signal = null ) => { const pages = await fetchGlobalPages(priority, signal); if (!pages || !Number.isFinite(pages)) return 0; @@ -73,8 +73,8 @@ export default () => { const ranking = ( await Promise.all( pages.map(async (page) => - country ? fetchCountry(country, page) : fetchGlobal(page), - ), + country ? fetchCountry(country, page) : fetchGlobal(page) + ) ) ) .reduce((cum, arr) => cum.concat(arr), []) diff --git a/src/services/scoresaber/scores.js b/src/services/scoresaber/scores.js index 0c089f6..d05e730 100644 --- a/src/services/scoresaber/scores.js +++ b/src/services/scoresaber/scores.js @@ -118,7 +118,7 @@ export default () => { const getPlayerScoresAsObject = async ( playerId, idFunc = (score) => opt(score, "leaderboard.leaderboardId"), - asArray = false, + asArray = false ) => convertScoresToObject(await getPlayerScores(playerId), idFunc, asArray); const getPlayerSongScore = async (playerId, leaderboardId) => scoresRepository().get(playerId + "_" + leaderboardId); @@ -137,7 +137,7 @@ export default () => { scores.reduce((allScores, scorePage) => [...allScores, ...scorePage], []); const isAnyScoreOlderThan = (scores, olderThan) => scores.some( - (s) => s.score && s.score.timeSet && s.score.timeSet <= olderThan, + (s) => s.score && s.score.timeSet && s.score.timeSet <= olderThan ); const createFetchUntilLastUpdated = (olderThan) => (scores) => isAnyScoreOlderThan(scores, olderThan); @@ -145,7 +145,7 @@ export default () => { const convertScoresToObject = ( scores, idFunc = (score) => opt(score, "leaderboard.leaderboardId"), - asArray = false, + asArray = false ) => scores.reduce((scoresObj, score) => { const _id = idFunc(score); @@ -176,11 +176,11 @@ export default () => { priority = PRIORITY.BG_NORMAL, signal = null, untilFunc = null, - dontReduce = false, + dontReduce = false ) => { log.debug( `Fetching scores of player "${playerId}" starting from page #${startPage}`, - "ScoresService", + "ScoresService" ); let data = []; @@ -212,7 +212,7 @@ export default () => { ) { // push only relevant scores and return data.push( - pageData.filter((score) => !untilFunc || !untilFunc([score])), + pageData.filter((score) => !untilFunc || !untilFunc([score])) ); break; @@ -238,11 +238,11 @@ export default () => { playerId, numOfPages, priority = PRIORITY.BG_NORMAL, - signal = null, + signal = null ) => { log.debug( `Fetching all scores of player "${playerId}, number of pages: ${numOfPages}`, - "ScoresService", + "ScoresService" ); const pages = Array(numOfPages) @@ -256,8 +256,8 @@ export default () => { page, signal, priority, - }), - ), + }) + ) ); if (!data || !data.length) return []; @@ -271,7 +271,7 @@ export default () => { priority, signal, null, - true, + true )), ]; } @@ -285,7 +285,7 @@ export default () => { opt(s, "score.timeSet") && s.score.timeSet > recentPlay ? s.score.timeSet : recentPlay, - defaultRecentPlay, + defaultRecentPlay ); const addScoreIndexFields = (playerId, score) => { @@ -310,12 +310,12 @@ export default () => { try { log.debug( "Rank and pp update queue, waiting for the scores to finish refreshing.", - "ScoresService", + "ScoresService" ); await refreshingFinished(); log.debug( "Rank and pp update queue, scores refreshed, start queue processing.", - "ScoresService", + "ScoresService" ); await db.runInTransaction( @@ -373,14 +373,14 @@ export default () => { if (cursor) cursor = await cursor.continue(); } } - }, + } ); log.debug("Rank and pp update queue processed.", "ScoresService"); } catch (err) { log.debug( "Rank and pp update queue has NOT been processed.", - "ScoresService", + "ScoresService" ); } }; @@ -391,12 +391,12 @@ export default () => { log.debug( "Queueing rank and pp update for bunch of scores", "ScoresService", - scoresToUpdate, + scoresToUpdate ); try { await Promise.all( - scoresToUpdate.map(async (s) => scoresUpdateQueueRepository().set(s)), + scoresToUpdate.map(async (s) => scoresUpdateQueueRepository().set(s)) ); } catch (err) { // swallow error @@ -405,7 +405,7 @@ export default () => { log.debug( "Scores rank & pp queued for update.", "ScoresService", - scoresToUpdate, + scoresToUpdate ); }; @@ -414,7 +414,7 @@ export default () => { log.warn( `Can not refresh scores, empty playerId`, "ScoresService", - player, + player ); return null; @@ -434,7 +434,7 @@ export default () => { const playerScores = await getPlayerScores(player.playerId); const currentScoresById = convertScoresById( player.playerId, - playerScores, + playerScores ); let mostRecentPlayFromScores = null; @@ -455,7 +455,7 @@ export default () => { player.playerId, numOfPages, priority, - abortController.signal, + abortController.signal ); else newScores = await fetchScoresUntil( @@ -463,7 +463,7 @@ export default () => { 1, priority, abortController.signal, - createFetchUntilLastUpdated(startUpdatingDate), + createFetchUntilLastUpdated(startUpdatingDate) ); if (!newScores || !newScores.length) { @@ -568,7 +568,7 @@ export default () => { const getScoresFreshnessDate = ( player, refreshInterval = null, - key = "scoresLastUpdated", + key = "scoresLastUpdated" ) => { const lastUpdated = player && player[key] ? player[key] : null; if (!lastUpdated) return addToDate(-SECOND); @@ -585,12 +585,12 @@ export default () => { const isScoreDateFresh = ( player, refreshInterval = null, - key = "scoresLastUpdated", + key = "scoresLastUpdated" ) => getScoresFreshnessDate(player, refreshInterval, key) > new Date(); const getPlayerScoresPage = async ( playerId, - serviceParams = { sort: "recent", order: "desc", page: 1 }, + serviceParams = { sort: "recent", order: "desc", page: 1 } ) => { let page = serviceParams?.page ?? 1; if (page < 1) page = 1; @@ -615,7 +615,7 @@ export default () => { }; const getScoresHistogramDefinition = ( - serviceParams = { sort: "recent", order: "desc" }, + serviceParams = { sort: "recent", order: "desc" } ) => { const sort = serviceParams?.sort ?? "recent"; const order = serviceParams?.order ?? "desc"; @@ -732,7 +732,7 @@ export default () => { playerId, serviceParams = { sort: "recent", order: "desc", page: 1 }, priority = PRIORITY.FG_LOW, - { ...options } = {}, + { ...options } = {} ) => ((serviceParams?.sort ?? "recent") === "top" ? topScoresApiClient @@ -750,7 +750,7 @@ export default () => { priority = PRIORITY.FG_LOW, signal = null, canUseBrowserCache = false, - refreshInterval = MINUTE, + refreshInterval = MINUTE ) => { const fetchedScoresResponse = await fetchScoresPage( playerId, @@ -761,13 +761,13 @@ export default () => { cacheTtl: MINUTE, maxAge: canUseBrowserCache ? 0 : refreshInterval, fullResponse: true, - }, + } ); if (topScoresApiClient.isResponseCached(fetchedScoresResponse)) return topScoresApiClient.getDataFromResponse(fetchedScoresResponse); const fetchedScores = topScoresApiClient.getDataFromResponse( - fetchedScoresResponse, + fetchedScoresResponse ); const playerScores = await getPlayerScores(playerId); @@ -835,7 +835,7 @@ export default () => { refreshInterval = MINUTE, priority = PRIORITY.FG_LOW, signal = null, - force = false, + force = false ) => { if (!player || !player.playerId) return null; @@ -845,7 +845,7 @@ export default () => { const scoresPage = await getPlayerScoresPage( player.playerId, - serviceParams, + serviceParams ); if ( @@ -889,7 +889,7 @@ export default () => { priority, signal, canUseBrowserCache && !shouldPageBeRefetched, - refreshInterval, + refreshInterval ); return scoresPage; @@ -899,7 +899,7 @@ export default () => { playerId, forceUpdate = false, priority = PRIORITY.BG_NORMAL, - throwErrors = false, + throwErrors = false ) => { refreshCallCounter++; @@ -908,13 +908,13 @@ export default () => { `Starting player "${playerId}" scores refreshing${ forceUpdate ? " (forced)" : "" }...`, - "ScoresService", + "ScoresService" ); if (!playerId) { log.warn( `Can not refresh player scores if an empty playerId is given`, - "ScoresService", + "ScoresService" ); return null; @@ -923,7 +923,7 @@ export default () => { if (updateInProgress.includes(playerId)) { log.warn( `Player "${playerId}" scores are being fetched, skipping.`, - "ScoresService", + "ScoresService" ); return null; @@ -939,7 +939,7 @@ export default () => { if (!player) { log.debug( - `Can not refresh the scores of player "${playerId}" because it has not been added to the DB`, + `Can not refresh the scores of player "${playerId}" because it has not been added to the DB` ); return null; } @@ -949,9 +949,9 @@ export default () => { if (scoresFreshnessDate > new Date()) { log.debug( `Player "${playerId}" scores are still fresh, skipping. Next refresh on ${formatDate( - scoresFreshnessDate, + scoresFreshnessDate )}`, - "ScoresService", + "ScoresService" ); return { @@ -959,7 +959,7 @@ export default () => { newScores: null, scores: convertScoresById( player.playerId, - await getPlayerScores(player.playerId), + await getPlayerScores(player.playerId) ), }; } @@ -967,18 +967,18 @@ export default () => { log.trace( `Fetching player "${playerId}" scores from ScoreSaber...`, - "ScoresService", + "ScoresService" ); const updatedPlayerScores = await resolvePromiseOrWaitForPending( `service/updatePlayerScores/${playerId}`, - () => updatePlayerScores(player, priority), + () => updatePlayerScores(player, priority) ); if (!updatedPlayerScores) { log.warn( `Can not refresh player "${playerId}" scores`, - "ScoresService", + "ScoresService" ); return null; @@ -989,7 +989,7 @@ export default () => { log.trace( `Player "${playerId}" scores updated`, "ScoresService", - scoresInfo.newScores, + scoresInfo.newScores ); if (scoresInfo.newScores && scoresInfo.newScores.length) { @@ -1012,7 +1012,7 @@ export default () => { e.toString ? `: ${e.toString()}` : "" }`, "ScoresService", - e, + e ); return null; @@ -1026,11 +1026,11 @@ export default () => { const refreshAll = async ( force = false, priority = PRIORITY.BG_NORMAL, - throwErrors = false, + throwErrors = false ) => { log.trace( `Starting refreshing all players scores${force ? " (forced)" : ""}...`, - "ScoresService", + "ScoresService" ); const allActivePlayers = await playerService.getAllActive(); @@ -1041,19 +1041,19 @@ export default () => { const allNewScores = await Promise.all( allActivePlayers.map((player) => - refresh(player.playerId, force, priority, throwErrors), - ), + refresh(player.playerId, force, priority, throwErrors) + ) ); const allPlayersWithNewScores = allActivePlayers.map((player, idx) => allNewScores[idx] ? { player, ...allNewScores[idx] } - : { player, newScores: null, scores: null, recentPlay: null }, + : { player, newScores: null, scores: null, recentPlay: null } ); log.trace( `All players scores refreshed.`, "ScoresService", - allPlayersWithNewScores, + allPlayersWithNewScores ); return allPlayersWithNewScores; diff --git a/src/services/twitch.js b/src/services/twitch.js index b3b9b0b..42c4a9c 100644 --- a/src/services/twitch.js +++ b/src/services/twitch.js @@ -87,7 +87,7 @@ export default () => { const fetchProfile = async ( login, priority = PRIORITY.FG_LOW, - { fullResponse = false, ...options } = {}, + { fullResponse = false, ...options } = {} ) => { const token = await getCurrentToken(); if (!token || !token.expires || token.expires <= new Date()) return null; @@ -101,14 +101,14 @@ export default () => { login, priority, fullResponse, - }), + }) ); }; const fetchVideos = async ( userId, priority = PRIORITY.FG_LOW, - { fullResponse = false, ...options } = {}, + { fullResponse = false, ...options } = {} ) => { const token = await getCurrentToken(); if (!token || !token.expires || token.expires <= new Date()) return null; @@ -122,7 +122,7 @@ export default () => { userId, priority, fullResponse, - }), + }) ); }; @@ -134,11 +134,11 @@ export default () => { playerId, forceUpdate = false, priority = queues.PRIORITY.FG_LOW, - throwErrors = false, + throwErrors = false ) => { log.trace( `Starting Twitch videos refreshing${forceUpdate ? " (forced)" : ""}...`, - "TwitchService", + "TwitchService" ); if (!playerId) { @@ -152,7 +152,7 @@ export default () => { if (!twitchProfile || !twitchProfile.login) { log.debug( `Twitch profile for player ${playerId} is not set, skipping`, - "TwitchService", + "TwitchService" ); return null; @@ -163,9 +163,9 @@ export default () => { if (lastUpdated && lastUpdated > new Date() - REFRESH_INTERVAL) { log.debug( `Refresh interval not yet expired, skipping. Next refresh on ${formatDate( - addToDate(REFRESH_INTERVAL, lastUpdated), + addToDate(REFRESH_INTERVAL, lastUpdated) )}`, - "TwitchService", + "TwitchService" ); return twitchProfile; @@ -177,7 +177,7 @@ export default () => { if (lastUpdated && lastUpdated > player.recentPlay) { log.debug( `Twitch updated after recent player play, skipping`, - "TwitchService", + "TwitchService" ); return twitchProfile; @@ -189,7 +189,7 @@ export default () => { if (!fetchedProfile) { log.debug( `Can not fetch Twitch profile for player ${playerId}, skipping`, - "TwitchService", + "TwitchService" ); return twitchProfile; @@ -220,7 +220,7 @@ export default () => { log.debug( `Twitch player ${playerId} refreshing error`, "TwitchService", - e, + e ); return null; @@ -243,7 +243,7 @@ export default () => { created_at: dateFromString(v.created_at), ended_at: addToDate( durationToMillis(v.duration), - dateFromString(v.created_at), + dateFromString(v.created_at) ), })) .find((v) => v.created_at <= songStarted && songStarted < v.ended_at); diff --git a/src/services/utils.js b/src/services/utils.js index ff0390c..038ff16 100644 --- a/src/services/utils.js +++ b/src/services/utils.js @@ -5,7 +5,7 @@ export const getServicePlayerGain = ( dateTruncFunc, dateKey, daysAgo = 1, - maxDaysAgo = 7, + maxDaysAgo = 7 ) => { if (!playerHistory?.length) return null; @@ -21,7 +21,7 @@ export const getServicePlayerGain = ( return playerHistory .sort((a, b) => b?.[dateKey]?.getTime() - a?.[dateKey]?.getTime()) .find( - (h) => h?.[dateKey] <= compareToDate && h?.[dateKey] >= maxServiceDate, + (h) => h?.[dateKey] <= compareToDate && h?.[dateKey] >= maxServiceDate ); }; diff --git a/src/stores/config.js b/src/stores/config.js index f8e4e62..924f0ee 100644 --- a/src/stores/config.js +++ b/src/stores/config.js @@ -78,7 +78,7 @@ export default async () => { const determineNewSettingsAvailable = (dbConfig) => Object.entries(newSettingsAvailableDefinition) .map(([key, description]) => - opt(dbConfig, key) === undefined ? description : null, + opt(dbConfig, key) === undefined ? description : null ) .filter((d) => d); diff --git a/src/stores/container.js b/src/stores/container.js index f918580..9ab47bc 100644 --- a/src/stores/container.js +++ b/src/stores/container.js @@ -1,7 +1,7 @@ import { writable } from "svelte/store"; export default ( - sizes = { phone: 0, tablet: 768, desktop: 1024, xxl: 1749 }, + sizes = { phone: 0, tablet: 768, desktop: 1024, xxl: 1749 } ) => { const defaultValue = { name: null, width: null, nodeWidth: null, rect: null }; const { subscribe, unsubscribe, set } = writable(defaultValue); @@ -41,8 +41,8 @@ export default ( item[1] <= nodeWidth ? { name: item[0], width: item[1], nodeWidth, rect } : cum, - defaultValue, - ), + defaultValue + ) ); }); diff --git a/src/stores/http/enhancers/common/acc-calc.js b/src/stores/http/enhancers/common/acc-calc.js index 8f1ca00..ae94d99 100644 --- a/src/stores/http/enhancers/common/acc-calc.js +++ b/src/stores/http/enhancers/common/acc-calc.js @@ -11,7 +11,7 @@ export default (score, bmStats, leaderboardId) => { } else if (leaderboardId) { maxScore = getFixedLeaderboardMaxScore( leaderboardId, - score?.maxScore ?? null, + score?.maxScore ?? null ); } diff --git a/src/stores/http/enhancers/common/beatmaps.js b/src/stores/http/enhancers/common/beatmaps.js index 02971e6..89f6d9b 100644 --- a/src/stores/http/enhancers/common/beatmaps.js +++ b/src/stores/http/enhancers/common/beatmaps.js @@ -9,6 +9,6 @@ export default async (data, cachedOnly = false) => { data.leaderboard.beatMaps = await beatMaps.byHash( data.leaderboard.song.hash, false, - cachedOnly, + cachedOnly ); }; diff --git a/src/stores/http/enhancers/scores/acc.js b/src/stores/http/enhancers/scores/acc.js index 2ec1888..af3c507 100644 --- a/src/stores/http/enhancers/scores/acc.js +++ b/src/stores/http/enhancers/scores/acc.js @@ -15,7 +15,7 @@ export default async (data) => { : 0; const bmStats = findDiffInfoWithDiffAndTypeFromBeatMaps( opt(data, `leaderboard.beatMaps.versions.${versionsLastIdx}.diffs`), - diffInfo, + diffInfo ); data.score = calculateAcc(data.score, bmStats, leaderboardId); diff --git a/src/stores/http/enhancers/scores/compare.js b/src/stores/http/enhancers/scores/compare.js index 5c02ef7..6c54204 100644 --- a/src/stores/http/enhancers/scores/compare.js +++ b/src/stores/http/enhancers/scores/compare.js @@ -48,11 +48,11 @@ export default async (data, playerId = null) => { const mainPlayerScore = await produce( await produce( await produce(comparePlayerScores[leaderboardId], (draft) => - beatMapsEnhancer(draft), + beatMapsEnhancer(draft) ), - (draft) => accEnhancer(draft, true), + (draft) => accEnhancer(draft, true) ), - (draft) => beatSaviorEnhancer(draft, mainPlayerId), + (draft) => beatSaviorEnhancer(draft, mainPlayerId) ); data.comparePlayers = [ diff --git a/src/stores/http/enhancers/scores/diff.js b/src/stores/http/enhancers/scores/diff.js index f1931a1..6cfff41 100644 --- a/src/stores/http/enhancers/scores/diff.js +++ b/src/stores/http/enhancers/scores/diff.js @@ -15,7 +15,7 @@ export default async (data, playerId = null) => { if (!scoresService) scoresService = createScoresService(); const playerScores = scoresService.convertScoresToObject( - await scoresService.getPlayerScores(playerId), + await scoresService.getPlayerScores(playerId) ); // skip if no cached score @@ -41,7 +41,7 @@ export default async (data, playerId = null) => { : 0; const bmStats = findDiffInfoWithDiffAndTypeFromBeatMaps( opt(data, `leaderboard.beatMaps.versions.${versionsLastIdx}.diffs`), - diffInfo, + diffInfo ); data.prevScore = calculateAcc(prevScore, bmStats, leaderboardId); diff --git a/src/stores/http/enhancers/scores/pp-attribution.js b/src/stores/http/enhancers/scores/pp-attribution.js index aa01ebb..1789573 100644 --- a/src/stores/http/enhancers/scores/pp-attribution.js +++ b/src/stores/http/enhancers/scores/pp-attribution.js @@ -20,7 +20,7 @@ export default async (data, playerId = null, whatIfOnly = false) => { const whatIfPp = await ppService.getWhatIfScore( mainPlayerId, leaderboardId, - pp, + pp ); if (whatIfPp && whatIfPp.diff >= 0.01) data.score.whatIfPp = whatIfPp; } diff --git a/src/stores/http/enhancers/scores/twitch.js b/src/stores/http/enhancers/scores/twitch.js index 24ba84a..2c93e16 100644 --- a/src/stores/http/enhancers/scores/twitch.js +++ b/src/stores/http/enhancers/scores/twitch.js @@ -15,7 +15,7 @@ export default async (data, playerId = null) => { : 0; const bmStats = findDiffInfoWithDiffAndTypeFromBeatMaps( opt(data, `leaderboard.beatMaps.versions.${versionsLastIdx}.diffs`), - data.leaderboard.diffInfo, + data.leaderboard.diffInfo ); if (!bmStats || !bmStats.seconds) return; @@ -27,7 +27,7 @@ export default async (data, playerId = null) => { const video = await twitchService.findTwitchVideo( twitchProfile, data.score.timeSet, - bmStats.seconds, + bmStats.seconds ); if (!video || !video.url) return; diff --git a/src/stores/http/http-leaderboard-store.js b/src/stores/http/http-leaderboard-store.js index 326e311..6de6796 100644 --- a/src/stores/http/http-leaderboard-store.js +++ b/src/stores/http/http-leaderboard-store.js @@ -13,7 +13,7 @@ export default ( type = "global", page = 1, initialState = null, - initialStateType = "initial", + initialStateType = "initial" ) => { let currentLeaderboardId = leaderboardId ? leaderboardId : null; let currentType = type ? type : "global"; @@ -62,13 +62,13 @@ export default ( const patchId = getPatchId(currentLeaderboardId, scoreRow); const stateRowIdx = newState.scores.findIndex( - (s) => getPatchId(currentLeaderboardId, s) === patchId, + (s) => getPatchId(currentLeaderboardId, s) === patchId ); if (stateRowIdx < 0) return; newState.scores[stateRowIdx] = applyPatches( newState.scores[stateRowIdx], - enhancePatches[patchId], + enhancePatches[patchId] ); debouncedSetState(enhanceTaskId, newState); @@ -88,7 +88,7 @@ export default ( const bpm = newState?.leaderboard?.beatMaps?.metadata?.bpm ?? null; const bmStats = findDiffInfoWithDiffAndTypeFromBeatMaps( newState?.leaderboard?.beatMaps?.versions?.[versionsLastIdx]?.diffs, - newState?.leaderboard?.diffInfo, + newState?.leaderboard?.diffInfo ); if (!bmStats) return null; @@ -113,7 +113,7 @@ export default ( leaderboard: newState.leaderboard, }, getPatchId(currentLeaderboardId, scoreRow), - (draft) => accEnhancer(draft), + (draft) => accEnhancer(draft) ) .then((scoreRow) => setStateRow(enhanceTaskId, scoreRow)) .then((scoreRow) => @@ -124,9 +124,9 @@ export default ( ppAttributionEnhancer( draft, scoreRow?.player?.playerId, - true, - ), - ), + true + ) + ) ) .then((scoreRow) => setStateRow(enhanceTaskId, scoreRow)); } @@ -144,14 +144,14 @@ export default ( onAfterStateChange: onNewData, onSetPending: ({ fetchParams }) => ({ ...fetchParams }), }, - initialStateType, + initialStateType ); const fetch = async ( leaderboardId = currentLeaderboardId, type = currentType, page = currentPage, - force = false, + force = false ) => { if (!leaderboardId) return false; diff --git a/src/stores/http/http-player-store.js b/src/stores/http/http-player-store.js index 0d7351d..0226113 100644 --- a/src/stores/http/http-player-store.js +++ b/src/stores/http/http-player-store.js @@ -4,7 +4,7 @@ import playerApiClient from "../../network/clients/scoresaber/player/api"; export default ( playerId = null, initialState = null, - initialStateType = "initial", + initialStateType = "initial" ) => { let currentPlayerId = playerId; @@ -20,7 +20,7 @@ export default ( onInitialized: onNewData, onAfterStateChange: onNewData, }, - initialStateType, + initialStateType ); const fetch = async (playerId = currentPlayerId, force = false) => { diff --git a/src/stores/http/http-player-with-scores-store.js b/src/stores/http/http-player-with-scores-store.js index e109770..bb11c08 100644 --- a/src/stores/http/http-player-with-scores-store.js +++ b/src/stores/http/http-player-with-scores-store.js @@ -11,7 +11,7 @@ export default ( service = "scoresaber", serviceParams = { type: "recent", page: 1 }, initialState = null, - initialStateType = "initial", + initialStateType = "initial" ) => { let currentPlayerId = playerId; let currentService = service; @@ -42,14 +42,14 @@ export default ( onInitialized: onNewData, onAfterStateChange: onNewData, }, - initialStateType, + initialStateType ); const fetch = async ( playerId = currentPlayerId, service = currentService, serviceParams = currentServiceParams, - force = false, + force = false ) => { if ( (!playerId || playerId === currentPlayerId) && @@ -70,7 +70,7 @@ export default ( { playerId, service, serviceParams }, force, provider, - !playerId || playerId !== currentPlayerId || force, + !playerId || playerId !== currentPlayerId || force ); }; @@ -94,7 +94,7 @@ export default ( playerForLastRecentPlay = playerId; await refresh(); - }, + } ); const subscribe = (fn) => { @@ -112,7 +112,7 @@ export default ( if (!currentPlayerId) { setTimeout( () => enqueueRecentPlayRefresh(), - DEFAULT_RECENT_PLAY_REFRESH_INTERVAL, + DEFAULT_RECENT_PLAY_REFRESH_INTERVAL ); return; @@ -130,7 +130,7 @@ export default ( setTimeout( () => enqueueRecentPlayRefresh(), - DEFAULT_RECENT_PLAY_REFRESH_INTERVAL, + DEFAULT_RECENT_PLAY_REFRESH_INTERVAL ); return { diff --git a/src/stores/http/http-ranking-store.js b/src/stores/http/http-ranking-store.js index 1260d19..e727713 100644 --- a/src/stores/http/http-ranking-store.js +++ b/src/stores/http/http-ranking-store.js @@ -5,7 +5,7 @@ export default ( type = "global", page = 1, initialState = null, - initialStateType = "initial", + initialStateType = "initial" ) => { let currentType = type ? type : "global"; let currentPage = page ? page : 1; @@ -26,13 +26,13 @@ export default ( onAfterStateChange: onNewData, onSetPending: ({ fetchParams }) => ({ ...fetchParams }), }, - initialStateType, + initialStateType ); const fetch = async ( type = currentType, page = currentPage, - force = false, + force = false ) => { if ( (!type || type === currentType) && diff --git a/src/stores/http/http-scores-store.js b/src/stores/http/http-scores-store.js index 9bff65d..0a18062 100644 --- a/src/stores/http/http-scores-store.js +++ b/src/stores/http/http-scores-store.js @@ -17,7 +17,7 @@ export default ( service = "scoresaber", serviceParams = { type: "recent", page: 1 }, initialState = null, - initialStateType = "initial", + initialStateType = "initial" ) => { let currentPlayerId = playerId; let currentService = service; @@ -82,13 +82,13 @@ export default ( const patchId = getPatchId(currentPlayerId, scoreRow); const stateRowIdx = newState.findIndex( - (s) => getPatchId(currentPlayerId, s) === patchId, + (s) => getPatchId(currentPlayerId, s) === patchId ); if (stateRowIdx < 0) return; newState[stateRowIdx] = applyPatches( newState[stateRowIdx], - enhancePatches[patchId], + enhancePatches[patchId] ); debouncedSetState(enhanceTaskId, newState); @@ -99,74 +99,74 @@ export default ( for (const scoreRow of newState) { if (currentService !== "accsaber") { stateProduce(scoreRow, getPatchId(currentPlayerId, scoreRow), (draft) => - beatMapsEnhancer(draft), + beatMapsEnhancer(draft) ) .then((scoreRow) => stateProduce( scoreRow, getPatchId(currentPlayerId, scoreRow), - (draft) => accEnhancer(draft), - ), + (draft) => accEnhancer(draft) + ) ) .then((scoreRow) => setStateRow(enhanceTaskId, scoreRow)) .then((scoreRow) => stateProduce( scoreRow, getPatchId(currentPlayerId, scoreRow), - (draft) => diffEnhancer(draft, currentPlayerId), - ), + (draft) => diffEnhancer(draft, currentPlayerId) + ) ) .then((scoreRow) => setStateRow(enhanceTaskId, scoreRow)) .then((scoreRow) => stateProduce( scoreRow, getPatchId(currentPlayerId, scoreRow), - (draft) => compareEnhancer(draft, currentPlayerId), - ), + (draft) => compareEnhancer(draft, currentPlayerId) + ) ) .then((scoreRow) => setStateRow(enhanceTaskId, scoreRow)) .then((scoreRow) => stateProduce( scoreRow, getPatchId(currentPlayerId, scoreRow), - (draft) => twitchEnhancer(draft, currentPlayerId), - ), + (draft) => twitchEnhancer(draft, currentPlayerId) + ) ) .then((scoreRow) => setStateRow(enhanceTaskId, scoreRow)); stateProduce(scoreRow, getPatchId(currentPlayerId, scoreRow), (draft) => - rankedsEnhancer(draft), + rankedsEnhancer(draft) ).then((scoreRow) => setStateRow(enhanceTaskId, scoreRow)); stateProduce(scoreRow, getPatchId(currentPlayerId, scoreRow), (draft) => - ppAttributionEnhancer(draft, currentPlayerId), + ppAttributionEnhancer(draft, currentPlayerId) ).then((scoreRow) => setStateRow(enhanceTaskId, scoreRow)); if (stateType && stateType === "live") stateProduce( scoreRow, getPatchId(currentPlayerId, scoreRow), - (draft) => beatSaviorEnhancer(draft, currentPlayerId), + (draft) => beatSaviorEnhancer(draft, currentPlayerId) ).then((scoreRow) => setStateRow(enhanceTaskId, scoreRow)); } else { stateProduce(scoreRow, getPatchId(currentPlayerId, scoreRow), (draft) => - beatMapsEnhancer(draft), + beatMapsEnhancer(draft) ) .then((scoreRow) => setStateRow(enhanceTaskId, scoreRow)) .then((scoreRow) => stateProduce( scoreRow, getPatchId(currentPlayerId, scoreRow), - (draft) => twitchEnhancer(draft, currentPlayerId), - ), + (draft) => twitchEnhancer(draft, currentPlayerId) + ) ) .then((scoreRow) => setStateRow(enhanceTaskId, scoreRow)) .then((scoreRow) => stateProduce( scoreRow, getPatchId(currentPlayerId, scoreRow), - (draft) => beatSaviorEnhancer(draft, currentPlayerId), - ), + (draft) => beatSaviorEnhancer(draft, currentPlayerId) + ) ) .then((scoreRow) => setStateRow(enhanceTaskId, scoreRow)); } @@ -185,14 +185,14 @@ export default ( onAfterStateChange: onNewData, onSetPending: ({ fetchParams }) => ({ ...fetchParams }), }, - initialStateType, + initialStateType ); const fetch = async ( serviceParams = currentServiceParams, service = currentService, playerId = currentPlayerId, - force = false, + force = false ) => { if ( (!playerId || playerId === currentPlayerId) && @@ -207,7 +207,7 @@ export default ( { playerId, service, serviceParams }, force, provider, - !playerId || playerId !== currentPlayerId || force, + !playerId || playerId !== currentPlayerId || force ); }; diff --git a/src/stores/http/http-store.js b/src/stores/http/http-store.js index 4333fb6..29ab2da 100644 --- a/src/stores/http/http-store.js +++ b/src/stores/http/http-store.js @@ -16,7 +16,7 @@ export default ( onSetPending = null, onError = null, } = {}, - initialStateType = "initial", + initialStateType = "initial" ) => { const getFinalParams = (fetchParams) => ({ ...defaultFetchParams, @@ -46,7 +46,7 @@ export default ( fetchParams = {}, force = false, provider = currentProvider, - fetchCachedFirst = false, + fetchCachedFirst = false ) => { const abortController = new AbortController(); @@ -67,7 +67,7 @@ export default ( set( onBeforeStateChange ? onBeforeStateChange(cachedState, stateType) - : cachedState, + : cachedState ); } }); @@ -78,7 +78,7 @@ export default ( setPending( onSetPending ? onSetPending({ fetchParams, abortController }) - : fetchParams, + : fetchParams ); pendingAbortController = abortController; diff --git a/src/stores/http/providers/api-player-with-scores.js b/src/stores/http/providers/api-player-with-scores.js index d552728..32066f6 100644 --- a/src/stores/http/providers/api-player-with-scores.js +++ b/src/stores/http/providers/api-player-with-scores.js @@ -30,14 +30,14 @@ export default () => { refreshInterval, priority, signal, - force, + force ); const scores = await scoresFetcher.fetchLiveScores( player, service, serviceParams, - { refreshInterval, priority, signal, force }, + { refreshInterval, priority, signal, force } ); return { ...player, scores, service, serviceParams }; diff --git a/src/stores/http/providers/api-scores.js b/src/stores/http/providers/api-scores.js index 821174e..f90277b 100644 --- a/src/stores/http/providers/api-scores.js +++ b/src/stores/http/providers/api-scores.js @@ -20,7 +20,7 @@ export default () => { return; player = newPlayer; - }, + } ); const playerRecentPlayUpdatedUnsubscribe = eventBus.on( @@ -30,7 +30,7 @@ export default () => { player.recentPlay = recentPlay; player.recentPlayLastUpdated = recentPlayLastUpdated; - }, + } ); return { @@ -47,7 +47,7 @@ export default () => { playerId, MINUTE, priority, - signal, + signal ); return scoresFetcher.fetchLiveScores(player, service, serviceParams, { diff --git a/src/stores/http/providers/page-leaderboard.js b/src/stores/http/providers/page-leaderboard.js index 025e275..90a7a51 100644 --- a/src/stores/http/providers/page-leaderboard.js +++ b/src/stores/http/providers/page-leaderboard.js @@ -21,7 +21,7 @@ export default () => { page, priority, signal, - force, + force ); case "accsaber": return await leaderboardService.fetchAccSaberPage( @@ -29,14 +29,14 @@ export default () => { page, priority, signal, - force, + force ); default: return await leaderboardService.getFriendsLeaderboard( leaderboardId, priority, signal, - force, + force ); } }; diff --git a/src/stores/http/providers/utils/scores-fetch.js b/src/stores/http/providers/utils/scores-fetch.js index 257c0a0..e7d1082 100644 --- a/src/stores/http/providers/utils/scores-fetch.js +++ b/src/stores/http/providers/utils/scores-fetch.js @@ -19,7 +19,7 @@ export default () => { playerId, service, serviceParams = { sort: "recent", order: "desc", page: 1 }, - otherParams = {}, + otherParams = {} ) => { switch (service) { case "beatsavior": @@ -36,18 +36,18 @@ export default () => { player, service, serviceParams = { sort: "recent", order: "desc", page: 1 }, - otherParams = {}, + otherParams = {} ) => { switch (service) { case "beatsavior": return beatSaviorService.getPlayerScoresPage( player?.playerId, - serviceParams, + serviceParams ); case "accsaber": return accSaberService.getPlayerScoresPage( player?.playerId, - serviceParams, + serviceParams ); case "scoresaber": default: @@ -57,7 +57,7 @@ export default () => { otherParams?.refreshInterval, otherParams?.priority, otherParams?.signal, - otherParams?.force, + otherParams?.force ); } }; diff --git a/src/stores/scoresaber/friends.js b/src/stores/scoresaber/friends.js index a13cec5..560513b 100644 --- a/src/stores/scoresaber/friends.js +++ b/src/stores/scoresaber/friends.js @@ -15,7 +15,7 @@ export default () => { set( players .filter((p) => p && p.playerId && friends.includes(p.playerId)) - .sort((a, b) => (a.name ? a.name.localeCompare(b.name) : 0)), + .sort((a, b) => (a.name ? a.name.localeCompare(b.name) : 0)) ); }); diff --git a/src/stores/scoresaber/players.js b/src/stores/scoresaber/players.js index 81bb824..440cab7 100644 --- a/src/stores/scoresaber/players.js +++ b/src/stores/scoresaber/players.js @@ -23,11 +23,11 @@ export default () => { const playerAddedUnsubscribe = eventBus.on( "player-profile-added", - refreshState, + refreshState ); const playerRemovedUnsubscribe = eventBus.on( "player-profile-removed", - refreshState, + refreshState ); const subscribe = (fn) => { diff --git a/src/stores/scoresaber/rankeds.js b/src/stores/scoresaber/rankeds.js index a5cb5a9..b711786 100644 --- a/src/stores/scoresaber/rankeds.js +++ b/src/stores/scoresaber/rankeds.js @@ -18,7 +18,7 @@ export default async (refreshOnCreate = false) => { const get = () => rankeds; const refresh = async ( forceUpdate = false, - priority = PRIORITY.BG_NORMAL, + priority = PRIORITY.BG_NORMAL ) => { await rankedsService.refresh(forceUpdate, priority); }; @@ -32,7 +32,7 @@ export default async (refreshOnCreate = false) => { "rankeds-changed", ({ allRankeds }) => { if (allRankeds && Object.keys(allRankeds).length) set(allRankeds); - }, + } ); const subscribe = (fn) => { diff --git a/src/svelte-utils/actions/hoverable.js b/src/svelte-utils/actions/hoverable.js index 88953cd..4eac316 100644 --- a/src/svelte-utils/actions/hoverable.js +++ b/src/svelte-utils/actions/hoverable.js @@ -14,7 +14,7 @@ export function hoverable(node) { pageY: event.pageY, rect, }, - }), + }) ); } @@ -30,7 +30,7 @@ export function hoverable(node) { pageX: event.pageX, pageY: event.pageY, }, - }), + }) ); } diff --git a/src/utils/broadcast-channel-pubsub.js b/src/utils/broadcast-channel-pubsub.js index 26e9211..6e6b68e 100644 --- a/src/utils/broadcast-channel-pubsub.js +++ b/src/utils/broadcast-channel-pubsub.js @@ -17,7 +17,7 @@ const createGlobalPubSub = () => { `Create pub/sub channel for node ${nodeId} (${ isWorker ? "worker" : "browser" })`, - "PubSub", + "PubSub" ); bc = new BroadcastChannel("global-pub-sub", { webWorkerSupport: true }); @@ -41,7 +41,7 @@ const createGlobalPubSub = () => { if (!exists(eventName)) return; subscribers[eventName].forEach((handler) => - handler(value, isLocal, eventName), + handler(value, isLocal, eventName) ); }; @@ -49,7 +49,7 @@ const createGlobalPubSub = () => { if (!exists(eventName)) return; subscribers[eventName] = subscribers[eventName].filter( - (h) => h !== handler, + (h) => h !== handler ); }; diff --git a/src/utils/date.js b/src/utils/date.js index 82f9d20..0b4da52 100644 --- a/src/utils/date.js +++ b/src/utils/date.js @@ -20,7 +20,7 @@ export const dateFromString = (str) => { const matches = str && isString(str) ? str.match( - /^(\d{4}-\d{1,2}-\d{1,2})\s+(\d{1,2}:\d{1,2}(:\d{1,2})?)\sUTC$/, + /^(\d{4}-\d{1,2}-\d{1,2})\s+(\d{1,2}:\d{1,2}(:\d{1,2})?)\sUTC$/ ) : null; if (matches && matches.length >= 3) { @@ -99,7 +99,7 @@ export const fromAccSaberDateString = (dateStr) => export function formatDateWithOptions( val, options = { localeMatcher: "best fit" }, - locale = getCurrentLocale(), + locale = getCurrentLocale() ) { if (!isValidDate(val)) return null; @@ -112,7 +112,7 @@ export function formatDate( val, dateStyle = "short", timeStyle = "medium", - locale = getCurrentLocale(), + locale = getCurrentLocale() ) { return formatDateWithOptions( val, @@ -121,7 +121,7 @@ export function formatDate( dateStyle, timeStyle: timeStyle ?? undefined, }, - locale, + locale ); } @@ -158,12 +158,12 @@ export function formatDateRelative(val, roundFunc = Math.round, unit = "auto") { else if (diffInSecs < 60 * 60 * 24 * 365) return rtf.format( -roundFunc(diffInSecs / (60 * 60 * 24 * 30)), - "month", + "month" ); else return rtf.format( -roundFunc(diffInSecs / (60 * 60 * 24 * 365)), - "year", + "year" ); default: diff --git a/src/utils/debounce.js b/src/utils/debounce.js index 5629d32..0f81251 100644 --- a/src/utils/debounce.js +++ b/src/utils/debounce.js @@ -24,7 +24,7 @@ export const throttle = (callback, wait) => { lastFired = Date.now(); } }, - wait - (Date.now() - lastFired), + wait - (Date.now() - lastFired) ); } }; diff --git a/src/utils/export-import.js b/src/utils/export-import.js index e0ec281..6e325cd 100644 --- a/src/utils/export-import.js +++ b/src/utils/export-import.js @@ -110,7 +110,7 @@ const getOrigin = () => { }; export const exportJsonData = async ( - filename = "ssr-db-" + new Date().toISOString().replace(/:/g, "_") + ".json", + filename = "ssr-db-" + new Date().toISOString().replace(/:/g, "_") + ".json" ) => { const inLineKeysRepositories = getInLineKeysRepositories(); const outOfLineKeysRepositories = getOutOfLineKeysRepositories(); @@ -119,7 +119,7 @@ export const exportJsonData = async ( await Promise.all( inLineKeysRepositories .map((r) => r.repository) - .map(async (repository) => repository().getAll()), + .map(async (repository) => repository().getAll()) ) ).reduce( (cum, repositoryData, idx) => { @@ -133,7 +133,7 @@ export const exportJsonData = async ( version: db.version, exportedOn: new Date(), stores: {}, - }, + } ); await Promise.all( @@ -152,21 +152,21 @@ export const exportJsonData = async ( : respositoryValues[idx], }, ]), - [], + [] ); - }), + }) ); return download( JSON.stringify(data), filename, - "application/json;charset=utf-8;", + "application/json;charset=utf-8;" ); }; export const importJsonData = async (json) => { const availableStores = repositories.map((item) => - item.repository().getStoreName(), + item.repository().getStoreName() ); eventBus.publish("dl-manager-pause-cmd"); @@ -184,7 +184,7 @@ export const importJsonData = async (json) => { } const items = json.stores[storeName].map((value) => - castRepositoryItem(value, repositoryItem), + castRepositoryItem(value, repositoryItem) ); const store = tx.objectStore(storeName); @@ -209,7 +209,7 @@ function castObjectKeys( value, testKeys, castType = "date", - isOutOfLineRepository = false, + isOutOfLineRepository = false ) { const cast = (v, type = "date") => { switch (type) { @@ -225,7 +225,7 @@ function castObjectKeys( const splittedKey = key.split("."); const mainKey = splittedKey.shift(); const keys = (!isOutOfLineRepository ? [mainKey] : []).concat( - isOutOfLineRepository && !splittedKey.length ? [""] : splittedKey, + isOutOfLineRepository && !splittedKey.length ? [""] : splittedKey ); let valuePart = isOutOfLineRepository ? opt(value, "value") : value; @@ -248,7 +248,7 @@ function castObjectKeys( return v.map((innerV) => keys.length === 1 ? cast(innerV, castType) - : process(innerV, keys.slice(1)), + : process(innerV, keys.slice(1)) ); default: @@ -279,7 +279,7 @@ const castRepositoryItem = (value, repositoryItem) => { Object.entries(opt(repositoryItem, "casts", {})).forEach( ([castType, keys]) => { value = castObjectKeys(value, keys, castType, isOutOfLineRepository); - }, + } ); return value; diff --git a/src/utils/format.js b/src/utils/format.js index 59d7132..0b4bb24 100644 --- a/src/utils/format.js +++ b/src/utils/format.js @@ -3,14 +3,14 @@ import { getCurrentLocale } from "../stores/config"; export const substituteVars = (url, vars) => Object.keys(vars).reduce( (cum, key) => cum.replace(new RegExp("\\${" + key + "}", "gi"), vars[key]), - url, + url ); export function formatNumber( num, digits = 2, addSign = false, - notANumber = null, + notANumber = null ) { if (!Number.isFinite(num)) { return notANumber; diff --git a/src/utils/js.js b/src/utils/js.js index 0be9e7e..ebe48e3 100644 --- a/src/utils/js.js +++ b/src/utils/js.js @@ -43,7 +43,7 @@ export const opt = (obj, key, defaultValue = undefined) => .reduce( (o, i) => o && o[i] !== null && o[i] !== undefined ? o[i] : defaultValue, - obj, + obj ); export const optSet = (obj, key, value, createKeys = true) => { const keys = key.split("."); diff --git a/src/utils/logger.js b/src/utils/logger.js index bf6c525..cff2688 100644 --- a/src/utils/logger.js +++ b/src/utils/logger.js @@ -59,7 +59,7 @@ export default { }, logOnly: (types) => (enabledTypes = arrayUnique( - enabledTypes.concat(Array.isArray(types) ? types : [types]), + enabledTypes.concat(Array.isArray(types) ? types : [types]) )), logAll: () => (enabledTypes = []), }; diff --git a/src/utils/promise.js b/src/utils/promise.js index cc74fd1..24aeed1 100644 --- a/src/utils/promise.js +++ b/src/utils/promise.js @@ -5,7 +5,7 @@ export const delay = async (time, val, shouldReject = false, signal = null) => new Promise((resolve, reject) => { const handle = setTimeout( (_) => (shouldReject ? reject(val) : resolve(val)), - time, + time ); if (signal && signal.addEventListener) @@ -16,6 +16,6 @@ export const delay = async (time, val, shouldReject = false, signal = null) => reject(AbortError()); }, - { once: true }, + { once: true } ); }); diff --git a/src/utils/scoresaber/pp.js b/src/utils/scoresaber/pp.js index d71db93..3f342bf 100644 --- a/src/utils/scoresaber/pp.js +++ b/src/utils/scoresaber/pp.js @@ -3,5 +3,5 @@ export const WEIGHT_COEFFICIENT = 0.965; export const getTotalPpFromSortedPps = (ppArray, startIdx = 0) => ppArray.reduce( (cum, pp, idx) => cum + Math.pow(WEIGHT_COEFFICIENT, idx + startIdx) * pp, - 0, + 0 ); diff --git a/src/utils/scoresaber/song.js b/src/utils/scoresaber/song.js index 629415a..8dfa081 100644 --- a/src/utils/scoresaber/song.js +++ b/src/utils/scoresaber/song.js @@ -52,7 +52,7 @@ export const getMaxScore = (blocks, maxScorePerBlock = 115) => (blocks >= 14 ? 8 * maxScorePerBlock * (blocks - 13) : 0) + (blocks >= 6 ? 4 * maxScorePerBlock * (Math.min(blocks, 13) - 5) : 0) + (blocks >= 2 ? 2 * maxScorePerBlock * (Math.min(blocks, 5) - 1) : 0) + - Math.min(blocks, 1) * maxScorePerBlock, + Math.min(blocks, 1) * maxScorePerBlock ); export function getFixedLeaderboardMaxScore(leaderboardId, maxScore = null) { @@ -64,7 +64,7 @@ export function getFixedLeaderboardMaxScore(leaderboardId, maxScore = null) { export function getAccFromScore( score, maxSongScore = null, - percentageInsteadOfAcc = false, + percentageInsteadOfAcc = false ) { if (!score) return null; @@ -112,18 +112,18 @@ export function findDiffInfoWithDiffAndTypeFromBeatMaps(diffs, diffAndType) { : diffs.find( (diff) => diff.characteristic === diffAndType.type && - diff.difficulty === capitalize(diffAndType.diff), + diff.difficulty === capitalize(diffAndType.diff) ); } export function getMaxScoreFromSongCharacteristics( songCharacteristics, diffInfo, - maxScorePerBlock = 115, + maxScorePerBlock = 115 ) { const songDiffInfo = findDiffInfoWithDiffAndType( songCharacteristics, - diffInfo, + diffInfo ); return songDiffInfo && songDiffInfo.length && songDiffInfo.notes diff --git a/src/utils/uuid.js b/src/utils/uuid.js index b9693fd..2d7cf8a 100644 --- a/src/utils/uuid.js +++ b/src/utils/uuid.js @@ -20,6 +20,6 @@ export const uuid = (a) => { .replace( // replacing /[018]/g, // zeroes, ones, and eights with - uuid, // random hex digits + uuid // random hex digits ); }; diff --git a/src/workers/stats-worker.js b/src/workers/stats-worker.js index 71261b6..a1984bd 100644 --- a/src/workers/stats-worker.js +++ b/src/workers/stats-worker.js @@ -31,7 +31,7 @@ const getRankedsFromDb = async (refreshCache = false) => { const getRankeds = async (refreshCache = false) => resolvePromiseOrWaitForPending(`rankeds/${refreshCache}`, () => - getRankedsFromDb(), + getRankedsFromDb() ); async function init() { @@ -67,14 +67,14 @@ const getRankedScores = async (playerId, withStars = false) => { .map(async (score) => { score = await produce( await produce(score, (draft) => beatmapsEnhancer(draft, true)), - (draft) => accEnhancer(draft), + (draft) => accEnhancer(draft) ); return { ...score, stars: allRankeds[score?.leaderboardId]?.stars ?? null, }; - }), + }) ) ).filter((s) => s.stars) : scores.filter((score) => score?.score?.pp); @@ -92,7 +92,7 @@ const calcPlayerStats = async (playerId) => { const stats = rankedScores .filter( (score) => - (score?.score?.score && score?.score?.maxScore) || score?.score?.acc, + (score?.score?.score && score?.score?.maxScore) || score?.score?.acc ) .reduce( (cum, s) => { @@ -165,7 +165,7 @@ const calcPlayerStats = async (playerId) => { playCount: rankedScores.length, medianAcc: 0, stdDeviation: 0, - }, + } ); stats.medianAcc = @@ -178,8 +178,8 @@ const calcPlayerStats = async (playerId) => { stats.stdDeviation = Math.sqrt( rankedScores.reduce( (sum, s) => sum + Math.pow(stats.avgAcc - s.score.acc, 2), - 0, - ) / rankedScores.length, + 0 + ) / rankedScores.length ); delete stats.totalAcc; @@ -220,7 +220,7 @@ const calcPpBoundary = async (playerId, expectedPp = 1) => { const ppBoundary = calcRawPpAtIdx( rankedScorePps.slice(idx + 1), idx + 1, - expectedPp, + expectedPp ); eventBus.publish("player-pp-boundary-calculated", {