diff --git a/apps/server/.env b/apps/server/.env index 2895eb0a0..679d3684f 100644 --- a/apps/server/.env +++ b/apps/server/.env @@ -20,3 +20,8 @@ API_SERVER_URL="" GATEWAY_BASE_URL="http://localhost:18080" DEFAULT_CHAT_MODEL="openai/gpt-5-mini" DEFAULT_TTS_MODEL="microsoft/v1" + + +ASSETLINKS_PACKAGE_NAME="ai.moeru.airi_pocket" +ASSETLINKS_SHA256_FINGERPRINTS="1D:E5:2D:DC:89:DA:C9:C1:4B:5F:4A:48:E4:2D:62:E5:52:82:B7:41:D3:96:73:13:91:C8:41:D2:84:DF:84:55" + diff --git a/apps/server/src/app.ts b/apps/server/src/app.ts index 5b3d15483..c3caa5ade 100644 --- a/apps/server/src/app.ts +++ b/apps/server/src/app.ts @@ -48,6 +48,7 @@ import { createFluxRoutes } from './routes/flux' import { createV1CompletionsRoutes } from './routes/openai/v1' import { createProviderRoutes } from './routes/providers' import { createStripeRoutes } from './routes/stripe' +import { createWellKnownRoutes } from './routes/well-known' import { createBillingMq } from './services/billing/billing-events' import { createBillingService } from './services/billing/billing-service' import { createFluxMeter } from './services/billing/flux-meter' @@ -184,6 +185,7 @@ export async function buildApp(deps: AppDeps) { env: deps.env, configKV: deps.configKV, })) + .route('/.well-known', createWellKnownRoutes({ env: deps.env })) /** * Character routes are handled by the character service. diff --git a/apps/server/src/libs/env.ts b/apps/server/src/libs/env.ts index 54587a2f5..aebfcb118 100644 --- a/apps/server/src/libs/env.ts +++ b/apps/server/src/libs/env.ts @@ -89,6 +89,11 @@ const EnvSchema = object({ OTEL_EXPORTER_OTLP_ENDPOINT: optional(string()), OTEL_EXPORTER_OTLP_HEADERS: optional(string()), OTEL_DEBUG: optional(string()), + // Asset Links (Android deep link delegation) + // Example: ASSETLINKS_PACKAGE_NAME=com.example.app + // ASSETLINKS_SHA256_FINGERPRINTS=AB:CD:... ,EF:12:... + ASSETLINKS_PACKAGE_NAME: optional(string(), 'ai.moeru.airi_pocket'), + ASSETLINKS_SHA256_FINGERPRINTS: optional(string(), ''), }) export type Env = InferOutput diff --git a/apps/server/src/routes/well-known/index.ts b/apps/server/src/routes/well-known/index.ts new file mode 100644 index 000000000..75b9a8308 --- /dev/null +++ b/apps/server/src/routes/well-known/index.ts @@ -0,0 +1,34 @@ +import type { Env } from '../../libs/env' +import type { HonoEnv } from '../../types/hono' + +import { Hono } from 'hono' + +export interface WellKnownDeps { + env: Env +} + +export function createWellKnownRoutes(deps: WellKnownDeps) { + return new Hono() + .get('/assetlinks.json', (c) => { + const pkg = deps.env.ASSETLINKS_PACKAGE_NAME + const fingerprintsRaw = deps.env.ASSETLINKS_SHA256_FINGERPRINTS + + const fingerprints = fingerprintsRaw + .split(',') + .map(s => s.trim()) + .filter(Boolean) + + const payload = [ + { + relation: ['delegate_permission/common.handle_all_urls'], + target: { + namespace: 'android_app', + package_name: pkg, + sha256_cert_fingerprints: fingerprints, + }, + }, + ] + + return c.json(payload) + }) +}