2023-07-27 07:31:52 +02:00
|
|
|
/*
|
2024-02-13 16:59:27 +01:00
|
|
|
* SPDX-FileCopyrightText: syuilo and misskey-project
|
2023-07-27 07:31:52 +02:00
|
|
|
* SPDX-License-Identifier: AGPL-3.0-only
|
|
|
|
*/
|
|
|
|
|
2019-03-20 20:50:44 +01:00
|
|
|
import * as tmp from 'tmp';
|
|
|
|
|
2022-05-25 09:50:22 +02:00
|
|
|
export function createTemp(): Promise<[string, () => void]> {
|
|
|
|
return new Promise<[string, () => void]>((res, rej) => {
|
2019-03-20 20:50:44 +01:00
|
|
|
tmp.file((e, path, fd, cleanup) => {
|
|
|
|
if (e) return rej(e);
|
2023-11-12 17:32:24 +01:00
|
|
|
res([path, process.env.NODE_ENV === 'production' || process.env.NODE_ENV === 'development' ? cleanup : () => {}]);
|
2019-03-20 20:50:44 +01:00
|
|
|
});
|
|
|
|
});
|
|
|
|
}
|
2022-05-25 09:50:22 +02:00
|
|
|
|
|
|
|
export function createTempDir(): Promise<[string, () => void]> {
|
|
|
|
return new Promise<[string, () => void]>((res, rej) => {
|
2022-06-14 16:00:10 +02:00
|
|
|
tmp.dir(
|
|
|
|
{
|
|
|
|
unsafeCleanup: true,
|
|
|
|
},
|
|
|
|
(e, path, cleanup) => {
|
|
|
|
if (e) return rej(e);
|
2023-11-12 17:32:24 +01:00
|
|
|
res([path, process.env.NODE_ENV === 'production' || process.env.NODE_ENV === 'development' ? cleanup : () => {}]);
|
2022-12-03 11:42:05 +01:00
|
|
|
},
|
2022-06-14 16:00:10 +02:00
|
|
|
);
|
2022-05-25 09:50:22 +02:00
|
|
|
});
|
|
|
|
}
|