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(route): set api key via route query parameter #18326

Open
wants to merge 1 commit into
base: master
Choose a base branch
from
Open
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
7 changes: 4 additions & 3 deletions lib/routes/instructables/projects.ts
Original file line number Diff line number Diff line change
Expand Up @@ -30,10 +30,11 @@ export const route: Route = {
};

async function handler(ctx) {
const category = ctx.req.param('category') ?? 'all';
const { category = 'all' } = ctx.req.param();
const apiKey = ctx.req.query('typesenseApiKey');
Copy link
Collaborator

Choose a reason for hiding this comment

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

The value is fixed. Either hardcode it or extract it from #js-page-context instead of manual input.

Copy link
Contributor Author

Choose a reason for hiding this comment

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

The api key can be changed at some point then failed this route. That's why I made this patch.

Copy link
Collaborator

Choose a reason for hiding this comment

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

That's why I said either hardcode it or extract it from #js-page-context.

const limit = ctx.req.query('limit') ? Number.parseInt(ctx.req.query('limit'), 10) : 50;

const siteDomain = 'www.instructables.com';
const apiKey = 'NU5CdGwyRDdMVnVmM3l4cWNqQzFSVzJNZU5jaUxFU3dGK3J2L203MkVmVT02ZWFYeyJleGNsdWRlX2ZpZWxkcyI6WyJvdXRfb2YiLCJzZWFyY2hfdGltZV9tcyIsInN0ZXBCb2R5Il0sInBlcl9wYWdlIjo1MH0=';

let pathPrefix, projectFilter;
if (category === 'all') {
Expand All @@ -59,7 +60,7 @@ async function handler(ctx) {
q: '*',
query_by: 'title,stepBody,screenName',
page: 1,
per_page: 50,
per_page: limit,
sort_by: 'publishDate:desc',
include_fields: 'title,urlString,coverImageUrl,screenName,publishDate,favorites,views,primaryClassification,featureFlag,prizeLevel,IMadeItCount',
filter_by: `featureFlag:=true${projectFilter}`,
Expand Down