Formatting (Prettier + Rustfmt 1.72) (#1246)

Formatting
This commit is contained in:
Vítor Vasconcellos
2023-08-24 17:34:52 -03:00
committed by GitHub
parent d837192b75
commit 2756a55e04
28 changed files with 186 additions and 156 deletions

View File

@@ -123,7 +123,7 @@ pub async fn list_apps_associated_with_ext(file_path: impl AsRef<Path>) -> Vec<A
pub fn open_files_path_with(file_paths: &[impl AsRef<Path>], id: &str) -> Result<(), GlibError> {
let Some(app) = DesktopAppInfo::new(id) else {
return Err(GlibError::new(ResourceError::NotFound, "App not found"))
return Err(GlibError::new(ResourceError::NotFound, "App not found"));
};
LAUNCH_CTX.with(|ctx| {

View File

@@ -92,17 +92,15 @@ pub async fn get_file_path_open_with_apps(
ids: Vec<i32>,
node: NodeState<'_>,
) -> Result<Vec<OpenWithApplication>, ()> {
let Some(library) = node.libraries.get_library(&library).await
else {
return Ok(vec![]);
};
let Some(library) = node.libraries.get_library(&library).await else {
return Ok(vec![]);
};
let Ok(paths) = library
.get_file_paths(ids).await
.map_err(|e| {error!("{e:#?}");})
else {
return Ok(vec![]);
};
let Ok(paths) = library.get_file_paths(ids).await.map_err(|e| {
error!("{e:#?}");
}) else {
return Ok(vec![]);
};
#[cfg(target_os = "macos")]
return {
@@ -110,10 +108,10 @@ pub async fn get_file_path_open_with_apps(
.into_values()
.flat_map(|path| {
let Some(path) = path.and_then(|path| path.into_os_string().into_string().ok())
else {
error!("File not found in database");
return None;
};
else {
error!("File not found in database");
return None;
};
Some(
unsafe { sd_desktop_macos::get_open_with_applications(&path.as_str().into()) }
@@ -137,11 +135,10 @@ pub async fn get_file_path_open_with_apps(
use sd_desktop_linux::list_apps_associated_with_ext;
let apps = future::join_all(paths.into_values().map(|path| async {
let Some(path) = path
else {
error!("File not found in database");
return None;
};
let Some(path) = path else {
error!("File not found in database");
return None;
};
Some(
list_apps_associated_with_ext(&path)
@@ -168,17 +165,15 @@ pub async fn get_file_path_open_with_apps(
return Ok(paths
.into_values()
.filter_map(|path| {
let Some(path) = path
else {
error!("File not found in database");
return None;
};
let Some(path) = path else {
error!("File not found in database");
return None;
};
let Some(ext) = path.extension()
else {
error!("Failed to extract file extension");
return None;
};
let Some(ext) = path.extension() else {
error!("Failed to extract file extension");
return None;
};
sd_desktop_windows::list_apps_associated_with_ext(ext)
.map_err(|e| {
@@ -191,15 +186,27 @@ pub async fn get_file_path_open_with_apps(
.iter()
.filter_map(|handler| {
let (Ok(name), Ok(url)) = (
unsafe { handler.GetUIName() }.map_err(|e| { error!("{e:#?}");})
.and_then(|name| unsafe { name.to_string() }
.map_err(|e| { error!("{e:#?}");})),
unsafe { handler.GetName() }.map_err(|e| { error!("{e:#?}");})
.and_then(|name| unsafe { name.to_string() }
.map_err(|e| { error!("{e:#?}");})),
unsafe { handler.GetUIName() }
.map_err(|e| {
error!("{e:#?}");
})
.and_then(|name| {
unsafe { name.to_string() }.map_err(|e| {
error!("{e:#?}");
})
}),
unsafe { handler.GetName() }
.map_err(|e| {
error!("{e:#?}");
})
.and_then(|name| {
unsafe { name.to_string() }.map_err(|e| {
error!("{e:#?}");
})
}),
) else {
error!("Failed to get handler info");
return None
return None;
};
Some(OpenWithApplication { name, url })
@@ -223,10 +230,9 @@ pub async fn open_file_path_with(
file_ids_and_urls: Vec<FileIdAndUrl>,
node: NodeState<'_>,
) -> Result<(), ()> {
let Some(library) = node.libraries.get_library(&library).await
else {
return Err(())
};
let Some(library) = node.libraries.get_library(&library).await else {
return Err(());
};
let url_by_id = file_ids_and_urls.into_iter().collect::<HashMap<_, _>>();
let ids = url_by_id.keys().copied().collect::<Vec<_>>();
@@ -246,12 +252,11 @@ pub async fn open_file_path_with(
path.as_ref(),
#[cfg(not(windows))]
path.as_ref().and_then(|path| path.to_str()),
url_by_id.get(id)
)
else {
error!("File not found in database");
return Err(());
};
url_by_id.get(id),
) else {
error!("File not found in database");
return Err(());
};
#[cfg(target_os = "macos")]
return {
@@ -290,10 +295,9 @@ pub async fn reveal_items(
items: Vec<RevealItem>,
node: NodeState<'_>,
) -> Result<(), ()> {
let Some(library) = node.libraries.get_library(&library).await
else {
return Err(())
};
let Some(library) = node.libraries.get_library(&library).await else {
return Err(());
};
let (paths, locations): (Vec<_>, Vec<_>) =
items

View File

@@ -2,14 +2,14 @@ appId: com.spacedrive.app
---
- launchApp:
clearState: true
- tapOn: "Get Started"
- tapOn: 'Get Started'
- tapOn:
id: "library-name"
- inputText: "TestLib"
- tapOn: "New Library"
id: 'library-name'
- inputText: 'TestLib'
- tapOn: 'New Library'
- tapOn:
id: "share-minimal"
- tapOn: "Continue"
id: 'share-minimal'
- tapOn: 'Continue'
- tapOn:
id: "drawer-toggle"
- assertVisible: "TestLib"
id: 'drawer-toggle'
- assertVisible: 'TestLib'

View File

@@ -235,7 +235,7 @@ fn restore_backup(node: &Arc<Node>, path: PathBuf) -> Result<Header, BackupError
// TODO: Actually handle restoring into a library that exists. For now it's easier to error out.
let None = block_on(node.libraries.get_library(&header.library_id)) else {
return Err(BackupError::LibraryAlreadyExists)
return Err(BackupError::LibraryAlreadyExists);
};
let temp_dir = tempdir()?;

View File

@@ -255,10 +255,7 @@ pub(crate) fn mount() -> AlphaRouter<Ctx> {
R.with2(library())
.mutation(|(node, library), args: ObjectValidatorArgs| async move {
let Some(location) = find_location(&library, args.id)
.exec()
.await?
else {
let Some(location) = find_location(&library, args.id).exec().await? else {
return Err(LocationError::IdNotFound(args.id).into());
};

View File

@@ -176,15 +176,14 @@ impl JobReport {
pub fn get_meta(&self) -> (String, Option<String>) {
// actions are formatted like "added_location" or "added_location-1"
let Some(action_name) = self.action
.as_ref()
.map(
|action| action.split('-')
.next()
.map(str::to_string)
.unwrap_or_default()
) else {
return (self.id.to_string(), None);
let Some(action_name) = self.action.as_ref().map(|action| {
action
.split('-')
.next()
.map(str::to_string)
.unwrap_or_default()
}) else {
return (self.id.to_string(), None);
};
// create a unique group_key, EG: "added_location-<location_id>"
let group_key = self.parent_id.map_or_else(

View File

@@ -98,15 +98,15 @@ impl Libraries {
.is_file()
{
let Some(Ok(library_id)) = config_path
.file_stem()
.and_then(|v| v.to_str().map(Uuid::from_str))
.file_stem()
.and_then(|v| v.to_str().map(Uuid::from_str))
else {
warn!(
"Attempted to load library from path '{}' \
but it has an invalid filename. Skipping...",
config_path.display()
);
continue;
continue;
};
let db_path = config_path.with_extension("db");
@@ -399,7 +399,9 @@ impl Libraries {
async move {
loop {
let Ok(SyncMessage::Created) = sync.rx.recv().await else { continue };
let Ok(SyncMessage::Created) = sync.rx.recv().await else {
continue;
};
p2p::sync::originator(id, &library.sync, &node.nlm, &node.p2p).await;
}

View File

@@ -38,8 +38,8 @@ pub async fn shallow(
) -> Result<(), JobError> {
let location_id = location.id;
let Some(location_path) = location.path.as_ref().map(PathBuf::from) else {
return Err(JobError::Location(LocationError::MissingPath(location_id)));
};
return Err(JobError::Location(LocationError::MissingPath(location_id)));
};
let db = library.db.clone();

View File

@@ -441,9 +441,10 @@ where
return vec![];
};
let Ok(mut read_dir) = fs::read_dir(path).await
let Ok(mut read_dir) = fs::read_dir(path)
.await
.map_err(|e| errors.push(FileIOError::from((path.clone(), e)).into()))
else {
else {
return vec![];
};
@@ -490,9 +491,10 @@ where
accept_by_children_dir
);
let Ok(rules_per_kind) = IndexerRule::apply_all(indexer_rules, &current_path).await
let Ok(rules_per_kind) = IndexerRule::apply_all(indexer_rules, &current_path)
.await
.map_err(|e| errors.push(e.into()))
else {
else {
continue 'entries;
};
@@ -512,8 +514,8 @@ where
.metadata()
.await
.map_err(|e| errors.push(FileIOError::from((entry.path(), e)).into()))
else {
continue 'entries;
else {
continue 'entries;
};
// TODO: Hard ignoring symlinks for now, but this should be configurable
@@ -533,8 +535,8 @@ where
{
get_inode_and_device_from_path(&current_path).await
}
}.map_err(|e| errors.push(e.into()))
else {
}
.map_err(|e| errors.push(e.into())) else {
continue 'entries;
};
@@ -592,10 +594,10 @@ where
}
if accept_by_children_dir.unwrap_or(true) {
let Ok(iso_file_path) = iso_file_path_factory(&current_path, is_dir)
.map_err(|e| errors.push(e))
else {
continue 'entries;
let Ok(iso_file_path) =
iso_file_path_factory(&current_path, is_dir).map_err(|e| errors.push(e))
else {
continue 'entries;
};
paths_buffer.push(WalkingEntry {
@@ -615,11 +617,11 @@ where
.skip(1) // Skip the current directory as it was already indexed
.take_while(|&ancestor| ancestor != root)
{
let Ok(iso_file_path) = iso_file_path_factory(ancestor, true)
.map_err(|e| errors.push(e))
else {
// Checking the next ancestor, as this one we got an error
continue;
let Ok(iso_file_path) =
iso_file_path_factory(ancestor, true).map_err(|e| errors.push(e))
else {
// Checking the next ancestor, as this one we got an error
continue;
};
let mut ancestor_iso_walking_entry = WalkingEntry {
@@ -631,9 +633,9 @@ where
let Ok(metadata) = fs::metadata(ancestor)
.await
.map_err(|e| errors.push(FileIOError::from((&ancestor, e)).into()))
else {
// Checking the next ancestor, as this one we got an error
continue;
else {
// Checking the next ancestor, as this one we got an error
continue;
};
let Ok((inode, device)) = {
#[cfg(target_family = "unix")]
@@ -645,7 +647,8 @@ where
{
get_inode_and_device_from_path(ancestor).await
}
}.map_err(|e| errors.push(e.into())) else {
}
.map_err(|e| errors.push(e.into())) else {
// Checking the next ancestor, as this one we got an error
continue;
};

View File

@@ -67,8 +67,8 @@ pub(super) fn watch_location(
let location_id = location.id;
let location_path = location.path.as_ref();
let Some(location_path) = location_path.map(Path::new) else {
return
};
return;
};
if let Some(mut watcher) = locations_unwatched.remove(&(location_id, library_id)) {
if watcher.check_path(location_path) {
@@ -88,8 +88,8 @@ pub(super) fn unwatch_location(
let location_id = location.id;
let location_path = location.path.as_ref();
let Some(location_path) = location_path.map(Path::new) else {
return
};
return;
};
if let Some(mut watcher) = locations_watched.remove(&(location_id, library_id)) {
if watcher.check_path(location_path) {

View File

@@ -670,14 +670,18 @@ pub(super) async fn remove(
let location_path = extract_location_path(location_id, library).await?;
// if it doesn't exist either way, then we don't care
let Some(file_path) = library.db
let Some(file_path) = library
.db
.file_path()
.find_first(loose_find_existing_file_path_params(
location_id, &location_path, full_path,
location_id,
&location_path,
full_path,
)?)
.exec()
.await? else {
return Ok(());
.await?
else {
return Ok(());
};
remove_by_file_path(location_id, full_path, &file_path, library).await

View File

@@ -814,7 +814,10 @@ async fn check_nested_location(
let comps = location_path.components().collect::<Vec<_>>();
let is_a_child_location = potential_children.into_iter().any(|v| {
let Some(location_path) = v.path else {
warn!("Missing location path on location <id='{}'> at check nested location", v.id);
warn!(
"Missing location path on location <id='{}'> at check nested location",
v.id
);
return false;
};
let comps2 = PathBuf::from(location_path);

View File

@@ -105,7 +105,8 @@ pub async fn walk(
while let Some(entry) = read_dir.next_entry().await.map_err(|e| (path, e))? {
let Ok((entry_path, name)) = normalize_path(entry.path())
.map_err(|e| errors.push(NonIndexedLocationError::from((path, e)).into())) else {
.map_err(|e| errors.push(NonIndexedLocationError::from((path, e)).into()))
else {
continue;
};
@@ -124,10 +125,11 @@ pub async fn walk(
continue;
}
let Ok(metadata) = entry.metadata()
let Ok(metadata) = entry
.metadata()
.await
.map_err(|e| errors.push(NonIndexedLocationError::from((path, e)).into()))
else {
else {
continue;
};
@@ -136,9 +138,10 @@ pub async fn walk(
} else {
let path = Path::new(&entry_path);
let Some(name) = path.file_stem()
let Some(name) = path
.file_stem()
.and_then(|s| s.to_str().map(str::to_string))
else {
else {
warn!("Failed to extract name from path: {}", &entry_path);
continue;
};

View File

@@ -63,12 +63,14 @@ impl OrphanRemoverActor {
.select(object::select!({ id }))
.exec()
.await
.map(|objects| objects.into_iter()
.map(|object| object.id)
.collect::<Vec<_>>()
)
.map(|objects| {
objects
.into_iter()
.map(|object| object.id)
.collect::<Vec<_>>()
})
.map_err(|e| error!("Failed to fetch orphaned objects: {e:#?}"))
else {
else {
break;
};

View File

@@ -147,7 +147,7 @@ impl StatefulJob for ThumbnailerJobInit {
image_files
.into_iter()
.chain(video_files.into_iter())
.chain(video_files)
.collect::<Vec<_>>()
};
#[cfg(not(feature = "ffmpeg"))]

View File

@@ -41,10 +41,8 @@ impl IdentityOrRemoteIdentity {
pub fn to_bytes(&self) -> Vec<u8> {
match self {
Self::Identity(identity) => vec![&[b'I'], &*identity.to_bytes()].concat(),
Self::RemoteIdentity(identity) => {
vec![[b'R'].as_slice(), &identity.to_bytes()].concat()
}
Self::Identity(identity) => [&[b'I'], &*identity.to_bytes()].concat(),
Self::RemoteIdentity(identity) => [[b'R'].as_slice(), &identity.to_bytes()].concat(),
}
}
}

View File

@@ -342,10 +342,9 @@ impl P2PManager {
.await
.unwrap();
let Header::Connected(identities) =
Header::from_stream(stream).await.unwrap() else {
panic!("unreachable but error handling")
};
let Header::Connected(identities) = Header::from_stream(stream).await.unwrap() else {
panic!("unreachable but error handling")
};
for identity in identities {
nlm.peer_connected2(identity, peer_id).await;

View File

@@ -257,11 +257,14 @@ impl PairingManager {
.unwrap()
.insert(pairing_id, tx);
let PairingDecision::Accept(library_id) = rx.await.unwrap() else {
info!("The user rejected pairing '{pairing_id}'!");
// self.emit_progress(pairing_id, PairingStatus::PairingRejected); // TODO: Event to remove from frontend index
stream.write_all(&PairingResponse::Rejected.to_bytes()).await.unwrap();
return;
};
info!("The user rejected pairing '{pairing_id}'!");
// self.emit_progress(pairing_id, PairingStatus::PairingRejected); // TODO: Event to remove from frontend index
stream
.write_all(&PairingResponse::Rejected.to_bytes())
.await
.unwrap();
return;
};
info!("The user accepted pairing '{pairing_id}' for library '{library_id}'!");
let library = library_manager.get_library(&library_id).await.unwrap();
@@ -323,7 +326,8 @@ impl PairingManager {
// node.re
// library_manager.node.nlm.load_library(&library).await;
let Header::Connected(remote_identities) = Header::from_stream(&mut stream).await.unwrap() else {
let Header::Connected(remote_identities) = Header::from_stream(&mut stream).await.unwrap()
else {
todo!("unreachable; todo error handling");
};

View File

@@ -348,10 +348,9 @@ mod responder {
pub async fn run(mut tunnel: Tunnel, library: Arc<Library>) {
let ingest = &library.sync.ingest;
let Ok(mut rx) =
ingest.req_rx.try_lock() else {
return;
};
let Ok(mut rx) = ingest.req_rx.try_lock() else {
return;
};
ingest
.event_tx
@@ -364,7 +363,9 @@ mod responder {
const OPS_PER_REQUEST: u32 = 100;
let Request::Messages { timestamps } = req else { continue };
let Request::Messages { timestamps } = req else {
continue;
};
tunnel
.write_all(

View File

@@ -251,9 +251,9 @@ pub async fn get_volumes() -> Vec<Volume> {
#[cfg(windows)]
let Ok((disk_name, mount_point)) = ({
use normpath::PathExt;
mount_point.normalize_virtually().map(|p| {
(p.localize_name().to_os_string(), p.into_path_buf())
})
mount_point
.normalize_virtually()
.map(|p| (p.localize_name().to_os_string(), p.into_path_buf()))
}) else {
return None;
};

View File

@@ -178,16 +178,16 @@ impl Extension {
always_check_magic_bytes: bool,
) -> Option<Extension> {
let Some(ext_str) = path.as_ref().extension().and_then(OsStr::to_str) else {
return None
};
return None;
};
let Some(ext) = Extension::from_str(ext_str) else {
return None
return None;
};
let Ok(ref mut file) = File::open(&path).await else {
return None
};
return None;
};
match ext {
// we don't need to check the magic bytes unless there is conflict

View File

@@ -1,6 +1,6 @@
import { getLayeredIcon } from '@sd/assets/util';
import { type ImgHTMLAttributes } from 'react';
import { type ObjectKindKey } from '@sd/client';
import { getLayeredIcon } from '@sd/assets/util';
interface LayeredFileIconProps extends ImgHTMLAttributes<HTMLImageElement> {
kind: ObjectKindKey;

View File

@@ -68,11 +68,19 @@ export default ({ tag, onDelete }: Props) => {
</Tooltip>
</Button>
</div>
<div className='flex flex-col gap-2'>
<Setting mini title="Hide in Library search" description="Hide files with this tag from results when searching entire library.">
<div className="flex flex-col gap-2">
<Setting
mini
title="Hide in Library search"
description="Hide files with this tag from results when searching entire library."
>
<Switch />
</Setting>
<Setting mini title="Hide in sidebar" description="Prevent this tag from showing in the sidebar of the app.">
<Setting
mini
title="Hide in sidebar"
description="Prevent this tag from showing in the sidebar of the app."
>
<Switch />
</Setting>
</div>

View File

@@ -23,7 +23,7 @@ export const Component = () => {
// Set the first tag as selected when the tags list data is first loaded
useEffect(() => {
if (tags?.data?.length || 0 > 1 && !selectedTag) setSelectedTag(tags.data?.[0] ?? null);
if (tags?.data?.length || (0 > 1 && !selectedTag)) setSelectedTag(tags.data?.[0] ?? null);
// eslint-disable-next-line react-hooks/exhaustive-deps
}, [tags?.data]);

View File

@@ -39,7 +39,7 @@ const AlertDialog = (props: Props) => {
}}
size="icon"
>
<Clipboard className="w-4 h-4" />
<Clipboard className="h-4 w-4" />
</Button>
}
/>

View File

@@ -64,7 +64,10 @@ export const TEXTViewer = memo(
// Use link to normalize URL
return link ? (
<pre className={className} style={{ wordWrap: 'break-word', whiteSpace: 'pre-wrap', colorScheme: 'dark' }}>
<pre
className={className}
style={{ wordWrap: 'break-word', whiteSpace: 'pre-wrap', colorScheme: 'dark' }}
>
{quickPreviewContent}
</pre>
) : null;

View File

@@ -188,7 +188,7 @@ export function Dialog<S extends FieldValues>({
{props.children}
</div>
<div className="flex flex-row justify-end p-3 space-x-2 border-t border-app-line bg-app-selected">
<div className="flex flex-row justify-end space-x-2 border-t border-app-line bg-app-selected p-3">
{form.formState.isSubmitting && <Loader />}
{props.buttonsSideContent && (
<div>{props.buttonsSideContent}</div>

View File

@@ -86,7 +86,7 @@ export const Input = forwardRef<HTMLInputElement, InputProps>(
e.stopPropagation();
}}
ref={ref}
autoComplete={props.autoComplete || "off"}
autoComplete={props.autoComplete || 'off'}
{...props}
/>
</div>