mirror of
https://github.com/streamyfin/streamyfin.git
synced 2025-08-20 18:37:18 +02:00
fix: use sdk util
This commit is contained in:
@@ -1,7 +1,6 @@
|
|||||||
import { Api } from "@jellyfin/sdk";
|
import { Api } from "@jellyfin/sdk";
|
||||||
import { BaseItemDto } from "@jellyfin/sdk/lib/generated-client/models";
|
import { BaseItemDto } from "@jellyfin/sdk/lib/generated-client/models";
|
||||||
import { AxiosError } from "axios";
|
import { getPlaystateApi } from "@jellyfin/sdk/lib/utils/api";
|
||||||
import { getAuthHeaders } from "../jellyfin";
|
|
||||||
|
|
||||||
interface MarkAsPlayedParams {
|
interface MarkAsPlayedParams {
|
||||||
api: Api | null | undefined;
|
api: Api | null | undefined;
|
||||||
@@ -12,7 +11,7 @@ interface MarkAsPlayedParams {
|
|||||||
/**
|
/**
|
||||||
* Marks a media item as played and updates its progress to completion.
|
* Marks a media item as played and updates its progress to completion.
|
||||||
*
|
*
|
||||||
* @param params - The parameters for marking an item as played
|
* @param params - The parameters for marking an item as played∏
|
||||||
* @returns A promise that resolves to true if the operation was successful, false otherwise
|
* @returns A promise that resolves to true if the operation was successful, false otherwise
|
||||||
*/
|
*/
|
||||||
export const markAsPlayed = async ({ api, item, userId }: MarkAsPlayedParams): Promise<boolean> => {
|
export const markAsPlayed = async ({ api, item, userId }: MarkAsPlayedParams): Promise<boolean> => {
|
||||||
@@ -22,15 +21,12 @@ export const markAsPlayed = async ({ api, item, userId }: MarkAsPlayedParams): P
|
|||||||
}
|
}
|
||||||
|
|
||||||
try {
|
try {
|
||||||
const [playedResponse] = await Promise.all([
|
const response = await getPlaystateApi(api).markPlayedItem({
|
||||||
api.axiosInstance.post(
|
itemId: item.Id,
|
||||||
`${api.basePath}/UserPlayedItems/${item.Id}`,
|
datePlayed: new Date().toISOString(),
|
||||||
{ userId, datePlayed: new Date().toISOString() },
|
});
|
||||||
{ headers: getAuthHeaders(api) }
|
|
||||||
),
|
|
||||||
]);
|
|
||||||
|
|
||||||
return playedResponse.status === 200;
|
return response.status === 200;
|
||||||
} catch (error) {
|
} catch (error) {
|
||||||
return false;
|
return false;
|
||||||
}
|
}
|
||||||
|
|||||||
Reference in New Issue
Block a user