fix: enhance URL handling in refreshAttachmentURL and improve error handling in DataResolver
This commit is contained in:
@@ -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 },
|
||||
});
|
||||
|
||||
@@ -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) => {
|
||||
|
||||
Reference in New Issue
Block a user