1
1
import * as tar from 'tar-stream'
2
- import { Readable } from 'stream'
2
+ import { type Readable } from 'stream'
3
3
import YAML from 'yaml'
4
4
5
5
/**
6
6
* Validates the structure and content of an exported ActivityPub tarball.
7
- * @param tarBuffer - A Buffer containing the .tar archive.
7
+ * @param tarStream - A ReadableStream containing the .tar archive.
8
8
* @returns A promise that resolves to an object with `valid` (boolean) and `errors` (string[]).
9
9
*/
10
10
export async function validateExportStream (
11
- tarBuffer : Buffer
11
+ tarStream : Readable
12
12
) : Promise < { valid : boolean ; errors : string [ ] } > {
13
+ console . log ( 'Validating export stream...' )
14
+ console . log ( 'length of tarStream: ' , tarStream )
13
15
const extract = tar . extract ( )
14
16
const errors : string [ ] = [ ]
15
17
const requiredFiles = [
16
- 'manifest.yaml' ,
18
+ 'manifest.yaml' , // or 'manifest.yml'
17
19
'activitypub/actor.json' ,
18
20
'activitypub/outbox.json'
19
- ]
20
- const foundFiles = new Set ( )
21
+ ] . map ( ( file ) => file . toLowerCase ( ) ) // Normalize to lowercase for consistent comparison
22
+ const foundFiles = new Set < string > ( )
21
23
22
24
return await new Promise ( ( resolve ) => {
23
25
extract . on ( 'entry' , ( header , stream , next ) => {
24
- const fileName = header . name
26
+ const fileName = header . name . toLowerCase ( ) // Normalize file name
27
+ console . log ( `Processing file: ${ fileName } ` ) // Log the file name
25
28
foundFiles . add ( fileName )
26
29
27
30
let content = ''
@@ -37,7 +40,7 @@ export async function validateExportStream(
37
40
}
38
41
39
42
// Validate manifest file
40
- if ( fileName === 'manifest.yaml' ) {
43
+ if ( fileName === 'manifest.yaml' || fileName === 'manifest.yml' ) {
41
44
const manifest = YAML . parse ( content )
42
45
if ( ! manifest [ 'ubc-version' ] ) {
43
46
errors . push ( 'Manifest is missing required field: ubc-version' )
@@ -61,6 +64,9 @@ export async function validateExportStream(
61
64
} )
62
65
63
66
extract . on ( 'finish' , ( ) => {
67
+ console . log ( 'Found files:' , Array . from ( foundFiles ) ) // Debug log
68
+ console . log ( 'Required files:' , requiredFiles ) // Debug log
69
+
64
70
// Check if all required files are present
65
71
for ( const file of requiredFiles ) {
66
72
if ( ! foundFiles . has ( file ) ) {
@@ -82,8 +88,7 @@ export async function validateExportStream(
82
88
} )
83
89
} )
84
90
85
- // Convert Buffer to a Readable stream and pipe it to the extractor
86
- const stream = Readable . from ( tarBuffer )
87
- stream . pipe ( extract )
91
+ // Pipe the ReadableStream into the extractor
92
+ tarStream . pipe ( extract )
88
93
} )
89
94
}
0 commit comments