@openinc/parse-server-opendash
Version:
Parse Server Cloud Code for open.INC Stack.
41 lines (40 loc) • 1.25 kB
JavaScript
;
Object.defineProperty(exports, "__esModule", { value: true });
exports.ContentLoader = void 0;
class ContentLoader {
static async populate(files, githubClient, branch, rootPath) {
const candidates = files.filter((f) => this.TEXT_EXTENSIONS.has(f.extension));
if (!candidates.length)
return;
const normalizedRoot = rootPath?.replace(/^\/+/g, "").replace(/\/+$/g, "");
let fetched = 0;
for (const file of candidates) {
try {
const fullPath = normalizedRoot
? `${normalizedRoot}/${file.path}`
: file.path;
const ghContent = await githubClient.getFileContent(fullPath);
if (ghContent?.content) {
file.content = Buffer.from(ghContent.content, "base64").toString("utf-8");
fetched++;
}
}
catch (e) {
console.warn(`Failed to fetch content for ${file.path}:`, e);
}
}
}
}
exports.ContentLoader = ContentLoader;
ContentLoader.TEXT_EXTENSIONS = new Set([
"md",
"markdown",
"txt",
"json",
"yml",
"yaml",
"html",
"css",
"ts",
"js",
]);