twitter-openapi-typescript 0.0.31 → 0.0.33
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/README.md +19 -18
- package/cookies.json +476 -0
- package/dist/src/api.d.ts +7 -31
- package/dist/src/api.d.ts.map +1 -1
- package/dist/src/api.js +63 -38
- package/dist/src/api.js.map +1 -1
- package/dist/src/apis/tweetApi.d.ts.map +1 -1
- package/dist/src/apis/tweetApi.js +26 -1
- package/dist/src/apis/tweetApi.js.map +1 -1
- package/dist/src/utils/api.d.ts +2 -0
- package/dist/src/utils/api.d.ts.map +1 -1
- package/dist/src/utils/api.js +62 -34
- package/dist/src/utils/api.js.map +1 -1
- package/package.json +2 -3
- package/src/api.ts +29 -27
- package/src/apis/tweetApi.ts +10 -2
- package/src/utils/api.ts +47 -23
- package/test/init.ts +12 -8
- package/a.ts +0 -8
package/src/utils/api.ts
CHANGED
|
@@ -29,6 +29,8 @@ export const instructionToEntry = (item: i.InstructionUnion[]): i.TimelineAddEnt
|
|
|
29
29
|
return item.flatMap((e) => {
|
|
30
30
|
if (e.type == i.InstructionType.TimelineAddEntries) {
|
|
31
31
|
return (e as i.TimelineAddEntries).entries;
|
|
32
|
+
} else if (e.type == i.InstructionType.TimelineAddToModule) {
|
|
33
|
+
return [];
|
|
32
34
|
} else if (e.type == i.InstructionType.TimelineReplaceEntry) {
|
|
33
35
|
return [(e as i.TimelineReplaceEntry).entry];
|
|
34
36
|
}
|
|
@@ -36,6 +38,23 @@ export const instructionToEntry = (item: i.InstructionUnion[]): i.TimelineAddEnt
|
|
|
36
38
|
});
|
|
37
39
|
};
|
|
38
40
|
|
|
41
|
+
export const instructionConverter = (item: i.InstructionUnion[]): TweetApiUtilsData[] => {
|
|
42
|
+
return item
|
|
43
|
+
.flatMap((e) => {
|
|
44
|
+
if (e.type == i.InstructionType.TimelineAddEntries) {
|
|
45
|
+
return [];
|
|
46
|
+
} else if (e.type == i.InstructionType.TimelineAddToModule) {
|
|
47
|
+
const item = (e as i.TimelineAddToModule).moduleItems ?? [];
|
|
48
|
+
return moduleConverter(item);
|
|
49
|
+
} else if (e.type == i.InstructionType.TimelineReplaceEntry) {
|
|
50
|
+
return [];
|
|
51
|
+
}
|
|
52
|
+
return [];
|
|
53
|
+
})
|
|
54
|
+
.filter((e): e is NonNullable<typeof e> => e != undefined)
|
|
55
|
+
.flat();
|
|
56
|
+
};
|
|
57
|
+
|
|
39
58
|
export const tweetEntriesConverter = (item: i.TimelineAddEntry[]): TweetApiUtilsData[] => {
|
|
40
59
|
return item
|
|
41
60
|
.map((e) => {
|
|
@@ -51,29 +70,7 @@ export const tweetEntriesConverter = (item: i.TimelineAddEntry[]): TweetApiUtils
|
|
|
51
70
|
];
|
|
52
71
|
} else if (e.content.entryType == i.ContentEntryType.TimelineTimelineModule) {
|
|
53
72
|
const item = (e.content as i.TimelineTimelineModule).items ?? [];
|
|
54
|
-
|
|
55
|
-
.filter((e) => e.item.itemContent.itemType == i.ContentItemType.TimelineTweet)
|
|
56
|
-
.map((e) => e.item.itemContent as i.TimelineTweet);
|
|
57
|
-
if (timelineList.length == 0) return undefined;
|
|
58
|
-
|
|
59
|
-
const displayType = (e.content as i.TimelineTimelineModule).displayType;
|
|
60
|
-
if (displayType == i.DisplayType.VerticalGrid) {
|
|
61
|
-
return timelineList.map((e) =>
|
|
62
|
-
buildTweetApiUtils({
|
|
63
|
-
result: e.tweetResults,
|
|
64
|
-
promotedMetadata: e.promotedMetadata,
|
|
65
|
-
}),
|
|
66
|
-
);
|
|
67
|
-
} else {
|
|
68
|
-
const timeline = timelineList[0];
|
|
69
|
-
return [
|
|
70
|
-
buildTweetApiUtils({
|
|
71
|
-
result: timeline.tweetResults,
|
|
72
|
-
promotedMetadata: timeline.promotedMetadata,
|
|
73
|
-
reply: timelineList.slice(1),
|
|
74
|
-
}),
|
|
75
|
-
];
|
|
76
|
-
}
|
|
73
|
+
return moduleConverter(item);
|
|
77
74
|
}
|
|
78
75
|
})
|
|
79
76
|
.filter((e): e is NonNullable<typeof e> => e != undefined)
|
|
@@ -81,6 +78,33 @@ export const tweetEntriesConverter = (item: i.TimelineAddEntry[]): TweetApiUtils
|
|
|
81
78
|
.flat();
|
|
82
79
|
};
|
|
83
80
|
|
|
81
|
+
export const moduleConverter = (item: i.ModuleItem[]): TweetApiUtilsData[] => {
|
|
82
|
+
const timelineList = item
|
|
83
|
+
.filter((e) => e.item.itemContent.itemType == i.ContentItemType.TimelineTweet)
|
|
84
|
+
.map((e) => e.item.itemContent as i.TimelineTweet);
|
|
85
|
+
if (timelineList.length == 0) return [];
|
|
86
|
+
|
|
87
|
+
if (timelineList[0].tweetDisplayType == i.TimelineTweetTweetDisplayTypeEnum.MediaGrid) {
|
|
88
|
+
return timelineList
|
|
89
|
+
.map((e) =>
|
|
90
|
+
buildTweetApiUtils({
|
|
91
|
+
result: e.tweetResults,
|
|
92
|
+
promotedMetadata: e.promotedMetadata,
|
|
93
|
+
}),
|
|
94
|
+
)
|
|
95
|
+
.filter((e): e is NonNullable<typeof e> => e != undefined);
|
|
96
|
+
} else {
|
|
97
|
+
const timeline = timelineList[0];
|
|
98
|
+
return [
|
|
99
|
+
buildTweetApiUtils({
|
|
100
|
+
result: timeline.tweetResults,
|
|
101
|
+
promotedMetadata: timeline.promotedMetadata,
|
|
102
|
+
reply: timelineList.slice(1),
|
|
103
|
+
}),
|
|
104
|
+
].filter((e): e is NonNullable<typeof e> => e != undefined);
|
|
105
|
+
}
|
|
106
|
+
};
|
|
107
|
+
|
|
84
108
|
type buildTweetApiUtilsArgs = {
|
|
85
109
|
result: i.ItemResult;
|
|
86
110
|
promotedMetadata?: any;
|
package/test/init.ts
CHANGED
|
@@ -1,11 +1,8 @@
|
|
|
1
1
|
import { TwitterOpenApi } from '@/api';
|
|
2
|
-
import
|
|
2
|
+
import { promises as fs } from 'fs';
|
|
3
3
|
import * as log4js from 'log4js';
|
|
4
4
|
|
|
5
|
-
dotenv.config();
|
|
6
5
|
|
|
7
|
-
const authToken = process.env.AUTH_TOKEN as string;
|
|
8
|
-
const CsrfToken = process.env.CSRF_TOKEN as string;
|
|
9
6
|
|
|
10
7
|
export const logger = log4js
|
|
11
8
|
.configure({
|
|
@@ -25,12 +22,19 @@ export const logger = log4js
|
|
|
25
22
|
})
|
|
26
23
|
.getLogger('Test');
|
|
27
24
|
|
|
25
|
+
export type Cookie = {
|
|
26
|
+
name: string;
|
|
27
|
+
domain: string;
|
|
28
|
+
value: string;
|
|
29
|
+
};
|
|
30
|
+
|
|
28
31
|
export const getClient = async () => {
|
|
29
32
|
const api = new TwitterOpenApi();
|
|
30
|
-
const
|
|
31
|
-
|
|
32
|
-
|
|
33
|
-
|
|
33
|
+
const data = await fs.readFile('cookies.json', 'utf-8');
|
|
34
|
+
const parsed = JSON.parse(data)
|
|
35
|
+
const cookies = parsed as Cookie[]
|
|
36
|
+
const json = Object.fromEntries(cookies.filter((e) => e.domain === '.twitter.com').map((e) => [e.name, e.value]));
|
|
37
|
+
const client = await api.getClientFromCookies(json);
|
|
34
38
|
return client;
|
|
35
39
|
};
|
|
36
40
|
export const getGuestClient = async () => {
|
package/a.ts
DELETED
|
@@ -1,8 +0,0 @@
|
|
|
1
|
-
import { TwitterOpenApi } from "@/api";
|
|
2
|
-
|
|
3
|
-
(async () => {
|
|
4
|
-
const api = new TwitterOpenApi();
|
|
5
|
-
const client = await api.getGuestClient();
|
|
6
|
-
const res = await client.getDefaultApi().getTweetResultByRestId({ tweetId: "1771078537694601545" });
|
|
7
|
-
console.log(res.data);
|
|
8
|
-
})()
|