Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Deploy to main #49

Merged
merged 7 commits into from
Jun 9, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
24 changes: 17 additions & 7 deletions app/[lang]/download/page.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -117,15 +117,25 @@ export default async function DownloadPage({params: {lang}, searchParams}: Downl
return options;
}

const platformSelect = (
<PlatformSelect
locale={{ detect: dict.downloadPage.detect}}
checkbox={dict.downloadPage.daylight}
alert={isDaylight ?
<FAlert lang={lang} description={dict.downloadPage.daylight.alert} severity={'warning'}/> : null}
platforms={getPlatformOptions()}
/>
)

const noRelease = (
<>
<p>{dict.downloadPage.noReleaseFound}</p>
</>
);

return (
<div className="flex flex-col w-full sm:flex-row items-center justify-between sm:items-start gap-4">
<PlatformSelect
locale={{ detect: dict.downloadPage.detect}}
checkbox={dict.downloadPage.daylight}
alert={isDaylight ?
<FAlert lang={lang} description={dict.downloadPage.daylight.alert} severity={'warning'}/> : null}
platforms={getPlatformOptions()}
/>
{!release ? noRelease : platformSelect}
</div>
)
}
4 changes: 4 additions & 0 deletions app/layout.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,7 @@ import React from "react";
import {Inter as FontSans} from "next/font/google"
import {cn} from "@/lib/utils";
import {headers} from "next/headers";
import {getDictionary} from "@/i18n/dictionaries";

export const runtime = 'edge';

Expand All @@ -12,8 +13,11 @@ type RootLayoutProps = {
}

export async function generateMetadata(): Promise<Metadata> {
const dict = await getDictionary("en");
return {
metadataBase: new URL(`https://${headers().get("host")}`),
title: dict.common.title,
description: dict.common.description,
};
}

Expand Down
121 changes: 73 additions & 48 deletions lib/gh-utils.ts
Original file line number Diff line number Diff line change
Expand Up @@ -28,26 +28,26 @@ export type Release = {
}

const getReadableName = (name: string): string => {
if(name.includes('aarch64')) {
if (name.includes('aarch64')) {
return 'Linux ARM';
}
if(name.includes('x86_64') && name.includes('linux')) {
if (name.includes('x86_64') && name.includes('linux')) {
return 'Linux x86/x64';
}
if (name.includes('stub') && name.includes('exe')) {
return 'Windows 64bit Online Installer';
}
if (name.includes('exe') && name.includes('win32')){
if (name.includes('exe') && name.includes('win32')) {
return 'Windows 32-bit';
}
if (name.includes('exe') && name.includes('win64')){
if (name.includes('exe') && name.includes('win64')) {
return 'Windows 64-bit';
}
if (name.includes('portable') && name.includes('zip') && name.includes('win')){
if (name.includes('portable') && name.includes('zip') && name.includes('win')) {
return 'Windows Portable';
}
if (name.includes('dmg')) {
return 'MacOS';
return 'macOS';
}

return name;
Expand Down Expand Up @@ -75,61 +75,86 @@ const getPlatformTypByAssetName = (name: string): Platform => {
return Platform.Linux;
}

export async function getRelease(): Promise<Release | null> {
const octokit = new Octokit();
const response = await octokit.rest.repos.getLatestRelease({
owner: 'Floorp-Projects',
repo: 'Floorp',
});
const accessToken = process.env.GITHUB_TOKEN;
const options = accessToken ? {auth: accessToken} : {};

if (!response.data.assets || response.data.published_at === null) {
console.error('Failed to fetch release data');
return null;
}
const date = new Date(response.data.published_at);
const hasQuota = async (octokit: Octokit): Promise<boolean> => {
const rateLimitResponse = await octokit.rest.rateLimit.get();

let hashes = '';
const assets: Record<string, AssetInfo[]> = {}
for (let i = 0; i < response.data.assets.length; i++) {
const asset = response.data.assets[i];
if (rateLimitResponse.data.resources.core.remaining === 0) {
console.log('Request quota exhausted before making request');
return false;
}

if (asset.name === "hashes.txt") {
hashes = asset.browser_download_url;
}
return true;
}

if (asset.name.includes('.mar') || asset.name.includes('.txt')) {
continue;
export async function getRelease(): Promise<Release | null> {
const octokit = new Octokit(options);
if (!await hasQuota(octokit)) {
return null;
}
try {
const response = await octokit.rest.repos.getLatestRelease({
owner: 'Floorp-Projects',
repo: 'Floorp',
});

if (!response?.data.assets || response?.data.published_at === null) {
console.error('Failed to fetch release data');
return null;
}
const platform = getPlatformTypByAssetName(asset.name);
if (!assets[platform]) {
assets[platform] = [];
const date = new Date(response.data.published_at);

let hashes = '';
const assets: Record<string, AssetInfo[]> = {}
for (let i = 0; i < response.data.assets.length; i++) {
const asset = response.data.assets[i];

if (asset.name === "hashes.txt") {
hashes = asset.browser_download_url;
}

if (asset.name.includes('.mar') || asset.name.includes('.txt')) {
continue;
}
const platform = getPlatformTypByAssetName(asset.name);
if (!assets[platform]) {
assets[platform] = [];
}
assets[platform].push(getAssetInfo(asset));
}
assets[platform].push(getAssetInfo(asset));
}

const portableResponse = await octokit.rest.repos.getLatestRelease({
owner: 'Floorp-Projects',
repo: 'Floorp-Portable',
});
let targetAsset = portableResponse.data.assets.find((asset) => asset.name.includes('windows'));
if (targetAsset) {
if (!assets[Platform.Windows]) {
assets[Platform.Windows] = [];
const portableResponse = await octokit.rest.repos.getLatestRelease({
owner: 'Floorp-Projects',
repo: 'Floorp-Portable',
});
let targetAsset = portableResponse.data.assets.find((asset) => asset.name.includes('windows'));
if (targetAsset) {
if (!assets[Platform.Windows]) {
assets[Platform.Windows] = [];
}
assets[Platform.Windows].push(getAssetInfo(targetAsset));
}
assets[Platform.Windows].push(getAssetInfo(targetAsset));
}

return {
version: response.data.tag_name,
name: response.data.name || response.data.tag_name,
publishedAt: date,
downloads: assets,
hashes
return {
version: response.data.tag_name,
name: response.data.name || response.data.tag_name,
publishedAt: date,
downloads: assets,
hashes
}
} catch (e) {
console.error('Failed to fetch release data', e);
return null;
}
}

export async function getTags(): Promise<string[]> {
const octokit = new Octokit();
const octokit = new Octokit(options);
if (!await hasQuota(octokit)) {
return [];
}
const response = await octokit.rest.repos.listTags({
owner: 'Floorp-Projects',
repo: 'Floorp',
Expand Down
8 changes: 4 additions & 4 deletions lib/utils.ts
Original file line number Diff line number Diff line change
Expand Up @@ -24,17 +24,17 @@ export const getComponent = (node: React.ReactNode, returnIfProduction: boolean
export const platformOptions = {
"windows": "Windows",
"linux": "Linux",
"macos": "MacOS",
"macos": "macOS",
"android": "Android",
"ios": "IOS",
"ios": "iOS",
} as Record<string, string>;

export enum Platform {
Linux = 'Linux',
Windows = 'Windows',
MacOS = 'MacOS',
MacOS = 'macOS',
Android = 'Android',
IOS = 'IOS',
IOS = 'iOS',
}

export const convertOptionToPlatform = (option: string): Platform => {
Expand Down
Loading
Loading