Erwin 5 éve
szülő
commit
37bba27cd1
6 módosított fájl, 64 hozzáadás és 29 törlés
  1. 7 0
      Cargo.lock
  2. 1 0
      Cargo.toml
  3. 1 0
      src/query.rs
  4. 31 7
      src/server.rs
  5. 4 0
      src/test.rs
  6. 20 22
      webapp/index.html

+ 7 - 0
Cargo.lock

@@ -447,6 +447,7 @@ dependencies = [
  "serde_derive 1.0.98 (registry+https://github.com/rust-lang/crates.io-index)",
  "serde_json 1.0.40 (registry+https://github.com/rust-lang/crates.io-index)",
  "url 2.0.0 (registry+https://github.com/rust-lang/crates.io-index)",
+ "urldecode 0.1.1 (registry+https://github.com/rust-lang/crates.io-index)",
 ]
 
 [[package]]
@@ -1908,6 +1909,11 @@ dependencies = [
  "percent-encoding 2.0.0 (registry+https://github.com/rust-lang/crates.io-index)",
 ]
 
+[[package]]
+name = "urldecode"
+version = "0.1.1"
+source = "registry+https://github.com/rust-lang/crates.io-index"
+
 [[package]]
 name = "utf-8"
 version = "0.7.5"
@@ -2235,6 +2241,7 @@ source = "registry+https://github.com/rust-lang/crates.io-index"
 "checksum untrusted 0.6.2 (registry+https://github.com/rust-lang/crates.io-index)" = "55cd1f4b4e96b46aeb8d4855db4a7a9bd96eeeb5c6a1ab54593328761642ce2f"
 "checksum url 1.7.2 (registry+https://github.com/rust-lang/crates.io-index)" = "dd4e7c0d531266369519a4aa4f399d748bd37043b00bde1e4ff1f60a120b355a"
 "checksum url 2.0.0 (registry+https://github.com/rust-lang/crates.io-index)" = "77ddaf52e65c6b81c56b7e957c0b1970f7937f21c5c6774c4e56fcb4e20b48c6"
+"checksum urldecode 0.1.1 (registry+https://github.com/rust-lang/crates.io-index)" = "070c2eb79ba268848a73885f94a83b86d9e6441c5d5b10727d5f8989db2c8edc"
 "checksum utf-8 0.7.5 (registry+https://github.com/rust-lang/crates.io-index)" = "05e42f7c18b8f902290b009cde6d651262f956c98bc51bca4cd1d511c9cd85c7"
 "checksum utf8-ranges 1.0.3 (registry+https://github.com/rust-lang/crates.io-index)" = "9d50aa7650df78abf942826607c62468ce18d9019673d4a2ebe1865dbb96ffde"
 "checksum uuid 0.7.4 (registry+https://github.com/rust-lang/crates.io-index)" = "90dbc611eb48397705a6b0f6e917da23ae517e4d127123d2cf7674206627d32a"

+ 1 - 0
Cargo.toml

@@ -16,6 +16,7 @@ serde_json = "1.0"
 rocket = "0.4.1"
 lazy_static = "*"
 url = "*"
+urldecode = "0.1.1"
 
 [dependencies.rocket_contrib]
 version = "0.4.1"

+ 1 - 0
src/query.rs

@@ -7,6 +7,7 @@ use std::collections::HashMap;
 // extern crate url;
 use url::form_urlencoded::{byte_serialize};
 
