Skip to content

Commit ece2bac

Browse files
committed
fix: used switch case to parse different social feed metadata
1 parent 3a16113 commit ece2bac

File tree

1 file changed

+10
-29
lines changed

1 file changed

+10
-29
lines changed

packages/utils/types/feed.ts

Lines changed: 10 additions & 29 deletions
Original file line numberDiff line numberDiff line change
@@ -137,37 +137,18 @@ export type ReplyToType = {
137137
parentId?: string;
138138
};
139139

140-
type GroupPostCategoryType = Omit<
141-
PostCategory,
142-
PostCategory.Video | PostCategory.Article | PostCategory.MusicAudio
143-
>;
144-
145-
const postCategoriesGrouped: GroupPostCategoryType[] = [
146-
PostCategory.Reaction,
147-
PostCategory.Comment,
148-
PostCategory.Normal,
149-
PostCategory.Picture,
150-
PostCategory.Question,
151-
PostCategory.BriefForStableDiffusion,
152-
PostCategory.Flagged,
153-
PostCategory.VideoNote,
154-
PostCategory.Audio,
155-
];
156-
157-
const socialFeedSchemaMap: Record<PostCategory, z.ZodTypeAny> = {
158-
[PostCategory.Video]: ZodSocialFeedVideoMetadata,
159-
[PostCategory.Article]: ZodSocialFeedArticleMetadata,
160-
[PostCategory.MusicAudio]: ZodSocialFeedTrackMetadata,
161-
...Object.fromEntries(
162-
postCategoriesGrouped.map((cat) => [cat, ZodSocialFeedPostMetadata]),
163-
),
164-
};
165-
166140
export const parseSocialFeedMetadata = (
167141
category: PostCategory,
168142
metadata: string,
169143
) => {
170-
const zodType = socialFeedSchemaMap[category];
171-
172-
return zodTryParseJSON(zodType, metadata);
144+
switch (category) {
145+
case PostCategory.Video:
146+
return zodTryParseJSON(ZodSocialFeedVideoMetadata, metadata);
147+
case PostCategory.Article:
148+
return zodTryParseJSON(ZodSocialFeedPostMetadata, metadata);
149+
case PostCategory.MusicAudio:
150+
return zodTryParseJSON(ZodSocialFeedTrackMetadata, metadata);
151+
default:
152+
return zodTryParseJSON(ZodSocialFeedPostMetadata, metadata);
153+
}
173154
};

0 commit comments

Comments
 (0)