Better garbage collection?

This commit is contained in:
tamaina 2023-02-07 14:58:25 +00:00
parent 9b1da926e1
commit 0e741f928c
3 changed files with 13 additions and 5 deletions

View File

@ -158,8 +158,12 @@ async function proxyHandler(request, reply) {
if ('cleanup' in file) {
if ('pipe' in image.data && typeof image.data.pipe === 'function') {
// image.dataがstreamなら、stream終了後にcleanup
image.data.on('end', file.cleanup);
image.data.on('close', file.cleanup);
const cleanup = () => {
file.cleanup();
image = null;
};
image.data.on('end', cleanup);
image.data.on('close', cleanup);
}
else {
// image.dataがstreamでないなら直ちにcleanup

View File

@ -1,6 +1,6 @@
{
"name": "misskey-media-proxy",
"version": "0.0.5",
"version": "0.0.6",
"description": "The Media Proxy for Misskey",
"main": "built/index.js",
"packageManager": "pnpm@7.26.0",

View File

@ -204,8 +204,12 @@ async function proxyHandler(request: FastifyRequest<{ Params: { url: string; };
if ('cleanup' in file) {
if ('pipe' in image.data && typeof image.data.pipe === 'function') {
// image.dataがstreamなら、stream終了後にcleanup
image.data.on('end', file.cleanup);
image.data.on('close', file.cleanup);
const cleanup = () => {
file.cleanup();
image = null;
}
image.data.on('end', cleanup);
image.data.on('close', cleanup);
} else {
// image.dataがstreamでないなら直ちにcleanup
file.cleanup();