Skip to content

Commit

Permalink
Merge pull request #1366 from DIYgod/master
Browse files Browse the repository at this point in the history
[pull] master from diygod:master
  • Loading branch information
pull[bot] authored Apr 24, 2024
2 parents 9c6042a + aba18ac commit 7d4e332
Show file tree
Hide file tree
Showing 10 changed files with 225 additions and 45 deletions.
2 changes: 1 addition & 1 deletion lib/routes/douyin/live.ts
Original file line number Diff line number Diff line change
Expand Up @@ -46,7 +46,7 @@ async function handler(ctx) {
await page.setRequestInterception(true);

page.on('request', (request) => {
request.resourceType() === 'document' || request.resourceType() === 'script' || request.resourceType() === 'xhr' ? request.continue() : request.abort();
request.resourceType() === 'document' || request.resourceType() === 'stylesheet' || request.resourceType() === 'script' || request.resourceType() === 'xhr' ? request.continue() : request.abort();
});
page.on('response', async (response) => {
const request = response.request();
Expand Down
67 changes: 67 additions & 0 deletions lib/routes/ecnu/jwc.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,67 @@
import { Route } from '@/types';
import cache from '@/utils/cache';
import got from '@/utils/got';
import { load } from 'cheerio';
import { parseDate } from '@/utils/parse-date';
import timezone from '@/utils/timezone';

const type = (filename) => filename.split('.').pop();

export const route: Route = {
path: '/jwc',
categories: ['university'],
example: '/ecnu/jwc',
radar: [
{
source: ['www.jwc.ecnu.edu.cn', 'www.ecnu.edu.cn'],
target: '/tzgg',
},
],
name: '教务处通知',
maintainers: ['markbang'],
handler: async () => {
const baseUrl = 'http://www.jwc.ecnu.edu.cn/';

const response = await got(`${baseUrl}tzggwwxsgg/list.htm`);
const $ = load(response.data);
const links = $('.col_news_con ul.news_list > li')
.map((_, el) => ({
pubDate: timezone(parseDate($(el).find('.news_date').text()), 8),
link: new URL($(el).find('a').attr('href'), baseUrl).toString(),
title: $(el).find('a').text(),
}))
.get();
const items = await Promise.all(
links.map((item) =>
cache.tryGet(item.link, async () => {
if (type(item.link) === 'htm') {
try {
const { data } = await got(item.link, {
https: {
rejectUnauthorized: false,
},
});
const $ = load(data);
item.description = $('div.article')?.html()?.replaceAll('src="/', `src="${baseUrl}/`)?.replaceAll('href="/', `href="${baseUrl}/`)?.trim();
return item;
} catch {
// intranet
item.description = '请进行统一身份认证之后再访问';
return item;
}
} else {
// file to download
item.description = '点击认证后访问内容';
return item;
}
})
)
);

return {
title: '教务处通知',
link: 'http://www.jwc.ecnu.edu.cn/tzggwwxsgg/list.htm',
item: items,
};
},
};
2 changes: 1 addition & 1 deletion lib/routes/ecnu/namespace.ts
Original file line number Diff line number Diff line change
Expand Up @@ -2,5 +2,5 @@ import type { Namespace } from '@/types';

export const namespace: Namespace = {
name: 'East China Normal University 华东师范大学',
url: 'acm.ecnu.edu.cn',
url: 'ecnu.edu.cn',
};
92 changes: 92 additions & 0 deletions lib/routes/steam/appcommunityfeed.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,92 @@
import { Route } from '@/types';
import { getCurrentPath } from '@/utils/helpers';
const __dirname = getCurrentPath(import.meta.url);

import ofetch from '@/utils/ofetch';
import { art } from '@/utils/render';
import path from 'node:path';

const workshopFileTypes = {
0: 'Community',
1: 'Microtransaction',
2: 'Collection',
3: 'Art',
4: 'Video',
5: 'Screenshot',
6: 'Game',
7: 'Software',
8: 'Concept',
9: 'WebGuide',
10: 'IntegratedGuide',
11: 'Merch',
12: 'ControllerBinding',
13: 'SteamworksAccessInvite',
14: 'SteamVideo',
15: 'GameManagedItem',
};

export const route: Route = {
path: '/appcommunityfeed/:appid/:routeParams?',
categories: ['game'],
example: '/steam/appcommunityfeed/730',
parameters: {
appid: 'Steam appid, can be found on the community hub page or store page URL.',
routeParams: 'Query parameters.',
},
radar: [
{
title: 'Community Hub',
source: ['steamcommunity.com/app/:appid'],
target: '/appcommunityfeed/:appid',
},
{
title: 'Community Hub',
source: ['store.steampowered.com/app/:appid/*/'],
target: '/appcommunityfeed/:appid',
},
],
description: `Query Parameters:
| Name | Type | Description |
| ---------------------- | ------ | ----------------------- |
| p | string | p |
| rgSections[] | string | rgSections |
| filterLanguage | string | Filter Language |
| languageTag | string | Language Tag |
| nMaxInappropriateScore | string | Max Inappropriate Score |
Example:
- \`/appcommunityfeed/730/p=1&rgSections[]=2&rgSections[]=4&filterLanguage=english&languageTag=english&nMaxInappropriateScore=1\` for CS2 Screenshot and Artwork contents.
- \`/appcommunityfeed/730/rgSections[]=6\` for CS2 Workshop contents only.
- \`/appcommunityfeed/570/rgSections[]=3&rgSections[]=9\` for Dota2 Video and Guides contents.
:::tip
It can also access community hub contents that require a logged-in account.
:::
`,
name: 'Steam Community Hub Feeds',
maintainers: ['NyaaaDoge'],

handler: async (ctx) => {
const { appid = 730, routeParams } = ctx.req.param();

const baseUrl = 'https://steamcommunity.com';
const apiUrl = `${baseUrl}/library/appcommunityfeed/${appid}${routeParams ? `?${routeParams}` : ''}`;
const response = await ofetch(apiUrl);

return {
title: `${appid} Steam Community Hub`,
link: `https://steamcommunity.com/app/${appid}`,
item: response.hub.map((item) => ({
title: item.title === '' ? workshopFileTypes[item.type] : item.title,
link: `https://steamcommunity.com/sharedfiles/filedetails/?id=${item.published_file_id}`,
description: art(path.join(__dirname, 'templates/appcommunityfeed-description.art'), {
image: item.full_image_url,
description: item.description,
}),
author: item.creator.name,
category: workshopFileTypes[item.type],
})),
};
},
};
4 changes: 4 additions & 0 deletions lib/routes/steam/templates/appcommunityfeed-description.art
Original file line number Diff line number Diff line change
@@ -0,0 +1,4 @@
{{ if image }}
<img src="{{ image }}"/>
{{ /if }}
<p>{{ description }}</p>
30 changes: 30 additions & 0 deletions lib/routes/twitter/api/web-api/constants.ts
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,7 @@ const graphQLEndpointsPlain = [
'/graphql/tD8zKvQzwY3kdx5yz6YmOw/UserByRestId',
'/graphql/flaR-PUMshxFWZWPNpq4zA/SearchTimeline',
'/graphql/TOTgqavWmxywKv5IbMMK1w/ListLatestTweetsTimeline',
'/graphql/zJvfJs3gSbrVhC0MKjt_OQ/TweetDetail',
];

const gqlMap = Object.fromEntries(graphQLEndpointsPlain.map((endpoint) => [endpoint.split('/')[3].replace(/V2$|Query$|QueryV2$/, ''), endpoint]));
Expand Down Expand Up @@ -49,6 +50,34 @@ const gqlFeatureFeed = {
longform_notetweets_inline_media_enabled: true,
responsive_web_enhance_cards_enabled: false,
};

const TweetDetailFeatures = {
rweb_tipjar_consumption_enabled: true,
responsive_web_graphql_exclude_directive_enabled: true,
verified_phone_label_enabled: false,
creator_subscriptions_tweet_preview_api_enabled: true,
responsive_web_graphql_timeline_navigation_enabled: true,
responsive_web_graphql_skip_user_profile_image_extensions_enabled: false,
communities_web_enable_tweet_community_results_fetch: true,
c9s_tweet_anatomy_moderator_badge_enabled: true,
articles_preview_enabled: false,
tweetypie_unmention_optimization_enabled: true,
responsive_web_edit_tweet_api_enabled: true,
graphql_is_translatable_rweb_tweet_is_translatable_enabled: true,
view_counts_everywhere_api_enabled: true,
longform_notetweets_consumption_enabled: true,
responsive_web_twitter_article_tweet_consumption_enabled: true,
tweet_awards_web_tipping_enabled: false,
creator_subscriptions_quote_tweet_preview_enabled: false,
freedom_of_speech_not_reach_fetch_enabled: true,
standardized_nudges_misinfo: true,
tweet_with_visibility_results_prefer_gql_limited_actions_policy_enabled: true,
tweet_with_visibility_results_prefer_gql_media_interstitial_enabled: true,
rweb_video_timestamps_enabled: true,
longform_notetweets_rich_text_read_enabled: true,
longform_notetweets_inline_media_enabled: true,
responsive_web_enhance_cards_enabled: false,
};
const gqlFeatures = {
UserByScreenName: gqlFeatureUser,
UserByRestId: gqlFeatureUser,
Expand All @@ -58,6 +87,7 @@ const gqlFeatures = {
SearchTimeline: gqlFeatureFeed,
ListLatestTweetsTimeline: gqlFeatureFeed,
HomeTimeline: gqlFeatureFeed,
TweetDetail: TweetDetailFeatures,
};

const timelineParams = {
Expand Down
2 changes: 1 addition & 1 deletion lib/routes/twitter/api/web-api/utils.ts
Original file line number Diff line number Diff line change
Expand Up @@ -55,7 +55,6 @@ export const paginationTweets = async (endpoint: string, userId: number | undefi
}),
features: JSON.stringify(gqlFeatures[endpoint]),
});

let instructions;
if (path) {
instructions = data;
Expand Down Expand Up @@ -121,5 +120,6 @@ export function gatherLegacyFromData(entries: any[], filterNested?: string[], us
}
}
}

return tweets;
}
11 changes: 10 additions & 1 deletion lib/routes/twitter/tweet.ts
Original file line number Diff line number Diff line change
Expand Up @@ -39,7 +39,16 @@ async function handler(ctx) {
const status = ctx.req.param('status');
const routeParams = new URLSearchParams(ctx.req.param('original'));
const original = fallback(undefined, queryToBoolean(routeParams.get('original')), false);
const params = { focalTweetId: status };
const params = {
focalTweetId: status,
with_rux_injections: false,
includePromotedContent: true,
withCommunity: true,
withQuickPromoteEligibilityTweetFields: true,
withBirdwatchNotes: true,
withVoice: true,
withV2Timeline: true,
};
await api.init();
const userInfo = await api.getUser(id);
const data = await api.getUserTweet(id, params);
Expand Down
4 changes: 1 addition & 3 deletions package.json
Original file line number Diff line number Diff line change
Expand Up @@ -131,11 +131,10 @@
"@types/aes-js": "3.1.4",
"@types/babel__preset-env": "7.9.6",
"@types/crypto-js": "4.2.2",
"@types/eslint": "8.56.7",
"@types/eslint": "8.56.10",
"@types/eslint-config-prettier": "6.11.3",
"@types/etag": "1.8.3",
"@types/fs-extra": "11.0.4",
"@types/git-rev-sync": "2.0.2",
"@types/html-to-text": "9.0.4",
"@types/imapflow": "1.0.18",
"@types/js-beautify": "1.14.3",
Expand All @@ -147,7 +146,6 @@
"@types/markdown-it": "14.0.1",
"@types/module-alias": "2.0.4",
"@types/node": "20.12.7",
"@types/request-promise-native": "1.0.21",
"@types/sanitize-html": "2.11.0",
"@types/supertest": "6.0.2",
"@types/tiny-async-pool": "2.0.3",
Expand Down
Loading

0 comments on commit 7d4e332

Please sign in to comment.