+
 #[derive(Serialize, Deserialize, Debug, Default, Clone)]
 pub struct Auction {
     pub price: f32,

+ 31 - 7
src/server.rs

@@ -1,10 +1,14 @@
 use rocket_contrib::serve::StaticFiles;
 use rocket_contrib::json::Json;
 use rocket::response::content;
+use rocket::http::ContentType;
+use rocket::response::Response;
 use std::sync::Mutex;
 use std::collections::HashMap;
 use super::ACCOUNTS;
 use super::query::*;
+use reqwest;
+use urldecode;
 
 #[derive(Serialize, Deserialize, Debug, Clone)]
 struct Task {
@@ -16,6 +20,32 @@ lazy_static! {
     static ref TASKS: Mutex<Vec<Task>> = Mutex::new(vec![]);
 }
 
+
+pub fn proxy(url: &str) -> Vec<u8> {
+    match reqwest::get(url) {
+        Ok(mut resp) => {
+            // println!("resp = {:?}", resp);
+            let mut buf: Vec<u8> = vec![];
+            match resp.copy_to(&mut buf) {
+                Ok(_r) => buf,
+                Err(e) => vec![]
+            }
+
+        }
+        Err(e) => vec![]
+    }
+
+}
+
+
+#[get("/proxy/<url>")]
+fn proxy_gate(url: String)  -> Vec<u8>{
+    let html = ContentType::parse_flexible("image/jpeg").unwrap();
+    let response = Response::build().header(html).finalize();
+    proxy(&urldecode::decode(url))
+}
+
+
 #[get("/")]
 fn index() -> &'static str {
     let accounts = ACCOUNTS.lock().unwrap();
@@ -27,7 +57,6 @@ fn index() -> &'static str {
 #[post("/save", data = "<account>")] //<tasks> means that the function below will have a var called tasks
 fn save(account: Json<HashMap<String, Account>>) -> &'static str {
     dbg!(&account);
-
     let mut accounts = ACCOUNTS.lock().unwrap();
     accounts.extend(account.into_inner());
     dbg!(&accounts);
@@ -35,13 +64,9 @@ fn save(account: Json<HashMap<String, Account>>) -> &'static str {
     "Inserted"
 }
 
-// turn tasks into json (serialize)
 #[get("/load/<account>")]
 fn load(account: String) -> content::Json<String> {
-    // get a lock here on TASKS
     let guard = ACCOUNTS.lock().unwrap().clone();
-    // drop(ACCOUNTS);
-    // serialize all tasks
     match guard.get(&account) {
         Some(accountdata) => {
             let json_string = serde_json::to_string(&accountdata.queries).unwrap();
@@ -49,8 +74,6 @@ fn load(account: String) -> content::Json<String> {
         },
         None => content::Json("{}".to_string())
     }
-    
-    // hand them out to the browser (or anything else) and tell them to expect json
 }
 
 pub fn run() {
@@ -58,6 +81,7 @@ pub fn run() {
     // .mount("/", routes![index])
     .mount("/", routes![save])
     .mount("/", routes![load])
+    .mount("/", routes![proxy_gate])
     .mount("/", StaticFiles::from("webapp"))
     .launch();
 }

+ 4 - 0
src/test.rs

@@ -50,6 +50,10 @@ fn daemon() {
 
 fn main() {
     
+    //server::proxy("http://www.egun.de/market/cache/aucimg/100x100/3.7564934.665580173.jpg");
+    server::run();
+    return;
+
 
     match File::open(DBFILE) {
         Ok(f) => {

+ 20 - 22
webapp/index.html

@@ -117,6 +117,23 @@
       </div>
 
 
+      <template>
+        <div class="panel" v-if="!account">
+          {{account}}
+          Hi! Du hast noch keinen Account oder es ist keiner geladen. Macht aber nichts, gib einfach Deinen ein oder
+          denke Dir einen aus.
+          <input autocapitalize="none" v-model="new_account" v-on:keyup.enter="window.location.hash = new_account;">
+          <button @click="window.location.hash = new_account">OK</button>
+          <div>
+            Tip: der Accountname sollte einem Passwort aehnlich sein wenn Du nicht willst dass jemand anderes Deine
+            Suchen sieht.
+          </div>
+        </div>
+
+      </template>
+
+
+
 
       <div class="panel" v-for="auction in ordered_auctions()" v-if="auction.price != null && !auction.is_price_final && !search_visible">
         <div class="grid-auto">
@@ -144,39 +161,20 @@
       </div>
 
 
-      <h3>
-        Abgelaufene Aktionen:
-      </h3>
-
       <div class="panel" v-for="auction in ordered_auctions()" v-if="auction.price != null && auction.is_price_final && !search_visible">
-        <div class="grid-auto">
+
           <div>
             <img :src="auction.thumb" style="vertical-align:middle;">
-            <div>
-              <div class="badge">{{auction.price}} EUR</div>
-            </div>
+              <div>{{auction.price}} EUR</div>
           </div>
           <div><a :href="auction.url" target="_">{{auction.desc}}</a></div>
-        </div>
+        
       </div>
 
 
 
 
-      <template>
-        <div class="panel" v-if="!account">
-          {{account}}
-          Hi! Du hast noch keinen Account oder es ist keiner geladen. Macht aber nichts, gib einfach Deinen ein oder
-          denke Dir einen aus.
-          <input autocapitalize="none" v-model="new_account" v-on:keyup.enter="window.location.hash = new_account;">
-          <button @click="window.location.hash = new_account">OK</button>
-          <div>
-            Tip: der Accountname sollte einem Passwort aehnlich sein wenn Du nicht willst dass jemand anderes Deine
-            Suchen sieht.
-          </div>
-        </div>
 
-      </template>
 
 
     </div>