ニジカ投稿局 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.
 
 
 
 
 

55 lines
1.8 KiB

  1. import { doJSONRequest } from '@server/helpers/requests.js'
  2. import { ApplicationModel } from '@server/models/application/application.js'
  3. import { compareSemVer } from '@peertube/peertube-core-utils'
  4. import { JoinPeerTubeVersions } from '@peertube/peertube-models'
  5. import { logger } from '../../helpers/logger.js'
  6. import { CONFIG } from '../../initializers/config.js'
  7. import { PEERTUBE_VERSION, SCHEDULER_INTERVALS_MS } from '../../initializers/constants.js'
  8. import { Notifier } from '../notifier/index.js'
  9. import { AbstractScheduler } from './abstract-scheduler.js'
  10. export class PeerTubeVersionCheckScheduler extends AbstractScheduler {
  11. private static instance: AbstractScheduler
  12. protected schedulerIntervalMs = SCHEDULER_INTERVALS_MS.CHECK_PEERTUBE_VERSION
  13. private constructor () {
  14. super()
  15. }
  16. protected async internalExecute () {
  17. return this.checkLatestVersion()
  18. }
  19. private async checkLatestVersion () {
  20. if (CONFIG.PEERTUBE.CHECK_LATEST_VERSION.ENABLED === false) return
  21. logger.info('Checking latest PeerTube version.')
  22. const { body } = await doJSONRequest<JoinPeerTubeVersions>(CONFIG.PEERTUBE.CHECK_LATEST_VERSION.URL)
  23. if (!body?.peertube?.latestVersion) {
  24. logger.warn('Cannot check latest PeerTube version: body is invalid.', { body })
  25. return
  26. }
  27. const latestVersion = body.peertube.latestVersion
  28. const application = await ApplicationModel.load()
  29. // Already checked this version
  30. if (application.latestPeerTubeVersion === latestVersion) return
  31. if (compareSemVer(PEERTUBE_VERSION, latestVersion) < 0) {
  32. application.latestPeerTubeVersion = latestVersion
  33. await application.save()
  34. Notifier.Instance.notifyOfNewPeerTubeVersion(application, latestVersion)
  35. }
  36. }
  37. static get Instance () {
  38. return this.instance || (this.instance = new this())
  39. }
  40. }