@@ -30,57 +30,70 @@ import getAllRepositoryBranch from "../../../helpers/getAllRepositoryBranch";
3030import getAllRepositoryTag from "../../../helpers/getAllRepositoryTag" ;
3131import getUser from "../../../helpers/getUser" ;
3232import getDao from "../../../helpers/getDao" ;
33+ import validAddress from "../../../helpers/validAddress" ;
3334
3435const atob = ( base64 ) => {
3536 return Buffer . from ( base64 , "base64" ) . toString ( "binary" ) ;
3637} ;
3738
3839export async function getStaticProps ( { params } ) {
3940 try {
40- const fs = ( await import ( "fs" ) ) . default ;
41- const repositories = JSON . parse (
42- fs . readFileSync ( "./seo/dump-repositories.json" )
43- ) ;
44-
45- const r = find (
46- repositories ,
47- ( r ) =>
48- r . name === params . repositoryId &&
49- ( r . owner . id === params . userId || r . owner . username === params . userId )
50- ) ;
41+ const db = ( await import ( "../../../helpers/getSeoDatabase" ) ) . default ;
42+ let r ;
43+ if ( validAddress . test ( params . userId ) ) {
44+ r = JSON . parse (
45+ (
46+ await db
47+ . first ( "*" )
48+ . from ( "Repositories" )
49+ . where ( { name : params . repositoryId , ownerAddress : params . userId } )
50+ ) . data
51+ ) ;
52+ } else {
53+ r = JSON . parse (
54+ (
55+ await db
56+ . first ( "*" )
57+ . from ( "Repositories" )
58+ . where ( { name : params . repositoryId , ownerUsername : params . userId } )
59+ ) . data
60+ ) ;
61+ }
5162
5263 if ( r ) {
53- let branchSha = getBranchSha ( r . defaultBranch , r . branches , r . tags ) ;
54-
55- const entitiesRes = await getContent ( r . id , branchSha , null , null ) ;
56-
57- const commitHistory = await getCommitHistory ( r . id , branchSha , null , 1 ) ;
58-
59- const readmeRegex = new RegExp ( / ^ R E A D M E / gi) ;
60- let readmeFile = null ;
61- for ( let i = 0 ; i < entitiesRes ?. content ?. length ; i ++ ) {
62- if ( readmeRegex . test ( entitiesRes . content [ i ] . name ) ) {
63- const readme = await getContent (
64- r . id ,
65- branchSha ,
66- entitiesRes . content [ i ] . name
67- ) ;
68- if ( readme ?. content [ 0 ] ) {
69- readmeFile = atob ( readme . content [ 0 ] . content ) ;
70- }
71- }
72- }
64+ // let branchSha = getBranchSha(r.defaultBranch, r.branches, r.tags);
65+
66+ // const entitiesRes = await getContent(r.id, branchSha, null, null);
67+
68+ // const commitHistory = await getCommitHistory(r.id, branchSha, null, 1);
69+
70+ // const readmeRegex = new RegExp(/^README/gi);
71+ // let readmeFile = null;
72+ // for (let i = 0; i < entitiesRes?.content?.length; i++) {
73+ // if (readmeRegex.test(entitiesRes.content[i].name)) {
74+ // const readme = await getContent(
75+ // r.id,
76+ // branchSha,
77+ // entitiesRes.content[i].name
78+ // );
79+ // if (readme?.content[0]) {
80+ // readmeFile = atob(readme.content[0].content);
81+ // }
82+ // }
83+ // }
7384 return {
7485 props : {
7586 repository : r ,
76- entitiesRes,
77- commitHistory : { commits : [ { } ] , ...commitHistory } ,
78- readmeFile,
87+ // entitiesRes,
88+ // commitHistory: { commits: [{}], ...commitHistory },
89+ // readmeFile,
7990 } ,
8091 revalidate : 1 ,
8192 } ;
8293 }
83- } catch ( e ) { }
94+ } catch ( e ) {
95+ console . error ( e ) ;
96+ }
8497 return {
8598 props : { } ,
8699 } ;
0 commit comments