这是indexloc提供的服务,不要输入任何密码
Skip to content

Conversation

@shatfield4
Copy link
Collaborator

…e slug

Pull Request Type

  • ✨ feat
  • 🐛 fix
  • ♻️ refactor
  • 💄 style
  • 🔨 chore
  • 📝 docs

Relevant Issues

resolves #659

What is in this change?

Describe the changes in this PR that are impactful to the repo.

  • Bug fix for when chinese characters are provided as a workspace name, this would cause the workspace slug to be empty

Additional Information

Add any other context about the Pull Request here that was not captured above.

Developer Validations

  • I ran yarn lint from the root of the repo & committed changes
  • Relevant documentation has been updated
  • I have tested my code functionality
  • Docker build succeeds locally

@review-agent-prime
Copy link

server/models/workspace.js

Instead of using console.error to log the error message, it would be better to throw an error with a meaningful message. This will make it easier to debug and understand the error. Also, it would be better to use a try-catch block for each async operation separately. This will make it easier to identify which operation caused the error.
Create Issue
See the diff
Checkout the fix

    try {
      const workspace = await prisma.workspaces.create({
        data: { name, slug },
      });
    } catch (error) {
      throw new Error(`Failed to create workspace: ${error.message}`);
    }

    try {
      if (!!creatorId) await WorkspaceUser.create(creatorId, workspace.id);
    } catch (error) {
      throw new Error(`Failed to create workspace user: ${error.message}`);
    }
git fetch origin && git checkout -b ReviewBot/Impro-3kgeba8 origin/ReviewBot/Impro-3kgeba8

It would be better to move the logic for generating a unique slug into a separate function. This will make the code more readable and maintainable.
Create Issue
See the diff
Checkout the fix

    function generateUniqueSlug(name) {
      var slug = slugify(name, { lower: true }) || uuidv4();
      const existingBySlug = await this.get({ slug });
      if (existingBySlug !== null) {
        const slugSeed = Math.floor(10000000 + Math.random() * 90000000);
        slug = slugify(`${name}-${slugSeed}`, { lower: true });
      }
      return slug;
    }
git fetch origin && git checkout -b ReviewBot/Impro-xqhcpxb origin/ReviewBot/Impro-xqhcpxb

@timothycarambat timothycarambat merged commit 9d41049 into master Jan 31, 2024
@timothycarambat timothycarambat deleted the 659-bug-when-creating-a-workspace-if-the-name-of-the-space-contains-chinese-characters-the-corresponding-number-for-the-space-is-not-generated-and-it-is-not-possible-to-navigate-to-the-new-spaces-interface-as-shown-in-the-figure branch January 31, 2024 21:38
cabwds pushed a commit to cabwds/anything-llm that referenced this pull request Jul 3, 2025
…Labs#660)

if slug is empty on create workspace, generate a uuid as the workspace slug
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

3 participants