-
Notifications
You must be signed in to change notification settings - Fork 3
[Fix] sidebar 구현 #83
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] sidebar 구현 #83
Changes from all commits
f9ba768
7ceb07f
f864f93
20c62e3
9522cc6
4223a13
3cd4c53
ee42d54
9d452d8
03e50ff
4400e21
41cff32
6365d65
a85082f
30d76c6
f676473
7216bbd
02f1929
17558be
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
| Original file line number | Diff line number | Diff line change | ||||
|---|---|---|---|---|---|---|
|
|
@@ -8,7 +8,7 @@ | |||||
| DEFAULT_FONT_WEIGHT, | ||||||
| } from "./constants"; | ||||||
| import { initCommandListeners } from "./listeners/commandListeners"; | ||||||
| import { handleModalToggle } from "./listeners/modalCommandHandler"; | ||||||
|
|
||||||
| /** | ||||||
| * 백그라운드 스크립트 초기화 | ||||||
|
|
@@ -115,39 +115,57 @@ | |||||
|
|
||||||
| // FOOD API | ||||||
| if (message.type === "FETCH_FOOD_DATA") { | ||||||
| const payload = message.payload; | ||||||
| chrome.tabs.query({ active: true, currentWindow: true }, (tabs) => { | ||||||
| const activeTab = tabs[0]; | ||||||
| if (!activeTab?.url) { | ||||||
| sendResponse({ | ||||||
| status: 400, | ||||||
| error: "상품 페이지를 찾을 수 없습니다.", | ||||||
| }); | ||||||
| return; | ||||||
| } | ||||||
|
|
||||||
| fetch("https://voim.store/api/v1/products/foods", { | ||||||
| method: "POST", | ||||||
| headers: { | ||||||
| "Content-Type": "application/json", | ||||||
| }, | ||||||
| body: JSON.stringify(payload), | ||||||
| }) | ||||||
| .then((res) => res.json()) | ||||||
| .then((data) => { | ||||||
| logger.debug("FOOD API 응답 성공:", data); | ||||||
| if (sender.tab?.id) { | ||||||
| chrome.tabs.sendMessage(sender.tab.id, { | ||||||
| type: "FOOD_DATA_RESPONSE", | ||||||
| data, | ||||||
| }); | ||||||
| } | ||||||
| sendResponse({ status: 200, data }); | ||||||
| }) | ||||||
| .catch((err) => { | ||||||
| console.error( | ||||||
| "[voim][background] FOOD API 요청 실패:", | ||||||
| err.message, | ||||||
| ); | ||||||
| if (sender.tab?.id) { | ||||||
| chrome.tabs.sendMessage(sender.tab.id, { | ||||||
| type: "FOOD_DATA_ERROR", | ||||||
| error: err.message, | ||||||
| const productId = activeTab.url.match(/vp\/products\/(\d+)/)?.[1]; | ||||||
| if (!productId) { | ||||||
| sendResponse({ | ||||||
| status: 400, | ||||||
| error: "상품 ID를 찾을 수 없습니다.", | ||||||
| }); | ||||||
| return; | ||||||
| } | ||||||
|
|
||||||
| const payload = { | ||||||
| ...message.payload, | ||||||
| productId, | ||||||
| }; | ||||||
|
|
||||||
| fetch("https://voim.store/api/v1/products/foods", { | ||||||
| method: "POST", | ||||||
| headers: { "Content-Type": "application/json" }, | ||||||
| body: JSON.stringify(payload), | ||||||
| }).then(async (res) => { | ||||||
| const text = await res.text(); | ||||||
| console.log("[voim] 응답 상태 코드:", res.status); | ||||||
| console.log("[voim] 응답 원문:", text); | ||||||
| try { | ||||||
| const json = JSON.parse(text); | ||||||
| if (res.ok) { | ||||||
| sendResponse({ status: 200, data: json }); | ||||||
| } else { | ||||||
| sendResponse({ | ||||||
| status: res.status, | ||||||
| error: json?.message ?? "에러 발생", | ||||||
| }); | ||||||
| } | ||||||
| } catch (err) { | ||||||
| console.error("[voim] JSON 파싱 실패", text); | ||||||
|
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. catch 블록에서 err 변수를 사용하세요. 에러 정보를 로그에 포함시켜 디버깅을 용이하게 하세요. 다음과 같이 수정하세요: -console.error("[voim] JSON 파싱 실패", text);
+console.error("[voim] JSON 파싱 실패", text, err);📝 Committable suggestion
Suggested change
🧰 Tools🪛 GitHub Check: lint-and-test[warning] 161-161: 🤖 Prompt for AI Agents |
||||||
| sendResponse({ | ||||||
| status: res.status, | ||||||
| error: "JSON 파싱 실패", | ||||||
| }); | ||||||
| } | ||||||
| sendResponse({ status: 500, error: err.message }); | ||||||
| }); | ||||||
| }); | ||||||
|
|
||||||
| return true; | ||||||
| } | ||||||
|
|
@@ -255,57 +273,63 @@ | |||||
| // COSMETIC API | ||||||
| if (message.type === "FETCH_COSMETIC_DATA") { | ||||||
| const { productId, html } = message.payload; | ||||||
|
|
||||||
| fetch("https://voim.store/api/v1/cosmetic", { | ||||||
| method: "POST", | ||||||
| headers: { "Content-Type": "application/json" }, | ||||||
| body: JSON.stringify({ productId, html }), | ||||||
| }) | ||||||
| .then((res) => { | ||||||
| return res.json(); | ||||||
| .then(async (res) => { | ||||||
| const json = await res.json(); | ||||||
| console.log("[voim][background] 응답 원문:", json); | ||||||
| return json; | ||||||
|
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. console.log 대신 logger를 사용하세요. 일관성을 위해 logger 유틸리티를 사용하세요. 다음과 같이 수정하세요: -console.log("[voim][background] 응답 원문:", json);
+logger.debug("[voim][background] 응답 원문:", json);
🧰 Tools🪛 GitHub Check: lint-and-test[warning] 285-285: 🤖 Prompt for AI Agents |
||||||
| }) | ||||||
| .then((data) => { | ||||||
| const raw = data?.data; | ||||||
|
|
||||||
| if (!raw || typeof raw !== "object") { | ||||||
| console.warn( | ||||||
| "[voim][background] data.data 형식 이상함:", | ||||||
| raw, | ||||||
| ); | ||||||
| sendResponse({ | ||||||
| type: "COSMETIC_DATA_ERROR", | ||||||
| error: "API 응답 형식 오류", | ||||||
| }); | ||||||
| return; | ||||||
| } | ||||||
|
|
||||||
| const parsedList = Object.entries(raw || {}) | ||||||
| .filter(([_, v]) => v === true) | ||||||
| .map(([k]) => k); | ||||||
| sendResponse({ | ||||||
| type: "COSMETIC_DATA_RESPONSE", | ||||||
| data: raw, | ||||||
| }); | ||||||
|
|
||||||
| if (sender.tab?.id) { | ||||||
| chrome.tabs.sendMessage(sender.tab.id, { | ||||||
| type: "COSMETIC_DATA_RESPONSE", | ||||||
| data: raw, | ||||||
| }); | ||||||
| } | ||||||
|
|
||||||
| sendResponse({ | ||||||
| type: "COSMETIC_DATA_RESPONSE", | ||||||
| data: raw, | ||||||
| }); | ||||||
| }) | ||||||
| .catch((err) => { | ||||||
| console.error("[voim][background] COSMETIC 요청 실패:", err); | ||||||
| console.error("[voim][background] COSMETIC 요청 실패:", err); | ||||||
| sendResponse({ | ||||||
| type: "COSMETIC_DATA_ERROR", | ||||||
| error: err.message, | ||||||
| }); | ||||||
|
|
||||||
| if (sender.tab?.id) { | ||||||
| chrome.tabs.sendMessage(sender.tab.id, { | ||||||
| type: "COSMETIC_DATA_ERROR", | ||||||
| error: err.message, | ||||||
| }); | ||||||
| } | ||||||
| sendResponse({ | ||||||
| type: "COSMETIC_DATA_ERROR", | ||||||
| error: err.message, | ||||||
| }); | ||||||
| }); | ||||||
|
|
||||||
| return true; | ||||||
| } | ||||||
|
|
||||||
| // REVIEW SUMMARY API | ||||||
| // // REVIEW SUMMARY API | ||||||
| if (message.type === "FETCH_REVIEW_SUMMARY") { | ||||||
| const { productId, reviewRating, reviews } = message.payload; | ||||||
|
|
||||||
|
|
@@ -418,10 +442,41 @@ | |||||
| }); | ||||||
|
|
||||||
| chrome.action.onClicked.addListener(async (tab) => { | ||||||
| try { | ||||||
| logger.debug("툴바 아이콘 클릭됨"); | ||||||
| await handleModalToggle(); | ||||||
| } catch (error) { | ||||||
| logger.error("툴바 아이콘 클릭 처리 중 오류 발생:", error); | ||||||
| } | ||||||
| }); | ||||||
| chrome.runtime.onMessage.addListener((message, sender, sendResponse) => { | ||||||
| if (message.type === "GET_PRODUCT_TITLE") { | ||||||
| chrome.tabs.query({ active: true, currentWindow: true }, (tabs) => { | ||||||
| const tabId = tabs[0]?.id; | ||||||
| if (!tabId) { | ||||||
| sendResponse({ title: "" }); | ||||||
| return; | ||||||
| } | ||||||
|
|
||||||
| chrome.tabs.sendMessage( | ||||||
| tabId, | ||||||
| { type: "GET_PRODUCT_TITLE" }, | ||||||
| (response) => { | ||||||
| if (chrome.runtime.lastError) { | ||||||
| console.error( | ||||||
| "[voim][background] title 요청 실패:", | ||||||
| chrome.runtime.lastError.message, | ||||||
| ); | ||||||
| sendResponse({ title: "" }); | ||||||
| } else { | ||||||
| sendResponse(response); | ||||||
| } | ||||||
| }, | ||||||
| ); | ||||||
| }); | ||||||
|
|
||||||
| return true; | ||||||
| } | ||||||
|
|
||||||
| return false; | ||||||
| }); | ||||||
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.
console.log 대신 logger를 사용하세요.
프로덕션 환경을 위해 기존 logger 유틸리티를 사용하는 것이 좋습니다.
다음과 같이 수정하세요:
📝 Committable suggestion
🧰 Tools
🪛 GitHub Check: lint-and-test
[warning] 150-150:
Unexpected console statement. Only these console methods are allowed: error, warn
[warning] 149-149:
Unexpected console statement. Only these console methods are allowed: error, warn
🤖 Prompt for AI Agents