(request)
| 826 | } |
| 827 | |
| 828 | async fetch(request) { |
| 829 | const url = new URL(request.url); |
| 830 | |
| 831 | if (request.method !== "POST") { |
| 832 | return jsonResponse({ error: "Method not allowed" }, 405); |
| 833 | } |
| 834 | |
| 835 | let body; |
| 836 | |
| 837 | try { |
| 838 | body = await request.json(); |
| 839 | } catch { |
| 840 | return jsonResponse({ error: "Invalid request" }, 400); |
| 841 | } |
| 842 | |
| 843 | if (url.pathname === "/rate") { |
| 844 | return this.rate(body); |
| 845 | } |
| 846 | |
| 847 | if (url.pathname === "/dedupe/reserve") { |
| 848 | return this.reserve(body); |
| 849 | } |
| 850 | |
| 851 | if (url.pathname === "/dedupe/release") { |
| 852 | return this.release(body); |
| 853 | } |
| 854 | |
| 855 | if (url.pathname === "/idempotency/check") { |
| 856 | return this.idempotency(body, false); |
| 857 | } |
| 858 | |
| 859 | if (url.pathname === "/idempotency/bind") { |
| 860 | return this.idempotency(body, true); |
| 861 | } |
| 862 | |
| 863 | return jsonResponse({ error: "Not found" }, 404); |
| 864 | } |
| 865 | |
| 866 | async scheduleCleanup(expiresAt) { |
| 867 | const scheduledAt = await this.state.storage.getAlarm(); |
no test coverage detected