fix(frontend): break static import cycles for dpdm gate

This commit is contained in:
Stuart Anderson
2026-09-19 16:24:34 -05:00
parent 4dcc640e26
commit 76309225c1
7 changed files with 128 additions and 118 deletions

View File

@@ -0,0 +1,61 @@
export const ROUTES = {
SETUP: "setup",
LOGIN: "login",
RESET_PASSWORD: "reset-password",
REGISTER: "register",
MAIN: "main",
HOME: "home",
SEARCH: "search",
MUSIC: "music",
PLATFORM: "platform",
COLLECTION: "collection",
VIRTUAL_COLLECTION: "virtual-collection",
SMART_COLLECTION: "smart-collection",
ROM: "rom",
EMULATORJS: "emulatorjs",
JSDOS: "jsdos",
PICO8: "pico8",
RUFFLE: "ruffle",
STREAM: "stream",
STREAM_DESKTOP: "stream-desktop",
SCAN: "scan",
UPLOAD: "upload",
ACTIVITY: "activity",
USER_PROFILE: "user-profile",
USER_INTERFACE: "user-interface",
LIBRARY_MANAGEMENT: "library-management",
SCAN_SETTINGS: "scan-settings",
METADATA_SOURCES: "metadata-sources",
CLIENT_API_TOKENS: "client-api-tokens",
ADMINISTRATION: "administration",
SERVER_STATS: "server-stats",
LOGS: "logs",
PAIR: "pair",
PAIR_DEVICE: "pair-device",
APRIL_FOOLS: "april-fools",
CONSOLE_HOME: "console-home",
CONSOLE_PLATFORM: "console-platform",
CONSOLE_COLLECTION: "console-collection",
CONSOLE_SMART_COLLECTION: "console-smart-collection",
CONSOLE_VIRTUAL_COLLECTION: "console-virtual-collection",
CONSOLE_ROM: "console-rom",
CONSOLE_PLAY: "console-play",
PLATFORMS_INDEX: "platforms-index",
COLLECTIONS_INDEX: "collections-index",
CONTROLLER_DEBUG: "controller-debug",
NOT_FOUND: "404",
} as const;
const authExemptRoutes = [
ROUTES.LOGIN,
ROUTES.SETUP,
ROUTES.RESET_PASSWORD,
ROUTES.REGISTER,
ROUTES.PAIR,
] as const;
type AuthExemptRoute = (typeof authExemptRoutes)[number];
export function isAuthExemptRoute(route: string): route is AuthExemptRoute {
return (authExemptRoutes as readonly string[]).includes(route);
}

View File

