lemmy-js-client 0.20.0-api-v4.17 → 0.20.0-image-api-rework.0

Sign up to get free protection for your applications and to get access to all the features.
package/dist/http.d.ts CHANGED
@@ -123,7 +123,7 @@ import { SearchResponse } from "./types/SearchResponse";
123
123
  import { SiteResponse } from "./types/SiteResponse";
124
124
  import { TransferCommunity } from "./types/TransferCommunity";
125
125
  import { VerifyEmail } from "./types/VerifyEmail";
126
- import { DeleteImage, UploadImage, UploadImageResponse } from "./other_types";
126
+ import { UploadImage } from "./other_types";
127
127
  import { HideCommunity } from "./types/HideCommunity";
128
128
  import { GenerateTotpSecretResponse } from "./types/GenerateTotpSecretResponse";
129
129
  import { UpdateTotp } from "./types/UpdateTotp";
@@ -157,6 +157,8 @@ import { MyUserInfo } from "./types/MyUserInfo";
157
157
  import { UserBlockInstanceParams } from "./types/UserBlockInstanceParams";
158
158
  import { AdminAllowInstanceParams } from "./types/AdminAllowInstanceParams";
159
159
  import { AdminBlockInstanceParams } from "./types/AdminBlockInstanceParams";
160
+ import { DeleteImageParams } from "./types/DeleteImageParams";
161
+ import { UploadImageResponse } from "./types/UploadImageResponse";
160
162
  type RequestOptions = Pick<RequestInit, "signal">;
161
163
  /**
162
164
  * Helps build lemmy HTTP requests.
@@ -876,12 +878,28 @@ export declare class LemmyHttp {
876
878
  adminAllowInstance(form: AdminAllowInstanceParams, options?: RequestOptions): Promise<SuccessResponse>;
877
879
  /**
878
880
  * Upload an image to the server.
881
+ *
882
+ * `HTTP.Post /image`
879
883
  */
880
884
  uploadImage({ image }: UploadImage, options?: RequestOptions): Promise<UploadImageResponse>;
885
+ /**
886
+ * Upload new user avatar.
887
+ *
888
+ * `HTTP.Post /account/avatar`
889
+ */
890
+ userUploadAvatar({ image }: UploadImage, options?: RequestOptions): Promise<SuccessResponse>;
881
891
  /**
882
892
  * Delete a pictrs image
893
+ *
894
+ * `HTTP.Delete /image`
895
+ */
896
+ deleteImage(form: DeleteImageParams, options?: RequestOptions): Promise<SuccessResponse>;
897
+ /**
898
+ * Health check for image functionality
899
+ *
900
+ * `HTTP.Get /image/health`
883
901
  */
884
- deleteImage({ token, filename }: DeleteImage, options?: RequestOptions): Promise<boolean>;
902
+ imageHealth(options?: RequestOptions): Promise<SuccessResponse>;
885
903
  /**
886
904
  * Set the headers (can be used to set the auth header)
887
905
  */
package/dist/http.js CHANGED
@@ -28,6 +28,7 @@ var HttpType;
28
28
  HttpType["Get"] = "GET";
29
29
  HttpType["Post"] = "POST";
30
30
  HttpType["Put"] = "PUT";
31
+ HttpType["Delete"] = "DELETE";
31
32
  })(HttpType || (HttpType = {}));
32
33
  /**
33
34
  * Helps build lemmy HTTP requests.
@@ -992,34 +993,46 @@ class LemmyHttp {
992
993
  }
993
994
  /**
994
995
  * Upload an image to the server.
996
+ *
997
+ * `HTTP.Post /image`
995
998
  */
