Arch refactor #14
14 changed files with 40 additions and 26 deletions
|
@ -1,4 +1,4 @@
|
|||
const { MemoryStorage } = require('@mtcute/core/storage/memory.js')
|
||||
const { MemoryStorage } = require('@mtcute/core')
|
||||
const { LogManager } = require('@mtcute/core/utils.js')
|
||||
|
||||
exports.getApiParams = () => {
|
||||
|
|
|
@ -1,4 +1,4 @@
|
|||
import { MemoryStorage } from '@mtcute/core/storage/memory.js'
|
||||
import { MemoryStorage } from '@mtcute/core'
|
||||
import { LogManager } from '@mtcute/core/utils.js'
|
||||
|
||||
export const getApiParams = () => {
|
||||
|
|
|
@ -2,7 +2,6 @@
|
|||
"name": "mtcute-e2e",
|
||||
"private": true,
|
||||
"dependencies": {
|
||||
"@mtcute/client": "*",
|
||||
"@mtcute/core": "*",
|
||||
"@mtcute/crypto-node": "*",
|
||||
"@mtcute/dispatcher": "*",
|
||||
|
|
|
@ -1,7 +1,7 @@
|
|||
import { expect } from 'chai'
|
||||
import { describe, it } from 'mocha'
|
||||
|
||||
import { MtUnsupportedError, TelegramClient } from '@mtcute/client'
|
||||
import { BaseTelegramClient, MtUnsupportedError, TelegramClient } from '@mtcute/core'
|
||||
|
||||
import { getApiParams } from '../utils.js'
|
||||
|
||||
|
@ -14,11 +14,12 @@ describe('1. authorization', function () {
|
|||
this.timeout(300_000)
|
||||
|
||||
it('should authorize in default dc', async () => {
|
||||
const tg = new TelegramClient(getApiParams('dc2.session'))
|
||||
const base = new BaseTelegramClient(getApiParams('dc2.session'))
|
||||
const tg = new TelegramClient({ client: base })
|
||||
|
||||
// reset storage just in case
|
||||
await tg.storage.load?.()
|
||||
await tg.storage.reset(true)
|
||||
await base.mt.storage.load()
|
||||
await base.storage.clear(true)
|
||||
|
||||
while (true) {
|
||||
const phone = `999662${getAccountId()}`
|
||||
|
@ -45,11 +46,12 @@ describe('1. authorization', function () {
|
|||
})
|
||||
|
||||
it('should authorize in dc 1', async () => {
|
||||
const tg = new TelegramClient(getApiParams('dc1.session'))
|
||||
const base = new BaseTelegramClient(getApiParams('dc1.session'))
|
||||
const tg = new TelegramClient({ client: base })
|
||||
|
||||
// reset storage just in case
|
||||
await tg.storage.load?.()
|
||||
await tg.storage.reset(true)
|
||||
await base.mt.storage.load()
|
||||
await base.mt.storage.clear(true)
|
||||
|
||||
while (true) {
|
||||
const phone = `999661${getAccountId()}`
|
||||
|
|
|
@ -1,7 +1,7 @@
|
|||
import { expect } from 'chai'
|
||||
import { describe, it } from 'mocha'
|
||||
|
||||
import { TelegramClient } from '@mtcute/client'
|
||||
import { TelegramClient } from '@mtcute/core'
|
||||
|
||||
import { getApiParams } from '../utils.js'
|
||||
|
||||
|
|
|
@ -3,7 +3,7 @@ import { expect } from 'chai'
|
|||
import { createHash } from 'crypto'
|
||||
import { describe, it } from 'mocha'
|
||||
|
||||
import { FileDownloadLocation, TelegramClient, Thumbnail } from '@mtcute/client'
|
||||
import { FileDownloadLocation, TelegramClient, Thumbnail } from '@mtcute/core'
|
||||
import { sleep } from '@mtcute/core/utils.js'
|
||||
|
||||
import { getApiParams } from '../utils.js'
|
||||
|
|
|
@ -1,7 +1,7 @@
|
|||
import { expect } from 'chai'
|
||||
import { describe, it } from 'mocha'
|
||||
|
||||
import { Message, TelegramClient } from '@mtcute/client'
|
||||
import { Message, TelegramClient } from '@mtcute/core'
|
||||
|
||||
import { getApiParams, waitFor } from '../utils.js'
|
||||
|
||||
|
|
|
@ -1,12 +1,11 @@
|
|||
// eslint-disable-next-line no-restricted-imports
|
||||
import { join } from 'path'
|
||||
|
||||
import { BaseTelegramClientOptions, MaybeAsync } from '@mtcute/core'
|
||||
import { MemoryStorage } from '@mtcute/core/storage/memory.js'
|
||||
import { MaybeAsync, MemoryStorage } from '@mtcute/core'
|
||||
import { LogManager, sleep } from '@mtcute/core/utils.js'
|
||||
import { SqliteStorage } from '@mtcute/sqlite'
|
||||
|
||||
export const getApiParams = (storage?: string): BaseTelegramClientOptions => {
|
||||
export const getApiParams = (storage?: string) => {
|
||||
if (!process.env.API_ID || !process.env.API_HASH) {
|
||||
throw new Error('API_ID and API_HASH env variables must be set')
|
||||
}
|
||||
|
|
|
@ -684,6 +684,8 @@ on(name: string, handler: (...args: any[]) => void): this\n`)
|
|||
'notifyLoggedOut',
|
||||
'notifyChannelOpened',
|
||||
'notifyChannelClosed',
|
||||
'startUpdatesLoop',
|
||||
'stopUpdatesLoop',
|
||||
'call',
|
||||
'importSession',
|
||||
'exportSession',
|
||||
|
|
|
@ -132,6 +132,14 @@ export class BaseTelegramClient implements ITelegramClient {
|
|||
return this.updates?.notifyChannelClosed(channelId) ?? false
|
||||
}
|
||||
|
||||
async startUpdatesLoop(): Promise<void> {
|
||||
await this.updates?.startLoop()
|
||||
}
|
||||
|
||||
async stopUpdatesLoop(): Promise<void> {
|
||||
this.updates?.stopLoop()
|
||||
}
|
||||
|
||||
/**
|
||||
* Make an RPC call
|
||||
*
|
||||
|
|
|
@ -5909,6 +5909,12 @@ TelegramClient.prototype.notifyChannelOpened = function (...args) {
|
|||
TelegramClient.prototype.notifyChannelClosed = function (...args) {
|
||||
return this._client.notifyChannelClosed(...args)
|
||||
}
|
||||
TelegramClient.prototype.startUpdatesLoop = function (...args) {
|
||||
return this._client.startUpdatesLoop(...args)
|
||||
}
|
||||
TelegramClient.prototype.stopUpdatesLoop = function (...args) {
|
||||
return this._client.stopUpdatesLoop(...args)
|
||||
}
|
||||
TelegramClient.prototype.call = function (...args) {
|
||||
return this._client.call(...args)
|
||||
}
|
||||
|
|
|
@ -22,6 +22,8 @@ export interface ITelegramClient {
|
|||
notifyLoggedOut(): Promise<void>
|
||||
notifyChannelOpened(channelId: number, pts?: number): Promise<boolean>
|
||||
notifyChannelClosed(channelId: number): Promise<boolean>
|
||||
startUpdatesLoop(): Promise<void>
|
||||
stopUpdatesLoop(): Promise<void>
|
||||
call<T extends tl.RpcMethod>(
|
||||
message: MustEqual<T, tl.RpcMethod>,
|
||||
params?: RpcCallOptions,
|
||||
|
@ -42,12 +44,6 @@ export interface ITelegramClient {
|
|||
getPoolSize(kind: ConnectionKind, dcId?: number): Promise<number>
|
||||
getPrimaryDcId(): Promise<number>
|
||||
|
||||
computeSrpParams(
|
||||
request: tl.account.RawPassword,
|
||||
password: string,
|
||||
): Promise<tl.RawInputCheckPasswordSRP>
|
||||
computeNewPasswordHash(
|
||||
algo: tl.TypePasswordKdfAlgo,
|
||||
password: string,
|
||||
): Promise<Uint8Array>
|
||||
computeSrpParams(request: tl.account.RawPassword, password: string): Promise<tl.RawInputCheckPasswordSRP>
|
||||
computeNewPasswordHash(algo: tl.TypePasswordKdfAlgo, password: string): Promise<Uint8Array>
|
||||
}
|
||||
|
|
|
@ -38,9 +38,9 @@ export class TelegramStorageManager {
|
|||
this.mt._serviceOptions,
|
||||
)
|
||||
|
||||
async clear() {
|
||||
async clear(withAuthKeys = false) {
|
||||
await this.provider.peers.deleteAll()
|
||||
await this.provider.refMessages.deleteAll()
|
||||
await this.mt.clear()
|
||||
await this.mt.clear(withAuthKeys)
|
||||
}
|
||||
}
|
||||
|
|
|
@ -100,4 +100,6 @@ export class TelegramWorkerPort<Custom extends WorkerCustomMethods> implements I
|
|||
readonly getPrimaryDcId = this._bind('getPrimaryDcId')
|
||||
readonly computeSrpParams = this._bind('computeSrpParams')
|
||||
readonly computeNewPasswordHash = this._bind('computeNewPasswordHash')
|
||||
readonly startUpdatesLoop = this._bind('startUpdatesLoop')
|
||||
readonly stopUpdatesLoop = this._bind('stopUpdatesLoop')
|
||||
}
|
||||
|
|
Loading…
Reference in a new issue