Skip to content

Commit

Permalink
refactor: change /users/ to /u/ and /pastes/ to /p/ for web UI
Browse files Browse the repository at this point in the history
  • Loading branch information
Kyle Clemens committed Jul 12, 2018
1 parent 98e0d28 commit 1fe6f5e
Show file tree
Hide file tree
Showing 13 changed files with 30 additions and 30 deletions.
2 changes: 1 addition & 1 deletion webserver/src/routes/api/pastes/post.rs
Original file line number Diff line number Diff line change
Expand Up @@ -61,7 +61,7 @@ fn post(info: InfoResult, user: OptionalUser, conn: DbConn) -> RouteResult<Outpu
None => paste.commit("Anonymous", "none", "create paste")?,
}

// TODO: eventually replace this all with a GET /pastes/<id>?full=true backend call
// TODO: eventually replace this all with a GET /p/<id>?full=true backend call
let files: Vec<OutputFile> = files
.into_iter()
.map(|x| OutputFile::new(x.id(), Some(x.name()), x.highlight_language(), None))
Expand Down
2 changes: 1 addition & 1 deletion webserver/src/routes/web/pastes/delete.rs
Original file line number Diff line number Diff line change
Expand Up @@ -18,7 +18,7 @@ use uuid::Uuid;

use std::str::FromStr;

