File tree Expand file tree Collapse file tree 7 files changed +55
-32
lines changed
app/(docs)/(routes)/docs/releases Expand file tree Collapse file tree 7 files changed +55
-32
lines changed Original file line number Diff line number Diff line change 1
1
# Public common values
2
2
NEXT_PUBLIC_APP_URL =
3
- NEXT_PUBLIC_CONFIG_URL =
4
3
NEXT_PUBLIC_GOOGLE_DOMAIN =
5
4
NEXT_PUBLIC_OWNER_ID =
6
5
NEXT_PUBLIC_PUSHER_CLUSTER =
7
6
NEXT_PUBLIC_PUSHER_KEY =
8
7
NEXT_PUBLIC_YD_CAPTCHA =
9
8
10
- # Docs
11
- COOKIES_POLICY =
12
- PRIVACY_POLICY =
13
- TERMS =
14
-
15
9
# Auth secrets
16
10
NEXTAUTH_SECRET =
17
11
OTP_SECRET =
Original file line number Diff line number Diff line change 2
2
3
3
import { promises as fs } from 'fs' ;
4
4
5
- import { fetcher } from '@/lib/fetcher ' ;
5
+ import { getGithubContents } from '../github/get-contents ' ;
6
6
7
7
export type GetAppConfig = {
8
8
auth : Record < string , boolean > ;
@@ -15,7 +15,7 @@ export const getAppConfig = async (): Promise<GetAppConfig> => {
15
15
const config =
16
16
process . env . NODE_ENV === 'development'
17
17
? 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 ' } ) ;
19
19
20
20
return JSON . parse ( config ) ;
21
21
} catch ( error ) {
Original file line number Diff line number Diff line change 2
2
3
3
import { promises as fs } from 'fs' ;
4
4
5
- import { fetcher } from '@/lib/fetcher ' ;
5
+ import { getGithubContents } from '../github/get-contents ' ;
6
6
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 ) => {
14
8
try {
15
9
const content =
16
10
process . env . NODE_ENV === 'development'
17
11
? 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` } ) ;
19
13
20
14
return content ;
21
15
} catch ( error ) {
Original file line number Diff line number Diff line change
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
+ } ;
Original file line number Diff line number Diff line change @@ -19,7 +19,6 @@ export const getGithubReleases = async ({
19
19
html_url : string | null ;
20
20
name : string | null ;
21
21
publishedAt : string | null ;
22
- zipUrl : string | null ;
23
22
} [ ]
24
23
> => {
25
24
try {
@@ -42,7 +41,6 @@ export const getGithubReleases = async ({
42
41
html_url : release . html_url ,
43
42
name : release . name ,
44
43
publishedAt : release . published_at ,
45
- zipUrl : release . zipball_url ,
46
44
} ) ) ;
47
45
} ,
48
46
ONE_DAY_SEC ,
Original file line number Diff line number Diff line change 1
1
import { format } from 'date-fns' ;
2
- import { Download } from 'lucide-react' ;
3
2
import { Metadata } from 'next' ;
4
3
import Link from 'next/link' ;
5
4
import { getTranslations } from 'next-intl/server' ;
6
5
7
6
import { getGithubReleases } from '@/actions/github/get-releases' ;
8
7
import { MarkdownText } from '@/components/common/markdown-text' ;
9
- import { Button } from '@/components/ui' ;
10
8
import { TIMESTAMP_TEMPLATE } from '@/constants/common' ;
11
9
12
10
export const metadata : Metadata = {
@@ -25,7 +23,7 @@ const ReleasesPage = async ({ searchParams }: ReleasesPagePageProps) => {
25
23
26
24
return (
27
25
< 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 " >
29
27
{ releases . map ( ( release , index ) => (
30
28
< div className = "mb-8" key = { release . name } >
31
29
{ index === 0 && (
@@ -42,14 +40,6 @@ const ReleasesPage = async ({ searchParams }: ReleasesPagePageProps) => {
42
40
{ format ( release . publishedAt , TIMESTAMP_TEMPLATE ) }
43
41
</ p >
44
42
) }
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
- ) }
53
43
</ div >
54
44
< MarkdownText className = "max-w-screen-md" text = { release . body } />
55
45
</ div >
Original file line number Diff line number Diff line change @@ -12,13 +12,13 @@ type FetchMethod = (
12
12
class Fetcher {
13
13
get : FetchMethod = async ( url , options ) => {
14
14
if ( options ?. responseType === 'json' ) {
15
- const res = await fetch ( url ) ;
15
+ const res = await fetch ( url , { headers : options . headers } ) ;
16
16
17
17
return await res . json ( ) ;
18
18
}
19
19
20
20
if ( options ?. responseType === 'text' ) {
21
- const res = await fetch ( url ) ;
21
+ const res = await fetch ( url , { headers : options . headers } ) ;
22
22
23
23
return await res . text ( ) ;
24
24
}
You can’t perform that action at this time.
0 commit comments