forked from mirror/misskey
good cleanup
This commit is contained in:
parent
922c5930d6
commit
a0b3bb2117
@ -167,6 +167,12 @@ export class FileServerService {
|
|||||||
};
|
};
|
||||||
|
|
||||||
const image = await convertFile();
|
const image = await convertFile();
|
||||||
|
|
||||||
|
if (typeof image.data === 'object' && 'pipe' in image.data && typeof image.data.pipe === 'function') {
|
||||||
|
image.data.on('end', file.cleanup);
|
||||||
|
image.data.on('close', file.cleanup);
|
||||||
|
}
|
||||||
|
|
||||||
reply.header('Content-Type', FILE_TYPE_BROWSERSAFE.includes(image.type) ? image.type : 'application/octet-stream');
|
reply.header('Content-Type', FILE_TYPE_BROWSERSAFE.includes(image.type) ? image.type : 'application/octet-stream');
|
||||||
reply.header('Cache-Control', 'max-age=31536000, immutable');
|
reply.header('Cache-Control', 'max-age=31536000, immutable');
|
||||||
return image.data;
|
return image.data;
|
||||||
@ -190,8 +196,9 @@ export class FileServerService {
|
|||||||
reply.header('Content-Disposition', contentDisposition('inline', file.file.name));
|
reply.header('Content-Disposition', contentDisposition('inline', file.file.name));
|
||||||
return stream;
|
return stream;
|
||||||
}
|
}
|
||||||
} finally {
|
} catch (e) {
|
||||||
if ('cleanup' in file) file.cleanup();
|
if ('cleanup' in file) file.cleanup();
|
||||||
|
throw e;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -297,11 +304,17 @@ export class FileServerService {
|
|||||||
};
|
};
|
||||||
}
|
}
|
||||||
|
|
||||||
|
if (typeof image.data === 'object' && 'pipe' in image.data && typeof image.data.pipe === 'function' && 'cleanup' in file) {
|
||||||
|
image.data.on('end', file.cleanup);
|
||||||
|
image.data.on('close', file.cleanup);
|
||||||
|
}
|
||||||
|
|
||||||
reply.header('Content-Type', image.type);
|
reply.header('Content-Type', image.type);
|
||||||
reply.header('Cache-Control', 'max-age=31536000, immutable');
|
reply.header('Cache-Control', 'max-age=31536000, immutable');
|
||||||
return image.data;
|
return image.data;
|
||||||
} finally {
|
} catch (e) {
|
||||||
if ('cleanup' in file) file.cleanup();
|
if ('cleanup' in file) file.cleanup();
|
||||||
|
throw e;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
Loading…
Reference in New Issue
Block a user