Merge branch 'improve-descriptions' into 'master'
Improve paste descriptions See merge request pastebin.run/server!90
This commit is contained in:
commit
87bad84cb3
|
@ -1,10 +1,12 @@
|
||||||
use crate::Connection;
|
use crate::Connection;
|
||||||
|
use std::borrow::Cow;
|
||||||
use warp::http::header::CONTENT_SECURITY_POLICY;
|
use warp::http::header::CONTENT_SECURITY_POLICY;
|
||||||
use warp::http::response::{Builder, Response};
|
use warp::http::response::{Builder, Response};
|
||||||
|
|
||||||
pub struct Session {
|
pub struct Session {
|
||||||
pub nonce: String,
|
pub nonce: String,
|
||||||
pub connection: Connection,
|
pub connection: Connection,
|
||||||
|
pub description: Cow<'static, str>,
|
||||||
}
|
}
|
||||||
|
|
||||||
impl Session {
|
impl Session {
|
||||||
|
|
|
@ -6,12 +6,13 @@ use crate::templates::{self, RenderRucte};
|
||||||
use diesel::prelude::*;
|
use diesel::prelude::*;
|
||||||
use futures::future::*;
|
use futures::future::*;
|
||||||
use futures03::TryFutureExt;
|
use futures03::TryFutureExt;
|
||||||
|
use std::borrow::Cow;
|
||||||
use tokio_executor::blocking;
|
use tokio_executor::blocking;
|
||||||
use warp::{Rejection, Reply};
|
use warp::{Rejection, Reply};
|
||||||
|
|
||||||
pub fn display_paste(
|
pub fn display_paste(
|
||||||
requested_identifier: String,
|
requested_identifier: String,
|
||||||
session: Session,
|
mut session: Session,
|
||||||
) -> impl Future<Item = impl Reply, Error = Rejection> {
|
) -> impl Future<Item = impl Reply, Error = Rejection> {
|
||||||
blocking::run(move || {
|
blocking::run(move || {
|
||||||
let connection = &session.connection;
|
let connection = &session.connection;
|
||||||
|
@ -34,6 +35,7 @@ pub fn display_paste(
|
||||||
.optional()
|
.optional()
|
||||||
.map_err(warp::reject::custom)?
|
.map_err(warp::reject::custom)?
|
||||||
.ok_or_else(warp::reject::not_found)?;
|
.ok_or_else(warp::reject::not_found)?;
|
||||||
|
session.description = generate_description(&paste.paste);
|
||||||
let selected_language = Some(paste.language_id);
|
let selected_language = Some(paste.language_id);
|
||||||
session.render().html(|o| {
|
session.render().html(|o| {
|
||||||
templates::display_paste(
|
templates::display_paste(
|
||||||
|
@ -49,3 +51,11 @@ pub fn display_paste(
|
||||||
})
|
})
|
||||||
.compat()
|
.compat()
|
||||||
}
|
}
|
||||||
|
|
||||||
|
fn generate_description(paste: &str) -> Cow<'static, str> {
|
||||||
|
let mut description = paste.chars().take(239).collect();
|
||||||
|
if description != paste {
|
||||||
|
description += "…";
|
||||||
|
}
|
||||||
|
description
|
||||||
|
}
|
||||||
|
|
|
@ -51,6 +51,7 @@ fn get_session(pool: PgPool) -> impl Future<Output = Result<Session, Rejection>>
|
||||||
Session {
|
Session {
|
||||||
nonce: base64::encode(&bytes),
|
nonce: base64::encode(&bytes),
|
||||||
connection,
|
connection,
|
||||||
|
description: "Compile and share code in multiple programming languages".into(),
|
||||||
}
|
}
|
||||||
})
|
})
|
||||||
}
|
}
|
||||||
|
|
|
@ -1,13 +1,13 @@
|
||||||
@use crate::models::session::Session;
|
@use crate::models::session::Session;
|
||||||
|
|
||||||
@(_session: &Session)
|
@(session: &Session)
|
||||||
|
|
||||||
<!DOCTYPE html>
|
<!DOCTYPE html>
|
||||||
<meta charset=utf-8>
|
<meta charset=utf-8>
|
||||||
<meta name=viewport content="width=device-width, initial-scale=1">
|
<meta name=viewport content="width=device-width, initial-scale=1">
|
||||||
<title>pastebin.run</title>
|
<title>pastebin.run</title>
|
||||||
<link rel=stylesheet href="/static/style.css">
|
<link rel=stylesheet href="/static/style.css">
|
||||||
<meta name=description content="Pastebin.run is a website for privately storing and sharing text online.">
|
<meta name=description content="@session.description">
|
||||||
<header id=header>
|
<header id=header>
|
||||||
<div>
|
<div>
|
||||||
<a href="/">
|
<a href="/">
|
||||||
|
|
Loading…
Reference in New Issue
Block a user