close
Skip to content
Draft
Show file tree
Hide file tree
Changes from 1 commit
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Prev Previous commit
Next Next commit
[-] node-fetch => axios
  • Loading branch information
Doges committed Aug 5, 2022
commit 77edb418d78b124b7fc7abe62667a221912a9361
73 changes: 71 additions & 2 deletions package-lock.json

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

2 changes: 1 addition & 1 deletion package.json
Original file line number Diff line number Diff line change
Expand Up @@ -6,10 +6,10 @@
"dependencies": {
"@sentry/node": "^6.13.2",
"@svgdotjs/svg.js": "^3.1.1",
"axios": "^0.27.2",
"dd-trace": "^1.4.1",
"express": "^4.17.1",
"morgan": "^1.10.0",
"node-fetch": "^2.6.0",
"sharp": "^0.29.1",
"svgdom": "^0.1.8",
"text-to-svg": "^3.1.5",
Expand Down
9 changes: 4 additions & 5 deletions src/Discord.js
Original file line number Diff line number Diff line change
@@ -1,27 +1,26 @@
const fetch = require('node-fetch')
const axios = require('axios')

const API_BASE_URL = 'https://discord.com/api/v10'
const CDN_BASE_URL = 'https://cdn.discordapp.com'

module.exports = class Discord {
static getWidget (guildId) {
return fetch(`${API_BASE_URL}/guilds/${guildId}/widget.json`).then(res => res.json())
return axios(`${API_BASE_URL}/guilds/${guildId}/widget.json`).then(res => res.data)
}

static getInvite (inviteCode) {
return fetch(`${API_BASE_URL}/invites/${inviteCode}?with_counts=true`).then(res => res.json())
return axios(`${API_BASE_URL}/invites/${inviteCode}?with_counts=true`).then(res => res.data)
}

static fetchBase64Image (iconUrl) {
return fetch(iconUrl).then(res => res.buffer()).then(buffer => buffer.toString('base64'))
return axios(iconUrl, { responseType: 'arraybuffer' }).then(res => Buffer.from(res.data, 'binary').toString('base64'))
}

static getIconUrl (guildId, iconId) {
return `${CDN_BASE_URL}/icons/${guildId}/${iconId}${iconId.startsWith('a_') ? '.gif' : '.jpg'}`
}

static getSplashUrl (guildId, splashId) {
console.log(`${CDN_BASE_URL}/splashes/${guildId}/${splashId}.jpg?size=480`)
return `${CDN_BASE_URL}/splashes/${guildId}/${splashId}.jpg?size=480`
}
}