Skip to content

Commit

Permalink
fetch main-player id immidiately with parameter
Browse files Browse the repository at this point in the history
  • Loading branch information
Schippi committed Sep 28, 2023
2 parents f027d43 + 38558c9 commit 83317ce
Show file tree
Hide file tree
Showing 4 changed files with 20 additions and 18 deletions.
14 changes: 5 additions & 9 deletions src/components/Playlists/Playlist.svelte
Original file line number Diff line number Diff line change
Expand Up @@ -72,6 +72,9 @@
async function retrieveOwner(playlist, playerId) {
var newOwners = [];
canModify = true;
canShare = true;
if (playlist?.customData?.owner) {
canShare = false;
if (playlist.customData.owner == 'BeatLeader') {
Expand All @@ -84,16 +87,9 @@
for (let index = 0; index < ownersIds.length; index++) {
const element = ownersIds[index];
let playerService = createPlayerService();
let owner = playerService.fetchPlayerOrGetFromCache(element);
let owner = await playerService.fetchPlayerOrGetFromCache(element, undefined, undefined, undefined, undefined, false);
if (owner?.playerId != playerId) {
if (playerService.isMainPlayer(owner.playerId)) {
canModify = false;
} else {
let main_id = playerService.getPlayerMain(element);
if (main_id == null || main_id != playerId) {
canModify = false;
}
}
canModify = false;
}
if (owner) {
newOwners.push(owner);
Expand Down
4 changes: 2 additions & 2 deletions src/network/clients/beatleader/player/api.js
Original file line number Diff line number Diff line change
Expand Up @@ -2,8 +2,8 @@ import queue from '../../../queues/queues';
import createClient from '../../generic';
import process from './process';

const get = async ({playerId, priority = queue.PRIORITY.FG_HIGH, ...queueOptions} = {}) =>
queue.BEATLEADER_API.player(playerId, priority, queueOptions);
const get = async ({playerId, priority = queue.PRIORITY.FG_HIGH, keepOriginalId = true, ...queueOptions} = {}) =>
queue.BEATLEADER_API.player(playerId, priority, keepOriginalId, queueOptions);

const client = createClient(get, process);

Expand Down
6 changes: 3 additions & 3 deletions src/network/queues/beatleader/api-queue.js
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,7 @@ export const STEAM_API_URL = '/cors/steamapi';
export const STEAM_KEY = 'B0A7AF33E804D0ABBDE43BA9DD5DAB48';

export const BL_API_USER_URL = `${BL_API_URL}user`;
export const BL_API_PLAYER_INFO_URL = BL_API_URL + 'player/${playerId}?keepOriginalId=true';
export const BL_API_PLAYER_INFO_URL = BL_API_URL + 'player/${playerId}?keepOriginalId=${keepOriginalId}';
export const BL_API_SCORES_URL =
BL_API_URL +
'player/${playerId}/scores?page=${page}&sortBy=${sort}&order=${order}&search=${search}&diff=${diff}&mode=${mode}&requirements=${requirements}&type=${songType}&modifiers=${modifiers}&stars_from=${starsFrom}&stars_to=${starsTo}&eventId=${eventId}&count=${count}';
Expand Down Expand Up @@ -217,8 +217,8 @@ export default (options = {}) => {
const user = async (priority = PRIORITY.FG_HIGH, options = {}) =>
fetchJson(BL_API_USER_URL, {...options, retries: 0, credentials: 'include', maxAge: 1, cacheTtl: null}, priority);

const player = async (playerId, priority = PRIORITY.FG_LOW, options = {}) =>
fetchJson(substituteVars(BL_API_PLAYER_INFO_URL, {playerId}), options, priority);
const player = async (playerId, priority = PRIORITY.FG_LOW, keepOriginalId = true, options = {}) =>
fetchJson(substituteVars(BL_API_PLAYER_INFO_URL, {playerId, keepOriginalId}), options, priority);

const steamProfile = async (playerId, priority = PRIORITY.FG_LOW, options = {}) =>
fetchJson(substituteVars(STEAM_API_PROFILE_URL, {steamKey: STEAM_KEY, playerId}), options, priority);
Expand Down
14 changes: 10 additions & 4 deletions src/services/beatleader/player.js
Original file line number Diff line number Diff line change
Expand Up @@ -71,18 +71,24 @@ export default () => {
const isResponseCached = response => playerApiClient.isResponseCached(response);
const getDataFromResponse = response => playerApiClient.getDataFromResponse(response);

const fetchPlayer = async (playerId, priority = PRIORITY.FG_LOW, {fullResponse = false, ...options} = {}) =>
const fetchPlayer = async (playerId, priority = PRIORITY.FG_LOW, keepOriginalId = true, {fullResponse = false, ...options} = {}) =>
resolvePromiseOrWaitForPending(`apiClient/${playerId}/${fullResponse}/${options.maxAge ?? MINUTE}`, () =>
playerApiClient.getProcessed({...options, playerId, priority, fullResponse})
playerApiClient.getProcessed({...options, playerId, priority, keepOriginalId, fullResponse})
);

const findPlayer = async (query, priority = PRIORITY.FG_LOW, {fullResponse = false, ...options} = {}) =>
resolvePromiseOrWaitForPending(`apiClient/find/${query}/${fullResponse}`, () =>
playerFindApiClient.getProcessed({...options, query, priority, fullResponse})
);

const fetchPlayerOrGetFromCache = async (playerId, refreshInterval = MINUTE, priority = PRIORITY.FG_LOW, signal = null, force = false) =>
fetchPlayer(playerId, priority, {signal, cacheTtl: MINUTE, maxAge: force ? 0 : refreshInterval});
const fetchPlayerOrGetFromCache = async (
playerId,
refreshInterval = MINUTE,
priority = PRIORITY.FG_LOW,
signal = null,
force = false,
keepOriginalId = true
) => fetchPlayer(playerId, priority, keepOriginalId, {signal, cacheTtl: MINUTE, maxAge: force ? 0 : refreshInterval});

const fetchAccGraph = async (playerId, priority = PRIORITY.BG_NORMAL, throwErrors = false) => {
try {
Expand Down

0 comments on commit 83317ce

Please sign in to comment.