2.1.0 • Published 2 years ago

@tgsnake/fileid v2.1.0

Weekly downloads
-
License
MIT
Repository
github
Last release
2 years ago

@tgsnake/fileid

Core framework for creating fileId for tgsnake.

This framework is ported or inspired from pyrogram, big thank for that framework.

Another framework it should be can using this framework, not only a tgsnake.

The advantages we offer

  • Stable
    As long as we use this, the framework works fine without any problems. If a problem is found we will fix it as soon as possible.
  • Fast
    This framework using simple algorithm to make it fast compared to other frameworks.
  • Zero Dependencies
    With zero dependencies it make this framework fast and You don't have to worry about the security of this framework.
  • Typescript Support
    This framework is build with typescript, so for typescript user no need to worry about types, because we already have it.
  • Url Safe
    We are using base64url than base64 for encoding the file id, which base64url more safe when you using for Url. see : https://stackoverflow.com/a/55389212/16600138
  • Work with another framework fileId generator
    This framework also supported file id of :

    • Telethon
    • Pyrogram
    • Bot Api
    • tg-file-id
    • Another framework should be we supported too.

    We just tester for decoding file id from that framework, nvm work for re-sending the documents, but you can try. should be work too..

Installation

Installing this framework with npm

  cd my-project
  npm install @tgsnake/fileid

Installing this framework with yarn

  cd my-project
  yarn add @tgsnake/fileid

Usage/Examples

const { FileId, FileType, ThumbnailSource, FileTypeUniqueId } = require('@tgsnake/fileid');
const raw = FileId.decodeFileId(
  'CAACAgUAAxkBAAICjWKI4c8Zg7eo6bSbtAV_bVcFa9DmAAJ3BgACuNvZV0cotKoi35kTHgQ'
);
console.log(fileId);

Documentation

Options

This options is using for generating unique file id or file id. Pass this options when you create a new class from FileId.

fieldtyperequireddescription
versionnumbertrueThe major version of bot api file id. Usually is 4.
subVersionnumbertrueThe minor version of bot api file id. Usually same with tdlib version or 32.
dcIdnumbertrueThe data center id, where that file is stored.
fileTypeenum/number of FileTypetrueThe enum/number of FileType. recommend to use enum.
idbiginttrueThe id of file.
accessHashbiginttrueThe hash to access that file.
fileReferenceBufferoptionalFile reference of that file.
urlstringoptionalIf the file has web location, fill this with url of that web location.
volumeIdbigintoptionalIf the file has volume id, fill this with it. or if file doesn't have a volume id, fill this with `BigInt(0). This is required when you try to make file id of photo/thumbnail.
localIdnumberoptionalIf the file has local id, fill this with it. or if file doesn't have a local id, fill this with 0. This is required when you try to make file id of photo/thumbnail.
secretbigintoptionalThe secret key from file, if file doesn't have a secret key fill this with BigInt(0). This is required when you try to make ThumbnailSource.LEGACY
chatIdbigintoptionalIf you want to make a file id of photo profil, fill this with BigInt of chatId.
chatAccessHashbigintoptionalIf you want to make a file id of photo profil, fill this with BigInt of accessHash that chat, or BigInt(0) it must be work when you doesn't have a accessHash of that chat.
stickerSetIdbigintoptionalThe id of that sticker set.
stickerSetAccessHashbigintoptionalThe accessHash of that sticker set. `BigInt(0) ot must be work when you doesn't have a accessHash of that sticker set.
thumbnailSourceenum/number of ThumbnailSourceoptionalThe enum/number of ThumbnailSource. recommended to use enum.
thumbnailFileTypeenum/number of FileTypeoptionalThe enum/number of FileType. recommend to use enum.
thumbnailSizestringoptionalThe size of that thumbnail. see : https://core.telegram.org/api/files#image-thumbnail-types
fileTypeUniqueIdenum/number of FileTypeUniqueIdoptionalOnly for generating uniqueFileId. The enum/number of FileTypeUniqueId. recommended to use enum.

Enums

FileType

enum FileType {
  THUMBNAIL = 0,
  CHAT_PHOTO = 1, // ProfilePhoto
  PHOTO = 2,
  VOICE = 3, // VoiceNote
  VIDEO = 4,
  DOCUMENT = 5,
  ENCRYPTED = 6,
  TEMP = 7,
  STICKER = 8,
  AUDIO = 9,
  ANIMATION = 10,
  ENCRYPTED_THUMBNAIL = 11,
  WALLPAPER = 12,
  VIDEO_NOTE = 13,
  SECURE_RAW = 14,
  SECURE = 15,
  BACKGROUND = 16,
  DOCUMENT_AS_FILE = 17,
}

Importing this enum :

const { FileType } = require('@tgsnake/fileid');

ThumbnailSource

enum ThumbnailSource {
  LEGACY = 0,
  THUMBNAIL = 1,
  CHAT_PHOTO_SMALL = 2, // DialogPhotoSmall
  CHAT_PHOTO_BIG = 3, // DialogPhotoBig
  STICKER_SET_THUMBNAIL = 4,
}

Importing this enum :

const { ThumbnailSource } = require('@tgsnake/fileid');

FileTypeUniqueId

enum FileTypeUniqueId {
  WEB = 0,
  PHOTO = 1,
  DOCUMENT = 2,
  SECURE = 3,
  ENCRYPTED = 4,
  TEMP = 5,
}

Importing this enum :

const { FileTypeUniqueId } = require('@tgsnake/fileid');

Generating file id.

for generating file id, you can use .encodeFileId method. And for decoding using .decodeFileIdmethod.

const { FileId, FileType, ThumbnailSource, FileTypeUniqueId } = require("@tgsnake/fileid")
const fileId = FileId.encodeFileId({
  version : 4,
  subVersion : 32,
  fileType : FileType.STICKER,
  id : ,// fill this with document id
  accessHash : , // fill this with document accessHash
  fileReference : , // fill this with document fileReference
  dcId : // fill this with document dcId
  // fill with another options.
})
console.log(fileId)

Generating file id and uniqueFileId

for generating only unique file id, you can use .encodeUniqueId method. And for decoding using decodeUniqueId method.

const { FileId, FileType, ThumbnailSource, FileTypeUniqueId } = require("@tgsnake/fileid")
const fileId = FileId.encode({
  version : 4,
  subVersion : 32,
  fileType : FileType.STICKER,
  fileTypeUniqueId : FileTypeUniqueId.DOCUMENT,
  id : ,// fill this with document id
  accessHash : , // fill this with document accessHash
  fileReference : , // fill this with document fileReference
  dcId : // fill this with document dcId
  // fill with another options.
})
console.log(fileId)

License

MIT


Build With ❤️ by tgsnake dev.

2.0.2

2 years ago

2.1.0

2 years ago

2.0.1

3 years ago

2.0.0

3 years ago

1.0.1

3 years ago

1.0.0

3 years ago