Compare commits

..

No commits in common. "b5e30e467b9997209925b32748bca166e9bd99c2" and "2987221c93e38d8ae3fe064f0c904e3c05a3f068" have entirely different histories.

10 changed files with 65 additions and 31 deletions

1
Cargo.lock generated
View File

@ -1187,6 +1187,7 @@ dependencies = [
"tokio",
"tracing",
"tracing-subscriber",
"url",
]
[[package]]

View File

@ -8,4 +8,5 @@ rocket = {path = "../Rocket/core/lib"}
tokio = { version = "1.40.0", features = ["full"] }
tracing = "0.1.40"
tracing-subscriber = "0.3.18"
url = "2.5.2"
minio = {git="https://github.com/minio/minio-rs.git", rev = "c28f576"}

View File

@ -1,13 +0,0 @@
function handle(requestDetails) {
let b64 = btoa(requestDetails.url)
// let original = atob(b64);
// console.log(`Loading: ${requestDetails.url} || ${b64}`);
return {
redirectUrl: `http://localhost:4433/s3/${b64}`
}
}
browser.webRequest.onBeforeRequest.addListener(
handle, { urls: ["<all_urls>"] }, ["blocking"]
);

14
browser/main/main.html Normal file
View File

@ -0,0 +1,14 @@
<!DOCTYPE html>
<html>
<head>
<meta charset="utf-8">
<meta http-equiv="X-UA-Compatible" content="IE=edge">
<title></title>
<meta name="description" content="">
<meta name="viewport" content="width=device-width, initial-scale=1">
</head>
<body>
<h1>Now click "load" in the extension window</h1>
<div id="anchor" hidden></div>
</body>
</html>

View File

@ -4,14 +4,8 @@
"version": "0.1",
"description": "Adds a red border to all webpages matching mozilla.org.",
"permissions": [
"activeTab",
"webRequest",
"webRequestBlocking",
"<all_urls>"
"activeTab"
],
"background": {
"scripts": ["background.js"]
},
"browser_action": {
"default_icon": "icon.png",
"default_title": "Click me!",

13
browser/popup/inject.js Normal file
View File

@ -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;
})
}

View File

@ -5,9 +5,10 @@
</head>
<body>
<button id="">On</button>
<button id="">Off</button>
<button id="newtab">Open canvas</button>
<button id="replacer">Load page</button>
<p id="output"></p>
<script src="popup.js"></script>
</body>
<style>
html {

21
browser/popup/popup.js Normal file
View File

@ -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}";
`

View File

@ -1,6 +1,7 @@
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;
mod s3;
@ -20,7 +21,7 @@ async fn main() {
.init();
let config = Config {
s3_bucket: "b64v1",
s3_bucket: "v1.10",
s3_url: "http://localhost:9000",
s3_access_key: "8UO76z8wCs9DnpxSbQUY",
s3_secret_key: "xwKVMpf2jzgprsdo85Dvo74UmO84y0aRrAUorYY5",
@ -41,12 +42,14 @@ async fn main() {
}
#[get("/s3/<path>")]
async fn get_s3_content(path: &str, db: &State<S3>) -> Option<String> {
if let Some(resp) = db.get(&path).await {
return Some(resp)
async fn get_s3_content(path: &str, db: &State<S3>) -> String {
info!(path);
// TODO this is just pseudo-code
let url = "en.wikipedia.org/wiki/CNBC";
if let Some(resp) = db.get(&url).await {
return resp
}
// instead of some/none I would rather this be 200/404
None
"Hello world.".to_owned()
}
// CORS, to allow other sites to request this from their front-end
@ -66,7 +69,5 @@ impl Fairing for CORS {
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"));
// TODO set this automatically like how Rocket/core/lib/src/fs/server.rs does (bottom of file)
response.set_header(Header::new("Content-Type", "text/html"));
}
}

View File

@ -2,6 +2,7 @@ use minio::s3::{
args::{BucketExistsArgs, MakeBucketArgs}, client::ClientBuilder, creds::StaticProvider, error::Error, http::BaseUrl, types::S3Api, Client
};
use tracing::{instrument, trace};
use url::Url;
use crate::Config;
@ -34,7 +35,7 @@ impl S3 {
.await?;
}
trace!("Connection successful");
trace!("Connection successfull");
Ok(Self {
bucket_name: config.s3_bucket.to_owned(),