This repository has been archived by the owner on Jul 20, 2020. It is now read-only.
-
Notifications
You must be signed in to change notification settings - Fork 1
Add basic example to page content renderer #39
Open
notgull
wants to merge
3
commits into
master
Choose a base branch
from
fill-page
base: master
Could not load branches
Branch not found: {{ refName }}
Loading
Could not load tags
Nothing to show
Loading
Are you sure you want to change the base?
Some commits from the old base branch may be removed from the timeline,
and old review comments may become outdated.
Open
Changes from 1 commit
Commits
Show all changes
3 commits
Select commit
Hold shift + click to select a range
File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -47,20 +47,20 @@ pub async fn get_deepwell_page( | |
wiki_id: WikiId, | ||
slug: &str, | ||
deepwell: &web::Data<DeepwellPool>, | ||
) -> std::result::Result<HttpResponse, ()> { | ||
) -> Option<HttpResponse> { | ||
debug!("Retrieving page by WikiId {} and slug {}", wiki_id, slug); | ||
let result = deepwell | ||
.claim() | ||
.await | ||
.get_page_contents(wiki_id.clone(), slug.to_string()) | ||
.await; | ||
|
||
match try_io_result!(result) { | ||
match try_io_option!(result) { | ||
Ok(Some(page)) => { | ||
// now run FTML on it | ||
let mut contents = match String::from_utf8(page.to_vec()) { | ||
Ok(v) => v, | ||
Err(e) => return Ok(HttpResponse::InternalServerError().json(format!("{:?}", e))), | ||
Err(e) => return Some(HttpResponse::InternalServerError().json(format!("{:?}", e))), | ||
}; | ||
|
||
// TODO: something that uses Deepwell | ||
|
@@ -85,7 +85,7 @@ pub async fn get_deepwell_page( | |
|
||
let mut output = match renderer.transform(&mut contents, page_info, &remote_handle) { | ||
Ok(o) => o, | ||
Err(e) => return Ok(HttpResponse::InternalServerError().json(format!("{:?}", e))), | ||
Err(e) => return Some(HttpResponse::InternalServerError().json(format!("{:?}", e))), | ||
}; | ||
|
||
// TODO: use jinja/other templater to put this text into a better template | ||
|
@@ -101,13 +101,13 @@ pub async fn get_deepwell_page( | |
buffer.push_str(&output.html); | ||
buffer.push_str("</body></html>\n"); | ||
|
||
Ok(HttpResponse::Ok().json(buffer)) | ||
Some(HttpResponse::Ok().json(buffer)) | ||
} | ||
Ok(None) => Err(()), | ||
Ok(None) => None, | ||
Err(e) => { | ||
warn!("Failed to retrieve page contents: {}", e); | ||
|
||
Ok(HttpResponse::InternalServerError().json(e)) | ||
Some(HttpResponse::InternalServerError().json(e)) | ||
} | ||
} | ||
} | ||
|
@@ -118,8 +118,8 @@ pub async fn get_deepwell_page_wrapped( | |
deepwell: web::Data<DeepwellPool>, | ||
) -> 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 | ||
Some(o) => o, | ||
None => get_deepwell_page(wiki_id, "_404", &deepwell).await.unwrap(), // todo: make this safer | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe 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
instead (or
for constants or cheap evaluations) There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. This pattern doesn't seem to work, since the There was a problem hiding this comment. Choose a reason for hiding this commentThe 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. |
||
} | ||
} | ||
|
||
|
@@ -142,7 +142,7 @@ pub async fn page_main(req: HttpRequest, deepwell: web::Data<DeepwellPool>) -> H | |
info!("GET / [{}]", host.unwrap_or("none")); | ||
|
||
let page_req = PageRequest { | ||
slug: "", | ||
slug: "main", | ||
categories: Vec::new(), | ||
arguments: HashMap::new(), | ||
}; | ||
|
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
There was a problem hiding this comment.
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]>
toString
. I'll check if wikidot has any non-UTF-8 pages.