Skip to content

Commit

Permalink
Hide blog list (#620)
Browse files Browse the repository at this point in the history
* List of hidden blogs

* Adjusted the api to return blog
  • Loading branch information
icemedia001 authored Jan 17, 2025
1 parent f30bba5 commit 7dedf23
Show file tree
Hide file tree
Showing 3 changed files with 48 additions and 4 deletions.
3 changes: 3 additions & 0 deletions src/App/Blog/blog.dto.ts
Original file line number Diff line number Diff line change
Expand Up @@ -56,6 +56,9 @@ export class Blog extends FormatedBlogType {

@Field({ nullable: true })
hidden?: boolean

@Field({ nullable: true })
hiddenAt?: Date
}

@ObjectType()
Expand Down
4 changes: 2 additions & 2 deletions src/App/Blog/blog.resolver.ts
Original file line number Diff line number Diff line change
Expand Up @@ -43,8 +43,8 @@ class BlogResolver {
return this.blogService.unhideBlogByDigest(digest)
}

@Query(() => [HiddenBlog], { nullable: 'items' })
async getHiddenBlogs(): Promise<HiddenBlog[]> {
@Query(() => [Blog], { nullable: 'items' })
async getHiddenBlogs(): Promise<Blog[]> {
return this.blogService.getHiddenBlogs()
}
}
Expand Down
45 changes: 43 additions & 2 deletions src/App/Blog/blog.service.ts
Original file line number Diff line number Diff line change
Expand Up @@ -316,8 +316,49 @@ class BlogService {
}
}

async getHiddenBlogs(): Promise<HiddenBlog[]> {
return this.dataSource.getRepository(HiddenBlog).find()
async getHiddenBlogs(): Promise<Blog[]> {
const hiddenBlogsRepo = this.dataSource.getRepository(HiddenBlog)
const hiddenBlogs = await hiddenBlogsRepo.find()

let allBlogs = await this.cacheManager.get<Blog[]>(this.BLOG_CACHE_KEY)
if (!allBlogs) {
const accounts = [
this.EVERIPEDIA_BLOG_ACCOUNT2,
this.EVERIPEDIA_BLOG_ACCOUNT3,
]

allBlogs = await Promise.all(
accounts.map(async (account) => {
try {
if (!account) return []
const entries = await this.mirrorApiService.getBlogs(account)
return (
entries
?.filter((entry) => entry.publishedAtTimestamp)
.map((b: Blog) => this.formatBlog(b, true)) || []
)
} catch (error) {
console.error(`Error fetching blogs for account ${account}:`, error)
return []
}
}),
).then((blogArrays) => blogArrays.flat())

await this.cacheManager.set(this.BLOG_CACHE_KEY, allBlogs, { ttl: 7200 })
}

const hiddenBlogsWithInfo =
allBlogs?.filter((blog) =>
hiddenBlogs.some((hiddenBlog) => hiddenBlog.digest === blog.digest),
) || []

return hiddenBlogsWithInfo.map((blog) => {
const hiddenBlog = hiddenBlogs.find((hb) => hb.digest === blog.digest)
return {
...blog,
hiddenAt: hiddenBlog?.hiddenAt,
}
})
}
}

Expand Down

0 comments on commit 7dedf23

Please sign in to comment.