* wip

* wip

* wip

* Update page-editor.vue

* wip

* wip

* wip

* wip

* wip

* wip

* wip

* Update page-editor.variable.core.vue

* wip

* wip

* wip

* wip

* wip

* wip

* wip

* wip

* wip

* wip

* wip

* Update aiscript.ts

* wip

* Update package.json

* wip

* wip

* wip

* wip

* wip

* Update page.vue

* wip

* wip

* wip

* wip

* more info

* wip fn

* wip

* wip

* wip
This commit is contained in:
syuilo
2019-04-29 09:11:57 +09:00
committed by GitHub
parent 747a0b1791
commit 05b8111c19
52 changed files with 3583 additions and 37 deletions

105
src/models/entities/page.ts Normal file
View File

@ -0,0 +1,105 @@
import { Entity, Index, JoinColumn, Column, PrimaryColumn, ManyToOne } from 'typeorm';
import { User } from './user';
import { id } from '../id';
import { DriveFile } from './drive-file';
@Entity()
@Index(['userId', 'name'], { unique: true })
export class Page {
@PrimaryColumn(id())
public id: string;
@Index()
@Column('timestamp with time zone', {
comment: 'The created date of the Page.'
})
public createdAt: Date;
@Index()
@Column('timestamp with time zone', {
comment: 'The updated date of the Page.'
})
public updatedAt: Date;
@Column('varchar', {
length: 256,
})
public title: string;
@Index()
@Column('varchar', {
length: 256,
})
public name: string;
@Column('varchar', {
length: 256, nullable: true
})
public summary: string | null;
@Column('boolean')
public alignCenter: boolean;
@Column('varchar', {
length: 32,
})
public font: string;
@Index()
@Column({
...id(),
comment: 'The ID of author.'
})
public userId: User['id'];
@ManyToOne(type => User, {
onDelete: 'CASCADE'
})
@JoinColumn()
public user: User | null;
@Column({
...id(),
nullable: true,
})
public eyeCatchingImageId: DriveFile['id'] | null;
@ManyToOne(type => DriveFile, {
onDelete: 'CASCADE'
})
@JoinColumn()
public eyeCatchingImage: DriveFile | null;
@Column('jsonb', {
default: []
})
public content: Record<string, any>[];
@Column('jsonb', {
default: []
})
public variables: Record<string, any>[];
/**
* public ... 公開
* followers ... フォロワーのみ
* specified ... visibleUserIds で指定したユーザーのみ
*/
@Column('enum', { enum: ['public', 'followers', 'specified'] })
public visibility: 'public' | 'followers' | 'specified';
@Index()
@Column({
...id(),
array: true, default: '{}'
})
public visibleUserIds: User['id'][];
constructor(data: Partial<Page>) {
if (data == null) return;
for (const [k, v] of Object.entries(data)) {
(this as any)[k] = v;
}
}
}

View File

@ -35,6 +35,7 @@ import { AbuseUserReportRepository } from './repositories/abuse-user-report';
import { AuthSessionRepository } from './repositories/auth-session';
import { UserProfile } from './entities/user-profile';
import { HashtagRepository } from './repositories/hashtag';
import { PageRepository } from './repositories/page';
export const Apps = getCustomRepository(AppRepository);
export const Notes = getCustomRepository(NoteRepository);
@ -72,3 +73,4 @@ export const MessagingMessages = getCustomRepository(MessagingMessageRepository)
export const ReversiGames = getCustomRepository(ReversiGameRepository);
export const ReversiMatchings = getCustomRepository(ReversiMatchingRepository);
export const Logs = getRepository(Log);
export const Pages = getCustomRepository(PageRepository);

View File

@ -0,0 +1,61 @@
import { EntityRepository, Repository } from 'typeorm';
import { Page } from '../entities/page';
import { SchemaType, types, bool } from '../../misc/schema';
import { Users, DriveFiles } from '..';
import { awaitAll } from '../../prelude/await-all';
import { DriveFile } from '../entities/drive-file';
export type PackedPage = SchemaType<typeof packedPageSchema>;
@EntityRepository(Page)
export class PageRepository extends Repository<Page> {
public async pack(
src: Page,
): Promise<PackedPage> {
const attachedFiles: Promise<DriveFile | undefined>[] = [];
const collectFile = (xs: any[]) => {
for (const x of xs) {
if (x.type === 'image') {
attachedFiles.push(DriveFiles.findOne({
id: x.fileId,
userId: src.userId
}));
}
if (x.children) {
collectFile(x.children);
}
}
};
collectFile(src.content);
return await awaitAll({
id: src.id,
createdAt: src.createdAt.toISOString(),
updatedAt: src.updatedAt.toISOString(),
userId: src.userId,
user: Users.pack(src.user || src.userId),
content: src.content,
variables: src.variables,
title: src.title,
name: src.name,
summary: src.summary,
alignCenter: src.alignCenter,
font: src.font,
eyeCatchingImageId: src.eyeCatchingImageId,
eyeCatchingImage: src.eyeCatchingImageId ? await DriveFiles.pack(src.eyeCatchingImageId) : null,
attachedFiles: DriveFiles.packMany(await Promise.all(attachedFiles))
});
}
public packMany(
pages: Page[],
) {
return Promise.all(pages.map(x => this.pack(x)));
}
}
export const packedPageSchema = {
type: types.object,
optional: bool.false, nullable: bool.false,
properties: {
}
};