Skip to content

Commit

Permalink
feat: refresh api 추가
Browse files Browse the repository at this point in the history
  • Loading branch information
coddingyun committed Oct 31, 2023
1 parent f33b454 commit bd4fb88
Show file tree
Hide file tree
Showing 3 changed files with 29 additions and 11 deletions.
11 changes: 8 additions & 3 deletions src/common/annotation-manager.js
Original file line number Diff line number Diff line change
Expand Up @@ -132,10 +132,15 @@ class AnnotationManager {
const paperId = sessionStorage.getItem('paperId')
const workspaceId = sessionStorage.getItem('workspaceId')

//refresh api 넣기
postApi(api, `/api/paper/item?paperId=${paperId}&workspaceId=${workspaceId}`, payload)
.catch(error => {
console.log(error)
.then(async response => {
if (response.status === 200) {
return response
} else if (response.status === 401) {
await refreshApi(api)
} else {
throw new Error("논문 노팅을 추가하는데 실패하였습니다.")
}
})

return annotation;
Expand Down
6 changes: 3 additions & 3 deletions src/custom/utils/apiFetch.js
Original file line number Diff line number Diff line change
Expand Up @@ -35,7 +35,7 @@ export const deleteApi = (apiEndPoint, api) => {
})
}

export const refreshApi = (apiEndPoint, notify, navigate) => {
export const refreshApi = async (apiEndPoint) => {
return fetch(`${apiEndPoint}/api/update/token`
, {
headers: {
Expand All @@ -44,8 +44,8 @@ export const refreshApi = (apiEndPoint, notify, navigate) => {
}
).then(response => {
if (response.status === 401) {
navigate('/login')
notify('Login time has expired')
window.location.href = '/login'
//notify('Login time has expired')
throw new Error('로그아웃')
}
else if (response.status === 200) {
Expand Down
23 changes: 18 additions & 5 deletions src/index.dev.js
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@ import pdf from '../demo/pdf';
import epub from '../demo/epub';
import snapshot from '../demo/snapshot';
import { setCookie, getCookie } from './custom/cookie'
import { putApi, deleteApi } from './custom/utils/apiFetch';
import { putApi, deleteApi, refreshApi } from './custom/utils/apiFetch';
import { getSortIndex } from './pdf/selection';

window.dev = true;
Expand Down Expand Up @@ -178,10 +178,15 @@ async function createReader(paperId, paperItems, userPdf) {
const paperId = sessionStorage.getItem('paperId')
const workspaceId = sessionStorage.getItem('workspaceId')

//refresh api 넣기
putApi(api, `/api/paper/item?paperId=${paperId}&workspaceId=${workspaceId}`, payload)
.catch(error => {
console.log(error)
.then(async response => {
if (response.status === 200) {
return response
} else if (response.status === 401) {
await refreshApi(api)
} else {
throw new Error("논문 노팅을 수정하는데 실패하였습니다.")
}
})
console.log('Save annotations', annotations);
},
Expand All @@ -190,8 +195,16 @@ async function createReader(paperId, paperItems, userPdf) {
const paperId = sessionStorage.getItem('paperId')
const workspaceId = sessionStorage.getItem('workspaceId')

//refresh api 넣기
deleteApi(api, `/api/paper/item?paperId=${paperId}&workspaceId=${workspaceId}&itemId=${ids}`)
.then(async response => {
if (response.status === 200) {
return response
} else if (response.status === 401) {
await refreshApi(api)
} else {
throw new Error("논문 노팅을 삭제하는데 실패하였습니다.")
}
})
console.log('Delete annotations', JSON.stringify(ids));
},
// 추가: view가 업데이트 될 때마다 pageIndex 보내주기
Expand Down

0 comments on commit bd4fb88

Please sign in to comment.