diff --git a/functions/api/[[route]].ts b/functions/api/[[route]].ts index 899eb85..5241b60 100644 --- a/functions/api/[[route]].ts +++ b/functions/api/[[route]].ts @@ -4,6 +4,7 @@ import { Bot, InputFile, InputMediaBuilder } from 'grammy' import { Hono } from 'hono' import { env } from 'hono/adapter' import { handle } from 'hono/cloudflare-pages' +import { cors } from 'hono/cors' import { customAlphabet } from 'nanoid' const nanoid = customAlphabet('abcdefghijklmnopqrstuvwxyzABCDEFGHIJKLMNOPQRSTUVWXYZ1234567890', 8) @@ -28,6 +29,8 @@ app.onError((err, c) => { return c.json(newError500(), 500) }) +app.use('/api/*', cors()) + app.get('/api', (c) => { return c.text('Hello, Project Trans SuggestionBox!') }) @@ -72,7 +75,9 @@ app.post('/api/v1/suggestion', async (c) => { return c.json(newErrorFormat400(), 400) } - const msgs = [`意见箱收到新消息 #TN-${nanoid()}\n`] + const ticketNumber = `#TN-${nanoid()}` + + const msgs = [`意见箱收到新消息 ${ticketNumber}\n`] msgs.push(`${replaceHtmlTag(textContent)}\n`) contactContent && msgs.push( @@ -118,7 +123,7 @@ app.post('/api/v1/suggestion', async (c) => { else { await bot.api.sendMessage(TG_GROUP_ID, message, { parse_mode: 'HTML' }) } - return c.json(newSuccess()) + return c.json(newSuccess(ticketNumber)) } catch (error) { // TODO handle error diff --git a/functions/package.json b/functions/package.json index a82eaf3..8ef93ce 100644 --- a/functions/package.json +++ b/functions/package.json @@ -6,11 +6,11 @@ "deploy": "wrangler deploy --minify src/index.ts" }, "dependencies": { - "grammy": "^1.21.1", - "hono": "^4.0.8", + "grammy": "^1.35.0", + "hono": "^4.7.2", "nanoid": "^5.1.0" }, "devDependencies": { - "@cloudflare/workers-types": "^4.20240208.0" + "@cloudflare/workers-types": "^4.20250214.0" } } diff --git a/functions/wrangler.toml b/functions/wrangler.toml index 7722651..e4dba7c 100644 --- a/functions/wrangler.toml +++ b/functions/wrangler.toml @@ -1,5 +1,5 @@ name = "server" -compatibility_date = "2023-12-01" +compatibility_date = "2025-02-14" # [vars] # MY_VARIABLE = "production_value" diff --git a/pnpm-lock.yaml b/pnpm-lock.yaml index 7805a28..739896d 100644 --- a/pnpm-lock.yaml +++ b/pnpm-lock.yaml @@ -61,18 +61,18 @@ importers: functions: dependencies: grammy: - specifier: ^1.21.1 - version: 1.33.0 + specifier: ^1.35.0 + version: 1.35.0 hono: - specifier: ^4.0.8 - version: 4.6.13 + specifier: ^4.7.2 + version: 4.7.2 nanoid: specifier: ^5.1.0 version: 5.1.0 devDependencies: '@cloudflare/workers-types': - specifier: ^4.20240208.0 - version: 4.20241205.0 + specifier: ^4.20250214.0 + version: 4.20250214.0 packages: @@ -332,9 +332,6 @@ packages: '@clack/prompts@0.10.0': resolution: {integrity: sha512-H3rCl6CwW1NdQt9rE3n373t7o5cthPv7yUoxF2ytZvyvlJv89C5RYMJu83Hed8ODgys5vpBU0GKxIRG83jd8NQ==} - '@cloudflare/workers-types@4.20241205.0': - resolution: {integrity: sha512-pj1VKRHT/ScQbHOIMFODZaNAlJHQHdBSZXNIdr9ebJzwBff9Qz8VdqhbhggV7f+aUEh8WSbrsPIo4a+WtgjUvw==} - '@cloudflare/workers-types@4.20250214.0': resolution: {integrity: sha512-+M8oOFVbyXT5GeJrYLWMUGyPf5wGB4+k59PPqdedtOig7NjZ5r4S79wMdaZ/EV5IV8JPtZBSNjTKpDnNmfxjaQ==} @@ -867,8 +864,8 @@ packages: resolution: {integrity: sha512-lB05FkqEdUg2AA0xEbUz0SnkXT1LcCTa438W4IWTUh4hdOnVbQyOJ81OrDXsJk/LSiJHubgGEFoR5EHq1NsH1A==} engines: {node: ^18.18.0 || ^20.9.0 || >=21.1.0} - '@grammyjs/types@3.17.0': - resolution: {integrity: sha512-e8AR3xQwRAFX248E7Qw/7mIu1OzvoXloJzOBJVtuPKzzL7tGkn5trZAdZUBgGViVQg5ZwVS/x9N2nRrcyH/DfA==} + '@grammyjs/types@3.19.0': + resolution: {integrity: sha512-N0MS+RJG+AGSNuka1GWVj88oyK1oti4I0eQq6jGo4hic3P9MwFfnHjGQuIExZ3tlJUrZYwC/T7gk4Tu3+guJyg==} '@humanfs/core@0.19.1': resolution: {integrity: sha512-5DyQ4+1JEUzejeK1JGICcideyfUbGixgS9jNgex5nqkW+cY7WZhxBigmieN5Qnw9ZosSNVC9KQKyb+GUaGyKUA==} @@ -1672,15 +1669,6 @@ packages: supports-color: optional: true - debug@4.3.4: - resolution: {integrity: sha512-PRWFHuSU3eDtQJPvnNY7Jcket1j0t5OuOsFzPPzsekD52Zl8qUfFIPEiswXqIvHWGVHOgX+7G/vCNNhehwxfkQ==} - engines: {node: '>=6.0'} - peerDependencies: - supports-color: '*' - peerDependenciesMeta: - supports-color: - optional: true - debug@4.4.0: resolution: {integrity: sha512-6WTZ/IxCY/T6BALoZHaE4ctp9xm+Z5kY/pzYaCHRFeyVhojxlrm+46y68HA6hr0TcwEssoxNiDEUJQjfPZ/RYA==} engines: {node: '>=6.0'} @@ -2123,8 +2111,8 @@ packages: graceful-fs@4.2.11: resolution: {integrity: sha512-RbJ5/jmFcNNCcDV5o9eTnBLJ/HszWV0P73bc+Ff4nS/rJj+YaS6IGyiOL0VoBYX+l1Wrl3k63h/KrH+nhJ0XvQ==} - grammy@1.33.0: - resolution: {integrity: sha512-kvQuIBtiPcqNGntsVevjXYBMByIJ3PtOP7swr1zbCg6xY+dNX76f4VX5auKuJNI/sflexPr3L4wNwbTJHu9ocA==} + grammy@1.35.0: + resolution: {integrity: sha512-Qlu5kVaekL4w5clWSpQcRxwJJoEeU13g8DTALuNbZsDAJuFJNXBuI8EqR6U1m1of7j9NEMQz59sXu+0/KsKjyg==} engines: {node: ^12.20.0 || >=14.13.1} graphemer@1.4.0: @@ -2175,8 +2163,8 @@ packages: hastscript@9.0.0: resolution: {integrity: sha512-jzaLBGavEDKHrc5EfFImKN7nZKKBdSLIdGvCwDZ9TfzbF2ffXiov8CKE445L2Z1Ek2t/m4SKQ2j6Ipv7NyUolw==} - hono@4.6.13: - resolution: {integrity: sha512-haV0gaMdSjy9URCRN9hxBPlqHa7fMm/T72kAImIxvw4eQLbNz1rgjN4hHElLJSieDiNuiIAXC//cC6YGz2KCbg==} + hono@4.7.2: + resolution: {integrity: sha512-8V5XxoOF6SI12jkHkzX/6aLBMU5GEF5g387EjVSQipS0DlxWgWGSMeEayY3CRBjtTUQYwLHx9JYouWqKzy2Vng==} engines: {node: '>=16.9.0'} hookable@5.5.3: @@ -2633,9 +2621,6 @@ packages: resolution: {integrity: sha512-Y3wQdFg2Va6etvQ5I82yUhGdsKrcYox6p7FfL1LbK2J4V01F9TGlepTIhnK24t7koZibmg82KGglhA1XK5IsLQ==} engines: {node: '>=10'} - ms@2.1.2: - resolution: {integrity: sha512-sGkPx+VjMtmA6MX27oA4FBFELFCZZ4S4XqeGOXCv68tT+jb3vk/RyaKWP0PTKyWtmLSM0b+adUTEvbs1PEaH2w==} - ms@2.1.3: resolution: {integrity: sha512-6FlzubTLZG3J2a/NVCAleEhjzq5oxgHyaCU9yYXvcLsvoVaHJq/s5xXI6/XXP6tz7R9xAOtHnSO/tXtF3WRTlA==} @@ -3780,8 +3765,6 @@ snapshots: picocolors: 1.1.1 sisteransi: 1.0.5 - '@cloudflare/workers-types@4.20241205.0': {} - '@cloudflare/workers-types@4.20250214.0': {} '@docsearch/css@3.8.2': {} @@ -4111,7 +4094,7 @@ snapshots: '@eslint/core': 0.10.0 levn: 0.4.1 - '@grammyjs/types@3.17.0': {} + '@grammyjs/types@3.19.0': {} '@humanfs/core@0.19.1': {} @@ -5035,10 +5018,6 @@ snapshots: dependencies: ms: 2.1.3 - debug@4.3.4: - dependencies: - ms: 2.1.2 - debug@4.4.0: dependencies: ms: 2.1.3 @@ -5627,11 +5606,11 @@ snapshots: graceful-fs@4.2.11: {} - grammy@1.33.0: + grammy@1.35.0: dependencies: - '@grammyjs/types': 3.17.0 + '@grammyjs/types': 3.19.0 abort-controller: 3.0.0 - debug: 4.3.4 + debug: 4.4.0 node-fetch: 2.7.0 transitivePeerDependencies: - encoding @@ -5739,7 +5718,7 @@ snapshots: property-information: 6.5.0 space-separated-tokens: 2.0.2 - hono@4.6.13: {} + hono@4.7.2: {} hookable@5.5.3: {} @@ -6378,8 +6357,6 @@ snapshots: mrmime@2.0.1: {} - ms@2.1.2: {} - ms@2.1.3: {} nanoid@3.3.8: {}