File tree Expand file tree Collapse file tree 2 files changed +12
-14
lines changed Expand file tree Collapse file tree 2 files changed +12
-14
lines changed Original file line number Diff line number Diff line change 1
1
{
2
2
"name" : " @hackmd/api" ,
3
- "version" : " 1.0 .0" ,
3
+ "version" : " 1.1 .0" ,
4
4
"description" : " HackMD/CodiMD Node.js API Client" ,
5
5
"main" : " dist/index.js" ,
6
6
"declaration" : " ./dist/index.d.ts" ,
Original file line number Diff line number Diff line change @@ -140,7 +140,7 @@ class API {
140
140
}
141
141
}
142
142
143
- async export ( noteId : string , type : ExportType , output : string ) {
143
+ private async exportRes ( noteId : string , type : ExportType ) {
144
144
let res : Response
145
145
switch ( type ) {
146
146
case ExportType . PDF :
@@ -157,21 +157,19 @@ class API {
157
157
res = await this . fetch ( `${ this . serverUrl } /${ noteId } /download` )
158
158
}
159
159
160
- return this . downloadFile ( res , output )
160
+ return res
161
161
}
162
162
163
- private async downloadFile ( res : any , output : string ) {
164
- const fileStream = fs . createWriteStream ( output )
163
+ async exportString ( noteId : string , type : ExportType ) {
164
+ const res = await this . exportRes ( noteId , type )
165
165
166
- await new Promise ( ( resolve , reject ) => {
167
- res . body . pipe ( fileStream )
168
- res . body . on ( 'error' , ( err : any ) => {
169
- reject ( err )
170
- } )
171
- fileStream . on ( 'finish' , function ( ) {
172
- resolve ( )
173
- } )
174
- } )
166
+ return res . text ( )
167
+ }
168
+
169
+ async exportStream ( noteId : string , type : ExportType ) {
170
+ const res = await this . exportRes ( noteId , type )
171
+
172
+ return res . body
175
173
}
176
174
177
175
get fetch ( ) {
You can’t perform that action at this time.
0 commit comments