Quellcode durchsuchen

Add /dl path + patch info/ls

mmeisson vor 6 Jahren
Ursprung
Commit
c421f28d79
4 geänderte Dateien mit 167 neuen und 58 gelöschten Zeilen
  1. 167 58
      src/main.rs
  2. BIN
      test.mp3
  3. BIN
      toto.mp3
  4. BIN
      truc.mp3

+ 167 - 58
src/main.rs

@@ -6,6 +6,9 @@ extern crate rocket_contrib;
 #[macro_use]
 extern crate serde_derive;
 
+use std::fs;
+use rocket::response::NamedFile;
+
 use rocket_contrib::json::Json;
 use serde::Serialize;
 
@@ -78,7 +81,7 @@ struct FbxFileInfo
     mimetype: String,
     r#type: String,
     size: i32,
-    modification: i32,
+    modification: u64,
     index: i32,
     link: bool,
     target: String,
@@ -92,13 +95,23 @@ fn fs_info(file_path: String)
     -> Json<FbxCmdResult<FbxFileInfo>>
 {
     let name: String = match file_path.as_ref() {
-        "L3Rlc3Q=" => "test".into(),
-        "L3RvdG8=" => "toto".into(),
-        "L3RydWM=" => "truc".into(),
+        "L3Rlc3QubXAz" => "test.mp3".into(),
+        "L3RvdG8ubXAz" => "toto.mp3".into(),
+        "L3RydWMubXAz" => "truc.mp3".into(),
+        "L2Rpci90ZXN0Lm1wMw==" => "test.mp3".into(),
+        "L2Rpcg==" => "dir".into(),
         _ => "/".into()
     };
-    let mtype: String = match file_path.as_ref() {
+    let size: i32 = match file_path.as_ref() {
+        "L3Rlc3QubXAz" => 6668854,
+        "L3RvdG8ubXAz" => 3065529,
+        "L3RydWMubXAz" => 8887960,
+        "L2Rpci90ZXN0Lm1wMw==" => 6668854,
+        _ => 4096,
+    };
+    let ftype: String = match file_path.as_ref() {
         "Lw==" => "dir".into(),
+        "L2Rpcg==" => "dir".into(),
         _ => "file".into()
     };
 
@@ -107,9 +120,9 @@ fn fs_info(file_path: String)
         result: FbxFileInfo {
             path: file_path,
             name: name,
-            mimetype: mtype.clone(),
-            r#type: mtype,
-            size: 1024,
+            mimetype: "audio/mpeg".into(),
+            r#type: ftype,
+            size: size,
             modification: 0,
             index: 1,
             link: false,
@@ -122,57 +135,152 @@ fn fs_info(file_path: String)
 
 #[get("/api/v6/fs/ls/<file_path>")]
 fn fs_ls(file_path: String)
-    -> Json<FbxCmdResult<[FbxFileInfo; 3]>>
+    -> Json<FbxCmdResult<[FbxFileInfo; 4]>>
+{
+    if file_path == "L2Rpcg==" {
+        return Json(
+            FbxCmdResult {
+                success: true,
+                result: [
+                    FbxFileInfo {
+                        path: "L2Rpci90ZXN0Lm1wMw==".into(),
+                        name: "test.mp3".into(),
+                        mimetype: "audio/mpeg".into(),
+                        r#type: "file".into(),
+                        size: 6668854,
+                        modification: 0,
+                        index: 1,
+                        link: false,
+                        target: "".into(),
+                        hidden: false,
+                        foldercount: 5,
+                        filecount: 5,
+                    },
+                    FbxFileInfo {
+                        path: "L2Rpci90ZXN0Lm1wMw==".into(),
+                        name: "test.mp3".into(),
+                        mimetype: "audio/mpeg".into(),
+                        r#type: "file".into(),
+                        size: 6668854,
+                        modification: 0,
+                        index: 1,
+                        link: false,
+                        target: "".into(),
+                        hidden: false,
+                        foldercount: 5,
+                        filecount: 5,
+                    },
+                    FbxFileInfo {
+                        path: "L2Rpci90ZXN0Lm1wMw==".into(),
+                        name: "test.mp3".into(),
+                        mimetype: "audio/mpeg".into(),
+                        r#type: "file".into(),
+                        size: 6668854,
+                        modification: 0,
+                        index: 1,
+                        link: false,
+                        target: "".into(),
+                        hidden: false,
+                        foldercount: 5,
+                        filecount: 5,
+                    },
+                    FbxFileInfo {
+                        path: "L2Rpci90ZXN0Lm1wMw==".into(),
+                        name: "test.mp3".into(),
+                        mimetype: "audio/mpeg".into(),
+                        r#type: "file".into(),
+                        size: 6668854,
+                        modification: 0,
+                        index: 1,
+                        link: false,
+                        target: "".into(),
+                        hidden: false,
+                        foldercount: 5,
+                        filecount: 5,
+                    },
+                ]
+            }
+        )
+    }
+    else {
+        Json(
+            FbxCmdResult {
+                success: true,
+                result: [
+                    FbxFileInfo {
+                        path: "L2Rpcg==".into(),
+                        name: "dir".into(),
+                        mimetype: "dir".into(),
+                        r#type: "dir".into(),
+                        size: 1024,
+                        modification: 0,
+                        index: 1,
+                        link: false,
+                        target: "".into(),
+                        hidden: false,
+                        foldercount: 0,
+                        filecount: 1,
+                    },
+                    FbxFileInfo {
+                        path: "L3Rlc3QubXAz".into(),
+                        name: "test.mp3".into(),
+                        mimetype: "audio/mpeg".into(),
+                        r#type: "file".into(),
+                        size: 6668854,
+                        modification: 0,
+                        index: 1,
+                        link: false,
+                        target: "".into(),
+                        hidden: false,
+                        foldercount: 5,
+                        filecount: 5,
+                    },
+                    FbxFileInfo {
+                        path: "L3RvdG8ubXAz".into(),
+                        name: "toto.mp3".into(),
+                        mimetype: "audio/mpeg".into(),
+                        r#type: "file".into(),
+                        size: 3065529,
+                        modification: 0,
+                        index: 1,
+                        link: false,
+                        target: "".into(),
+                        hidden: false,
+                        foldercount: 5,
+                        filecount: 5,
+                    },
+                    FbxFileInfo {
+                        path: "L3RydWMubXAz".into(),
+                        name: "truc.mp3".into(),
+                        mimetype: "audio/mpeg".into(),
+                        r#type: "file".into(),
+                        size: 8887960,
+                        modification: 0,
+                        index: 1,
+                        link: false,
+                        target: "".into(),
+                        hidden: false,
+                        foldercount: 5,
+                        filecount: 5,
+                    },
+                ]
+            }
+        )
+    }
+}
+
+#[get("/api/v6/dl/<file_path>")]
+fn fs_dl(file_path: String) -> NamedFile
 {
-    Json(
-        FbxCmdResult {
-            success: true,
-            result: [
-                FbxFileInfo {
-                    path: "L3Rlc3Q=".into(),
-                    name: "test".into(),
-                    mimetype: "file".into(),
-                    r#type: "file".into(),
-                    size: 1024,
-                    modification: 0,
-                    index: 1,
-                    link: false,
-                    target: "".into(),
-                    hidden: false,
-                    foldercount: 5,
-                    filecount: 5,
-                },
-                FbxFileInfo {
-                    path: "L3RvdG8=".into(),
-                    name: "toto".into(),
-                    mimetype: "file".into(),
-                    r#type: "file".into(),
-                    size: 1024,
-                    modification: 0,
-                    index: 1,
-                    link: false,
-                    target: "".into(),
-                    hidden: false,
-                    foldercount: 5,
-                    filecount: 5,
-                },
-                FbxFileInfo {
-                    path: "L3RydWM=".into(),
-                    name: "truc".into(),
-                    mimetype: "file".into(),
-                    r#type: "file".into(),
-                    size: 1024,
-                    modification: 0,
-                    index: 1,
-                    link: false,
-                    target: "".into(),
-                    hidden: false,
-                    foldercount: 5,
-                    filecount: 5,
-                },
-            ]
-        }
-    )
+    println!("{}", file_path);
+
+    match file_path.as_ref() {
+        "L3Rlc3QubXAz" => NamedFile::open("test.mp3"),
+        "L3RvdG8ubXAz" => NamedFile::open("toto.mp3"),
+        "L3RydWMubXAz" => NamedFile::open("truc.mp3"),
+        "L2Rpci90ZXN0Lm1wMw==" => NamedFile::open("test.mp3"),
+        _ => NamedFile::open("truc.mp3"),
+    }.unwrap()
 }
 
 
@@ -185,6 +293,7 @@ fn main()
                login_session,
                fs_info,
                fs_ls,
+               fs_dl,
         ])
         .launch();
 }

BIN
test.mp3


BIN
toto.mp3


BIN
truc.mp3