Skip to content
New issue

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

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

Already on GitHub? Sign in to your account

using cache storage store image data #5013 #5061

Merged
merged 7 commits into from
Jul 19, 2024

Conversation

lloydzhou
Copy link
Contributor

@lloydzhou lloydzhou commented Jul 19, 2024

πŸ’» ε˜ζ›΄η±»εž‹ | Change Type

  • feat
  • fix
  • refactor
  • perf
  • style
  • test
  • docs
  • ci
  • chore
  • build

πŸ”€ ε˜ζ›΄θ―΄ζ˜Ž | Description of Change

  1. using cache storage store image data
  2. get base64image before chat to api

πŸ“ θ‘₯充俑息 | Additional Information

close #5013

Summary by CodeRabbit

  • New Features

    • Enhanced image processing capabilities, including uploading and caching.
    • Improved message handling logic to accommodate different content types, especially images.
    • Introduced new functionalities for pre-processing, caching, uploading, and removing images.
  • Bug Fixes

    • Improved service worker registration process for better responsiveness and reliability.

@lloydzhou lloydzhou requested a review from Dogtiti July 19, 2024 05:53
Copy link

vercel bot commented Jul 19, 2024

@lloydzhou is attempting to deploy a commit to the NextChat Team on Vercel.

A member of the Team first needs to authorize it.

@lloydzhou lloydzhou added the enhancement New feature or request label Jul 19, 2024
Copy link
Contributor

coderabbitai bot commented Jul 19, 2024

Walkthrough

The recent code changes enhance the application's image handling by introducing new functionalities for processing, caching, uploading, and removing images. The integration of CacheStorage improves performance and user experience by facilitating efficient resource management. Additionally, the service worker's capabilities have been expanded to ensure timely updates and improved responsiveness when dealing with image content.

Changes

Files Change Summary
app/utils/chat.ts Introduced functions for image processing, base64 conversion, caching, uploading, and removal.
public/serviceWorkerRegister.js Updated service worker registration to enhance timing and responsiveness with improved state change handling.

Sequence Diagram(s)

sequenceDiagram
    participant User
    participant ChatComponent
    participant ServiceWorker
    participant CacheStorage

    User->>ChatComponent: Upload Image
    ChatComponent->>ServiceWorker: Call uploadImage
    ServiceWorker->>CacheStorage: Store image in cache
    CacheStorage-->>ServiceWorker: Confirm storage
    ServiceWorker-->>ChatComponent: Return cached image URL
    ChatComponent-->>User: Display uploaded image
Loading

Assessment against linked issues

