@gramio/files
Advanced tools
Comparing version 0.0.12 to 0.1.0
import { Readable } from 'node:stream'; | ||
import { APIMethods, APIMethodParams, TelegramInputFile, TelegramInputMediaAnimation, TelegramInputMediaDocument, TelegramInputMediaAudio, TelegramInputMediaPhoto, TelegramInputMediaVideo } from '@gramio/types'; | ||
import { BinaryLike } from 'node:crypto'; | ||
@@ -87,7 +88,7 @@ /** Guard to check is method used for File Uploading */ | ||
*/ | ||
static stream(stream: Readable, filename?: string): Promise<File>; | ||
static stream(stream: Readable | ReadableStream, filename?: string): Promise<File>; | ||
/** | ||
* Method for uploading Media File by Buffer or ArrayBuffer. | ||
* Method for uploading Media File by BinaryLike (Buffer or ArrayBuffer and etc). | ||
*/ | ||
static buffer(buffer: Buffer | ArrayBuffer, filename?: string): File; | ||
static buffer(buffer: Exclude<BinaryLike, string>, filename?: string): File; | ||
/** | ||
@@ -94,0 +95,0 @@ * Method for uploading Media File by URL (also with fetch options). |
import fs from 'node:fs/promises'; | ||
import { basename } from 'node:path'; | ||
import { Readable } from 'node:stream'; | ||
function isBlob(blob) { | ||
if (!blob || typeof blob !== "object") | ||
return false; | ||
if (!blob || typeof blob !== "object") return false; | ||
return blob instanceof Blob || blob instanceof Promise; | ||
@@ -93,4 +93,3 @@ } | ||
const mediaMethod = MEDIA_METHODS[method]; | ||
if (!mediaMethod) | ||
return false; | ||
if (!mediaMethod) return false; | ||
return mediaMethod[0](params); | ||
@@ -109,6 +108,4 @@ } | ||
let file = params[extractorValue.property][extractorValue.name]; | ||
if (file instanceof Promise) | ||
file = await file; | ||
if (!(file instanceof Blob)) | ||
continue; | ||
if (file instanceof Promise) file = await file; | ||
if (!(file instanceof Blob)) continue; | ||
const currentAttachId = attachId++; | ||
@@ -122,6 +119,4 @@ formData.set(`file-${currentAttachId}`, file); | ||
let file = element[extractorValue.name]; | ||
if (file instanceof Promise) | ||
file = await file; | ||
if (!(file instanceof Blob)) | ||
continue; | ||
if (file instanceof Promise) file = await file; | ||
if (!(file instanceof Blob)) continue; | ||
const currentAttachId = attachId++; | ||
@@ -134,10 +129,7 @@ formData.set(`file-${currentAttachId}`, file); | ||
for (let [key, value] of Object.entries(params)) { | ||
if (value instanceof Promise) | ||
value = await value; | ||
if (value instanceof Blob) | ||
formData.append(key, value); | ||
if (value instanceof Promise) value = await value; | ||
if (value instanceof Blob) formData.append(key, value); | ||
else if (typeof value === "object") | ||
formData.append(key, JSON.stringify(value)); | ||
else | ||
formData.append(key, String(value)); | ||
else formData.append(key, String(value)); | ||
} | ||
@@ -229,10 +221,10 @@ return formData; | ||
static async stream(stream, filename = "file.stream") { | ||
const buffer = await convertStreamToBuffer(stream); | ||
const buffer = await convertStreamToBuffer(Readable.from(stream)); | ||
return new File([buffer], filename); | ||
} | ||
/** | ||
* Method for uploading Media File by Buffer or ArrayBuffer. | ||
* Method for uploading Media File by BinaryLike (Buffer or ArrayBuffer and etc). | ||
*/ | ||
static buffer(buffer, filename = "file.buffer") { | ||
return new File([new Blob([buffer])], filename); | ||
return new File([buffer], filename); | ||
} | ||
@@ -244,5 +236,4 @@ /** | ||
const res = await fetch(url, options); | ||
const buffer = await res.arrayBuffer(); | ||
return new File( | ||
[new Blob([buffer])], | ||
[await res.blob()], | ||
filename ?? (typeof url === "string" ? basename(url) : basename(url.pathname)) | ||
@@ -249,0 +240,0 @@ ); |
{ | ||
"name": "@gramio/files", | ||
"main": "./dist/index.cjs", | ||
"module": "./dist/index.js", | ||
"types": "./dist/index.d.ts", | ||
"exports": { | ||
"import": { | ||
"types": "./dist/index.d.ts", | ||
"default": "./dist/index.js" | ||
}, | ||
"require": { | ||
"types": "./dist/index.d.cts", | ||
"default": "./dist/index.cjs" | ||
} | ||
}, | ||
"version": "0.0.12", | ||
"type": "module", | ||
"description": "Set of utils for work with files and Telegram Bot API", | ||
"keywords": [ | ||
"gramio", | ||
"telegram", | ||
"file", | ||
"files", | ||
"upload" | ||
], | ||
"scripts": { | ||
"generate": "bun scripts/generate.ts", | ||
"prepublishOnly": "bunx pkgroll", | ||
"lint": "bunx @biomejs/biome check ./src", | ||
"lint:fix": "bun lint --apply", | ||
"jsr": "bun scripts/release-jsr.ts" | ||
}, | ||
"devDependencies": { | ||
"@biomejs/biome": "1.7.3", | ||
"@types/bun": "^1.1.6", | ||
"@types/node": "^20.14.10", | ||
"mitata": "^0.1.11", | ||
"pkgroll": "^2.1.1", | ||
"prettier": "^3.3.2", | ||
"typescript": "^5.5.3" | ||
}, | ||
"dependencies": { | ||
"@gramio/types": "^7.7.1" | ||
}, | ||
"files": [ | ||
"dist" | ||
], | ||
"license": "MIT" | ||
"name": "@gramio/files", | ||
"main": "./dist/index.cjs", | ||
"module": "./dist/index.js", | ||
"types": "./dist/index.d.ts", | ||
"exports": { | ||
"import": { | ||
"types": "./dist/index.d.ts", | ||
"default": "./dist/index.js" | ||
}, | ||
"require": { | ||
"types": "./dist/index.d.cts", | ||
"default": "./dist/index.cjs" | ||
} | ||
}, | ||
"version": "0.1.0", | ||
"type": "module", | ||
"description": "Set of utils for work with files and Telegram Bot API", | ||
"keywords": ["gramio", "telegram", "file", "files", "upload"], | ||
"scripts": { | ||
"generate": "bun scripts/generate.ts", | ||
"prepublishOnly": "bunx pkgroll", | ||
"lint": "bunx @biomejs/biome check ./src", | ||
"lint:fix": "bun lint --apply", | ||
"jsr": "bun scripts/release-jsr.ts" | ||
}, | ||
"devDependencies": { | ||
"@biomejs/biome": "1.9.2", | ||
"@types/bun": "^1.1.10", | ||
"@types/node": "^22.5.5", | ||
"gramio": "^0.0.50", | ||
"mitata": "^1.0.2", | ||
"pkgroll": "^2.5.0", | ||
"prettier": "^3.3.3", | ||
"typescript": "^5.6.2", | ||
"xlsxtable": "^0.3.1" | ||
}, | ||
"dependencies": { | ||
"@gramio/types": "^7.10.1" | ||
}, | ||
"files": ["dist"], | ||
"license": "MIT" | ||
} |
@@ -10,3 +10,1 @@ # @gramio/files | ||
## Please see [Documentation](https://gramio.dev/files/overview.html) and [API Reference](https://jsr.io/@gramio/files/doc) | ||
Currently, support Telegram Bot API v7.7+ |
Sorry, the diff of this file is not supported yet
Sorry, the diff of this file is not supported yet
License Policy Violation
LicenseThis package is not allowed per your license policy. Review the package's license to ensure compliance.
Found 1 instance in 1 package
License Policy Violation
LicenseThis package is not allowed per your license policy. Review the package's license to ensure compliance.
Found 1 instance in 1 package
Major refactor
Supply chain riskPackage has recently undergone a major refactor. It may be unstable or indicate significant internal changes. Use caution when updating to versions that include significant changes.
Found 1 instance in 1 package
2
25821
9
583
10
Updated@gramio/types@^7.10.1