refactor(streaming): type a claim's 409 detail in one place

The player and the desktop each spelled the busy-container detail inline, and the two copies had already drifted.
This commit is contained in:
Zach Clendenen
2026-09-18 12:27:43 -05:00
parent 983ecc01c6
commit 35761aa85c
3 changed files with 16 additions and 10 deletions

View File

@@ -80,6 +80,16 @@ export function isMemoryCardImportDetail(
);
}
/** Body of the 409 a claim returns when the container is taken. The route
* raises it as a plain detail dict, so it has no generated schema. */
export interface ContainerBusyDetail {
message: string;
draining: boolean;
/** The game holding it, null when the caller may not see which. */
rom_name: string | null;
claimed_at: string | null;
}
// ── Requests ──────────────────────────────────────────────────────────────────
async function fetchConfig() {

View File

@@ -14,7 +14,9 @@ import { computed, onMounted, ref } from "vue";
import { useI18n } from "vue-i18n";
import { onBeforeRouteLeave, useRoute, useRouter } from "vue-router";
import { ROUTES } from "@/plugins/router";
import streamingApi from "@/services/api/streaming";
import streamingApi, {
type ContainerBusyDetail,
} from "@/services/api/streaming";
import { type SessionTermination, useStreamingStore } from "@/stores/streaming";
import StreamStage from "@/v2/components/Player/StreamStage.vue";
import { useConfirm } from "@/v2/composables/useConfirm";
@@ -70,10 +72,7 @@ async function openDesktop(): Promise<void> {
? err.response?.data?.detail
: undefined;
if (status === 409) {
const busy = detail as {
draining?: boolean;
rom_name?: string | null;
} | null;
const busy = detail as ContainerBusyDetail | null;
// A drain marker is nobody's claim: the container comes free on its own
// once the previous session has finished saving.
if (busy?.draining)

View File

@@ -42,6 +42,7 @@ import { onBeforeRouteLeave, useRoute, useRouter } from "vue-router";
import type { SaveSchema, UserStateSchema } from "@/__generated__";
import romApi from "@/services/api/rom";
import streamingApi, {
type ContainerBusyDetail,
isMemoryCardImportDetail,
type LaunchFailed,
type LaunchPhase,
@@ -905,11 +906,7 @@ async function onPlay(cardImport?: MemoryCardImport): Promise<void> {
errorType.value = "occupied";
const busy =
detail && typeof detail === "object"
? (detail as {
rom_name: string | null;
claimed_at: string | null;
draining?: boolean;
})
? (detail as ContainerBusyDetail)
: null;
// A draining container is nobody's: the previous session is over and its
// exit state is still being collected, so there is no holder to name.