Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Going to http://sandbox.edit.io/?new=1 should open up a new page #229

Open
tcr opened this issue Dec 20, 2018 · 1 comment
Open

Going to http://sandbox.edit.io/?new=1 should open up a new page #229

tcr opened this issue Dec 20, 2018 · 1 comment
Labels
C-feature-small Category: small feature requiring few changes. good first issue

Comments

@tcr
Copy link
Owner

tcr commented Dec 20, 2018

Right now, going to sandbox.edit.io (or a locally running edit-text instance) will open up the document that corresponds to the requester's IP address, e.g. /welcome-127-0-0-1. This code lives in edit-server.rs:

// Upload files using /?from={url}
let load_doc = request.get_param("from")
.ok_or(format_err!("no from parameter to download from")) // TODO what is this line for
.and_then(|from| {
// Create a randomly-named page ID for this page.
id = random_id_alpha();
// Download directly from URLs.
// TODO is this irresponsible
if from.starts_with("http") {
let mut client = reqwest::Client::new();
let mut res = client.get(&from).send()?;
if !res.status().is_success() {
bail!("Unsuccessful request")
}
let md = res.text()?;
let doc = Doc(markdown_to_doc(&md)?);
Ok(match validate_doc(&doc) {
Ok(_) => doc,
Err(err) => {
eprintln!("Error decoding document: {:?}", err);
Doc(doc_span![
DocGroup({"tag": "pre"}, [
DocChars("Error decoding document.", {Style::Normie => None}),
]),
])
}
})
} else {
// Interpret as a Markdown document
let doc = Doc(markdown_to_doc(&from)?);
Ok(match validate_doc(&doc) {
Ok(_) => doc,
Err(err) => {
eprintln!("Error decoding document: {:?}", err);
Doc(doc_span![
DocGroup({"tag": "pre"}, [
DocChars("Error decoding document.", {Style::Normie => None}),
]),
])
}
})
}
})
.unwrap_or(default_doc());
// Initialize the "hello world" post.
eprintln!("creating helloworld post for {:?}", id);
get_or_create_page_graphql(&id, &load_doc);
return Response::redirect_302(format!("/{}", id));

We want to add another check just before this which looks to see if the parameter "new" exists, and if so, sets the id to a random value (using random_id_alpha). It should also set the document contents to default_doc(), so once it's generated there will be a basic document template for the user to edit.

Some expectations about how this works:

  • ?new=1 would redirect to a random document id with the header "Welcome" and some accompanying text.
  • If both new and from were supplied (e.g. ?new=1&from=markdown_content), we can assume that the "from" code will run last and take precedence.
  • The behavior for http://sandbox.edit.io/?new=1 should be identical to going to the URL http://sandbox.edit.io/?from=https:, which (due to a quirk of the code right now) does the same thing.
@briankabiro
Copy link
Contributor

briankabiro commented Jan 8, 2019

Starting on it. 💻

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
C-feature-small Category: small feature requiring few changes. good first issue
Projects
None yet
Development

No branches or pull requests

2 participants