mirror of
https://github.com/LemmyNet/lemmy-js-client.git
synced 2024-11-01 01:59:55 +00:00
parent
33eccecf94
commit
140c756ea2
2 changed files with 41 additions and 1 deletions
33
src/http.ts
33
src/http.ts
|
@ -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";
|
||||
|
@ -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}`;
|
||||
}
|
||||
|
|
|
@ -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;
|
||||
}
|
||||
|
|
Loading…
Reference in a new issue