Add extensions service and routes

This commit is contained in:
rijkvanzanten
2020-06-19 11:14:40 -04:00
parent 031b511523
commit d4ddd20b9a
6 changed files with 81 additions and 2 deletions

25
src/utils/list-folders.ts Normal file
View File

@@ -0,0 +1,25 @@
import fs from 'fs';
import path from 'path';
import { promisify } from 'util';
import APIError, { ErrorCode } from '../error';
const readdir = promisify(fs.readdir);
const stat = promisify(fs.stat);
export default async function listFolders(location: string) {
const fullPath = path.join(process.cwd(), location);
const files = await readdir(fullPath);
const directories: string[] = [];
for (const file of files) {
const filePath = path.join(fullPath, file);
const stats = await stat(filePath);
if (stats.isDirectory()) {
directories.push(file);
}
}
return directories;
}