File tree Expand file tree Collapse file tree 2 files changed +27
-38
lines changed
Expand file tree Collapse file tree 2 files changed +27
-38
lines changed Original file line number Diff line number Diff line change @@ -123,42 +123,23 @@ const EmbedPage: NextPage = () => {
123123 case 5 :
124124 return Message . error ( t ( 'submit.check_fail6' ) ) ;
125125 }
126-
127- const urlToCheck = `https://api.github.com/repos/${ info_res . data . full_name } /contents/${ readmeFilename } ` ;
128- setIsLoading ( true ) ; // 设置加载状态为 true,禁用按钮
129- // 发送GET请求到URL
130- fetch ( urlToCheck )
131- . then ( ( response ) => response . json ( ) )
132- . then ( async ( data ) => {
133- const base64EncodedString = data . content ;
134- const decodedString = Buffer . from (
135- base64EncodedString ,
136- 'base64'
137- ) . toString ( 'utf8' ) ;
138- // 检查响应的字段
139- if (
140- decodedString . includes (
141- `https://hellogithub.com/repository/${ repoID } `
142- ) &&
143- decodedString . includes ( userInfo ?. uid as string )
144- ) {
145- // 如果响应包含字段,发送POST请求到后台
146- const res = await claimRepo ( repoID , readmeFilename ) ;
147- if ( res . success ) {
148- return Message . success ( t ( 'submit.success' ) ) ;
149- } else {
150- return Message . error ( res . message as string ) ;
151- }
152- } else {
153- return Message . error ( t ( 'submit.fail' ) ) ;
154- }
155- } )
156- . catch ( ( ) => {
157- return Message . error ( t ( 'submit.fail2' ) ) ;
158- } )
159- . finally ( ( ) => {
160- setIsLoading ( false ) ; // 设置加载状态为 false,启用按钮
161- } ) ;
126+ try {
127+ setIsLoading ( true ) ;
128+ const res = await claimRepo (
129+ repoID ,
130+ readmeFilename ,
131+ info_res . data . full_name
132+ ) ;
133+ if ( res . success ) {
134+ return Message . success ( t ( 'submit.success' ) ) ;
135+ } else {
136+ return Message . error ( res . message as string ) ;
137+ }
138+ } catch ( error ) {
139+ return Message . error ( t ( 'submit.fail' ) ) ;
140+ } finally {
141+ setIsLoading ( false ) ;
142+ }
162143 } ;
163144
164145 return (
Original file line number Diff line number Diff line change @@ -193,11 +193,19 @@ export const checkRepo = (url: string): Promise<CheckRepoRes> => {
193193} ;
194194
195195// 认领仓库
196- export const claimRepo = async ( rid : string , readme_name : string ) => {
196+ export const claimRepo = async (
197+ rid : string ,
198+ readme_name : string ,
199+ repo_full_name : string
200+ ) => {
197201 const url = makeUrl ( `/repository/claim/` ) ;
198202 const result = await fetcher < { success : boolean ; message ?: string } > ( url , {
199203 method : 'POST' ,
200- body : JSON . stringify ( { rid : rid , readme_name : readme_name } ) ,
204+ body : JSON . stringify ( {
205+ rid : rid ,
206+ readme_name : readme_name ,
207+ repo_full_name : repo_full_name ,
208+ } ) ,
201209 } ) . catch ( ( err ) => {
202210 Message . error ( err . message || '认领失败' ) ;
203211 throw err ;
You can’t perform that action at this time.
0 commit comments