Skip to content
This repository has been archived by the owner on Feb 26, 2024. It is now read-only.

Commit

Permalink
New: Use ETAG in header for reading releases from the cache (#12)
Browse files Browse the repository at this point in the history
* New: Use ETAG in header for reading releases from the cache

* Fix: per comments
  • Loading branch information
swatikode authored and abhijit945 committed Sep 11, 2019
1 parent 335c6b1 commit 2dae5d4
Show file tree
Hide file tree
Showing 2 changed files with 20 additions and 4 deletions.
6 changes: 5 additions & 1 deletion src/helpers/constants.js
Original file line number Diff line number Diff line change
Expand Up @@ -41,5 +41,9 @@ export default {
].join(",")
}
}),
VERSIONS_PATH: "versions"
VERSIONS_PATH: "versions",
LOCAL_STORAGE: {
GET_RELEASES_ETAG: "getReleasesETAG",
RELEASES_DATA: "releasesData",
}
};
18 changes: 15 additions & 3 deletions src/helpers/releasesInfo.js
Original file line number Diff line number Diff line change
Expand Up @@ -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);
}
});
});

Expand All @@ -31,4 +43,4 @@ export const getLatestRelease = releases => {
};

export const isLatestRelease = (versions, targetRelease) =>
getLatestRelease(versions) === targetRelease.tag_name;
getLatestRelease(versions) === targetRelease.tag_name;

0 comments on commit 2dae5d4

Please sign in to comment.