Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

fix: remark-lsx pagination #9513

Merged
merged 1 commit into from
Dec 23, 2024
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
4 changes: 2 additions & 2 deletions packages/remark-lsx/src/server/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -14,8 +14,8 @@ const filterXSS = new FilterXSS();

const lsxValidator = [
query('pagePath').notEmpty().isString(),
query('offset').optional().isInt(),
query('limit').optional().isInt(),
query('offset').optional().isInt().toInt(),
query('limit').optional().isInt().toInt(),
Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

バグの原因

offset が文字列になっていたことにより、 ("50" ?? 0) + pages.length の結果が 5050 のようになってしまっていた。

const cursor = (offset ?? 0) + pages.length;

API のレスポンスである cursor は次の Road more をクリックした時に走る API リクエストのクエリパラメーターである offset に入る。

async([endpoint, pagePath, options, offset, limit, parseErrorMessage]) => {
if (parseErrorMessage != null) {
throw new Error(parseErrorMessage);
}
const apiOptions = Object.assign({}, options, { num: undefined }) as LsxApiOptions;
const params: LsxApiParams = {
pagePath,
offset,
limit,
options: apiOptions,
};
try {
const res = await axios.get<LsxApiResponseData>(endpoint, { params });

解決策

express-validation でクエリパラメータに指定された文字列を Number に変換する
https://express-validator.github.io/docs/api/validation-chain/#toint

query('options')
.optional()
.customSanitizer((options) => {
Expand Down
Loading