1
0
Fork 0
mirror of https://github.com/Chocobozzz/PeerTube.git synced 2025-10-04 02:09:37 +02:00

server/server -> server/core

This commit is contained in:
Chocobozzz 2023-10-04 15:13:25 +02:00
parent 114327d4ce
commit 5a3d0650c9
No known key found for this signature in database
GPG key ID: 583A612D890159BE
838 changed files with 111 additions and 111 deletions

View file

@ -0,0 +1,49 @@
import { logger } from '@server/helpers/logger.js'
import { CONFIG } from '@server/initializers/config.js'
import { UserModel } from '@server/models/user/user.js'
import { UserNotificationModel } from '@server/models/user/user-notification.js'
import { MUserDefault, MUserWithNotificationSetting, UserNotificationModelForApi } from '@server/types/models/index.js'
import { UserNotificationType, UserRight } from '@peertube/peertube-models'
import { AbstractNotification } from '../common/abstract-notification.js'
export class DirectRegistrationForModerators extends AbstractNotification <MUserDefault> {
private moderators: MUserDefault[]
async prepare () {
this.moderators = await UserModel.listWithRight(UserRight.MANAGE_USERS)
}
log () {
logger.info('Notifying %s moderators of new user registration of %s.', this.moderators.length, this.payload.username)
}
getSetting (user: MUserWithNotificationSetting) {
return user.NotificationSetting.newUserRegistration
}
getTargetUsers () {
return this.moderators
}
createNotification (user: MUserWithNotificationSetting) {
const notification = UserNotificationModel.build<UserNotificationModelForApi>({
type: UserNotificationType.NEW_USER_REGISTRATION,
userId: user.id,
accountId: this.payload.Account.id
})
notification.Account = this.payload.Account
return notification
}
createEmail (to: string) {
return {
template: 'user-registered',
to,
subject: `A new user registered on ${CONFIG.INSTANCE.NAME}: ${this.payload.username}`,
locals: {
user: this.payload
}
}
}
}

View file

@ -0,0 +1,4 @@
export * from './new-peertube-version-for-admins.js'
export * from './new-plugin-version-for-admins.js'
export * from './direct-registration-for-moderators.js'
export * from './registration-request-for-moderators.js'

View file

@ -0,0 +1,54 @@
import { logger } from '@server/helpers/logger.js'
import { UserModel } from '@server/models/user/user.js'
import { UserNotificationModel } from '@server/models/user/user-notification.js'
import { MApplication, MUserDefault, MUserWithNotificationSetting, UserNotificationModelForApi } from '@server/types/models/index.js'
import { UserNotificationType, UserRight } from '@peertube/peertube-models'
import { AbstractNotification } from '../common/abstract-notification.js'
export type NewPeerTubeVersionForAdminsPayload = {
application: MApplication
latestVersion: string
}
export class NewPeerTubeVersionForAdmins extends AbstractNotification <NewPeerTubeVersionForAdminsPayload> {
private admins: MUserDefault[]
async prepare () {
// Use the debug right to know who is an administrator
this.admins = await UserModel.listWithRight(UserRight.MANAGE_DEBUG)
}
log () {
logger.info('Notifying %s admins of new PeerTube version %s.', this.admins.length, this.payload.latestVersion)
}
getSetting (user: MUserWithNotificationSetting) {
return user.NotificationSetting.newPeerTubeVersion
}
getTargetUsers () {
return this.admins
}
createNotification (user: MUserWithNotificationSetting) {
const notification = UserNotificationModel.build<UserNotificationModelForApi>({
type: UserNotificationType.NEW_PEERTUBE_VERSION,
userId: user.id,
applicationId: this.payload.application.id
})
notification.Application = this.payload.application
return notification
}
createEmail (to: string) {
return {
to,
template: 'peertube-version-new',
subject: `A new PeerTube version is available: ${this.payload.latestVersion}`,
locals: {
latestVersion: this.payload.latestVersion
}
}
}
}

View file

@ -0,0 +1,58 @@
import { logger } from '@server/helpers/logger.js'
import { WEBSERVER } from '@server/initializers/constants.js'
import { UserModel } from '@server/models/user/user.js'
import { UserNotificationModel } from '@server/models/user/user-notification.js'
import { MPlugin, MUserDefault, MUserWithNotificationSetting, UserNotificationModelForApi } from '@server/types/models/index.js'
import { UserNotificationType, UserRight } from '@peertube/peertube-models'
import { AbstractNotification } from '../common/abstract-notification.js'
export class NewPluginVersionForAdmins extends AbstractNotification <MPlugin> {
private admins: MUserDefault[]
async prepare () {
// Use the debug right to know who is an administrator
this.admins = await UserModel.listWithRight(UserRight.MANAGE_DEBUG)
}
log () {
logger.info('Notifying %s admins of new PeerTube version %s.', this.admins.length, this.payload.latestVersion)
}
getSetting (user: MUserWithNotificationSetting) {
return user.NotificationSetting.newPluginVersion
}
getTargetUsers () {
return this.admins
}
createNotification (user: MUserWithNotificationSetting) {
const notification = UserNotificationModel.build<UserNotificationModelForApi>({
type: UserNotificationType.NEW_PLUGIN_VERSION,
userId: user.id,
pluginId: this.plugin.id
})
notification.Plugin = this.plugin
return notification
}
createEmail (to: string) {
const pluginUrl = WEBSERVER.URL + '/admin/plugins/list-installed?pluginType=' + this.plugin.type
return {
to,
template: 'plugin-version-new',
subject: `A new plugin/theme version is available: ${this.plugin.name}@${this.plugin.latestVersion}`,
locals: {
pluginName: this.plugin.name,
latestVersion: this.plugin.latestVersion,
pluginUrl
}
}
}
private get plugin () {
return this.payload
}
}

View file

@ -0,0 +1,48 @@
import { logger } from '@server/helpers/logger.js'
import { UserModel } from '@server/models/user/user.js'
import { UserNotificationModel } from '@server/models/user/user-notification.js'
import { MRegistration, MUserDefault, MUserWithNotificationSetting, UserNotificationModelForApi } from '@server/types/models/index.js'
import { UserNotificationType, UserRight } from '@peertube/peertube-models'
import { AbstractNotification } from '../common/abstract-notification.js'
export class RegistrationRequestForModerators extends AbstractNotification <MRegistration> {
private moderators: MUserDefault[]
async prepare () {
this.moderators = await UserModel.listWithRight(UserRight.MANAGE_REGISTRATIONS)
}
log () {
logger.info('Notifying %s moderators of new user registration request of %s.', this.moderators.length, this.payload.username)
}
getSetting (user: MUserWithNotificationSetting) {
return user.NotificationSetting.newUserRegistration
}
getTargetUsers () {
return this.moderators
}
createNotification (user: MUserWithNotificationSetting) {
const notification = UserNotificationModel.build<UserNotificationModelForApi>({
type: UserNotificationType.NEW_USER_REGISTRATION_REQUEST,
userId: user.id,
userRegistrationId: this.payload.id
})
notification.UserRegistration = this.payload
return notification
}
createEmail (to: string) {
return {
template: 'user-registration-request',
to,
subject: `A new user wants to register: ${this.payload.username}`,
locals: {
registration: this.payload
}
}
}
}