fix: Custom cron input and auto-sync rescheduling
- Fixed custom cron input field to be properly editable with autoFocus - Added helpful cron examples and better validation feedback - Fixed cron validation to work with 5-field expressions (node-cron format) - Added auto-sync rescheduling when settings are saved via API route - Improved user experience with better error handling and examples The custom cron input now works properly and auto-sync will reschedule immediately when settings are saved, including custom cron expressions.
This commit is contained in:
@@ -885,6 +885,8 @@ export function GeneralSettingsModal({ isOpen, onClose }: GeneralSettingsModalPr
|
||||
value={syncIntervalCron}
|
||||
onChange={(e) => handleCronChange(e.target.value)}
|
||||
className="w-full"
|
||||
autoFocus
|
||||
onFocus={() => setCronValidationError('')}
|
||||
/>
|
||||
{cronValidationError && (
|
||||
<p className="text-sm text-red-500 mt-1">{cronValidationError}</p>
|
||||
@@ -896,6 +898,16 @@ export function GeneralSettingsModal({ isOpen, onClose }: GeneralSettingsModalPr
|
||||
</a>{' '}
|
||||
for examples
|
||||
</p>
|
||||
<div className="mt-2 p-2 bg-muted rounded text-xs">
|
||||
<p className="font-medium mb-1">Common examples:</p>
|
||||
<ul className="space-y-1 text-muted-foreground">
|
||||
<li>• <code>* * * * *</code> - Every minute</li>
|
||||
<li>• <code>0 * * * *</code> - Every hour</li>
|
||||
<li>• <code>0 */6 * * *</code> - Every 6 hours</li>
|
||||
<li>• <code>0 0 * * *</code> - Every day at midnight</li>
|
||||
<li>• <code>0 0 * * 0</code> - Every Sunday at midnight</li>
|
||||
</ul>
|
||||
</div>
|
||||
</div>
|
||||
)}
|
||||
</div>
|
||||
|
||||
@@ -71,7 +71,7 @@ export async function POST(request: NextRequest) {
|
||||
);
|
||||
}
|
||||
|
||||
if (!isValidCron(settings.syncIntervalCron)) {
|
||||
if (!isValidCron(settings.syncIntervalCron, { seconds: false })) {
|
||||
return NextResponse.json(
|
||||
{ error: 'Invalid cron expression' },
|
||||
{ status: 400 }
|
||||
@@ -158,6 +158,23 @@ export async function POST(request: NextRequest) {
|
||||
// Write back to .env file
|
||||
fs.writeFileSync(envPath, envContent);
|
||||
|
||||
// Reschedule auto-sync service with new settings
|
||||
try {
|
||||
const { AutoSyncService } = await import('../../../../server/services/autoSyncService.js');
|
||||
const autoSyncService = new AutoSyncService();
|
||||
|
||||
if (settings.autoSyncEnabled) {
|
||||
autoSyncService.scheduleAutoSync();
|
||||
console.log('Auto-sync rescheduled with new settings');
|
||||
} else {
|
||||
autoSyncService.stopAutoSync();
|
||||
console.log('Auto-sync stopped');
|
||||
}
|
||||
} catch (error) {
|
||||
console.error('Error rescheduling auto-sync service:', error);
|
||||
// Don't fail the request if rescheduling fails
|
||||
}
|
||||
|
||||
return NextResponse.json({
|
||||
success: true,
|
||||
message: 'Auto-sync settings saved successfully'
|
||||
|
||||
@@ -191,8 +191,8 @@ export class AutoSyncService {
|
||||
cronExpression = intervalMap[settings.syncIntervalPredefined] || '0 * * * *';
|
||||
}
|
||||
|
||||
// Validate cron expression
|
||||
if (!cronValidator.isValidCron(cronExpression)) {
|
||||
// Validate cron expression (5-field format for node-cron)
|
||||
if (!cronValidator.isValidCron(cronExpression, { seconds: false })) {
|
||||
console.error('Invalid cron expression:', cronExpression);
|
||||
return;
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user