ニジカ投稿局 https://tv.nizika.tv
You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.
 
 
 
 
 

85 lines
1.9 KiB

  1. import { getNodeABIVersion } from '@server/helpers/version.js'
  2. import memoizee from 'memoizee'
  3. import { AllowNull, Column, Default, DefaultScope, HasOne, IsInt, Table } from 'sequelize-typescript'
  4. import { AccountModel } from '../account/account.js'
  5. import { ActorImageModel } from '../actor/actor-image.js'
  6. import { SequelizeModel } from '../shared/index.js'
  7. export const getServerActor = memoizee(async function () {
  8. const application = await ApplicationModel.load()
  9. if (!application) throw Error('Could not load Application from database.')
  10. const actor = application.Account.Actor
  11. actor.Account = application.Account
  12. const { avatars, banners } = await ActorImageModel.listActorImages(actor)
  13. actor.Avatars = avatars
  14. actor.Banners = banners
  15. return actor
  16. }, { promise: true })
  17. @DefaultScope(() => ({
  18. include: [
  19. {
  20. model: AccountModel,
  21. required: true
  22. }
  23. ]
  24. }))
  25. @Table({
  26. tableName: 'application',
  27. timestamps: false
  28. })
  29. export class ApplicationModel extends SequelizeModel<ApplicationModel> {
  30. @AllowNull(false)
  31. @Default(0)
  32. @IsInt
  33. @Column
  34. migrationVersion: number
  35. @AllowNull(true)
  36. @Column
  37. latestPeerTubeVersion: string
  38. @AllowNull(false)
  39. @Column
  40. nodeVersion: string
  41. @AllowNull(false)
  42. @Column
  43. nodeABIVersion: number
  44. @HasOne(() => AccountModel, {
  45. foreignKey: {
  46. allowNull: true
  47. },
  48. onDelete: 'cascade'
  49. })
  50. Account: Awaited<AccountModel>
  51. static countTotal () {
  52. return ApplicationModel.count()
  53. }
  54. static load () {
  55. return ApplicationModel.findOne()
  56. }
  57. static async nodeABIChanged () {
  58. const application = await this.load()
  59. return application.nodeABIVersion !== getNodeABIVersion()
  60. }
  61. static async updateNodeVersions () {
  62. const application = await this.load()
  63. application.nodeABIVersion = getNodeABIVersion()
  64. application.nodeVersion = process.version
  65. await application.save()
  66. }
  67. }