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

Adding deleteImage endpoint. Fixes #193 #196

Merged
merged 1 commit into from
Oct 4, 2023
Merged
Show file tree
Hide file tree
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
33 changes: 32 additions & 1 deletion src/http.ts
Original file line number Diff line number Diff line change
Expand Up @@ -125,7 +125,12 @@ import { SiteResponse } from "./types/SiteResponse";
import { TransferCommunity } from "./types/TransferCommunity";
import { VerifyEmail } from "./types/VerifyEmail";
import { VerifyEmailResponse } from "./types/VerifyEmailResponse";
import { UploadImage, UploadImageResponse, VERSION } from "./types/others";
import {
DeleteImage,
UploadImage,
UploadImageResponse,
VERSION,
} from "./types/others";
import { HideCommunity } from "./types/HideCommunity";
import { BlockInstance } from "./types/BlockInstance";
import { BlockInstanceResponse } from "./types/BlockInstanceResponse";
Expand Down Expand Up @@ -1358,6 +1363,32 @@ export class LemmyHttp {
};
}

/**
* Delete a pictrs image
*/
async deleteImage({ token, filename, auth }: DeleteImage): Promise<any> {
// If auth cookie not already set by browser, set it with passed in auth
const headers = {} as any;
if (
!globalThis?.document?.cookie?.includes("auth=") &&
!this.#headers?.Cookie?.includes("auth=")
) {
headers.Cookie = `auth=${auth}`;
}

const deleteUrl = `${this.#pictrsUrl}/delete/${token}/${filename}`;

const response = await this.#fetchFunction(deleteUrl, {
method: HttpType.Get,
headers: {
...this.#headers,
...headers,
},
});

return await response.json();
}

#buildFullUrl(endpoint: string) {
return `${this.#apiUrl}${endpoint}`;
}
Expand Down
9 changes: 9 additions & 0 deletions src/types/others.ts
Original file line number Diff line number Diff line change
Expand Up @@ -22,3 +22,12 @@ export interface ImageFile {
file: string;
delete_token: string;
}

export interface DeleteImage {
token: string;
filename: string;
/**
* Optional if cookie with jwt set is already present. Otherwise, auth is required.
*/
auth?: string;
}