<commit_before><?php

$docroot = __DIR__;
require_once $docroot . '/vendor/autoload.php';

/**
 * Read config.
 *
 * Config is a json file reposing at config.json in the document root.
 *  {
 *      baseUrl : String each request's path starts with. Defaults to '/'.
 *      storage : Path to the distributed files' directory relative to the document root.
 *  }
**/
$configFilename = $docroot . '/config.json';
$configContent = file_get_contents($configFilename);
$config = json_decode($configContent, true);

// Determine command.
$uri = $_SERVER['REQUEST_URI'];
if (substr($uri, 0, strlen($config['baseUrl'])) !== $config['baseUrl']) {
    print 'Unexpected request path. Expecting request with base url "' . $config['baseUrl'] . '"';
    die;
}
$uri = substr($uri, strlen($config['baseUrl']));
$action = empty($uri) ? 'list_folder' : 'download_file';

// Execute controller.
switch ($action) {
    case 'list_folder':
        $webAuthBuilder = new Ob_Ivan\DropboxProxy\WebAuthBuilder(
            $docroot . '/dropbox.json',
            'DownloadProxy/0.1'
        );
        // TODO
        print 'Folder listing is not yet supported. Please come back later.';
        break;

    case 'download_file':
        $filename = implode(DIRECTORY_SEPARATOR, [$docroot, $config['storage'], $uri]);

        if (file_exists($filename)) {
            // copy-pasted from php.net/readfile
            header('Content-Description: File Transfer');
            header('Content-Type: application/octet-stream');
            header('Content-Disposition: attachment; filename=' . basename($filename));
            header('Content-Transfer-Encoding: binary');
            header('Expires: 0');
            header('Cache-Control: must-revalidate');
            header('Pragma: public');
            header('Content-Length: ' . filesize($filename));
            ob_clean();
            flush();
            readfile($filename);
        } else {
            header('HTTP/1.0 404 Not found');
            print 'File "' . $uri . '" was not found on server. Check for typos or contact system administrator.';
        }
        break;

    default:
        print 'Unknown command "' . $action . '".';
        break;
}
<commit_msg>Переписал всё то же самое, что было в index.php, на silex<commit_after><?php

$docroot = __DIR__;
require_once $docroot . '/vendor/autoload.php';

/**
 * Read config.
 *
 * Config is a json file reposing at config.json in the document root.
 *  {
 *      debug   : Boolean which should be true only in development environment.
 *      storage : Path to the distributed files' directory relative to the document root.
 *  }
**/
$configFilename = $docroot . '/config.json';
$configContent = file_get_contents($configFilename);
$config = json_decode($configContent, true);

$app = new Silex\Application([
    'docroot' => $docroot,
    'config'  => $config,
]);
if ($config['debug']) {
    $app['debug'] = true;
}

// Routing and controllers.
$app->get('/', function () use ($app) {
    $webAuthBuilder = new Ob_Ivan\DropboxProxy\WebAuthBuilder(
        $app['docroot'] . '/dropbox.json',
        'DownloadProxy/0.1'
    );
    // TODO: folder listing
    return 'Folder listing is not yet supported. Please come back later.';
});

$app->get('/{file}', function ($file) use ($app) {
    // Download a file.
    $filename = implode(DIRECTORY_SEPARATOR, [$app['docroot'], $app['config']['storage'], $file]);
    if (! file_exists($filename)) {
        return
            'File "' . $file . '" was not found on server. ' .
            'Check for typos or contact system administrator.'
        ;
    }
    return $app->sendFile($filename);
});

$app->run();
{'fraction_non_alphanumeric': 0.1526071526071526, 'fraction_numerical': 0.003003003003003003, 'mean_word_length': 2.777319587628866, 'pattern_counts': {'":': 0, '<': 5, '<?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': 5, 'profanity_word_list.json': 0, 'sexual_word_list.json': 0, 'zh_pornsignals.json': 0}}
{'dir': 'git-commits-cleaned', 'id': '438493', 'n_tokens_mistral': 1076, 'n_tokens_neox': 1066, 'n_words': 293}