Skip to content
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.

Commit 739f3ff

Browse files
committedFeb 17, 2025·
Merge remote-tracking branch 'refs/remotes/origin/add-validate-cli-tool' into add-validate-cli-tool
2 parents 1666668 + 91e22c1 commit 739f3ff

File tree

1 file changed

+15
-0
lines changed

1 file changed

+15
-0
lines changed
 

‎src/index.ts

+15
Original file line numberDiff line numberDiff line change
@@ -183,6 +183,7 @@ export async function exportActorProfile({
183183
* Imports an ActivityPub profile from a .tar archive stream.
184184
* @param tarStream - A ReadableStream containing the .tar archive.
185185
* @param options - Options for the import process.
186+
* @param options - Options for the import process.
186187
* @returns A promise that resolves to the parsed profile data.
187188
*/
188189
export async function importActorProfile(
@@ -191,7 +192,13 @@ export async function importActorProfile(
191192
console?: Pick<Console, 'log' | 'warn' | 'error'>
192193
onError?: (error: Error, context: { fileName?: string }) => void
193194
} = {}
195+
tarStream: Readable,
196+
options: {
197+
console?: Pick<Console, 'log' | 'warn' | 'error'>
198+
onError?: (error: Error, context: { fileName?: string }) => void
199+
} = {}
194200
): Promise<Record<string, any>> {
201+
const { console = undefined } = options
195202
const { console = undefined } = options
196203
const extract = tar.extract()
197204
const result: Record<string, any> = {}
@@ -210,6 +217,7 @@ export async function importActorProfile(
210217
return
211218
}
212219

220+
console?.log(`Processing file: ${fileName}`)
213221
console?.log(`Processing file: ${fileName}`)
214222
let content = ''
215223

@@ -222,12 +230,14 @@ export async function importActorProfile(
222230
if (fileName.endsWith('.json')) {
223231
result[fileName] = JSON.parse(content)
224232
console?.log('Parsed JSON file successfully:', fileName)
233+
console?.log('Parsed JSON file successfully:', fileName)
225234
} else if (fileName.endsWith('.yaml') || fileName.endsWith('.yml')) {
226235
result[fileName] = YAML.parse(content)
227236
} else if (fileName.endsWith('.csv')) {
228237
result[fileName] = content
229238
} else {
230239
console?.warn(`Unsupported file type: ${fileName}, skipping...`)
240+
console?.warn(`Unsupported file type: ${fileName}, skipping...`)
231241
}
232242
} catch (error: any) {
233243
const errorMessage = `Error processing file ${fileName}: ${error.message}`
@@ -244,20 +254,25 @@ export async function importActorProfile(
244254
stream.on('error', (error: any) => {
245255
console?.error(`Stream error on file ${fileName}:`, error.message)
246256
next(error) // Continue even on stream error
257+
console?.error(`Stream error on file ${fileName}:`, error.message)
258+
next(error) // Continue even on stream error
247259
})
248260
})
249261

250262
extract.on('finish', () => {
263+
console?.log('All files processed successfully.')
251264
console?.log('All files processed successfully.')
252265
resolve(result)
253266
})
254267

255268
extract.on('error', (error) => {
269+
console?.error('Error during tar extraction:', error.message)
256270
console?.error('Error during tar extraction:', error.message)
257271
reject(new Error('Failed to extract tar file.'))
258272
})
259273

260274
tarStream.on('error', (error) => {
275+
console?.error('Error in tar stream:', error.message)
261276
console?.error('Error in tar stream:', error.message)
262277
reject(new Error('Failed to process tar stream.'))
263278
})

0 commit comments

Comments
 (0)
Please sign in to comment.