feat: static getShorten (WebEmbed)

This commit is contained in:
March 7th 2022-11-12 17:56:42 +07:00
parent 41f414b13a
commit bd48db3f8c

View File

@ -371,16 +371,15 @@ class WebEmbed {
} }
const fullURL = `${this.baseURL}${arrayQuery.join('&')}`; const fullURL = `${this.baseURL}${arrayQuery.join('&')}`;
if (this.shorten) { if (this.shorten) {
const url = await getShorten(fullURL, this); const url = await this.constructor.getShorten(fullURL, this);
if (!url) console.log('Cannot shorten URL in WebEmbed'); if (!url) console.log('Cannot shorten URL in WebEmbed');
return this.hidden ? `${hiddenCharter} ${url || fullURL}` : url || fullURL; return this.hidden ? `${hiddenCharter} ${url || fullURL}` : url || fullURL;
} else { } else {
return this.hidden ? `${hiddenCharter} ${fullURL}` : fullURL; return this.hidden ? `${hiddenCharter} ${fullURL}` : fullURL;
} }
} }
}
const getShorten = async (url, embed) => { static async getShorten(url, embed) {
const APIurl = ['https://tinyurl.com/api-create.php?url=']; const APIurl = ['https://tinyurl.com/api-create.php?url='];
const shorten = `${ const shorten = `${
embed.shortenAPI && typeof embed.shortenAPI == 'string' embed.shortenAPI && typeof embed.shortenAPI == 'string'
@ -395,7 +394,8 @@ const getShorten = async (url, embed) => {
} catch { } catch {
return undefined; return undefined;
} }
}; }
}
module.exports = WebEmbed; module.exports = WebEmbed;
module.exports.hiddenEmbed = hiddenCharter; module.exports.hiddenEmbed = hiddenCharter;