-
Notifications
You must be signed in to change notification settings - Fork 9
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Image preloading should be rate limited, to not overload the server. Now it is set to max. 5 requests at the same time. Signed-off-by: Ferdinand Thiessen <opensource@fthiessen.de>
- Loading branch information
Showing
5 changed files
with
77 additions
and
18 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,24 @@ | ||
/** | ||
* SPDX-FileCopyrightText: 2024 Nextcloud GmbH and Nextcloud contributors | ||
* SPDX-License-Identifier: AGPL-3.0-or-later | ||
*/ | ||
|
||
import PQueue from 'p-queue' | ||
|
||
const queue = new PQueue({ concurrency: 5 }) | ||
|
||
/** | ||
* Preload an image URL | ||
* @param url URL of the image | ||
*/ | ||
export function preloadImage(url: string): Promise<boolean> { | ||
const { resolve, promise } = Promise.withResolvers<boolean>() | ||
Check failure on line 15 in lib/utils/imagePreload.ts GitHub Actions / testlib/composables/preview.spec.ts > preview composable > previewURL > is reactive
|
||
queue.add(() => { | ||
const image = new Image() | ||
image.onerror = () => resolve(false) | ||
image.onload = () => resolve(true) | ||
image.src = url | ||
}) | ||
|
||
return promise | ||
} |
Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.
Oops, something went wrong.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters