Skip to content

Commit a2aebb4

Browse files
committed
allow overriding the default placeholder.json
1 parent 2243de6 commit a2aebb4

File tree

1 file changed

+9
-3
lines changed
  • twitter-openapi-typescript/src

1 file changed

+9
-3
lines changed

twitter-openapi-typescript/src/api.ts

Lines changed: 9 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -22,6 +22,10 @@ export type TwitterOpenApiCookie = {
2222
value: string;
2323
};
2424

25+
export type TwitterOpenApiClientOptions = {
26+
flag?: DefaultFlag;
27+
};
28+
2529
export class TwitterOpenApi {
2630
static hash = 'd5ccc25869b68cbb39c68fa81a1fa77967a667da';
2731
static url = `https://raw.githubusercontent.com/fa0311/twitter-openapi/${this.hash}/src/config/placeholder.json`;
@@ -90,7 +94,7 @@ export class TwitterOpenApi {
9094
return context;
9195
}
9296

93-
async getClient(): Promise<TwitterOpenApiClient> {
97+
async getClient(options?: TwitterOpenApiClientOptions): Promise<TwitterOpenApiClient> {
9498
const cookies: TwitterOpenApiCookie[] = await this.getGuestSession();
9599
const config: i.ConfigurationParameters = {
96100
fetchApi: this.fetchApi,
@@ -106,8 +110,10 @@ export class TwitterOpenApi {
106110
},
107111
accessToken: TwitterOpenApi.bearer,
108112
};
109-
const flag = this.fetchApi(TwitterOpenApi.url, { method: 'GET' }).then((res) => res.json()) as Promise<DefaultFlag>;
110-
return new TwitterOpenApiClient(new i.Configuration(config), await flag);
113+
const flag =
114+
options.flag ||
115+
((await this.fetchApi(TwitterOpenApi.url, { method: 'GET' }).then((res) => res.json())) as DefaultFlag);
116+
return new TwitterOpenApiClient(new i.Configuration(config), flag);
111117
}
112118

113119
async getClientFromCookies(ct0: string, authToken: string): Promise<TwitterOpenApiClient> {

0 commit comments

Comments
 (0)