Skip to content

Commit

Permalink
api: transition to new endpoint, fallback to existing one to ease mig…
Browse files Browse the repository at this point in the history
…ration
  • Loading branch information
xTVaser committed Jan 24, 2025
1 parent 2a13649 commit 79055e6
Show file tree
Hide file tree
Showing 2 changed files with 31 additions and 6 deletions.
27 changes: 23 additions & 4 deletions src/pages/downloads/index.js
Original file line number Diff line number Diff line change
Expand Up @@ -60,7 +60,8 @@ const renderReleaseCell = (release, columnKey, isNightly, isSelected) => {
}
};

let baseApiUrl = "https://api.pcsx2.net/v1";
let baseApiUrl = "https://apinew.pcsx2.net/v1";
let backupBaseApiUrl = "https://api.pcsx2.net/v1";

export default function Downloads() {
const isBrowser = useIsBrowser();
Expand All @@ -84,7 +85,11 @@ export default function Downloads() {

const fetchLatestReleases = async () => {
try {
const resp = await fetch(`${baseApiUrl}/latestReleasesAndPullRequests`);
let resp = await fetch(`${baseApiUrl}/latestReleasesAndPullRequests`);
// TODO: potentially retry with old URL, just temp code to ease migration
if (resp.status !== 200) {
resp = await fetch(`${backupBaseApiUrl}/latestReleasesAndPullRequests`);
}
if (resp.status === 429) {
setApiErrorMsg("You are Being Rate-Limited. Try Again Later!");
} else if (resp.status !== 200) {
Expand Down Expand Up @@ -249,9 +254,16 @@ export default function Downloads() {
tableColumns={releaseTableColumns}
renderRowFunc={renderReleaseCell}
fetchMoreFunc={async (offset) => {
return await fetch(
let resp = await fetch(
`${baseApiUrl}/stableReleases?offset=${offset}`,
);
// TODO: potentially retry with old URL, just temp code to ease migration
if (resp.status !== 200) {
resp = await fetch(
`${backupBaseApiUrl}/stableReleases?offset=${offset}`,
);
}
return resp;
}}
tableType={"stable"}
/>
Expand Down Expand Up @@ -348,9 +360,16 @@ export default function Downloads() {
tableColumns={releaseTableColumns}
renderRowFunc={renderReleaseCell}
fetchMoreFunc={async (offset) => {
return await fetch(
let resp = await fetch(
`${baseApiUrl}/nightlyReleases?offset=${offset}`,
);
// TODO: potentially retry with old URL, just temp code to ease migration
if (resp.status !== 200) {
resp = await fetch(
`${backupBaseApiUrl}/nightlyReleases?offset=${offset}`,
);
}
return resp;
}}
tableType={"nightly"}
/>
Expand Down
10 changes: 8 additions & 2 deletions src/pages/index.js
Original file line number Diff line number Diff line change
Expand Up @@ -45,7 +45,8 @@ import {

import useIsBrowser from "@docusaurus/useIsBrowser";

let baseApiUrl = "https://api.pcsx2.net/v1";
let baseApiUrl = "https://apinew.pcsx2.net/v1";
let backupBaseApiUrl = "https://api.pcsx2.net/v1";

export default function Home() {
const { theme, setTheme } = useTheme();
Expand All @@ -61,7 +62,12 @@ export default function Home() {

const fetchLatestReleases = async () => {
try {
const resp = await fetch(`${baseApiUrl}/latestReleasesAndPullRequests`);
let resp = await fetch(`${baseApiUrl}/latestReleasesAndPullRequests`);
// TODO: potentially retry with old URL, just temp code to ease migration
if (resp.status !== 200) {
resp = await fetch(`${backupBaseApiUrl}/latestReleasesAndPullRequests`);
}

if (resp.status === 429) {
setApiErrorMsg("You are Being Rate-Limited. Try Again Later!");
} else if (resp.status !== 200) {
Expand Down

0 comments on commit 79055e6

Please sign in to comment.