The settings GET endpoint masks emailImapPass and ftpPass for security. The test endpoints and save handler were using these masked values, causing IMAP/FTP test failures and potentially overwriting real passwords. Now the test endpoints fall back to the DB-stored password when they receive the masked value, and the save handler strips masked passwords from the payload. Made-with: Cursor
31 lines
908 B
TypeScript
31 lines
908 B
TypeScript
import { NextRequest, NextResponse } from "next/server";
|
|
import { testFtpConnection } from "@/lib/ftp-watcher";
|
|
import { requireApiAuth, handleApiError } from "@/lib/api-auth";
|
|
import { prisma } from "@/lib/db";
|
|
|
|
const MASKED = "••••••••";
|
|
|
|
export async function POST(request: NextRequest) {
|
|
try {
|
|
await requireApiAuth();
|
|
const body = await request.json();
|
|
|
|
let pass = body.pass || "";
|
|
if (!pass || pass === MASKED) {
|
|
const settings = await prisma.appSettings.findUnique({ where: { id: "singleton" } });
|
|
pass = settings?.ftpPass || "";
|
|
}
|
|
|
|
const result = await testFtpConnection({
|
|
host: body.host,
|
|
port: body.port || 21,
|
|
user: body.user,
|
|
pass,
|
|
tls: body.tls ?? true,
|
|
incomingDir: body.incomingDir || "/incoming",
|
|
});
|
|
return NextResponse.json(result);
|
|
} catch (error) {
|
|
return handleApiError(error);
|
|
}
|
|
}
|