Clean up util functions

This commit is contained in:
Saoud Rizwan
2024-08-10 03:28:52 -04:00
parent 71b226b5c4
commit c1012dcd99
2 changed files with 5 additions and 36 deletions

View File

@@ -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))
}

4
src/utils/index.ts Normal file
View File

@@ -0,0 +1,4 @@
export * from "./getNonce"
export * from "./getUri"
export * from "./process-images"
export * from "./export-markdown"