mirror of
https://github.com/LemmyNet/lemmy-js-client.git
synced 2024-11-01 01:59:55 +00:00
Remove separate auth params for image endpoints (#212)
These use the same header/cookie auth now as all other api endpoints, so there is no reason for separate auth param.
This commit is contained in:
parent
6f0fab6d7d
commit
8d2364559d
2 changed files with 4 additions and 39 deletions
35
src/http.ts
35
src/http.ts
|
@ -1375,31 +1375,16 @@ export class LemmyHttp {
|
||||||
/**
|
/**
|
||||||
* Upload an image to the server.
|
* Upload an image to the server.
|
||||||
*/
|
*/
|
||||||
async uploadImage({
|
async uploadImage({ image }: UploadImage): Promise<UploadImageResponse> {
|
||||||
image,
|
|
||||||
auth,
|
|
||||||
}: UploadImage): Promise<UploadImageResponse> {
|
|
||||||
const formData = createFormData(image);
|
const formData = createFormData(image);
|
||||||
|
|
||||||
// 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}`;
|
|
||||||
}
|
|
||||||
|
|
||||||
let url: string | undefined = undefined;
|
let url: string | undefined = undefined;
|
||||||
let delete_url: string | undefined = undefined;
|
let delete_url: string | undefined = undefined;
|
||||||
|
|
||||||
const response = await this.#fetchFunction(this.#pictrsUrl, {
|
const response = await this.#fetchFunction(this.#pictrsUrl, {
|
||||||
method: HttpType.Post,
|
method: HttpType.Post,
|
||||||
body: formData as unknown as BodyInit,
|
body: formData as unknown as BodyInit,
|
||||||
headers: {
|
headers: this.#headers,
|
||||||
...this.#headers,
|
|
||||||
...headers,
|
|
||||||
},
|
|
||||||
});
|
});
|
||||||
|
|
||||||
if (response.status === 413) {
|
if (response.status === 413) {
|
||||||
|
@ -1424,24 +1409,12 @@ export class LemmyHttp {
|
||||||
/**
|
/**
|
||||||
* Delete a pictrs image
|
* Delete a pictrs image
|
||||||
*/
|
*/
|
||||||
async deleteImage({ token, filename, auth }: DeleteImage): Promise<any> {
|
async deleteImage({ token, filename }: 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 deleteUrl = `${this.#pictrsUrl}/delete/${token}/${filename}`;
|
||||||
|
|
||||||
const response = await this.#fetchFunction(deleteUrl, {
|
const response = await this.#fetchFunction(deleteUrl, {
|
||||||
method: HttpType.Get,
|
method: HttpType.Get,
|
||||||
headers: {
|
headers: this.#headers,
|
||||||
...this.#headers,
|
|
||||||
...headers,
|
|
||||||
},
|
|
||||||
});
|
});
|
||||||
|
|
||||||
return await response.json();
|
return await response.json();
|
||||||
|
|
|
@ -2,10 +2,6 @@ export const VERSION = "v3";
|
||||||
|
|
||||||
export interface UploadImage {
|
export interface UploadImage {
|
||||||
image: File | Buffer;
|
image: File | Buffer;
|
||||||
/**
|
|
||||||
* Optional if cookie with jwt set is already present. Otherwise, auth is required.
|
|
||||||
*/
|
|
||||||
auth?: string;
|
|
||||||
}
|
}
|
||||||
|
|
||||||
export interface UploadImageResponse {
|
export interface UploadImageResponse {
|
||||||
|
@ -26,8 +22,4 @@ export interface ImageFile {
|
||||||
export interface DeleteImage {
|
export interface DeleteImage {
|
||||||
token: string;
|
token: string;
|
||||||
filename: string;
|
filename: string;
|
||||||
/**
|
|
||||||
* Optional if cookie with jwt set is already present. Otherwise, auth is required.
|
|
||||||
*/
|
|
||||||
auth?: string;
|
|
||||||
}
|
}
|
||||||
|
|
Loading…
Reference in a new issue