forked from rust-lang/crates.io
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathreadmes.rs
40 lines (35 loc) · 1.04 KB
/
readmes.rs
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
//! Render README files to HTML.
use cargo_registry_markdown::text_to_html;
use swirl::PerformError;
use crate::background_jobs::Environment;
use crate::models::Version;
#[swirl::background_job]
pub fn render_and_upload_readme(
conn: &PgConnection,
env: &Environment,
version_id: i32,
text: String,
readme_path: String,
base_url: Option<String>,
pkg_path_in_vcs: Option<String>,
) -> Result<(), PerformError> {
use crate::schema::*;
use diesel::prelude::*;
let rendered = text_to_html(
&text,
&readme_path,
base_url.as_deref(),
pkg_path_in_vcs.as_deref(),
);
conn.transaction(|| {
Version::record_readme_rendering(version_id, conn)?;
let (crate_name, vers): (String, String) = versions::table
.find(version_id)
.inner_join(crates::table)
.select((crates::name, versions::num))
.first(&*conn)?;
env.uploader
.upload_readme(env.http_client(), &crate_name, &vers, rendered)?;
Ok(())
})
}