forked from realaravinth/libmedium
Compare commits
60 commits
chore-rm-g
...
master
Author | SHA1 | Date | |
---|---|---|---|
02b20ba677 | |||
ec522a5bb2 | |||
7e5469ad2e | |||
2a4f8ce539 | |||
|
74bf91b976 | ||
|
91c46a64ae | ||
2cec7c2ad2 | |||
c64b40c616 | |||
c249ebeb8b | |||
|
1db3171069 | ||
|
c41f5649e6 | ||
84bb01dbb3 | |||
1b8c15aded | |||
aae35112cd | |||
bfee1f132d | |||
|
fc55eb4de0 | ||
|
888354ed5c | ||
|
4665d2ff87 | ||
|
2b5e82878e | ||
02280710a0 | |||
|
b0183fa2b3 | ||
da71fc1d08 | |||
|
ae52cc555f | ||
eb5f3067c1 | |||
|
3111f3e25c | ||
8bddddea2c | |||
|
e42bff0b5c | ||
1bf1d60cd9 | |||
|
b261bee2f1 | ||
64313eca1f | |||
|
b373dcd75a | ||
b6f916f5f9 | |||
3cf66d941f | |||
fce6090bfa | |||
6586c02cbf | |||
8b9819008a | |||
|
fa38ee17e2 | ||
|
e3a862905d | ||
|
825b01cfa6 | ||
|
19996e67f3 | ||
|
4d7283c3da | ||
d621853a1d | |||
|
b0b09176c5 | ||
2ca90b1d3f | |||
|
b8c3e17404 | ||
8fc0f8f0d5 | |||
|
ecbcf02d4d | ||
ea24dca77d | |||
|
3714d29a23 | ||
4f6d4b709e | |||
95616fef4a | |||
0b3a43088b | |||
ac503b0b06 | |||
883c609412 | |||
|
d44cf2d5c6 | ||
8ee266d846 | |||
c07c5798d9 | |||
63ef7f75ba | |||
b53ac22ba4 | |||
|
d3b4ae0952 |
9 changed files with 479 additions and 417 deletions
|
@ -31,7 +31,6 @@ steps:
|
|||
when:
|
||||
event: [push, tag, deployment]
|
||||
branch: master
|
||||
secrets: [docker_token]
|
||||
settings:
|
||||
repo: realaravinth/libmedium
|
||||
username: realaravinth
|
||||
|
|
797
Cargo.lock
generated
797
Cargo.lock
generated
File diff suppressed because it is too large
Load diff
|
@ -16,7 +16,7 @@ actix-rt = "2"
|
|||
actix-web = "4.0.1"
|
||||
bincode = "1.3.3"
|
||||
chrono = "0.4.23"
|
||||
config = "0.13"
|
||||
config = "0.14"
|
||||
derive_more = "0.99"
|
||||
futures = "0.3.17"
|
||||
lazy_static = "1.4"
|
||||
|
|
|
@ -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://read.sudovanilla.com | US | Cloudflare | [SudoVanilla](https://sudovanilla.com) |
|
||||
| https://r.sudovanilla.org | US | Selfhosted | [SudoVanilla](https://sudovanilla.org) |
|
||||
| https://libmedium.ducks.party | DE | Datalix | [ducks.party](https://ducks.party) |
|
||||
## Deploy
|
||||
|
||||
|
|
20
src/data.rs
20
src/data.rs
|
@ -164,14 +164,14 @@ impl Data {
|
|||
}
|
||||
}
|
||||
|
||||
pub async fn get_post_light(&self, id: &str) -> PostUrl {
|
||||
pub async fn get_post_light(&self, id: &str) -> Option<PostUrl> {
|
||||
match self.posts.get(id) {
|
||||
Ok(Some(v)) => {
|
||||
let cached: PostResp = bincode::deserialize(&v[..]).unwrap();
|
||||
PostUrl {
|
||||
Some(PostUrl {
|
||||
slug: cached.unique_slug,
|
||||
username: cached.creator.username,
|
||||
}
|
||||
})
|
||||
}
|
||||
_ => {
|
||||
let vars = get_post_light::Variables { id: id.to_owned() };
|
||||
|
@ -180,10 +180,16 @@ impl Data {
|
|||
let res = post_graphql::<GetPostLight, _>(&self.client, URL, vars)
|
||||
.await
|
||||
.unwrap();
|
||||
let res = res.data.expect("missing response data").post.unwrap();
|
||||
PostUrl {
|
||||
slug: res.unique_slug,
|
||||
username: res.creator.username,
|
||||
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,
|
||||
}),
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
|
34
src/post.rs
34
src/post.rs
|
@ -345,6 +345,7 @@ 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 {
|
||||
|
@ -383,33 +384,42 @@ pub fn apply_markup(
|
|||
}
|
||||
|
||||
let mut content = String::with_capacity(p.text.len());
|
||||
content += &Markup::start(p, gists, pindex, &mut state);
|
||||
let start = &Markup::start(p, gists, pindex, &mut state);
|
||||
content += start;
|
||||
if start == "<pre>" {
|
||||
no_render_html = true;
|
||||
}
|
||||
pos.arr.sort();
|
||||
let mut page = String::default();
|
||||
if let Some(first) = pos.arr.first() {
|
||||
//content += p.text.substring(cur, *first as usize);
|
||||
content += p.text.slice(cur..*first as usize);
|
||||
page += 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 {
|
||||
// content += p.text.substring(cur, *point as usize);
|
||||
content += p.text.slice(cur..*point as usize);
|
||||
page += p.text.slice(cur..*point as usize);
|
||||
}
|
||||
// }
|
||||
let pos_markups = pos.map.get(point).unwrap();
|
||||
for m in pos_markups.iter() {
|
||||
content += &m.apply_markup(pindex);
|
||||
page += &m.apply_markup(pindex);
|
||||
}
|
||||
cur = incr_cur(cur, *point);
|
||||
}
|
||||
log::debug!("LAST");
|
||||
content += p.text.slice(cur..);
|
||||
content += &Markup::end(p, pindex, &mut state);
|
||||
page += p.text.slice(cur..);
|
||||
let end = &Markup::end(p, pindex, &mut state);
|
||||
if end == "</pre>" {
|
||||
no_render_html = false;
|
||||
}
|
||||
content += &page;
|
||||
content += end;
|
||||
} else {
|
||||
log::debug!("LAST WITH NO MARKUP");
|
||||
content += p.text.slice(cur..);
|
||||
page += p.text.slice(cur..);
|
||||
if no_render_html {
|
||||
page = page.replace("<", "<").replace(">", ">");
|
||||
}
|
||||
content += &page;
|
||||
content += &Markup::end(p, pindex, &mut state);
|
||||
}
|
||||
paragraphs.push(content);
|
||||
|
|
38
src/proxy.rs
38
src/proxy.rs
|
@ -158,29 +158,33 @@ 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 {
|
||||
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()
|
||||
match data.get_post_light(&path).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(),
|
||||
}
|
||||
}
|
||||
|
||||
#[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(),
|
||||
}
|
||||
} else {
|
||||
HttpResponse::NotFound().body("Post not found, please file bug report")
|
||||
}
|
||||
|
|
|
@ -7,7 +7,6 @@
|
|||
body {
|
||||
width: 100%;
|
||||
display: flex;
|
||||
flex-direction: column;
|
||||
}
|
||||
|
||||
main {
|
||||
|
|
|
@ -317,7 +317,6 @@ padding: 0;
|
|||
body {
|
||||
width: 100%;
|
||||
display: flex;
|
||||
flex-direction: column;
|
||||
}
|
||||
main {
|
||||
width: 35em;
|
||||
|
|
Loading…
Reference in a new issue