Skip to content

Commit feb0f18

Browse files
committed
Fix limit option
1 parent 2b89cab commit feb0f18

3 files changed

Lines changed: 52 additions & 47 deletions

File tree

.github/workflows/nodejs.yml

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -25,17 +25,17 @@ jobs:
2525
- name: Install pnpm
2626
uses: pnpm/action-setup@v4
2727
with:
28-
version: 9
29-
run_install: |
30-
- recursive: false
31-
args: [--frozen-lockfile]
28+
version: 10
3229

3330
- name: Install Node.js ${{ matrix.node-version }}
3431
uses: actions/setup-node@v4
3532
with:
3633
node-version: ${{ matrix.node-version }}
3734
cache: 'pnpm'
3835

36+
- name: Install dependencies
37+
run: pnpm install
38+
3939
- name: Test project
4040
run: pnpm test
4141
env:

pnpm-lock.yaml

Lines changed: 35 additions & 35 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

src/Downloader.js

Lines changed: 13 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -8,6 +8,7 @@ import ValidateUsername from "./helpers/ValidateUsername.js"
88
import FindRegexArray from "./helpers/FindRegexArray.js"
99
import GetURLFilename from "./helpers/GetURLFilename.js"
1010
import filenamify from "filenamify"
11+
import isNumber from "./helpers/isNumber.js"
1112
import dotenv from "dotenv"
1213
import Debug from "./helpers/Debug.js"
1314
import 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

Comments
 (0)