瀏覽代碼

refactor: remove /rates endpoint

Co-Authored-By: Claude Opus 4.6 <noreply@anthropic.com>
kotoyuuko 3 天之前
父節點
當前提交
566cbacf3d
共有 2 個文件被更改,包括 2 次插入79 次删除
  1. 0 25
      README.md
  2. 2 54
      src/index.ts

+ 0 - 25
README.md

@@ -90,7 +90,6 @@ wrangler secret put NOTION_DATABASE_ID
 |----------|--------|-------------|
 | `/` | GET | Info page |
 | `/convert` | GET | Convert currency |
-| `/rates` | GET | Get exchange rates |
 | `/sync` | GET | Sync rates to Notion |
 
 ### Convert Currency
@@ -117,30 +116,6 @@ Response:
 }
 ```
 
-### Get Exchange Rates
-
-```bash
-GET /rates?base=USD
-```
-
-Parameters:
-- `base` - Base currency (default: USD)
-
-Response:
-```json
-{
-  "base": "USD",
-  "timestamp": 1773900000000,
-  "rates": {
-    "AED": 3.6725,
-    "CNY": 6.9002,
-    "EUR": 0.9175,
-    "JPY": 149.85,
-    ...
-  }
-}
-```
-
 ### Manual Sync to Notion
 
 ```bash

+ 2 - 54
src/index.ts

@@ -354,65 +354,13 @@ export default {
       });
     }
 
-    // Rates endpoint - get all rates from Notion database
-    if (url.pathname === '/rates') {
-      const base = url.searchParams.get('base') || 'USD';
-
-      try {
-        const ratesData = await getRatesFromNotion(env);
-
-        // If base is USD, return as-is
-        if (base.toUpperCase() === 'USD') {
-          return new Response(
-            JSON.stringify(ratesData, null, 2),
-            { headers: { 'Content-Type': 'application/json' } }
-          );
-        }
-
-        // Otherwise, recalculate rates for the new base
-        const baseRate = ratesData.rates[base.toUpperCase()];
-        if (!baseRate) {
-          return new Response(
-            JSON.stringify({ error: `Unknown currency: ${base}` }),
-            { status: 400, headers: { 'Content-Type': 'application/json' } }
-          );
-        }
-
-        const convertedRates: Record<string, number> = {};
-        for (const [currency, rate] of Object.entries(ratesData.rates)) {
-          convertedRates[currency] = rate / baseRate;
-        }
-        convertedRates['USD'] = 1 / baseRate;
-
-        return new Response(
-          JSON.stringify(
-            {
-              base: base.toUpperCase(),
-              timestamp: ratesData.timestamp,
-              rates: convertedRates,
-            },
-            null,
-            2
-          ),
-          { headers: { 'Content-Type': 'application/json' } }
-        );
-      } catch (error) {
-        const errorMessage = error instanceof Error ? error.message : String(error);
-        return new Response(
-          JSON.stringify({ error: errorMessage }),
-          { status: 500, headers: { 'Content-Type': 'application/json' } }
-        );
-      }
-    }
-
     // Home page
     return new Response(
       `Notion Exchange Rate Worker
 
 API Endpoints:
-  GET /convert?from=USD&to=CNY&amount=100  - Convert currency (data from Notion)
-  GET /rates?base=USD                      - Get exchange rates (data from Notion)
-  GET /sync                                - Sync rates from OXR to Notion`,
+  GET /convert?from=USD&to=CNY&amount=100  - Convert currency
+  GET /sync                                - Sync rates to Notion`,
       { headers: { 'Content-Type': 'text/plain' } }
     );
   },