|
@@ -6,6 +6,9 @@ extern crate rocket_contrib;
|
|
#[macro_use]
|
|
#[macro_use]
|
|
extern crate serde_derive;
|
|
extern crate serde_derive;
|
|
|
|
|
|
|
|
+use std::fs;
|
|
|
|
+use rocket::response::NamedFile;
|
|
|
|
+
|
|
use rocket_contrib::json::Json;
|
|
use rocket_contrib::json::Json;
|
|
use serde::Serialize;
|
|
use serde::Serialize;
|
|
|
|
|
|
@@ -78,7 +81,7 @@ struct FbxFileInfo
|
|
mimetype: String,
|
|
mimetype: String,
|
|
r#type: String,
|
|
r#type: String,
|
|
size: i32,
|
|
size: i32,
|
|
- modification: i32,
|
|
|
|
|
|
+ modification: u64,
|
|
index: i32,
|
|
index: i32,
|
|
link: bool,
|
|
link: bool,
|
|
target: String,
|
|
target: String,
|
|
@@ -92,13 +95,23 @@ fn fs_info(file_path: String)
|
|
-> Json<FbxCmdResult<FbxFileInfo>>
|
|
-> Json<FbxCmdResult<FbxFileInfo>>
|
|
{
|
|
{
|
|
let name: String = match file_path.as_ref() {
|
|
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()
|
|
_ => "/".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(),
|
|
"Lw==" => "dir".into(),
|
|
|
|
+ "L2Rpcg==" => "dir".into(),
|
|
_ => "file".into()
|
|
_ => "file".into()
|
|
};
|
|
};
|
|
|
|
|
|
@@ -107,9 +120,9 @@ fn fs_info(file_path: String)
|
|
result: FbxFileInfo {
|
|
result: FbxFileInfo {
|
|
path: file_path,
|
|
path: file_path,
|
|
name: name,
|
|
name: name,
|
|
- mimetype: mtype.clone(),
|
|
|
|
- r#type: mtype,
|
|
|
|
- size: 1024,
|
|
|
|
|
|
+ mimetype: "audio/mpeg".into(),
|
|
|
|
+ r#type: ftype,
|
|
|
|
+ size: size,
|
|
modification: 0,
|
|
modification: 0,
|
|
index: 1,
|
|
index: 1,
|
|
link: false,
|
|
link: false,
|
|
@@ -122,57 +135,152 @@ fn fs_info(file_path: String)
|
|
|
|
|
|
#[get("/api/v6/fs/ls/<file_path>")]
|
|
#[get("/api/v6/fs/ls/<file_path>")]
|
|
fn fs_ls(file_path: String)
|
|
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,
|
|
login_session,
|
|
fs_info,
|
|
fs_info,
|
|
fs_ls,
|
|
fs_ls,
|
|
|
|
+ fs_dl,
|
|
])
|
|
])
|
|
.launch();
|
|
.launch();
|
|
}
|
|
}
|