1- import { checkPermission , generateUniqueId , slugify } from "@courselit/utils" ;
1+ import {
2+ checkPermission ,
3+ extractMediaIDs ,
4+ generateUniqueId ,
5+ slugify ,
6+ } from "@courselit/utils" ;
27import CommunityModel , { InternalCommunity } from "@models/Community" ;
38import constants from "../../config/constants" ;
49import GQLContext from "../../models/GQLContext" ;
@@ -57,13 +62,12 @@ import { hasActiveSubscription } from "../users/logic";
5762import { internal } from "@config/strings" ;
5863import { hasCommunityPermission as hasPermission } from "@ui-lib/utils" ;
5964import ActivityModel from "@models/Activity" ;
60- import getDeletedMediaIds , {
61- extractMediaIDs ,
62- } from "@/lib/get-deleted-media-ids" ;
63- import { deleteMedia } from "@/services/medialit" ;
65+ import getDeletedMediaIds from "@/lib/get-deleted-media-ids" ;
66+ import { deleteMedia , sealMedia } from "@/services/medialit" ;
6467import CommunityPostSubscriberModel from "@models/CommunityPostSubscriber" ;
6568import InvoiceModel from "@models/Invoice" ;
6669import { InternalMembership } from "@courselit/common-logic" ;
70+ import { replaceTempMediaWithSealedMediaInProseMirrorDoc } from "@/lib/replace-temp-media-with-sealed-media-in-prosemirror-doc" ;
6771
6872const { permissions, communityPage } = constants ;
6973
@@ -272,10 +276,6 @@ export async function updateCommunity({
272276} ) : Promise < Community > {
273277 checkIfAuthenticated ( ctx ) ;
274278
275- // if (!checkPermission(ctx.user.permissions, [permissions.manageCommunity])) {
276- // throw new Error(responses.action_not_allowed);
277- // }
278-
279279 const community = await CommunityModel . findOne < InternalCommunity > (
280280 getCommunityQuery ( ctx , id ) ,
281281 ) ;
@@ -307,7 +307,10 @@ export async function updateCommunity({
307307 ) ;
308308
309309 if ( nextDescription ) {
310- community . description = JSON . parse ( nextDescription ) ;
310+ community . description =
311+ await replaceTempMediaWithSealedMediaInProseMirrorDoc (
312+ nextDescription ,
313+ ) ;
311314 }
312315 }
313316
@@ -321,7 +324,10 @@ export async function updateCommunity({
321324 ) ;
322325
323326 if ( nextBanner ) {
324- community . banner = JSON . parse ( nextBanner ) ;
327+ community . banner =
328+ await replaceTempMediaWithSealedMediaInProseMirrorDoc (
329+ nextBanner ,
330+ ) ;
325331 }
326332 }
327333
@@ -334,7 +340,9 @@ export async function updateCommunity({
334340 }
335341
336342 if ( featuredImage !== undefined ) {
337- community . featuredImage = featuredImage ;
343+ community . featuredImage = featuredImage ?. mediaId
344+ ? await sealMedia ( featuredImage . mediaId )
345+ : undefined ;
338346 }
339347
340348 const plans = await getPlans ( {
@@ -601,6 +609,14 @@ export async function createCommunityPost({
601609 throw new Error ( responses . invalid_category ) ;
602610 }
603611
612+ if ( media ?. length ) {
613+ for ( const med of media ) {
614+ if ( med . media ?. mediaId ) {
615+ med . media = await sealMedia ( med . media . mediaId ) ;
616+ }
617+ }
618+ }
619+
604620 const post = await CommunityPostModel . create ( {
605621 domain : ctx . subdomain . _id ,
606622 userId : ctx . user . userId ,
0 commit comments