-
Notifications
You must be signed in to change notification settings - Fork 112
Console log #187
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
Merged
Merged
Console log #187
Conversation
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Reviewer's GuideCentralizes logging through the shared Log utility, adds image-blob validation for authenticated image fetching, and removes a few low-level debug calls from the Yjs editor integration. Sequence diagram for authenticated image fetch with blob validationsequenceDiagram
actor User
participant Browser
participant ImageUtils as ImageUtils_checkImage
participant Auth as Auth_getTokenParsed
participant Storage as AppFlowyFileStorage
participant Log
User->>Browser: Navigate to page with image URL
Browser->>ImageUtils: checkImage(url)
alt isAppFlowyFileStorageUrl(url)
ImageUtils->>Auth: getTokenParsed()
alt token exists
ImageUtils->>Storage: fetch(url, { Authorization: Bearer token })
Storage-->>ImageUtils: HTTP response
alt response.ok
ImageUtils->>ImageUtils: response.blob()
ImageUtils->>ImageUtils: validateImageBlob(blob, url)
alt blob is JSON (application/json)
ImageUtils->>Log: Log.error("Image fetch returned JSON instead of image", text)
ImageUtils-->>Browser: { ok: false, status: 406, error: "Image fetch returned JSON instead of image" }
else non JSON blob
ImageUtils->>Browser: URL.createObjectURL(validatedBlob)
Browser-->>User: Image rendered from blob URL
end
else !response.ok
ImageUtils-->>Browser: { ok: false, status: response.status }
end
else no token
ImageUtils-->>Browser: { ok: false, status: 401 }
end
else not AppFlowy file URL
Browser->>ImageUtils: validateImageLoad(url)
ImageUtils-->>Browser: Load result using plain URL
end
Class diagram for updated Log utilityclassDiagram
class Log {
- prototype
+constructor()
+debug(msg1, msg2, msg3, msg4, msg5)
+trace(msg1, msg2, msg3, msg4, msg5)
+info(msg1, msg2, msg3, msg4, msg5)
+warn(msg1, msg2, msg3, msg4, msg5)
+error(msg1, msg2, msg3, msg4, msg5)
}
note for Log "debug and trace only log to console when import.meta.env.DEV is true"
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.
Hey there - I've reviewed your changes - here's some feedback:
- In
checkImage, whenvalidateImageBlobreturns null you currently hardcode a 406 status; consider using the actualresponse.status/statusTextso callers see the real HTTP result rather than a fabricated status code. Log.debug/Log.traceare completely disabled outsideimport.meta.env.DEV; for areas like WebSocket reconnect logic and auth state sync where debug logs are often needed in production diagnostics, consider a configurable log level (e.g., via env or runtime setting) instead of hardwiring them to dev-only.
Prompt for AI Agents
Please address the comments from this code review:
## Overall Comments
- In `checkImage`, when `validateImageBlob` returns null you currently hardcode a 406 status; consider using the actual `response.status`/`statusText` so callers see the real HTTP result rather than a fabricated status code.
- `Log.debug`/`Log.trace` are completely disabled outside `import.meta.env.DEV`; for areas like WebSocket reconnect logic and auth state sync where debug logs are often needed in production diagnostics, consider a configurable log level (e.g., via env or runtime setting) instead of hardwiring them to dev-only.
## Individual Comments
### Comment 1
<location> `src/utils/image.ts:63-65` </location>
<code_context>
});
};
+const validateImageBlob = async (blob: Blob, url?: string): Promise<Blob | null> => {
+ // Check if the response is actually JSON (e.g. error message with 200 status)
+ if (blob.type === 'application/json') {
+ try {
+ const text = await blob.text();
+
+ Log.error('Image fetch returned JSON instead of image:', text);
</code_context>
<issue_to_address>
**🚨 suggestion (security):** Consider truncating or redacting JSON error payloads before logging to avoid huge logs or leaking sensitive data.
Here the entire JSON body is logged when `blob.type === 'application/json'`. That payload could be very large and may include sensitive user data. Prefer logging a reduced version (e.g., truncated text or selected fields like status/error code) instead of the full body.
```suggestion
const text = await blob.text();
// Avoid logging full JSON payloads which may be large or contain sensitive data
let safePayload: unknown = undefined;
try {
const parsed = JSON.parse(text);
if (parsed && typeof parsed === 'object') {
const obj = parsed as Record<string, unknown>;
// Prefer logging only high‑level error metadata if present
const { status, code, error, message } = obj;
safePayload = {
status,
code,
error,
message,
// Indicate that additional fields were omitted for safety
redacted: true,
};
} else {
// Non‑object JSON (e.g. string/number/array) – truncate the stringified form
const truncated = JSON.stringify(parsed).slice(0, 500);
safePayload = `${truncated}${truncated.length === 500 ? '…[truncated]' : ''}`;
}
} catch {
// Not valid JSON – fall back to a truncated text representation
const truncated = text.slice(0, 500);
safePayload = `${truncated}${truncated.length === 500 ? '…[truncated]' : ''}`;
}
Log.error('Image fetch returned JSON instead of image', safePayload);
```
</issue_to_address>Help me be more useful! Please click 👍 or 👎 on each comment and I'll use the feedback to improve your reviews.
josue693
pushed a commit
to josue693/AppFlowy-Web
that referenced
this pull request
Dec 21, 2025
* chore: log json * chore: use log
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
Description
Checklist
General
Testing
Feature-Specific
Summary by Sourcery
Improve logging consistency and image handling robustness across the app.
Bug Fixes:
Enhancements: