mirror of
https://codeberg.org/SafeTwitch/safetwitch.git
synced 2024-12-23 05:42:59 -05:00
27 lines
No EOL
705 B
TypeScript
27 lines
No EOL
705 B
TypeScript
import { Router, Response, Request, NextFunction } from 'express'
|
|
|
|
const proxyRouter = Router();
|
|
|
|
proxyRouter.get('/img', async (req: Request, res: Response, next: NextFunction) => {
|
|
const imageUrl = req.query.imageUrl?.toString()
|
|
if(!imageUrl) return;
|
|
|
|
fetch(imageUrl).then((response) => {
|
|
response.body!.pipeTo(
|
|
new WritableStream({
|
|
start() {
|
|
response.headers.forEach((v, n) => res.setHeader(n, v));
|
|
},
|
|
write(chunk) {
|
|
res.write(chunk);
|
|
},
|
|
close() {
|
|
res.end();
|
|
},
|
|
})
|
|
);
|
|
})
|
|
.catch((err) => next(err))
|
|
})
|
|
|
|
export default proxyRouter |