<commit_before>import * as akala from '@akala/server';
import { meta } from './scrapper';
import { MediaTypes, MediaType, Media } from '../../metadata';
import { Connection } from '@akala/json-rpc-ws';

var scrappers: { [key: string]: { connection: Connection, priority: number }[] } = {}

akala.injectWithName(['$router'], function (router: akala.HttpRouter)
{
    akala.createServerFromMeta(meta)(router, '/media', {
        register: function (scrapper, connection)
        {
            if (scrapper.type in scrappers)
                scrappers[scrapper.type] = [];
            for (var index = 0; index < scrappers[scrapper.type].length; index++)
            {
                if (scrappers[scrapper.type][index].priority < scrapper.priority)
                    break;
            }
            scrappers[scrapper.type].splice(index, 0, { connection: connection, priority: scrapper.priority });
        },
        scrap: function (media)
        {
            return akala.eachAsync(scrappers[media.type], (scrapper, i, next) =>
            {
                this.$proxy(scrapper.connection).scrap(media).then((m) =>
                {
                    media = m;
                    next();
                }, next);
            }).then(() => { return media; });
        }
    });
})();<commit_msg>bug fix in scrapper registration<commit_after>import * as akala from '@akala/server';
import { meta } from './scrapper';
import { MediaTypes, MediaType, Media } from '../../metadata';
import { Connection } from '@akala/json-rpc-ws';

var scrappers: { [key: string]: { connection: Connection, priority: number }[] } = {}

akala.injectWithName(['$router'], function (router: akala.HttpRouter)
{
    akala.createServerFromMeta(meta)(router, '/media', {
        register: function (scrapper, connection)
        {
            if (!(scrapper.type in scrappers))
                scrappers[scrapper.type] = [];
            for (var index = 0; index < scrappers[scrapper.type].length; index++)
            {
                if (scrappers[scrapper.type][index].priority < scrapper.priority)
                    break;
            }
            scrappers[scrapper.type].splice(index, 0, { connection: connection, priority: scrapper.priority });
        },
        scrap: function (media)
        {
            return akala.eachAsync(scrappers[media.type], (scrapper, i, next) =>
            {
                this.$proxy(scrapper.connection).scrap(media).then((m) =>
                {
                    media = m;
                    next();
                }, next);
            }).then(() => { return media; });
        }
    });
})();
{'fraction_non_alphanumeric': 0.15136570561456753, 'fraction_numerical': 0.0015174506828528073, 'mean_word_length': 1.9796610169491526, 'pattern_counts': {'":': 0, '<': 7, '<?xml version=': 0, '>': 9, 'https://': 0, 'lorem ipsum': 0, 'www.': 0, 'xml': 0}, 'pii_count': 0, 'substrings_counts': 0, 'word_list_counts': {'cursed_substrings.json': 0, 'profanity_word_list.json': 0, 'sexual_word_list.json': 0, 'zh_pornsignals.json': 0}}
{'dir': 'git-commits-cleaned', 'id': '2252719', 'n_tokens_mistral': 726, 'n_tokens_neox': 717, 'n_words': 154}