@@ -121,6 +121,7 @@ export class HttpCacheInterceptor implements NestInterceptor {
|
|||||||
|
|
||||||
setCacheHeader(res: FastifyReply, ttl: number) {
|
setCacheHeader(res: FastifyReply, ttl: number) {
|
||||||
if (res.raw.statusCode !== 200) return
|
if (res.raw.statusCode !== 200) return
|
||||||
|
res.header('x-mx-cache', 'hit')
|
||||||
if (HTTP_CACHE.enableCDNHeader) {
|
if (HTTP_CACHE.enableCDNHeader) {
|
||||||
res.header(
|
res.header(
|
||||||
'cdn-cache-control',
|
'cdn-cache-control',
|
||||||
|
|||||||
@@ -241,4 +241,9 @@ export class ActivityController {
|
|||||||
|
|
||||||
return [...postList, ...noteList]
|
return [...postList, ...noteList]
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@Get('/last-year/publication')
|
||||||
|
getLastYearPublication() {
|
||||||
|
return this.service.getLastYearPublication()
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -1,8 +1,10 @@
|
|||||||
import { Module } from '@nestjs/common'
|
import { forwardRef, Module } from '@nestjs/common'
|
||||||
|
|
||||||
import { GatewayModule } from '~/processors/gateway/gateway.module'
|
import { GatewayModule } from '~/processors/gateway/gateway.module'
|
||||||
|
|
||||||
import { CommentModule } from '../comment/comment.module'
|
import { CommentModule } from '../comment/comment.module'
|
||||||
|
import { NoteModule } from '../note/note.module'
|
||||||
|
import { PostModule } from '../post/post.module'
|
||||||
import { ActivityController } from './activity.controller'
|
import { ActivityController } from './activity.controller'
|
||||||
import { ActivityService } from './activity.service'
|
import { ActivityService } from './activity.service'
|
||||||
|
|
||||||
@@ -10,6 +12,12 @@ import { ActivityService } from './activity.service'
|
|||||||
providers: [ActivityService],
|
providers: [ActivityService],
|
||||||
controllers: [ActivityController],
|
controllers: [ActivityController],
|
||||||
exports: [ActivityService],
|
exports: [ActivityService],
|
||||||
imports: [GatewayModule, CommentModule],
|
imports: [
|
||||||
|
GatewayModule,
|
||||||
|
CommentModule,
|
||||||
|
|
||||||
|
forwardRef(() => PostModule),
|
||||||
|
forwardRef(() => NoteModule),
|
||||||
|
],
|
||||||
})
|
})
|
||||||
export class ActivityModule {}
|
export class ActivityModule {}
|
||||||
|
|||||||
@@ -14,7 +14,13 @@ import type {
|
|||||||
} from './activity.interface'
|
} from './activity.interface'
|
||||||
import type { UpdatePresenceDto } from './dtos/presence.dto'
|
import type { UpdatePresenceDto } from './dtos/presence.dto'
|
||||||
|
|
||||||
import { BadRequestException, Injectable, Logger } from '@nestjs/common'
|
import {
|
||||||
|
BadRequestException,
|
||||||
|
forwardRef,
|
||||||
|
Inject,
|
||||||
|
Injectable,
|
||||||
|
Logger,
|
||||||
|
} from '@nestjs/common'
|
||||||
|
|
||||||
import { ArticleTypeEnum } from '~/constants/article.constant'
|
import { ArticleTypeEnum } from '~/constants/article.constant'
|
||||||
import { BusinessEvents, EventScope } from '~/constants/business-event.constant'
|
import { BusinessEvents, EventScope } from '~/constants/business-event.constant'
|
||||||
@@ -35,6 +41,8 @@ import { checkRefModelCollectionType, getAvatar } from '~/utils'
|
|||||||
import { CommentState } from '../comment/comment.model'
|
import { CommentState } from '../comment/comment.model'
|
||||||
import { CommentService } from '../comment/comment.service'
|
import { CommentService } from '../comment/comment.service'
|
||||||
import { ConfigsService } from '../configs/configs.service'
|
import { ConfigsService } from '../configs/configs.service'
|
||||||
|
import { NoteService } from '../note/note.service'
|
||||||
|
import { PostService } from '../post/post.service'
|
||||||
import { Activity } from './activity.constant'
|
import { Activity } from './activity.constant'
|
||||||
import { ActivityModel } from './activity.model'
|
import { ActivityModel } from './activity.model'
|
||||||
import {
|
import {
|
||||||
@@ -66,6 +74,11 @@ export class ActivityService implements OnModuleInit, OnModuleDestroy {
|
|||||||
private readonly webGateway: WebEventsGateway,
|
private readonly webGateway: WebEventsGateway,
|
||||||
private readonly gatewayService: GatewayService,
|
private readonly gatewayService: GatewayService,
|
||||||
private readonly configsService: ConfigsService,
|
private readonly configsService: ConfigsService,
|
||||||
|
|
||||||
|
@Inject(forwardRef(() => PostService))
|
||||||
|
private readonly postService: PostService,
|
||||||
|
@Inject(forwardRef(() => NoteService))
|
||||||
|
private readonly noteService: NoteService,
|
||||||
) {
|
) {
|
||||||
this.logger = new Logger(ActivityService.name)
|
this.logger = new Logger(ActivityService.name)
|
||||||
}
|
}
|
||||||
@@ -621,4 +634,50 @@ export class ActivityService implements OnModuleInit, OnModuleDestroy {
|
|||||||
note,
|
note,
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* 获取过去一年的文章发布
|
||||||
|
*/
|
||||||
|
async getLastYearPublication() {
|
||||||
|
const $gte = new Date(new Date().getTime() - 365 * 24 * 60 * 60 * 1000)
|
||||||
|
const [posts, notes] = await Promise.all([
|
||||||
|
this.postService.model
|
||||||
|
.find({
|
||||||
|
created: {
|
||||||
|
$gte,
|
||||||
|
},
|
||||||
|
})
|
||||||
|
.select('title created slug categoryId category')
|
||||||
|
.sort({ created: -1 }),
|
||||||
|
this.noteService.model
|
||||||
|
.find(
|
||||||
|
{
|
||||||
|
created: {
|
||||||
|
$gte,
|
||||||
|
},
|
||||||
|
},
|
||||||
|
{
|
||||||
|
title: 1,
|
||||||
|
created: 1,
|
||||||
|
nid: 1,
|
||||||
|
weather: 1,
|
||||||
|
mood: 1,
|
||||||
|
bookmark: 1,
|
||||||
|
password: 1,
|
||||||
|
hide: 1,
|
||||||
|
},
|
||||||
|
)
|
||||||
|
.lean(),
|
||||||
|
])
|
||||||
|
return {
|
||||||
|
posts,
|
||||||
|
notes: notes.map((note) => {
|
||||||
|
if (note.password || note.hide) {
|
||||||
|
note.title = '未公开的日记'
|
||||||
|
}
|
||||||
|
|
||||||
|
return omit(note, 'password', 'hide')
|
||||||
|
}),
|
||||||
|
}
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -3,6 +3,7 @@ import type { IController } from '~/interfaces/controller'
|
|||||||
import type { IRequestHandler } from '~/interfaces/request'
|
import type { IRequestHandler } from '~/interfaces/request'
|
||||||
import type {
|
import type {
|
||||||
ActivityPresence,
|
ActivityPresence,
|
||||||
|
LastYearPublication,
|
||||||
RecentActivities,
|
RecentActivities,
|
||||||
RoomsData,
|
RoomsData,
|
||||||
} from '~/models/activity'
|
} from '~/models/activity'
|
||||||
@@ -95,4 +96,8 @@ export class ActivityController<ResponseWrapper> implements IController {
|
|||||||
async getRecentActivities() {
|
async getRecentActivities() {
|
||||||
return this.proxy.recent.get<RecentActivities>()
|
return this.proxy.recent.get<RecentActivities>()
|
||||||
}
|
}
|
||||||
|
|
||||||
|
async getLastYearPublication(): Promise<LastYearPublication> {
|
||||||
|
return this.proxy(`last-year`).publication.get<LastYearPublication>()
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -100,3 +100,33 @@ export interface RecentRecent {
|
|||||||
down: number
|
down: number
|
||||||
created: string
|
created: string
|
||||||
}
|
}
|
||||||
|
|
||||||
|
export interface LastYearPublication {
|
||||||
|
posts: PostsItem[]
|
||||||
|
notes: NotesItem[]
|
||||||
|
}
|
||||||
|
|
||||||
|
interface PostsItem {
|
||||||
|
id: string
|
||||||
|
created: string
|
||||||
|
title: string
|
||||||
|
slug: string
|
||||||
|
categoryId: string
|
||||||
|
category: Category
|
||||||
|
}
|
||||||
|
interface Category {
|
||||||
|
id: string
|
||||||
|
type: number
|
||||||
|
name: string
|
||||||
|
slug: string
|
||||||
|
created: string
|
||||||
|
}
|
||||||
|
interface NotesItem {
|
||||||
|
id: string
|
||||||
|
created: string
|
||||||
|
title: string
|
||||||
|
mood: string
|
||||||
|
weather: string
|
||||||
|
nid: number
|
||||||
|
bookmark: boolean
|
||||||
|
}
|
||||||
|
|||||||
Reference in New Issue
Block a user