<commit_before>//
//   Copyright 2014 <NAME> <<EMAIL>>
//
//   Licensed under the Apache License, Version 2.0 (the "License");
//   you may not use this file except in compliance with the License.
//   You may obtain a copy of the License at
//
//     http://www.apache.org/licenses/LICENSE-2.0
//
//   Unless required by applicable law or agreed to in writing,
//   software distributed under the License is distributed on an "AS
//   IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either
//   express or implied.  See the License for the specific language
//   governing permissions and limitations under the License.
//

'use strict';

const path = require('path'),
      send = require('koa-send'),
      conf = require('../lib/conf');

let dataDirectory = path.normalize(conf.get('files:upload_directory'));

// TBD: move this to library. Add exists check.
if (dataDirectory.charAt(0) !== path.sep) {
    dataDirectory = path.join(__dirname, '..', '..', dataDirectory);
}

module.exports = function*() {
    let file = this.params.file;
    let firstTwo = file.substring(0, 2);

    yield send(this, dataDirectory + path.sep + firstTwo + path.sep + file, {
        maxage: 1000 * 60 * 60 * 24 * 365 // 1 year
    });
};
<commit_msg>Fix cache-control header<commit_after>//
//   Copyright 2014 <NAME> <<EMAIL>>
//
//   Licensed under the Apache License, Version 2.0 (the "License");
//   you may not use this file except in compliance with the License.
//   You may obtain a copy of the License at
//
//     http://www.apache.org/licenses/LICENSE-2.0
//
//   Unless required by applicable law or agreed to in writing,
//   software distributed under the License is distributed on an "AS
//   IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either
//   express or implied.  See the License for the specific language
//   governing permissions and limitations under the License.
//

'use strict';

const path = require('path'),
      send = require('koa-send'),
      conf = require('../lib/conf');

const oneYearInSeconds = 60 * 60 * 24 * 365;
let dataDirectory = path.normalize(conf.get('files:upload_directory'));

// TBD: move this to library. Add exists check.
if (dataDirectory.charAt(0) !== path.sep) {
    dataDirectory = path.join(__dirname, '..', '..', dataDirectory);
}

module.exports = function*() {
    let file = this.params.file;
    let firstTwo = file.substring(0, 2);

    yield send(this, dataDirectory + path.sep + firstTwo + path.sep + file);

    this.set('Cache-Control', 'public, max-age=' + oneYearInSeconds);
};

{'fraction_non_alphanumeric': 0.13671875, 'fraction_numerical': 0.017578125, 'mean_word_length': 3.1306451612903228, 'pattern_counts': {'":': 0, '<': 9, '<?xml version=': 0, '>': 9, 'https://': 0, 'lorem ipsum': 0, 'www.': 2, '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': '5193525', 'n_tokens_mistral': 774, 'n_tokens_neox': 741, 'n_words': 270}