<commit_before><?php

namespace Joselfonseca\ImageManager\Controllers;

use Illuminate\Http\Request;
use Illuminate\Routing\Controller;
use Illuminate\Support\Facades\Storage;
use Joselfonseca\ImageManager\ImageRender;
use Illuminate\Validation\ValidationException;
use Joselfonseca\ImageManager\Models\ImageManagerFiles;
use Illuminate\Foundation\Validation\ValidatesRequests;
use Illuminate\Database\Eloquent\ModelNotFoundException;

/**
 * Description of ImageManagerController
 *
 * @author jfonseca
 */
class ImageManagerController extends Controller
{
    use ValidatesRequests;

    protected $model;

    protected $renderService;

    public function __construct(ImageManagerFiles $model, ImageRender $renderService)
    {
        $this->model = $model;
        $this->renderService = $renderService;
    }

    public function index()
    {
        return view('image-manager::image_manager');
    }

    public function getImages()
    {
        $files = $this->model->orderBy('created_at', 'desc')->where('from_manager', 1)->paginate(12);

        return view('image-manager::images_collection')->with('files', $files);
    }

    public function thumb($id)
    {
        try {
            $image = $this->model->findOrFail($id);
            return $this->renderService->render($image->path, 250, 250, true);
        } catch (ModelNotFoundException $e) {
            return $this->renderService->renderDefault(250, 250);
        }
    }

    public function full($id, $width = 800, $height = null, $canvas = false)
    {
        try {
            $image = $this->model->findOrFail($id);
            return $this->renderService->render($image->path, $width, $height, (bool) $canvas);
        } catch (ModelNotFoundException $e) {
            return $this->renderService->renderDefault($width, $height);
        }
    }

    public function store(Request $request)
    {
        try {
            $this->validate($request, [
                'file' => "image|required|between:1,".config('image-manager.maxFileSize'),
            ]);
            $path = $request->file->store('local');
            $file = $this->model->create([
                'name' => $path,
                'originalName' => $request->file('file')->getClientOriginalName(),
                'type' => $request->file('file')->getClientMimeType(),
                'path' => $path,
                'size' => $request->file('file')->getClientSize(),
                'from_manager' => $request->get('from_manager', '1'),<commit_msg>Do not use 800px width by default<commit_after><?php

namespace Joselfonseca\ImageManager\Controllers;

use Illuminate\Http\Request;
use Illuminate\Routing\Controller;
use Illuminate\Support\Facades\Storage;
use Joselfonseca\ImageManager\ImageRender;
use Illuminate\Validation\ValidationException;
use Joselfonseca\ImageManager\Models\ImageManagerFiles;
use Illuminate\Foundation\Validation\ValidatesRequests;
use Illuminate\Database\Eloquent\ModelNotFoundException;

/**
 * Description of ImageManagerController
 *
 * @author jfonseca
 */
class ImageManagerController extends Controller
{
    use ValidatesRequests;

    protected $model;

    protected $renderService;

    public function __construct(ImageManagerFiles $model, ImageRender $renderService)
    {
        $this->model = $model;
        $this->renderService = $renderService;
    }

    public function index()
    {
        return view('image-manager::image_manager');
    }

    public function getImages()
    {
        $files = $this->model->orderBy('created_at', 'desc')->where('from_manager', 1)->paginate(12);

        return view('image-manager::images_collection')->with('files', $files);
    }

    public function thumb($id)
    {
        try {
            $image = $this->model->findOrFail($id);
            return $this->renderService->render($image->path, 250, 250, true);
        } catch (ModelNotFoundException $e) {
            return $this->renderService->renderDefault(250, 250);
        }
    }

    public function full($id, $width = null, $height = null, $canvas = false)
    {
        try {
            $image = $this->model->findOrFail($id);
            return $this->renderService->render($image->path, $width, $height, (bool) $canvas);
        } catch (ModelNotFoundException $e) {
            return $this->renderService->renderDefault($width, $height);
        }
    }

    public function store(Request $request)
    {
        try {
            $this->validate($request, [
                'file' => "image|required|between:1,".config('image-manager.maxFileSize'),
            ]);
            $path = $request->file->store('local');
            $file = $this->model->create([
                'name' => $path,
                'originalName' => $request->file('file')->getClientOriginalName(),
                'type' => $request->file('file')->getClientMimeType(),
                'path' => $path,
                'size' => $request->file('file')->getClientSize(),
                'from_manager' => $request->get('from_manager', '1'),
{'fraction_non_alphanumeric': 0.1451003776585172, 'fraction_numerical': 0.007950705625124229, 'mean_word_length': 2.820804859529233, 'pattern_counts': {'":': 0, '<': 5, '<?xml version=': 0, '>': 83, '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': '3942840', 'n_tokens_mistral': 1426, 'n_tokens_neox': 1395, 'n_words': 255}