Compare commits

..

No commits in common. "master" and "chore-rm-gh-actions" have entirely different histories.

9 changed files with 415 additions and 477 deletions

View file

@ -31,6 +31,7 @@ steps:
when:
event: [push, tag, deployment]
branch: master
secrets: [docker_token]
settings:
repo: realaravinth/libmedium
username: realaravinth

793
Cargo.lock generated

File diff suppressed because it is too large Load diff

View file

@ -16,7 +16,7 @@ actix-rt = "2"
actix-web = "4.0.1"
bincode = "1.3.3"
chrono = "0.4.23"
config = "0.14"
config = "0.13"
derive_more = "0.99"
futures = "0.3.17"
lazy_static = "1.4"

View file

@ -57,7 +57,7 @@ business.
| http://md.vernccvbvyi5qhfzyqengccj7lkove6bjot2xhh5kajhwvidqafczrad.onion/ | N/A | Hetzner | [~vern](https://vern.cc) |
| http://vernaqj2qr2pijpgvf3od6ssc3ulz3nv52gwr3hba5l6humuzmgq.b32.i2p/ | N/A | Hetzner | [~vern](https://vern.cc) |
| https://medium.hostux.net | France | Gandi | [hostux](https://hostux.net) |
| https://r.sudovanilla.org | US | Selfhosted | [SudoVanilla](https://sudovanilla.org) |
| https://read.sudovanilla.com | US | Cloudflare | [SudoVanilla](https://sudovanilla.com) |
| https://libmedium.ducks.party | DE | Datalix | [ducks.party](https://ducks.party) |
## Deploy

View file

@ -164,14 +164,14 @@ impl Data {
}
}
pub async fn get_post_light(&self, id: &str) -> Option<PostUrl> {
pub async fn get_post_light(&self, id: &str) -> PostUrl {
match self.posts.get(id) {
Ok(Some(v)) => {
let cached: PostResp = bincode::deserialize(&v[..]).unwrap();
Some(PostUrl {
PostUrl {
slug: cached.unique_slug,
username: cached.creator.username,
})
}
}
_ => {
let vars = get_post_light::Variables { id: id.to_owned() };
@ -180,16 +180,10 @@ impl Data {
let res = post_graphql::<GetPostLight, _>(&self.client, URL, vars)
.await
.unwrap();
if res.data.is_none() {
None
} else {
match res.data.expect("missing response data").post {
None => None,
Some(res) => Some(PostUrl {
slug: res.unique_slug,
username: res.creator.username,
}),
}
let res = res.data.expect("missing response data").post.unwrap();
PostUrl {
slug: res.unique_slug,
username: res.creator.username,
}
}
}

View file

@ -345,7 +345,6 @@ pub fn apply_markup(
) -> Vec<String> {
let mut paragraphs: Vec<String> = Vec::with_capacity(data.content.body_model.paragraphs.len());
let mut state = ListState::default();
let mut no_render_html = false;
for (pindex, p) in data.content.body_model.paragraphs.iter().enumerate() {
let mut pos = PositionMap::default();
if p.type_ == "H3" && pindex == 0 {
@ -384,42 +383,33 @@ pub fn apply_markup(
}
let mut content = String::with_capacity(p.text.len());
let start = &Markup::start(p, gists, pindex, &mut state);
content += start;
if start == "<pre>" {
no_render_html = true;
}
content += &Markup::start(p, gists, pindex, &mut state);
pos.arr.sort();
let mut page = String::default();
if let Some(first) = pos.arr.first() {
page += p.text.slice(cur..*first as usize);
//content += p.text.substring(cur, *first as usize);
content += p.text.slice(cur..*first as usize);
cur = incr_cur(cur, *first);
for point in pos.arr.iter() {
//content.push(p.text.substring(start, start + point);
// if *point != 0 {
if cur != *point as usize {
page += p.text.slice(cur..*point as usize);
// content += p.text.substring(cur, *point as usize);
content += p.text.slice(cur..*point as usize);
}
// }
let pos_markups = pos.map.get(point).unwrap();
for m in pos_markups.iter() {
page += &m.apply_markup(pindex);
content += &m.apply_markup(pindex);
}
cur = incr_cur(cur, *point);
}
log::debug!("LAST");
page += p.text.slice(cur..);
let end = &Markup::end(p, pindex, &mut state);
if end == "</pre>" {
no_render_html = false;
}
content += &page;
content += end;
content += p.text.slice(cur..);
content += &Markup::end(p, pindex, &mut state);
} else {
log::debug!("LAST WITH NO MARKUP");
page += p.text.slice(cur..);
if no_render_html {
page = page.replace("<", "&lt;").replace(">", "&gt;");
}
content += &page;
content += p.text.slice(cur..);
content += &Markup::end(p, pindex, &mut state);
}
paragraphs.push(content);

View file

@ -158,33 +158,29 @@ async fn assets(path: web::Path<String>, data: AppData) -> impl Responder {
#[actix_web_codegen_const_routes::get(path = "crate::V1_API_ROUTES.proxy.by_post_id")]
async fn by_post_id(path: web::Path<String>, data: AppData) -> impl Responder {
match data.get_post_light(&path).await {
None => HttpResponse::NotFound().body("Post not found"),
Some(post_data) => HttpResponse::Found()
let post_data = data.get_post_light(&path).await;
HttpResponse::Found()
.append_header((
header::LOCATION,
crate::V1_API_ROUTES
.proxy
.get_page(&post_data.username, &post_data.slug),
))
.finish()
}
#[actix_web_codegen_const_routes::get(path = "crate::V1_API_ROUTES.proxy.top_level_post")]
async fn by_top_level_post(path: web::Path<String>, data: AppData) -> impl Responder {
if let Some(post_id) = path.split('-').last() {
let post_data = data.get_post_light(post_id).await;
HttpResponse::Found()
.append_header((
header::LOCATION,
crate::V1_API_ROUTES
.proxy
.get_page(&post_data.username, &post_data.slug),
))
.finish(),
}
}
#[actix_web_codegen_const_routes::get(path = "crate::V1_API_ROUTES.proxy.top_level_post")]
async fn by_top_level_post(path: web::Path<String>, data: AppData) -> impl Responder {
if let Some(post_id) = path.split('-').last() {
match data.get_post_light(post_id).await {
None => HttpResponse::NotFound().body("Post not found"),
Some(post_data) => HttpResponse::Found()
.append_header((
header::LOCATION,
crate::V1_API_ROUTES
.proxy
.get_page(&post_data.username, &post_data.slug),
))
.finish(),
}
.finish()
} else {
HttpResponse::NotFound().body("Post not found, please file bug report")
}

View file

@ -7,6 +7,7 @@
body {
width: 100%;
display: flex;
flex-direction: column;
}
main {

View file

@ -317,6 +317,7 @@ padding: 0;
body {
width: 100%;
display: flex;
flex-direction: column;
}
main {
width: 35em;