-
Notifications
You must be signed in to change notification settings - Fork 13
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge pull request #33 from portapack-mayhem/button_disable
Fixed local cors issue
- Loading branch information
Showing
17 changed files
with
221 additions
and
49 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,63 @@ | ||
const corsHeaders = { | ||
"Access-Control-Allow-Origin": "*", | ||
"Access-Control-Allow-Methods": "GET,HEAD,POST,PUT,OPTIONS,DELETE", | ||
"Access-Control-Allow-Headers": "*", | ||
"Access-Control-Expose-Headers": "*", | ||
"Access-Control-Max-Age": "86400", | ||
}; | ||
|
||
export const onRequestGet: PagesFunction = async (context) => { | ||
const convertNightlyString = (nightlyTag: string) => { | ||
const parts = nightlyTag.split("-"); | ||
|
||
// We expect the input to be 'nightly-tag-YYYY-MM-DD' format | ||
const year = parts[2].slice(2); // remove '20' prefix from the year | ||
const month = parts[3]; | ||
const day = parts[4]; | ||
|
||
return `n_${year}${month}${day}`; | ||
}; | ||
|
||
let apiUrl = | ||
"https://api.github.com/repos/portapack-mayhem/mayhem-firmware/releases"; | ||
|
||
let apiResponse = await fetch(apiUrl, { | ||
method: "GET", | ||
headers: { "User-Agent": "portapack-mayhem" }, | ||
}); | ||
|
||
if (!apiResponse.ok) { | ||
throw new Error(`HTTP error! status: ${apiResponse.status}`); | ||
} | ||
|
||
let apiData: any = await apiResponse.json(); | ||
|
||
const latestNightlyObject = apiData.find( | ||
(item: any) => item.prerelease === true | ||
); | ||
const nightlyVersion = convertNightlyString(latestNightlyObject.tag_name); | ||
|
||
const latestStableObject = apiData.find( | ||
(item: any) => item.prerelease === false | ||
); | ||
|
||
const data = { | ||
stable: { | ||
version: latestStableObject.tag_name, | ||
published_at: latestStableObject.published_at, | ||
}, | ||
nightly: { | ||
version: nightlyVersion, | ||
published_at: latestNightlyObject.published_at, | ||
}, | ||
}; | ||
|
||
const json = JSON.stringify(data); | ||
|
||
return new Response(json, { | ||
headers: { | ||
...corsHeaders, | ||
"content-type": "application/json;charset=UTF-8", | ||
}, | ||
}); | ||
}; |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,9 @@ | ||
export interface LatestVersions { | ||
stable: VersionDetails; | ||
nightly: VersionDetails; | ||
} | ||
|
||
export interface VersionDetails { | ||
version: string; | ||
published_at: string; | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
2 changes: 1 addition & 1 deletion
2
...omponents/DeviceButtons/DeviceButtons.tsx → ...omponents/DeviceButtons/DeviceButtons.tsx
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,47 @@ | ||
type Version = "stable" | "nightly" | "custom" | "unknown"; | ||
|
||
export const nightlyVersionFormat = (input: string): number => { | ||
const removedPrefix = input.replace("n_", ""); | ||
const number = parseInt(removedPrefix); | ||
return number; | ||
}; | ||
|
||
const nightlyToDate = (input: string): string => { | ||
const prefixRemoved = input.replace("n_", ""); | ||
|
||
const year = "20" + prefixRemoved.slice(0, 2); | ||
const month = prefixRemoved.slice(2, 4); | ||
const day = prefixRemoved.slice(4, 8); | ||
|
||
return `${year}-${month}-${day}`; | ||
}; | ||
|
||
export const getVersionType = (versionString: string): Version => { | ||
const stableRegex = /^v?\d+\.\d+\.\d+$/; | ||
const nightlyRegex = /^n_\d+$/; | ||
const customRegex = /^[a-f0-9]+$/; | ||
|
||
if (stableRegex.test(versionString)) { | ||
return "stable"; | ||
} else if (nightlyRegex.test(versionString)) { | ||
return "nightly"; | ||
} else if (customRegex.test(versionString)) { | ||
return "custom"; | ||
} else { | ||
return "unknown"; | ||
} | ||
}; | ||
|
||
export const getVersionLink = (versionString: string = ""): string => { | ||
const type = getVersionType(versionString); | ||
if (type === "stable") { | ||
return `https://github.com/portapack-mayhem/mayhem-firmware/releases/tag/${versionString}`; | ||
} else if (type === "nightly") { | ||
return `https://github.com/portapack-mayhem/mayhem-firmware/releases/tag/nightly-tag-${nightlyToDate( | ||
versionString | ||
)}`; | ||
} else if (type === "custom") { | ||
return `https://github.com/portapack-mayhem/mayhem-firmware/commit/${versionString}`; | ||
} | ||
return ""; | ||
}; |