2024-05-08 21:08:47 +00:00
|
|
|
"use strict";
|
|
|
|
Object.defineProperty(exports, "__esModule", { value: true });
|
|
|
|
exports.Files = void 0;
|
2024-07-31 18:39:21 +00:00
|
|
|
const promises_1 = require("fs/promises");
|
2024-05-08 21:08:47 +00:00
|
|
|
const hash_1 = require("../hash");
|
|
|
|
const path_1 = require("path");
|
2024-07-31 18:39:21 +00:00
|
|
|
const videoExtensions = [
|
2024-05-15 18:34:24 +00:00
|
|
|
'.mp4',
|
|
|
|
'.mkv',
|
|
|
|
'.mov'
|
|
|
|
];
|
2024-07-31 18:39:21 +00:00
|
|
|
const imageExtensions = [
|
|
|
|
'.jpg',
|
|
|
|
'.jpeg',
|
|
|
|
'.png',
|
|
|
|
'.tif',
|
|
|
|
'.tiff',
|
|
|
|
'.bmp'
|
|
|
|
];
|
2024-05-08 21:08:47 +00:00
|
|
|
class Files {
|
|
|
|
static async exists(path) {
|
|
|
|
try {
|
2024-07-31 18:39:21 +00:00
|
|
|
await (0, promises_1.access)(path);
|
2024-05-08 21:08:47 +00:00
|
|
|
return true;
|
|
|
|
}
|
|
|
|
catch {
|
|
|
|
return false;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
static async enumerateSequences(path) {
|
|
|
|
const dirs = [];
|
|
|
|
let all;
|
|
|
|
let stats;
|
2024-07-31 18:39:21 +00:00
|
|
|
let dirPath;
|
|
|
|
path = await (0, promises_1.realpath)(path);
|
2024-05-08 21:08:47 +00:00
|
|
|
try {
|
2024-07-31 18:39:21 +00:00
|
|
|
all = await (0, promises_1.readdir)(path);
|
2024-05-08 21:08:47 +00:00
|
|
|
}
|
|
|
|
catch (err) {
|
|
|
|
throw err;
|
|
|
|
}
|
|
|
|
for (let elem of all) {
|
2024-07-31 18:39:21 +00:00
|
|
|
dirPath = (0, path_1.join)(path, elem);
|
2024-05-08 21:08:47 +00:00
|
|
|
try {
|
2024-07-31 18:39:21 +00:00
|
|
|
stats = await (0, promises_1.lstat)(dirPath);
|
2024-05-08 21:08:47 +00:00
|
|
|
if (stats.isDirectory()) {
|
|
|
|
dirs.push({
|
2024-07-31 18:39:21 +00:00
|
|
|
path: dirPath,
|
|
|
|
hash: hash_1.Hashes.stringHash(dirPath),
|
|
|
|
name: (0, path_1.basename)(dirPath)
|
2024-05-08 21:08:47 +00:00
|
|
|
});
|
|
|
|
}
|
|
|
|
}
|
|
|
|
catch (err) {
|
|
|
|
//
|
|
|
|
}
|
|
|
|
}
|
|
|
|
return dirs;
|
|
|
|
}
|
2024-05-15 18:34:24 +00:00
|
|
|
static async enumerateVideos(path) {
|
|
|
|
const videos = [];
|
|
|
|
let all;
|
|
|
|
let stats;
|
2024-07-31 18:39:21 +00:00
|
|
|
let filePath;
|
|
|
|
path = await (0, promises_1.realpath)(path);
|
2024-05-15 21:29:59 +00:00
|
|
|
try {
|
2024-07-31 18:39:21 +00:00
|
|
|
all = await (0, promises_1.readdir)(path);
|
2024-05-15 21:29:59 +00:00
|
|
|
}
|
|
|
|
catch (err) {
|
|
|
|
throw err;
|
|
|
|
}
|
|
|
|
for (let elem of all) {
|
2024-07-31 18:39:21 +00:00
|
|
|
filePath = (0, path_1.join)(path, elem);
|
2024-05-15 21:29:59 +00:00
|
|
|
try {
|
2024-07-31 18:39:21 +00:00
|
|
|
stats = await (0, promises_1.lstat)(filePath);
|
|
|
|
if (stats.isFile() && videoExtensions.indexOf((0, path_1.extname)((0, path_1.basename)(elem).toLowerCase())) !== -1) {
|
2024-05-15 21:29:59 +00:00
|
|
|
videos.push({
|
2024-07-31 18:39:21 +00:00
|
|
|
path: filePath,
|
|
|
|
hash: hash_1.Hashes.stringHash(filePath),
|
|
|
|
name: (0, path_1.basename)(filePath)
|
2024-05-15 21:29:59 +00:00
|
|
|
});
|
|
|
|
}
|
|
|
|
}
|
|
|
|
catch (err) {
|
|
|
|
//
|
|
|
|
}
|
|
|
|
}
|
2024-05-15 18:34:24 +00:00
|
|
|
return videos;
|
|
|
|
}
|
2024-07-31 18:39:21 +00:00
|
|
|
static async enumerateSequence(path) {
|
2024-08-09 20:20:07 +00:00
|
|
|
const imgs = [];
|
2024-07-31 18:39:21 +00:00
|
|
|
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() && imageExtensions.indexOf((0, path_1.extname)((0, path_1.basename)(elem).toLowerCase())) !== -1) {
|
2024-08-09 20:20:07 +00:00
|
|
|
imgs.push({
|
2024-07-31 18:39:21 +00:00
|
|
|
path: filePath,
|
|
|
|
hash: hash_1.Hashes.stringHash(filePath),
|
|
|
|
name: (0, path_1.basename)(filePath)
|
|
|
|
});
|
|
|
|
}
|
|
|
|
}
|
|
|
|
catch (err) {
|
|
|
|
//
|
|
|
|
}
|
|
|
|
}
|
2024-08-09 20:20:07 +00:00
|
|
|
return imgs;
|
2024-07-31 18:39:21 +00:00
|
|
|
}
|
2024-05-08 21:08:47 +00:00
|
|
|
}
|
|
|
|
exports.Files = Files;
|
|
|
|
module.exports = { Files };
|
|
|
|
//# sourceMappingURL=index.js.map
|