lib/fetching/sourceToChannel.js
/**
 * Creates a new Channel corresponding to the given Source.
 */
Creates a new Channel corresponding to the given Source.
Creates a new Channel corresponding to the given Source .
function createChannel(source) {
    let channel;
    const {
        _id,
        lastReportDate,
        keywords,
        credentials,
        media,
        tags,
        enabled
    } = source;
    let options = {
        lastTimestamp: lastReportDate,
        onFetch: async (lastTimestamp) => {
            return Source.updateOne(
                { _id },
                { lastReportDate: lastTimestamp },
            ).exec();
        }
    };
    switch(media) {
        case 'facebook':
        case 'instagram':
            options = {
                ...options,
                dashboardToken: credentials.secrets.dashboardAPIToken,
                queryParams: {
                    searchTerm: keywords, 
                    platforms: media,
                },
            };
            channel = new AggieCrowdTangleChannel(options);
            break;
        case 'twitter':
            options = {
                ...options,
                credentials: {
                    consumerKey: credentials.secrets.consumerKey,
                    consumerSecret: credentials.secrets.consumerSecret,
                },
                queryParams: {
                    query: keywords 
                },
            }
            channel = new TwitterPageChannel(options);
            break;
        default:
    }
    channel.enabled = enabled;
    channel.tags = tags;
    const channelID = downstream.register(channel);
    sourceChannelJoin[_id] = channelID;
}
function createChannel ( source ) { let channel ; const { _id , lastReportDate , keywords , credentials , media , tags , enabled } = source ; let options = { lastTimestamp : lastReportDate , onFetch : async ( lastTimestamp ) => { return Source . updateOne ( { _id } , { lastReportDate : lastTimestamp } , ) . exec ( ) ; } } ; switch ( media ) { case 'facebook' : case 'instagram' : options = { ... options , dashboardToken : credentials . secrets . dashboardAPIToken , queryParams : { searchTerm : keywords , platforms : media , } , } ; channel = new AggieCrowdTangleChannel ( options ) ; break ; case 'twitter' : options = { ... options , credentials : { consumerKey : credentials . secrets . consumerKey , consumerSecret : credentials . secrets . consumerSecret , } , queryParams : { query : keywords } , } channel = new TwitterPageChannel ( options ) ; break ; default : } channel . enabled = enabled ; channel . tags = tags ; const channelID = downstream . register ( channel ) ; sourceChannelJoin [ _id ] = channelID ; }
Creates a new Channel corresponding to the given Source.
Creates a new Channel corresponding to the given Source .
// TODO rename to something better // TODO rename to something better