<commit_before><?php

namespace App;

use App\Models\Upload;
use Auth;
use Cache;
use Dflydev\ApacheMimeTypes\PhpRepository;
use Exception;
use Image;
use Log;
use Mimey\MimeTypes;
use Symfony\Component\HttpFoundation\File\UploadedFile;

class Helpers
{
    const PAGINATION_DEFAULT_ITEMS = 9;
    const API_KEY_LENGTH = 64;

    /**
     * Handle sending a file, preferably by offloading to the webserver.
     *
     * @param Upload $upload
     * @return mixed
     */
    public static function sendFile(Upload $upload)
    {
        switch (config('upste.sendfile_method')) {
            case 'x-accel':
                return response()->make()->header('X-Accel-Redirect', '/' . $upload->getPath())
                    ->header('Content-Type', '')
                    ->header('Content-Disposition', sprintf('inline; filename="%s"', $upload->original_name));
                break;
            case 'x-sendfile':
                return response()->make()->header('X-Sendfile', $upload->getPath(true))
                    ->header('Content-Type', '')
                    ->header('Content-Disposition', sprintf('inline; filename="%s"', $upload->original_name));
                break;
            default:
                return response()->download($upload->getPath(true), $upload->original_name);
        }
    }

    // http://stackoverflow.com/questions/2510434/format-bytes-to-kilobytes-megabytes-gigabytes
    /**
     * @param $bytes<commit_msg>Fix all files downloading when sendfile method is null<commit_after><?php

namespace App;

use App\Models\Upload;
use Auth;
use Cache;
use Dflydev\ApacheMimeTypes\PhpRepository;
use Exception;
use Image;
use Log;
use Mimey\MimeTypes;
use Symfony\Component\HttpFoundation\File\UploadedFile;

class Helpers
{
    const PAGINATION_DEFAULT_ITEMS = 9;
    const API_KEY_LENGTH = 64;

    /**
     * Handle sending a file, preferably by offloading to the webserver.
     *
     * @param Upload $upload
     * @return mixed
     */
    public static function sendFile(Upload $upload)
    {
        switch (config('upste.sendfile_method')) {
            case 'x-accel':
                return response()->make()->header('X-Accel-Redirect', '/' . $upload->getPath())
                    ->header('Content-Type', '')
                    ->header('Content-Disposition', sprintf('inline; filename="%s"', $upload->original_name));
                break;
            case 'x-sendfile':
                return response()->make()->header('X-Sendfile', $upload->getPath(true))
                    ->header('Content-Type', '')
                    ->header('Content-Disposition', sprintf('inline; filename="%s"', $upload->original_name));
                break;
            default:
                return response()->file($upload->getPath(true), ['Content-Disposition' => sprintf('inline; filename="%s"', $upload->original_name)]);
        }
    }

    // http://stackoverflow.com/questions/2510434/format-bytes-to-kilobytes-megabytes-gigabytes
    /**
     * @param $bytes
{'fraction_non_alphanumeric': 0.1457503320053121, 'fraction_numerical': 0.006640106241699867, 'mean_word_length': 2.439497716894977, 'pattern_counts': {'":': 0, '<': 5, '<?xml version=': 0, '>': 34, 'https://': 0, 'lorem ipsum': 0, 'www.': 0, 'xml': 0}, 'pii_count': 0, 'substrings_counts': 0, 'word_list_counts': {'cursed_substrings.json': 2, 'profanity_word_list.json': 0, 'sexual_word_list.json': 0, 'zh_pornsignals.json': 0}}
{'dir': 'git-commits-cleaned', 'id': '1507134', 'n_tokens_mistral': 893, 'n_tokens_neox': 856, 'n_words': 170}