SHA256
46 lines
1.1 KiB
JavaScript
46 lines
1.1 KiB
JavaScript
import { openArweaveAttachmentManager } from './arweave-attachment-manager.js';
|
|
import { saveProfileAvatarArweave } from '../services/user-profile-params.js';
|
|
|
|
export async function openAvatarWizard({
|
|
login,
|
|
storagePwd,
|
|
gateway,
|
|
navigate,
|
|
onAvatarSaved,
|
|
onStatus,
|
|
} = {}) {
|
|
const cleanLogin = String(login || '').trim();
|
|
const cleanStoragePwd = String(storagePwd || '').trim();
|
|
const cleanGateway = String(gateway || '').trim();
|
|
if (!cleanLogin || !cleanStoragePwd) {
|
|
throw new Error('Нет активной сессии.');
|
|
}
|
|
|
|
const item = await openArweaveAttachmentManager({
|
|
login: cleanLogin,
|
|
storagePwd: cleanStoragePwd,
|
|
gateway: cleanGateway,
|
|
navigate,
|
|
mode: 'avatar',
|
|
historyPurpose: 'avatar',
|
|
});
|
|
|
|
if (!item?.ar || !item?.sha256) return false;
|
|
|
|
if (typeof onStatus === 'function') {
|
|
onStatus('Сохраняем аватар в профиль...');
|
|
}
|
|
|
|
await saveProfileAvatarArweave(cleanLogin, item.ar, item.sha256);
|
|
|
|
if (typeof onAvatarSaved === 'function') {
|
|
await onAvatarSaved(item);
|
|
}
|
|
|
|
if (typeof onStatus === 'function') {
|
|
onStatus('');
|
|
}
|
|
|
|
return true;
|
|
}
|