Spaces:
Sleeping
Sleeping
File size: 1,126 Bytes
19e88d2 | 1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 | import { HUB_URL } from "../consts";
import { createApiError } from "../error";
import type { CredentialsParams } from "../types/public";
import { checkCredentials } from "../utils/checkCredentials";
export async function deleteCollectionItem(
params: {
/**
* The slug of the collection to delete the item from.
*/
slug: string;
/**
* The item object id which is different from the repo_id/paper_id provided when adding the item to the collection.
* This should be the _id property of the item.
*/
itemId: string;
hubUrl?: string;
/**
* Custom fetch function to use instead of the default one, for example to use a proxy or edit headers.
*/
fetch?: typeof fetch;
} & Partial<CredentialsParams>,
): Promise<void> {
const accessToken = checkCredentials(params);
const res = await (params.fetch ?? fetch)(
`${params.hubUrl ?? HUB_URL}/api/collections/${params.slug}/items/${params.itemId}`,
{
method: "DELETE",
headers: {
Authorization: `Bearer ${accessToken}`,
"Content-Type": "application/json",
},
},
);
if (!res.ok) {
throw await createApiError(res);
}
}
|