114 lines
4.1 KiB
JavaScript
114 lines
4.1 KiB
JavaScript
"use strict";
|
|
var __createBinding = (this && this.__createBinding) || (Object.create ? (function(o, m, k, k2) {
|
|
if (k2 === undefined) k2 = k;
|
|
var desc = Object.getOwnPropertyDescriptor(m, k);
|
|
if (!desc || ("get" in desc ? !m.__esModule : desc.writable || desc.configurable)) {
|
|
desc = { enumerable: true, get: function() { return m[k]; } };
|
|
}
|
|
Object.defineProperty(o, k2, desc);
|
|
}) : (function(o, m, k, k2) {
|
|
if (k2 === undefined) k2 = k;
|
|
o[k2] = m[k];
|
|
}));
|
|
var __setModuleDefault = (this && this.__setModuleDefault) || (Object.create ? (function(o, v) {
|
|
Object.defineProperty(o, "default", { enumerable: true, value: v });
|
|
}) : function(o, v) {
|
|
o["default"] = v;
|
|
});
|
|
var __importStar = (this && this.__importStar) || (function () {
|
|
var ownKeys = function(o) {
|
|
ownKeys = Object.getOwnPropertyNames || function (o) {
|
|
var ar = [];
|
|
for (var k in o) if (Object.prototype.hasOwnProperty.call(o, k)) ar[ar.length] = k;
|
|
return ar;
|
|
};
|
|
return ownKeys(o);
|
|
};
|
|
return function (mod) {
|
|
if (mod && mod.__esModule) return mod;
|
|
var result = {};
|
|
if (mod != null) for (var k = ownKeys(mod), i = 0; i < k.length; i++) if (k[i] !== "default") __createBinding(result, mod, k[i]);
|
|
__setModuleDefault(result, mod);
|
|
return result;
|
|
};
|
|
})();
|
|
var __importDefault = (this && this.__importDefault) || function (mod) {
|
|
return (mod && mod.__esModule) ? mod : { "default": mod };
|
|
};
|
|
Object.defineProperty(exports, "__esModule", { value: true });
|
|
exports.readRecursively = void 0;
|
|
const node_fs_1 = __importStar(require("node:fs"));
|
|
const node_path_1 = __importDefault(require("node:path"));
|
|
// There can be symbolic links that point to files that don't exist.
|
|
// https://github.com/remotion-dev/remotion/issues/2587
|
|
const statOrNull = (p) => {
|
|
try {
|
|
return (0, node_fs_1.statSync)(p);
|
|
}
|
|
catch (_a) {
|
|
return null;
|
|
}
|
|
};
|
|
const encodeBySplitting = (p) => {
|
|
// Intentional: split by path.sep, then join by /
|
|
const splitBySlash = p.split(node_path_1.default.sep);
|
|
const encodedArray = splitBySlash.map((element) => {
|
|
return encodeURIComponent(element);
|
|
});
|
|
const merged = encodedArray.join('/');
|
|
return merged;
|
|
};
|
|
const readRecursively = ({ folder, output = [], startPath, staticHash, limit, }) => {
|
|
const absFolder = node_path_1.default.join(startPath, folder);
|
|
if (!node_fs_1.default.existsSync(absFolder)) {
|
|
return [];
|
|
}
|
|
const files = node_fs_1.default.readdirSync(absFolder);
|
|
for (const file of files) {
|
|
if (output.length >= limit) {
|
|
break;
|
|
}
|
|
if (file.startsWith('.DS_Store')) {
|
|
continue;
|
|
}
|
|
const stat = statOrNull(node_path_1.default.join(absFolder, file));
|
|
if (!stat) {
|
|
continue;
|
|
}
|
|
if (stat.isDirectory()) {
|
|
(0, exports.readRecursively)({
|
|
startPath,
|
|
folder: node_path_1.default.join(folder, file),
|
|
output,
|
|
staticHash,
|
|
limit,
|
|
});
|
|
}
|
|
else if (stat.isFile()) {
|
|
output.push({
|
|
name: node_path_1.default.join(folder, file),
|
|
lastModified: Math.floor(stat.mtimeMs),
|
|
sizeInBytes: stat.size,
|
|
src: staticHash + '/' + encodeBySplitting(node_path_1.default.join(folder, file)),
|
|
});
|
|
}
|
|
else if (stat.isSymbolicLink()) {
|
|
const realpath = node_fs_1.default.realpathSync(node_path_1.default.join(folder, file));
|
|
const realStat = statOrNull(realpath);
|
|
if (!realStat) {
|
|
continue;
|
|
}
|
|
if (realStat.isFile()) {
|
|
output.push({
|
|
name: realpath,
|
|
lastModified: Math.floor(realStat.mtimeMs),
|
|
sizeInBytes: realStat.size,
|
|
src: staticHash + '/' + encodeBySplitting(realpath),
|
|
});
|
|
}
|
|
}
|
|
}
|
|
return output.sort((a, b) => a.name.localeCompare(b.name));
|
|
};
|
|
exports.readRecursively = readRecursively;
|