11import { getFiles as getGithubFiles } from '@/lib/sync/github'
22import { GithubContent } from '@/lib/sync/github.types'
33import { getFiles as getGiteeFiles } from '@/lib/sync/gitee'
4+ import { getFiles as getGiteaFiles } from '@/lib/sync/gitea'
45import { getFiles as getGitlabFiles } from '@/lib/sync/gitlab'
56import { GiteeFile } from '@/lib/sync/gitee'
7+ import { GiteaDirectoryItem } from '@/lib/sync/gitea.types'
68import { getSyncRepoName } from '@/lib/sync/repo-utils'
79import { autoSyncIfNeeded , hasNetworkConnection , ensureDirectoryExists } from '@/lib/sync/auto-sync'
810import { sanitizeFilePath , hasInvalidFileNameChars } from '@/lib/sync/filename-utils'
@@ -488,6 +490,11 @@ const useArticleStore = create<NoteState>((set, get) => ({
488490 if ( ! gitlabAccessToken ) {
489491 return
490492 }
493+ } else if ( primaryBackupMethod === 'gitea' ) {
494+ const giteaAccessToken = await store . get < string > ( 'giteaAccessToken' )
495+ if ( ! giteaAccessToken ) {
496+ return
497+ }
491498 }
492499
493500 // 只为根目录和本地存在的已展开文件夹加载远程文件
@@ -536,11 +543,15 @@ const useArticleStore = create<NoteState>((set, get) => ({
536543 const gitlabRepo = await getSyncRepoName ( 'gitlab' ) ;
537544 files = await getGitlabFiles ( { path, repo : gitlabRepo } ) ;
538545 break ;
546+ case 'gitea' :
547+ const giteaRepo = await getSyncRepoName ( 'gitea' ) ;
548+ files = await getGiteaFiles ( { path, repo : giteaRepo } ) ;
549+ break ;
539550 }
540551
541552 if ( files ) {
542553 const dirs = get ( ) . fileTree
543- files . forEach ( ( file : GithubContent | GiteeFile ) => {
554+ files . forEach ( ( file : GithubContent | GiteeFile | GiteaDirectoryItem ) => {
544555 // 过滤以"."开头的文件和文件夹
545556 if ( file . name . startsWith ( '.' ) ) {
546557 return ;
@@ -641,6 +652,9 @@ const useArticleStore = create<NoteState>((set, get) => ({
641652 } else if ( primaryBackupMethod === 'gitlab' ) {
642653 const gitlabAccessToken = await store . get < string > ( 'gitlabAccessToken' )
643654 hasCloudSync = ! ! gitlabAccessToken
655+ } else if ( primaryBackupMethod === 'gitea' ) {
656+ const giteaAccessToken = await store . get < string > ( 'giteaAccessToken' )
657+ hasCloudSync = ! ! giteaAccessToken
644658 }
645659
646660 // 只有在配置了云同步时才设置加载状态
@@ -731,6 +745,9 @@ const useArticleStore = create<NoteState>((set, get) => ({
731745 } else if ( primaryBackupMethod === 'gitlab' ) {
732746 const gitlabAccessToken = await store . get < string > ( 'gitlabAccessToken' )
733747 if ( ! gitlabAccessToken ) return
748+ } else if ( primaryBackupMethod === 'gitea' ) {
749+ const giteaAccessToken = await store . get < string > ( 'giteaAccessToken' )
750+ if ( ! giteaAccessToken ) return
734751 }
735752
736753 try {
@@ -748,14 +765,18 @@ const useArticleStore = create<NoteState>((set, get) => ({
748765 const gitlabRepo1 = await getSyncRepoName ( 'gitlab' ) ;
749766 files = await getGitlabFiles ( { path : fullpath , repo : gitlabRepo1 } ) ;
750767 break ;
768+ case 'gitea' :
769+ const giteaRepo1 = await getSyncRepoName ( 'gitea' ) ;
770+ files = await getGiteaFiles ( { path : fullpath , repo : giteaRepo1 } ) ;
771+ break ;
751772 }
752773
753774 if ( files ) {
754775 const cacheTree = get ( ) . fileTree
755776 const currentFolder = getCurrentFolder ( fullpath , cacheTree )
756777
757778 if ( currentFolder ) {
758- files . forEach ( ( file : GithubContent | GiteeFile ) => {
779+ files . forEach ( ( file : GithubContent | GiteeFile | GiteaDirectoryItem ) => {
759780 // 过滤以"."开头的文件和文件夹
760781 if ( file . name . startsWith ( '.' ) ) {
761782 return ;
0 commit comments