matze / wastebin

wastebin is a pastebin 📝
https://bin.bloerg.net
MIT License
303 stars 28 forks source link

Download button #2

Closed yannickfunk closed 2 years ago

yannickfunk commented 2 years ago

This PR persists the file extension into the database and adds a download button for direct file download

matze commented 2 years ago

The download feature is much appreciated but why the need for the database layout change? The whole thing could be a lot simpler by just fetching the raw data from the database and then appending the extension on the response as requested by the user. Similar to how the paste view highlights on demand.

yannickfunk commented 2 years ago

My problem was that I couldn't see a way to obtain the extension after the paste was created. Initially I thought it is as easy is getting the extension from Entry because Entry is a 1:1 mapping to the db content. But it appeared that Entry doesn't 1:1 reflect the db content because extension is not persisted.

Could you point me to an alternative way to obtain the extension when download() https://github.com/yannickfunk/wastebin/blob/4e2b143e54af3138be0c839907ade805fed78d3f/src/rest.rs#L61 is called?

One dirty workaround I could imagine would be to use javascript to parse the extension from window.location.href and then pass it along with the id to the download/ route. But I don't like that

matze commented 2 years ago

Could you point me to an alternative way to obtain the extension

In the show handler id and ext are extracted from the final path segment. You could pass Key.ext (e.g using a getter) to the Paste template and reconstruct the filename there.

yannickfunk commented 2 years ago

Thanks a lot, totally missed that possibility. I added an updated version

matze commented 2 years ago

I'll approve and run the workflow but please squash the commits, so git bisect becomes a bit easier to do in the future.

yannickfunk commented 2 years ago

As far as I know you can just choose the squash option when merging with the github ui. Let me know if it doesn't work

matze commented 2 years ago

I always assume people want to craft their own commits but since you are okay with squashing :-) anyhow, thanks!