Coder Social home page Coder Social logo

Comments (4)

dinandmentink avatar dinandmentink commented on May 25, 2024

At the moment there is no way to override the default controller. It would, theoretically, be possible to monkeypatch DinandMentink\Markdown\Http\Controllers\UploadController.

Is there a specific reason you would want to override the controller? Theoretically I could make this configurable, but it would require some refactoring and maybe there's a better way for your usecase.

from nova-markdown.

lukebouch avatar lukebouch commented on May 25, 2024

@dinandmentink I'm currently using Easy Markdown Editor on it's own and have some custom logic around the uploads. Instead of just dropping the file in a disk and returning a link, I save it to a model using the Laravel Media Library by Spatie and then return a url with a random hash. This decouples the url from the actual location on the disk.

This is what my current controller looks like.

public function upload(Request $request)
    {
        /** @var User $user */
        $user = auth()->user();
        $site = $user->activeSite;

        $this->authorize('upload', $site);

        $name = $request->all()['image']->hashName();
        $file = $site->addMedia($request->all()['image']->path())->usingFileName($name)->toMediaCollection('uploads');

        $data = ['data' => ['filePath' => Upload::getUrl($user->activeSite, $file->uuid)]];

        return response()->json($data);
    }

from nova-markdown.

dinandmentink avatar dinandmentink commented on May 25, 2024

Ok. This makes sense. I think I could make this. I'll make a note to add this in a future release. However, I'm quite swamped at the moment so this may take a while.

There may also be a nicer way than overriding the controller. Some kind of contract which specifies how to handle the upload itself.

Note that some of this behaviour could already be done by overriding the directory config item with a function (see readme). I use this myself for quite similar behaviour, minus the authorization.

Feel free to submit a PR if you want to have a go at it.

Closing; added to internal list of feature requests.

from nova-markdown.

lukebouch avatar lukebouch commented on May 25, 2024

@dinandmentink The reason I cannot use a function in the config is because my config is cached on deploy, but good thought.

from nova-markdown.

Related Issues (14)

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. 📊📈🎉

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google ❤️ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.