| 58 | } |
| 59 | |
| 60 | async function encodeAndSign(source) { |
| 61 | if (!process.env.APIFY_SIGNING_TOKEN) { |
| 62 | return 'invalid-token'; |
| 63 | } |
| 64 | |
| 65 | if (working) { |
| 66 | return new Promise((resolve, reject) => { |
| 67 | queue.push(() => { |
| 68 | return getHash(source).then(resolve, reject); |
| 69 | }); |
| 70 | }); |
| 71 | } |
| 72 | |
| 73 | let res; |
| 74 | |
| 75 | try { |
| 76 | working = true; |
| 77 | res = await getHash(source); |
| 78 | |
| 79 | while (queue.length) { |
| 80 | await queue.shift()(); |
| 81 | } |
| 82 | } finally { |
| 83 | working = false; |
| 84 | } |
| 85 | |
| 86 | return res; |
| 87 | } |
| 88 | |
| 89 | module.exports = async function (code) { |
| 90 | if (process.env.CRAWLEE_DOCS_FAST) { |