mirror of
https://github.com/nestriness/nestri.git
synced 2026-08-01 17:34:15 +03:00
feat: Fix some typings
This commit is contained in:
@@ -10,9 +10,9 @@ import {
|
|||||||
AudioCodecName,
|
AudioCodecName,
|
||||||
RetryOptions,
|
RetryOptions,
|
||||||
SessionInfo,
|
SessionInfo,
|
||||||
type SessionInfo as SessionInfoType,
|
|
||||||
type Session as SessionInterface,
|
|
||||||
type Config as SessionConfig,
|
type Config as SessionConfig,
|
||||||
|
type Session as SessionInterface,
|
||||||
|
type SessionInfo as SessionInfoType,
|
||||||
} from "./types.js";
|
} from "./types.js";
|
||||||
import { Actor } from "../actor.js";
|
import { Actor } from "../actor.js";
|
||||||
import { Database } from "../drizzle/index.js";
|
import { Database } from "../drizzle/index.js";
|
||||||
@@ -93,16 +93,16 @@ export namespace Session {
|
|||||||
|
|
||||||
export function serialize(
|
export function serialize(
|
||||||
input: typeof sessionTable.$inferSelect,
|
input: typeof sessionTable.$inferSelect,
|
||||||
): z.infer<typeof SessionInfo> {
|
): z.infer<typeof Info> {
|
||||||
return {
|
return {
|
||||||
id: input.id,
|
id: input.id,
|
||||||
room: input.room || undefined,
|
// room: input.room || undefined,
|
||||||
|
machine: input.machine,
|
||||||
|
relayUrl: input.relayUrl,
|
||||||
retry: input.retry || undefined,
|
retry: input.retry || undefined,
|
||||||
queue: input.queue || undefined,
|
queue: input.queue || undefined,
|
||||||
machine: input.machine || undefined,
|
|
||||||
description: input.description || undefined,
|
description: input.description || undefined,
|
||||||
maxDuration: input.maxDuration || undefined,
|
maxDuration: input.maxDuration || undefined,
|
||||||
relayUrl: input.relayUrl || undefined,
|
|
||||||
resolution: input.resolution || undefined,
|
resolution: input.resolution || undefined,
|
||||||
framerate: input.framerate || undefined,
|
framerate: input.framerate || undefined,
|
||||||
gpuVendor: input.gpuVendor || undefined,
|
gpuVendor: input.gpuVendor || undefined,
|
||||||
|
|||||||
@@ -33,14 +33,17 @@ export const sessionTable = pgTable("sessions", {
|
|||||||
.notNull(),
|
.notNull(),
|
||||||
retry: jsonb("retry").$type<RetryOptions>(),
|
retry: jsonb("retry").$type<RetryOptions>(),
|
||||||
queue: jsonb("queue").$type<Queue>(),
|
queue: jsonb("queue").$type<Queue>(),
|
||||||
machine: varchar("machine", { length: 200 }).$type<MachinePresetName>(),
|
machine: varchar("machine", { length: 200 })
|
||||||
|
.$type<MachinePresetName>()
|
||||||
|
.notNull()
|
||||||
|
.default("ns3-micro"),
|
||||||
maxDuration: integer("max_duration"),
|
maxDuration: integer("max_duration"),
|
||||||
relayUrl: varchar("relay_url", { length: 500 }),
|
relayUrl: varchar("relay_url", { length: 500 }).notNull(),
|
||||||
resolution: varchar("resolution", {
|
resolution: varchar("resolution", {
|
||||||
length: 20,
|
length: 20,
|
||||||
}).$type<ScreenResolutionPresetName>(),
|
}).$type<ScreenResolutionPresetName>(),
|
||||||
framerate: integer("framerate"),
|
framerate: integer("framerate"),
|
||||||
room: varchar("room", { length: 255 }),
|
// room: varchar("room", { length: 255 }),
|
||||||
gpuVendor: varchar("gpu_vendor", { length: 100 }),
|
gpuVendor: varchar("gpu_vendor", { length: 100 }),
|
||||||
gpuName: varchar("gpu_name", { length: 255 }),
|
gpuName: varchar("gpu_name", { length: 255 }),
|
||||||
gpuIndex: integer("gpu_index"),
|
gpuIndex: integer("gpu_index"),
|
||||||
|
|||||||
@@ -123,20 +123,26 @@ export const SessionInfo = z
|
|||||||
example: Examples.Session.queue,
|
example: Examples.Session.queue,
|
||||||
}),
|
}),
|
||||||
/** Machine preset for the session */
|
/** Machine preset for the session */
|
||||||
machine: MachinePresetName.optional().meta({
|
machine: MachinePresetName.optional()
|
||||||
|
.meta({
|
||||||
description: "Machine preset for the session",
|
description: "Machine preset for the session",
|
||||||
example: Examples.Session.machine,
|
example: Examples.Session.machine,
|
||||||
}),
|
})
|
||||||
|
.default("ns3-micro"),
|
||||||
/** Maximum duration in seconds the session can run */
|
/** Maximum duration in seconds the session can run */
|
||||||
maxDuration: z.number().optional().meta({
|
maxDuration: z.number().optional().meta({
|
||||||
description: "Maximum duration in seconds the session can run",
|
description: "Maximum duration in seconds the session can run",
|
||||||
example: Examples.Session.maxDuration,
|
example: Examples.Session.maxDuration,
|
||||||
}),
|
}),
|
||||||
/** Nestri relay URL for streaming and signaling */
|
/** Nestri relay URL for streaming and signaling */
|
||||||
relayUrl: z.url().optional().meta({
|
relayUrl: z
|
||||||
|
.url()
|
||||||
|
.optional()
|
||||||
|
.meta({
|
||||||
description: "Nestri relay URL for streaming and signaling",
|
description: "Nestri relay URL for streaming and signaling",
|
||||||
example: Examples.Session.relayUrl,
|
example: Examples.Session.relayUrl,
|
||||||
}),
|
})
|
||||||
|
.default("https://relay.nestri.io"),
|
||||||
/** Display or stream resolution in 'WxH' format */
|
/** Display or stream resolution in 'WxH' format */
|
||||||
resolution: ScreenResolutionPresetName.optional().meta({
|
resolution: ScreenResolutionPresetName.optional().meta({
|
||||||
description: "Display or stream resolution in 'WxH' format",
|
description: "Display or stream resolution in 'WxH' format",
|
||||||
@@ -148,10 +154,10 @@ export const SessionInfo = z
|
|||||||
example: Examples.Session.framerate,
|
example: Examples.Session.framerate,
|
||||||
}),
|
}),
|
||||||
/** Room name or identifier for multiplayer sessions */
|
/** Room name or identifier for multiplayer sessions */
|
||||||
room: z.string().optional().meta({
|
// room: z.string().optional().meta({
|
||||||
description: "Room name or identifier for multiplayer sessions",
|
// description: "Room name or identifier for multiplayer sessions",
|
||||||
example: Examples.Session.room,
|
// example: Examples.Session.room,
|
||||||
}),
|
// }),
|
||||||
/** Preferred GPU vendor */
|
/** Preferred GPU vendor */
|
||||||
gpuVendor: z.string().optional().meta({
|
gpuVendor: z.string().optional().meta({
|
||||||
description: "Preferred GPU vendor",
|
description: "Preferred GPU vendor",
|
||||||
|
|||||||
@@ -3,6 +3,7 @@ import { Hono } from "hono";
|
|||||||
import { cors } from "hono/cors";
|
import { cors } from "hono/cors";
|
||||||
import { auth } from "./utils/auth";
|
import { auth } from "./utils/auth";
|
||||||
import { Log } from "@nestri/core/utils/log";
|
import { Log } from "@nestri/core/utils/log";
|
||||||
|
import { SessionApi } from "./routes/session.js";
|
||||||
import { HTTPException } from "hono/http-exception";
|
import { HTTPException } from "hono/http-exception";
|
||||||
import { VisibleError, ErrorCodes } from "@nestri/core/error";
|
import { VisibleError, ErrorCodes } from "@nestri/core/error";
|
||||||
import { openAPIRouteHandler, validator } from "hono-openapi";
|
import { openAPIRouteHandler, validator } from "hono-openapi";
|
||||||
@@ -38,6 +39,7 @@ export const routes = app
|
|||||||
.get("/", async (c) => {
|
.get("/", async (c) => {
|
||||||
return c.text("ok");
|
return c.text("ok");
|
||||||
})
|
})
|
||||||
|
.route("/session", SessionApi.route)
|
||||||
.onError((error, c) => {
|
.onError((error, c) => {
|
||||||
// Handle our custom VisibleError
|
// Handle our custom VisibleError
|
||||||
if (error instanceof VisibleError) {
|
if (error instanceof VisibleError) {
|
||||||
|
|||||||
@@ -4,7 +4,7 @@ import { ErrorResponses } from "../utils/error.js";
|
|||||||
import { Session } from "@nestri/core/session/index";
|
import { Session } from "@nestri/core/session/index";
|
||||||
import { describeRoute, resolver, validator } from "hono-openapi";
|
import { describeRoute, resolver, validator } from "hono-openapi";
|
||||||
|
|
||||||
export namespace SessionRoute {
|
export namespace SessionApi {
|
||||||
export const route = new Hono()
|
export const route = new Hono()
|
||||||
.use(notPublic)
|
.use(notPublic)
|
||||||
.get(
|
.get(
|
||||||
|
|||||||
Reference in New Issue
Block a user