996
999
  uploadImage(_a, options_1) {
997
1000
  return __awaiter(this, arguments, void 0, function* ({ image }, options) {
998
1001
  const formData = createFormData(image);
999
- let url = undefined;
1000
- let delete_url = undefined;
1001
1002
  const response = yield __classPrivateFieldGet(this, _LemmyHttp_fetchFunction, "f").call(this, __classPrivateFieldGet(this, _LemmyHttp_pictrsUrl, "f"), Object.assign(Object.assign({}, options), { method: HttpType.Post, body: formData, headers: __classPrivateFieldGet(this, _LemmyHttp_headers, "f") }));
1002
- if (response.status === 413) {
1003
- return { msg: "too_large" };
1004
- }
1005
- const responseJson = yield response.json();
1006
- if (responseJson.msg === "ok") {
1007
- const { file: hash, delete_token: deleteToken } = responseJson.files[0];
1008
- delete_url = `${__classPrivateFieldGet(this, _LemmyHttp_pictrsUrl, "f")}/delete/${deleteToken}/${hash}`;
1009
- url = `${__classPrivateFieldGet(this, _LemmyHttp_pictrsUrl, "f")}/${hash}`;
1010
- }
1011
- return Object.assign(Object.assign({}, responseJson), { url,
1012
- delete_url });
1003
+ return response.json();
1004
+ });
1005
+ }
1006
+ /**
1007
+ * Upload new user avatar.
1008
+ *
1009
+ * `HTTP.Post /account/avatar`
1010
+ */
1011
+ userUploadAvatar(_a, options_1) {
1012
+ return __awaiter(this, arguments, void 0, function* ({ image }, options) {
1013
+ const formData = createFormData(image);
1014
+ const response = yield __classPrivateFieldGet(this, _LemmyHttp_fetchFunction, "f").call(this, __classPrivateFieldGet(this, _LemmyHttp_pictrsUrl, "f"), Object.assign(Object.assign({}, options), { method: HttpType.Post, body: formData, headers: __classPrivateFieldGet(this, _LemmyHttp_headers, "f") }));
1015
+ return response.json();
1013
1016
  });
1014
1017
  }
1015
1018
  /**
1016
1019
  * Delete a pictrs image
1020
+ *
1021
+ * `HTTP.Delete /image`
1022
+ */
1023
+ deleteImage(form, options) {
1024
+ return __awaiter(this, void 0, void 0, function* () {
1025
+ return __classPrivateFieldGet(this, _LemmyHttp_instances, "m", _LemmyHttp_wrapper).call(this, HttpType.Delete, "/image", form, options);
1026
+ });
1027
+ }
1028
+ /**
1029
+ * Health check for image functionality
1030
+ *
1031
+ * `HTTP.Get /image/health`
1017
1032
  */
