远程遥控完成
This commit is contained in:
@@ -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),
|
||||
});
|
||||
}
|
||||
@@ -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 });
|
||||
}
|
||||
@@ -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 });
|
||||
}
|
||||
Reference in New Issue
Block a user