-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Clean up download endpoint and move logic to utils
- Loading branch information
Leon
committed
Nov 2, 2023
1 parent
7335bae
commit c7e4904
Showing
3 changed files
with
25 additions
and
25 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,23 @@ | ||
import fs from "fs"; | ||
|
||
export const findLargestFileInPath = (path): string => { | ||
console.log("finding largest file in path:", path); | ||
|
||
if (!fs.lstatSync(path).isDirectory()) { | ||
return path; | ||
} | ||
|
||
const files = fs.readdirSync(path); | ||
|
||
const largest = files | ||
.map((file) => { | ||
const stat = fs.statSync(`${path}/${file}`); | ||
return { | ||
file, | ||
size: stat.size, | ||
}; | ||
}) | ||
.sort((a, b) => b.size - a.size)[0]; | ||
|
||
return `${path}/${largest.file}`; | ||
}; |