Adding deleteImage endpoint. Fixes #193 (#196)

This commit is contained in:
Dessalines 2023-10-04 17:36:41 -04:00 committed by GitHub
parent 33eccecf94
commit 140c756ea2
No known key found for this signature in database
GPG key ID: 4AEE18F83AFDEB23
2 changed files with 41 additions and 1 deletions

View file

@ -125,7 +125,12 @@ import { SiteResponse } from "./types/SiteResponse";
import { TransferCommunity } from "./types/TransferCommunity"; import { TransferCommunity } from "./types/TransferCommunity";
import { VerifyEmail } from "./types/VerifyEmail"; import { VerifyEmail } from "./types/VerifyEmail";
import { VerifyEmailResponse } from "./types/VerifyEmailResponse"; 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 { HideCommunity } from "./types/HideCommunity";
import { BlockInstance } from "./types/BlockInstance"; import { BlockInstance } from "./types/BlockInstance";
import { BlockInstanceResponse } from "./types/BlockInstanceResponse"; import { BlockInstanceResponse } from "./types/BlockInstanceResponse";
@ -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) { #buildFullUrl(endpoint: string) {
return `${this.#apiUrl}${endpoint}`; return `${this.#apiUrl}${endpoint}`;
} }

View file

@ -22,3 +22,12 @@ export interface ImageFile {
file: string; file: string;
delete_token: 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;
}