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