diff --git a/apps/core/src/migration/history.ts b/apps/core/src/migration/history.ts index d72ab491..3a452826 100644 --- a/apps/core/src/migration/history.ts +++ b/apps/core/src/migration/history.ts @@ -5,5 +5,15 @@ import v3393 from './version/v3.39.3' import v460 from './version/v4.6.0' import v4_6_0__1 from './version/v4.6.0-1' import v4_6_1 from './version/v4.6.2' +import v5_0_0__1 from './version/v5.0.0-1' -export default [v200Alpha1, v3330, v3360, v3393, v460, v4_6_0__1, v4_6_1] +export default [ + v200Alpha1, + v3330, + v3360, + v3393, + v460, + v4_6_0__1, + v4_6_1, + v5_0_0__1, +] diff --git a/apps/core/src/migration/version/v5.0.0-1.ts b/apps/core/src/migration/version/v5.0.0-1.ts new file mode 100644 index 00000000..b9a3c619 --- /dev/null +++ b/apps/core/src/migration/version/v5.0.0-1.ts @@ -0,0 +1,25 @@ +import { NOTE_COLLECTION_NAME } from '~/constants/db.constant' + +import { defineMigration } from '../helper' + +export default defineMigration('v5.0.0-1', async (db, connection) => { + try { + await Promise.all([ + db.collection(NOTE_COLLECTION_NAME).updateMany( + { + secret: { $exists: true }, + }, + { $rename: { secret: 'publicAt' } }, + ), + db.collection(NOTE_COLLECTION_NAME).updateMany( + { + hasMemory: { $exists: true }, + }, + { $rename: { secret: 'bookmark' } }, + ), + ]) + } catch (err) { + console.error('v5.0.0-1 migration failed') + throw err + } +}) diff --git a/apps/core/src/modules/aggregate/aggregate.service.ts b/apps/core/src/modules/aggregate/aggregate.service.ts index d8513299..4232c24f 100644 --- a/apps/core/src/modules/aggregate/aggregate.service.ts +++ b/apps/core/src/modules/aggregate/aggregate.service.ts @@ -165,7 +165,7 @@ export class AggregateService { hide: false, ...addYearCondition(year), }, - '_id nid title weather mood created modified hasMemory', + '_id nid title weather mood created modified bookmark', ) .sort({ created: sortBy }) .lean() @@ -213,17 +213,17 @@ export class AggregateService { $or: [ { - secret: { + publicAt: { $lte: new Date(), }, }, { - secret: { + publicAt: { $exists: false, }, }, { - secret: null, + publicAt: null, }, ], }) @@ -305,17 +305,17 @@ export class AggregateService { { $or: [ { - secret: { + publicAt: { $lte: new Date(), }, }, { - secret: { + publicAt: { $exists: false, }, }, { - secret: null, + publicAt: null, }, ], }, diff --git a/apps/core/src/modules/note/note.model.ts b/apps/core/src/modules/note/note.model.ts index caf0d91a..f079dc4c 100644 --- a/apps/core/src/modules/note/note.model.ts +++ b/apps/core/src/modules/note/note.model.ts @@ -64,7 +64,7 @@ export class NoteModel extends WriteBaseModel { @IsOptional() @IsDate() @Transform(({ value }) => (value ? new Date(value) : null)) - secret: Date | null + publicAt: Date | null @prop() @IsString() @@ -76,10 +76,10 @@ export class NoteModel extends WriteBaseModel { @IsString() weather?: string - @prop() + @prop({ default: false }) @IsBoolean() @IsOptional() - hasMemory?: boolean + bookmark: boolean @prop({ select: false, type: Coordinate }) @ValidateNested() diff --git a/apps/core/src/modules/note/note.service.ts b/apps/core/src/modules/note/note.service.ts index 1b04379f..fd3fe846 100644 --- a/apps/core/src/modules/note/note.service.ts +++ b/apps/core/src/modules/note/note.service.ts @@ -67,10 +67,10 @@ export class NoteService { } public checkNoteIsSecret(note: NoteModel) { - if (!note.secret) { + if (!note.publicAt) { return false } - const isSecret = dayjs(note.secret).isAfter(new Date()) + const isSecret = dayjs(note.publicAt).isAfter(new Date()) return isSecret } @@ -265,7 +265,7 @@ export class NoteService { scope: EventScope.TO_SYSTEM, }) - if (updated.password || updated.hide || updated.secret) { + if (updated.password || updated.hide || updated.publicAt) { return } this.eventManager.broadcast( diff --git a/apps/core/src/modules/search/search.service.ts b/apps/core/src/modules/search/search.service.ts index fad8b11e..2ff86efb 100644 --- a/apps/core/src/modules/search/search.service.ts +++ b/apps/core/src/modules/search/search.service.ts @@ -65,8 +65,8 @@ export class SearchService { { hide: { $in: showHidden ? [false, true] : [false] } }, { $or: [ - { secret: { $not: null } }, - { secret: { $lte: new Date() } }, + { publicAt: { $not: null } }, + { publicAt: { $lte: new Date() } }, ], }, ], diff --git a/apps/core/src/modules/subscribe/subscribe.service.ts b/apps/core/src/modules/subscribe/subscribe.service.ts index cd9a29c6..f785461e 100644 --- a/apps/core/src/modules/subscribe/subscribe.service.ts +++ b/apps/core/src/modules/subscribe/subscribe.service.ts @@ -152,7 +152,17 @@ export class SubscribeService implements OnModuleInit, OnModuleDestroy { } } - const precheck: CoAction = async function () { + const precheck: CoAction = async function ( + noteOrPost: NoteModel | PostModel, + ) { + if ('hide' in noteOrPost && noteOrPost.hide) return this.abort() + if ('password' in noteOrPost && !!noteOrPost.password) return this.abort() + if ( + 'publicAt' in noteOrPost && + noteOrPost.publicAt && + new Date(noteOrPost.publicAt) > new Date() + ) + return this.abort() const enable = await self.checkEnable() if (enable) { diff --git a/packages/api-client/controllers/note.ts b/packages/api-client/controllers/note.ts index d9ac4117..2adfdc37 100644 --- a/packages/api-client/controllers/note.ts +++ b/packages/api-client/controllers/note.ts @@ -8,12 +8,11 @@ import type { NoteWrappedPayload, NoteWrappedWithLikedPayload, } from '~/models/note' +import type { HTTPClient } from '../core/client' import type { SortOptions } from './base' import { autoBind } from '~/utils/auto-bind' -import { HTTPClient } from '../core/client' - declare module '../core/client' { interface HTTPClient< T extends IRequestAdapter = IRequestAdapter, diff --git a/packages/api-client/models/aggregate.ts b/packages/api-client/models/aggregate.ts index 207ffd81..bb813ff5 100644 --- a/packages/api-client/models/aggregate.ts +++ b/packages/api-client/models/aggregate.ts @@ -60,7 +60,7 @@ export interface TimelineData { | 'mood' | 'created' | 'modified' - | 'hasMemory' + | 'bookmark' >[] posts?: (Pick< diff --git a/packages/api-client/models/note.ts b/packages/api-client/models/note.ts index 705b48f7..9d77b3bf 100644 --- a/packages/api-client/models/note.ts +++ b/packages/api-client/models/note.ts @@ -10,9 +10,9 @@ export interface NoteModel extends TextBaseModel { mood?: string weather?: string - hasMemory?: boolean + bookmark?: boolean - secret?: Date + publicAt?: Date password?: string | null nid: number music?: NoteMusicRecord[]