mirror of
https://github.com/spacedriveapp/spacedrive.git
synced 2025-12-11 20:15:30 +01:00
remove int-enum (#721)
This commit is contained in:
parent
02a14135a2
commit
aeb17e8e72
23
Cargo.lock
generated
23
Cargo.lock
generated
@ -3293,27 +3293,6 @@ dependencies = [
|
||||
"cfg-if",
|
||||
]
|
||||
|
||||
[[package]]
|
||||
name = "int-enum"
|
||||
version = "0.5.0"
|
||||
source = "registry+https://github.com/rust-lang/crates.io-index"
|
||||
checksum = "cff87d3cc4b79b4559e3c75068d64247284aceb6a038bd4bb38387f3f164476d"
|
||||
dependencies = [
|
||||
"int-enum-impl",
|
||||
]
|
||||
|
||||
[[package]]
|
||||
name = "int-enum-impl"
|
||||
version = "0.5.0"
|
||||
source = "registry+https://github.com/rust-lang/crates.io-index"
|
||||
checksum = "df1f2f068675add1a3fc77f5f5ab2e29290c841ee34d151abc007bce902e5d34"
|
||||
dependencies = [
|
||||
"proc-macro-crate 1.2.1",
|
||||
"proc-macro2",
|
||||
"quote",
|
||||
"syn",
|
||||
]
|
||||
|
||||
[[package]]
|
||||
name = "interceptor"
|
||||
version = "0.8.2"
|
||||
@ -6650,7 +6629,6 @@ dependencies = [
|
||||
"httpz 0.0.3 (git+https://github.com/oscartbeaumont/httpz?rev=a5185f2ed2fdefeb2f582dce38a692a1bf76d1d6)",
|
||||
"image",
|
||||
"include_dir",
|
||||
"int-enum",
|
||||
"itertools",
|
||||
"mini-moka",
|
||||
"normpath",
|
||||
@ -6732,7 +6710,6 @@ dependencies = [
|
||||
name = "sd-file-ext"
|
||||
version = "0.0.0"
|
||||
dependencies = [
|
||||
"int-enum",
|
||||
"serde",
|
||||
"serde_json",
|
||||
"strum 0.24.1",
|
||||
|
||||
@ -10,8 +10,12 @@ rust-version = "1.68.1"
|
||||
|
||||
[features]
|
||||
default = []
|
||||
mobile = [] # This feature allows features to be disabled when the Core is running on mobile.
|
||||
ffmpeg = ["dep:ffmpeg-next", "dep:sd-ffmpeg"] # This feature controls whether the Spacedrive Core contains functionality which requires FFmpeg.
|
||||
mobile = [
|
||||
] # This feature allows features to be disabled when the Core is running on mobile.
|
||||
ffmpeg = [
|
||||
"dep:ffmpeg-next",
|
||||
"dep:sd-ffmpeg",
|
||||
] # This feature controls whether the Spacedrive Core contains functionality which requires FFmpeg.
|
||||
location-watcher = ["dep:notify"]
|
||||
sync-messages = []
|
||||
|
||||
@ -43,7 +47,6 @@ serde = { version = "1.0", features = ["derive"] }
|
||||
chrono = { version = "0.4.22", features = ["serde"] }
|
||||
serde_json = "1.0"
|
||||
futures = "0.3"
|
||||
int-enum = "0.5.0"
|
||||
rmp = "^0.8.11"
|
||||
rmp-serde = "^1.1.1"
|
||||
blake3 = "1.3.1"
|
||||
|
||||
@ -30,7 +30,6 @@ use std::{
|
||||
|
||||
use chrono::{DateTime, Utc};
|
||||
use futures::future::BoxFuture;
|
||||
use int_enum::IntEnum;
|
||||
use prisma_client_rust::Direction;
|
||||
use rspc::Type;
|
||||
use serde::{Deserialize, Serialize};
|
||||
@ -178,7 +177,7 @@ impl JobManager {
|
||||
Ok(library
|
||||
.db
|
||||
.job()
|
||||
.find_many(vec![job::status::not(JobStatus::Running.int_value())])
|
||||
.find_many(vec![job::status::not(JobStatus::Running as i32)])
|
||||
.order_by(job::date_created::order(Direction::Desc))
|
||||
.take(100)
|
||||
.exec()
|
||||
@ -219,7 +218,7 @@ impl JobManager {
|
||||
.db
|
||||
.job()
|
||||
.find_many(vec![
|
||||
job::status::equals(JobStatus::Paused.int_value()),
|
||||
job::status::equals(JobStatus::Paused as i32),
|
||||
job::parent_id::equals(None), // only fetch top-level jobs, they will resume their children
|
||||
])
|
||||
.exec()
|
||||
@ -393,11 +392,11 @@ impl Display for JobReport {
|
||||
|
||||
// convert database struct into a resource struct
|
||||
impl From<job::Data> for JobReport {
|
||||
fn from(data: job::Data) -> JobReport {
|
||||
fn from(data: job::Data) -> Self {
|
||||
JobReport {
|
||||
id: Uuid::from_slice(&data.id).unwrap(),
|
||||
name: data.name,
|
||||
status: JobStatus::from_int(data.status).unwrap(),
|
||||
status: JobStatus::try_from(data.status).unwrap(),
|
||||
task_count: data.task_count,
|
||||
completed_task_count: data.completed_task_count,
|
||||
created_at: Some(data.date_created.into()),
|
||||
@ -476,7 +475,7 @@ impl JobReport {
|
||||
.update(
|
||||
job::id::equals(self.id.as_bytes().to_vec()),
|
||||
vec![
|
||||
job::status::set(self.status.int_value()),
|
||||
job::status::set(self.status as i32),
|
||||
job::data::set(self.data.clone()),
|
||||
job::metadata::set(serde_json::to_vec(&self.metadata).ok()),
|
||||
job::task_count::set(self.task_count),
|
||||
@ -492,7 +491,7 @@ impl JobReport {
|
||||
}
|
||||
|
||||
#[repr(i32)]
|
||||
#[derive(Debug, Clone, Copy, Serialize, Deserialize, Type, Eq, PartialEq, IntEnum)]
|
||||
#[derive(Debug, Clone, Copy, Serialize, Deserialize, Type, Eq, PartialEq)]
|
||||
pub enum JobStatus {
|
||||
Queued = 0,
|
||||
Running = 1,
|
||||
@ -501,3 +500,21 @@ pub enum JobStatus {
|
||||
Failed = 4,
|
||||
Paused = 5,
|
||||
}
|
||||
|
||||
impl TryFrom<i32> for JobStatus {
|
||||
type Error = JobError;
|
||||
|
||||
fn try_from(value: i32) -> Result<Self, Self::Error> {
|
||||
let s = match value {
|
||||
0 => Self::Queued,
|
||||
1 => Self::Running,
|
||||
2 => Self::Completed,
|
||||
3 => Self::Canceled,
|
||||
4 => Self::Failed,
|
||||
5 => Self::Paused,
|
||||
_ => return Err(JobError::InvalidJobStatusInt(value)),
|
||||
};
|
||||
|
||||
Ok(s)
|
||||
}
|
||||
}
|
||||
|
||||
@ -51,6 +51,8 @@ pub enum JobError {
|
||||
OsStr,
|
||||
#[error("error converting/handling paths")]
|
||||
Path,
|
||||
#[error("invalid job status integer")]
|
||||
InvalidJobStatusInt(i32),
|
||||
|
||||
// Specific job errors
|
||||
#[error("Indexer error: {0}")]
|
||||
|
||||
@ -222,4 +222,6 @@ pub enum NodeError {
|
||||
FailedToInitializeLibraryManager(#[from] library::LibraryManagerError),
|
||||
#[error("Location manager error: {0}")]
|
||||
LocationManager(#[from] LocationManagerError),
|
||||
#[error("invalid platform integer")]
|
||||
InvalidPlatformInt(i32),
|
||||
}
|
||||
|
||||
@ -13,10 +13,8 @@ use std::{
|
||||
};
|
||||
|
||||
use chrono::{DateTime, Utc};
|
||||
use int_enum::IntEnumError;
|
||||
use rmp_serde::{decode, encode};
|
||||
use rspc::ErrorCode;
|
||||
use rules::RuleKind;
|
||||
use serde::{de::DeserializeOwned, Deserialize, Serialize};
|
||||
use serde_json::json;
|
||||
use thiserror::Error;
|
||||
@ -109,7 +107,7 @@ pub enum IndexerError {
|
||||
|
||||
// User errors
|
||||
#[error("Invalid indexer rule kind integer: {0}")]
|
||||
InvalidRuleKindInt(#[from] IntEnumError<RuleKind>),
|
||||
InvalidRuleKindInt(i32),
|
||||
#[error("Glob builder error: {0}")]
|
||||
GlobBuilderError(#[from] globset::Error),
|
||||
|
||||
|
||||
@ -6,7 +6,6 @@ use crate::{
|
||||
|
||||
use chrono::{DateTime, Utc};
|
||||
use globset::{Glob, GlobSet, GlobSetBuilder};
|
||||
use int_enum::IntEnum;
|
||||
use rmp_serde;
|
||||
use rspc::Type;
|
||||
use serde::{Deserialize, Serialize};
|
||||
@ -56,7 +55,7 @@ impl IndexerRuleCreateArgs {
|
||||
|
||||
#[repr(i32)]
|
||||
#[non_exhaustive]
|
||||
#[derive(Debug, Clone, Copy, Serialize, Deserialize, Type, Eq, PartialEq, IntEnum, Hash)]
|
||||
#[derive(Debug, Clone, Copy, Serialize, Deserialize, Type, Eq, PartialEq, Hash)]
|
||||
pub enum RuleKind {
|
||||
AcceptFilesByGlob = 0,
|
||||
RejectFilesByGlob = 1,
|
||||
@ -64,6 +63,22 @@ pub enum RuleKind {
|
||||
RejectIfChildrenDirectoriesArePresent = 3,
|
||||
}
|
||||
|
||||
impl TryFrom<i32> for RuleKind {
|
||||
type Error = IndexerError;
|
||||
|
||||
fn try_from(value: i32) -> Result<Self, Self::Error> {
|
||||
let s = match value {
|
||||
0 => Self::AcceptFilesByGlob,
|
||||
1 => Self::RejectFilesByGlob,
|
||||
2 => Self::AcceptIfChildrenDirectoriesArePresent,
|
||||
3 => Self::RejectIfChildrenDirectoriesArePresent,
|
||||
_ => return Err(IndexerError::InvalidRuleKindInt(value)),
|
||||
};
|
||||
|
||||
Ok(s)
|
||||
}
|
||||
}
|
||||
|
||||
/// `ParametersPerKind` is a mapping from `RuleKind` to the parameters required for each kind of rule.
|
||||
/// In case of doubt about globs, consult <https://docs.rs/globset/latest/globset/#syntax>
|
||||
///
|
||||
@ -175,7 +190,7 @@ impl TryFrom<&indexer_rule::Data> for IndexerRule {
|
||||
type Error = IndexerError;
|
||||
|
||||
fn try_from(data: &indexer_rule::Data) -> Result<Self, Self::Error> {
|
||||
let kind = RuleKind::from_int(data.kind)?;
|
||||
let kind = RuleKind::try_from(data.kind)?;
|
||||
|
||||
Ok(Self {
|
||||
id: Some(data.id),
|
||||
|
||||
@ -40,7 +40,6 @@ use std::{
|
||||
use sd_file_ext::extensions::ImageExtension;
|
||||
|
||||
use chrono::{DateTime, Local};
|
||||
use int_enum::IntEnum;
|
||||
use notify::{Event, EventKind};
|
||||
use prisma_client_rust::{raw, PrismaValue};
|
||||
use serde_json::json;
|
||||
@ -219,7 +218,7 @@ pub(super) async fn create_file(
|
||||
object::date_created::set(
|
||||
DateTime::<Local>::from(fs_metadata.created_or_now()).into(),
|
||||
),
|
||||
object::kind::set(kind.int_value()),
|
||||
object::kind::set(kind as i32),
|
||||
],
|
||||
)
|
||||
.select(object_just_id_has_thumbnail::select())
|
||||
@ -431,7 +430,7 @@ async fn inner_update_file(
|
||||
generate_thumbnail(&file_path.extension, &cas_id, full_path, library).await;
|
||||
}
|
||||
|
||||
let int_kind = kind.int_value();
|
||||
let int_kind = kind as i32;
|
||||
|
||||
if object.kind != int_kind {
|
||||
sync.write_op(
|
||||
|
||||
@ -1,7 +1,6 @@
|
||||
use crate::prisma::node;
|
||||
use crate::{prisma::node, NodeError};
|
||||
|
||||
use chrono::{DateTime, Utc};
|
||||
use int_enum::IntEnum;
|
||||
use rspc::Type;
|
||||
use serde::{Deserialize, Serialize};
|
||||
use uuid::Uuid;
|
||||
@ -24,7 +23,7 @@ impl From<node::Data> for LibraryNode {
|
||||
Self {
|
||||
uuid: Uuid::from_slice(&data.pub_id).unwrap(),
|
||||
name: data.name,
|
||||
platform: IntEnum::from_int(data.platform).unwrap(),
|
||||
platform: Platform::try_from(data.platform).unwrap(),
|
||||
last_seen: data.last_seen.into(),
|
||||
}
|
||||
}
|
||||
@ -38,7 +37,7 @@ impl From<Box<node::Data>> for LibraryNode {
|
||||
|
||||
#[allow(clippy::upper_case_acronyms)]
|
||||
#[repr(i32)]
|
||||
#[derive(Debug, Clone, Copy, Serialize, Deserialize, Type, Eq, PartialEq, IntEnum)]
|
||||
#[derive(Debug, Clone, Copy, Serialize, Deserialize, Type, Eq, PartialEq)]
|
||||
pub enum Platform {
|
||||
Unknown = 0,
|
||||
Windows = 1,
|
||||
@ -47,3 +46,21 @@ pub enum Platform {
|
||||
IOS = 4,
|
||||
Android = 5,
|
||||
}
|
||||
|
||||
impl TryFrom<i32> for Platform {
|
||||
type Error = NodeError;
|
||||
|
||||
fn try_from(value: i32) -> Result<Self, Self::Error> {
|
||||
let s = match value {
|
||||
0 => Self::Unknown,
|
||||
1 => Self::Windows,
|
||||
2 => Self::MacOS,
|
||||
3 => Self::Linux,
|
||||
4 => Self::IOS,
|
||||
5 => Self::Android,
|
||||
_ => return Err(NodeError::InvalidPlatformInt(value)),
|
||||
};
|
||||
|
||||
Ok(s)
|
||||
}
|
||||
}
|
||||
|
||||
@ -13,7 +13,6 @@ use sd_file_ext::{extensions::Extension, kind::ObjectKind};
|
||||
use sd_sync::CRDTOperation;
|
||||
|
||||
use futures::future::join_all;
|
||||
use int_enum::IntEnum;
|
||||
use serde::{Deserialize, Serialize};
|
||||
use serde_json::json;
|
||||
use std::{
|
||||
@ -240,7 +239,7 @@ async fn identifier_job_step(
|
||||
};
|
||||
|
||||
let size = meta.fs_metadata.len().to_string();
|
||||
let kind = meta.kind.int_value();
|
||||
let kind = meta.kind as i32;
|
||||
|
||||
let object_creation_args = (
|
||||
[sync.shared_create(sync_id())]
|
||||
|
||||
@ -9,7 +9,6 @@ authors = [
|
||||
# See more keys and their definitions at https://doc.rust-lang.org/cargo/reference/manifest.html
|
||||
|
||||
[dependencies]
|
||||
int-enum = "0.5.0"
|
||||
serde = { version = "1.0.145", features = ["derive"] }
|
||||
serde_json = "1.0.85"
|
||||
strum = { version = "0.24", features = ["derive"] }
|
||||
|
||||
@ -1,53 +1,50 @@
|
||||
/// Object Kind
|
||||
///
|
||||
use int_enum::IntEnum;
|
||||
use serde::{Deserialize, Serialize};
|
||||
|
||||
#[repr(i32)]
|
||||
#[derive(Debug, Clone, Copy, Serialize, Deserialize, Eq, PartialEq, IntEnum)]
|
||||
#[derive(Debug, Clone, Copy, Serialize, Deserialize, Eq, PartialEq)]
|
||||
pub enum ObjectKind {
|
||||
// A file that can not be identified by the indexer
|
||||
/// A file that can not be identified by the indexer
|
||||
Unknown = 0,
|
||||
// A known filetype, but without specific support
|
||||
/// A known filetype, but without specific support
|
||||
Document = 1,
|
||||
// A virtual filesystem directory
|
||||
/// A virtual filesystem directory
|
||||
Folder = 2,
|
||||
// A file that contains human-readable text
|
||||
/// A file that contains human-readable text
|
||||
Text = 3,
|
||||
// A virtual directory int
|
||||
/// A virtual directory int
|
||||
Package = 4,
|
||||
// An image file
|
||||
/// An image file
|
||||
Image = 5,
|
||||
// An audio file
|
||||
/// An audio file
|
||||
Audio = 6,
|
||||
// A video file
|
||||
/// A video file
|
||||
Video = 7,
|
||||
// A compressed archive of data
|
||||
/// A compressed archive of data
|
||||
Archive = 8,
|
||||
// An executable, program or application
|
||||
/// An executable, program or application
|
||||
Executable = 9,
|
||||
// A link to another object
|
||||
/// A link to another object
|
||||
Alias = 10,
|
||||
// Raw bytes encrypted by Spacedrive with self contained metadata
|
||||
/// Raw bytes encrypted by Spacedrive with self contained metadata
|
||||
Encrypted = 11,
|
||||
// A link can open web pages, apps or Spaces
|
||||
/// A link can open web pages, apps or Spaces
|
||||
Key = 12,
|
||||
// A link can open web pages, apps or Spaces
|
||||
/// A link can open web pages, apps or Spaces
|
||||
Link = 13,
|
||||
// A special filetype that represents a preserved webpage
|
||||
/// A special filetype that represents a preserved webpage
|
||||
WebPageArchive = 14,
|
||||
// A widget is a mini app that can be placed in a Space at various sizes, associated Widget struct required
|
||||
/// A widget is a mini app that can be placed in a Space at various sizes, associated Widget struct required
|
||||
Widget = 15,
|
||||
// Albums can only have one level of children, and are associated with the Album struct
|
||||
/// Albums can only have one level of children, and are associated with the Album struct
|
||||
Album = 16,
|
||||
// Its like a folder, but appears like a stack of files, designed for burst photos / associated groups of files
|
||||
/// Its like a folder, but appears like a stack of files, designed for burst photos / associated groups of files
|
||||
Collection = 17,
|
||||
// You know, text init
|
||||
/// You know, text init
|
||||
Font = 18,
|
||||
// 3D Object
|
||||
/// 3D Object
|
||||
Mesh = 19,
|
||||
// Editable source code file
|
||||
/// Editable source code file
|
||||
Code = 20,
|
||||
// Database file
|
||||
/// Database file
|
||||
Database = 21,
|
||||
}
|
||||
|
||||
Loading…
x
Reference in New Issue
Block a user