@@ -7,6 +7,7 @@ import {
type RouteLocationNormalized,
} from "vue-router";
import i18n, { loadLocale } from "@/locales";
import { isAuthExemptRoute, ROUTES } from "@/plugins/routeNames";
import { startViewTransition } from "@/plugins/transition";
import romApi from "@/services/api/rom";
import storeAuth from "@/stores/auth";
@@ -19,54 +20,7 @@ import {
v2RouteComponents,
} from "@/v2/router/routes";
export const ROUTES = {
SETUP: "setup",
LOGIN: "login",
RESET_PASSWORD: "reset-password",
REGISTER: "register",
MAIN: "main",
HOME: "home",
SEARCH: "search",
MUSIC: "music",
PLATFORM: "platform",
COLLECTION: "collection",
VIRTUAL_COLLECTION: "virtual-collection",
SMART_COLLECTION: "smart-collection",
ROM: "rom",
EMULATORJS: "emulatorjs",
JSDOS: "jsdos",
PICO8: "pico8",
RUFFLE: "ruffle",
STREAM: "stream",
STREAM_DESKTOP: "stream-desktop",
SCAN: "scan",
UPLOAD: "upload",
ACTIVITY: "activity",
USER_PROFILE: "user-profile",
USER_INTERFACE: "user-interface",
LIBRARY_MANAGEMENT: "library-management",
SCAN_SETTINGS: "scan-settings",
METADATA_SOURCES: "metadata-sources",
CLIENT_API_TOKENS: "client-api-tokens",
ADMINISTRATION: "administration",
SERVER_STATS: "server-stats",
LOGS: "logs",
PAIR: "pair",
PAIR_DEVICE: "pair-device",
APRIL_FOOLS: "april-fools",
CONSOLE_HOME: "console-home",
CONSOLE_PLATFORM: "console-platform",
CONSOLE_COLLECTION: "console-collection",
CONSOLE_SMART_COLLECTION: "console-smart-collection",
CONSOLE_VIRTUAL_COLLECTION: "console-virtual-collection",
CONSOLE_ROM: "console-rom",
CONSOLE_PLAY: "console-play",
// V2-only routes (no v1 equivalent — v1 uses its drawer for these).
PLATFORMS_INDEX: "platforms-index",
COLLECTIONS_INDEX: "collections-index",
CONTROLLER_DEBUG: "controller-debug",
NOT_FOUND: "404",
} as const;
export { isAuthExemptRoute, ROUTES } from "@/plugins/routeNames";
// Resolve the v2 component for a given route name, falling back to the 404
// view so every route renders something when the user is on uiVersion=v2.
@@ -618,20 +572,6 @@ const routePermissions: RoutePermissions[] = [
{ path: ROUTES.LOGS, requiredScopes: ["logs.read"] },
];
const authExemptRoutes = [
ROUTES.LOGIN,
ROUTES.SETUP,
ROUTES.RESET_PASSWORD,
ROUTES.REGISTER,
ROUTES.PAIR,
] as const;
type AuthExemptRoute = (typeof authExemptRoutes)[number];
export function isAuthExemptRoute(route: string): route is AuthExemptRoute {
return (authExemptRoutes as readonly string[]).includes(route);
}
function checkRoutePermissions(route: string, user: User | null): boolean {
// No checks needed for login and setup pages
if (isAuthExemptRoute(route)) {

View File

@@ -1,8 +1,6 @@
import axios from "axios";
import { default as Cookies } from "js-cookie";
import { debounce } from "lodash";
import router from "@/plugins/router";
import { ROUTES, isAuthExemptRoute } from "@/plugins/router";
const api = axios.create({
// This will keep the url query params on refresh
@@ -133,6 +131,14 @@ api.interceptors.response.use(
const params = new URLSearchParams(search);
const fullPath = pathname + search;
// Static router import created api ↔ router TDZ; dynamic load only on 401.
// @dpdm-ignore
const {
default: router,
ROUTES,
isAuthExemptRoute,
} = await import("@/plugins/router");
// Don't redirect to login if already on an auth-exempt route.
// Also resolve the route from the browser URL to handle the case where
// the router hasn't been started yet (e.g., during app initialization),

View File

@@ -23,7 +23,7 @@ import { type CustomLimitOffsetPage_SimpleRomSchema_ as GetRomsResponse } from "
import api from "@/services/api";
import socket from "@/services/socket";
import storeUpload from "@/stores/upload";
import { getDownloadPath } from "@/utils";
import { getDownloadPath } from "@/utils/downloadPath";
import { buildFormInput, type FormInputField } from "@/utils/formData";
export const romApi = api;

View File

@@ -1,6 +1,6 @@
import { useLocalStorage } from "@vueuse/core";
import { defineStore } from "pinia";
import { ROUTES } from "@/plugins/router";
import { ROUTES } from "@/plugins/routeNames";
const mainBarCollapsed = useLocalStorage("ui.mainBarCollapsed", false);

View File

@@ -0,0 +1,54 @@
import type { SimpleRomSchema } from "@/__generated__";
type DownloadRom = Pick<
SimpleRomSchema,
"id" | "fs_name" | "has_nested_single_file" | "files"
>;
/**
* Generate a download link for ROM content.
*/
export function getDownloadPath({
rom,
fileIDs = [],
}: {
rom: DownloadRom;
fileIDs?: number[];
}) {
const queryParams = new URLSearchParams();
if (fileIDs.length > 0) {
queryParams.append("file_ids", fileIDs.join(","));
}
const queryString = queryParams.toString();
const selectedFile =
fileIDs.length === 1
? rom.files?.find((f) => f.id === fileIDs[0])
: undefined;
const nestedFile =
fileIDs.length === 0 &&
rom.has_nested_single_file &&
rom.files?.length === 1
? rom.files[0]
: undefined;
const contentFile = selectedFile ?? nestedFile;
const contentName = contentFile
? encodeURIComponent(contentFile.file_name)
: rom.fs_name;
return `/api/roms/${rom.id}/content/${contentName}${
queryString ? `?${queryString}` : ""
}`;
}
export function getDownloadLink({
rom,
fileIDs = [],
}: {
rom: DownloadRom;
fileIDs?: number[];
}) {
return `${window.location.origin}${encodeURI(
getDownloadPath({ rom, fileIDs }),
)}`;
}

View File

@@ -107,58 +107,7 @@ export function convertCronExperssion(expression: string) {
return convertedExpression;
}
/**
* Generate a download link for ROM content.
*
* @param rom The ROM object.
* @param files Optional array of file names to include in the download.
* @returns The download link.
*/
export function getDownloadPath({
rom,
fileIDs = [],
}: {
rom: SimpleRom;
fileIDs?: number[];
}) {
const queryParams = new URLSearchParams();
if (fileIDs.length > 0) {
queryParams.append("file_ids", fileIDs.join(","));
}
const queryString = queryParams.toString();
// If a single file is selected, use its name for the download path
const selectedFile =
fileIDs.length === 1
? rom.files?.find((f) => f.id === fileIDs[0])
: undefined;
const nestedFile =
fileIDs.length === 0 &&
rom.has_nested_single_file &&
rom.files?.length === 1
? rom.files[0]
: undefined;
const contentFile = selectedFile ?? nestedFile;
const contentName = contentFile
? encodeURIComponent(contentFile.file_name)
: rom.fs_name;
return `/api/roms/${rom.id}/content/${contentName}${
queryString ? `?${queryString}` : ""
}`;
}
export function getDownloadLink({
rom,
fileIDs = [],
}: {
rom: SimpleRom;
fileIDs?: number[];
}) {
return `${window.location.origin}${encodeURI(
getDownloadPath({ rom, fileIDs }),
)}`;
}
export { getDownloadLink, getDownloadPath } from "@/utils/downloadPath";
/**
* Format bytes as human-readable text.