mirror of
https://github.com/zed-industries/zed.git
synced 2025-01-12 05:15:00 +00:00
Avoid fetching GH releases in home route
Co-Authored-By: Antonio Scandurra <me@as-cii.com>
This commit is contained in:
parent
6e8d35379c
commit
1cfdd07d40
1 changed files with 4 additions and 42 deletions
|
@ -1,8 +1,5 @@
|
||||||
use crate::{
|
use crate::{AppState, Request, RequestExt as _};
|
||||||
auth::RequestExt as _, github::Release, AppState, LayoutData, Request, RequestExt as _,
|
use serde::Deserialize;
|
||||||
};
|
|
||||||
use comrak::ComrakOptions;
|
|
||||||
use serde::{Deserialize, Serialize};
|
|
||||||
use std::sync::Arc;
|
use std::sync::Arc;
|
||||||
use tide::{http::mime, log, Server};
|
use tide::{http::mime, log, Server};
|
||||||
|
|
||||||
|
@ -13,42 +10,7 @@ pub fn add_routes(app: &mut Server<Arc<AppState>>) {
|
||||||
}
|
}
|
||||||
|
|
||||||
async fn get_home(mut request: Request) -> tide::Result {
|
async fn get_home(mut request: Request) -> tide::Result {
|
||||||
#[derive(Serialize)]
|
let data = request.layout_data().await?;
|
||||||
struct HomeData {
|
|
||||||
#[serde(flatten)]
|
|
||||||
layout: Arc<LayoutData>,
|
|
||||||
releases: Option<Vec<Release>>,
|
|
||||||
}
|
|
||||||
|
|
||||||
let mut data = HomeData {
|
|
||||||
layout: request.layout_data().await?,
|
|
||||||
releases: None,
|
|
||||||
};
|
|
||||||
|
|
||||||
if let Some(user) = request.current_user().await? {
|
|
||||||
if user.is_insider {
|
|
||||||
data.releases = Some(
|
|
||||||
request
|
|
||||||
.state()
|
|
||||||
.repo_client
|
|
||||||
.releases()
|
|
||||||
.await?
|
|
||||||
.into_iter()
|
|
||||||
.filter_map(|mut release| {
|
|
||||||
if release.draft {
|
|
||||||
None
|
|
||||||
} else {
|
|
||||||
let mut options = ComrakOptions::default();
|
|
||||||
options.render.unsafe_ = true; // Allow raw HTML in the markup. We control these release notes anyway.
|
|
||||||
release.body = comrak::markdown_to_html(&release.body, &options);
|
|
||||||
Some(release)
|
|
||||||
}
|
|
||||||
})
|
|
||||||
.collect(),
|
|
||||||
);
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
Ok(tide::Response::builder(200)
|
Ok(tide::Response::builder(200)
|
||||||
.body(request.state().render_template("home.hbs", &data)?)
|
.body(request.state().render_template("home.hbs", &data)?)
|
||||||
.content_type(mime::HTML)
|
.content_type(mime::HTML)
|
||||||
|
@ -114,4 +76,4 @@ async fn get_release_asset(request: Request) -> tide::Result {
|
||||||
.content_type(mime::BYTE_STREAM)
|
.content_type(mime::BYTE_STREAM)
|
||||||
.body(body)
|
.body(body)
|
||||||
.build())
|
.build())
|
||||||
}
|
}
|
||||||
|
|
Loading…
Reference in a new issue