From 8d2364559dc2ee7ee3794a7d0f23eed900400735 Mon Sep 17 00:00:00 2001 From: Nutomic Date: Tue, 14 Nov 2023 19:26:25 +0100 Subject: [PATCH] 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. --- src/http.ts | 35 ++++------------------------------- src/other_types.ts | 8 -------- 2 files changed, 4 insertions(+), 39 deletions(-) diff --git a/src/http.ts b/src/http.ts index d78878b..fe482f0 100644 --- a/src/http.ts +++ b/src/http.ts @@ -1375,31 +1375,16 @@ export class LemmyHttp { /** * Upload an image to the server. */ - async uploadImage({ - image, - auth, - }: UploadImage): Promise { + async uploadImage({ image }: UploadImage): Promise { 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 delete_url: string | undefined = undefined; const response = await this.#fetchFunction(this.#pictrsUrl, { method: HttpType.Post, body: formData as unknown as BodyInit, - headers: { - ...this.#headers, - ...headers, - }, + headers: this.#headers, }); if (response.status === 413) { @@ -1424,24 +1409,12 @@ export class LemmyHttp { /** * Delete a pictrs image */ - async deleteImage({ token, filename, auth }: DeleteImage): Promise { - // 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}`; - } - + async deleteImage({ token, filename }: DeleteImage): Promise { const deleteUrl = `${this.#pictrsUrl}/delete/${token}/${filename}`; const response = await this.#fetchFunction(deleteUrl, { method: HttpType.Get, - headers: { - ...this.#headers, - ...headers, - }, + headers: this.#headers, }); return await response.json(); diff --git a/src/other_types.ts b/src/other_types.ts index 8f2504a..9db74ea 100644 --- a/src/other_types.ts +++ b/src/other_types.ts @@ -2,10 +2,6 @@ export const VERSION = "v3"; export interface UploadImage { image: File | Buffer; - /** - * Optional if cookie with jwt set is already present. Otherwise, auth is required. - */ - auth?: string; } export interface UploadImageResponse { @@ -26,8 +22,4 @@ export interface ImageFile { export interface DeleteImage { token: string; filename: string; - /** - * Optional if cookie with jwt set is already present. Otherwise, auth is required. - */ - auth?: string; }