SHA256
Добавлен канал личных публикаций
This commit is contained in:
@@ -2123,6 +2123,25 @@ export class AuthService {
|
||||
if (!Number.isFinite(cleanTargetBlockNumber) || cleanTargetBlockNumber < 0) {
|
||||
throw new Error('Invalid target block number');
|
||||
}
|
||||
if (cleanLogin.toLowerCase() === cleanTargetLogin.toLowerCase()) throw new Error('Cannot follow own channel');
|
||||
if (cleanTargetBlockNumber === 0 && unfollow) {
|
||||
const feed = await this.listSubscriptionsFeed(cleanLogin, 1000);
|
||||
const roots = (feed.followedUsersChannels || []).filter(row =>
|
||||
Number(row?.channel?.channelRoot?.blockNumber) === 0
|
||||
&& String(row?.channel?.ownerLogin || '').toLowerCase() === cleanTargetLogin.toLowerCase());
|
||||
const hashes = [...new Set(roots.map(row => normalizeHex32(row?.channel?.channelRoot?.blockHash, ZERO64)))];
|
||||
if (hashes.length) {
|
||||
let result;
|
||||
for (const hash of hashes) {
|
||||
result = await this.addBlockConnectionTarget({
|
||||
login: cleanLogin, storagePwd, subType: MSG_SUBTYPE_CONNECTION_UNFOLLOW,
|
||||
toLogin: cleanTargetLogin, toForkNumber: forkNumberFromBlockchainNameValue(cleanTargetBch),
|
||||
toBlockNumber: 0, toBlockHashHex: hash,
|
||||
});
|
||||
}
|
||||
return result;
|
||||
}
|
||||
}
|
||||
const seedHash = normalizeHex32(targetBlockHashHex, ZERO64);
|
||||
let targetHashHex = seedHash;
|
||||
if (targetHashHex === ZERO64) {
|
||||
@@ -2395,6 +2414,10 @@ export class AuthService {
|
||||
|
||||
let channelSlug = toCanonicalChannelSlug(String(selector?.channelName || selector?.slug || ''));
|
||||
let rootHashHex = normalizeHex32(selector?.channelRootBlockHash, ZERO64);
|
||||
if (lineCode === 0) {
|
||||
channelSlug = 'stories';
|
||||
rootHashHex = await this.resolveHeaderHashForBlockchain(blockchainName);
|
||||
}
|
||||
if (rootHashHex === ZERO64 || !channelSlug) {
|
||||
const ownChannels = await this.listOwnChannelsForBlockchain(login, blockchainName);
|
||||
const rootChannel = ownChannels.find((item) => item.rootBlockNumber === lineCode);
|
||||
@@ -2529,6 +2552,7 @@ export class AuthService {
|
||||
const selector = channel || {};
|
||||
const owner = String(selector?.ownerBlockchainName || '').trim();
|
||||
const root = Number(selector?.channelRootBlockNumber);
|
||||
if (root === 0) throw new Error(channelNameErrorText('reserved_stories'));
|
||||
const metaText = composeChannelMetaText({ title, description, avatar });
|
||||
const key = `channel-line:${cleanLogin}:${owner}:${root}`;
|
||||
|
||||
@@ -2573,6 +2597,7 @@ export class AuthService {
|
||||
const selector = channel || {};
|
||||
const owner = String(selector?.ownerBlockchainName || '').trim();
|
||||
const root = Number(selector?.channelRootBlockNumber);
|
||||
if (root === 0) throw new Error(channelNameErrorText('reserved_stories'));
|
||||
const key = `channel-line:${cleanLogin}:${owner}:${root}`;
|
||||
|
||||
return this.runLineWriteLocked(key, async () => {
|
||||
|
||||
@@ -44,6 +44,7 @@ export function validateChannelDisplayName(value) {
|
||||
}
|
||||
|
||||
const slug = toCanonicalChannelSlug(normalized);
|
||||
if (slug === 'stories') return { ok: false, code: 'reserved_stories', normalized, slug: '' };
|
||||
if (!slug) {
|
||||
return { ok: false, code: 'bad_chars', normalized, slug: '' };
|
||||
}
|
||||
@@ -53,6 +54,8 @@ export function validateChannelDisplayName(value) {
|
||||
|
||||
export function channelNameErrorText(code) {
|
||||
switch (String(code || '').trim()) {
|
||||
case 'reserved_stories':
|
||||
return t('remaining.channels.reserved_stories');
|
||||
case 'blank':
|
||||
return t('remaining.channel_validation.enter_a_channel_name');
|
||||
case 'too_short':
|
||||
|
||||
@@ -1,3 +1,5 @@
|
||||
import { t } from '../i18n/index.js';
|
||||
|
||||
// @ допустим в сегменте пути URL: не маскируем namespace в публичных ссылках.
|
||||
// Остальные специальные символы по-прежнему экранируются.
|
||||
function encodeRoutePart(value = '') {
|
||||
@@ -20,9 +22,12 @@ export function normalizeLogin(value = '') {
|
||||
|
||||
// Видимый адрес канала: <login>@<namespace>/<channel>, без декоративной @ перед логином.
|
||||
// Нормализуем только отображение, не меняем сохранённый идентификатор или URL.
|
||||
export function formatChannelAddress({ ownerLogin = '', channelName = '' } = {}) {
|
||||
export function formatChannelAddress({ ownerLogin = '', channelName = '', channelRootBlockNumber = null } = {}) {
|
||||
const owner = normalizeLogin(ownerLogin);
|
||||
const channel = String(channelName || '').trim();
|
||||
if (channelRootBlockNumber === 0 || (channelRootBlockNumber == null && channel.toLowerCase() === 'stories')) {
|
||||
return owner ? `${owner} (${t('remaining.channels.publications')})` : t('remaining.channels.publications');
|
||||
}
|
||||
return [owner, channel].filter(Boolean).join('/');
|
||||
}
|
||||
|
||||
|
||||
Reference in New Issue
Block a user