diff --git a/apps/frontend/nuxt.config.ts b/apps/frontend/nuxt.config.ts index ebe3688f4..829db0b8a 100644 --- a/apps/frontend/nuxt.config.ts +++ b/apps/frontend/nuxt.config.ts @@ -45,6 +45,22 @@ const localesCategoriesOverrides: Partial pes: "experimental", }; +function readBinding( + binding: string, + defaultValue?: V, +): undefined extends V ? string | undefined : string { + const globalThis_ = globalThis as Record; + + let value; + if (binding in globalThis_) value = globalThis_[binding]; + + if (value == null || typeof value !== "string") { + return defaultValue as never; + } + + return value; +} + export default defineNuxtConfig({ srcDir: "src/", app: { @@ -296,10 +312,8 @@ export default defineNuxtConfig({ }, }, runtimeConfig: { - // @ts-ignore - apiBaseUrl: process.env.BASE_URL ?? globalThis.BASE_URL ?? getApiUrl(), - // @ts-ignore - rateLimitKey: process.env.RATE_LIMIT_IGNORE_KEY ?? globalThis.RATE_LIMIT_IGNORE_KEY, + apiBaseUrl: process.env.BASE_URL ?? readBinding("BASE_URL") ?? getApiUrl(), + rateLimitKey: process.env.RATE_LIMIT_IGNORE_KEY ?? readBinding("RATE_LIMIT_IGNORE_KEY"), public: { apiBaseUrl: getApiUrl(), siteUrl: getDomain(), @@ -311,14 +325,12 @@ export default defineNuxtConfig({ branch: process.env.VERCEL_GIT_COMMIT_REF || process.env.CF_PAGES_BRANCH || - // @ts-ignore - globalThis.CF_PAGES_BRANCH || + readBinding("CF_PAGES_BRANCH") || "master", hash: process.env.VERCEL_GIT_COMMIT_SHA || process.env.CF_PAGES_COMMIT_SHA || - // @ts-ignore - globalThis.CF_PAGES_COMMIT_SHA || + readBinding("CF_PAGES_COMMIT_SHA") || "unknown", turnstile: { siteKey: "0x4AAAAAAAW3guHM6Eunbgwu" }, @@ -396,8 +408,7 @@ export default defineNuxtConfig({ }); function getApiUrl() { - // @ts-ignore - return process.env.BROWSER_BASE_URL ?? globalThis.BROWSER_BASE_URL ?? STAGING_API_URL; + return process.env.BROWSER_BASE_URL ?? readBinding("BROWSER_BASE_URL") ?? STAGING_API_URL; } function isProduction() { @@ -412,11 +423,8 @@ function getDomain() { if (process.env.NODE_ENV === "production") { if (process.env.SITE_URL) { return process.env.SITE_URL; - } - // @ts-ignore - else if (process.env.CF_PAGES_URL || globalThis.CF_PAGES_URL) { - // @ts-ignore - return process.env.CF_PAGES_URL ?? globalThis.CF_PAGES_URL; + } else if (process.env.CF_PAGES_URL || readBinding("CF_PAGES_URL")) { + return process.env.CF_PAGES_URL ?? readBinding("CF_PAGES_URL"); } else if (process.env.HEROKU_APP_NAME) { return `https://${process.env.HEROKU_APP_NAME}.herokuapp.com`; } else if (process.env.VERCEL_URL) { diff --git a/apps/frontend/src/composables/use-client-try.ts b/apps/frontend/src/composables/use-client-try.ts index 697fcae34..ec1c7a191 100644 --- a/apps/frontend/src/composables/use-client-try.ts +++ b/apps/frontend/src/composables/use-client-try.ts @@ -1,25 +1,24 @@ -type AsyncFunction = (...args: TArgs) => Promise; -type ErrorFunction = (err: any) => void | Promise; -type VoidFunction = () => void | Promise; - -type useClientTry = ( - fn: AsyncFunction, - onFail?: ErrorFunction, - onFinish?: VoidFunction, -) => (...args: TArgs) => Promise; - -const defaultOnError: ErrorFunction = (error) => { +function defaultErrorHandler(error: any) { addNotification({ group: "main", title: "An error occurred", text: error?.data?.description || error.message || error || "Unknown error", type: "error", }); -}; +} + +type AsyncFunction = (...args: TArgs) => Promise; -export const useClientTry: useClientTry = - (fn, onFail = defaultOnError, onFinish) => - async (...args) => { +type ErrorHandlerFunction = (err: unknown) => void | Promise; + +type FinishCallbackFunction = () => Promise | void; + +export async function useClientTry( + fn: AsyncFunction, + onFail: ErrorHandlerFunction = defaultErrorHandler, + onFinish?: FinishCallbackFunction, +) { + return async function (...args: TArgs) { startLoading(); try { return await fn(...args); @@ -34,3 +33,4 @@ export const useClientTry: useClientTry = stopLoading(); } }; +} diff --git a/apps/frontend/src/helpers/highlight.js b/apps/frontend/src/helpers/highlight.js index 983eb64f1..15238c62e 100644 --- a/apps/frontend/src/helpers/highlight.js +++ b/apps/frontend/src/helpers/highlight.js @@ -54,7 +54,7 @@ export const renderHighlightedString = (string) => if (lang && hljs.getLanguage(lang)) { try { return hljs.highlight(str, { language: lang }).value; - } catch (__) { + } catch { /* empty */ } } diff --git a/apps/frontend/src/helpers/infer.js b/apps/frontend/src/helpers/infer.js index 165d25305..8be5eb7f7 100644 --- a/apps/frontend/src/helpers/infer.js +++ b/apps/frontend/src/helpers/infer.js @@ -97,23 +97,18 @@ export const inferVersionInfo = async function (rawFile, project, gameVersions) const inferFunctions = { // Forge 1.13+ and NeoForge "META-INF/mods.toml": async (file, zip) => { - const metadata = TOML.parse(file, { joiner: "\n" }); + const metadata = TOML.parse(file, { joiner: "\n" }); if (metadata.mods && metadata.mods.length > 0) { let versionNum = metadata.mods[0].version; // ${file.jarVersion} -> Implementation-Version from manifest const manifestFile = zip.file("META-INF/MANIFEST.MF"); - if ( - - metadata.mods[0].version.includes("${file.jarVersion}") && - manifestFile !== null - ) { + if (metadata.mods[0].version.includes("${file.jarVersion}") && manifestFile !== null) { const manifestText = await manifestFile.async("text"); const regex = /Implementation-Version: (.*)$/m; const match = manifestText.match(regex); if (match) { - versionNum = versionNum.replace("${file.jarVersion}", match[1]); } } diff --git a/apps/frontend/src/pages/dashboard/collections.vue b/apps/frontend/src/pages/dashboard/collections.vue index 66ebb86eb..c4dac133d 100644 --- a/apps/frontend/src/pages/dashboard/collections.vue +++ b/apps/frontend/src/pages/dashboard/collections.vue @@ -142,7 +142,7 @@ const { data: collections } = await useAsyncData(`user/${auth.value.user.id}/col const orderedCollections = computed(() => { if (!collections.value) return []; - return collections.value + return [...collections.value] .sort((a, b) => { const aUpdated = new Date(a.updated); const bUpdated = new Date(b.updated); diff --git a/apps/frontend/src/pages/dashboard/projects.vue b/apps/frontend/src/pages/dashboard/projects.vue index ebd06c9ce..45f11e412 100644 --- a/apps/frontend/src/pages/dashboard/projects.vue +++ b/apps/frontend/src/pages/dashboard/projects.vue @@ -440,19 +440,19 @@ export default defineNuxtComponent({ discord_url: this.editLinks.discord.clear ? null : this.editLinks.discord.val.trim(), }; - if (!baseData.issues_url?.length ?? 1 > 0) { + if (!((baseData.issues_url?.length ?? 1) > 0)) { delete baseData.issues_url; } - if (!baseData.source_url?.length ?? 1 > 0) { + if (!((baseData.source_url?.length ?? 1) > 0)) { delete baseData.source_url; } - if (!baseData.wiki_url?.length ?? 1 > 0) { + if (!((baseData.wiki_url?.length ?? 1) > 0)) { delete baseData.wiki_url; } - if (!baseData.discord_url?.length ?? 1 > 0) { + if (!((baseData.discord_url?.length ?? 1) > 0)) { delete baseData.discord_url; } diff --git a/apps/frontend/src/pages/dashboard/revenue/transfers.vue b/apps/frontend/src/pages/dashboard/revenue/transfers.vue index d2fc96c7c..d1f9c5548 100644 --- a/apps/frontend/src/pages/dashboard/revenue/transfers.vue +++ b/apps/frontend/src/pages/dashboard/revenue/transfers.vue @@ -118,7 +118,7 @@ const { data: payouts, refresh } = await useAsyncData(`payout`, () => ); const sortedPayouts = computed(() => - payouts.value.sort((a, b) => dayjs(b.created) - dayjs(a.created)), + [...payouts.value].sort((a, b) => dayjs(b.created) - dayjs(a.created)), ); const years = computed(() => { diff --git a/apps/frontend/src/utils/analytics.js b/apps/frontend/src/utils/analytics.js index d7576f92f..f1384c575 100644 --- a/apps/frontend/src/utils/analytics.js +++ b/apps/frontend/src/utils/analytics.js @@ -5,7 +5,7 @@ import { ref, watch, computed } from "vue"; // note: build step can miss unix import for some reason, so // we have to import it like this -const { unix } = dayjs; +const { unix } = dayjs; export function useCountryNames(style = "long") { const formattingOptions = { type: "region", style }; @@ -277,7 +277,7 @@ export const processAnalyticsByCountry = (category, projects, sortFn) => { }; }; -const sortCount = ([_a, a], [_b, b]) => b - a; +const sortCount = ([, a], [, b]) => b - a; const sortTimestamp = ([a], [b]) => a - b; const roundValue = ([ts, value]) => [ts, Math.round(parseFloat(value) * 100) / 100]; diff --git a/apps/frontend/src/utils/vue-children.ts b/apps/frontend/src/utils/vue-children.ts index 59e820bad..daa077545 100644 --- a/apps/frontend/src/utils/vue-children.ts +++ b/apps/frontend/src/utils/vue-children.ts @@ -8,7 +8,7 @@ import { createTextVNode, isVNode, toDisplayString, type VNode } from "vue"; * @returns Either the original VNode or a text VNode containing child converted * to a display string. */ -function normalizeChild(child: any): VNode { +function normalizeChild(child: unknown): VNode { return isVNode(child) ? child : createTextVNode(toDisplayString(child)); } @@ -20,6 +20,6 @@ function normalizeChild(child: any): VNode { * @param children Children to normalize. * @returns Children with all of non-VNodes converted to display strings. */ -export function normalizeChildren(children: any | any[]): VNode[] { +export function normalizeChildren(children: unknown | unknown[]): VNode[] { return Array.isArray(children) ? children.map(normalizeChild) : [normalizeChild(children)]; }