Compare commits
No commits in common. "b5e30e467b9997209925b32748bca166e9bd99c2" and "2987221c93e38d8ae3fe064f0c904e3c05a3f068" have entirely different histories.
b5e30e467b
...
2987221c93
1
Cargo.lock
generated
1
Cargo.lock
generated
@ -1187,6 +1187,7 @@ dependencies = [
|
|||||||
"tokio",
|
"tokio",
|
||||||
"tracing",
|
"tracing",
|
||||||
"tracing-subscriber",
|
"tracing-subscriber",
|
||||||
|
"url",
|
||||||
]
|
]
|
||||||
|
|
||||||
[[package]]
|
[[package]]
|
||||||
|
@ -8,4 +8,5 @@ rocket = {path = "../Rocket/core/lib"}
|
|||||||
tokio = { version = "1.40.0", features = ["full"] }
|
tokio = { version = "1.40.0", features = ["full"] }
|
||||||
tracing = "0.1.40"
|
tracing = "0.1.40"
|
||||||
tracing-subscriber = "0.3.18"
|
tracing-subscriber = "0.3.18"
|
||||||
|
url = "2.5.2"
|
||||||
minio = {git="https://github.com/minio/minio-rs.git", rev = "c28f576"}
|
minio = {git="https://github.com/minio/minio-rs.git", rev = "c28f576"}
|
||||||
|
@ -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
14
browser/main/main.html
Normal 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>
|
@ -4,14 +4,8 @@
|
|||||||
"version": "0.1",
|
"version": "0.1",
|
||||||
"description": "Adds a red border to all webpages matching mozilla.org.",
|
"description": "Adds a red border to all webpages matching mozilla.org.",
|
||||||
"permissions": [
|
"permissions": [
|
||||||
"activeTab",
|
"activeTab"
|
||||||
"webRequest",
|
|
||||||
"webRequestBlocking",
|
|
||||||
"<all_urls>"
|
|
||||||
],
|
],
|
||||||
"background": {
|
|
||||||
"scripts": ["background.js"]
|
|
||||||
},
|
|
||||||
"browser_action": {
|
"browser_action": {
|
||||||
"default_icon": "icon.png",
|
"default_icon": "icon.png",
|
||||||
"default_title": "Click me!",
|
"default_title": "Click me!",
|
||||||
|
13
browser/popup/inject.js
Normal file
13
browser/popup/inject.js
Normal 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;
|
||||||
|
})
|
||||||
|
|
||||||
|
|
||||||
|
}
|
||||||
|
|
@ -5,9 +5,10 @@
|
|||||||
</head>
|
</head>
|
||||||
|
|
||||||
<body>
|
<body>
|
||||||
<button id="">On</button>
|
<button id="newtab">Open canvas</button>
|
||||||
<button id="">Off</button>
|
<button id="replacer">Load page</button>
|
||||||
<p id="output"></p>
|
<p id="output"></p>
|
||||||
|
<script src="popup.js"></script>
|
||||||
</body>
|
</body>
|
||||||
<style>
|
<style>
|
||||||
html {
|
html {
|
||||||
|
21
browser/popup/popup.js
Normal file
21
browser/popup/popup.js
Normal 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}";
|
||||||
|
`
|
17
src/main.rs
17
src/main.rs
@ -1,6 +1,7 @@
|
|||||||
use rocket::{fairing::{Fairing, Info, Kind}, fs::FileServer, get, http::Header, routes, Request, Response, State};
|
use rocket::{fairing::{Fairing, Info, Kind}, fs::FileServer, get, http::Header, routes, Request, Response, State};
|
||||||
use s3::S3;
|
use s3::S3;
|
||||||
use tracing::{info, Level};
|
use tracing::{info, Level};
|
||||||
|
use url::Url;
|
||||||
|
|
||||||
mod s3;
|
mod s3;
|
||||||
|
|
||||||
@ -20,7 +21,7 @@ async fn main() {
|
|||||||
.init();
|
.init();
|
||||||
|
|
||||||
let config = Config {
|
let config = Config {
|
||||||
s3_bucket: "b64v1",
|
s3_bucket: "v1.10",
|
||||||
s3_url: "http://localhost:9000",
|
s3_url: "http://localhost:9000",
|
||||||
s3_access_key: "8UO76z8wCs9DnpxSbQUY",
|
s3_access_key: "8UO76z8wCs9DnpxSbQUY",
|
||||||
s3_secret_key: "xwKVMpf2jzgprsdo85Dvo74UmO84y0aRrAUorYY5",
|
s3_secret_key: "xwKVMpf2jzgprsdo85Dvo74UmO84y0aRrAUorYY5",
|
||||||
@ -41,12 +42,14 @@ async fn main() {
|
|||||||
}
|
}
|
||||||
|
|
||||||
#[get("/s3/<path>")]
|
#[get("/s3/<path>")]
|
||||||
async fn get_s3_content(path: &str, db: &State<S3>) -> Option<String> {
|
async fn get_s3_content(path: &str, db: &State<S3>) -> String {
|
||||||
if let Some(resp) = db.get(&path).await {
|
info!(path);
|
||||||
return Some(resp)
|
// 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
|
"Hello world.".to_owned()
|
||||||
None
|
|
||||||
}
|
}
|
||||||
|
|
||||||
// CORS, to allow other sites to request this from their front-end
|
// 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-Methods", "POST, GET, PATCH, OPTIONS"));
|
||||||
response.set_header(Header::new("Access-Control-Allow-Headers", "*"));
|
response.set_header(Header::new("Access-Control-Allow-Headers", "*"));
|
||||||
response.set_header(Header::new("Access-Control-Allow-Credentials", "true"));
|
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"));
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
@ -2,6 +2,7 @@ use minio::s3::{
|
|||||||
args::{BucketExistsArgs, MakeBucketArgs}, client::ClientBuilder, creds::StaticProvider, error::Error, http::BaseUrl, types::S3Api, Client
|
args::{BucketExistsArgs, MakeBucketArgs}, client::ClientBuilder, creds::StaticProvider, error::Error, http::BaseUrl, types::S3Api, Client
|
||||||
};
|
};
|
||||||
use tracing::{instrument, trace};
|
use tracing::{instrument, trace};
|
||||||
|
use url::Url;
|
||||||
|
|
||||||
use crate::Config;
|
use crate::Config;
|
||||||
|
|
||||||
@ -34,7 +35,7 @@ impl S3 {
|
|||||||
.await?;
|
.await?;
|
||||||
}
|
}
|
||||||
|
|
||||||
trace!("Connection successful");
|
trace!("Connection successfull");
|
||||||
|
|
||||||
Ok(Self {
|
Ok(Self {
|
||||||
bucket_name: config.s3_bucket.to_owned(),
|
bucket_name: config.s3_bucket.to_owned(),
|
||||||
|
Loading…
x
Reference in New Issue
Block a user