瀏覽代碼

Add fs/info and fs/ls endpoints

mmeisson 6 年之前
父節點
當前提交
6f5d0e71ca
共有 1 個文件被更改,包括 109 次插入1 次删除
  1. 109 1
      src/main.rs

+ 109 - 1
src/main.rs

@@ -70,6 +70,111 @@ fn login_session(payload: Json<LoginSessionPayload>)
         }})
 }
 
+#[derive(Serialize)]
+struct FbxFileInfo
+{
+    path: String,
+    name: String,
+    mimetype: String,
+    r#type: String,
+    size: i32,
+    modification: i32,
+    index: i32,
+    link: bool,
+    target: String,
+    hidden: bool,
+    foldercount: i32,
+    filecount: i32,
+}
+
+#[get("/api/v6/fs/info/<file_path>")]
+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(),
+        _ => "/".into()
+    };
+    let mtype: String = match file_path.as_ref() {
+        "Lw==" => "dir".into(),
+        _ => "file".into()
+    };
+
+    Json(FbxCmdResult {
+        success: true,
+        result: FbxFileInfo {
+            path: file_path,
+            name: name,
+            mimetype: mtype.clone(),
+            r#type: mtype,
+            size: 1024,
+            modification: 0,
+            index: 1,
+            link: false,
+            target: "".into(),
+            hidden: false,
+            foldercount: 5,
+            filecount: 5,
+        }})
+}
+
+#[get("/api/v6/fs/ls/<file_path>")]
+fn fs_ls(file_path: String)
+    -> Json<FbxCmdResult<[FbxFileInfo; 3]>>
+{
+    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,
+                },
+            ]
+        }
+    )
+}
+
 
 fn main()
 {
@@ -77,6 +182,9 @@ fn main()
         .mount("/",routes![
                index,
                login,
-               login_session])
+               login_session,
+               fs_info,
+               fs_ls,
+        ])
         .launch();
 }