@mtkruto/node 0.0.920 → 0.0.921

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
@@ -1169,6 +1169,18 @@ export class Client extends ClientAbstract {
1169
1169
  const location = new types.InputPeerPhotoFileLocation({ big: big ? true : undefined, peer, photoId: fileId.params.mediaId });
1170
1170
  return this.downloadInner(location);
1171
1171
  }
1172
+ case FileType.Photo: {
1173
+ if (fileId.params.mediaId == undefined || fileId.params.accessHash == undefined || fileId.params.fileReference == undefined || fileId.params.thumbnailSize == undefined) {
1174
+ UNREACHABLE();
1175
+ }
1176
+ const location = new types.InputPhotoFileLocation({
1177
+ id: fileId.params.mediaId,
1178
+ accessHash: fileId.params.accessHash,
1179
+ fileReference: fileId.params.fileReference,
1180
+ thumbSize: fileId.params.thumbnailSize,
1181
+ });
1182
+ return this.downloadInner(location);
1183
+ }
1172
1184
  default:
1173
1185
  UNREACHABLE();
1174
1186
  }
@@ -4,7 +4,7 @@ export declare const publicKeys: Map<bigint, [bigint, bigint]>;
4
4
  export declare const VECTOR_CONSTRUCTOR = 481674261;
5
5
  export declare const DEFAULT_INITIAL_DC: DC;
6
6
  export declare const LAYER = 158;
7
- export declare const DEFAULT_APP_VERSION = "MTKruto 0.0.920";
7
+ export declare const DEFAULT_APP_VERSION = "MTKruto 0.0.921";
8
8
  export declare const DEFAULT_DEVICE_MODEL: string;
9
9
  export declare const DEFAULT_LANG_CODE: string;
10
10
  export declare const DEFAULT_LANG_PACK = "";
