Files
SHiNE-server/shine-UI/js/components/avatar-wizard.js
T

45 lines
1.1 KiB
JavaScript

import { t } from '../i18n/index.js';
import { openChannelAttachmentManager } from './channel-attachment-manager.js';
import { saveProfileAvatar } 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(t('screens.avatar_wizard.text_001'));
}
const item = await openChannelAttachmentManager({
login: cleanLogin,
storagePwd: cleanStoragePwd,
gateway: cleanGateway,
mode: 'avatar',
});
if (!item?.pr || !item?.size) return false;
if (typeof onStatus === 'function') {
onStatus(t('screens.avatar_wizard.text_002'));
}
await saveProfileAvatar(cleanLogin, item);
if (typeof onAvatarSaved === 'function') {
await onAvatarSaved(item);
}
if (typeof onStatus === 'function') {
onStatus('');
}
return true;
}