SHA256
Полностью поддерживает английский язык
This commit is contained in:
@@ -1,18 +1,19 @@
|
||||
import { t } from '../i18n/index.js';
|
||||
import { authService, state } from '../state.js';
|
||||
import { validateArweaveTxId, validateSha256Hex } from './arweave-file-service.js';
|
||||
import { buildAvatarReference, parseAvatarReference } from './avatar-reference.js';
|
||||
import { CITY_MAX_LENGTH, CITY_PARAM, CITY_SUGGESTIONS } from './cities.js';
|
||||
|
||||
export const profileFieldDefs = [
|
||||
{ key: 'first_name', readKeys: ['first_name'], label: 'Имя', placeholder: 'Введите имя' },
|
||||
{ key: 'last_name', readKeys: ['last_name'], label: 'Фамилия', placeholder: 'Введите фамилию' },
|
||||
{ key: 'first_name', readKeys: ['first_name'], get label() { return t('remaining.profile_fields.first_name'); }, get placeholder() { return t('remaining.profile_fields.enter_your_first_name'); } },
|
||||
{ key: 'last_name', readKeys: ['last_name'], get label() { return t('remaining.profile_fields.last_name'); }, get placeholder() { return t('remaining.profile_fields.enter_your_last_name'); } },
|
||||
// Город виден в профиле и собирает знакомых в раскладке «Города» на карте связей.
|
||||
{ key: CITY_PARAM, readKeys: [CITY_PARAM], label: 'Город', placeholder: 'Например, Казань', maxLength: CITY_MAX_LENGTH, suggestions: CITY_SUGGESTIONS },
|
||||
{ key: 'address', readKeys: ['address'], label: 'Адрес', placeholder: 'Улица, дом' },
|
||||
{ key: 'web', readKeys: ['web'], label: 'Ссылки', placeholder: 'Сайт, профиль или другая ссылка' },
|
||||
{ key: 'phone', readKeys: ['phone'], label: 'Телефон', placeholder: '+7 ...' },
|
||||
{ key: 'about', readKeys: ['about'], label: 'О себе', placeholder: 'Коротко расскажите о себе', maxLength: 160, multiline: true },
|
||||
{ key: 'spiritual_path', readKeys: ['spiritual_path'], label: 'Духовный путь', placeholder: 'Расскажите о своём духовном пути, опыте, практиках и взглядах', maxLength: 5000, multiline: true },
|
||||
{ key: CITY_PARAM, readKeys: [CITY_PARAM], get label() { return t('remaining.profile_fields.city'); }, get placeholder() { return t('remaining.profile_fields.for_example_london'); }, maxLength: CITY_MAX_LENGTH, suggestions: CITY_SUGGESTIONS },
|
||||
{ key: 'address', readKeys: ['address'], get label() { return t('remaining.profile_fields.address'); }, get placeholder() { return t('remaining.profile_fields.street_and_house_number'); } },
|
||||
{ key: 'web', readKeys: ['web'], get label() { return t('remaining.profile_fields.links'); }, get placeholder() { return t('remaining.profile_fields.website_profile_or_other_link'); } },
|
||||
{ key: 'phone', readKeys: ['phone'], get label() { return t('remaining.profile_fields.phone'); }, placeholder: '+7 ...' },
|
||||
{ key: 'about', readKeys: ['about'], get label() { return t('remaining.profile_fields.about_me'); }, get placeholder() { return t('remaining.profile_fields.tell_us_a_little_about_yourself'); }, maxLength: 160, multiline: true },
|
||||
{ key: 'spiritual_path', readKeys: ['spiritual_path'], get label() { return t('remaining.profile_fields.spiritual_path'); }, get placeholder() { return t('remaining.profile_fields.share_your_spiritual_journey_experience_practices_and_view'); }, maxLength: 5000, multiline: true },
|
||||
];
|
||||
|
||||
export const profileToggleDefs = []; // legacy boolean toggles are no longer used by the new UI.
|
||||
@@ -60,7 +61,7 @@ function normalizeGenderValue(value) {
|
||||
async function getStoragePwd() {
|
||||
const storagePwd = state.session.storagePwdInMemory;
|
||||
if (!storagePwd) {
|
||||
throw new Error('Нет storagePwd в памяти сессии. Выполните вход заново.');
|
||||
throw new Error(t('remaining.profile_errors.session_password_is_unavailable_sign_in_again'));
|
||||
}
|
||||
return storagePwd;
|
||||
}
|
||||
@@ -131,8 +132,8 @@ export async function loadProfileSnapshot(login) {
|
||||
// Legacy shine=no is intentionally ignored. Legacy official=yes/no is not read at all.
|
||||
|
||||
const toggles = [
|
||||
{ key: 'account_role', label: 'Роль аккаунта', enabled: accountRole === PROFILE_ACCOUNT_ROLE_PRIMARY, rawValue: accountRole, timeMs: latestAccountRole?.timeMs || 0 },
|
||||
{ key: 'shine', label: 'Сияние', enabled: shineStatus === PROFILE_SHINE_SHINING, rawValue: shineStatus, timeMs: latestShine?.timeMs || 0 },
|
||||
{ key: 'account_role', get label() { return t('remaining.profile_fields.account_role'); }, enabled: accountRole === PROFILE_ACCOUNT_ROLE_PRIMARY, rawValue: accountRole, timeMs: latestAccountRole?.timeMs || 0 },
|
||||
{ key: 'shine', get label() { return t('remaining.profile_fields.shine'); }, enabled: shineStatus === PROFILE_SHINE_SHINING, rawValue: shineStatus, timeMs: latestShine?.timeMs || 0 },
|
||||
];
|
||||
|
||||
const latestGender = loadLatestByAliasesFromItems(items, ['gender']);
|
||||
@@ -186,10 +187,10 @@ export async function saveProfileStatus(login, key, value) {
|
||||
const cleanKey = String(key || '').trim();
|
||||
const cleanValue = String(value || '').trim().toLowerCase();
|
||||
if (cleanKey === 'account_role' && ![PROFILE_ACCOUNT_ROLE_PRIMARY, PROFILE_ACCOUNT_ROLE_NON_VOTING].includes(cleanValue)) {
|
||||
throw new Error('Некорректное значение account_role');
|
||||
throw new Error(t('remaining.profile_errors.invalid_account_role_value'));
|
||||
}
|
||||
if (cleanKey === 'shine' && ![PROFILE_SHINE_SHINING, PROFILE_SHINE_UNKNOWN, PROFILE_SHINE_NOT_INTERESTED].includes(cleanValue)) {
|
||||
throw new Error('Некорректное значение shine');
|
||||
throw new Error(t('remaining.profile_errors.invalid_shine_value'));
|
||||
}
|
||||
const storagePwd = await getStoragePwd();
|
||||
await authService.addBlockUserParam({ login, param: cleanKey, value: cleanValue, storagePwd });
|
||||
@@ -198,7 +199,7 @@ export async function saveProfileStatus(login, key, value) {
|
||||
// Kept only for old callers outside the current UI. New code must use saveProfileStatus().
|
||||
export async function saveProfileToggle(login, key, enabled) {
|
||||
if (key === 'shine') return saveProfileStatus(login, 'shine', enabled ? PROFILE_SHINE_SHINING : PROFILE_SHINE_UNKNOWN);
|
||||
if (key === 'official') throw new Error('Параметр official устарел. Используйте account_role.');
|
||||
if (key === 'official') throw new Error(t('remaining.profile_errors.the_official_parameter_is_deprecated_use_account_role'));
|
||||
throw new Error(`Неизвестный legacy toggle: ${key}`);
|
||||
}
|
||||
|
||||
@@ -217,8 +218,8 @@ export async function saveProfileAvatar(login, avatar) {
|
||||
const cleanAr = String(avatar?.ar || '').trim();
|
||||
const cleanSha = String(avatar?.sha256 || avatar?.sha256Hex || '').trim().toLowerCase();
|
||||
const size = Number(avatar?.size || 0);
|
||||
if (cleanAr && !validateArweaveTxId(cleanAr)) throw new Error('Некорректный Transaction ID Arweave');
|
||||
if (!validateSha256Hex(cleanSha)) throw new Error('Некорректный SHA256 хэш аватара');
|
||||
if (cleanAr && !validateArweaveTxId(cleanAr)) throw new Error(t('remaining.profile_errors.invalid_arweave_transaction_id'));
|
||||
if (!validateSha256Hex(cleanSha)) throw new Error(t('remaining.profile_errors.invalid_avatar_sha_256_hash'));
|
||||
await saveProfileParamBlock(login, 'ava', buildAvatarReference({ ar: cleanAr, sha256: cleanSha, size }));
|
||||
}
|
||||
|
||||
|
||||
Reference in New Issue
Block a user