Skip to content

prx0/rocket-pastebin

Folders and files

NameName
Last commit message
Last commit date

Latest commit

 

History

20 Commits
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 

Repository files navigation

Rocket pastebin

Based on https://rocket.rs/v0.5-rc/guide/pastebin/

  • Add a web form to the index where users can manually input new pastes. Accept the form at POST /. Use format and/or rank to specify which of the two POST /routes should be called.
  • Support deletion of pastes by adding a new DELETE / route. Use PasteId to validate .
  • Indicate partial uploads with a 206 partial status code. If the user uploads a paste that meets or exceeds the allowed limit, return a 206 partial statuscode. Otherwise, return a 201 created status code.
  • Set the Content-Type of the return value in upload and retrieve to text/plain.
  • Return a unique "key" after each upload and require that the key is present and matches when doing deletion. Use one of Rocket's core traits to do the keyvalidation.
  • Add a PUT / route that allows a user with the key for to replace the existing paste, if any.
  • Add a new route, GET // that syntax highlights the paste with ID for language . If is not a known language, do no highlighting. Possibly validate with FromParam.
  • Use the local module to write unit tests for your pastebin.
  • Dispatch a thread before launching Rocket in main that periodically cleans up idling old pastes in upload/.

How to use ?

cargo run

Then, go open your browser and go to http://127.0.0.1:8000.

You can post a pastebin from a web page. Select the language and see the pastebin with syntax highlight using Prism.js

homepage example

Run test

cargo test && rm upload/*

Run test and remove files generated by tests.

Configuration

You can found a .env with these value by default.

ROCKET_PORT=8000
ROCKET_HOST=http://localhost
ROCKET_LIMITS={forms="128 KiB", file="128 KiB}
ROCKET_TEMPLATE_DIR=templates

FILE_LIFETIME_DURATION=300 # in secondes, Lifetime duration for uploaded file

Endpoint API

GET http://localhost:8000/api/pastebin/{id}

request parameter: id as PasteId.

result: type text/plain; charset=utf-8, represent a pastebin.

status code: Ok or NotFound if id does not exist

POST http://localhost:8000/api/pastebin/

body: type binary, represent your file.

result: type text/plain; charset=utf-8, represent a pastebin url

status code: Ok

PUT http://localhost:8000/api/pastebin/{id}

request parameter: id as PasteId.

body: type binary, represent the new file content which replace the older file content

result: type text/plain; charset=utf-8, represent a pastebin url

status code: Ok or NotFound if id does not exist

DELETE http://localhost:8000/api/pastebin/{id}

request parameter: id as PasteId.

result: type text/plain; charset=utf-8, represent a pastebin url

status code: Ok or NotFound if id does not exist