enhance(Page): ページを非公開にできるように (MisskeyIO#821)
This commit is contained in:
parent
6a416468e3
commit
1a81d3fa46
14 changed files with 75 additions and 16 deletions
19
packages/backend/migration/1733563840208-page-visibility.js
Normal file
19
packages/backend/migration/1733563840208-page-visibility.js
Normal file
|
@ -0,0 +1,19 @@
|
|||
export class PageVisibility1733563840208 {
|
||||
name = 'PageVisibility1733563840208'
|
||||
|
||||
async up(queryRunner) {
|
||||
await queryRunner.query(`ALTER TYPE "public"."page_visibility_enum" RENAME TO "page_visibility_enum_old"`);
|
||||
await queryRunner.query(`CREATE TYPE "public"."page_visibility_enum" AS ENUM('public', 'private')`);
|
||||
await queryRunner.query(`ALTER TABLE "page" ALTER COLUMN "visibility" TYPE "public"."page_visibility_enum" USING "visibility"::"text"::"public"."page_visibility_enum"`);
|
||||
await queryRunner.query(`DROP TYPE "public"."page_visibility_enum_old"`);
|
||||
await queryRunner.query(`ALTER TABLE "page" ALTER COLUMN "visibility" SET DEFAULT 'public'`);
|
||||
}
|
||||
|
||||
async down(queryRunner) {
|
||||
await queryRunner.query(`CREATE TYPE "public"."page_visibility_enum_old" AS ENUM('followers', 'public', 'specified')`);
|
||||
await queryRunner.query(`ALTER TABLE "page" ALTER COLUMN "visibility" TYPE "public"."page_visibility_enum_old" USING "visibility"::"text"::"public"."page_visibility_enum_old"`);
|
||||
await queryRunner.query(`DROP TYPE "public"."page_visibility_enum"`);
|
||||
await queryRunner.query(`ALTER TYPE "public"."page_visibility_enum_old" RENAME TO "page_visibility_enum"`);
|
||||
await queryRunner.query(`ALTER TABLE "page" ALTER COLUMN "visibility" DROP DEFAULT`);
|
||||
}
|
||||
}
|
|
@ -105,6 +105,7 @@ export class PageEntityService {
|
|||
attachedFiles: this.driveFileEntityService.packMany((await Promise.all(attachedFiles)).filter(isNotNull), me),
|
||||
likedCount: page.likedCount,
|
||||
isLiked: meId ? await this.pageLikesRepository.exists({ where: { pageId: page.id, userId: meId } }) : undefined,
|
||||
visibility: page.visibility,
|
||||
});
|
||||
}
|
||||
|
||||
|
|
|
@ -99,18 +99,13 @@ export class MiPage {
|
|||
|
||||
/**
|
||||
* public ... 公開
|
||||
* followers ... フォロワーのみ
|
||||
* specified ... visibleUserIds で指定したユーザーのみ
|
||||
* private ... 非公開
|
||||
*/
|
||||
@Column('enum', { enum: ['public', 'followers', 'specified'] })
|
||||
public visibility: 'public' | 'followers' | 'specified';
|
||||
|
||||
@Index()
|
||||
@Column({
|
||||
...id(),
|
||||
array: true, default: '{}',
|
||||
@Column('enum', {
|
||||
enum: ['public', 'private'],
|
||||
default: 'public',
|
||||
})
|
||||
public visibleUserIds: MiUser['id'][];
|
||||
public visibility: 'public' | 'private';
|
||||
|
||||
@Column('integer', {
|
||||
default: 0,
|
||||
|
|
|
@ -205,6 +205,11 @@ export const packedPageSchema = {
|
|||
type: 'boolean',
|
||||
optional: true, nullable: false,
|
||||
},
|
||||
visibility: {
|
||||
type: 'string',
|
||||
optional: false, nullable: false,
|
||||
enum: ['public', 'private'],
|
||||
},
|
||||
},
|
||||
} as const;
|
||||
|
||||
|
|
|
@ -65,6 +65,7 @@ export const paramDef = {
|
|||
font: { type: 'string', enum: ['serif', 'sans-serif'], default: 'sans-serif' },
|
||||
alignCenter: { type: 'boolean', default: false },
|
||||
hideTitleWhenPinned: { type: 'boolean', default: false },
|
||||
visibility: { type: 'string', enum: ['public', 'private'] },
|
||||
},
|
||||
required: ['title', 'name', 'content', 'variables', 'script'],
|
||||
} as const;
|
||||
|
@ -114,7 +115,7 @@ export default class extends Endpoint<typeof meta, typeof paramDef> { // eslint-
|
|||
script: ps.script,
|
||||
eyeCatchingImageId: eyeCatchingImage ? eyeCatchingImage.id : null,
|
||||
userId: me.id,
|
||||
visibility: 'public',
|
||||
visibility: ps.visibility,
|
||||
alignCenter: ps.alignCenter,
|
||||
hideTitleWhenPinned: ps.hideTitleWhenPinned,
|
||||
font: ps.font,
|
||||
|
|
|
@ -78,6 +78,10 @@ export default class extends Endpoint<typeof meta, typeof paramDef> { // eslint-
|
|||
throw new ApiError(meta.errors.noSuchPage);
|
||||
}
|
||||
|
||||
if (page.visibility === 'private' && (me == null || (page.userId !== me.id))) {
|
||||
throw new ApiError(meta.errors.noSuchPage);
|
||||
}
|
||||
|
||||
return await this.pageEntityService.pack(page, me);
|
||||
});
|
||||
}
|
||||
|
|
|
@ -70,6 +70,7 @@ export const paramDef = {
|
|||
font: { type: 'string', enum: ['serif', 'sans-serif'] },
|
||||
alignCenter: { type: 'boolean' },
|
||||
hideTitleWhenPinned: { type: 'boolean' },
|
||||
visibility: { type: 'string', enum: ['public', 'private'] },
|
||||
},
|
||||
required: ['pageId', 'title', 'name', 'content', 'variables', 'script'],
|
||||
} as const;
|
||||
|
@ -129,6 +130,8 @@ export default class extends Endpoint<typeof meta, typeof paramDef> { // eslint-
|
|||
hideTitleWhenPinned: ps.hideTitleWhenPinned === undefined ? page.hideTitleWhenPinned : ps.hideTitleWhenPinned,
|
||||
// eslint-disable-next-line @typescript-eslint/prefer-nullish-coalescing
|
||||
font: ps.font === undefined ? page.font : ps.font,
|
||||
// eslint-disable-next-line @typescript-eslint/prefer-nullish-coalescing
|
||||
visibility: ps.visibility === undefined ? page.visibility : ps.visibility,
|
||||
eyeCatchingImageId: ps.eyeCatchingImageId === null
|
||||
? null
|
||||
: ps.eyeCatchingImageId === undefined
|
||||
|
|
|
@ -196,6 +196,7 @@ export const page = async (user: UserToken, page: Partial<misskey.entities.Page>
|
|||
eyeCatchingImageId: null,
|
||||
font: 'sans-serif' as FIXME,
|
||||
hideTitleWhenPinned: false,
|
||||
visibility: 'public',
|
||||
name: '1678594845072',
|
||||
script: '',
|
||||
summary: null,
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue