"use strict"; Object.defineProperty(exports, "__esModule", { value: true }); exports.Files = void 0; const promises_1 = require("fs/promises"); const hash_1 = require("../hash"); const path_1 = require("path"); const env_1 = require("../env"); const os_1 = require("os"); const videoExtensions = [ '.mp4', '.mkv', '.mov' ]; const imageExtensions = [ '.jpg', '.jpeg', '.png', '.tif', '.tiff', '.bmp', '.dpx' ]; class Files { static async init(sequencesDir) { this.sequencesDir = sequencesDir; return this.exists(sequencesDir); } static async exists(path) { try { await (0, promises_1.access)(path); return true; } catch { return false; } } static async enumerateSequenceDirs() { const sequencesDirs = [ await (0, promises_1.realpath)(this.sequencesDir) ]; let drivesDir = null; let drives = []; let drive; let user; let stats; if ((0, os_1.platform)() === 'darwin') { drivesDir = `/Volumes/`; } else if ((0, os_1.platform)() === 'linux') { user = (0, env_1.envString)('USER', null); if (user !== null) { drivesDir = (0, path_1.join)('/media', user); } } if (drivesDir !== null) { try { drives = await (0, promises_1.readdir)(drivesDir); } catch (err) { // } } for (let drive of drives) { if (drive.substring(0, 1) === '.') { continue; } try { drive = await (0, promises_1.realpath)((0, path_1.join)(drivesDir, drive)); stats = await (0, promises_1.lstat)(drive); } catch (err) { continue; } if (stats.isDirectory()) { sequencesDirs.push(drive); } } return sequencesDirs; } static async enumerateSequences() { const dirs = []; let all; let stats; let dirPath; const paths = await this.enumerateSequenceDirs(); for (let path of paths) { try { all = await (0, promises_1.readdir)(path); } catch (err) { // } for (let elem of all) { if (elem.substring(0, 1) === '.') { continue; } dirPath = (0, path_1.join)(path, elem); try { stats = await (0, promises_1.lstat)(dirPath); } catch (err) { continue; } if (!stats.isDirectory()) { continue; } if (!await this.isSequence(dirPath)) { continue; } dirs.push({ created: +stats.birthtime, path: dirPath, hash: hash_1.Hashes.stringHash(dirPath), name: (0, path_1.basename)(dirPath) }); } } dirs.sort((a, b) => { return b.created - a.created; }); return dirs; } static async isSequence(dirPath) { let sequence = false; let all; let stats; let filePath; try { all = await (0, promises_1.readdir)(dirPath); } catch (err) { // } for (let elem of all) { filePath = (0, path_1.join)(dirPath, elem); try { stats = await (0, promises_1.lstat)(filePath); } catch (err) { // } if (stats.isFile() && elem.substring(0, 1) !== '.' && imageExtensions.indexOf((0, path_1.extname)((0, path_1.basename)(elem).toLowerCase())) !== -1) { sequence = true; break; } } return sequence; } static async enumerateVideos(path) { const videos = []; let all; let stats; let filePath; path = await (0, promises_1.realpath)(path); try { all = await (0, promises_1.readdir)(path); } catch (err) { throw err; } for (let elem of all) { filePath = (0, path_1.join)(path, elem); try { stats = await (0, promises_1.lstat)(filePath); if (stats.isFile() && videoExtensions.indexOf((0, path_1.extname)((0, path_1.basename)(elem).toLowerCase())) !== -1) { videos.push({ created: +stats.birthtime, path: filePath, hash: hash_1.Hashes.stringHash(filePath), name: (0, path_1.basename)(filePath) }); } } catch (err) { // } } return videos; } static async enumerateSequence(path) { const imgs = []; let all; let stats; let filePath; path = await (0, promises_1.realpath)(path); try { all = await (0, promises_1.readdir)(path); } catch (err) { throw err; } for (let elem of all) { if (elem.substring(0, 1) === '.') { continue; } filePath = (0, path_1.join)(path, elem); try { stats = await (0, promises_1.lstat)(filePath); if (stats.isFile() && imageExtensions.indexOf((0, path_1.extname)((0, path_1.basename)(elem).toLowerCase())) !== -1) { imgs.push({ path: filePath, hash: hash_1.Hashes.stringHash(filePath), name: (0, path_1.basename)(filePath) }); } } catch (err) { // } } return imgs; } } exports.Files = Files; module.exports = { Files }; //# sourceMappingURL=index.js.map