fix: improve unbookmark url handling
This commit is contained in:
@@ -1,7 +1,7 @@
|
||||
/**
|
||||
* Extract tweet ID from a Twitter/X URL or return the input unchanged if it's already an ID.
|
||||
*/
|
||||
const TWEET_URL_REGEX = /(?:twitter\.com|x\.com)\/\w+\/status\/(\d+)/;
|
||||
const TWEET_URL_REGEX = /(?:twitter\.com|x\.com)\/(?:\w+\/status|i\/web\/status)\/(\d+)/i;
|
||||
|
||||
export function extractTweetId(input: string): string {
|
||||
// If it's a URL, extract the tweet ID
|
||||
|
||||
@@ -16,15 +16,15 @@ export function withBookmarks<TBase extends AbstractConstructor<TwitterClientBas
|
||||
}
|
||||
|
||||
async unbookmark(tweetId: string): Promise<BookmarkMutationResult> {
|
||||
// TODO: verify if DeleteBookmark requires client user ID or additional payload fields; add ensureClientUserId() if needed (needs live API test).
|
||||
const variables = { tweet_id: tweetId };
|
||||
let queryId = await this.getQueryId('DeleteBookmark');
|
||||
let urlWithOperation = `${TWITTER_API_BASE}/${queryId}/DeleteBookmark`;
|
||||
|
||||
const buildBody = () => JSON.stringify({ variables, queryId });
|
||||
const buildHeaders = () => ({ ...this.getHeaders(), referer: `https://x.com/i/status/${tweetId}` });
|
||||
let body = buildBody();
|
||||
|
||||
const headers = { ...this.getHeaders(), referer: `https://x.com/i/status/${tweetId}` };
|
||||
|
||||
const parseResponse = async (response: Response): Promise<BookmarkMutationResult> => {
|
||||
if (!response.ok) {
|
||||
const text = await response.text();
|
||||
@@ -42,7 +42,7 @@ export function withBookmarks<TBase extends AbstractConstructor<TwitterClientBas
|
||||
try {
|
||||
let response = await this.fetchWithTimeout(urlWithOperation, {
|
||||
method: 'POST',
|
||||
headers,
|
||||
headers: buildHeaders(),
|
||||
body,
|
||||
});
|
||||
|
||||
@@ -54,14 +54,14 @@ export function withBookmarks<TBase extends AbstractConstructor<TwitterClientBas
|
||||
|
||||
response = await this.fetchWithTimeout(urlWithOperation, {
|
||||
method: 'POST',
|
||||
headers,
|
||||
headers: buildHeaders(),
|
||||
body,
|
||||
});
|
||||
|
||||
if (response.status === 404) {
|
||||
const retry = await this.fetchWithTimeout(TWITTER_GRAPHQL_POST_URL, {
|
||||
method: 'POST',
|
||||
headers,
|
||||
headers: buildHeaders(),
|
||||
body,
|
||||
});
|
||||
|
||||
|
||||
Reference in New Issue
Block a user