Skip to content
This repository has been archived by the owner on Jul 20, 2020. It is now read-only.

Add basic example to page content renderer #39

Open
wants to merge 3 commits into
base: master
Choose a base branch
from
Open

Conversation

notgull
Copy link
Member

@notgull notgull commented Mar 3, 2020

No description provided.

@@ -25,6 +25,7 @@ deadpool = { version = "0.5", features = ["unmanaged"] }
deepwell-core = { path = "../deepwell/deepwell-core" }
deepwell-rpc = { path = "../deepwell-rpc" }
dns-lookup = "1"
ftml = { path = "../ftml" }
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

You'll need to set travis to download it in order for builds to pass.

@@ -23,14 +23,27 @@ macro_rules! try_io {
match $result {
Ok(object) => object,
Err(error) => {
let error = Error::ServiceTransport(error).to_sendable();
let error = deepwell_core::error::Error::ServiceTransport(error).to_sendable();
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

N/B alternatively:

Suggested change
let error = deepwell_core::error::Error::ServiceTransport(error).to_sendable();
use deepwell_core::error::Error;
let error = Error::ServiceTransport(error).to_sendable();

wiki_id: WikiId,
slug: &str,
deepwell: &web::Data<DeepwellPool>,
) -> std::result::Result<HttpResponse, ()> {
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

use StdResult instead of std::result::Result

}
};
}

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Why is this necessary? (see below in its usage)

) -> HttpResponse {
match get_deepwell_page(wiki_id, slug, &deepwell).await {
Ok(o) => o,
Err(()) => get_deepwell_page(wiki_id, "_404", &deepwell).await.unwrap(), // todo: make this safer
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Agreed this needs to be a helper function. It's actually more complicated: it needs to return the _404 page for the requested page category.

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

How do I pass the categories along to deepwell?


Ok(HttpResponse::Ok().json(buffer))
}
Ok(None) => Err(()),
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Why are we returning an empty error? This case is if there's no page, we should return an Option not Err(()), it's confusing with the fact that there's an actual error case being handled here.

imo it should return Option<HttpResponse>, where None means no such page.

match try_io_result!(result) {
Ok(Some(page)) => {
// now run FTML on it
let mut contents = match String::from_utf8(page.to_vec()) {
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Hmm, we'll need to check if it's safe to switch from Box<[u8]> to String. I'll check if wikidot has any non-UTF-8 pages.

buffer.push_str(&output.html);
buffer.push_str("</body></html>\n");

Ok(HttpResponse::Ok().json(buffer))
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Returning JSON of a string seems pretty unnecessary. Either we return the string itself or we return the usual output from an API call output.

And yes I agree this is very ad-hoc implementation-wise

slug: "",
categories: Vec::new(),
arguments: HashMap::new(),
};

// TODO get page request
Ok(HttpResponse::NotImplemented().finish())
Ok(get_deepwell_page_wrapped(*TEMP_WIKI_ID, page_req.slug, deepwell).await)
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Slug needs to changed from "", which is invalid. We need to fetch what the root page is based on wiki settings.

Ok(o) => o,
Err(()) => get_deepwell_page(wiki_id, "_404", &deepwell).await.unwrap(), // todo: make this safer
Some(o) => o,
None => get_deepwell_page(wiki_id, "_404", &deepwell).await.unwrap(), // todo: make this safer
Copy link
Member

@emmiegit emmiegit Mar 6, 2020

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

In cases where you have

match item {
    Some(x) => x,
    None => something_else(n),
}

you can do

item.unwrap_or_else(|| something_else(n));

instead

(or

item.unwrap_or(10)

for constants or cheap evaluations)

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This pattern doesn't seem to work, since the None pattern here requires an async evaluation.

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

mhmm that is true. we should just work on getting the page handlers set up so we can call that instead.

Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

None yet

2 participants