#[delete("/pastes/<username>/<id>", format = "application/x-www-form-urlencoded", data = "<deletion>")]
#[delete("/p/<username>/<id>", format = "application/x-www-form-urlencoded", data = "<deletion>")]
fn delete(deletion: Form<PasteDeletion>, username: String, id: PasteId, user: OptionalWebUser, mut sess: Session, conn: DbConn) -> Result<Rst> {
let deletion = deletion.into_inner();

Expand Down
2 changes: 1 addition & 1 deletion webserver/src/routes/web/pastes/files/raw.rs
Original file line number Diff line number Diff line change
Expand Up @@ -31,7 +31,7 @@ impl<'r> Responder<'r> for As {
}


#[get("/pastes/<username>/<paste_id>/files/<file_id>/raw")]
#[get("/p/<username>/<paste_id>/files/<file_id>/raw")]
fn get(username: String, paste_id: PasteId, file_id: FileId, user: OptionalWebUser, conn: DbConn) -> Result<As> {
let paste: DbPaste = match paste_id.get(&conn)? {
Some(p) => p,
Expand Down
8 changes: 4 additions & 4 deletions webserver/src/routes/web/pastes/get.rs
Original file line number Diff line number Diff line change
Expand Up @@ -69,16 +69,16 @@ fn id(id: PasteId, user: OptionalWebUser, conn: DbConn) -> Result<Rst> {
&username,
PATH_SEGMENT_ENCODE_SET,
);
Ok(Rst::Redirect(Redirect::to(&format!("/pastes/{}/{}", owner, id))))
Ok(Rst::Redirect(Redirect::to(&format!("/p/{}/{}", owner, id))))
}

#[get("/<username>/<id>", rank = 10)]
fn username_id(username: String, id: PasteId) -> Redirect {
let username = utf8_percent_encode(&username, PATH_SEGMENT_ENCODE_SET);
Redirect::to(&format!("/pastes/{}/{}", username, id))
Redirect::to(&format!("/p/{}/{}", username, id))
}

#[get("/pastes/<username>/<id>")]
#[get("/p/<username>/<id>")]
fn users_username_id(username: String, id: PasteId, config: State<Config>, user: OptionalWebUser, mut sess: Session, conn: DbConn) -> Result<Rst> {
let paste: DbPaste = match id.get(&conn)? {
Some(p) => p,
Expand Down Expand Up @@ -156,7 +156,7 @@ fn users_username_id(username: String, id: PasteId, config: State<Config>, user:
Ok(Rst::Template(Template::render("paste/index", ctx)))
}

#[get("/pastes/<username>/<id>/edit")]
#[get("/p/<username>/<id>/edit")]
fn edit(username: String, id: PasteId, config: State<Config>, user: OptionalWebUser, mut sess: Session, conn: DbConn) -> Result<Rst> {
let user = match user.into_inner() {
Some(u) => u,
Expand Down
4 changes: 2 additions & 2 deletions webserver/src/routes/web/pastes/patch.rs
Original file line number Diff line number Diff line change
Expand Up @@ -67,7 +67,7 @@ fn check_paste(paste: &PasteUpdate, files: &[MultiFile]) -> result::Result<(), S
Ok(())
}

#[patch("/pastes/<username>/<paste_id>", format = "application/x-www-form-urlencoded", data = "<update>")]
#[patch("/p/<username>/<paste_id>", format = "application/x-www-form-urlencoded", data = "<update>")]
fn patch(update: LenientForm<PasteUpdate>, username: String, paste_id: PasteId, user: OptionalWebUser, mut sess: Session, conn: DbConn) -> Result<Rst> {
let update = update.into_inner();
sess.set_form(&update);
Expand Down Expand Up @@ -243,7 +243,7 @@ fn patch(update: LenientForm<PasteUpdate>, username: String, paste_id: PasteId,
sess.take_form();

let username = utf8_percent_encode(&username, PATH_SEGMENT_ENCODE_SET);
Ok(Rst::Redirect(Redirect::to(&format!("/pastes/{}/{}", username, paste_id.simple()))))
Ok(Rst::Redirect(Redirect::to(&format!("/p/{}/{}", username, paste_id.simple()))))
}

#[derive(Debug, FromForm, Serialize)]
Expand Down
2 changes: 1 addition & 1 deletion webserver/src/routes/web/pastes/post.rs
Original file line number Diff line number Diff line change
Expand Up @@ -111,7 +111,7 @@ fn post(paste: Form<PasteUpload>, user: OptionalWebUser, mut sess: Session, conn
sess.take_form();

let username = utf8_percent_encode(username, PATH_SEGMENT_ENCODE_SET);
Ok(Redirect::to(&format!("/pastes/{}/{}", username, paste.id().simple())))
Ok(Redirect::to(&format!("/p/{}/{}", username, paste.id().simple())))
}

#[derive(Debug, FromForm, Serialize)]
Expand Down
2 changes: 1 addition & 1 deletion webserver/src/routes/web/pastes/revisions.rs
Original file line number Diff line number Diff line change
Expand Up @@ -19,7 +19,7 @@ use rocket_contrib::Template;

use std::result;

#[get("/pastes/<username>/<id>/revisions")]
#[get("/p/<username>/<id>/revisions")]
fn get(username: String, id: PasteId, config: State<Config>, user: OptionalWebUser, mut sess: Session, conn: DbConn) -> Result<Rst> {
let paste: DbPaste = match id.get(&conn)? {
Some(p) => p,
Expand Down
4 changes: 2 additions & 2 deletions webserver/src/routes/web/users/get.rs
Original file line number Diff line number Diff line change
Expand Up @@ -19,12 +19,12 @@ use rocket_contrib::Template;
use std::fs::File;
use std::io::Read;

#[get("/users/<username>")]
#[get("/u/<username>")]
fn get(username: String, config: State<Config>, user: OptionalWebUser, sess: Session, conn: DbConn) -> Result<Rst> {
_get(1, username, config, user, sess, conn)
}

#[get("/users/<username>?<params>")]
#[get("/u/<username>?<params>")]
fn get_page(username: String, params: PageParams, config: State<Config>, user: OptionalWebUser, sess: Session, conn: DbConn) -> Result<Rst> {
_get(params.page, username, config, user, sess, conn)
}
Expand Down
2 changes: 1 addition & 1 deletion webserver/web/templates/base.html.tera
Original file line number Diff line number Diff line change
Expand Up @@ -75,7 +75,7 @@
{% if user %}
<a
class="navbar-link"
href="/users/{{ user.username | urlencode(safe="") }}">{{ user.name }}</a>
href="/u/{{ user.username | urlencode(safe="") }}">{{ user.name }}</a>
{% else %}
<a class="navbar-link" href="/login">Log in</a>
{% endif %}
Expand Down
6 changes: 3 additions & 3 deletions webserver/web/templates/paste/edit.html.tera
Original file line number Diff line number Diff line change
Expand Up @@ -76,8 +76,8 @@ Edit untitled paste
</div>
<div class="left tabs">
<ul>
<li><a href="/pastes/{{ author_name | urlencode(safe="") }}/{{ paste.id }}">files</a></li>
<li><a href="/pastes/{{ author_name | urlencode(safe="") }}/{{ paste.id }}/revisions">revisions <span class="right tag">{{ num_commits }}</span></a></li>
<li><a href="/p/{{ author_name | urlencode(safe="") }}/{{ paste.id }}">files</a></li>
<li><a href="/p/{{ author_name | urlencode(safe="") }}/{{ paste.id }}/revisions">revisions <span class="right tag">{{ num_commits }}</span></a></li>
</ul>
</div>
</div>
Expand All @@ -86,7 +86,7 @@ Edit untitled paste
{% endblock header %}

{% block main %}
<form id="paste_upload" method="post" action="/pastes/{{ author_name | urlencode(safe="") }}/{{ paste.id }}">
<form id="paste_upload" method="post" action="/p/{{ author_name | urlencode(safe="") }}/{{ paste.id }}">
<input type="hidden" name="_method" value="patch"/>
<input type="hidden" name="anti_csrf_token" value="{{ session.data.anti_csrf_token }}"/>
<div>
Expand Down
10 changes: 5 additions & 5 deletions webserver/web/templates/paste/index.html.tera
Original file line number Diff line number Diff line change
Expand Up @@ -57,7 +57,7 @@ untitled paste
<div class="field is-grouped">
{% if is_owner %}
<div class="control">
<a class="button is-info is-large" href="/pastes/{{ author_name | urlencode(safe="") }}/{{ paste.id }}/edit">
<a class="button is-info is-large" href="/p/{{ author_name | urlencode(safe="") }}/{{ paste.id }}/edit">
<span class="icon is-large">
<i class="fas fa-pencil-alt"></i>
</span>
Expand Down Expand Up @@ -101,8 +101,8 @@ untitled paste
</div>
<div class="left tabs">
<ul>
<li class="is-active"><a href="/pastes/{{ author_name | urlencode(safe="") }}/{{ paste.id }}">files</a></li>
<li><a href="/pastes/{{ author_name | urlencode(safe="") }}/{{ paste.id }}/revisions">revisions <span class="right tag">{{ num_commits }}</span></a></li>
<li class="is-active"><a href="/p/{{ author_name | urlencode(safe="") }}/{{ paste.id }}">files</a></li>
<li><a href="/p/{{ author_name | urlencode(safe="") }}/{{ paste.id }}/revisions">revisions <span class="right tag">{{ num_commits }}</span></a></li>
</ul>
</div>
</div>
Expand All @@ -113,7 +113,7 @@ untitled paste
{% block main %}
{% if not paste.author or is_owner %}
<div id="deletion_modal" class="modal">
<form id="deletion_form" action="/pastes/{{ author_name | urlencode(safe="") }}/{{ paste.id }}" method="post">
<form id="deletion_form" action="/p/{{ author_name | urlencode(safe="") }}/{{ paste.id }}" method="post">
<input type="hidden" name="_method" value="delete"/>
<input type="hidden" name="anti_csrf_token" value="{{ session.data.anti_csrf_token }}"/>
<div class="modal-background closes-modal"></div>
Expand Down Expand Up @@ -195,7 +195,7 @@ untitled paste
</div>
{% endif %}
</div>
<a class="is-pulled-right button" href="/pastes/{{ author_name | urlencode(safe="") }}/{{ paste.id }}/files/{{ file.id }}/raw">Raw</a>
<a class="is-pulled-right button" href="/p/{{ author_name | urlencode(safe="") }}/{{ paste.id }}/files/{{ file.id }}/raw">Raw</a>
</div>
{% endif %}
{% if file.content.format == "text" %}
Expand Down
6 changes: 3 additions & 3 deletions webserver/web/templates/paste/revisions.html.tera
Original file line number Diff line number Diff line change
Expand Up @@ -58,7 +58,7 @@ untitled paste
<div class="field is-grouped">
{% if is_owner %}
<div class="control">
<a class="button is-info is-large" href="/pastes/{{ author_name | urlencode(safe="") }}/{{ paste.id }}/edit">
<a class="button is-info is-large" href="/p/{{ author_name | urlencode(safe="") }}/{{ paste.id }}/edit">
<span class="icon is-large">
<i class="fas fa-pencil-alt"></i>
</span>
Expand Down Expand Up @@ -101,8 +101,8 @@ untitled paste
</div>
<div class="left tabs">
<ul>
<li><a href="/pastes/{{ author_name | urlencode(safe="") }}/{{ paste.id }}">files</a></li>
<li class="is-active"><a href="/pastes/{{ author_name | urlencode(safe="") }}/{{ paste.id }}/revisions">revisions <span class="right tag">{{ num_commits }}</span></a></li>
<li><a href="/p/{{ author_name | urlencode(safe="") }}/{{ paste.id }}">files</a></li>
<li class="is-active"><a href="/p/{{ author_name | urlencode(safe="") }}/{{ paste.id }}/revisions">revisions <span class="right tag">{{ num_commits }}</span></a></li>
</ul>
</div>
</div>
Expand Down
10 changes: 5 additions & 5 deletions webserver/web/templates/user/index.html.tera
Original file line number Diff line number Diff line change
Expand Up @@ -61,12 +61,12 @@
{% if page == 1 %}
<a class="pagination-previous" disabled>Previous</a>
{% else %}
<a href="/users/{{ target.username | urlencode(safe="") }}?page={{ page - 1 }}" class="pagination-previous">Previous</a>
<a href="/u/{{ target.username | urlencode(safe="") }}?page={{ page - 1 }}" class="pagination-previous">Previous</a>
{% endif %}
{% if page == last_page %}
<a class="pagination-next" disabled>Next</a>
{% else %}
<a href="/users/{{ target.username | urlencode(safe="") }}?page={{ page + 1 }}" class="pagination-next">Next</a>
<a href="/u/{{ target.username | urlencode(safe="") }}?page={{ page + 1 }}" class="pagination-next">Next</a>
{% endif %}
</nav>

Expand All @@ -81,7 +81,7 @@
<div class="box-title">
<div>
<h3 class="title is-marginless">
<a href="/pastes/{{ target.username | urlencode(safe="") }}/{{ paste.id }}">
<a href="/p/{{ target.username | urlencode(safe="") }}/{{ paste.id }}">
{% if paste.name %}
<span class="keeps-spaces">{{ paste.name }}</span>
{% else %}
Expand Down Expand Up @@ -123,12 +123,12 @@
{% if page == 1 %}
<a class="pagination-previous" disabled>Previous</a>
{% else %}
<a href="/users/{{ target.username | urlencode(safe="") }}?page={{ page - 1 }}" class="pagination-previous">Previous</a>
<a href="/u/{{ target.username | urlencode(safe="") }}?page={{ page - 1 }}" class="pagination-previous">Previous</a>
{% endif %}
{% if page == last_page %}
<a class="pagination-next" disabled>Next</a>
{% else %}
<a href="/users/{{ target.username | urlencode(safe="") }}?page={{ page + 1 }}" class="pagination-next">Next</a>
<a href="/u/{{ target.username | urlencode(safe="") }}?page={{ page + 1 }}" class="pagination-next">Next</a>
{% endif %}
</nav>
{% endif %}
Expand Down

0 comments on commit 1fe6f5e

Please sign in to comment.