@@ -8,6 +8,7 @@ import ValidateUsername from "./helpers/ValidateUsername.js"
88import FindRegexArray from "./helpers/FindRegexArray.js"
99import GetURLFilename from "./helpers/GetURLFilename.js"
1010import filenamify from "filenamify"
11+ import isNumber from "./helpers/isNumber.js"
1112import dotenv from "dotenv"
1213import Debug from "./helpers/Debug.js"
1314import Queue from "./Queue.js"
@@ -194,13 +195,15 @@ export default class Downloader {
194195
195196 headers . Cookie = Object . entries ( cookie ) . map ( ( [ key , value ] ) => `${ key } =${ value || "" } ` ) . join ( "; " )
196197 }
197- /** @param {Pick<import("./typings/index.d.ts").Options, "output" | "timeline" | "highlights" | "stories" | "hcover" | "debug" | "flatDir"> } data */
198- async Init ( { output, timeline, highlights, hcover, stories, debug, flatDir } ) {
198+ /** @param {Pick<import("./typings/index.d.ts").Options, "output" | "timeline" | "highlights" | "limit" | " stories" | "hcover" | "debug" | "flatDir"> } data */
199+ async Init ( { output, timeline, highlights, limit , hcover, stories, debug, flatDir } ) {
199200 Log ( "Initializing" )
200201
201202 this . debug = debug
202203 this . flatDir = flatDir
203204
205+ if ( isNumber ( limit ) ) this . limit = Number ( limit )
206+
204207 if ( ! this . usernames . length ) {
205208 throw "There are no valid usernames"
206209 }
@@ -270,7 +273,7 @@ export default class Downloader {
270273 const folder = join ( output , username )
271274
272275 const results = await Promise . allSettled ( [
273- timeline && this . DownloadTimeline ( username , folder ) ,
276+ timeline && this . DownloadTimeline ( username , folder , this . limit ) ,
274277 highlights && this . DownloadHighlights ( userId , folder , hcover , this . limit , username ) ,
275278 stories && this . DownloadStories ( userId , folder , this . limit , username )
276279 ] )
@@ -585,12 +588,13 @@ export default class Downloader {
585588
586589 const { items : stories } = results
587590
591+ if ( ! stories . length ) return
592+
593+ Log ( "Downloading stories" )
594+
588595 const target_dir = this . flatDir ? folder : join ( folder , "stories" )
589596
590- if ( stories . length ) {
591- await mkdir ( target_dir , { recursive : true } )
592- Log ( "Downloading stories" )
593- }
597+ await mkdir ( target_dir , { recursive : true } )
594598
595599 let count = 0
596600
@@ -646,11 +650,12 @@ export default class Downloader {
646650 const data = { count, limit }
647651 const { limited } = await this . DownloadItems ( items , target_dir , data , username )
648652
653+ count = data . count
654+
649655 if ( limited ) break
650656
651657 hasMore = more_available
652658 lastId = next_max_id
653- count = data . count
654659 } else Log ( new Error ( "Failed to get timeline, lastId: " + ( lastId || null ) ) )
655660 }
656661
0 commit comments