[ENG-1344] Limit node name length (#1730)

limit length
This commit is contained in:
Oscar Beaumont 2023-11-04 20:16:15 +11:00 committed by GitHub
parent bf543f45d0
commit 395e0ee3da
No known key found for this signature in database
GPG key ID: 4AEE18F83AFDEB23
3 changed files with 13 additions and 10 deletions

View file

@ -20,7 +20,7 @@ pub(crate) fn mount() -> AlphaRouter<Ctx> {
}
R.mutation(|node, args: ChangeNodeNameArgs| async move {
if let Some(name) = &args.name {
if name.is_empty() || name.len() > 32 {
if name.is_empty() || name.len() > 250 {
return Err(rspc::Error::new(
ErrorCode::BadRequest,
"invalid node name".into(),

View file

@ -47,16 +47,19 @@ impl Migrate for NodeConfig {
type Ctx = ();
fn default(_path: PathBuf) -> Result<Self, MigratorError> {
let mut name = match hostname::get() {
// SAFETY: This is just for display purposes so it doesn't matter if it's lossy
Ok(hostname) => hostname.to_string_lossy().into_owned(),
Err(err) => {
eprintln!("Falling back to default node name as an error occurred getting your systems hostname: '{err}'");
"my-spacedrive".into()
}
};
name.truncate(250);
Ok(Self {
id: Uuid::new_v4(),
name: match hostname::get() {
// SAFETY: This is just for display purposes so it doesn't matter if it's lossy
Ok(hostname) => hostname.to_string_lossy().into_owned(),
Err(err) => {
eprintln!("Falling back to default node name as an error occurred getting your systems hostname: '{err}'");
"my-spacedrive".into()
}
},
name,
keypair: Keypair::generate(),
p2p: Default::default(),
features: vec![],

View file

@ -33,7 +33,7 @@ export const Component = () => {
const form = useZodForm({
schema: z.object({
name: z.string().min(1).optional(),
name: z.string().min(1).max(250).optional(),
p2p_enabled: z.boolean().optional(),
p2p_port: u16,
customOrDefault: z.enum(['Custom', 'Default'])