@@ -103,19 +103,9 @@ async function findAccounts(
103103 return accounts ;
104104}
105105
106- // ── Main entry ──
107-
108- export async function parseInstagramZip (
109- file : File
110- ) : Promise < AnalysisResult > {
111- const zip = await JSZip . loadAsync ( file ) ;
112-
113- const paths = Object . keys ( zip . files ) ;
114- const isInstagram = paths . some (
115- ( p ) => p . includes ( "followers" ) || p . includes ( "following" )
116- ) ;
117- if ( ! isInstagram ) throw new Error ( "INVALID_ZIP" ) ;
106+ // ── Shared analysis helper ──
118107
108+ async function analyzeZip ( zip : JSZip ) : Promise < AnalysisResult > {
119109 const [
120110 followers ,
121111 following ,
@@ -151,59 +141,36 @@ export async function parseInstagramZip(
151141 } ;
152142}
153143
154- export async function parseFileFull ( file : File ) : Promise < FullData > {
155- if ( ! file . name . endsWith ( ".zip" ) ) throw new Error ( "UNSUPPORTED_FORMAT" ) ;
156-
157- const zip = await JSZip . loadAsync ( file ) ;
144+ // ── Validate ZIP contains Instagram data ──
158145
146+ function validateInstagramZip ( zip : JSZip ) : void {
159147 const paths = Object . keys ( zip . files ) ;
160148 const isInstagram = paths . some (
161149 ( p ) => p . includes ( "followers" ) || p . includes ( "following" )
162150 ) ;
163151 if ( ! isInstagram ) throw new Error ( "INVALID_ZIP" ) ;
152+ }
164153
165- const [ analysis , insights ] = await Promise . all ( [
166- parseInstagramZipFromLoaded ( zip ) ,
167- parseInsights ( zip ) ,
168- ] ) ;
154+ // ── Main entry ──
169155
170- return { analysis, insights } ;
156+ export async function parseInstagramZip (
157+ file : File
158+ ) : Promise < AnalysisResult > {
159+ const zip = await JSZip . loadAsync ( file ) ;
160+ validateInstagramZip ( zip ) ;
161+ return analyzeZip ( zip ) ;
171162}
172163
173- async function parseInstagramZipFromLoaded (
174- zip : JSZip
175- ) : Promise < AnalysisResult > {
176- const [
177- followers ,
178- following ,
179- pending ,
180- unfollowed ,
181- closeFriends ,
182- blocked ,
183- restricted ,
184- ] = await Promise . all ( [
185- findAccounts ( zip , "followers" ) ,
186- findAccounts ( zip , "following" ) ,
187- findAccounts ( zip , "pending_follow" ) ,
188- findAccounts ( zip , "unfollowed" ) ,
189- findAccounts ( zip , "close_friends" ) ,
190- findAccounts ( zip , "blocked" ) ,
191- findAccounts ( zip , "restricted" ) ,
192- ] ) ;
164+ export async function parseFileFull ( file : File ) : Promise < FullData > {
165+ if ( ! file . name . endsWith ( ".zip" ) ) throw new Error ( "UNSUPPORTED_FORMAT" ) ;
193166
194- const followerSet = new Set ( followers . map ( ( a ) => a . username ) ) ;
195- const followingSet = new Set ( following . map ( ( a ) => a . username ) ) ;
167+ const zip = await JSZip . loadAsync ( file ) ;
168+ validateInstagramZip ( zip ) ;
196169
197- return {
198- followers,
199- following,
200- pendingRequests : pending ,
201- recentlyUnfollowed : unfollowed ,
202- closeFriends,
203- blockedAccounts : blocked ,
204- restrictedAccounts : restricted ,
205- nonMutual : following . filter ( ( a ) => ! followerSet . has ( a . username ) ) ,
206- fansOnly : followers . filter ( ( a ) => ! followingSet . has ( a . username ) ) ,
207- mutual : following . filter ( ( a ) => followerSet . has ( a . username ) ) ,
208- } ;
170+ const [ analysis , insights ] = await Promise . all ( [
171+ analyzeZip ( zip ) ,
172+ parseInsights ( zip ) ,
173+ ] ) ;
174+
175+ return { analysis, insights } ;
209176}
0 commit comments