SHA256
Полностью поддерживает английский язык
This commit is contained in:
@@ -1,3 +1,4 @@
|
||||
import { t } from '../i18n/index.js';
|
||||
import {
|
||||
buildArweaveDataUrl,
|
||||
sha256HexFromArrayBuffer,
|
||||
@@ -14,7 +15,7 @@ const MAX_BYTES = 50 * 1024 * 1024;
|
||||
function openDb() {
|
||||
return new Promise((resolve, reject) => {
|
||||
if (typeof indexedDB === 'undefined') {
|
||||
reject(new Error('IndexedDB недоступен'));
|
||||
reject(new Error(t('remaining.avatar_errors.indexeddb_is_unavailable')));
|
||||
return;
|
||||
}
|
||||
const request = indexedDB.open(DB_NAME, DB_VERSION);
|
||||
@@ -25,7 +26,7 @@ function openDb() {
|
||||
}
|
||||
};
|
||||
request.onsuccess = () => resolve(request.result);
|
||||
request.onerror = () => reject(request.error || new Error('Ошибка открытия IndexedDB'));
|
||||
request.onerror = () => reject(request.error || new Error(t('remaining.avatar_errors.could_not_open_indexeddb')));
|
||||
});
|
||||
}
|
||||
|
||||
@@ -37,7 +38,7 @@ async function withStore(mode, runner) {
|
||||
const store = tx.objectStore(STORE);
|
||||
const result = runner(store, tx, resolve, reject);
|
||||
if (result !== undefined) resolve(result);
|
||||
tx.onerror = () => reject(tx.error || new Error('Ошибка транзакции IndexedDB'));
|
||||
tx.onerror = () => reject(tx.error || new Error(t('remaining.avatar_errors.indexeddb_transaction_failed')));
|
||||
});
|
||||
} finally {
|
||||
db.close();
|
||||
@@ -48,7 +49,7 @@ async function getRecord(txId) {
|
||||
return withStore('readonly', (store, _tx, resolve, reject) => {
|
||||
const req = store.get(txId);
|
||||
req.onsuccess = () => resolve(req.result || null);
|
||||
req.onerror = () => reject(req.error || new Error('Ошибка чтения кэша аватарки'));
|
||||
req.onerror = () => reject(req.error || new Error(t('remaining.avatar_errors.could_not_read_avatar_cache')));
|
||||
});
|
||||
}
|
||||
|
||||
@@ -56,7 +57,7 @@ async function putRecord(record) {
|
||||
return withStore('readwrite', (store, tx, resolve, reject) => {
|
||||
store.put(record);
|
||||
tx.oncomplete = () => resolve(true);
|
||||
tx.onerror = () => reject(tx.error || new Error('Ошибка записи кэша аватарки'));
|
||||
tx.onerror = () => reject(tx.error || new Error(t('remaining.avatar_errors.could_not_write_avatar_cache')));
|
||||
});
|
||||
}
|
||||
|
||||
@@ -72,7 +73,7 @@ async function getAllRecords() {
|
||||
return withStore('readonly', (store, _tx, resolve, reject) => {
|
||||
const req = store.getAll();
|
||||
req.onsuccess = () => resolve(Array.isArray(req.result) ? req.result : []);
|
||||
req.onerror = () => reject(req.error || new Error('Ошибка чтения списка кэша аватарок'));
|
||||
req.onerror = () => reject(req.error || new Error(t('remaining.avatar_errors.could_not_read_avatar_cache_entries')));
|
||||
});
|
||||
}
|
||||
|
||||
@@ -81,7 +82,7 @@ async function deleteRecords(keys) {
|
||||
await withStore('readwrite', (store, tx, resolve, reject) => {
|
||||
keys.forEach((key) => store.delete(key));
|
||||
tx.oncomplete = () => resolve(true);
|
||||
tx.onerror = () => reject(tx.error || new Error('Ошибка очистки кэша аватарок'));
|
||||
tx.onerror = () => reject(tx.error || new Error(t('remaining.avatar_errors.could_not_clear_avatar_cache')));
|
||||
});
|
||||
}
|
||||
|
||||
@@ -208,7 +209,7 @@ async function getBlobFromCacheOrGateway({ gateway, txId, expectedSha256Hex = ''
|
||||
export async function getCachedAvatarObjectUrl({ gateway, txId, expectedSha256Hex = '' }) {
|
||||
const cleanTxId = String(txId || '').trim();
|
||||
if (!validateArweaveTxId(cleanTxId)) {
|
||||
throw new Error('Некорректный Transaction ID Arweave');
|
||||
throw new Error(t('remaining.avatar_errors.invalid_arweave_transaction_id'));
|
||||
}
|
||||
const blob = await getBlobFromCacheOrGateway({
|
||||
gateway,
|
||||
@@ -222,6 +223,6 @@ export async function clearAvatarCache() {
|
||||
await withStore('readwrite', (store, tx, resolve, reject) => {
|
||||
store.clear();
|
||||
tx.oncomplete = () => resolve(true);
|
||||
tx.onerror = () => reject(tx.error || new Error('Ошибка очистки кэша аватарок'));
|
||||
tx.onerror = () => reject(tx.error || new Error(t('remaining.avatar_errors.could_not_clear_avatar_cache')));
|
||||
});
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user