fix(publishing): normalize media links to https

This commit is contained in:
Tommaso Casaburi
2026-04-21 14:23:52 +07:00
parent 80e0cabf01
commit fb19ee47c8
7 changed files with 97 additions and 13 deletions
@@ -66,6 +66,19 @@ describe('publish stores', () => {
expect(usePublishPostStore.getState().title).toBeUndefined();
});
it('normalizes post publish links to https before building the payload', () => {
usePublishPostStore.getState().setPublishPostStore({
content: 'post body',
link: 'http://i.imgur.com/YpB7qfa.jpg',
communityAddress: 'history-posting.bso',
title: 'Hello',
});
const state = usePublishPostStore.getState();
expect(state.link).toBe('https://i.imgur.com/YpB7qfa.jpg');
expect(state.publishCommentOptions.link).toBe('https://i.imgur.com/YpB7qfa.jpg');
});
it('usePublishReplyStore stores reply data per parentCid and resets a single thread', () => {
const comment: PublishReplyInput = {
author: { address: '0x123', displayName: 'Author Name', role: 'mod' },
@@ -97,4 +110,17 @@ describe('publish stores', () => {
expect(usePublishReplyStore.getState().publishCommentOptions['parent-1']).toBeUndefined();
expect(usePublishReplyStore.getState().content['parent-1']).toBeUndefined();
});
it('normalizes reply publish links to https before building the payload', () => {
usePublishReplyStore.getState().setPublishReplyStore({
content: 'reply body',
link: 'http://i.imgur.com/YpB7qfa.jpg',
parentCid: 'parent-1',
communityAddress: 'history-posting.bso',
});
const state = usePublishReplyStore.getState();
expect(state.link['parent-1']).toBe('https://i.imgur.com/YpB7qfa.jpg');
expect(state.publishCommentOptions['parent-1']?.link).toBe('https://i.imgur.com/YpB7qfa.jpg');
});
});
+3 -1
View File
@@ -2,6 +2,7 @@ import { ChallengeVerification, Comment, PublishCommentOptions } from '@bitsocia
import { create } from 'zustand';
import { alertChallengeVerificationFailed } from '../lib/utils/challenge-utils';
import { getCommentCommunityAddress } from '../lib/utils/comment-utils';
import { normalizePublishURL } from '../lib/utils/url-utils';
type SubmitState = {
author?: any | undefined;
@@ -27,7 +28,8 @@ const usePublishPostStore = create<SubmitState>((set) => ({
publishCommentOptions: {},
setPublishPostStore: (comment: Comment) =>
set(() => {
const { author, content, link, spoiler, title } = comment;
const { author, content, spoiler, title } = comment;
const link = comment.link ? normalizePublishURL(comment.link) : undefined;
const communityAddress = getCommentCommunityAddress(comment);
const displayName = 'displayName' in comment ? comment.displayName || undefined : author?.displayName;
+3 -1
View File
@@ -2,6 +2,7 @@ import { ChallengeVerification, Comment, PublishCommentOptions } from '@bitsocia
import { create } from 'zustand';
import { alertChallengeVerificationFailed } from '../lib/utils/challenge-utils';
import { getCommentCommunityAddress } from '../lib/utils/comment-utils';
import { normalizePublishURL } from '../lib/utils/url-utils';
type ReplyState = {
author: { [parentCid: string]: any | undefined };
@@ -24,7 +25,8 @@ const usePublishReplyStore = create<ReplyState>((set) => ({
setPublishReplyStore: (comment: Comment) =>
set((state) => {
const { parentCid, author, content, link, spoiler } = comment;
const { parentCid, author, content, spoiler } = comment;
const link = comment.link ? normalizePublishURL(comment.link) : undefined;
const communityAddress = getCommentCommunityAddress(comment);
const displayName = 'displayName' in comment ? comment.displayName || undefined : author?.displayName;