<commit_before>import Axios from 'axios';

import { parseThread } from '../../parsers/4chanParser';
import { chan as options } from '../../config/requestHeaders';
import { fourchanAPI } from '../../config/apiEndpoints';

import moment from 'moment'

const timeFormat = 'ddd[,] M MMM YYYY hh:mm:ss [GMT]'

export default function (req, res, next) {
    const { boardID, threadID, requestedAt } = req.params;
    const url = fourchanAPI(boardID, threadID).thread

    log.info("requestedAt:",requestedAt)
    if (requestedAt) {
        options['If-Modified-Since'] = moment(requestedAt).format(timeFormat)
    }

    log.http(`Fetching Thread from ${url}`)

    Axios(url, options)
        .then( ({data: {posts}}) => res.send(parseThread(posts, boardID)))
        .catch( err => next(err));
};
<commit_msg>server(getThread): Fix 304 requesting; was using requestedAt not receivedAt<commit_after>import Axios from 'axios';
import moment from 'moment'

import options from '../../config/requestHeaders';
import { parseThread } from '../../parsers/4chanParser';
import { fourchanAPI } from '../../config/apiEndpoints';
import { writeObjToRoot } from '../../services/inspector'


const timeFormat = 'ddd[,] M MMM YYYY hh:mm:ss [GMT]'

export default function (req, res, next) {
    const { boardID, threadID } = req.params;
    const { receivedAt } = req.query;
    const url = fourchanAPI(boardID, threadID).thread

    if (receivedAt) {
        log.warn(`receivedAt: ${receivedAt}`)
        options.headers["If-Modified-Since"] = moment(parseInt(receivedAt)).format(timeFormat)
    }

    log.http(`Fetching Thread from ${url}`)

    Axios(url, options)
        .then( ({data: {posts}}) => res.send(parseThread(posts, boardID)))
        .catch( err => {
            log.error('Thread fetch error:', err)
            writeObjToRoot('4chan_thread_error.json', err)
            next(err)
        });
};

{'fraction_non_alphanumeric': 0.15972588297311544, 'fraction_numerical': 0.0031628887717448603, 'mean_word_length': 3.3935185185185186, 'pattern_counts': {'":': 0, '<': 3, '<?xml version=': 0, '>': 7, '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': '393443', 'n_tokens_mistral': 599, 'n_tokens_neox': 591, 'n_words': 147}