@@ -37,7 +37,7 @@ export class BookService {
3737 private cate : CateService
3838 ) {
3939 this . crud . getItems ( { table : 'Book' } )
40- . subscribe ( ( res : IQueryResult ) => {
40+ . then ( ( res : IQueryResult ) => {
4141 this . opMessage . newMsg ( res . message ) ;
4242 const books = res . data as Book [ ] ;
4343 this . list = books . slice ( ) ;
@@ -72,51 +72,50 @@ export class BookService {
7272
7373 const re = new RegExp ( / \. g i t $ / )
7474 newBook . name = re . test ( name ) ? name . replace ( re , '' ) : name ;
75+ newBook . isFromMainstreamPlatform = / g i t h u b / . test ( site ) || / g i t e e / . test ( site ) || / g i t l a b / . test ( site ) ;
7576
7677 newBook . website = await this . website . newWebsit ( site ) ;
77-
78+
79+ let rawRepo : object ;
7880 if ( / g i t e e / . test ( site ) ) {
79- await this . fetchService . getRepoProfile ( site , newBook . name , writerName ) . subscribe ( async ( res ) => {
80- newBook . writer = await this . writer . newWriter ( writerName , newBook . website , res [ 'owner' ] [ 'login' ] ) ;
81- } ) ;
81+ rawRepo = await this . fetchService . getRepoProfile ( site , newBook . name , writerName ) ;
82+ newBook . writer = await this . writer . newWriter ( writerName , newBook , rawRepo [ 'owner' ] [ 'login' ] ) ;
8283 }
8384 else {
84- newBook . writer = await this . writer . newWriter ( writerName , newBook . website ) ;
85+ newBook . writer = await this . writer . newWriter ( writerName , newBook ) ;
8586 }
8687
8788 newBook . cateList = await this . cate . saveList ( res . cateList ) ;
8889 newBook . recordList = [ ] ;
8990
9091 // 这里要获取到 Repository 的更多信息
9192 if ( / g i t l a b / . test ( site ) ) {
92- await this . fetchService . getRepoProfile ( site , newBook . name , writerName , newBook . writer . platformId )
93- . subscribe ( res => {
94- const repo = ( res as object [ ] ) . find ( repo => repo [ 'path' ] === newBook . name )
93+ const rawRepoList = await this . fetchService . getRepoProfile ( site , newBook . name , writerName , newBook . writer . platformId ) ;
9594
96- newBook . desc = repo [ 'description' ] ;
97- newBook . defaultBranch = repo [ 'default_branch' ] ;
98- } ) ;
95+ rawRepo = ( rawRepoList as object [ ] ) . find ( repo => repo [ 'path' ] === newBook . name ) ;
96+
97+ newBook . desc = rawRepo [ 'description' ] ;
98+ newBook . defaultBranch = rawRepo [ 'default_branch' ] ;
9999 }
100- else {
101- await this . fetchService . getRepoProfile ( site , newBook . name , writerName )
102- . subscribe ( res => {
103- newBook . desc = res [ 'description' ] ;
104- newBook . defaultBranch = res [ 'default_branch' ] ;
105- } ) ;
100+
101+ if ( newBook . isFromMainstreamPlatform && ! ( / g i t l a b / . test ( site ) ) ) {
102+ rawRepo = rawRepo ? rawRepo : await this . fetchService . getRepoProfile ( site , newBook . name , writerName ) ;
103+ newBook . desc = rawRepo [ 'description' ] ;
104+ newBook . defaultBranch = rawRepo [ 'default_branch' ] ;
106105 }
107106
107+ console . log ( newBook )
108108 const query : IQuery = {
109109 table : 'Book' ,
110110 item : newBook
111111 }
112112
113- this . crud . addItem ( query ) . subscribe ( ( res : IQueryResult ) => {
114- this . opMessage . newMsg ( res . message ) ;
115- this . listUpdated ( res . data as Book ) ;
116- } ) ;
113+ const queryRes :IQueryResult = await this . crud . addItem ( query ) ;
114+ this . opMessage . newMsg ( queryRes . message ) ;
115+ this . listUpdated ( queryRes . data as Book ) ;
117116 }
118117
119- open = ( book : Book ) => {
118+ open = async ( book : Book ) => {
120119 this . crud . ipcRenderer . send ( 'open-book' , book ) ;
121120 book . recycled = false ;
122121
@@ -125,10 +124,9 @@ export class BookService {
125124 item : book
126125 }
127126
128- this . crud . updateItem ( query ) . subscribe ( ( queryRes : IQueryResult ) => {
129- this . opMessage . newMsg ( queryRes . message ) ;
130- this . listUpdated ( queryRes . data as Book ) ;
131- } ) ;
127+ const res : IQueryResult = await this . crud . updateItem ( query ) ;
128+ this . opMessage . newMsg ( res . message ) ;
129+ this . listUpdated ( res . data as Book ) ;
132130 }
133131
134132 update = async ( book : Book ) => {
@@ -140,10 +138,9 @@ export class BookService {
140138 table : 'Book' ,
141139 item : book
142140 }
143- this . crud . updateItem ( query ) . subscribe ( ( queryRes : IQueryResult ) => {
144- this . opMessage . newMsg ( queryRes . message ) ;
145- this . listUpdated ( queryRes . data as Book ) ;
146- } ) ;
141+ const queryRes : IQueryResult = await this . crud . updateItem ( query ) ;
142+ this . opMessage . newMsg ( queryRes . message ) ;
143+ this . listUpdated ( queryRes . data as Book ) ;
147144 }
148145
149146 recycleRecoverDelete = async ( res : IDeleteBookDialogResData ) => {
@@ -155,9 +152,8 @@ export class BookService {
155152 item : res . book
156153 }
157154
158- await this . crud . deleteItem ( query ) . subscribe ( ( res : IQueryResult ) => {
159- this . opMessage . newMsg ( res . message ) ;
160- } ) ;
155+ const queryRes : IQueryResult = await this . crud . deleteItem ( query ) ;
156+ this . opMessage . newMsg ( queryRes . message ) ;
161157 }
162158
163159 if ( ! res . recycled && res . remove ) {
@@ -166,10 +162,9 @@ export class BookService {
166162 item : res . book
167163 }
168164
169- await this . crud . deleteItem ( query ) . subscribe ( ( queryRes : IQueryResult ) => {
170- this . opMessage . newMsg ( queryRes . message ) ;
171- this . listUpdated ( res . book , true ) ;
172- } ) ;
165+ const queryRes :IQueryResult = await this . crud . deleteItem ( query ) ;
166+ this . opMessage . newMsg ( queryRes . message ) ;
167+ this . listUpdated ( res . book , true ) ;
173168
174169 return ;
175170 }
@@ -183,9 +178,8 @@ export class BookService {
183178 item : res . book
184179 }
185180
186- this . crud . updateItem ( query ) . subscribe ( ( queryRes : IQueryResult ) => {
187- this . opMessage . newMsg ( queryRes . message ) ;
188- this . listUpdated ( queryRes . data as Book ) ;
189- } ) ;
181+ const queryRes :IQueryResult = await this . crud . updateItem ( query ) ;
182+ this . opMessage . newMsg ( queryRes . message ) ;
183+ this . listUpdated ( queryRes . data as Book ) ;
190184 }
191185}
0 commit comments