From d86165d6807158bf13e5a5b166ce93cbce1a59a6 Mon Sep 17 00:00:00 2001 From: Eric Doughty-Papassideris Date: Wed, 25 Sep 2024 00:08:57 +0200 Subject: [PATCH] =?UTF-8?q?=E2=9C=A8=20cli:=20add=20`editing=5Fsession=20p?= =?UTF-8?q?arse`=20to=20output=20key=20information=20(#525)?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../cli/cmds/editing_session_cmds/parse.ts | 34 +++++++++++++++++++ 1 file changed, 34 insertions(+) create mode 100644 tdrive/backend/node/src/cli/cmds/editing_session_cmds/parse.ts diff --git a/tdrive/backend/node/src/cli/cmds/editing_session_cmds/parse.ts b/tdrive/backend/node/src/cli/cmds/editing_session_cmds/parse.ts new file mode 100644 index 00000000..5329a13a --- /dev/null +++ b/tdrive/backend/node/src/cli/cmds/editing_session_cmds/parse.ts @@ -0,0 +1,34 @@ +import yargs from "yargs"; + +import { NonPlatformCommandYargsBuilder } from "../../utils/non-plaform-command-yargs-builder"; +import { EditingSessionKeyFormat } from "../../../services/documents/entities/drive-file"; + +interface ParseArguments { + editing_session_key: string; +} + +const command: yargs.CommandModule = { + command: "parse ", + describe: ` + Parse the provided editing_session_key and output json data (to stderr) + `.trim(), + + builder: { + ...NonPlatformCommandYargsBuilder, + }, + handler: async argv => { + const args = argv as unknown as ParseArguments; + const parsed = EditingSessionKeyFormat.parse(decodeURIComponent("" + args.editing_session_key)); + console.error( + JSON.stringify( + { + ageH: (new Date().getTime() - parsed.timestamp.getTime()) / (60 * 60 * 1000), + ...parsed, + }, + null, + 2, + ), + ); + }, +}; +export default command;