Objective Addressed Explanation
Using CacheStorage to store images (#[5013]) βœ…
Upload images using fetch and store in CacheStorage (#[5013]) βœ…
Component displays images from CacheStorage (#[5013]) βœ…

🐰✨
In a world of bytes and bits,
A rabbit hops, and never quits.
With images stored, so bright and clear,
Cache is here, let’s all cheer!
Remote uploads, how grand a sight,
Happy coding, from day to night!
πŸŒ™πŸ’»


Thank you for using CodeRabbit. We offer it for free to the OSS community and would appreciate your support in helping us grow. If you find it useful, would you consider giving us a shout-out on your favorite social media?

Share
Tips

Chat

There are 3 ways to chat with CodeRabbit:

  • Review comments: Directly reply to a review comment made by CodeRabbit. Example:
    • I pushed a fix in commit <commit_id>.
    • Generate unit testing code for this file.
    • Open a follow-up GitHub issue for this discussion.
  • Files and specific lines of code (under the "Files changed" tab): Tag @coderabbitai in a new review comment at the desired location with your query. Examples:
    • @coderabbitai generate unit testing code for this file.
    • @coderabbitai modularize this function.
  • PR comments: Tag @coderabbitai in a new PR comment to ask questions about the PR branch. For the best results, please provide a very specific query, as very limited context is provided in this mode. Examples:
    • @coderabbitai generate interesting stats about this repository and render them as a table.
    • @coderabbitai show all the console.log statements in this repository.
    • @coderabbitai read src/utils.ts and generate unit testing code.
    • @coderabbitai read the files in the src/scheduler package and generate a class diagram using mermaid and a README in the markdown format.
    • @coderabbitai help me debug CodeRabbit configuration file.

Note: Be mindful of the bot's finite context window. It's strongly recommended to break down tasks such as reading entire modules into smaller chunks. For a focused discussion, use review comments to chat about specific files and their changes, instead of using the PR comments.

CodeRabbit Commands (invoked as PR comments)

  • @coderabbitai pause to pause the reviews on a PR.
  • @coderabbitai resume to resume the paused reviews.
  • @coderabbitai review to trigger an incremental review. This is useful when automatic reviews are disabled for the repository.
  • @coderabbitai full review to do a full review from scratch and review all the files again.
  • @coderabbitai summary to regenerate the summary of the PR.
  • @coderabbitai resolve resolve all the CodeRabbit review comments.
  • @coderabbitai configuration to show the current CodeRabbit configuration for the repository.
  • @coderabbitai help to get help.

Additionally, you can add @coderabbitai ignore anywhere in the PR description to prevent this PR from being reviewed.

CodeRabbit Configuration File (.coderabbit.yaml)

  • You can programmatically configure CodeRabbit by adding a .coderabbit.yaml file to the root of your repository.
  • Please see the configuration documentation for more information.
  • If your editor has YAML language server enabled, you can add the path at the top of this file to enable auto-completion and validation: # yaml-language-server: $schema=https://coderabbit.ai/integrations/schema.v2.json

Documentation and Community

  • Visit our Documentation for detailed information on how to use CodeRabbit.
  • Join our Discord Community to get help, request features, and share feedback.
  • Follow us on X/Twitter for updates and announcements.

Copy link
Contributor

@coderabbitai coderabbitai bot left a comment

Choose a reason for hiding this comment

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

Actionable comments posted: 3

Outside diff range, codebase verification and nitpick comments (3)
public/serviceWorker.js (1)

Line range hint 88-88:
Refactor: Avoid assignment within an expression.

The assignment within the expression can be confusing. Refactor it to improve readability.

-  (blob) => (imageCaches[imageUrl] = compressImage(blob, 256 * 1024)),
+  (blob) => {
+    imageCaches[imageUrl] = compressImage(blob, 256 * 1024);
+    return imageCaches[imageUrl];
+  },
app/components/chat.tsx (2)

Ensure proper error handling in the uploadImage function.

The uploadImage function uses uploadImageRemote to handle image uploads. While one instance includes error handling with a .catch block, another instance does not. Ensure that errors are handled consistently and the user is informed of any issues.

  • File: app/components/chat.tsx
  • Lines: 1209-1215
Analysis chain

Line range hint 1212-1220: Ensure proper error handling in the uploadImage function.

The uploadImage function uses uploadImageRemote to handle image uploads. Ensure that errors are handled gracefully and the user is informed of any issues.

Scripts executed

The following scripts were executed for the analysis:

Script:

#!/bin/bash
# Description: Verify the error handling in the `uploadImage` function.

# Test: Search for the usage of `uploadImageRemote` in the `uploadImage` function. Expect: Proper error handling and user notification.
rg --type tsx -A 5 $'uploadImageRemote'

Length of output: 66


Script:

#!/bin/bash
# Description: Verify the error handling in the `uploadImage` function.

# Test: Search for the usage of `uploadImageRemote` in TypeScript files. Expect: Proper error handling and user notification.
rg 'uploadImageRemote' -A 10 --glob '*.ts' --glob '*.tsx'

Length of output: 1923


Ensure proper error handling in the paste event handler.

The paste event handler uses uploadImageRemote to handle image uploads. The current implementation lacks user notifications for errors. Please add user notifications to inform the user of any issues during the image upload process.

  • First instance: Add user notification in the catch block after setUploading(false) and before rej(e).
  • Second instance: Add a catch block with appropriate error handling and user notification.
Analysis chain

Line range hint 1170-1176: Ensure proper error handling in the paste event handler.

The paste event handler uses uploadImageRemote to handle image uploads. Ensure that errors are handled gracefully and the user is informed of any issues.

Scripts executed

The following scripts were executed for the analysis:

Script:

#!/bin/bash
# Description: Verify the error handling in the paste event handler.

# Test: Search for the usage of `uploadImageRemote` in the paste event handler. Expect: Proper error handling and user notification.
rg --type tsx -A 5 $'uploadImageRemote'

Length of output: 66


Script:

#!/bin/bash
# Description: Verify the error handling in the paste event handler.

# Test: Search for the usage of `uploadImageRemote` in the paste event handler. Expect: Proper error handling and user notification.
rg --type js -A 5 $'uploadImageRemote'

Length of output: 37


Script:

#!/bin/bash
# Description: Verify the error handling in the paste event handler.

# Test: Search for the usage of `uploadImageRemote` in the paste event handler. Expect: Proper error handling and user notification.
rg --type ts -A 5 $'uploadImageRemote'

Length of output: 1155


Script:

#!/bin/bash
# Description: Verify the error handling in the paste event handler.

# Test: Search for the usage of `uploadImageRemote` in the paste event handler and capture more lines to check error handling.
rg --type ts -A 10 -B 5 $'uploadImageRemote'

Length of output: 2781

Review details

Configuration used: CodeRabbit UI
Review profile: CHILL

Commits

Files that changed from the base of the PR and between afa1a43 and 287fa0a.

Files selected for processing (9)
  • app/client/platforms/alibaba.ts (1 hunks)
  • app/client/platforms/anthropic.ts (3 hunks)
  • app/client/platforms/google.ts (2 hunks)
  • app/client/platforms/openai.ts (2 hunks)
  • app/components/chat.tsx (3 hunks)
  • app/constant.ts (2 hunks)
  • app/utils/chat.ts (3 hunks)
  • public/serviceWorker.js (1 hunks)
  • public/serviceWorkerRegister.js (1 hunks)
Files skipped from review due to trivial changes (1)
  • app/client/platforms/alibaba.ts
Additional context used
Biome
app/utils/chat.ts

[error] 88-88: The assignment should not be in an expression.

The use of assignments in expressions is confusing.
Expressions are often considered as side-effect free.

(lint/suspicious/noAssignInExpressions)

Additional comments not posted (27)
public/serviceWorkerRegister.js (2)

5-7: Good practice: Update service worker registration.

The addition of registration.update() ensures that the service worker checks for updates immediately after registration, which helps in keeping the service worker up-to-date.


11-14: Good practice: Handle controllerchange event.

Adding an event listener for controllerchange ensures that the page reloads when a new service worker takes control, which helps in using the latest version of the service worker.

public/serviceWorker.js (5)

2-3: Good practice: Define cache constants.

Defining CHATGPT_NEXT_WEB_FILE_CACHE and CHATGPT_NEXT_WEB_CACHE helps in managing different caches within the service worker, improving code readability and maintainability.


3-3: Good practice: Add nanoid function for unique identifiers.

The nanoid function generates unique identifiers for files, which helps in managing cached files effectively.


10-10: Good practice: Call self.skipWaiting() in install event.

Calling self.skipWaiting() ensures that the new service worker takes control immediately after installation, which helps in using the latest version of the service worker.


39-43: Good implementation: Handle file deletions in remove function.

The remove function correctly handles file deletions from the cache based on the request URL.


45-58: Good implementation: Handle different HTTP methods in fetch event listener.

The fetch event listener correctly distinguishes between GET, POST, and DELETE methods for API requests related to file caching and calls the appropriate function for each method.

app/utils/chat.ts (5)

1-2: Good practice: Import necessary constants.

The import statement correctly includes the necessary constants CACHE_URL_PREFIX and UPLOAD_URL for image processing and caching.


44-44: Good practice: Dynamically import heic2any library.

Dynamically importing the heic2any library ensures it is only loaded when necessary, improving performance.


76-94: Good implementation: Manage image caching in cacheImageToBase64Image function.

The cacheImageToBase64Image function correctly checks if the image URL includes the specified CACHE_URL_PREFIX and retrieves the image as a blob, compressing it if not already cached.

Tools
Biome

[error] 88-88: The assignment should not be in an expression.

The use of assignments in expressions is confusing.
Expressions are often considered as side-effect free.

(lint/suspicious/noAssignInExpressions)


96-104: Good implementation: Convert base64 string to Blob object in base64Image2Blob function.

The base64Image2Blob function correctly converts a base64 string to a Blob object by decoding the base64 string and creating a Uint8Array.


125-131: Good implementation: Handle image deletions in removeImage function.

The removeImage function correctly sends a DELETE request to the server to delete an image.

app/constant.ts (2)

24-24: Addition of CACHE_URL_PREFIX is appropriate.

The constant CACHE_URL_PREFIX is correctly defined to provide a base path for cache-related API calls.


25-25: Addition of UPLOAD_URL is appropriate.

The constant UPLOAD_URL is correctly defined to provide an upload endpoint using the CACHE_URL_PREFIX.

app/client/platforms/google.ts (6)

17-17: Import of preProcessImageContent is necessary.

The import of preProcessImageContent from @/app/utils/chat is required for the changes made in the chat method.


62-62: Initialization of _messages array is necessary.

The _messages array is correctly initialized to store processed messages.


63-65: Asynchronous loop for processing message content is necessary.

The loop correctly processes each message's content using preProcessImageContent and stores the processed messages in _messages.


66-66: Mapping of _messages to create messages array is necessary.

The mapping correctly creates the messages array with the preprocessed content.


Line range hint 67-87: Processing of messages for vision models is necessary.

The processing correctly handles vision models by extracting image data and creating parts for the messages.


Line range hint 88-96: Merging of consecutive messages with the same role is necessary.

The merging correctly ensures that roles in neighboring messages are not the same, complying with Google's requirement.

app/client/platforms/anthropic.ts (5)

15-15: Import of preProcessImageContent is necessary.

The import of preProcessImageContent from @/app/utils/chat is required for the changes made in the chat method.


98-98: Initialization of messages array is necessary.

The messages array is correctly initialized to store processed messages.


99-101: Asynchronous loop for processing message content is necessary.

The loop correctly processes each message's content using preProcessImageContent and stores the processed messages in messages.


144-144: Console log statement enhances debugging capabilities.

The log statement provides valuable insight into the message processing flow by logging the type, text, and image URL of each processed message.


Line range hint 103-143: Construction of prompt array is necessary.

The prompt array is correctly constructed by filtering and mapping the messages array, ensuring that each message's content is processed correctly.

app/client/platforms/openai.ts (1)

109-115: Ensure correct handling of image content for vision models.

The conditional check for vision models and the usage of preProcessImageContent seem correct. However, ensure that preProcessImageContent handles errors gracefully and returns a valid content format.

app/components/chat.tsx (1)

64-64: Ensure correct usage of uploadImageRemote.

The uploadImageRemote function replaces compressImage. Ensure that uploadImageRemote handles errors gracefully and returns a valid data URL.

public/serviceWorker.js Show resolved Hide resolved
app/utils/chat.ts Outdated Show resolved Hide resolved
app/utils/chat.ts Outdated Show resolved Hide resolved
Copy link

vercel bot commented Jul 19, 2024

The latest updates on your projects. Learn more about Vercel for Git β†—οΈŽ

Name Status Preview Comments Updated (UTC)
nextchat ❌ Failed (Inspect) Jul 19, 2024 6:00am

Copy link
Contributor

@coderabbitai coderabbitai bot left a comment

Choose a reason for hiding this comment

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

Actionable comments posted: 1

Review details

Configuration used: CodeRabbit UI
Review profile: CHILL

Commits

Files that changed from the base of the PR and between 287fa0a and 7237d33.

Files selected for processing (4)
  • app/client/platforms/anthropic.ts (4 hunks)
  • app/client/platforms/google.ts (2 hunks)
  • app/client/platforms/openai.ts (2 hunks)
  • app/utils/chat.ts (2 hunks)
Files skipped from review as they are similar to previous changes (1)
  • app/client/platforms/google.ts
Additional context used
Biome
app/utils/chat.ts

[error] 90-90: The assignment should not be in an expression.

The use of assignments in expressions is confusing.
Expressions are often considered as side-effect free.

(lint/suspicious/noAssignInExpressions)

Additional comments not posted (8)
app/utils/chat.ts (5)

59-75: LGTM! Add error handling for cacheImageToBase64Image.

The function correctly processes different content types. Consider adding error handling for cacheImageToBase64Image.

-      const url = await cacheImageToBase64Image(part?.image_url?.url);
-      result.push({ type: part.type, image_url: { url } });
+      try {
+        const url = await cacheImageToBase64Image(part?.image_url?.url);
+        result.push({ type: part.type, image_url: { url } });
+      } catch (error) {
+        console.error('Error processing image URL:', error);
+      }

98-106: LGTM!

The function correctly converts base64 data to a Blob object.


108-125: LGTM! Add error handling for the fetch request.

The function correctly uploads an image file. Consider adding error handling for the fetch request.

-  return fetch(UPLOAD_URL, {
-    method: "post",
-    body,
-    mode: "cors",
-    credentials: "include",
-  })
-    .then((res) => res.json())
-    .then((res) => {
-      console.log("res", res);
-      if (res?.code == 0 && res?.data) {
-        return res?.data;
-      }
-      throw Error(`upload Error: ${res?.msg}`);
-    });
+  return fetch(UPLOAD_URL, {
+    method: "post",
+    body,
+    mode: "cors",
+    credentials: "include",
+  })
+    .then((res) => {
+      if (!res.ok) {
+        throw new Error('Network response was not ok');
+      }
+      return res.json();
+    })
+    .then((res) => {
+      console.log("res", res);
+      if (res?.code == 0 && res?.data) {
+        return res?.data;
+      }
+      throw Error(`upload Error: ${res?.msg}`);
+    });

127-133: LGTM!

The function correctly sends a DELETE request to remove an image from the server.


Line range hint 1-50:
LGTM! Verify the dynamic import of heic2any.

The dynamic import of heic2any is a good practice for performance optimization.

Ensure the dynamic import works correctly in all environments.

Verification successful

LGTM! The dynamic import of heic2any is correctly implemented.

The dynamic import of heic2any is a good practice for performance optimization.

  • app/utils/chat.ts: const heic2any = require("heic2any");
Scripts executed

The following scripts were executed for the analysis:

Script:

#!/bin/bash
# Description: Verify the dynamic import of `heic2any` works correctly.

# Test: Search for the usage of `heic2any` to ensure it's dynamically imported.
rg --type javascript 'require\("heic2any"\)'

Length of output: 81


Script:

#!/bin/bash
# Description: Verify the dynamic import of `heic2any` works correctly.

# Test: Search for the usage of `heic2any` to ensure it's dynamically imported.
rg 'require\("heic2any"\)'

Length of output: 90

Tools
Biome

[error] 90-90: The assignment should not be in an expression.

The use of assignments in expressions is confusing.
Expressions are often considered as side-effect free.

(lint/suspicious/noAssignInExpressions)

app/client/platforms/anthropic.ts (2)

96-101: LGTM! Verify the performance impact of asynchronous processing.

The function correctly processes messages asynchronously. Ensure the performance impact is acceptable.


143-143: LGTM!

The console log statement enhances debugging capabilities.

app/client/platforms/openai.ts (1)

109-115: LGTM! Verify the performance impact of asynchronous processing.

The function correctly processes messages asynchronously and conditionally. Ensure the performance impact is acceptable.

app/utils/chat.ts Outdated Show resolved Hide resolved
Copy link
Contributor

Your build has completed!

Preview deployment

Copy link
Contributor

@coderabbitai coderabbitai bot left a comment

Choose a reason for hiding this comment

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

Actionable comments posted: 0

Review details

Configuration used: CodeRabbit UI
Review profile: CHILL

Commits

Files that changed from the base of the PR and between 7237d33 and a765237.

Files selected for processing (2)
  • app/client/platforms/anthropic.ts (3 hunks)
  • public/serviceWorkerRegister.js (1 hunks)
Files skipped from review as they are similar to previous changes (1)
  • public/serviceWorkerRegister.js
Additional comments not posted (2)
app/client/platforms/anthropic.ts (2)

14-14: Import statement for preProcessImageContent.

The import statement for preProcessImageContent is correctly added. Ensure that this function is properly implemented and tested.


97-101: Asynchronous loop for processing messages.

The asynchronous loop processes each message's content using the preProcessImageContent function. This change ensures that image content is handled appropriately before being added to the messages array.

Copy link
Contributor

@coderabbitai coderabbitai bot left a comment

Choose a reason for hiding this comment

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

Actionable comments posted: 5

Outside diff range, codebase verification and nitpick comments (1)
app/utils/chat.ts (1)

Line range hint 5-54:
Clean up canvas element after use.

The canvas element should be cleaned up after use to avoid potential memory leaks.

        resolve(dataUrl);
+       canvas = null;
+       ctx = null;
      };
Tools
Biome

[error] 90-90: The assignment should not be in an expression.

The use of assignments in expressions is confusing.
Expressions are often considered as side-effect free.

(lint/suspicious/noAssignInExpressions)

Review details

Configuration used: CodeRabbit UI
Review profile: CHILL

Commits

Files that changed from the base of the PR and between a765237 and 052004d.

Files selected for processing (2)
  • app/utils/chat.ts (2 hunks)
  • public/serviceWorkerRegister.js (1 hunks)
Files skipped from review as they are similar to previous changes (1)
  • public/serviceWorkerRegister.js
Additional context used
Biome
app/utils/chat.ts

[error] 90-90: The assignment should not be in an expression.

The use of assignments in expressions is confusing.
Expressions are often considered as side-effect free.

(lint/suspicious/noAssignInExpressions)

Additional comments not posted (2)
app/utils/chat.ts (2)

98-106: LGTM!

The base64Image2Blob function is correctly implemented.


131-137: LGTM!

The removeImage function is correctly implemented.

app/utils/chat.ts Show resolved Hide resolved
app/utils/chat.ts Show resolved Hide resolved
app/utils/chat.ts Outdated Show resolved Hide resolved
app/utils/chat.ts Outdated Show resolved Hide resolved
app/utils/chat.ts Show resolved Hide resolved
Copy link
Contributor

@coderabbitai coderabbitai bot left a comment

Choose a reason for hiding this comment

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

Actionable comments posted: 0

Review details

Configuration used: CodeRabbit UI
Review profile: CHILL

Commits

Files that changed from the base of the PR and between 052004d and 862c2e8.

Files selected for processing (1)
  • app/utils/chat.ts (2 hunks)
Additional context used
Biome
app/utils/chat.ts

[error] 97-97: The assignment should not be in an expression.

The use of assignments in expressions is confusing.
Expressions are often considered as side-effect free.

(lint/suspicious/noAssignInExpressions)

Additional comments not posted (8)
app/utils/chat.ts (8)

44-55: Add error handling for dynamic import.

The dynamic import of heic2any should include error handling to manage cases where the import fails.

-      try {
-        const heic2any = require("heic2any");
-        heic2any({ blob: file, toType: "image/jpeg" })
-          .then((blob: Blob) => {
-            reader.readAsDataURL(blob);
-          })
-          .catch((e: any) => {
-            reject(e);
-          });
-      } catch (e) {
-        reject(e);
-      }
+      let heic2any;
+      try {
+        heic2any = require("heic2any");
+      } catch (e) {
+        return reject(new Error("Failed to load heic2any library"));
+      }
+      heic2any({ blob: file, toType: "image/jpeg" })
+        .then((blob: Blob) => {
+          reader.readAsDataURL(blob);
+        })
+        .catch((e: any) => {
+          reject(e);
+        });

62-76: Add error handling for cacheImageToBase64Image function call.

The function should handle potential errors when calling cacheImageToBase64Image.

-      const url = await cacheImageToBase64Image(part?.image_url?.url);
-      result.push({ type: part.type, image_url: { url } });
+      try {
+        const url = await cacheImageToBase64Image(part?.image_url?.url);
+        result.push({ type: part.type, image_url: { url } });
+      } catch (error) {
+        console.error('Error processing image URL:', error);
+      }

96-98: Avoid assignment in expressions.

The use of assignments in expressions can be confusing. Refactor to separate the assignment from the expression.

-        .then(
-          async (blob) =>
-            (imageCaches[imageUrl] = await compressImage(blob, 256 * 1024)),
-        ); // compressImage
+        .then(async (blob) => {
+          const compressedImage = await compressImage(blob, 256 * 1024);
+          imageCaches[imageUrl] = compressedImage;
+          return compressedImage;
+        }); // compressImage
Tools
Biome

[error] 97-97: The assignment should not be in an expression.

The use of assignments in expressions is confusing.
Expressions are often considered as side-effect free.

(lint/suspicious/noAssignInExpressions)


105-113: LGTM!

The base64Image2Blob function correctly converts a base64 string to a Blob.


122-135: Add error handling for fetch request.

The fetch request should include error handling to manage cases where the network response is not ok.

    .then((res) => res.json())
+   .then((res) => {
+     if (!res.ok) {
+       throw new Error('Network response was not ok');
+     }
+     return res.json();
+   })

138-144: LGTM!

The removeImage function correctly sends a DELETE request to remove an image.


1-2: LGTM!

The imports are correctly implemented.


44-55: Verify reader.readAsDataURL(file) call.

Ensure that reader.readAsDataURL(file) is not called twice when the file is of type HEIC.

@Dogtiti Dogtiti merged commit 9a78a72 into ChatGPTNextWeb:main Jul 19, 2024
1 of 2 checks passed
@lloydzhou lloydzhou deleted the feature-cache-storage branch August 1, 2024 05:13
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
enhancement New feature or request
Projects
None yet
Development

Successfully merging this pull request may close these issues.

[Feature Request] using CacheStorage to store image
2 participants