diff --git a/src/helpers/constants.js b/src/helpers/constants.js index 4f89720..17d6671 100644 --- a/src/helpers/constants.js +++ b/src/helpers/constants.js @@ -41,5 +41,9 @@ export default { ].join(",") } }), - VERSIONS_PATH: "versions" + VERSIONS_PATH: "versions", + LOCAL_STORAGE: { + GET_RELEASES_ETAG: "getReleasesETAG", + RELEASES_DATA: "releasesData", + } }; diff --git a/src/helpers/releasesInfo.js b/src/helpers/releasesInfo.js index e4500da..52b0057 100644 --- a/src/helpers/releasesInfo.js +++ b/src/helpers/releasesInfo.js @@ -9,17 +9,29 @@ export const retrieveReleases = gitHubURL => constants.GITHUB_API_RELEASE_URL.replace( "{repo_name}", repositoryName - ) + ), + { + headers: { + "If-None-Match": localStorage.getItem(constants.LOCAL_STORAGE.GET_RELEASES_ETAG) || "" + } + } ) .then(response => { if (response.status === 200) { + localStorage.setItem(constants.LOCAL_STORAGE.GET_RELEASES_ETAG, response.headers.etag.toString()); + localStorage.setItem(constants.LOCAL_STORAGE.RELEASES_DATA, JSON.stringify(response.data)); resolve(response.data); } else { resolve([]); } }) .catch(err => { - reject(err); + if (err.response && err.response.status === 304) { + resolve(JSON.parse(localStorage.getItem(constants.LOCAL_STORAGE.RELEASES_DATA))); + } + else { + reject(err); + } }); }); @@ -31,4 +43,4 @@ export const getLatestRelease = releases => { }; export const isLatestRelease = (versions, targetRelease) => - getLatestRelease(versions) === targetRelease.tag_name; + getLatestRelease(versions) === targetRelease.tag_name;