package/esm/constants.js CHANGED
@@ -62,7 +62,7 @@ export const publicKeys = new Map([
62
62
  export const VECTOR_CONSTRUCTOR = 0x1CB5C415;
63
63
  export const DEFAULT_INITIAL_DC = "2-test";
64
64
  export const LAYER = 158;
65
- export const DEFAULT_APP_VERSION = "MTKruto 0.0.920";
65
+ export const DEFAULT_APP_VERSION = "MTKruto 0.0.921";
66
66
  // @ts-ignore: lib
67
67
  export const DEFAULT_DEVICE_MODEL = typeof dntShim.Deno === "undefined" ? typeof navigator === "undefined" ? typeof process === "undefined" ? "Unknown" : process.platform + "-" + process.arch : navigator.userAgent.split(" ")[0] : dntShim.Deno.build.os + "-" + dntShim.Deno.build.arch;
68
68
  export const DEFAULT_LANG_CODE = typeof navigator === "undefined" ? "en" : navigator.language.split("-")[0];
@@ -0,0 +1,9 @@
1
+ import * as types from "../tl/2_types.js";
2
+ export interface Thumbnail {
3
+ fileId: string;
4
+ fileUniqueId: string;
5
+ width: number;
6
+ height: number;
7
+ fileSize: number;
8
+ }
9
+ export declare function constructThumbnail(size: types.PhotoSize, fileId: string, fileUniqueId: string): Thumbnail;
@@ -0,0 +1,9 @@
1
+ export function constructThumbnail(size, fileId, fileUniqueId) {
2
+ return {
3
+ fileId,
4
+ fileUniqueId,
5
+ width: size.w,
6
+ height: size.h,
7
+ fileSize: size.size,
8
+ };
9
+ }
@@ -0,0 +1,11 @@
1
+ import * as types from "../tl/2_types.js";
2
+ import { Thumbnail } from "./0_thumbnail.js";
3
+ export interface Photo {
4
+ fileId: string;
5
+ fileUniqueId: string;
6
+ width: number;
7
+ height: number;
8
+ fileSize: number;
9
+ thumbnails: Thumbnail[];
10
+ }
11
+ export declare function constructPhoto(photo: types.Photo): Photo;
@@ -0,0 +1,49 @@
1
+ import { as } from "../tl/1_tl_object.js";
2
+ import * as types from "../tl/2_types.js";
3
+ import { FileID, FileType, FileUniqueID, FileUniqueType, ThumbnailSource } from "./!0_file_id.js";
4
+ import { constructThumbnail } from "./0_thumbnail.js";
5
+ export function constructPhoto(photo) {
6
+ const sizes = photo.sizes
7
+ .map((v) => {
8
+ if (v instanceof types.PhotoSizeProgressive) {
9
+ return new types.PhotoSize({ type: v.type, w: v.w, h: v.h, size: Math.max(...v.sizes) });
10
+ }
11
+ else {
12
+ return v;
13
+ }
14
+ })
15
+ .map((v) => v[as](types.PhotoSize))
16
+ .sort((a, b) => a.size - b.size);
17
+ const largest = sizes.slice(-1)[0];
18
+ const { dcId, id: mediaId, accessHash, fileReference } = photo;
19
+ const fileUniqueId = new FileUniqueID(FileUniqueType.Document, { mediaId: photo.id }).encode();
20
+ return {
21
+ fileId: new FileID(null, null, FileType.Photo, dcId, {
22
+ mediaId,
23
+ accessHash,
24
+ fileReference,
25
+ thumbnailSource: ThumbnailSource.Thumbnail,
26
+ thumbnailFileType: FileType.Photo,
27
+ thumbnailSize: largest.type,
28
+ volumeId: 0n,
29
+ localId: 0,
30
+ }).encode(),
31
+ fileUniqueId,
32
+ width: largest.w,
33
+ height: largest.h,
34
+ fileSize: largest.size,
35
+ thumbnails: sizes.slice(0, -1).map((v) => {
36
+ const fileId = new FileID(null, null, FileType.Photo, dcId, {
37
+ mediaId,
38
+ accessHash,
39
+ fileReference,
40
+ thumbnailSource: ThumbnailSource.Thumbnail,
41
+ thumbnailFileType: FileType.Photo,
42
+ thumbnailSize: v.type,
43
+ volumeId: 0n,
44
+ localId: 0,
45
+ }).encode();
46
+ return constructThumbnail(v, fileId, fileUniqueId);
47
+ }),
48
+ };
49
+ }
@@ -7,6 +7,7 @@ import { Chat } from "./1_chat.js";
7
7
  import { User } from "./1_user.js";
8
8
  import { InlineKeyboardMarkup } from "./2_inline_keyboard_markup.js";
9
9
  import { ReplyKeyboardMarkup } from "./2_reply_keyboard_markup.js";
10
+ import { Photo } from "./1_photo.js";
10
11
  export interface Message {
11
12
  id: number;
12
13
  threadId?: number;
@@ -35,6 +36,7 @@ export interface Message {
35
36
  hasMediaSpoiler?: boolean;
36
37
  views?: number;
37
38
  replyMarkup?: InlineKeyboardMarkup | ReplyKeyboardMarkup | ReplyKeyboardRemove | ForceReply;
39
+ photo?: Photo;
38
40
  }
39
41
  export declare function constructMessage(message_: types.Message, getEntity: {
40
42
  (peer: types.PeerUser): MaybePromise<types.User | null>;
@@ -9,6 +9,7 @@ import { constructChat } from "./1_chat.js";
9
9
  import { constructUser } from "./1_user.js";
10
10
  import { constructInlineKeyboardMarkup } from "./2_inline_keyboard_markup.js";
11
11
  import { constructReplyKeyboardMarkup } from "./2_reply_keyboard_markup.js";
12
+ import { constructPhoto } from "./1_photo.js";
12
13
  const d = debug("types/Message");
13
14
  export async function constructMessage(message_, getEntity, getMessage) {
14
15
  let chat_ = null;
@@ -173,5 +174,12 @@ export async function constructMessage(message_, getEntity, getMessage) {
173
174
  UNREACHABLE();
174
175
  }
175
176
  }
177
+ if (message_.media) {
178
+ if (message_.media instanceof types.MessageMediaPhoto) {
179
+ if (message_.media.photo instanceof types.Photo) {
180
+ message.photo = constructPhoto(message_.media.photo);
181
+ }
182
+ }
183
+ }
176
184
  return cleanObject(message);
177
185
  }
package/package.json CHANGED
@@ -2,7 +2,7 @@
2
2
  "module": "./esm/mod.js",
3
3
  "main": "./script/mod.js",
4
4
  "name": "@mtkruto/node",
5
- "version": "0.0.920",
5
+ "version": "0.0.921",
6
6
  "description": "MTKruto for Node.js",
7
7
  "author": "Roj <rojvv@icloud.com>",
8
8
  "license": "LGPL-3.0-or-later",
@@ -1195,6 +1195,18 @@ class Client extends _1_client_abstract_js_1.ClientAbstract {
1195
1195
  const location = new types.InputPeerPhotoFileLocation({ big: big ? true : undefined, peer, photoId: fileId.params.mediaId });
1196
1196
  return this.downloadInner(location);
1197
1197
  }
1198
+ case _0_file_id_js_1.FileType.Photo: {
1199
+ if (fileId.params.mediaId == undefined || fileId.params.accessHash == undefined || fileId.params.fileReference == undefined || fileId.params.thumbnailSize == undefined) {
1200
+ (0, _0_control_js_1.UNREACHABLE)();
1201
+ }
1202
+ const location = new types.InputPhotoFileLocation({
1203
+ id: fileId.params.mediaId,
1204
+ accessHash: fileId.params.accessHash,
1205
+ fileReference: fileId.params.fileReference,
1206
+ thumbSize: fileId.params.thumbnailSize,
1207
+ });
1208
+ return this.downloadInner(location);
1209
+ }
1198
1210
  default:
1199
1211
  (0, _0_control_js_1.UNREACHABLE)();
1200
1212
  }
@@ -4,7 +4,7 @@ export declare const publicKeys: Map<bigint, [bigint, bigint]>;
4
4
  export declare const VECTOR_CONSTRUCTOR = 481674261;
5
5
  export declare const DEFAULT_INITIAL_DC: DC;
6
6
  export declare const LAYER = 158;
7
- export declare const DEFAULT_APP_VERSION = "MTKruto 0.0.920";
7
+ export declare const DEFAULT_APP_VERSION = "MTKruto 0.0.921";
8
8
  export declare const DEFAULT_DEVICE_MODEL: string;
9
9
  export declare const DEFAULT_LANG_CODE: string;
10
10
  export declare const DEFAULT_LANG_PACK = "";
@@ -88,7 +88,7 @@ exports.publicKeys = new Map([
88
88
  exports.VECTOR_CONSTRUCTOR = 0x1CB5C415;
89
89
  exports.DEFAULT_INITIAL_DC = "2-test";
90
90
  exports.LAYER = 158;
91
- exports.DEFAULT_APP_VERSION = "MTKruto 0.0.920";
91
+ exports.DEFAULT_APP_VERSION = "MTKruto 0.0.921";
92
92
  // @ts-ignore: lib
93
93
  exports.DEFAULT_DEVICE_MODEL = typeof dntShim.Deno === "undefined" ? typeof navigator === "undefined" ? typeof process === "undefined" ? "Unknown" : process.platform + "-" + process.arch : navigator.userAgent.split(" ")[0] : dntShim.Deno.build.os + "-" + dntShim.Deno.build.arch;
94
94
  exports.DEFAULT_LANG_CODE = typeof navigator === "undefined" ? "en" : navigator.language.split("-")[0];
@@ -0,0 +1,9 @@
1
+ import * as types from "../tl/2_types.js";
2
+ export interface Thumbnail {
3
+ fileId: string;
4
+ fileUniqueId: string;
5
+ width: number;
6
+ height: number;
7
+ fileSize: number;
8
+ }
9
+ export declare function constructThumbnail(size: types.PhotoSize, fileId: string, fileUniqueId: string): Thumbnail;
@@ -0,0 +1,13 @@
1
+ "use strict";
2
+ Object.defineProperty(exports, "__esModule", { value: true });
3
+ exports.constructThumbnail = void 0;
4
+ function constructThumbnail(size, fileId, fileUniqueId) {
5
+ return {
6
+ fileId,
7
+ fileUniqueId,
8
+ width: size.w,
9
+ height: size.h,
10
+ fileSize: size.size,
11
+ };
12
+ }
13
+ exports.constructThumbnail = constructThumbnail;
@@ -0,0 +1,11 @@
1
+ import * as types from "../tl/2_types.js";
2
+ import { Thumbnail } from "./0_thumbnail.js";
3
+ export interface Photo {
4
+ fileId: string;
5
+ fileUniqueId: string;
6
+ width: number;
7
+ height: number;
8
+ fileSize: number;
9
+ thumbnails: Thumbnail[];
10
+ }
11
+ export declare function constructPhoto(photo: types.Photo): Photo;
@@ -0,0 +1,76 @@
1
+ "use strict";
2
+ var __createBinding = (this && this.__createBinding) || (Object.create ? (function(o, m, k, k2) {
3
+ if (k2 === undefined) k2 = k;
4
+ var desc = Object.getOwnPropertyDescriptor(m, k);
5
+ if (!desc || ("get" in desc ? !m.__esModule : desc.writable || desc.configurable)) {
6
+ desc = { enumerable: true, get: function() { return m[k]; } };
7
+ }
8
+ Object.defineProperty(o, k2, desc);
9
+ }) : (function(o, m, k, k2) {
10
+ if (k2 === undefined) k2 = k;
11
+ o[k2] = m[k];
12
+ }));
13
+ var __setModuleDefault = (this && this.__setModuleDefault) || (Object.create ? (function(o, v) {
14
+ Object.defineProperty(o, "default", { enumerable: true, value: v });
15
+ }) : function(o, v) {
16
+ o["default"] = v;
17
+ });
18
+ var __importStar = (this && this.__importStar) || function (mod) {
19
+ if (mod && mod.__esModule) return mod;
20
+ var result = {};
21
+ if (mod != null) for (var k in mod) if (k !== "default" && Object.prototype.hasOwnProperty.call(mod, k)) __createBinding(result, mod, k);
22
+ __setModuleDefault(result, mod);
23
+ return result;
24
+ };
25
+ Object.defineProperty(exports, "__esModule", { value: true });
26
+ exports.constructPhoto = void 0;
27
+ const _1_tl_object_js_1 = require("../tl/1_tl_object.js");
28
+ const types = __importStar(require("../tl/2_types.js"));
29
+ const _0_file_id_js_1 = require("./!0_file_id.js");
30
+ const _0_thumbnail_js_1 = require("./0_thumbnail.js");
31
+ function constructPhoto(photo) {
32
+ const sizes = photo.sizes
33
+ .map((v) => {
34
+ if (v instanceof types.PhotoSizeProgressive) {
35
+ return new types.PhotoSize({ type: v.type, w: v.w, h: v.h, size: Math.max(...v.sizes) });
36
+ }
37
+ else {
38
+ return v;
39
+ }
40
+ })
41
+ .map((v) => v[_1_tl_object_js_1.as](types.PhotoSize))
42
+ .sort((a, b) => a.size - b.size);
43
+ const largest = sizes.slice(-1)[0];
44
+ const { dcId, id: mediaId, accessHash, fileReference } = photo;
45
+ const fileUniqueId = new _0_file_id_js_1.FileUniqueID(_0_file_id_js_1.FileUniqueType.Document, { mediaId: photo.id }).encode();
46
+ return {
47
+ fileId: new _0_file_id_js_1.FileID(null, null, _0_file_id_js_1.FileType.Photo, dcId, {
48
+ mediaId,
49
+ accessHash,
50
+ fileReference,
51
+ thumbnailSource: _0_file_id_js_1.ThumbnailSource.Thumbnail,
52
+ thumbnailFileType: _0_file_id_js_1.FileType.Photo,
53
+ thumbnailSize: largest.type,
54
+ volumeId: 0n,
55
+ localId: 0,
56
+ }).encode(),
57
+ fileUniqueId,
58
+ width: largest.w,
59
+ height: largest.h,
60
+ fileSize: largest.size,
61
+ thumbnails: sizes.slice(0, -1).map((v) => {
62
+ const fileId = new _0_file_id_js_1.FileID(null, null, _0_file_id_js_1.FileType.Photo, dcId, {
63
+ mediaId,
64
+ accessHash,
65
+ fileReference,
66
+ thumbnailSource: _0_file_id_js_1.ThumbnailSource.Thumbnail,
67
+ thumbnailFileType: _0_file_id_js_1.FileType.Photo,
68
+ thumbnailSize: v.type,
69
+ volumeId: 0n,
70
+ localId: 0,
71
+ }).encode();
72
+ return (0, _0_thumbnail_js_1.constructThumbnail)(v, fileId, fileUniqueId);
73
+ }),
74
+ };
75
+ }
76
+ exports.constructPhoto = constructPhoto;
@@ -7,6 +7,7 @@ import { Chat } from "./1_chat.js";
7
7
  import { User } from "./1_user.js";
8
8
  import { InlineKeyboardMarkup } from "./2_inline_keyboard_markup.js";
9
9
  import { ReplyKeyboardMarkup } from "./2_reply_keyboard_markup.js";
10
+ import { Photo } from "./1_photo.js";
10
11
  export interface Message {
11
12
  id: number;
12
13
  threadId?: number;
@@ -35,6 +36,7 @@ export interface Message {
35
36
  hasMediaSpoiler?: boolean;
36
37
  views?: number;
37
38
  replyMarkup?: InlineKeyboardMarkup | ReplyKeyboardMarkup | ReplyKeyboardRemove | ForceReply;
39
+ photo?: Photo;
38
40
  }
39
41
  export declare function constructMessage(message_: types.Message, getEntity: {
40
42
  (peer: types.PeerUser): MaybePromise<types.User | null>;
@@ -35,6 +35,7 @@ const _1_chat_js_1 = require("./1_chat.js");
35
35
  const _1_user_js_1 = require("./1_user.js");
36
36
  const _2_inline_keyboard_markup_js_1 = require("./2_inline_keyboard_markup.js");
37
37
  const _2_reply_keyboard_markup_js_1 = require("./2_reply_keyboard_markup.js");
38
+ const _1_photo_js_1 = require("./1_photo.js");
38
39
  const d = (0, deps_js_1.debug)("types/Message");
39
40
  async function constructMessage(message_, getEntity, getMessage) {
40
41
  let chat_ = null;
@@ -199,6 +200,13 @@ async function constructMessage(message_, getEntity, getMessage) {
199
200
  (0, _0_control_js_1.UNREACHABLE)();
200
201
  }
201
202
  }
203
+ if (message_.media) {
204
+ if (message_.media instanceof types.MessageMediaPhoto) {
205
+ if (message_.media.photo instanceof types.Photo) {
206
+ message.photo = (0, _1_photo_js_1.constructPhoto)(message_.media.photo);
207
+ }
208
+ }
209
+ }
202
210
  return (0, _0_object_js_1.cleanObject)(message);
203
211
  }
204
212
  exports.constructMessage = constructMessage;