-
Notifications
You must be signed in to change notification settings - Fork 9
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
feat: Rate-limit image previews #1478
Conversation
/backport to stable5 |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Everything apart from rate-limiting looks and works fine 🙈
Should be fixed, somehow forgot to return the promise |
c8d2341
to
9d8265d
Compare
* @param url URL of the image | ||
*/ | ||
export function preloadImage(url: string): Promise<boolean> { | ||
const { resolve, promise } = Promise.withResolvers<boolean>() |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
https://caniuse.com/?search=promise.withresolvers
Should be polyfilled for now, until it has normal support?
// @ts-expect-error This does not exist outside of polyfill which this is doing
if (typeof Promise.withResolvers === 'undefined') {
if (window)
// @ts-expect-error This does not exist outside of polyfill which this is doing
window.Promise.withResolvers = function () {
let resolve, reject
const promise = new Promise((res, rej) => {
resolve = res
reject = rej
})
return { promise, resolve, reject }
};
}
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
it has normal support?
It already has, supported by every browser, also supported by Node - but we need to upgrade to LTS Node version 22.
Also: We already polyfill this for Nextcloud server, so the only problem here are the tests.
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>
Signed-off-by: Ferdinand Thiessen <opensource@fthiessen.de>
9d8265d
to
5cfd115
Compare
Image preloading should be rate limited, to not overload the server. Now it is set to max. 5 requests at the same time.