refactor!: rename note model field and fix exposure of hidden data

Signed-off-by: Innei <i@innei.in>
This commit is contained in:
Innei
2024-02-15 22:29:51 +08:00
parent 722045ce6d
commit 6745194197
10 changed files with 66 additions and 22 deletions

View File

@@ -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,
]

View File

@@ -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
}
})

View File

@@ -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,
},
],
},

View File

@@ -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()

View File

@@ -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(

View File

@@ -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() } },
],
},
],

View File

@@ -152,7 +152,17 @@ export class SubscribeService implements OnModuleInit, OnModuleDestroy {
}
}
const precheck: CoAction<any> = async function () {
const precheck: CoAction<any> = 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) {

View File

@@ -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,

View File

@@ -60,7 +60,7 @@ export interface TimelineData {
| 'mood'
| 'created'
| 'modified'
| 'hasMemory'
| 'bookmark'
>[]
posts?: (Pick<

View File

@@ -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[]