-
Notifications
You must be signed in to change notification settings - Fork 220
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
Conversation
|
query('offset').optional().isInt(), | ||
query('limit').optional().isInt(), | ||
query('offset').optional().isInt().toInt(), | ||
query('limit').optional().isInt().toInt(), |
There was a problem hiding this comment.
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
に入る。
growi/packages/remark-lsx/src/client/stores/lsx/lsx.ts
Lines 43 to 56 in 8217a12
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
Task