Skip to content

Commit

Permalink
Encode HTTP method and path in each filename
Browse files Browse the repository at this point in the history
To make the output directory a bit more human readable.
  • Loading branch information
oleavr committed Aug 11, 2019
1 parent 5dbe83b commit 07c7440
Showing 1 changed file with 13 additions and 1 deletion.
14 changes: 13 additions & 1 deletion bin/airspy.ts
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,7 @@ import {
IRequestHeadEvent,
IResponseEvent,
LogLevel,
RequestId,
TargetDevice,
} from "../lib";

Expand Down Expand Up @@ -134,6 +135,8 @@ class ConsoleUI implements IDelegate {

private pendingOperation: IPendingOperation | null = null;

private requests: Map<RequestId, string> = new Map<RequestId, string>();

private getOutputDirPromise: Promise<string> | null = null;
private getEventOutputStreamPromise: Promise<Writable> | null = null;

Expand Down Expand Up @@ -219,6 +222,9 @@ class ConsoleUI implements IDelegate {
private onRequestHead(event: IRequestHeadEvent): void {
const { id, method, path, headers } = event;

const description = method.toLowerCase().replace(/[^\w]/g, "-") + path.toLowerCase().replace(/[^\w]/g, "-");
this.requests.set(id, description);

this.printLines(inboundPrefix,
[
chalk.cyan(`[ID: ${id}] ${method} ${path}`),
Expand Down Expand Up @@ -381,7 +387,13 @@ class ConsoleUI implements IDelegate {

private async withNewlyCreatedFileFor(event: AgentEvent, suffix: string, write: (stream: Writable) => void): Promise<void> {
const id = event.id.toString().padStart(3, "0");
const description = event.type.replace(/[^\w]/g, "-");

let requestDescription = this.requests.get(event.id);
if (requestDescription === undefined) {
requestDescription = "unknown";
}
const eventDescription = event.type.replace(/[^\w]/g, "-");
const description = `${requestDescription}-${eventDescription}`;

const path = await this.getOutputPath(`${id}-${description}${suffix}`);

Expand Down

0 comments on commit 07c7440

Please sign in to comment.