1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
import { Buffer } from "node:buffer";
import { createHash } from "node:crypto";
// 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 = createHash("sha256");
hash.update(Buffer.from(data));
return hash.digest("hex");
}
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