远程遥控完成

This commit is contained in:
mtvpls
2026-05-30 22:34:07 +08:00
parent 30554fcd77
commit 3a030cce5a
13 changed files with 1036 additions and 88 deletions
+18
View File
@@ -0,0 +1,18 @@
import { NextRequest, NextResponse } from 'next/server';
import { getAuthInfoFromCookie } from '@/lib/auth';
const { listTVRemoteDevices } = require('@/lib/tv-remote-hub');
export const runtime = 'nodejs';
export async function GET(request: NextRequest) {
const authInfo = getAuthInfoFromCookie(request);
if (!authInfo?.username) {
return NextResponse.json({ error: '未登录' }, { status: 401 });
}
return NextResponse.json({
devices: listTVRemoteDevices(authInfo.username),
});
}
+33
View File
@@ -0,0 +1,33 @@
import { NextRequest, NextResponse } from 'next/server';
import { getAuthInfoFromCookie } from '@/lib/auth';
import type { TVRemoteKeyCommand } from '@/lib/tv-remote-types';
const { sendTVRemoteCommand } = require('@/lib/tv-remote-hub');
export const runtime = 'nodejs';
export async function POST(request: NextRequest) {
const authInfo = getAuthInfoFromCookie(request);
if (!authInfo?.username) {
return NextResponse.json({ error: '未登录' }, { status: 401 });
}
const body = await request.json().catch(() => null) as {
deviceId?: string;
command?: TVRemoteKeyCommand;
} | null;
if (!body?.deviceId || !body.command?.key) {
return NextResponse.json({ error: '参数不完整' }, { status: 400 });
}
const result = sendTVRemoteCommand(
authInfo.username,
body.deviceId,
'tv-remote:key',
body.command
);
return NextResponse.json(result, { status: result.success ? 200 : 404 });
}
+33
View File
@@ -0,0 +1,33 @@
import { NextRequest, NextResponse } from 'next/server';
import { getAuthInfoFromCookie } from '@/lib/auth';
import type { TVRemoteTextCommand } from '@/lib/tv-remote-types';
const { sendTVRemoteCommand } = require('@/lib/tv-remote-hub');
export const runtime = 'nodejs';
export async function POST(request: NextRequest) {
const authInfo = getAuthInfoFromCookie(request);
if (!authInfo?.username) {
return NextResponse.json({ error: '未登录' }, { status: 401 });
}
const body = await request.json().catch(() => null) as {
deviceId?: string;
command?: TVRemoteTextCommand;
} | null;
if (!body?.deviceId || !body.command?.mode) {
return NextResponse.json({ error: '参数不完整' }, { status: 400 });
}
const result = sendTVRemoteCommand(
authInfo.username,
body.deviceId,
'tv-remote:text',
body.command
);
return NextResponse.json(result, { status: result.success ? 200 : 404 });
}