From c9cc9114c32a5f1bd9e66aa089d9309a07588d54 Mon Sep 17 00:00:00 2001 From: streakingman Date: Tue, 4 Oct 2022 15:39:11 +0800 Subject: [PATCH] =?UTF-8?q?feat:=20=E9=85=8D=E7=BD=AE=E4=B8=8A=E4=BC=A0?= =?UTF-8?q?=E6=97=B6=E9=97=B4=E9=97=B4=E9=9A=94=E9=99=90=E5=88=B6?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- src/components/ConfigDialog.tsx | 26 +++++++++++++++++++++++--- src/utils.ts | 1 + 2 files changed, 24 insertions(+), 3 deletions(-) diff --git a/src/components/ConfigDialog.tsx b/src/components/ConfigDialog.tsx index cca9525..15cdf00 100644 --- a/src/components/ConfigDialog.tsx +++ b/src/components/ConfigDialog.tsx @@ -4,7 +4,7 @@ import classNames from 'classnames'; import { Icon, Sound, Theme } from '../themes/interface'; import { QRCodeCanvas } from 'qrcode.react'; import Bmob from 'hydrogen-js-sdk'; -import { captureElement } from '../utils'; +import { captureElement, LAST_UPLOAD_TIME_STORAGE_KEY } from '../utils'; import { copy } from 'clipboard'; const STORAGEKEY = 'customTheme'; @@ -261,6 +261,21 @@ export const ConfigDialog: FC<{ setConfigError(''); generateTheme() .then((theme) => { + // 五分钟能只能上传一次 + const lastUploadTime = localStorage.getItem( + LAST_UPLOAD_TIME_STORAGE_KEY + ); + if ( + lastUploadTime && + new Date().getTime() - Number(lastUploadTime) < + 1000 * 60 * 5 + ) { + setConfigError( + '五分钟内只能上传一次(用的人有点多十分抱歉😭),先保存预览看看效果把~' + ); + return; + } + const stringify = JSON.stringify(theme); localStorage.setItem(STORAGEKEY, stringify); const query = Bmob.Query('config'); @@ -271,9 +286,14 @@ export const ConfigDialog: FC<{ //@ts-ignore const link = `${location.origin}?customTheme=${res.objectId}`; setGenLink(link); + localStorage.setItem( + LAST_UPLOAD_TIME_STORAGE_KEY, + new Date().getTime().toString() + ); }) - .catch((e) => { - console.log(e); + .catch(({ error }) => { + setConfigError(error); + setGenLink(''); }); }) .catch((e) => { diff --git a/src/utils.ts b/src/utils.ts index 439b4fa..01375bf 100644 --- a/src/utils.ts +++ b/src/utils.ts @@ -3,6 +3,7 @@ import { getDefaultTheme } from './themes/default'; export const LAST_LEVEL_STORAGE_KEY = 'lastLevel'; export const LAST_SCORE_STORAGE_KEY = 'lastScore'; +export const LAST_UPLOAD_TIME_STORAGE_KEY = 'lastUploadTime'; export const DEFAULT_BGM_STORAGE_KEY = 'defaultBgm'; export const DEFAULT_TRIPLE_SOUND_STORAGE_KEY = 'defaultTripleSound'; export const DEFAULT_CLICK_SOUND_STORAGE_KEY = 'defaultClickSound';