DAV file management delete
This commit is contained in:
@@ -6,7 +6,7 @@
|
||||
|
||||
use std::sync::Arc;
|
||||
|
||||
use common::{Files, Server};
|
||||
use common::{FileItem, Files, Server};
|
||||
use jmap_proto::types::collection::Collection;
|
||||
use percent_encoding::NON_ALPHANUMERIC;
|
||||
use trc::AddContext;
|
||||
@@ -62,10 +62,16 @@ async fn build_file_hierarchy(server: &Server, account_id: u32) -> trc::Result<F
|
||||
modseq: None,
|
||||
};
|
||||
|
||||
for (id, name) in list.into_iterator() {
|
||||
files.size +=
|
||||
(std::mem::size_of::<u32>() + std::mem::size_of::<String>() + name.len()) as u64;
|
||||
files.files.insert(id, name);
|
||||
for expanded in list.into_iterator() {
|
||||
files.size += (std::mem::size_of::<u32>()
|
||||
+ std::mem::size_of::<String>()
|
||||
+ expanded.name.len()) as u64;
|
||||
files.files.insert(FileItem {
|
||||
document_id: expanded.document_id,
|
||||
parent_id: expanded.parent_id,
|
||||
name: expanded.name,
|
||||
is_container: expanded.is_container,
|
||||
});
|
||||
}
|
||||
|
||||
Ok(files)
|
||||
|
||||
@@ -6,9 +6,9 @@
|
||||
|
||||
use common::storage::{
|
||||
folder::FolderHierarchy,
|
||||
index::{IndexValue, IndexableObject},
|
||||
index::{IndexValue, IndexableAndSerializableObject, IndexableObject},
|
||||
};
|
||||
use jmap_proto::types::property::Property;
|
||||
use jmap_proto::types::{property::Property, value::AclGrant};
|
||||
|
||||
use super::{ArchivedFileNode, FileNode};
|
||||
|
||||
@@ -29,7 +29,9 @@ impl IndexableObject for FileNode {
|
||||
field: Property::ParentId.into(),
|
||||
value: self.parent_id.into(),
|
||||
},
|
||||
IndexValue::Acl { value: &self.acls },
|
||||
IndexValue::Acl {
|
||||
value: (&self.acls).into(),
|
||||
},
|
||||
]);
|
||||
|
||||
if let Some(file) = &self.file {
|
||||
@@ -52,6 +54,55 @@ impl IndexableObject for FileNode {
|
||||
}
|
||||
}
|
||||
|
||||
impl IndexableObject for &ArchivedFileNode {
|
||||
fn index_values(&self) -> impl Iterator<Item = IndexValue<'_>> {
|
||||
let size = self.dead_properties.size() as u32
|
||||
+ self.display_name.as_ref().map_or(0, |n| n.len() as u32)
|
||||
+ self.name.len() as u32;
|
||||
|
||||
let mut values = Vec::with_capacity(6);
|
||||
|
||||
values.extend([
|
||||
IndexValue::Text {
|
||||
field: Property::Name.into(),
|
||||
value: self.name.to_lowercase().into(),
|
||||
},
|
||||
IndexValue::U32 {
|
||||
field: Property::ParentId.into(),
|
||||
value: u32::from(self.parent_id).into(),
|
||||
},
|
||||
IndexValue::Acl {
|
||||
value: self
|
||||
.acls
|
||||
.iter()
|
||||
.map(AclGrant::from)
|
||||
.collect::<Vec<_>>()
|
||||
.into(),
|
||||
},
|
||||
]);
|
||||
|
||||
if let Some(file) = self.file.as_ref() {
|
||||
let size = size + file.size;
|
||||
values.extend([
|
||||
IndexValue::Blob {
|
||||
value: (&file.blob_hash).into(),
|
||||
},
|
||||
IndexValue::U32 {
|
||||
field: Property::Size.into(),
|
||||
value: size.into(),
|
||||
},
|
||||
IndexValue::Quota { used: size },
|
||||
]);
|
||||
} else {
|
||||
values.push(IndexValue::Quota { used: size });
|
||||
}
|
||||
|
||||
values.into_iter()
|
||||
}
|
||||
}
|
||||
|
||||
impl IndexableAndSerializableObject for FileNode {}
|
||||
|
||||
impl FolderHierarchy for ArchivedFileNode {
|
||||
fn name(&self) -> String {
|
||||
self.name.to_string()
|
||||
@@ -60,4 +111,8 @@ impl FolderHierarchy for ArchivedFileNode {
|
||||
fn parent_id(&self) -> u32 {
|
||||
u32::from(self.parent_id)
|
||||
}
|
||||
|
||||
fn is_container(&self) -> bool {
|
||||
self.file.is_none()
|
||||
}
|
||||
}
|
||||
|
||||
@@ -14,6 +14,7 @@ use utils::BlobHash;
|
||||
#[derive(
|
||||
rkyv::Archive, rkyv::Deserialize, rkyv::Serialize, Debug, Default, Clone, PartialEq, Eq,
|
||||
)]
|
||||
#[rkyv(derive(Debug))]
|
||||
pub struct FileNode {
|
||||
pub parent_id: u32,
|
||||
pub name: String,
|
||||
@@ -29,6 +30,7 @@ pub struct FileNode {
|
||||
#[derive(
|
||||
rkyv::Archive, rkyv::Deserialize, rkyv::Serialize, Debug, Default, Clone, PartialEq, Eq,
|
||||
)]
|
||||
#[rkyv(derive(Debug))]
|
||||
pub struct FileProperties {
|
||||
pub blob_hash: BlobHash,
|
||||
pub size: u32,
|
||||
|
||||
Reference in New Issue
Block a user