Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Remove saved media in collections #1389

Open
wants to merge 1 commit into
base: master
Choose a base branch
from
Open
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
20 changes: 18 additions & 2 deletions src/repositories/media.repository.ts
Original file line number Diff line number Diff line change
Expand Up @@ -702,10 +702,26 @@ export class MediaRepository extends Repository {
return body;
}

async unsave(mediaId: string) {
/**
* unsave a media, or remove saved media form collection if you pass the collection ids in array
* @param {string} mediaId - The mediaId of the post
* @param {string[]} [collection_ids] - Optional, The array of collection ids if you want to remove the saved media from these specific collection
* Example:
* unsave("2524149952724070925_1829855275") unsave media
* unsave("2524149952724070925_1829855275", ["17865977635619975"]) remove the saved media in 1 collection if it exists in it
* unsave("2524149952724070925_1829855275", ["17865977635619975", "17845997638619928"]) remove the saved media in 2 collections if it exists in it
*/
async unsave(mediaId: string, collection_ids?: string[]) {
const { body } = await this.client.request.send({
url: `/api/v1/media/${mediaId}/unsave/`,
url: `/api/v1/media/${mediaId}/${collection_ids ? 'save' : 'unsave'}/`,
method: 'POST',
form: this.client.request.sign({
removed_collection_ids: collection_ids ? JSON.stringify(collection_ids) : undefined,
_uuid: this.client.state.uuid,
_uid: this.client.state.cookieUserId,
_csrftoken: this.client.state.cookieCsrfToken,
device_id: this.client.state.deviceId,
}),
});
return body;
}
Expand Down