Skip to content
New issue

Have a question about this project? # for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “#”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? # to your account

export different file types #26

Merged
merged 2 commits into from
Oct 31, 2024
Merged

export different file types #26

merged 2 commits into from
Oct 31, 2024

Conversation

Korny666
Copy link
Contributor

@Korny666 Korny666 commented Oct 31, 2024

Sorry but my fork did not want to update...
@NyllRE What do you think of this?

Summary by Sourcery

Add support for exporting different file types by introducing new TypeScript interfaces for ServerFile and ClientFile. Refactor storage utilities and module type exports to utilize these new types, enhancing type safety and consistency across the codebase.

New Features:

  • Introduce support for exporting different file types by defining new TypeScript interfaces for ServerFile and ClientFile.

Enhancements:

  • Refactor the storage utility to use the new ServerFile type for better type safety and clarity.
  • Update the module to export types from a centralized types file, improving type management across the project.

Korny666 and others added 2 commits October 31, 2024 15:53
- Refactor file handling in the Vue component to use the correct type for file content.
- Update imports in the module and composable files to include the types directory.

Closes NyllRE#24

(cherry picked from commit 08cfa60)
Copy link

sourcery-ai bot commented Oct 31, 2024

Reviewer's Guide by Sourcery

This PR improves type definitions and file handling by introducing dedicated type interfaces, moving types to a centralized location, and making minor fixes to file operations. The changes include better TypeScript typing for file-related operations and improved documentation.

Sequence diagram for storing files locally

sequenceDiagram
    participant EventHandler
    participant StorageUtils
    EventHandler->>StorageUtils: storeFileLocally(file, 12, '/specificFolder')
    StorageUtils->>StorageUtils: mkdir(location + filelocation)
    StorageUtils->>StorageUtils: writeFile(location + filelocation + filename, binaryString)
    StorageUtils-->>EventHandler: return filename
Loading

Updated class diagram for file handling types

classDiagram
    class ServerFile {
        +string name
        +string content
        +string size
        +string type
        +string lastModified
    }
    class ClientFile {
        +string|ArrayBuffer|null|undefined content
        +string name
        +number lastModified
    }
    class ModuleOptions {
        +string mount
        +string version
    }
Loading

File-Level Changes

Change Details Files
Centralized type definitions by creating dedicated interfaces for file handling
  • Created new ServerFile and ClientFile interfaces
  • Created ModuleOptions interface
  • Moved all type definitions to a central types.d.ts file
  • Removed old types.d.ts file from types directory
src/types.d.ts
types/types.d.ts
Enhanced type safety and imports across the codebase
  • Added type imports for ServerFile
  • Updated file type references to use new interfaces
  • Exported all types from module
  • Removed inline interface definitions
src/runtime/server/utils/storage.ts
playground/server/api/files.ts
src/module.ts
src/runtime/composables/useFileStorage.ts
Improved documentation and fixed minor issues
  • Enhanced JSDoc comments with backticks for parameters
  • Added detailed documentation for deleteFile function
  • Fixed ref syntax in template
  • Added type casting for file content in template
src/runtime/server/utils/storage.ts
playground/app.vue

Tips and commands

Interacting with Sourcery

  • Trigger a new review: Comment @sourcery-ai review on the pull request.
  • Continue discussions: Reply directly to Sourcery's review comments.
  • Generate a GitHub issue from a review comment: Ask Sourcery to create an
    issue from a review comment by replying to it.
  • Generate a pull request title: Write @sourcery-ai anywhere in the pull
    request title to generate a title at any time.
  • Generate a pull request summary: Write @sourcery-ai summary anywhere in
    the pull request body to generate a PR summary at any time. You can also use
    this command to specify where the summary should be inserted.

Customizing Your Experience

Access your dashboard to:

  • Enable or disable review features such as the Sourcery-generated pull request
    summary, the reviewer's guide, and others.
  • Change the review language.
  • Add, remove or edit custom review instructions.
  • Adjust other review settings.

Getting Help

@Korny666 Korny666 mentioned this pull request Oct 31, 2024
Copy link

@sourcery-ai sourcery-ai bot left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Hey @Korny666 - I've reviewed your changes - here's some feedback:

Overall Comments:

  • The as any type assertion in storage.ts should be avoided. Consider properly typing the binaryString variable instead of bypassing type checking.
  • Removing files.value.splice(0) from handleFileInput could lead to memory leaks or unexpected behavior as files accumulate. Consider keeping the array clear operation or document why it's no longer needed.
Here's what I looked at during the review
  • 🟡 General issues: 1 issue found
  • 🟢 Security: all looks good
  • 🟢 Testing: all looks good
  • 🟢 Complexity: all looks good
  • 🟢 Documentation: all looks good

Sourcery is free for open source - if you like our reviews please consider sharing them ✨
Help me be more useful! Please click 👍 or 👎 on each comment and I'll use the feedback to improve your reviews.

@@ -24,7 +25,6 @@ export default function () {
}

const handleFileInput = async (event: any) => {
Copy link

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

issue (bug_risk): Removed files.value.splice(0) could lead to file accumulation

Without clearing the files array, multiple file selections will keep adding to the array, potentially causing memory issues.

@NyllRE NyllRE merged commit b3cd57a into NyllRE:master Oct 31, 2024
1 check passed
@NyllRE
Copy link
Owner

NyllRE commented Oct 31, 2024

looks great! thanks for your contribution I will be pushing the update to npm soon. I was wondering about something which is a breaking change I wanted to push, do you know the most optimal method of warning the users on a breaking change without displaying a warning in the terminal over and over?

@NyllRE NyllRE mentioned this pull request Oct 31, 2024
@Korny666
Copy link
Contributor Author

Korny666 commented Nov 4, 2024 via email

@NyllRE
Copy link
Owner

NyllRE commented Nov 5, 2024

I just want the user to know that there is a breaking change that you might need to look into but I don't want to add a console.warn() function that keeps warning the user each time they rerun the server

@Korny666
Copy link
Contributor Author

Korny666 commented Nov 6, 2024 via email

@NyllRE
Copy link
Owner

NyllRE commented Nov 6, 2024

Hello, Regarding the pnpm issue I haven't encountered such an issue and I'd like to get more logs on the topic or perhaps create a reproduction of the issue through this link.

About the semantic versioning I was planning on releasing a totally complete version of Nuxt File Storage that has file browser features with even more documentation and some other features that I already made documentation for on file-storage.nuxt.space in addition to a logo change so I will not be touching the major version until I have time to develop the other ideas I had in mind. but for now I believe your suggestion of making it backwards compatible while also implementing the other features I had in mind would be a great move. Thanks for your help!

# for free to join this conversation on GitHub. Already have an account? # to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

2 participants