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

Add basic example to page content renderer#39

Open
notgull wants to merge 3 commits into
masterfrom
fill-page
Open

Add basic example to page content renderer#39
notgull wants to merge 3 commits into
masterfrom
fill-page

Conversation

@notgull

@notgull notgull commented Mar 3, 2020

Copy link
Copy Markdown
Contributor

No description provided.

Comment thread Cargo.toml
deepwell-core = { path = "../deepwell/deepwell-core" }
deepwell-rpc = { path = "../deepwell-rpc" }
dns-lookup = "1"
ftml = { path = "../ftml" }

Copy link
Copy Markdown
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.

Comment thread src/route/macros.rs Outdated
Ok(object) => object,
Err(error) => {
let error = Error::ServiceTransport(error).to_sendable();
let error = deepwell_core::error::Error::ServiceTransport(error).to_sendable();

Copy link
Copy Markdown
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();

Comment thread src/route/page.rs Outdated
wiki_id: WikiId,
slug: &str,
deepwell: &web::Data<DeepwellPool>,
) -> std::result::Result<HttpResponse, ()> {

Copy link
Copy Markdown
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

Comment thread src/route/macros.rs
}
};
}

Copy link
Copy Markdown
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)

Comment thread src/route/page.rs Outdated
) -> 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
Copy Markdown
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
Copy Markdown
Contributor 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?

Comment thread src/route/page.rs Outdated

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

Copy link
Copy Markdown
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.

Comment thread src/route/page.rs
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
Copy Markdown
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.

Comment thread src/route/page.rs Outdated
buffer.push_str(&output.html);
buffer.push_str("</body></html>\n");

Ok(HttpResponse::Ok().json(buffer))

Copy link
Copy Markdown
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

Comment thread src/route/page.rs

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

Copy link
Copy Markdown
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.

Comment thread src/route/page.rs Outdated
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

@emmiegit emmiegit Mar 6, 2020

Copy link
Copy Markdown
Member

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
Copy Markdown
Contributor 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
Copy Markdown
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.

2 participants