mirror of
https://github.com/openclaw/openclaw.git
synced 2026-06-06 05:51:15 +08:00
fix(file-transfer): centralize dir-list page token parsing
This commit is contained in:
@@ -144,6 +144,19 @@ describe("handleDirList — happy path", () => {
|
||||
expect(r.entries.map((e) => e.name)).toEqual(["f-0.txt"]);
|
||||
expect(r.nextPageToken).toBe("1");
|
||||
});
|
||||
|
||||
it("accepts plus-signed page tokens", async () => {
|
||||
for (let i = 0; i < 3; i++) {
|
||||
await fs.writeFile(path.join(tmpRoot, `f-${i}.txt`), "x");
|
||||
}
|
||||
|
||||
const r = await handleDirList({ path: tmpRoot, maxEntries: 1, pageToken: "+01" });
|
||||
if (!r.ok) {
|
||||
throw new Error("expected ok");
|
||||
}
|
||||
expect(r.entries.map((e) => e.name)).toEqual(["f-1.txt"]);
|
||||
expect(r.nextPageToken).toBe("2");
|
||||
});
|
||||
});
|
||||
|
||||
describe("handleDirList — limits", () => {
|
||||
|
||||
@@ -1,4 +1,5 @@
|
||||
import path from "node:path";
|
||||
import { parseStrictNonNegativeInteger } from "openclaw/plugin-sdk/number-runtime";
|
||||
import { root } from "openclaw/plugin-sdk/security-runtime";
|
||||
import { mimeFromExtension } from "../shared/mime.js";
|
||||
import {
|
||||
@@ -63,12 +64,7 @@ function parsePageOffset(input: unknown): number {
|
||||
if (typeof input !== "string") {
|
||||
return 0;
|
||||
}
|
||||
const trimmed = input.trim();
|
||||
if (!/^\d+$/.test(trimmed)) {
|
||||
return 0;
|
||||
}
|
||||
const offset = Number(trimmed);
|
||||
return Number.isSafeInteger(offset) ? offset : 0;
|
||||
return parseStrictNonNegativeInteger(input) ?? 0;
|
||||
}
|
||||
|
||||
function classifyFsError(err: unknown): DirListErrCode {
|
||||
|
||||
Reference in New Issue
Block a user