All files / src/web archive-sources.js

100% Statements 28/28
100% Branches 2/2
100% Functions 13/13
100% Lines 18/18

Press n or j to go to the next uncovered block, b, p or k for the previous block.

1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45                                  10x 10x 10x 10x 10x         10x 10x 10x   10x 10x 10x 10x 2x 2x     10x 10x 10x 119x      
import { StairwayToHell } from "../sth.js";
import { BbcDiscArchive } from "../bbcdiscs.js";
import { BitshiftersArchive } from "../bitshifters.js";
import GitHubDiscs from "./github-discs.json";
import {
    describeBitshiftersEntry,
    describeGitHubEntry,
    describeHfeEntry,
    describeSthDisc,
    describeSthTape,
} from "./media-catalogue.js";
 
/**
 * Registers the public archives with the loader: each one's fetcher, its list for the media window, and a describer
 * for those whose entries can name the machine they need.
 */
export function addArchiveSources(media) {
    const sthDiscs = new StairwayToHell();
    const sthTapes = new StairwayToHell({ tapes: true });
    media.addSource("sth", (name) => sthDiscs.fetch(name));
    media.addSource("tapeSth", (name) => sthTapes.fetch(name));
    media.addLister("sth", async () => [
        ...(await sthDiscs.catalogue()).map(describeSthDisc),
        ...(await sthTapes.catalogue()).map(describeSthTape),
    ]);
 
    const hfe = new BbcDiscArchive();
    media.addSource("hfe", (path) => hfe.fetch(path));
    media.addLister("hfe", async () => (await hfe.catalogue()).map(describeHfeEntry));
 
    const bitshifters = new BitshiftersArchive();
    media.addSource("bitshifters", (path) => bitshifters.fetch(path));
    media.addLister("bitshifters", async () => (await bitshifters.catalogue()).map(describeBitshiftersEntry));
    media.addDescriber("bitshifters", async (path) => {
        const entry = (await bitshifters.catalogue()).find((file) => file.path === path);
        return entry && describeBitshiftersEntry(entry);
    });
 
    const gitHubDiscs = GitHubDiscs.map(describeGitHubEntry);
    media.addLister("github", () => gitHubDiscs);
    media.addDescriber("github", (location) =>
        gitHubDiscs.find((descriptor) => descriptor.ref === `github:${location}`),
    );
}