Compare commits
2 Commits
74844da4ae
...
5d59adb7d2
Author | SHA1 | Date | |
---|---|---|---|
5d59adb7d2 | |||
281c4a262b |
@ -1,5 +1,7 @@
|
||||
import asyncio
|
||||
import functools
|
||||
import gc
|
||||
from concurrent.futures import ProcessPoolExecutor
|
||||
|
||||
import telebot
|
||||
from sqlalchemy.future import Engine
|
||||
@ -305,7 +307,7 @@ async def _add_account5(
|
||||
password=data["passwd"],
|
||||
)
|
||||
|
||||
encrypted_account = encryption.other_accounts.encrypt(
|
||||
encrypted_account = encryption.accounts.encrypt(
|
||||
account,
|
||||
text,
|
||||
)
|
||||
@ -391,7 +393,7 @@ async def _get_account3(
|
||||
)
|
||||
|
||||
account = database.get.get_account_info(engine, mes.from_user.id, name)
|
||||
account = encryption.other_accounts.decrypt(
|
||||
account = encryption.accounts.decrypt(
|
||||
account,
|
||||
text,
|
||||
)
|
||||
@ -534,7 +536,18 @@ async def _export2(
|
||||
)
|
||||
|
||||
accounts = database.get.get_all_accounts(engine, mes.from_user.id)
|
||||
accounts = encryption.other_accounts.decrypt_multiple(accounts, text)
|
||||
with ProcessPoolExecutor() as pool:
|
||||
loop = asyncio.get_running_loop()
|
||||
tasks = []
|
||||
for account in accounts:
|
||||
function = functools.partial(
|
||||
encryption.accounts.decrypt,
|
||||
account,
|
||||
text,
|
||||
)
|
||||
tasks.append(loop.run_in_executor(pool, function))
|
||||
accounts = await asyncio.gather(*tasks)
|
||||
accounts.sort(key=lambda account: account.name)
|
||||
json_io = accounts_to_json(accounts)
|
||||
await bot.send_document(
|
||||
mes.chat.id,
|
||||
@ -638,7 +651,7 @@ async def _import3(
|
||||
if not check_account(account):
|
||||
failed.append(account.name)
|
||||
continue
|
||||
account = encryption.other_accounts.encrypt(
|
||||
account = encryption.accounts.encrypt(
|
||||
account,
|
||||
text,
|
||||
)
|
||||
|
@ -36,12 +36,8 @@ def get_accounts(
|
||||
|
||||
def get_all_accounts(engine: Engine, user_id: int) -> list[models.Account]:
|
||||
"""Returns a list of accounts of a user"""
|
||||
statement = (
|
||||
sqlmodel.select(models.Account)
|
||||
.where(
|
||||
models.Account.user_id == user_id,
|
||||
)
|
||||
.order_by(models.Account.name)
|
||||
statement = sqlmodel.select(models.Account).where(
|
||||
models.Account.user_id == user_id,
|
||||
)
|
||||
with sqlmodel.Session(engine) as session:
|
||||
result = session.exec(statement).fetchall()
|
||||
|
@ -1,3 +1,3 @@
|
||||
from . import master_pass, other_accounts
|
||||
from . import accounts, master_pass
|
||||
|
||||
__all__ = ["master_pass", "other_accounts"]
|
||||
__all__ = ["master_pass", "accounts"]
|
||||
|
@ -1,6 +1,5 @@
|
||||
import base64
|
||||
import os
|
||||
from typing import Iterable, Iterator
|
||||
|
||||
from cryptography.fernet import Fernet
|
||||
from cryptography.hazmat.backends import default_backend
|
||||
@ -71,12 +70,3 @@ def decrypt(
|
||||
login=login,
|
||||
password=password,
|
||||
)
|
||||
|
||||
|
||||
def decrypt_multiple(
|
||||
accounts: Iterable[Account], master_pass: str
|
||||
) -> Iterator[DecryptedAccount]:
|
||||
"""Decrypts an iterable of accounts using master_pass and
|
||||
returns an Iterator of decrypted accounts"""
|
||||
for account in accounts:
|
||||
yield decrypt(account, master_pass)
|
Reference in New Issue
Block a user