-
Notifications
You must be signed in to change notification settings - Fork 21
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Support MemoLanes archive export (Part 1) #104
Conversation
server/src/misc_handler.rs
Outdated
@@ -145,5 +196,5 @@ async fn upload<'r>( | |||
} | |||
|
|||
pub fn routes() -> Vec<rocket::Route> { | |||
routes![upload, download] | |||
routes![upload, download,export_all] |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
这个项目没有强制格式检查。 最好还是手动跑一下 cargo fmt --all
icon={<FileDownloadIcon />} | ||
onClick={() => { | ||
console.log("导出Achive Zip."); | ||
window.open(Api.backendUrl + "misc/export_all", "_blank"); |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
hmm 这种写法应该只能在 Single User Mode 下运行,因为这样无法传token。
这也是为什么另外那个下载的函数是先通过一个请求获得一次性下载链接,再用这个下载链接下载。
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
一个让单用户模式行为更符合普通模式的办法:前端启动时检测是否是单用户模式,是的话设置一个特殊token。服务端收到特殊token后,检测是否是单用户模式,再通过验证。 其实可以放到一个单独PR中,不过我也没有特别在意。
server/src/misc_handler.rs
Outdated
.all(db) | ||
.await?; | ||
|
||
let temp_dir = TempDir::new().unwrap(); |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
不要 unwrap 直接丢 exception,这里用 ?
向上级传错误更合适一些
server/src/misc_handler.rs
Outdated
let zip_file_path = temp_dir.path().join("temp_sync.zip"); | ||
let mut zip_file = fs::File::create(&zip_file_path)?; | ||
let mut zip = zip::ZipWriter::new(&mut zip_file); | ||
let options = zip::write::SimpleFileOptions::default() | ||
.compression_method(zip::CompressionMethod::Stored); | ||
zip.add_directory("Sync/", options)?; | ||
|
||
let entity::snapshot::SyncFiles(sync_files) = snapshot.sync_files; | ||
for (file_id, sha256) in &sync_files { | ||
let sync_file = data_fetcher::SyncFile::create_from_id(*file_id, sha256)?; | ||
zip.start_file(format!("Sync/{}", sync_file.filename()), options)?; | ||
let mut file = server_state.file_storage.open_file(&user, sha256)?; | ||
std::io::copy(&mut file, &mut zip)?; | ||
} | ||
zip.finish()?; |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
这段代码基本上与上方download_snapshot
中的那段一致,应该提取出一个函数复用代码。
No description provided.