Skip to content
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

Merged
merged 13 commits into from
Nov 4, 2024

Conversation

newhzh
Copy link
Contributor

@newhzh newhzh commented May 9, 2024

No description provided.

@@ -145,5 +196,5 @@ async fn upload<'r>(
}

pub fn routes() -> Vec<rocket::Route> {
routes![upload, download]
routes![upload, download,export_all]
Copy link
Owner

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");
Copy link
Owner

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。
这也是为什么另外那个下载的函数是先通过一个请求获得一次性下载链接,再用这个下载链接下载。

Copy link
Owner

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

一个让单用户模式行为更符合普通模式的办法:前端启动时检测是否是单用户模式,是的话设置一个特殊token。服务端收到特殊token后,检测是否是单用户模式,再通过验证。 其实可以放到一个单独PR中,不过我也没有特别在意。

.all(db)
.await?;

let temp_dir = TempDir::new().unwrap();
Copy link
Owner

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

不要 unwrap 直接丢 exception,这里用 ? 向上级传错误更合适一些

Comment on lines 134 to 148
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()?;
Copy link
Owner

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

这段代码基本上与上方download_snapshot 中的那段一致,应该提取出一个函数复用代码。

@CaviarChen CaviarChen changed the title add export archive zip Support MemoLanes archive export (Part 1) Nov 4, 2024
@CaviarChen CaviarChen merged commit d4f26d3 into CaviarChen:main Nov 4, 2024
5 checks passed
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

2 participants