Skip to content

Commit e025685

Browse files
committed
feat: prevent rapid submissions
1 parent 48fc373 commit e025685

2 files changed

Lines changed: 10 additions & 1 deletion

File tree

locales.ts

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -7,6 +7,7 @@ const en = {
77
'notice.alreadyCheckedIn': 'Already checked in today',
88
'notice.editorUnavailable': 'Editor instance not available',
99
'notice.onlyCheckInInEditMode': 'Please switch to edit mode to check in.',
10+
'notice.checkInTooFast': 'You are checking in too frequently. Please wait a moment before trying again.',
1011
'card.goalTitle': 'My Goal',
1112
'card.goalPlaceholder': 'Define your goal here!',
1213
'card.activityHistoryTitle': 'Activity History',
@@ -55,6 +56,7 @@ const zhCN: Record<LocaleKey, string> = {
5556
'notice.alreadyCheckedIn': '今天已经打卡了',
5657
'notice.editorUnavailable': '无法获取编辑器实例',
5758
'notice.onlyCheckInInEditMode': '请切换到编辑模式以进行打卡。',
59+
'notice.checkInTooFast': '你打卡得太频繁了,请稍等片刻再试。',
5860
'card.goalTitle': '我的目标',
5961
'card.goalPlaceholder': '在这里描述你的目标!',
6062
'card.activityHistoryTitle': '活动记录',

main.ts

Lines changed: 8 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -3,14 +3,14 @@ import CalendarHeatmap, { CalendarHeatmapOptions } from './calendar-heatmap/inde
33
import { hasTodayEntry, insertTodayEntry, parseEntries } from './utils';
44
import { computeDailyOverview, renderDailyOverview, updateDailyOverview } from './daily-overview';
55
import { createTranslator, isLanguageSetting, LanguageSetting, LocaleCode, LocaleKey, resolveLocale, Translator } from './locales';
6-
import { BlobOptions } from 'buffer';
76

87
export default class MyPlugin extends Plugin {
98
settings: MyPluginSettings;
109
private heatmaps: CalendarHeatmap[] = [];
1110
private overviewBlocks: HTMLElement[] = [];
1211
private locale: LocaleCode = 'en';
1312
private translator: Translator = createTranslator('en');
13+
private lastCheckInTime: number = 0;
1414

1515
public t(key: LocaleKey, vars?: Record<string, string | number>): string {
1616
return this.translator(key, vars);
@@ -60,6 +60,13 @@ export default class MyPlugin extends Plugin {
6060

6161
// Safely insert today's entry with a value (prevents duplicates)
6262
private insertEntry(value: number): boolean {
63+
const now = Date.now();
64+
if (now - this.lastCheckInTime < 1000) {
65+
new Notice(this.t('notice.checkInTooFast'));
66+
return false;
67+
}
68+
this.lastCheckInTime = now;
69+
6370
const view = this.getActiveMarkdownView();
6471
if (!view) return false;
6572

0 commit comments

Comments
 (0)