1018
- deleteImage(_a, options_1) {
1019
- return __awaiter(this, arguments, void 0, function* ({ token, filename }, options) {
1020
- const deleteUrl = `${__classPrivateFieldGet(this, _LemmyHttp_pictrsUrl, "f")}/delete/${token}/${filename}`;
1021
- const response = yield __classPrivateFieldGet(this, _LemmyHttp_fetchFunction, "f").call(this, deleteUrl, Object.assign(Object.assign({}, options), { method: HttpType.Get, headers: __classPrivateFieldGet(this, _LemmyHttp_headers, "f") }));
1022
- return response.status == 204;
1033
+ imageHealth(options) {
1034
+ return __awaiter(this, void 0, void 0, function* () {
1035
+ return __classPrivateFieldGet(this, _LemmyHttp_instances, "m", _LemmyHttp_wrapper).call(this, HttpType.Get, "/image/health", {}, options);
1023
1036
  });
1024
1037
  }
1025
1038
  /**
package/dist/index.d.ts CHANGED
@@ -1,5 +1,5 @@
1
1
  export * from "./http";
2
- export { UploadImage, UploadImageResponse, ImageFile, DeleteImage, } from "./other_types";
2
+ export { UploadImage } from "./other_types";
3
3
  export { ActivityId } from "./types/ActivityId";
4
4
  export { AddAdmin } from "./types/AddAdmin";
5
5
  export { AddAdminResponse } from "./types/AddAdminResponse";
@@ -80,6 +80,7 @@ export { DeleteAccount } from "./types/DeleteAccount";
80
80
  export { DeleteComment } from "./types/DeleteComment";
81
81
  export { DeleteCommunity } from "./types/DeleteCommunity";
82
82
  export { DeleteCustomEmoji } from "./types/DeleteCustomEmoji";
83
+ export { DeleteImageParams } from "./types/DeleteImageParams";
83
84
  export { DeleteOAuthProvider } from "./types/DeleteOAuthProvider";
84
85
  export { DeletePost } from "./types/DeletePost";
85
86
  export { DeletePrivateMessage } from "./types/DeletePrivateMessage";
@@ -133,6 +134,8 @@ export { GetUnreadRegistrationApplicationCountResponse } from "./types/GetUnread
133
134
  export { HideCommunity } from "./types/HideCommunity";
134
135
  export { HidePost } from "./types/HidePost";
135
136
  export { ImageDetails } from "./types/ImageDetails";
137
+ export { ImageGetParams } from "./types/ImageGetParams";
138
+ export { ImageProxyParams } from "./types/ImageProxyParams";
136
139
  export { Instance } from "./types/Instance";
137
140
  export { InstanceId } from "./types/InstanceId";
138
141
  export { InstanceWithFederationState } from "./types/InstanceWithFederationState";
@@ -286,6 +289,7 @@ export { TransferCommunity } from "./types/TransferCommunity";
286
289
  export { UpdateTagline } from "./types/UpdateTagline";
287
290
  export { UpdateTotp } from "./types/UpdateTotp";
288
291
  export { UpdateTotpResponse } from "./types/UpdateTotpResponse";
292
+ export { UploadImageResponse } from "./types/UploadImageResponse";
289
293
  export { UserBlockInstanceParams } from "./types/UserBlockInstanceParams";
290
294
  export { VerifyEmail } from "./types/VerifyEmail";
291
295
  export { VoteView } from "./types/VoteView";
@@ -2,20 +2,3 @@ export declare const VERSION = "v4";
2
2
  export interface UploadImage {
3
3
  image: File | Buffer;
4
4
  }
5
- export interface UploadImageResponse {
6
- /**
7
- * Is "ok" if the upload was successful; is something else otherwise.
8
- */
9
- msg: string;
10
- files?: ImageFile[];
11
- url?: string;
12
- delete_url?: string;
13
- }
14
- export interface ImageFile {
15
- file: string;
16
- delete_token: string;
17
- }
18
- export interface DeleteImage {
19
- token: string;
20
- filename: string;
21
- }
@@ -0,0 +1,4 @@
1
+ export type DeleteImageParams = {
2
+ file: string;
3
+ token: string;
4
+ };
@@ -0,0 +1,3 @@
1
+ "use strict";
2
+ // This file was generated by [ts-rs](https://github.com/Aleph-Alpha/ts-rs). Do not edit this file manually.
3
+ Object.defineProperty(exports, "__esModule", { value: true });
@@ -0,0 +1,4 @@
1
+ export type ImageGetParams = {
2
+ format: string | null;
3
+ thumbnail: number | null;
4
+ };
@@ -0,0 +1,3 @@
1
+ "use strict";
2
+ // This file was generated by [ts-rs](https://github.com/Aleph-Alpha/ts-rs). Do not edit this file manually.
3
+ Object.defineProperty(exports, "__esModule", { value: true });
@@ -0,0 +1,5 @@
1
+ export type ImageProxyParams = {
2
+ url: string;
3
+ format: string | null;
4
+ thumbnail: number | null;
5
+ };
@@ -0,0 +1,3 @@
1
+ "use strict";
2
+ // This file was generated by [ts-rs](https://github.com/Aleph-Alpha/ts-rs). Do not edit this file manually.
3
+ Object.defineProperty(exports, "__esModule", { value: true });
@@ -41,6 +41,8 @@ export type LemmyErrorType = {
41
41
  error: "no_content_type_header";
42
42
  } | {
43
43
  error: "not_an_image_type";
44
+ } | {
45
+ error: "invalid_image_upload";
44
46
  } | {
45
47
  error: "not_a_mod_or_admin";
46
48
  } | {
@@ -40,10 +40,6 @@ export type SaveUserSettings = {
40
40
  * The language of the lemmy interface
41
41
  */
42
42
  interface_language?: string;
43
- /**
44
- * A URL for your avatar.
45
- */
46
- avatar?: string;
47
43
  /**
48
44
  * A URL for your banner.
49
45
  */
@@ -0,0 +1,5 @@
1
+ export type UploadImageResponse = {
2
+ image_url: string;
3
+ filename: string;
4
+ delete_token: string;
5
+ };
@@ -0,0 +1,3 @@
1
+ "use strict";
2
+ // This file was generated by [ts-rs](https://github.com/Aleph-Alpha/ts-rs). Do not edit this file manually.
3
+ Object.defineProperty(exports, "__esModule", { value: true });
package/package.json CHANGED
@@ -1,7 +1,7 @@
1
1
  {
2
2
  "name": "lemmy-js-client",
3
3
  "description": "A javascript / typescript client for Lemmy",
4
- "version": "0.20.0-api-v4.17",
4
+ "version": "0.20.0-image-api-rework.0",
5
5
  "author": "Dessalines <tyhou13@gmx.com>",
6
6
  "license": "AGPL-3.0",
7
7
  "main": "./dist/index.js",