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: biliNFT #696

Merged
merged 4 commits into from
Dec 17, 2024
Merged
Show file tree
Hide file tree
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
11 changes: 1 addition & 10 deletions __tests__/mediafetch/biliNFT.test.ts
Original file line number Diff line number Diff line change
@@ -1,32 +1,23 @@
import {
biliNFTVideoFetch,
biliNFTRedeemFetch,
} from '../../src/utils/mediafetch/biliNFTNew';

test.only('dummy fetch', () => {
expect('dummy').toBe('dummy');
});

// HACK: ghactions cant connect to biliNFT for some reasons
} from '../../src/utils/mediafetch/biliNFT';

test('biliNFT', async () => {
const content = await biliNFTVideoFetch({
act_id: '161',
lottery_id: '75',
index: '夜间魅影 小可',
});
// console.log(content);
expect(content).not.toBeNull();
const content2 = await biliNFTVideoFetch({
act_id: '161',
lottery_id: '75',
index: 1,
});
// console.log(content);
expect(content2).not.toBeNull();
const content3 = await biliNFTRedeemFetch({
act_id: '101926',
lottery_id: '101927',
index: '小山重叠金明灭',
});
// console.log(content);
Expand Down
28 changes: 28 additions & 0 deletions __tests__/mediafetch/biliNFTNew.test.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,28 @@
import {
biliNFTVideoFetch,
biliNFTRedeemFetch,
} from '../../src/utils/mediafetch/biliNFTNew';

test('biliNFT', async () => {
const content = await biliNFTVideoFetch({
act_id: '161',
lottery_id: '75',
index: '夜间魅影 小可',
});
// console.log(content);
expect(content).not.toBeNull();
const content2 = await biliNFTVideoFetch({
act_id: '161',
lottery_id: '75',
index: 1,
});
// console.log(content);
expect(content2).not.toBeNull();
const content3 = await biliNFTRedeemFetch({
act_id: '101926',
lottery_id: '101927',
index: '小山重叠金明灭',
});
// console.log(content);
expect(content3).not.toBeNull();
});
14 changes: 7 additions & 7 deletions package.json
Original file line number Diff line number Diff line change
Expand Up @@ -40,14 +40,14 @@
"@react-native/gradle-plugin": "^0.76.5",
"@react-native/metro-config": "^0.76.5",
"@react-native/typescript-config": "0.76.5",
"@react-navigation/drawer": "^7.1.0",
"@react-navigation/drawer": "^7.1.1",
"@react-navigation/native": "^7.0.14",
"@react-navigation/native-stack": "^7.2.0",
"@revenuecat/purchases-js": "^0.14.0",
"@sentry/react-native": "^6.4.0",
"@sharcoux/slider": "8.0.6",
"@shopify/flash-list": "^1.7.2",
"@shopify/react-native-skia": "1.7.2",
"@shopify/react-native-skia": "1.7.5",
"axios": "^1.7.9",
"base-64": "^1.0.0",
"base64-js": "^1.5.1",
Expand All @@ -61,7 +61,7 @@
"deepmerge": "^4.3.1",
"dropbox": "git+https://[email protected]/lovegaoshi/dropbox-sdk-js.git",
"event-target-polyfill": "^0.0.4",
"expo": "^52.0.18",
"expo": "^52.0.19",
"expo-auth-session": "~6.0.1",
"expo-clipboard": "~7.0.0",
"expo-crypto": "~14.0.1",
Expand All @@ -86,7 +86,7 @@
"postinstall-postinstall": "^2.1.0",
"qs": "^6.13.1",
"react": "18.3.1",
"react-i18next": "^15.1.4",
"react-i18next": "^15.2.0",
"react-native": "^0.76.5",
"react-native-app-auth": "^8.0.1",
"react-native-background-timer": "git+https://github.com/lovegaoshi/react-native-background-timer.git",
Expand Down Expand Up @@ -144,14 +144,14 @@
"@types/lodash": "^4.17.13",
"@types/md5": "^2.3.5",
"@types/node": "^22.10.2",
"@types/react": "~18.3.16",
"@types/react": "~18.3.17",
"@types/react-native": "^0.73.0",
"@types/react-native-background-timer": "^2.0.2",
"@types/react-native-share-menu": "^5.0.5",
"@types/react-test-renderer": "^19.0.0",
"@types/uuid": "^10.0.0",
"@typescript-eslint/eslint-plugin": "^8.18.0",
"@typescript-eslint/parser": "^8.18.0",
"@typescript-eslint/eslint-plugin": "^8.18.1",
"@typescript-eslint/parser": "^8.18.1",
"@welldone-software/why-did-you-render": "^8.0.3",
"argparse": "^2.0.1",
"babel-jest": "^29.7.0",
Expand Down
5 changes: 4 additions & 1 deletion src/utils/Utils.ts
Original file line number Diff line number Diff line change
Expand Up @@ -199,7 +199,7 @@ export const getExt = (url: string) => {

interface ExecWhenTrue {
loopCheck: () => Promise<boolean>;
executeFn: () => void;
executeFn: () => unknown;
wait?: number;
loopGuard?: number;
funcName?: string;
Expand All @@ -223,4 +223,7 @@ export const execWhenTrue = async ({
}
}
executeFn();
logger.debug(
`[ExecWhenTrue] function ${funcName} executed after ${loops} try.`,
);
};
35 changes: 21 additions & 14 deletions src/utils/mediafetch/biliNFT.ts
Original file line number Diff line number Diff line change
@@ -1,40 +1,47 @@
/* eslint-disable @typescript-eslint/no-explicit-any */
import bfetch from '@utils/BiliFetch';

// see https://github.com/lovegaoshi/biliNFT
// see https://github.com/SocialSisterYi/bilibili-API-collect/issues/1155

const API =
'https://api.bilibili.com/x/vas/dlc_act/act/item/list?act_id={act_id}';
const API = 'https://api.bilibili.com/x/vas/dlc_act/asset_bag?act_id={act_id}';

interface Props {
act_id: string;
index: number | string;
resolver?: (json: any) => string;
resolver?: (v: any) => string;
filter?: (v: any) => any;
}

const biliNFTFetch = async ({
act_id,
index,
resolver = (json: any) => json.card_img,
resolver = (json: any) => json.card_item.card_img,
filter = (json: any) =>
json.item_list.filter((item: any) => item.card_item.card_name === index)[0],
}: Props) => {
const res = await bfetch(API.replace('{act_id}', act_id));
const json = await res.json();
if (typeof index === 'string') {
return resolver(
json.data.item_list.filter(
(item: { card_item: { card_name: string } }) =>
item.card_item.card_name === index,
)[0].card_item,
);
return resolver(filter(json.data));
}
return resolver(json.data.item_list[index].card_item);
return resolver(json.data.item_list[index]);
};

const biliNFTVideoFetch = ({ act_id, index }: Props) =>
biliNFTFetch({
act_id,
index,
resolver: (json: any) => json.video_list[0],
resolver: v => v.card_item.video_list[0],
});

export { biliNFTVideoFetch };
const biliNFTRedeemFetch = ({ act_id, index }: Props) =>
biliNFTFetch({
act_id,
index,
resolver: v =>
v.card_item.card_type_info.content.animation.animation_video_urls[0],
filter: v =>
v.collect_list.filter((item: any) => item.redeem_item_name === index)[0],
});

export { biliNFTVideoFetch, biliNFTRedeemFetch };
Loading
Loading