Skip to content

Commit 9eb2203

Browse files
committed
refactor: 스타 생성 로직 수정
1 parent 256ac6a commit 9eb2203

11 files changed

Lines changed: 94 additions & 60 deletions

File tree

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -2,12 +2,12 @@ import axios from "axios";
22

33
const baseURL = import.meta.env.VITE_BASE_URL;
44

5-
export const api = axios.create({
5+
export const apiV1 = axios.create({
66
baseURL,
77
withCredentials: true,
88
});
99

10-
api.interceptors.response.use(
10+
apiV1.interceptors.response.use(
1111
(response) => response,
1212
async (error) => {
1313
const originalRequest = error.config;
@@ -21,7 +21,7 @@ api.interceptors.response.use(
2121
originalRequest._retry = true;
2222

2323
try {
24-
const { data } = await api.get("/oauth/reissue", {
24+
const { data } = await apiV1.get("/oauth/reissue", {
2525
withCredentials: true,
2626
});
2727

@@ -33,7 +33,7 @@ api.interceptors.response.use(
3333
httpOnly: true,
3434
});
3535

36-
return api(originalRequest);
36+
return apiV1(originalRequest);
3737
} catch (refreshError) {
3838
return Promise.reject(refreshError);
3939
}

apps/extension/src/apis/api-v2.ts

Lines changed: 43 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,43 @@
1+
import axios from "axios";
2+
3+
const baseURL = import.meta.env.VITE_BASE_URL_V2;
4+
5+
export const apiV2 = axios.create({
6+
baseURL,
7+
withCredentials: true,
8+
});
9+
10+
apiV2.interceptors.response.use(
11+
(response) => response,
12+
async (error) => {
13+
const originalRequest = error.config;
14+
15+
if (
16+
error.response &&
17+
error.response.data &&
18+
error.response.data.code === "TOKEN4001" &&
19+
!originalRequest._retry
20+
) {
21+
originalRequest._retry = true;
22+
23+
try {
24+
const { data } = await apiV2.get("/oauth/reissue", {
25+
withCredentials: true,
26+
});
27+
28+
await chrome.cookies.set({
29+
url: baseURL,
30+
name: "accessToken",
31+
value: data.result.accessToken,
32+
path: "/",
33+
httpOnly: true,
34+
});
35+
36+
return apiV2(originalRequest);
37+
} catch (refreshError) {
38+
return Promise.reject(refreshError);
39+
}
40+
}
41+
return Promise.reject(error);
42+
}
43+
);

apps/extension/src/models/star.ts

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,9 +1,10 @@
11
export interface SummarizeStarDTO {
2-
starId: string;
32
title: string;
43
siteUrl: string;
54
thumbnailUrl: string;
5+
faviconUrl: string;
66
keywords: string[];
7+
s3key: string;
78
}
89

910
export interface CompleteSummarizeStarDTO {

apps/extension/src/pages/bookmark.tsx

Lines changed: 11 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -47,17 +47,17 @@ const Bookmark = () => {
4747
});
4848
};
4949

50-
// useEffect(() => {
51-
// updateCurrentTab(setCurrentTab);
52-
// chrome.tabs.onActivated.addListener(() => {
53-
// updateCurrentTab(setCurrentTab);
54-
// });
55-
// chrome.tabs.onUpdated.addListener((_, changeInfo) => {
56-
// if (changeInfo.status === "complete") {
57-
// updateCurrentTab(setCurrentTab);
58-
// }
59-
// });
60-
// }, []);
50+
useEffect(() => {
51+
updateCurrentTab(setCurrentTab);
52+
chrome.tabs.onActivated.addListener(() => {
53+
updateCurrentTab(setCurrentTab);
54+
});
55+
chrome.tabs.onUpdated.addListener((_, changeInfo) => {
56+
if (changeInfo.status === "complete") {
57+
updateCurrentTab(setCurrentTab);
58+
}
59+
});
60+
}, []);
6161

6262
return (
6363
<Loading title="페이지를 요약하고 있어요!">

apps/extension/src/pages/create-bookmark.tsx

Lines changed: 18 additions & 17 deletions
Original file line numberDiff line numberDiff line change
@@ -8,23 +8,30 @@ import { useCreateCategory } from "@/state/mutation/category";
88
import { useCompleteCreateStar } from "@/state/mutation/star";
99
import { useGetKeywords } from "@/state/query/keyword";
1010
import { CategoryListProps } from "@/types/category";
11-
import { BookmarkProps } from "@repo/types";
11+
import { CompleteSummarizeStarProps } from "@/types/star";
1212
import { Keyword, RectangleButton, Textarea } from "@repo/ui";
1313

1414
import { Navigate, useLocation } from "react-router-dom";
1515

1616
const DEFAULT_BOOKMARK = {
1717
categoryName: "",
1818
categories: [],
19-
summary: "",
20-
memo: "",
19+
summaryAI: "",
20+
userMemo: "",
2121
keyword: "",
2222
};
2323

24+
interface StateProps extends CompleteSummarizeStarProps {
25+
categoryName: string;
26+
categories: CategoryListProps[];
27+
keyword: string;
28+
keywords: string[];
29+
}
30+
2431
const CreateBookmark = () => {
2532
const { state } = useLocation();
2633

27-
const [bookmark, setBookmark] = useState<BookmarkProps>(Object.assign(DEFAULT_BOOKMARK, state));
34+
const [bookmark, setBookmark] = useState<StateProps>(Object.assign(DEFAULT_BOOKMARK, state));
2835

2936
const { mutateAsync } = useCompleteCreateStar();
3037
const { mutateAsync: mutateAsyncCategory, isPending } = useCreateCategory();
@@ -86,19 +93,13 @@ const CreateBookmark = () => {
8693
if (!categoryName) {
8794
return;
8895
}
96+
8997
const body = {
90-
thumbnailUrl: state.thumbnailUrl,
91-
summaryAI: bookmark.summary,
92-
userMemo: bookmark.memo,
93-
categoryName,
98+
...bookmark,
9499
keywordList: bookmark.keywords,
95-
faviconUrl: state.faviconUrl,
96100
};
97101

98-
await mutateAsync({
99-
starId: state.starId,
100-
body,
101-
});
102+
await mutateAsync(body);
102103
};
103104

104105
return (
@@ -126,16 +127,16 @@ const CreateBookmark = () => {
126127
/>
127128
<section>
128129
<Textarea
129-
id="summary"
130+
id="summaryAI"
130131
label="요약"
131-
value={bookmark.summary}
132+
value={bookmark.summaryAI}
132133
onChange={onChangeText}
133134
placeholder="북마크에 대한 요약을 작성할 수 있어요."
134135
/>
135136
<Textarea
136-
id="memo"
137+
id="userMemo"
137138
label="메모"
138-
value={bookmark.memo}
139+
value={bookmark.userMemo}
139140
onChange={onChangeText}
140141
placeholder="북마크에 대한 메모를 작성할 수 있어요."
141142
/>
Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,12 +1,12 @@
11
import { BaseResponseDTO } from "@/models";
22
import { CreateCategoryDTO, GetCategoryDTO } from "@/models/category";
33

4-
import { api } from "./api";
4+
import { apiV1 } from "../apis/api-v1";
55

66
export const getCategories = async (): Promise<BaseResponseDTO<GetCategoryDTO>> => {
7-
return (await api.get("/stars/categories")).data;
7+
return (await apiV1.get("/stars/categories")).data;
88
};
99

1010
export const createCategory = async (name: string): Promise<BaseResponseDTO<CreateCategoryDTO>> => {
11-
return (await api.post("/stars/categories", { name })).data;
11+
return (await apiV1.post("/stars/categories", { name })).data;
1212
};
Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,7 @@
11
import { BaseResponseDTO } from "@/models";
22

3-
import { api } from "./api";
3+
import { apiV1 } from "../apis/api-v1";
44

55
export const getKeywords = async (): Promise<BaseResponseDTO<string[]>> => {
6-
return (await api.get("/keywords")).data;
6+
return (await apiV1.get("/keywords")).data;
77
};

apps/extension/src/services/star.ts

Lines changed: 6 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -2,22 +2,18 @@ import { BaseResponseDTO } from "@/models";
22
import { CompleteSummarizeStarDTO, SummarizeStarDTO } from "@/models/star";
33
import { CompleteSummarizeStarProps, SummarizeStarProps } from "@/types/star";
44

5-
import { api } from "./api";
5+
import { apiV2 } from "../apis/api-v2";
66

77
export const createStar = async ({
88
title,
99
siteUrl,
1010
htmlFile,
1111
}: SummarizeStarProps): Promise<BaseResponseDTO<SummarizeStarDTO>> => {
12-
return (await api.post(`/stars?title=${title}&siteUrl=${siteUrl}`, htmlFile)).data;
12+
return (await apiV2.post(`/stars?title=${title}&siteUrl=${siteUrl}`, htmlFile)).data;
1313
};
1414

15-
export const completeCreateStar = async ({
16-
starId,
17-
body,
18-
}: {
19-
starId: string;
20-
body: CompleteSummarizeStarProps;
21-
}): Promise<BaseResponseDTO<CompleteSummarizeStarDTO>> => {
22-
return (await api.patch(`/stars/complete/${starId}`, body)).data;
15+
export const completeCreateStar = async (
16+
body: CompleteSummarizeStarProps
17+
): Promise<BaseResponseDTO<CompleteSummarizeStarDTO>> => {
18+
return (await apiV2.post("/stars/save", body)).data;
2319
};

apps/extension/src/types/star.ts

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -5,9 +5,13 @@ export interface SummarizeStarProps {
55
}
66

77
export interface CompleteSummarizeStarProps {
8+
title: string;
9+
siteUrl: string;
10+
faviconUrl: string;
811
thumbnailUrl: string;
912
summaryAI: string;
1013
userMemo: string;
1114
categoryName: string;
1215
keywordList: string[];
16+
s3key: string;
1317
}

packages/types/src/bookmark/index.ts

Lines changed: 0 additions & 11 deletions
This file was deleted.

0 commit comments

Comments
 (0)