feat(history): Load additional watch history pages (#1055)

This commit is contained in:
Dave Nicolson
2025-10-12 15:00:35 +02:00
committed by GitHub
parent f7099ab42e
commit 6c127199ba

View File

@@ -31,31 +31,50 @@ export default class History extends Feed<IBrowseResponse> {
/** /**
* Removes a video from watch history. * Removes a video from watch history.
*/ */
async removeVideo(video_id: string): Promise<boolean> { async removeVideo(video_id: string, pages_to_load: number = 1): Promise<boolean> {
let feedbackToken; let pagesToLoad = pages_to_load;
// eslint-disable-next-line @typescript-eslint/no-this-alias
let currentHistory: History = this;
for (const section of this.sections) { while (pagesToLoad > 0) {
for (const content of section.contents) { let feedbackToken;
const video = content as Video;
if (video.video_id === video_id && video.menu) { for (const section of currentHistory.sections) {
feedbackToken = video.menu.top_level_buttons[0].as(Button).endpoint.payload.feedbackToken; for (const content of section.contents) {
const video = content as Video;
if (video.video_id === video_id && video.menu) {
feedbackToken = video.menu.top_level_buttons[0].as(Button).endpoint.payload.feedbackToken;
break;
}
}
if (feedbackToken) {
break; break;
} }
} }
if (feedbackToken) {
const body = { feedbackTokens: [ feedbackToken ] };
const response = await this.actions.execute('/feedback', body);
const data = response.data;
if (!data.feedbackResponses[0].isProcessed) {
throw new Error('Failed to remove video from watch history');
}
return true;
}
if (--pagesToLoad > 0) {
try {
currentHistory = await currentHistory.getContinuation();
} catch {
throw new Error('Unable to find video in watch history');
}
} else {
throw new Error('Unable to find video in watch history');
}
} }
if (!feedbackToken) { return false;
throw new Error('Failed to get feedback token');
}
const body = { feedbackTokens: [ feedbackToken ] };
const response = await this.actions.execute('/feedback', body);
const data = response.data;
if (!data.feedbackResponses[0].isProcessed) {
throw new Error('Failed to remove video from watch history');
}
return true;
} }
} }