diff --git a/browser/icon.png b/browser/icon.png new file mode 100644 index 0000000..6b41a93 Binary files /dev/null and b/browser/icon.png differ diff --git a/browser/jsconfig.json b/browser/jsconfig.json new file mode 100644 index 0000000..e90bc9d --- /dev/null +++ b/browser/jsconfig.json @@ -0,0 +1,5 @@ +{ + "typeAcquisition": { + "include": ["firefox-webext-browser"] + } +} diff --git a/browser/main/main.html b/browser/main/main.html new file mode 100644 index 0000000..0a4ceb5 --- /dev/null +++ b/browser/main/main.html @@ -0,0 +1,14 @@ + + + + + + + + + + +

Now click "load" in the extension window

+ + + \ No newline at end of file diff --git a/browser/manifest.json b/browser/manifest.json new file mode 100644 index 0000000..c1d8e0c --- /dev/null +++ b/browser/manifest.json @@ -0,0 +1,14 @@ +{ + "manifest_version": 2, + "name": "Viewer", + "version": "0.1", + "description": "Adds a red border to all webpages matching mozilla.org.", + "permissions": [ + "activeTab" + ], + "browser_action": { + "default_icon": "icon.png", + "default_title": "Click me!", + "default_popup": "popup/popup.html" + } +} \ No newline at end of file diff --git a/browser/popup/inject.js b/browser/popup/inject.js new file mode 100644 index 0000000..225d980 --- /dev/null +++ b/browser/popup/inject.js @@ -0,0 +1,13 @@ + +let anchor = document.getElementById('anchor'); +if (anchor) { + window.fetch(anchor.innerText) + .then(res => res.text()) + .then((body) => { + document.body.textContent = ""; + document.body.innerHTML = body; + }) + + +} + diff --git a/browser/popup/popup.html b/browser/popup/popup.html new file mode 100644 index 0000000..c5daa44 --- /dev/null +++ b/browser/popup/popup.html @@ -0,0 +1,23 @@ + + + + + + + + + +

+ + + + diff --git a/browser/popup/popup.js b/browser/popup/popup.js new file mode 100644 index 0000000..17c0d90 --- /dev/null +++ b/browser/popup/popup.js @@ -0,0 +1,21 @@ +const output = document.getElementById('output'); +let page_url = "http://127.0.0.1:4433/s3/style.css"; + +document.getElementById("newtab").addEventListener('click', async function(e) { + browser.tabs.create({ url: "/main/main.html" }).then((t) => { + if (t.id) { + output.innerText += t.id + } + }) +}) + +document.getElementById("replacer").addEventListener('click', async function(e) { + browser.tabs.executeScript({ code: injection }) + browser.tabs.executeScript({ file: "inject.js" }); +}) + + +const injection = ` +let head = document.getElementById('anchor'); +head.innerText = "${page_url}"; +` \ No newline at end of file diff --git a/src/main.rs b/src/main.rs index dc9ed71..04f2c19 100644 --- a/src/main.rs +++ b/src/main.rs @@ -1,4 +1,4 @@ -use rocket::{fs::FileServer, get, routes, State}; +use rocket::{fairing::{Fairing, Info, Kind}, fs::FileServer, get, http::Header, routes, Request, Response, State}; use s3::S3; use tracing::{info, Level}; use url::Url; @@ -28,18 +28,20 @@ async fn main() { }; let s3 = S3::connect(&config).await.expect("Failed to connect to minio, aborting."); + let cors = CORS; let _ = rocket::build() .mount("/", FileServer::new("www/")) .mount("/", routes![get_s3_content]) .manage(s3) + .attach(cors) .launch() .await; info!("Bye"); } -#[get("/")] +#[get("/s3/")] async fn get_s3_content(path: &str, db: &State) -> String { info!(path); // TODO this is just pseudo-code @@ -50,3 +52,22 @@ async fn get_s3_content(path: &str, db: &State) -> String { "Hello world.".to_owned() } +// CORS, to allow other sites to request this from their front-end +pub struct CORS; + +#[rocket::async_trait] +impl Fairing for CORS { + fn info(&self) -> Info { + Info { + name: "Add CORS headers to responses", + kind: Kind::Response + } + } + + async fn on_response<'r>(&self, _request: &'r Request<'_>, response: &mut Response<'r>) { + response.set_header(Header::new("Access-Control-Allow-Origin", "*")); + response.set_header(Header::new("Access-Control-Allow-Methods", "POST, GET, PATCH, OPTIONS")); + response.set_header(Header::new("Access-Control-Allow-Headers", "*")); + response.set_header(Header::new("Access-Control-Allow-Credentials", "true")); + } +} diff --git a/www/index.html b/www/index.html index 0b0f930..74b5e63 100644 --- a/www/index.html +++ b/www/index.html @@ -9,8 +9,8 @@ - Hello world - -
+

Hello 👋

+

Please install the extension from here!

+

This url is only for internal use, you won't get much out of it.

\ No newline at end of file diff --git a/www/main.js b/www/main.js deleted file mode 100644 index e69de29..0000000