forked from realaravinth/libmedium
feat: use medium.com's URL patterns
closes: https://github.com/realaravinth/libmedium/issues/28
This commit is contained in:
parent
a1491cb8d0
commit
2272eaa90c
2 changed files with 20 additions and 1 deletions
20
src/proxy.rs
20
src/proxy.rs
|
@ -34,6 +34,7 @@ pub mod routes {
|
||||||
pub by_post_id: &'static str,
|
pub by_post_id: &'static str,
|
||||||
pub page: &'static str,
|
pub page: &'static str,
|
||||||
pub asset: &'static str,
|
pub asset: &'static str,
|
||||||
|
pub top_level_post: &'static str,
|
||||||
}
|
}
|
||||||
|
|
||||||
impl Proxy {
|
impl Proxy {
|
||||||
|
@ -43,6 +44,7 @@ pub mod routes {
|
||||||
by_post_id: "/utils/post/{post}",
|
by_post_id: "/utils/post/{post}",
|
||||||
page: "/{username}/{post}",
|
page: "/{username}/{post}",
|
||||||
asset: "/asset/medium/{name}",
|
asset: "/asset/medium/{name}",
|
||||||
|
top_level_post: "/{post}",
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
pub fn get_page(&self, username: &str, post: &str) -> String {
|
pub fn get_page(&self, username: &str, post: &str) -> String {
|
||||||
|
@ -167,6 +169,23 @@ async fn by_post_id(path: web::Path<String>, data: AppData) -> impl Responder {
|
||||||
.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() {
|
||||||
|
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()
|
||||||
|
} else {
|
||||||
|
HttpResponse::NotFound().body("Post not found, please file bug report")
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
#[actix_web_codegen_const_routes::get(path = "crate::V1_API_ROUTES.proxy.page")]
|
#[actix_web_codegen_const_routes::get(path = "crate::V1_API_ROUTES.proxy.page")]
|
||||||
async fn page(path: web::Path<(String, String)>, data: AppData) -> impl Responder {
|
async fn page(path: web::Path<(String, String)>, data: AppData) -> impl Responder {
|
||||||
let post_id = path.1.split('-').last();
|
let post_id = path.1.split('-').last();
|
||||||
|
@ -238,6 +257,7 @@ pub fn services(cfg: &mut web::ServiceConfig) {
|
||||||
cfg.service(by_post_id);
|
cfg.service(by_post_id);
|
||||||
cfg.service(assets);
|
cfg.service(assets);
|
||||||
cfg.service(page);
|
cfg.service(page);
|
||||||
|
cfg.service(by_top_level_post);
|
||||||
cfg.service(index);
|
cfg.service(index);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
|
@ -69,7 +69,6 @@ impl Settings {
|
||||||
|
|
||||||
s = s.add_source(Environment::with_prefix("PAGES").separator("__"));
|
s = s.add_source(Environment::with_prefix("PAGES").separator("__"));
|
||||||
|
|
||||||
|
|
||||||
match env::var("PORT") {
|
match env::var("PORT") {
|
||||||
Ok(val) => {
|
Ok(val) => {
|
||||||
s = s.set_override("server.port", val).unwrap();
|
s = s.set_override("server.port", val).unwrap();
|
||||||
|
|
Loading…
Reference in a new issue