Skip to content

Commit

Permalink
I deserve that nasa applause now
Browse files Browse the repository at this point in the history
  • Loading branch information
strawmelonjuice committed Aug 16, 2024
1 parent 8089571 commit f7d5a6f
Show file tree
Hide file tree
Showing 5 changed files with 38 additions and 14 deletions.
16 changes: 13 additions & 3 deletions source/Main/externalpluginservers.rs
Original file line number Diff line number Diff line change
Expand Up @@ -96,9 +96,19 @@ struct EPSResponse {
#[serde(tag = "as")]
pub(crate) enum EPSResponseBody {
NoneOk,
OkString { value: String },
Json { value: String },
Error { message: Option<String> },
WebResponse {
append_headers: Vec<(String, String)>,
response_body: String,
},
OkString {
value: String,
},
Json {
value: String,
},
Error {
message: Option<String>,
},
Disabled,
}

Expand Down
10 changes: 10 additions & 0 deletions source/Main/requestresponse.rs
Original file line number Diff line number Diff line change
Expand Up @@ -81,6 +81,16 @@ pub(crate) async fn serve(
)
.await;
match pluginsresponse {
crate::externalpluginservers::EPSResponseBody::WebResponse {
append_headers,
response_body,
} => {
let mut response = HttpResponse::build(actix_web::http::StatusCode::OK);
for (k, v) in append_headers {
response.append_header((k, v));
}
return response.body(response_body);
}
crate::externalpluginservers::EPSResponseBody::NoneOk => {}
crate::externalpluginservers::EPSResponseBody::Disabled => {}
_ => return HttpResponse::InternalServerError().body("Internal server error."),
Expand Down
19 changes: 13 additions & 6 deletions source/Plugin-runners/node-plugin-api/main.ts
Original file line number Diff line number Diff line change
Expand Up @@ -161,7 +161,7 @@ export interface WebResponse {
id: number;
body: {
as: "WebResponse";
append_headers: Record<string, string>;
append_headers: Array<[string, string]>;
response_body: string;
};
}
Expand Down Expand Up @@ -222,7 +222,7 @@ export const Cynthia = {
console: terminalOut,
};
export interface ResponderResponse {
headers: Record<string, string>;
headers: Array<[string, string]>;
body: string;
}
export type Responder = () => ResponderResponse;
Expand All @@ -249,18 +249,18 @@ export interface IncomingWebRequest {
for: "WebRequest";
method: string;
uri: string;
headers: Record<string, string>;
headers: Array<[string, string]>;
};
}
export class WebRequest {
private id: number;
private method: string;
uri: string;
headers: Record<string, string>;
headers: Array<[string, string]>;
private respondand: boolean;
constructor(
id: number,
a: { method: string; uri: string; headers: Record<string, string> },
a: { method: string; uri: string; headers: Array<[string, string]> },
) {
this.id = id;
this.method = a.method;
Expand All @@ -284,7 +284,6 @@ export class WebRequest {
Cynthia.send(response);
}
private matchUris(str: string, rule: string) {
Cynthia.console.info(`matchUris: '${str}'; '${rule}'`);
if (str === rule) return true;

// biome-ignore lint/style/noVar: This is a regex, not a variable
Expand Down Expand Up @@ -316,4 +315,12 @@ export class WebRequest {
this.respond(responder);
}
}
escalate() {
if (this.stillResponding()) {
this.respondand = true;
const response = new EmptyOKResponse(this.id);
return Cynthia.send(response);
}
return;
}
}
4 changes: 1 addition & 3 deletions source/Plugin-runners/node-plugin-runner/src/handler.ts
Original file line number Diff line number Diff line change
Expand Up @@ -45,9 +45,7 @@ export default async function handle(buffer: Buffer, cynthiabase: PluginBase) {
modifier(req, CynthiaPassed);
}

// Until this is implemented, we will just return EmptyOk.
const response = new EmptyOKResponse(request.id);
return Cynthia.send(response);
return req.escalate();
}
case "PostlistRenderRequest": {
try {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -45,9 +45,8 @@ export const newPluginBase: PluginBase = {
},
(req: WebRequest, Cynthia: typeof CynthiaPassed) => {
req.get("/pltest*", () => {
Cynthia.console.info("Request for /pltest received!");
const a: ResponderResponse = {
headers: {},
headers: [],
body: "This is a test response.",
};
return a;
Expand Down

0 comments on commit f7d5a6f

Please sign in to comment.