diff --git a/README.md b/README.md index 00b5731..e8e4af0 100644 --- a/README.md +++ b/README.md @@ -46,7 +46,7 @@ I will make this more convenient later. - Inbox Name:: [[Inbox]] - API Key:: insert key you get from Telegram's bot system - {{[[TODO]]}} update the Telegram API key above - - Trusted Media Proxy:: https://telegram-cors-proxy.herokuapp.com + - Trusted Media Proxy:: https://telegroam-cors-proxy.herokuapp.com - Latest Update ID:: 5. Make a block with the text `{{[[roam/js]]}}`. diff --git a/telegroam.js b/telegroam.js index 2f877f2..1767682 100644 --- a/telegroam.js +++ b/telegroam.js @@ -548,36 +548,36 @@ roamAlphaAPI.util.generateUID() let lockPath = - `https://binary-semaphore.herokuapp.com/lock/${lockId}/${nonce}` - - let acquirePath = `${lockPath}/acquire` - let releasePath = `${lockPath}/release` - - for (;;) { - let result = - await fetch(acquirePath, { method: "POST" }) - - if (result.status === lockStatus.ok) { - currentLockPath = lockPath - - try { - return await action() - } finally { - console.log("telegroam: releasing lock") - currentLockPath = null - try { - await fetch(releasePath, { method: "POST" }) - } catch (e) { - console.error(e) - throw e + `https://roam-binary-semaphore.herokuapp.com/lock/${lockId}/${nonce}` + + let acquirePath = `${lockPath}` + let releasePath = `${lockPath}` + + for (;;) { + let result = + await fetch(acquirePath, { method: "PUT" }) + + if (result.status === lockStatus.ok) { + currentLockPath = lockPath + + try { + return await action() + } finally { + console.log("telegroam: releasing lock") + currentLockPath = null + try { + await fetch(releasePath, { method: "DELETE" }) + } catch (e) { + console.error(e) + throw e + } + } + + } else if (result.status === lockStatus.busy) { + console.log(`telegroam: lock busy; waiting ${waitSeconds}s`) + await sleep(waitSeconds) } - } - - } else if (result.status === lockStatus.busy) { - console.log(`telegroam: lock busy; waiting ${waitSeconds}s`) - await sleep(waitSeconds) } - } } async function updateFromTelegramContinuously() {