mirror of
https://github.com/YuzuZensai/VRC-Circle.git
synced 2026-09-14 03:10:01 +00:00
✨ feat: Create Instance, Auto Instance Region
This commit is contained in:
@@ -1,6 +1,12 @@
|
||||
import type { Instance } from "../../shared/types/instance";
|
||||
import type {
|
||||
Instance,
|
||||
CreateInstanceInput,
|
||||
CreateInstanceType,
|
||||
} from "../../shared/types/instance";
|
||||
import { toInstance } from "./mappers";
|
||||
import { cachedRead } from "./cachedRead";
|
||||
import { requireActiveClient } from "./client";
|
||||
import { currentUser } from "./userService";
|
||||
import { cacheKeys, policies } from "../cache/policies";
|
||||
|
||||
export async function getInstance(worldId: string, instanceId: string): Promise<Instance> {
|
||||
@@ -13,3 +19,42 @@ export async function getInstance(worldId: string, instanceId: string): Promise<
|
||||
},
|
||||
);
|
||||
}
|
||||
|
||||
type SdkType = "public" | "friends" | "hidden" | "private";
|
||||
|
||||
function mapCreateType(type: CreateInstanceType): { type: SdkType; canRequestInvite?: boolean } {
|
||||
switch (type) {
|
||||
case "public":
|
||||
return { type: "public" };
|
||||
case "friends+":
|
||||
return { type: "hidden" };
|
||||
case "friends":
|
||||
return { type: "friends" };
|
||||
case "invite":
|
||||
return { type: "private" };
|
||||
case "invite+":
|
||||
return { type: "private", canRequestInvite: true };
|
||||
}
|
||||
}
|
||||
|
||||
export async function createInstance(input: CreateInstanceInput): Promise<Instance> {
|
||||
const vrc = requireActiveClient();
|
||||
const sdk = mapCreateType(input.type);
|
||||
const ownerId = sdk.type === "public" ? undefined : (await currentUser()).id;
|
||||
const { data } = await vrc.createInstance({
|
||||
body: {
|
||||
worldId: input.worldId,
|
||||
region: input.region,
|
||||
type: sdk.type,
|
||||
...(ownerId ? { ownerId } : {}),
|
||||
...(sdk.canRequestInvite ? { canRequestInvite: true } : {}),
|
||||
},
|
||||
throwOnError: true,
|
||||
});
|
||||
return toInstance(data);
|
||||
}
|
||||
|
||||
export async function inviteSelf(worldId: string, instanceId: string): Promise<void> {
|
||||
const vrc = requireActiveClient();
|
||||
await vrc.inviteMyselfTo({ path: { worldId, instanceId }, throwOnError: true });
|
||||
}
|
||||
|
||||
@@ -211,6 +211,8 @@ export function toInstance(raw: SdkInstance): Instance {
|
||||
full: raw.full ?? false,
|
||||
queueEnabled: raw.queueEnabled ?? false,
|
||||
queueSize: raw.queueSize ?? 0,
|
||||
secureName: raw.secureName ?? undefined,
|
||||
shortName: raw.shortName ?? undefined,
|
||||
};
|
||||
}
|
||||
|
||||
|
||||
Reference in New Issue
Block a user