Implement Integral Data Types #13
@@ -45,3 +45,16 @@ pub trait IntoCommandDefinition: Sized {
|
||||
|
||||
fn parse(command: Command) -> Result<Self, IntoCommandDefinitionError>;
|
||||
}
|
||||
|
||||
impl IntoCommandDefinition for () {
|
||||
fn create(name: String) -> CommandDefinition {
|
||||
CommandDefinition {
|
||||
name,
|
||||
parameters: vec![],
|
||||
}
|
||||
}
|
||||
|
||||
fn parse(_: Command) -> Result<Self, IntoCommandDefinitionError> {
|
||||
Ok(())
|
||||
}
|
||||
}
|
||||
|
||||
@@ -19,7 +19,9 @@ const model = defineModel<{ [key: string]: CommandParameterData }>({
|
||||
required: true,
|
||||
});
|
||||
|
||||
const { data: command_info } = useCommand(props.command_name);
|
||||
const { data: command_info, error: command_error } = useCommand(
|
||||
props.command_name,
|
||||
);
|
||||
|
||||
watch([command_info], ([cmd_info]) => {
|
||||
if (cmd_info == null) {
|
||||
@@ -97,6 +99,9 @@ watch([command_info], ([cmd_info]) => {
|
||||
></CommandParameterDataConfigurator>
|
||||
</template>
|
||||
</template>
|
||||
<template v-else-if="command_error">
|
||||
<span>Error: {{ command_error }}</span>
|
||||
</template>
|
||||
<template v-else>
|
||||
<span> Loading... </span>
|
||||
</template>
|
||||
|
||||
@@ -41,8 +41,13 @@ export function useCommand(name: MaybeRefOrGetter<string>) {
|
||||
|
||||
try {
|
||||
const res = await fetch(`/api/cmd/${name_value}`);
|
||||
if (res.ok) {
|
||||
data.value = await res.json();
|
||||
error.value = null;
|
||||
} else {
|
||||
data.value = null;
|
||||
error.value = await res.text();
|
||||
}
|
||||
} catch (e) {
|
||||
data.value = null;
|
||||
error.value = e;
|
||||
|
||||
@@ -2,6 +2,7 @@
|
||||
export function toJsonString(data: any): string {
|
||||
return JSON.stringify(data, (_key, value) => {
|
||||
if (typeof value == 'bigint') {
|
||||
// @ts-expect-error TS2339
|
||||
return JSON.rawJSON(value.toString());
|
||||
}
|
||||
return value;
|
||||
@@ -10,6 +11,7 @@ export function toJsonString(data: any): string {
|
||||
|
||||
// eslint-disable-next-line @typescript-eslint/no-explicit-any
|
||||
export function parseJsonString(data: string): any {
|
||||
// @ts-expect-error TS2345, TS7006
|
||||
return JSON.parse(data, (key, value, context) => {
|
||||
if (key === 'Int64' || key == 'Unsigned64') {
|
||||
// Or use the constructor of your custom high-precision number library
|
||||
|
||||
@@ -29,6 +29,10 @@ pub(super) async fn get_one(
|
||||
name: web::Path<String>,
|
||||
) -> Result<impl Responder, HttpServerResultError> {
|
||||
Ok(web::Json(
|
||||
command_service.get_command_definition(&name.to_string()),
|
||||
command_service
|
||||
.get_command_definition(&name.to_string())
|
||||
.ok_or_else(|| HttpServerResultError::CmdNotFound {
|
||||
cmd: name.to_string(),
|
||||
})?,
|
||||
))
|
||||
}
|
||||
|
||||
@@ -23,6 +23,8 @@ pub enum HttpServerResultError {
|
||||
PanelUuidNotFound { uuid: Uuid },
|
||||
#[error(transparent)]
|
||||
Command(#[from] crate::command::error::Error),
|
||||
#[error("Command Not Found: {cmd}")]
|
||||
CmdNotFound { cmd: String },
|
||||
}
|
||||
|
||||
impl ResponseError for HttpServerResultError {
|
||||
@@ -36,6 +38,7 @@ impl ResponseError for HttpServerResultError {
|
||||
HttpServerResultError::InternalError { .. } => StatusCode::INTERNAL_SERVER_ERROR,
|
||||
HttpServerResultError::PanelUuidNotFound { .. } => StatusCode::NOT_FOUND,
|
||||
HttpServerResultError::Command(inner) => inner.status_code(),
|
||||
HttpServerResultError::CmdNotFound { .. } => StatusCode::NOT_FOUND,
|
||||
}
|
||||
}
|
||||
fn error_response(&self) -> HttpResponse {
|
||||
|
||||
Reference in New Issue
Block a user