fix crontab task (#19)

This commit is contained in:
paisley
2026-02-09 18:59:21 +08:00
committed by GitHub
Unverified
parent 19ae5b0f75
commit 905b828e9b
2 changed files with 90 additions and 57 deletions

View File

@@ -208,6 +208,12 @@ function registerCronHandlers(gatewayManager: GatewayManager): void {
}) => {
try {
// Transform frontend input to Gateway cron.add format
// For Discord, the recipient must be prefixed with "channel:" or "user:"
const recipientId = input.target.channelId;
const deliveryTo = input.target.channelType === 'discord' && recipientId
? `channel:${recipientId}`
: recipientId;
const gatewayInput = {
name: input.name,
schedule: { kind: 'cron', expr: input.schedule },
@@ -218,6 +224,7 @@ function registerCronHandlers(gatewayManager: GatewayManager): void {
delivery: {
mode: 'announce',
channel: input.target.channelType,
to: deliveryTo,
},
};
const result = await gatewayManager.rpc('cron.add', gatewayInput);

View File

@@ -140,9 +140,11 @@ function TaskDialog({ job, onClose, onSave }: TaskDialogProps) {
const [customSchedule, setCustomSchedule] = useState('');
const [useCustom, setUseCustom] = useState(false);
const [channelId, setChannelId] = useState(job?.target.channelId || '');
const [discordChannelId, setDiscordChannelId] = useState('');
const [enabled, setEnabled] = useState(job?.enabled ?? true);
const selectedChannel = channels.find((c) => c.id === channelId);
const isDiscord = selectedChannel?.type === 'discord';
const handleSubmit = async () => {
if (!name.trim()) {
@@ -157,6 +159,11 @@ function TaskDialog({ job, onClose, onSave }: TaskDialogProps) {
toast.error('Please select a channel');
return;
}
// Validate Discord channel ID when Discord is selected
if (selectedChannel?.type === 'discord' && !discordChannelId.trim()) {
toast.error('Please enter a Discord Channel ID');
return;
}
const finalSchedule = useCustom ? customSchedule : schedule;
if (!finalSchedule.trim()) {
@@ -166,13 +173,18 @@ function TaskDialog({ job, onClose, onSave }: TaskDialogProps) {
setSaving(true);
try {
// For Discord, use the manually entered channel ID; for others, use empty
const actualChannelId = selectedChannel!.type === 'discord'
? discordChannelId.trim()
: '';
await onSave({
name: name.trim(),
message: message.trim(),
schedule: finalSchedule,
target: {
channelType: selectedChannel!.type,
channelId: selectedChannel!.id,
channelId: actualChannelId,
channelName: selectedChannel!.name,
},
enabled,
@@ -285,6 +297,20 @@ function TaskDialog({ job, onClose, onSave }: TaskDialogProps) {
)}
</div>
{/* Discord Channel ID - only shown when Discord is selected */}
{isDiscord && (
<div className="space-y-2">
<Label>Discord Channel ID</Label>
<Input
value={discordChannelId}
onChange={(e) => setDiscordChannelId(e.target.value)}
placeholder="e.g., 1438452657525100686"
/>
<p className="text-xs text-muted-foreground">
Right-click the Discord channel Copy Channel ID
</p>
</div>
)}
{/* Enabled */}
<div className="flex items-center justify-between">
<div>