Files
RSSHub/lib/routes/daily/utils.ts
T
238955b5fe fix(daily dev): fixed routes and added one new one (#18021)
* add squads

* style: auto format

* null check

* fix: add null checks for items

* changes

* trigger

* use params

* fix: add categories

---------

Co-authored-by: rjnishant530 <singhnisant530@gmail.com>
Co-authored-by: github-actions[bot] <41898282+github-actions[bot]@users.noreply.github.com>
2025-01-05 22:42:10 +08:00

68 lines
2.1 KiB
TypeScript

import { parseDate } from '@/utils/parse-date';
import ofetch from '@/utils/ofetch';
import cache from '@/utils/cache';
import { config } from '@/config';
import { art } from '@/utils/render';
import path from 'node:path';
import { getCurrentPath } from '@/utils/helpers';
import { DataItem } from '@/types';
const __dirname = getCurrentPath(import.meta.url);
export const baseUrl = 'https://app.daily.dev';
const gqlUrl = `https://api.daily.dev/graphql`;
export const variables = {
version: 54,
loggedIn: false,
};
export const getBuildId = () =>
cache.tryGet(
'daily:buildId',
async () => {
const response = await ofetch(`${baseUrl}/onboarding`);
const buildId = response.match(/"buildId":"(.*?)"/)[1];
return buildId;
},
config.cache.routeExpire,
false
);
export const getData = async (graphqlQuery, source = false) => {
const response = await ofetch(gqlUrl, {
method: 'POST',
body: graphqlQuery,
});
return source ? response.data.source : response.data.page.edges;
};
const render = (data) => art(path.join(__dirname, 'templates/posts.art'), data);
export const getList = (edges, innerSharedContent: boolean, dateSort: boolean) =>
edges.map(({ node }) => {
let link: string;
let title: string;
if (innerSharedContent && node.type === 'share') {
link = node.sharedPost.permalink;
title = node.sharedPost.title;
} else {
link = node.commentsPermalink ?? node.permalink;
title = node.title;
}
return {
id: node.id,
title,
link,
guid: node.permalink,
description: render({
image: node.image,
content: node.contentHtml?.replaceAll('\n', '<br>') ?? node.summary,
}),
author: node.author?.name,
itunes_item_image: node.image,
pubDate: dateSort ? parseDate(node.createdAt) : '',
upvotes: node.numUpvotes,
comments: node.numComments,
category: node.tags,
} as DataItem;
});