From cda03765fe366f028897e9b02dd4a0a19af3c935 Mon Sep 17 00:00:00 2001 From: Chocobozzz Date: Thu, 11 Apr 2019 17:33:36 +0200 Subject: Add ability to delete old remote views --- shared/core-utils/logs/logs.ts | 25 +++++++++++++++++++++++++ 1 file changed, 25 insertions(+) create mode 100644 shared/core-utils/logs/logs.ts (limited to 'shared/core-utils/logs') diff --git a/shared/core-utils/logs/logs.ts b/shared/core-utils/logs/logs.ts new file mode 100644 index 000000000..d0996cf55 --- /dev/null +++ b/shared/core-utils/logs/logs.ts @@ -0,0 +1,25 @@ +import { stat } from 'fs-extra' + +async function mtimeSortFilesDesc (files: string[], basePath: string) { + const promises = [] + const out: { file: string, mtime: number }[] = [] + + for (const file of files) { + const p = stat(basePath + '/' + file) + .then(stats => { + if (stats.isFile()) out.push({ file, mtime: stats.mtime.getTime() }) + }) + + promises.push(p) + } + + await Promise.all(promises) + + out.sort((a, b) => b.mtime - a.mtime) + + return out +} + +export { + mtimeSortFilesDesc +} -- cgit v1.2.3