-
Notifications
You must be signed in to change notification settings - Fork 112
fix: copy image #186
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
fix: copy image #186
Conversation
Reviewer's GuideRefactors image loading and fetching utilities to be promise-based, improves MIME-type handling for image blobs, adds PNG conversion support for clipboard copying, and updates the image toolbar to reliably copy images (especially from authenticated AppFlowy storage) to the clipboard. Sequence diagram for the updated image copy to clipboard flowsequenceDiagram
actor User
participant ImageToolbar
participant ImageUtils
participant AppFlowyStorage
participant Clipboard
User->>ImageToolbar: clickCopyImage()
ImageToolbar->>ImageUtils: fetchImageBlob(imageUrl)
alt isAppFlowyFileStorageUrl
ImageUtils->>AppFlowyStorage: getTokenParsed()
alt tokenAvailable
ImageUtils->>AppFlowyStorage: fetch(fullUrl, AuthorizationBearer)
alt responseOk
AppFlowyStorage-->>ImageUtils: Blob
ImageUtils->>ImageUtils: inferMimeTypeIfGeneric(url)
ImageUtils-->>ImageToolbar: Blob
else responseNotOk
ImageUtils-->>ImageToolbar: null
end
else noToken
ImageUtils-->>ImageToolbar: null
end
else externalUrl
ImageUtils->>AppFlowyStorage: fetch(url)
alt responseOk
AppFlowyStorage-->>ImageUtils: Blob
ImageUtils->>ImageUtils: inferMimeTypeIfGeneric(url)
ImageUtils-->>ImageToolbar: Blob
else responseNotOk
ImageUtils-->>ImageToolbar: null
end
end
alt blobReturned
alt blobTypeNotPng
ImageToolbar->>ImageUtils: convertBlobToPng(blob)
ImageUtils-->>ImageToolbar: pngBlob
ImageToolbar->>Clipboard: navigator.clipboard.write(ClipboardItem{imagePng})
Clipboard-->>ImageToolbar: success
ImageToolbar-->>User: showSuccessNotification
else blobTypeIsPng
ImageToolbar->>Clipboard: navigator.clipboard.write(ClipboardItem{blob})
Clipboard-->>ImageToolbar: success
ImageToolbar-->>User: showSuccessNotification
end
else noBlob
ImageToolbar-->>User: noActionOrError
end
Class diagram for image utilities and ImageToolbar changesclassDiagram
class ImageUtils {
+resolveImageUrl(url string) string
+validateImageLoad(imageUrl string) Promise~CheckImageResult~
+checkImage(url string) Promise~CheckImageResult~
+fetchImageBlob(url string) Promise~Blob or null~
+convertBlobToPng(blob Blob) Promise~Blob~
+getMimeTypeFromUrl(url string) string or null
}
class CheckImageResult {
+ok boolean
+status number
+statusText string
+error string
+validatedUrl string
}
class ImageToolbar {
-editor YjsEditor
-node ImageBlockNode
+onCopyImage() Promise~void~
}
class ClipboardAPI {
+write(items ClipboardItem[]) Promise~void~
}
ImageToolbar ..> ImageUtils : uses
ImageToolbar ..> ClipboardAPI : uses
ImageUtils ..> CheckImageResult : returns
Flow diagram for the refactored checkImage functionflowchart TD
A[checkImage url] --> B{isAppFlowyFileStorageUrl url}
B -- No --> C[return validateImageLoad url]
B -- Yes --> D[getTokenParsed]
D --> E{tokenAvailable}
E -- No --> F[fullUrl = resolveImageUrl url]
F --> G[return validateImageLoad fullUrl]
E -- Yes --> H[fullUrl = resolveImageUrl url]
H --> I[fetch fullUrl with AuthorizationBearer]
I --> J{response.ok}
J -- Yes --> K[blob = await response.blob]
K --> L[blobUrl = URL.createObjectURL blob]
L --> M[return ok 200 validatedUrl blobUrl]
J -- No --> N[log authenticated fetch failed]
N --> O[return validateImageLoad fullUrl]
subgraph validateImageLoad
P[create Image]
P --> Q[start 10s timeout]
P --> R[img.onload]
P --> S[img.onerror]
Q --> T[resolve ok false 408 RequestTimeout]
R --> U[clearTimeout]
R --> V[resolve ok true 200 validatedUrl imageUrl]
S --> W[clearTimeout]
S --> X[resolve ok false 404 ImageNotFound]
end
File-Level Changes
Tips and commandsInteracting with Sourcery
Customizing Your ExperienceAccess your dashboard to:
Getting Help
|
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
* fix: copy image * fix: log
Description
Checklist
General
Testing
Feature-Specific
Summary by Sourcery
Improve image loading, blob handling, and clipboard copying behavior for editor image blocks.
Bug Fixes:
Enhancements: