mirror of
https://github.com/xCyanGrizzly/DragonsStash.git
synced 2026-05-11 06:11:15 +00:00
fix: auto-create READER links when enabling a source channel
All checks were successful
continuous-integration/drone/push Build is passing
All checks were successful
continuous-integration/drone/push Build is passing
toggleChannelActive only flipped isActive but never created the AccountChannelMap READER link needed by the worker. Channels enabled via the toggle (rather than the channel picker) were invisible to the scanner. Now auto-creates READER links for all active authenticated accounts when a SOURCE channel is enabled. Also ran a one-time DB fix to backfill READER links for the 14 active channels that were missing them. Co-Authored-By: Claude Opus 4.6 (1M context) <noreply@anthropic.com>
This commit is contained in:
@@ -231,11 +231,35 @@ export async function toggleChannelActive(id: string): Promise<ActionResult> {
|
|||||||
const existing = await prisma.telegramChannel.findUnique({ where: { id } });
|
const existing = await prisma.telegramChannel.findUnique({ where: { id } });
|
||||||
if (!existing) return { success: false, error: "Channel not found" };
|
if (!existing) return { success: false, error: "Channel not found" };
|
||||||
|
|
||||||
|
const newActive = !existing.isActive;
|
||||||
|
|
||||||
try {
|
try {
|
||||||
await prisma.telegramChannel.update({
|
await prisma.telegramChannel.update({
|
||||||
where: { id },
|
where: { id },
|
||||||
data: { isActive: !existing.isActive },
|
data: { isActive: newActive },
|
||||||
});
|
});
|
||||||
|
|
||||||
|
// When enabling a SOURCE channel, auto-create READER links for all
|
||||||
|
// active authenticated accounts so the worker can scan it.
|
||||||
|
// Without this, toggling a channel active without going through the
|
||||||
|
// channel picker leaves it with no AccountChannelMap READER link.
|
||||||
|
if (newActive && existing.type === "SOURCE") {
|
||||||
|
const accounts = await prisma.telegramAccount.findMany({
|
||||||
|
where: { isActive: true, authState: "AUTHENTICATED" },
|
||||||
|
select: { id: true },
|
||||||
|
});
|
||||||
|
|
||||||
|
for (const account of accounts) {
|
||||||
|
try {
|
||||||
|
await prisma.accountChannelMap.create({
|
||||||
|
data: { accountId: account.id, channelId: id, role: "READER" },
|
||||||
|
});
|
||||||
|
} catch {
|
||||||
|
// Already linked — ignore unique constraint violation
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
revalidatePath(REVALIDATE_PATH);
|
revalidatePath(REVALIDATE_PATH);
|
||||||
return { success: true, data: undefined };
|
return { success: true, data: undefined };
|
||||||
} catch {
|
} catch {
|
||||||
|
|||||||
Reference in New Issue
Block a user