]>
Commit | Line | Data |
---|---|---|
1 | import { AllowNull, Column, Default, DefaultScope, HasOne, IsInt, Model, Table } from 'sequelize-typescript' | |
2 | import { AccountModel } from '../account/account' | |
3 | import * as memoizee from 'memoizee' | |
4 | ||
5 | export const getServerActor = memoizee(async function () { | |
6 | const application = await ApplicationModel.load() | |
7 | if (!application) throw Error('Could not load Application from database.') | |
8 | ||
9 | const actor = application.Account.Actor | |
10 | actor.Account = application.Account | |
11 | ||
12 | return actor | |
13 | }, { promise: true }) | |
14 | ||
15 | @DefaultScope(() => ({ | |
16 | include: [ | |
17 | { | |
18 | model: AccountModel, | |
19 | required: true | |
20 | } | |
21 | ] | |
22 | })) | |
23 | @Table({ | |
24 | tableName: 'application', | |
25 | timestamps: false | |
26 | }) | |
27 | export class ApplicationModel extends Model { | |
28 | ||
29 | @AllowNull(false) | |
30 | @Default(0) | |
31 | @IsInt | |
32 | @Column | |
33 | migrationVersion: number | |
34 | ||
35 | @AllowNull(true) | |
36 | @Column | |
37 | latestPeerTubeVersion: string | |
38 | ||
39 | @HasOne(() => AccountModel, { | |
40 | foreignKey: { | |
41 | allowNull: true | |
42 | }, | |
43 | onDelete: 'cascade' | |
44 | }) | |
45 | Account: AccountModel | |
46 | ||
47 | static countTotal () { | |
48 | return ApplicationModel.count() | |
49 | } | |
50 | ||
51 | static load () { | |
52 | return ApplicationModel.findOne() | |
53 | } | |
54 | } |