mirror of
https://github.com/bitsocialnet/5chan.git
synced 2026-08-03 07:41:04 +02:00
fix(publishing): normalize media links to https
This commit is contained in:
@@ -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');
|
||||
});
|
||||
});
|
||||
|
||||
@@ -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;
|
||||
|
||||
@@ -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;
|
||||
|
||||
Reference in New Issue
Block a user