1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
import { encodeHex } from "jsr:@std/encoding/hex"
// Retrieves the URL, and returns a hash of its contents.
export async function getHashForUrl(url: string): Promise<string> {
// Fetch the content from the URL
const response = await fetch(url);
if (!response.ok) {
throw new Error(`Failed to fetch URL: ${url}`);
}
const data = await response.arrayBuffer();
// Create a hash from the response data
const hash = await crypto.subtle.digest("SHA-256", data);
return encodeHex(hash);
}
Val Town is a social website to write and deploy JavaScript.
Build APIs and schedule functions from your browser.
Comments
Nobody has commented on this val yet: be the first!
April 4, 2024