Skip to content

Add minimal pastebin behaviour#1546

Merged
svenstaro merged 9 commits intosvenstaro:masterfrom
rktjmp:feat-pastebin
Feb 10, 2026
Merged

Add minimal pastebin behaviour#1546
svenstaro merged 9 commits intosvenstaro:masterfrom
rktjmp:feat-pastebin

Conversation

@rktjmp
Copy link
Copy Markdown
Contributor

@rktjmp rktjmp commented Jan 10, 2026

Fixes #1475

image

My usage for this is wanting to share text between systems on an authenticated network, any more complicated "password protection", "secret" or "expiry" behaviour seen on other pastebins is out of scope. Protecting the "pastebin" can be done by existing methods in miniserve if desired. Viewing pastes is done by viewing the file in browser. I think that's inline with miniserves objectives, "For when you really just want to serve some files text content over HTTP right now! ".

The PR allows users to create plaintext 'pastes' from the webui. The interface can be enabled with the --pastebin cli argument and also requires --file-uploads to be enabled.

A textarea (required) input & title input (optional) are presented to the user. When the paste form is submitted, we create a plaintext file in memory and pass it to the exiting upload form. This means the pastebin behaviour inherits all behaviours associated with uploading files (eg: filename collisions).

If no title is given we generate a paste-{random-6-ch}.txt filename, otherwise the given title is suffixed with .txt, if required, and used as the filename.

This is a WIP/POC to see if the idea is acceptable, things not addressed:

  • mobile theming (its "ok")
    • any theming really, all css is inline.
  • 'short option' name (-P was already taken)
  • ctrl-enter should submit the form (common on the web).
  • potential notification of the name of a paste that was created?
    • I think you could actually skip this if no existing infra exists, and just rely on users giving their pastes a name if needed, otherwise they can sort by last-modified.
    • alternatively, support a fragment in the URL to highlight a file in the listing and just set that somehow on the return from uploading.

Allows users to create plaintext 'pastes' from the webui. The interface
can be enabled with the `--pastebin` cli argumen and also requires
`--file-uploads` to be enabled.

A textarea input & title field are presented to the user. When
the paste form is submitted, we create a plaintext file in memory and
pass it to the exiting upload form. This means the pastebin behaviour
inherits all behaviours associated with uploading files (eg: filename
collisions).

If no title is given we generate a `paste-{random-6-ch}.txt` filename,
otherwise the given title is suffixed with `.txt`, if required, and used
as the filename.
@svenstaro
Copy link
Copy Markdown
Owner

I love this! Could you move the button a bit so save some space?
image

I don't think we need a shortcut for this, --pastebin should be fine.

Please continue implementing this with tests and your other TODOs. :)

@svenstaro
Copy link
Copy Markdown
Owner

Do you think you'll have some time soon-ish to work on this so I can ship this in the next release of miniserve?

@rktjmp
Copy link
Copy Markdown
Contributor Author

rktjmp commented Jan 20, 2026

Yep I will try and get it out tonight.

Creates a "stack" for upload + mkdir tools, with pastebin next to it
taking any remaining space. When the window is small, all tools are
stacked vertical. If pastebin is not enabled, upload + mkdir are
rendered horizontally with width: min-content.
@rktjmp
Copy link
Copy Markdown
Contributor Author

rktjmp commented Jan 20, 2026

This is where I got up to tonight.

I went with a system to stack upload+mkdir on the left if needed when pastebin is present, otherwise they're as they were-ish. There is an issue at around 860-760px wide, we run out of crushing space so the tools start to overrun the container. Couldn't really get it to behave in a satisfying way but it's kind of non-blocking IMO? It's solvable with media queries but if I started doing that I felt like it was better to rework them all to be mobile-first first.

I looked at tests but for upload + mkdir we build the http requests directly in the test then post to the server which isn't really applicable here as the paste interface just hits the upload interface via javascript. It would just read exactly the same as the regular upload test. I added one pretty dumb one, and wasn't sure how to check the server refused to start without --upload-files also being given (TestServer didn't have any kind of PID to check against, could check stderr?) but I dunno if you want to even test that really.

I also changed the language from "paste" to "file" as that seemed a bit more obvious. Dunno if --pastebin could have an alias --create-file-interface or something more "obvious".

image image image image image

@svenstaro svenstaro marked this pull request as draft February 8, 2026 04:12
@svenstaro svenstaro changed the title feat(wip): add minimal pastebin behaviour Add minimal pastebin behaviour Feb 8, 2026
Copy link
Copy Markdown
Owner

@svenstaro svenstaro left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I really like the effort you put into wrangling the CSS. Would just like to see some tests and then I think we're actually good to merge this. The JS looks fine, maybe sprinkle in a few comments about what you're doing and we're good.

Only one test really applicable to the pastebin functionality.
@rktjmp rktjmp marked this pull request as ready for review February 8, 2026 09:26
@rktjmp
Copy link
Copy Markdown
Contributor Author

rktjmp commented Feb 8, 2026

Probably ready to go I think. The CSS is still a bit awkward at some between-breakpoint limbo sizes but not in a blocking way.

@svenstaro
Copy link
Copy Markdown
Owner

Could you make cargo fmt happy?

@svenstaro svenstaro merged commit 77ddd7e into svenstaro:master Feb 10, 2026
18 checks passed
@svenstaro
Copy link
Copy Markdown
Owner

Very cool!

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

Suggestion: "pastebin" feature

2 participants