mirror of
https://github.com/LemmyNet/lemmy-js-client.git
synced 2025-02-05 16:34:43 +00:00
add missing endpoints including delete
This commit is contained in:
parent
890e1f9172
commit
575fe9b980
1 changed files with 178 additions and 33 deletions
211
src/http.ts
211
src/http.ts
|
@ -1835,47 +1835,176 @@ export class LemmyHttp {
|
||||||
);
|
);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Upload new user avatar.
|
||||||
|
*
|
||||||
|
* `HTTP.Post /account/avatar`
|
||||||
|
*/
|
||||||
|
async uploadUserAvatar(
|
||||||
|
image: UploadImage,
|
||||||
|
options?: RequestOptions,
|
||||||
|
): Promise<SuccessResponse> {
|
||||||
|
return this.#upload("/account/avatar", image, options);
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Delete the user avatar.
|
||||||
|
*
|
||||||
|
* `HTTP.Delete /account/avatar`
|
||||||
|
*/
|
||||||
|
async deleteUserAvatar(options?: RequestOptions): Promise<SuccessResponse> {
|
||||||
|
return this.#wrapper<object, SuccessResponse>(
|
||||||
|
HttpType.Delete,
|
||||||
|
"/account/avatar",
|
||||||
|
{},
|
||||||
|
options,
|
||||||
|
);
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Upload new user banner.
|
||||||
|
*
|
||||||
|
* `HTTP.Post /account/banner`
|
||||||
|
*/
|
||||||
|
async uploadUserBanner(
|
||||||
|
image: UploadImage,
|
||||||
|
options?: RequestOptions,
|
||||||
|
): Promise<SuccessResponse> {
|
||||||
|
return this.#upload("/account/banner", image, options);
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Delete the user banner.
|
||||||
|
*
|
||||||
|
* `HTTP.Delete /account/banner`
|
||||||
|
*/
|
||||||
|
async deleteUserBanner(options?: RequestOptions): Promise<SuccessResponse> {
|
||||||
|
return this.#wrapper<object, SuccessResponse>(
|
||||||
|
HttpType.Delete,
|
||||||
|
"/account/banner",
|
||||||
|
{},
|
||||||
|
options,
|
||||||
|
);
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Upload new community icon.
|
||||||
|
*
|
||||||
|
* `HTTP.Post /community/icon`
|
||||||
|
*/
|
||||||
|
async uploadCommunityIcon(
|
||||||
|
image: UploadImage,
|
||||||
|
options?: RequestOptions,
|
||||||
|
): Promise<SuccessResponse> {
|
||||||
|
return this.#upload("/community/icon", image, options);
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Delete the community icon.
|
||||||
|
*
|
||||||
|
* `HTTP.Delete /community/icon`
|
||||||
|
*/
|
||||||
|
async deleteCommunityIcon(
|
||||||
|
options?: RequestOptions,
|
||||||
|
): Promise<SuccessResponse> {
|
||||||
|
return this.#wrapper<object, SuccessResponse>(
|
||||||
|
HttpType.Delete,
|
||||||
|
"/community/icon",
|
||||||
|
{},
|
||||||
|
options,
|
||||||
|
);
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Upload new community banner.
|
||||||
|
*
|
||||||
|
* `HTTP.Post /community/banner`
|
||||||
|
*/
|
||||||
|
async uploadCommunityBanner(
|
||||||
|
image: UploadImage,
|
||||||
|
options?: RequestOptions,
|
||||||
|
): Promise<SuccessResponse> {
|
||||||
|
return this.#upload("/community/banner", image, options);
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Delete the community banner.
|
||||||
|
*
|
||||||
|
* `HTTP.Delete /community/banner`
|
||||||
|
*/
|
||||||
|
async deleteCommunityBanner(
|
||||||
|
options?: RequestOptions,
|
||||||
|
): Promise<SuccessResponse> {
|
||||||
|
return this.#wrapper<object, SuccessResponse>(
|
||||||
|
HttpType.Delete,
|
||||||
|
"/community/banner",
|
||||||
|
{},
|
||||||
|
options,
|
||||||
|
);
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Upload new site icon.
|
||||||
|
*
|
||||||
|
* `HTTP.Post /site/icon`
|
||||||
|
*/
|
||||||
|
async uploadSiteIcon(
|
||||||
|
image: UploadImage,
|
||||||
|
options?: RequestOptions,
|
||||||
|
): Promise<SuccessResponse> {
|
||||||
|
return this.#upload("/site/icon", image, options);
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Delete the site icon.
|
||||||
|
*
|
||||||
|
* `HTTP.Delete /site/icon`
|
||||||
|
*/
|
||||||
|
async deleteSiteIcon(options?: RequestOptions): Promise<SuccessResponse> {
|
||||||
|
return this.#wrapper<object, SuccessResponse>(
|
||||||
|
HttpType.Delete,
|
||||||
|
"/site/icon",
|
||||||
|
{},
|
||||||
|
options,
|
||||||
|
);
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Upload new site banner.
|
||||||
|
*
|
||||||
|
* `HTTP.Post /site/banner`
|
||||||
|
*/
|
||||||
|
async uploadSiteBanner(
|
||||||
|
image: UploadImage,
|
||||||
|
options?: RequestOptions,
|
||||||
|
): Promise<SuccessResponse> {
|
||||||
|
return this.#upload("/site/banner", image, options);
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Delete the site banner.
|
||||||
|
*
|
||||||
|
* `HTTP.Delete /site/banner`
|
||||||
|
*/
|
||||||
|
async deleteSiteBanner(options?: RequestOptions): Promise<SuccessResponse> {
|
||||||
|
return this.#wrapper<object, SuccessResponse>(
|
||||||
|
HttpType.Delete,
|
||||||
|
"/site/banner",
|
||||||
|
{},
|
||||||
|
options,
|
||||||
|
);
|
||||||
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Upload an image to the server.
|
* Upload an image to the server.
|
||||||
*
|
*
|
||||||
* `HTTP.Post /image`
|
* `HTTP.Post /image`
|
||||||
*/
|
*/
|
||||||
async uploadImage(
|
async uploadImage(
|
||||||
{ image }: UploadImage,
|
image: UploadImage,
|
||||||
options?: RequestOptions,
|
options?: RequestOptions,
|
||||||
): Promise<UploadImageResponse> {
|
): Promise<UploadImageResponse> {
|
||||||
const formData = createFormData(image);
|
return this.#upload("/image", image, options);
|
||||||
|
|
||||||
const response = await this.#fetchFunction(this.#buildFullUrl("/image"), {
|
|
||||||
...options,
|
|
||||||
method: HttpType.Post,
|
|
||||||
body: formData as unknown as BodyInit,
|
|
||||||
headers: this.#headers,
|
|
||||||
});
|
|
||||||
return response.json();
|
|
||||||
}
|
|
||||||
|
|
||||||
/**
|
|
||||||
* Upload new user avatar.
|
|
||||||
*
|
|
||||||
* `HTTP.Post /account/avatar`
|
|
||||||
*/
|
|
||||||
async userUploadAvatar(
|
|
||||||
{ image }: UploadImage,
|
|
||||||
options?: RequestOptions,
|
|
||||||
): Promise<SuccessResponse> {
|
|
||||||
const formData = createFormData(image);
|
|
||||||
|
|
||||||
const response = await this.#fetchFunction(
|
|
||||||
this.#buildFullUrl("/account/avatar"),
|
|
||||||
{
|
|
||||||
...options,
|
|
||||||
method: HttpType.Post,
|
|
||||||
body: formData as unknown as BodyInit,
|
|
||||||
headers: this.#headers,
|
|
||||||
},
|
|
||||||
);
|
|
||||||
return response.json();
|
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
|
@ -1910,6 +2039,22 @@ export class LemmyHttp {
|
||||||
return `${this.#apiUrl}${endpoint}`;
|
return `${this.#apiUrl}${endpoint}`;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
async #upload<ResponseType>(
|
||||||
|
path: string,
|
||||||
|
{ image }: UploadImage,
|
||||||
|
options?: RequestOptions,
|
||||||
|
): Promise<ResponseType> {
|
||||||
|
const formData = createFormData(image);
|
||||||
|
|
||||||
|
const response = await this.#fetchFunction(this.#buildFullUrl(path), {
|
||||||
|
...options,
|
||||||
|
method: HttpType.Post,
|
||||||
|
body: formData as unknown as BodyInit,
|
||||||
|
headers: this.#headers,
|
||||||
|
});
|
||||||
|
return response.json();
|
||||||
|
}
|
||||||
|
|
||||||
async #wrapper<BodyType extends object, ResponseType>(
|
async #wrapper<BodyType extends object, ResponseType>(
|
||||||
type_: HttpType,
|
type_: HttpType,
|
||||||
endpoint: string,
|
endpoint: string,
|
||||||
|
|
Loading…
Reference in a new issue