mirror of
https://gitdab.com/cadence/out-of-your-element.git
synced 2025-09-11 04:33:02 +02:00
Remove node-fetch
This commit is contained in:
parent
7782c120bf
commit
984d4362a5
14 changed files with 30 additions and 131 deletions
|
@ -1,10 +1,8 @@
|
|||
// @ts-check
|
||||
|
||||
const assert = require("assert")
|
||||
const fetch = require("node-fetch").default
|
||||
|
||||
const utils = require("../converters/utils")
|
||||
const {Readable} = require("stream")
|
||||
const {sync} = require("../../passthrough")
|
||||
const assert = require("assert").strict
|
||||
|
||||
/** @type {import("../converters/emoji-sheet")} */
|
||||
const emojiSheetConverter = sync.require("../converters/emoji-sheet")
|
||||
|
@ -18,16 +16,16 @@ const api = sync.require("../../matrix/api")
|
|||
*/
|
||||
async function getAndConvertEmoji(mxc) {
|
||||
const abortController = new AbortController()
|
||||
/** @type {import("node-fetch").Response} */
|
||||
// If it turns out to be a GIF, we want to abandon the connection without downloading the whole thing.
|
||||
// If we were using connection pooling, we would be forced to download the entire GIF.
|
||||
// So we set no agent to ensure we are not connection pooling.
|
||||
// @ts-ignore the signal is slightly different from the type it wants (still works fine)
|
||||
const res = await api.getMedia(mxc, {agent: false, signal: abortController.signal})
|
||||
return emojiSheetConverter.convertImageStream(res.body, () => {
|
||||
const res = await api.getMedia(mxc, {signal: abortController.signal})
|
||||
// @ts-ignore
|
||||
const readable = Readable.fromWeb(res.body)
|
||||
return emojiSheetConverter.convertImageStream(readable, () => {
|
||||
abortController.abort()
|
||||
res.body.pause()
|
||||
res.body.emit("end")
|
||||
readable.emit("end")
|
||||
readable.on("error", () => {}) // DOMException [AbortError]: This operation was aborted
|
||||
})
|
||||
}
|
||||
|
||||
|
|
|
@ -5,7 +5,6 @@ const DiscordTypes = require("discord-api-types/v10")
|
|||
const {Readable} = require("stream")
|
||||
const assert = require("assert").strict
|
||||
const crypto = require("crypto")
|
||||
const fetch = require("node-fetch").default
|
||||
const passthrough = require("../../passthrough")
|
||||
const {sync, discord, db, select} = passthrough
|
||||
|
||||
|
|
|
@ -48,7 +48,7 @@ async function compositeMatrixEmojis(mxcs, mxcDownloader) {
|
|||
}
|
||||
|
||||
/**
|
||||
* @param {import("node-fetch").Response["body"]} streamIn
|
||||
* @param {NodeJS.ReadableStream} streamIn
|
||||
* @param {() => any} stopStream
|
||||
* @returns {Promise<Buffer | undefined>} Uncompressed PNG image
|
||||
*/
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue