Skip to content

Commit

Permalink
feat(route): ktown4u (#17182)
Browse files Browse the repository at this point in the history
* add ktown4u route

* delete source

* fix some feedback

* Apply suggestions from code review

---------
  • Loading branch information
JamesWDGu authored Oct 18, 2024
1 parent ff76aa7 commit 6ac8649
Show file tree
Hide file tree
Showing 2 changed files with 67 additions and 0 deletions.
61 changes: 61 additions & 0 deletions lib/routes/ktown4u/artist-brandlist.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,61 @@
import { Route } from '@/types';
import ofetch from '@/utils/ofetch';
import { parseDate } from '@/utils/parse-date';

export const route: Route = {
path: '/artistBrandlist/:grpNo/:grpNo2?',
categories: ['shopping'],
example: '/ktown4u/artistBrandlist/234590/1723449',
parameters: { grpNo: 'artist id (Get in url)', grpNo2: 'product category id (Get in url), empty for all categories' },
features: {
requireConfig: false,
requirePuppeteer: false,
antiCrawler: false,
supportBT: false,
supportPodcast: false,
supportScihub: false,
},
radar: [
{
source: [],
target: '/artistBrandlist/:grpNo/:grpNo2',
},
],
name: 'Get the products on sale',
maintainers: ['JamesWDGu'],
handler: async (ctx) => {
const { grpNo, grpNo2 = '' } = ctx.req.param();
const data = await ofetch(`https://cn.ktown4u.com/selectArtistBrandList?cateGrpNo=${grpNo2}&currentPage=1&goodsSearch=newgoods&grpNo=${grpNo}&searchType=ARTIST`, {
method: 'POST',
headers: {
accept: 'application/json, text/plain, */*',
'accept-language': 'en,zh-CN;q=0.9,zh;q=0.8',
},
parseResponse: JSON.parse,
});
const items = data.map((item) => ({
title: item.GOODS_NM,
url: item.IMG_PATH,
link: `https://cn.ktown4u.com/iteminfo?goods_no=${item.GOODS_NO}`,
description: desc(item),
pubDate: parseDate(item.RELEASE_DT),
}));

return {
title: rssTitle(data),
link: `https://cn.ktown4u.com/artistBrandlist?grp_no=${grpNo}&grp_no2=${grpNo2}`,
item: items,
};
},
};

const rssTitle = (data) => `ktown4u ${data[0].GRP_NM}`;

const desc = (item) => {
const saleState = item.SALE_YN === 'N' ? '【售罄】' : '';
let price = `${item.CURR_F_CD}${item.DISP_PRICE}`;
if (item.DISP_PRICE !== item.DISP_DC_PRICE) {
price = `${item.CURR_F_CD}${item.DISP_DC_PRICE} / 原价:${price}`;
}
return `${saleState} ${price} <br> <img src=${item.IMG_PATH}> <br> ${item.GOODS_NM}`;
};
6 changes: 6 additions & 0 deletions lib/routes/ktown4u/namespace.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,6 @@
import type { Namespace } from '@/types';

export const namespace: Namespace = {
name: 'Ktown4u',
url: 'ktown4u.com',
};

0 comments on commit 6ac8649

Please sign in to comment.