Skip to content

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

Description

@tcr

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.

Metadata

Metadata

Assignees

No one assigned

    Labels

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions