@@ -6,7 +6,7 @@ import { type Pack } from 'tar-stream'
6
6
import YAML from 'yaml'
7
7
import { Readable } from 'stream'
8
8
9
- export type ActorProfileOptions = {
9
+ export interface ActorProfileOptions {
10
10
actorProfile ?: any
11
11
outbox ?: any
12
12
followers ?: any
@@ -113,14 +113,12 @@ export function exportActorProfile({
113
113
}
114
114
115
115
if ( followingAccounts ) {
116
- // CSV headers:
117
- // Account address, Show boosts, Notify on new posts, Languages
118
- manifest . contents . activitypub . contents [ 'following_accounts.csv' ] = {
116
+ manifest . contents . activitypub . contents [ 'following.json' ] = {
119
117
url : 'https://docs.joinmastodon.org/user/moving/#export'
120
118
}
121
119
pack . entry (
122
- { name : 'activitypub/following_accounts.csv ' } ,
123
- followingAccounts
120
+ { name : 'activitypub/following.json ' } ,
121
+ JSON . stringify ( followers , null , 2 )
124
122
)
125
123
}
126
124
@@ -161,48 +159,51 @@ export async function importActorProfile(tarBuffer: Buffer): Promise<any> {
161
159
const extract = tar . extract ( )
162
160
const result : Record < string , any > = { }
163
161
164
- return new Promise ( ( resolve , reject ) => {
162
+ return await new Promise ( ( resolve , reject ) => {
165
163
extract . on ( 'entry' , ( header , stream , next ) => {
166
164
let content = ''
165
+ console . log ( `Extracting file: ${ header . name } ` )
167
166
168
167
stream . on ( 'data' , ( chunk ) => {
169
168
content += chunk . toString ( )
170
169
} )
171
170
172
171
stream . on ( 'end' , ( ) => {
173
- // Handle JSON files
174
- if ( header . name . endsWith ( '.json' ) ) {
175
- try {
172
+ try {
173
+ if ( header . name . endsWith ( '.json' ) ) {
176
174
result [ header . name ] = JSON . parse ( content )
177
- } catch ( error ) {
178
- console . error ( `Error parsing JSON from ${ header . name } :` , error )
179
- }
180
- }
181
- // Handle YAML files
182
- else if (
183
- header . name . endsWith ( '.yaml' ) ||
184
- header . name . endsWith ( '.yml' )
185
- ) {
186
- try {
175
+ } else if (
176
+ header . name . endsWith ( '.yaml' ) ||
177
+ header . name . endsWith ( '.yml' )
178
+ ) {
187
179
result [ header . name ] = YAML . parse ( content )
188
- } catch ( error ) {
189
- console . error ( `Error parsing YAML from ${ header . name } :` , error )
180
+ } else if ( header . name . endsWith ( '.csv' ) ) {
181
+ result [ header . name ] = content
190
182
}
183
+ console . log ( `Successfully parsed: ${ header . name } ` )
184
+ } catch ( error ) {
185
+ console . error ( `Error processing file ${ header . name } :` , error )
186
+ reject ( error )
191
187
}
192
- // Handle CSV files
193
- else if ( header . name . endsWith ( '.csv' ) ) {
194
- result [ header . name ] = content // Return raw CSV as a string or implement CSV parsing here if needed
195
- }
188
+ next ( )
189
+ } )
196
190
197
- next ( ) // Process the next file in the tar archive
191
+ stream . on ( 'error' , ( error ) => {
192
+ console . error ( `Stream error on file ${ header . name } :` , error )
193
+ reject ( error )
198
194
} )
195
+ } )
199
196
200
- stream . on ( 'error' , ( error ) => { reject ( error ) ; } )
197
+ extract . on ( 'finish' , ( ) => {
198
+ console . log ( 'Extraction complete' , result )
199
+ resolve ( result )
201
200
} )
202
201
203
- extract . on ( 'finish' , ( ) => { resolve ( result ) ; } )
202
+ extract . on ( 'error' , ( error ) => {
203
+ console . error ( 'Error during extraction:' , error )
204
+ reject ( error )
205
+ } )
204
206
205
- // Stream the buffer data into the tar extractor
206
207
const stream = Readable . from ( tarBuffer )
207
208
stream . pipe ( extract )
208
209
} )
0 commit comments