MCPcopy Create free account
hub / github.com/apify/crawlee-python / getHash

Function getHash

website/roa-loader/index.js:18–58  ·  view source on GitHub ↗
(source)

Source from the content-addressed store, hash-verified

16}
17
18async function getHash(source) {
19 const cacheKey = hash(source);
20
21 if (cache[cacheKey]) {
22 return cache[cacheKey];
23 }
24
25 const memory = source.match(/playwright|puppeteer/i) ? 4096 : 1024;
26 const res = await fetch(signingUrl, {
27 method: 'POST',
28 body: JSON.stringify({
29 input: JSON.stringify({ code: source }),
30 options: {
31 build: 'latest',
32 contentType: 'application/json; charset=utf-8',
33 memory,
34 timeout: 180,
35 },
36 }),
37 headers: {
38 'Content-Type': 'application/json; charset=utf-8',
39 },
40 });
41
42 if (!res.ok) {
43 console.error(`Signing failed: ${res.status} ${res.statusText}`, await res.text());
44 return 'invalid-token';
45 }
46
47 const body = await res.json();
48
49 if (!body.data || !body.data.encoded) {
50 console.error(`Signing failed:' ${inspect(body.error) || 'Unknown error'}`, body);
51 return 'invalid-token';
52 }
53
54 cache[cacheKey] = body.data.encoded;
55 await new Promise((resolve) => setTimeout(resolve, 100));
56
57 return body.data.encoded;
58}
59
60async function encodeAndSign(source) {
61 if (!process.env.APIFY_SIGNING_TOKEN) {

Callers 1

encodeAndSignFunction · 0.85

Calls 1

hashFunction · 0.85

Tested by

no test coverage detected