From 83e0073134772b05f7b47eb1f379d0cbe3bec783 Mon Sep 17 00:00:00 2001 From: fyears <1142836+fyears@users.noreply.github.com> Date: Thu, 4 Apr 2024 21:58:52 +0800 Subject: [PATCH] remove dep on delay lib --- package.json | 1 - src/misc.ts | 10 +++++++++- src/remoteForDropbox.ts | 5 +++-- 3 files changed, 12 insertions(+), 4 deletions(-) diff --git a/package.json b/package.json index 98be03d..87ba612 100644 --- a/package.json +++ b/package.json @@ -72,7 +72,6 @@ "aws-crt": "^1.20.0", "buffer": "^6.0.3", "crypto-browserify": "^3.12.0", - "delay": "^6.0.0", "dropbox": "^10.34.0", "emoji-regex": "^10.3.0", "http-status-codes": "^2.3.0", diff --git a/src/misc.ts b/src/misc.ts index 39121d2..f19954d 100644 --- a/src/misc.ts +++ b/src/misc.ts @@ -513,6 +513,14 @@ export const stringToFragment = (string: string) => { return wrapper.content; }; +/** + * https://stackoverflow.com/questions/39538473/using-settimeout-on-promise-chain + * @param ms + * @returns + */ +export const delay = (ms: number) => + new Promise((resolve) => setTimeout(resolve, ms)); + /** * https://forum.obsidian.md/t/css-to-show-status-bar-on-mobile-devices/77185 * @param op @@ -550,7 +558,7 @@ export const changeMobileStatusBar = ( k.className.contains("mobile-toolbar") ) { // have to wait, otherwise the height is not correct?? - await new Promise((resolve) => setTimeout(resolve, 300)); + await delay(300); const height = window .getComputedStyle(k as Element) .getPropertyValue("height"); diff --git a/src/remoteForDropbox.ts b/src/remoteForDropbox.ts index c21e147..1c0ab9e 100644 --- a/src/remoteForDropbox.ts +++ b/src/remoteForDropbox.ts @@ -1,4 +1,3 @@ -import { rangeDelay } from "delay"; import { Dropbox, DropboxAuth } from "dropbox"; import type { files, DropboxResponseError, DropboxResponse } from "dropbox"; import { Vault } from "obsidian"; @@ -12,6 +11,7 @@ import { } from "./baseTypes"; import { bufferToArrayBuffer, + delay, fixEntityListCasesInplace, getFolderLevels, hasEmojiInText, @@ -19,6 +19,7 @@ import { mkdirpInVault, } from "./misc"; import { Cipher } from "./encryptUnified"; +import { random } from "lodash"; export { Dropbox } from "dropbox"; @@ -292,7 +293,7 @@ async function retryReq( 2 )}` ); - await rangeDelay(secMin * 1000, secMax * 1000); + await delay(random(secMin * 1000, secMax * 1000)); } } }