fix: enhance URL handling in refreshAttachmentURL and improve error handling in DataResolver

This commit is contained in:
Elysia
2024-12-29 21:43:28 +07:00
parent 9cfe153252
commit 053084d082
2 changed files with 10 additions and 2 deletions

View File

@@ -522,7 +522,14 @@ class Client extends BaseClient {
* @param {string[]} urls Discord CDN URLs
* @returns {Promise<Array<{ original: string, refreshed: string }>>}
*/
async refreshAttachmentURL(urls) {
async refreshAttachmentURL(urls = []) {
// Clean up the URLs
urls = urls.map(url => {
const urlObject = new URL(url);
// Clean query
urlObject.search = '';
return urlObject.toString();
});
const data = await this.api.attachments('refresh-urls').post({
data: { attachment_urls: urls },
});

View File

@@ -111,7 +111,8 @@ class DataResolver extends null {
if (typeof resource === 'string') {
if (/^https?:\/\//.test(resource)) {
const res = await fetch(resource);
return res.body;
if (res.ok) return res.body;
else throw new DiscordError('FILE_NOT_FOUND', resource);
}
return new Promise((resolve, reject) => {