Skip to content

Commit aed74e1

Browse files
author
maro114510
committed
fix: Address Copilot code review suggestions
- Fix djb2 hash: change no-op `hash & hash` to `hash | 0` for proper 32-bit conversion - Implement reload setting: respect `settings.reload` instead of always reloading - Add JSON parse error handling: wrap response.json() in try/catch with FeedlyError - Remove redundant token check: getUserId() already triggers token validation via feedlyApiRequest()
1 parent bb87da1 commit aed74e1

1 file changed

Lines changed: 12 additions & 9 deletions

File tree

content.js

Lines changed: 12 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -122,7 +122,7 @@ function simpleHash(str) {
122122
for (let i = 0; i < str.length; i++) {
123123
const char = str.charCodeAt(i);
124124
hash = ((hash << 5) - hash) + char;
125-
hash = hash & hash;
125+
hash = hash | 0; // Convert to 32-bit signed integer
126126
}
127127
return hash;
128128
}
@@ -254,7 +254,14 @@ async function feedlyApiRequest(endpoint, options = {}) {
254254
return { success: true };
255255
}
256256

257-
return response.json();
257+
try {
258+
return await response.json();
259+
} catch (parseError) {
260+
throw new FeedlyError(
261+
ErrorCode.SERVER_ERROR,
262+
`Invalid JSON response: ${parseError.message}`
263+
);
264+
}
258265
}
259266

260267
/**
@@ -362,11 +369,7 @@ async function unsaveEntriesViaAPI(userId, entryIds) {
362369
* @returns {Promise<Object>} Result object with ok, urls, and method
363370
*/
364371
async function handleOpenViaAPI(settings) {
365-
const token = await getAccessToken();
366-
if (!token) {
367-
throw new FeedlyError(ErrorCode.NO_TOKEN, 'No access token available');
368-
}
369-
372+
// Token check is handled by feedlyApiRequest() called from getUserId()
370373
const userId = await getUserId();
371374

372375
// Fetch entries: use pagination for "all" mode, single request for "count" mode
@@ -790,8 +793,8 @@ async function handleOpen(settings) {
790793
}
791794
}
792795

793-
// Always reload after successful operation to reflect UI changes
794-
if (result.ok) {
796+
// Reload after successful operation if enabled (default: true)
797+
if (result.ok && settings.reload) {
795798
setTimeout(() => {
796799
location.reload();
797800
}, 1000);

0 commit comments

Comments
 (0)