mirror of
https://github.com/MrUnknownDE/VRCX.git
synced 2026-04-28 19:23:47 +02:00
rewrite web request logging function
This commit is contained in:
@@ -13,7 +13,7 @@ import {
|
|||||||
storeAvatarImage
|
storeAvatarImage
|
||||||
} from '../shared/utils';
|
} from '../shared/utils';
|
||||||
import { avatarRequest, miscRequest, queryRequest } from '../api';
|
import { avatarRequest, miscRequest, queryRequest } from '../api';
|
||||||
import { AppDebug } from '../services/appConfig';
|
import { logWebRequest } from '../services/appConfig';
|
||||||
import { database } from '../services/database';
|
import { database } from '../services/database';
|
||||||
import { patchAvatarFromEvent } from '../queries';
|
import { patchAvatarFromEvent } from '../queries';
|
||||||
import { processBulk } from '../services/request';
|
import { processBulk } from '../services/request';
|
||||||
@@ -295,9 +295,7 @@ export async function lookupAvatars(type, search) {
|
|||||||
}
|
}
|
||||||
});
|
});
|
||||||
const json = JSON.parse(response.data);
|
const json = JSON.parse(response.data);
|
||||||
if (AppDebug.debugWebRequests) {
|
logWebRequest('[EXTERNAL GET]', url, `(${response.status})`, json);
|
||||||
console.log(url, json, response);
|
|
||||||
}
|
|
||||||
if (response.status === 200 && typeof json === 'object') {
|
if (response.status === 200 && typeof json === 'object') {
|
||||||
json.forEach((avatar) => {
|
json.forEach((avatar) => {
|
||||||
if (!avatars.has(avatar.Id)) {
|
if (!avatars.has(avatar.Id)) {
|
||||||
@@ -386,9 +384,7 @@ async function lookupAvatarByFileId(providerUrl, fileId) {
|
|||||||
}
|
}
|
||||||
});
|
});
|
||||||
const json = JSON.parse(response.data);
|
const json = JSON.parse(response.data);
|
||||||
if (AppDebug.debugWebRequests) {
|
logWebRequest('[EXTERNAL GET]', url, `(${response.status})`, json);
|
||||||
console.log(url, json, response);
|
|
||||||
}
|
|
||||||
if (response.status === 200 && typeof json === 'object') {
|
if (response.status === 200 && typeof json === 'object') {
|
||||||
const ref = {
|
const ref = {
|
||||||
authorId: '',
|
authorId: '',
|
||||||
@@ -436,9 +432,7 @@ async function lookupAvatarsByAuthor(providerUrl, authorId) {
|
|||||||
}
|
}
|
||||||
});
|
});
|
||||||
const json = JSON.parse(response.data);
|
const json = JSON.parse(response.data);
|
||||||
if (AppDebug.debugWebRequests) {
|
logWebRequest('[EXTERNAL GET]', url, `(${response.status})`, json);
|
||||||
console.log(url, json, response);
|
|
||||||
}
|
|
||||||
if (response.status === 200 && typeof json === 'object') {
|
if (response.status === 200 && typeof json === 'object') {
|
||||||
json.forEach((avatar) => {
|
json.forEach((avatar) => {
|
||||||
const ref = {
|
const ref = {
|
||||||
|
|||||||
@@ -12,7 +12,7 @@ import {
|
|||||||
replaceBioSymbols
|
replaceBioSymbols
|
||||||
} from '../shared/utils';
|
} from '../shared/utils';
|
||||||
import { i18n } from '../plugins/i18n';
|
import { i18n } from '../plugins/i18n';
|
||||||
import { AppDebug } from '../services/appConfig';
|
import { AppDebug, logWebRequest } from '../services/appConfig';
|
||||||
import { database } from '../services/database';
|
import { database } from '../services/database';
|
||||||
import {
|
import {
|
||||||
runLastLocationResetFlow,
|
runLastLocationResetFlow,
|
||||||
@@ -334,9 +334,7 @@ export function addGameLogEntry(gameLog, location) {
|
|||||||
vrcxStore.processScreenshot(gameLog.screenshotPath);
|
vrcxStore.processScreenshot(gameLog.screenshotPath);
|
||||||
break;
|
break;
|
||||||
case 'api-request':
|
case 'api-request':
|
||||||
if (AppDebug.debugWebRequests) {
|
logWebRequest('[GAMELOG API]', gameLog.url);
|
||||||
console.log('API Request:', gameLog.url);
|
|
||||||
}
|
|
||||||
if (advancedSettingsStore.saveInstanceEmoji) {
|
if (advancedSettingsStore.saveInstanceEmoji) {
|
||||||
const inv = parseInventoryFromUrl(gameLog.url);
|
const inv = parseInventoryFromUrl(gameLog.url);
|
||||||
if (inv) {
|
if (inv) {
|
||||||
|
|||||||
@@ -1,3 +1,4 @@
|
|||||||
|
import { AppDebug, logWebRequest, withQueryLog } from '../services/appConfig';
|
||||||
import { queryClient } from './client';
|
import { queryClient } from './client';
|
||||||
import { queryKeys } from './keys';
|
import { queryKeys } from './keys';
|
||||||
import { toQueryOptions } from './policies';
|
import { toQueryOptions } from './policies';
|
||||||
@@ -151,10 +152,16 @@ export async function fetchWithEntityPolicy({ queryKey, policy, queryFn }) {
|
|||||||
|
|
||||||
const data = await queryClient.fetchQuery({
|
const data = await queryClient.fetchQuery({
|
||||||
queryKey,
|
queryKey,
|
||||||
queryFn,
|
queryFn: () => withQueryLog(queryFn),
|
||||||
...toQueryOptions(policy)
|
...toQueryOptions(policy)
|
||||||
});
|
});
|
||||||
|
|
||||||
|
if (isFresh) {
|
||||||
|
logWebRequest('[QUERY CACHE HIT]', queryKey, data);
|
||||||
|
} else {
|
||||||
|
logWebRequest('[QUERY FETCH]', queryKey, data);
|
||||||
|
}
|
||||||
|
|
||||||
return {
|
return {
|
||||||
data,
|
data,
|
||||||
cache: isFresh
|
cache: isFresh
|
||||||
|
|||||||
@@ -26,4 +26,40 @@ window.$debug = AppDebug;
|
|||||||
window.utils = utils;
|
window.utils = utils;
|
||||||
window.dayjs = dayjs;
|
window.dayjs = dayjs;
|
||||||
|
|
||||||
|
/**
|
||||||
|
* @param {string} tag
|
||||||
|
* @param {string|unknown[]} target
|
||||||
|
* @param {...any} rest
|
||||||
|
*/
|
||||||
|
export function logWebRequest(tag, target, ...rest) {
|
||||||
|
if (!AppDebug.debugWebRequests) return;
|
||||||
|
console.log(tag, target, ...rest);
|
||||||
|
}
|
||||||
|
|
||||||
|
let _queryLogDepth = 0;
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Wraps an async fn so that any API request made inside
|
||||||
|
* will NOT emit the default [API …] debug log (the query
|
||||||
|
* layer prints its own log instead).
|
||||||
|
* @template T
|
||||||
|
* @param {() => Promise<T>} fn
|
||||||
|
* @returns {Promise<T>}
|
||||||
|
*/
|
||||||
|
export async function withQueryLog(fn) {
|
||||||
|
_queryLogDepth++;
|
||||||
|
try {
|
||||||
|
return await fn();
|
||||||
|
} finally {
|
||||||
|
_queryLogDepth--;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* @returns {boolean} true when inside a withQueryLog callback
|
||||||
|
*/
|
||||||
|
export function isApiLogSuppressed() {
|
||||||
|
return _queryLogDepth > 0;
|
||||||
|
}
|
||||||
|
|
||||||
export { AppDebug };
|
export { AppDebug };
|
||||||
|
|||||||
@@ -8,7 +8,7 @@ import {
|
|||||||
useUserStore
|
useUserStore
|
||||||
} from '../stores';
|
} from '../stores';
|
||||||
import { getCurrentUser } from '../coordinators/userCoordinator';
|
import { getCurrentUser } from '../coordinators/userCoordinator';
|
||||||
import { AppDebug } from './appConfig.js';
|
import { AppDebug, isApiLogSuppressed, logWebRequest } from './appConfig.js';
|
||||||
import { escapeTag } from '../shared/utils';
|
import { escapeTag } from '../shared/utils';
|
||||||
import { i18n } from '../plugins/i18n';
|
import { i18n } from '../plugins/i18n';
|
||||||
import { statusCodes } from '../shared/constants/api.js';
|
import { statusCodes } from '../shared/constants/api.js';
|
||||||
@@ -139,11 +139,17 @@ export function request(endpoint, options) {
|
|||||||
throw `API request blocked while logged out: ${endpoint}`;
|
throw `API request blocked while logged out: ${endpoint}`;
|
||||||
}
|
}
|
||||||
const parsed = parseResponse(response);
|
const parsed = parseResponse(response);
|
||||||
if (AppDebug.debugWebRequests) {
|
if (!isApiLogSuppressed()) {
|
||||||
|
const tag = `[API ${init.method}]`;
|
||||||
if (!parsed.data) {
|
if (!parsed.data) {
|
||||||
console.log(init, 'no data', parsed);
|
logWebRequest(tag, endpoint, `(${parsed.status}) no data`);
|
||||||
} else {
|
} else {
|
||||||
console.log(init, 'parsed data', parsed.data);
|
logWebRequest(
|
||||||
|
tag,
|
||||||
|
endpoint,
|
||||||
|
`(${parsed.status})`,
|
||||||
|
parsed.data
|
||||||
|
);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
if (parsed.hasApiError) {
|
if (parsed.hasApiError) {
|
||||||
|
|||||||
@@ -3,7 +3,7 @@ import { defineStore } from 'pinia';
|
|||||||
import { toast } from 'vue-sonner';
|
import { toast } from 'vue-sonner';
|
||||||
import { useI18n } from 'vue-i18n';
|
import { useI18n } from 'vue-i18n';
|
||||||
|
|
||||||
import { AppDebug } from '../../services/appConfig';
|
import { logWebRequest } from '../../services/appConfig';
|
||||||
import { database } from '../../services/database';
|
import { database } from '../../services/database';
|
||||||
import { languageCodes } from '../../localization';
|
import { languageCodes } from '../../localization';
|
||||||
import { useGameStore } from '../game';
|
import { useGameStore } from '../game';
|
||||||
@@ -464,9 +464,12 @@ export const useAdvancedSettingsStore = defineStore('AdvancedSettings', () => {
|
|||||||
}
|
}
|
||||||
|
|
||||||
const data = JSON.parse(response.data);
|
const data = JSON.parse(response.data);
|
||||||
if (AppDebug.debugWebRequests) {
|
logWebRequest(
|
||||||
console.log(modelsURL, data, response);
|
'[EXTERNAL GET]',
|
||||||
}
|
modelsURL,
|
||||||
|
`(${response.status})`,
|
||||||
|
data
|
||||||
|
);
|
||||||
|
|
||||||
if (data.data && Array.isArray(data.data)) {
|
if (data.data && Array.isArray(data.data)) {
|
||||||
return data.data
|
return data.data
|
||||||
@@ -703,9 +706,7 @@ export const useAdvancedSettingsStore = defineStore('AdvancedSettings', () => {
|
|||||||
}
|
}
|
||||||
});
|
});
|
||||||
const json = JSON.parse(response.data);
|
const json = JSON.parse(response.data);
|
||||||
if (AppDebug.debugWebRequests) {
|
logWebRequest('[EXTERNAL GET]', url, `(${response.status})`, json);
|
||||||
console.log(url, json, response);
|
|
||||||
}
|
|
||||||
if (response.status === 200) {
|
if (response.status === 200) {
|
||||||
data = json;
|
data = json;
|
||||||
} else {
|
} else {
|
||||||
@@ -753,9 +754,12 @@ export const useAdvancedSettingsStore = defineStore('AdvancedSettings', () => {
|
|||||||
);
|
);
|
||||||
}
|
}
|
||||||
const data = JSON.parse(response.data);
|
const data = JSON.parse(response.data);
|
||||||
if (AppDebug.debugWebRequests) {
|
logWebRequest(
|
||||||
console.log(url, data, response);
|
'[EXTERNAL POST]',
|
||||||
}
|
url,
|
||||||
|
`(${response.status})`,
|
||||||
|
data
|
||||||
|
);
|
||||||
return data.data.translations[0].translatedText;
|
return data.data.translations[0].translatedText;
|
||||||
} catch (err) {
|
} catch (err) {
|
||||||
toast.error(`Translation failed: ${err.message}`);
|
toast.error(`Translation failed: ${err.message}`);
|
||||||
@@ -817,9 +821,12 @@ export const useAdvancedSettingsStore = defineStore('AdvancedSettings', () => {
|
|||||||
}
|
}
|
||||||
|
|
||||||
const data = JSON.parse(response.data);
|
const data = JSON.parse(response.data);
|
||||||
if (AppDebug.debugWebRequests) {
|
logWebRequest(
|
||||||
console.log(endpoint, data, response);
|
'[EXTERNAL POST]',
|
||||||
}
|
endpoint,
|
||||||
|
`(${response.status})`,
|
||||||
|
data
|
||||||
|
);
|
||||||
|
|
||||||
const translated = data?.choices?.[0]?.message?.content;
|
const translated = data?.choices?.[0]?.message?.content;
|
||||||
return typeof translated === 'string' ? translated.trim() : null;
|
return typeof translated === 'string' ? translated.trim() : null;
|
||||||
|
|||||||
@@ -3,7 +3,7 @@ import { defineStore } from 'pinia';
|
|||||||
import { toast } from 'vue-sonner';
|
import { toast } from 'vue-sonner';
|
||||||
import { useI18n } from 'vue-i18n';
|
import { useI18n } from 'vue-i18n';
|
||||||
|
|
||||||
import { AppDebug } from '../services/appConfig';
|
import { logWebRequest } from '../services/appConfig';
|
||||||
import { branches } from '../shared/constants';
|
import { branches } from '../shared/constants';
|
||||||
import { changeLogRemoveLinks } from '../shared/utils';
|
import { changeLogRemoveLinks } from '../shared/utils';
|
||||||
|
|
||||||
@@ -222,9 +222,7 @@ export const useVRCXUpdaterStore = defineStore('VRCXUpdater', () => {
|
|||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
pendingVRCXUpdate.value = false;
|
pendingVRCXUpdate.value = false;
|
||||||
if (AppDebug.debugWebRequests) {
|
logWebRequest('[EXTERNAL GET]', url, `(${response.status})`, json);
|
||||||
console.log(url, json, response);
|
|
||||||
}
|
|
||||||
if (json === Object(json) && json.name && json.published_at) {
|
if (json === Object(json) && json.name && json.published_at) {
|
||||||
changeLogDialog.value.buildName = json.name;
|
changeLogDialog.value.buildName = json.name;
|
||||||
changeLogDialog.value.changeLog = changeLogRemoveLinks(json.body);
|
changeLogDialog.value.changeLog = changeLogRemoveLinks(json.body);
|
||||||
@@ -309,9 +307,7 @@ export const useVRCXUpdaterStore = defineStore('VRCXUpdater', () => {
|
|||||||
);
|
);
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
if (AppDebug.debugWebRequests) {
|
logWebRequest('[EXTERNAL GET]', url, `(${response.status})`, json);
|
||||||
console.log(url, json, response);
|
|
||||||
}
|
|
||||||
const releases = [];
|
const releases = [];
|
||||||
if (typeof json !== 'object' || json.message) {
|
if (typeof json !== 'object' || json.message) {
|
||||||
toast.error(
|
toast.error(
|
||||||
|
|||||||
Reference in New Issue
Block a user