From c1012dcd998ed43e3550599274a99fc0cb02a561 Mon Sep 17 00:00:00 2001 From: Saoud Rizwan <7799382+saoudrizwan@users.noreply.github.com> Date: Sat, 10 Aug 2024 03:28:52 -0400 Subject: [PATCH] Clean up util functions --- src/providers/ClaudeDevProvider.ts | 37 +----------------------------- src/utils/index.ts | 4 ++++ 2 files changed, 5 insertions(+), 36 deletions(-) create mode 100644 src/utils/index.ts diff --git a/src/providers/ClaudeDevProvider.ts b/src/providers/ClaudeDevProvider.ts index 0459105..60dac29 100644 --- a/src/providers/ClaudeDevProvider.ts +++ b/src/providers/ClaudeDevProvider.ts @@ -1,12 +1,9 @@ import * as vscode from "vscode" -import { Uri, Webview } from "vscode" import { ClaudeDev } from "../ClaudeDev" import { ApiProvider } from "../shared/api" import { ExtensionMessage } from "../shared/ExtensionMessage" import { WebviewMessage } from "../shared/WebviewMessage" -import { downloadTask } from "../utils/export-markdown" -import { selectImages } from "../utils/process-images" - +import { downloadTask, getNonce, getUri, selectImages } from "../utils" /* https://github.com/microsoft/vscode-webview-ui-toolkit-samples/blob/main/default/weather-webview/src/providers/WeatherViewProvider.ts @@ -500,35 +497,3 @@ export class ClaudeDevProvider implements vscode.WebviewViewProvider { return await this.context.secrets.get(key) } } - -/** - * A helper function that returns a unique alphanumeric identifier called a nonce. - * - * @remarks This function is primarily used to help enforce content security - * policies for resources/scripts being executed in a webview context. - * - * @returns A nonce - */ -export function getNonce() { - let text = "" - const possible = "ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz0123456789" - for (let i = 0; i < 32; i++) { - text += possible.charAt(Math.floor(Math.random() * possible.length)) - } - return text -} - -/** - * A helper function which will get the webview URI of a given file or resource. - * - * @remarks This URI can be used within a webview's HTML as a link to the - * given file/resource. - * - * @param webview A reference to the extension webview - * @param extensionUri The URI of the directory containing the extension - * @param pathList An array of strings representing the path to a file/resource - * @returns A URI pointing to the file/resource - */ -export function getUri(webview: Webview, extensionUri: Uri, pathList: string[]) { - return webview.asWebviewUri(Uri.joinPath(extensionUri, ...pathList)) -} diff --git a/src/utils/index.ts b/src/utils/index.ts new file mode 100644 index 0000000..50e1c47 --- /dev/null +++ b/src/utils/index.ts @@ -0,0 +1,4 @@ +export * from "./getNonce" +export * from "./getUri" +export * from "./process-images" +export * from "./export-markdown"