Skip to content

Conversation

@jhoward1994
Copy link
Contributor

@jhoward1994 jhoward1994 commented Mar 27, 2025

What does it do?

Adds file metadata update capabilities to the existing FilesManager class:

  1. New method in the FilesManager class:

    • update(id, data): Updates file metadata for a specific file by ID
  2. Enhanced type definitions:

    • FileUpdateData interface for metadata update parameters
    • FileUpdateResponse type for the update operation result
  3. Error handling for common update scenarios:

    • Non-existent file
    • Invalid update data format

Why is it needed?

The current implementation only allows retrieving files. This addition enables modifying file metadata in the Strapi Media Library.

How to test it?

  1. Testing file metadata updates:

    // Update multiple attributes at once
    const updatedFile = await client.files.update(12, {
      name: "banner-image",
      alternativeText: "Company banner",
      caption: "For homepage header"
    });
  2. Verify error handling:

    // Non-existent file handling
    try {
      await client.files.update(9999, { name: "test" });
    } catch (error) {
      console.error(error); // File not found error
    }

@jhoward1994 jhoward1994 added the flag: don't merge This PR should not be merged at the moment label Mar 27, 2025
@jhoward1994 jhoward1994 changed the title Feat/update-file-metadata Update file metadata Mar 27, 2025
@jhoward1994 jhoward1994 changed the base branch from main to feat/retrieve-files March 27, 2025 11:21
Base automatically changed from feat/retrieve-files to main March 27, 2025 13:57
@jhoward1994 jhoward1994 self-assigned this Mar 28, 2025
@jhoward1994 jhoward1994 removed the flag: don't merge This PR should not be merged at the moment label Mar 28, 2025
@jhoward1994 jhoward1994 added pr: feature New or updates to features source: client-files Source is the files manager labels Mar 28, 2025
Copy link
Contributor

@innerdvations innerdvations left a comment

Choose a reason for hiding this comment

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

LGTM!

}

// Example: Update file metadata
console.log('\n=== File Update Operations ===\n');
Copy link
Contributor

Choose a reason for hiding this comment

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

Just a nitpick, but could we replace all of these with something like:

  console.log(os.EOL);
  console.log('=== File Update Operations ===');
  console.log(os.EOL);

So that it's cleaner to read and works on windows?

@jhoward1994 jhoward1994 marked this pull request as ready for review March 28, 2025 11:35
@jhoward1994 jhoward1994 merged commit 36aa1bb into main Mar 28, 2025
7 checks passed
@jhoward1994 jhoward1994 deleted the feat/update-file-metadata branch March 28, 2025 11:35
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

pr: feature New or updates to features source: client-files Source is the files manager

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants