Skip to content

Commit 8167d42

Browse files
chore: fixed github configs
1 parent a5a74b0 commit 8167d42

File tree

7 files changed

+55
-32
lines changed

7 files changed

+55
-32
lines changed

.env.example

Lines changed: 0 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -1,17 +1,11 @@
11
# Public common values
22
NEXT_PUBLIC_APP_URL=
3-
NEXT_PUBLIC_CONFIG_URL=
43
NEXT_PUBLIC_GOOGLE_DOMAIN=
54
NEXT_PUBLIC_OWNER_ID=
65
NEXT_PUBLIC_PUSHER_CLUSTER=
76
NEXT_PUBLIC_PUSHER_KEY=
87
NEXT_PUBLIC_YD_CAPTCHA=
98

10-
# Docs
11-
COOKIES_POLICY=
12-
PRIVACY_POLICY=
13-
TERMS=
14-
159
# Auth secrets
1610
NEXTAUTH_SECRET=
1711
OTP_SECRET=

actions/configs/get-app-config.ts

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -2,7 +2,7 @@
22

33
import { promises as fs } from 'fs';
44

5-
import { fetcher } from '@/lib/fetcher';
5+
import { getGithubContents } from '../github/get-contents';
66

77
export type GetAppConfig = {
88
auth: Record<string, boolean>;
@@ -15,7 +15,7 @@ export const getAppConfig = async (): Promise<GetAppConfig> => {
1515
const config =
1616
process.env.NODE_ENV === 'development'
1717
? await fs.readFile(`${process.cwd()}/configs/app.json`, 'utf8')
18-
: await fetcher.get(process.env.NEXT_PUBLIC_CONFIG_URL as string, { responseType: 'text' });
18+
: await getGithubContents({ path: 'configs/app.json' });
1919

2020
return JSON.parse(config);
2121
} catch (error) {

actions/docs/get-app-docs.ts

Lines changed: 3 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -2,20 +2,14 @@
22

33
import { promises as fs } from 'fs';
44

5-
import { fetcher } from '@/lib/fetcher';
5+
import { getGithubContents } from '../github/get-contents';
66

7-
const docs = {
8-
'cookies-policy': process.env.COOKIES_POLICY,
9-
'privacy-policy': process.env.PRIVACY_POLICY,
10-
terms: process.env.TERMS,
11-
};
12-
13-
export const getAppDocs = async (document: keyof typeof docs) => {
7+
export const getAppDocs = async (document: string) => {
148
try {
159
const content =
1610
process.env.NODE_ENV === 'development'
1711
? await fs.readFile(`${process.cwd()}/docs/${document}.md`, 'utf8')
18-
: await fetcher.get(docs[document] as string, { responseType: 'text' });
12+
: await getGithubContents({ path: `docs/${document}.md` });
1913

2014
return content;
2115
} catch (error) {

actions/github/get-contents.ts

Lines changed: 47 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,47 @@
1+
'use server';
2+
3+
import { ONE_DAY_SEC } from '@/constants/common';
4+
import { PAGE_SIZES } from '@/constants/paginations';
5+
import { fetchCachedData } from '@/lib/cache';
6+
import { fetcher } from '@/lib/fetcher';
7+
8+
type GetGithubContents = {
9+
pageIndex?: string | number;
10+
pageSize?: string | number;
11+
path: string;
12+
};
13+
14+
export const getGithubContents = async ({
15+
pageIndex = 0,
16+
pageSize = PAGE_SIZES[0],
17+
path,
18+
}: GetGithubContents): Promise<string> => {
19+
try {
20+
const githubContents = await fetchCachedData(
21+
'github-contents',
22+
async () => {
23+
const res = await fetcher.get(
24+
`https://api.github.com/repos/${process.env.GITHUB_OWNER}/${process.env.GITHUB_REPO}/contents/${path}?per_page=${pageSize}&page=${pageIndex}`,
25+
{
26+
responseType: 'text',
27+
headers: {
28+
Accept: 'application/vnd.github.raw',
29+
Authorization: `Bearer ${process.env.GITHUB_TOKEN}`,
30+
},
31+
},
32+
);
33+
34+
console.log(res);
35+
36+
return res;
37+
},
38+
ONE_DAY_SEC,
39+
);
40+
41+
return githubContents;
42+
} catch (error) {
43+
console.error('[GET_GITHUB_CONTENTS]', error);
44+
45+
return '';
46+
}
47+
};

actions/github/get-releases.ts

Lines changed: 0 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -19,7 +19,6 @@ export const getGithubReleases = async ({
1919
html_url: string | null;
2020
name: string | null;
2121
publishedAt: string | null;
22-
zipUrl: string | null;
2322
}[]
2423
> => {
2524
try {
@@ -42,7 +41,6 @@ export const getGithubReleases = async ({
4241
html_url: release.html_url,
4342
name: release.name,
4443
publishedAt: release.published_at,
45-
zipUrl: release.zipball_url,
4644
}));
4745
},
4846
ONE_DAY_SEC,

app/(docs)/(routes)/docs/releases/page.tsx

Lines changed: 1 addition & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -1,12 +1,10 @@
11
import { format } from 'date-fns';
2-
import { Download } from 'lucide-react';
32
import { Metadata } from 'next';
43
import Link from 'next/link';
54
import { getTranslations } from 'next-intl/server';
65

76
import { getGithubReleases } from '@/actions/github/get-releases';
87
import { MarkdownText } from '@/components/common/markdown-text';
9-
import { Button } from '@/components/ui';
108
import { TIMESTAMP_TEMPLATE } from '@/constants/common';
119

1210
export const metadata: Metadata = {
@@ -25,7 +23,7 @@ const ReleasesPage = async ({ searchParams }: ReleasesPagePageProps) => {
2523

2624
return (
2725
<div className="p-6 flex flex-col mb-6">
28-
<div className="w-full flex flex-col items-center">
26+
<div className="w-full flex flex-col items-start">
2927
{releases.map((release, index) => (
3028
<div className="mb-8" key={release.name}>
3129
{index === 0 && (
@@ -42,14 +40,6 @@ const ReleasesPage = async ({ searchParams }: ReleasesPagePageProps) => {
4240
{format(release.publishedAt, TIMESTAMP_TEMPLATE)}
4341
</p>
4442
)}
45-
{release.zipUrl && (
46-
<Link href={release.zipUrl}>
47-
<Button variant="outline">
48-
<Download className="h-4 w-4 mr-2" />
49-
{t('download')}
50-
</Button>
51-
</Link>
52-
)}
5343
</div>
5444
<MarkdownText className="max-w-screen-md" text={release.body} />
5545
</div>

lib/fetcher.ts

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -12,13 +12,13 @@ type FetchMethod = (
1212
class Fetcher {
1313
get: FetchMethod = async (url, options) => {
1414
if (options?.responseType === 'json') {
15-
const res = await fetch(url);
15+
const res = await fetch(url, { headers: options.headers });
1616

1717
return await res.json();
1818
}
1919

2020
if (options?.responseType === 'text') {
21-
const res = await fetch(url);
21+
const res = await fetch(url, { headers: options.headers });
2222

2323
return await res.text();
2424
}

0 commit comments

Comments
 (0)