完成80%

This commit is contained in:
2026-07-27 06:50:07 +08:00
parent 8475bbd19a
commit 1eae3bbef4
63 changed files with 13664 additions and 280 deletions
+7 -7
View File
@@ -9,16 +9,16 @@ const requireFunction = (value, name) => {
};
export const createAuthSmsCooldown = ({
sceneCode,
operationCode,
onChange,
now = Date.now,
setIntervalFn = setInterval,
clearIntervalFn = clearInterval,
}) => {
if (typeof sceneCode !== "string" || !sceneCode.trim()) {
throw new TypeError("sceneCode must be a non-empty string");
if (typeof operationCode !== "string" || !operationCode.trim()) {
throw new TypeError("operationCode must be a non-empty string");
}
const normalizedSceneCode = sceneCode.trim();
const normalizedOperationCode = operationCode.trim();
const publish = requireFunction(onChange, "onChange");
const readNow = requireFunction(now, "now");
const scheduleInterval = requireFunction(setIntervalFn, "setIntervalFn");
@@ -32,13 +32,13 @@ export const createAuthSmsCooldown = ({
};
const sync = () => {
const expiresAt = sceneExpiresAt.get(normalizedSceneCode) || 0;
const expiresAt = sceneExpiresAt.get(normalizedOperationCode) || 0;
const remaining = Math.max(
0,
Math.ceil((expiresAt - Number(readNow())) / 1000),
);
if (remaining === 0) {
sceneExpiresAt.delete(normalizedSceneCode);
sceneExpiresAt.delete(normalizedOperationCode);
stopTimer();
} else if (timer === null) {
timer = scheduleInterval(sync, 1000);
@@ -52,7 +52,7 @@ export const createAuthSmsCooldown = ({
throw new TypeError("cooldown seconds must be an integer from 1 to 300");
}
sceneExpiresAt.set(
normalizedSceneCode,
normalizedOperationCode,
Number(readNow()) + seconds * 1000,
);
return sync();