this repo has no description
1import { MoonbaseNatives, RepositoryManifest } from "./types"; 2import asar from "@electron/asar"; 3import fs from "fs"; 4import path from "path"; 5import os from "os"; 6import { repoUrlFile } from "types/src/constants"; 7 8const logger = moonlightNode.getLogger("moonbase"); 9 10async function fetchRepositories(repos: string[]) { 11 const ret: Record<string, RepositoryManifest[]> = {}; 12 13 for (const repo of repos) { 14 try { 15 const req = await fetch(repo); 16 const json = await req.json(); 17 ret[repo] = json; 18 } catch (e) { 19 logger.error(`Error fetching repository ${repo}`, e); 20 } 21 } 22 23 return ret; 24} 25 26async function installExtension( 27 manifest: RepositoryManifest, 28 url: string, 29 repo: string 30) { 31 const req = await fetch(url); 32 33 const dir = moonlightNode.getExtensionDir(manifest.id); 34 // remake it in case of updates 35 if (fs.existsSync(dir)) fs.rmdirSync(dir, { recursive: true }); 36 fs.mkdirSync(dir, { recursive: true }); 37 38 // for some reason i just can't .writeFileSync() a file that ends in .asar??? 39 const tempDir = fs.mkdtempSync(path.join(os.tmpdir(), "moonlight-")); 40 const tempFile = path.join(tempDir, "extension"); 41 const buffer = await req.arrayBuffer(); 42 fs.writeFileSync(tempFile, Buffer.from(buffer)); 43 44 asar.extractAll(tempFile, dir); 45 fs.writeFileSync(path.join(dir, repoUrlFile), repo); 46} 47 48async function deleteExtension(id: string) { 49 const dir = moonlightNode.getExtensionDir(id); 50 fs.rmdirSync(dir, { recursive: true }); 51} 52 53function getExtensionConfig(id: string, key: string): any { 54 const config = moonlightNode.config.extensions[id]; 55 if (typeof config === "object") { 56 return config.config?.[key]; 57 } 58 59 return undefined; 60} 61 62const exports: MoonbaseNatives = { 63 fetchRepositories, 64 installExtension, 65 deleteExtension, 66 getExtensionConfig 67}; 68 69module.exports = exports;