Init commit

This commit is contained in:
ShreejitPanchal
2026-05-19 19:56:02 +08:00
commit 6601501eff
4047 changed files with 2185372 additions and 0 deletions

View File

@@ -0,0 +1,60 @@
import { UserNotificationType, UserRight } from '@peertube/peertube-models'
import { t } from '@server/helpers/i18n.js'
import { logger } from '@server/helpers/logger.js'
import { CONFIG } from '@server/initializers/config.js'
import { adminUsersListUrl } from '@server/lib/client-urls.js'
import { UserNotificationModel } from '@server/models/user/user-notification.js'
import { UserModel } from '@server/models/user/user.js'
import { MUserDefault, MUserWithNotificationSetting, UserNotificationModelForApi } from '@server/types/models/index.js'
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 (user: MUserWithNotificationSetting) {
const to = { email: user.email, language: user.getLanguage() }
return {
template: 'user-registered',
to,
subject: t('A new user registered on {instanceName}', to.language, { instanceName: CONFIG.INSTANCE.NAME }),
locals: {
userUsername: this.payload.username,
userEmail: this.payload.email,
userPendingEmail: this.payload.pendingEmail,
accountUrl: this.payload.Account.getClientUrl(),
action: {
type: t('View users', to.language),
url: adminUsersListUrl
}
}
}
}
}

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,57 @@
import { UserNotificationType, UserRight } from '@peertube/peertube-models'
import { t } from '@server/helpers/i18n.js'
import { logger } from '@server/helpers/logger.js'
import { UserNotificationModel } from '@server/models/user/user-notification.js'
import { UserModel } from '@server/models/user/user.js'
import { MApplication, MUserDefault, MUserWithNotificationSetting, UserNotificationModelForApi } from '@server/types/models/index.js'
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 (user: MUserWithNotificationSetting) {
const to = { email: user.email, language: user.getLanguage() }
return {
to,
template: 'peertube-version-new',
subject: t('A new PeerTube version is available: {latestVersion}', to.language, { latestVersion: this.payload.latestVersion }),
locals: {
latestVersion: this.payload.latestVersion
}
}
}
}

View File

@@ -0,0 +1,68 @@
import { PluginType, UserNotificationType, UserRight } from '@peertube/peertube-models'
import { t } from '@server/helpers/i18n.js'
import { logger } from '@server/helpers/logger.js'
import { getPluginUrl } from '@server/lib/client-urls.js'
import { UserNotificationModel } from '@server/models/user/user-notification.js'
import { UserModel } from '@server/models/user/user.js'
import { MPlugin, MUserDefault, MUserWithNotificationSetting, UserNotificationModelForApi } from '@server/types/models/index.js'
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 (user: MUserWithNotificationSetting) {
const to = { email: user.email, language: user.getLanguage() }
const language = user.getLanguage()
const pluginUrl = getPluginUrl(this.plugin.type)
const context = { pluginName: this.plugin.name, latestVersion: this.plugin.latestVersion }
return {
to,
template: 'plugin-version-new',
subject: this.plugin.type === PluginType.PLUGIN
? t('A new version of the plugin {pluginName} is available: {latestVersion}', language, context)
: t('A new version of the theme {pluginName} is available: {latestVersion}', language, context),
locals: {
pluginName: this.plugin.name,
latestVersion: this.plugin.latestVersion,
isPlugin: this.plugin.type === PluginType.PLUGIN,
pluginUrl
}
}
}
private get plugin () {
return this.payload
}
}

View File

@@ -0,0 +1,59 @@
import { UserNotificationType, UserRight } from '@peertube/peertube-models'
import { t } from '@server/helpers/i18n.js'
import { logger } from '@server/helpers/logger.js'
import { CONFIG } from '@server/initializers/config.js'
import { adminRegistrationsListUrl } from '@server/lib/client-urls.js'
import { UserNotificationModel } from '@server/models/user/user-notification.js'
import { UserModel } from '@server/models/user/user.js'
import { MRegistration, MUserDefault, MUserWithNotificationSetting, UserNotificationModelForApi } from '@server/types/models/index.js'
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 (user: MUserWithNotificationSetting) {
const to = { email: user.email, language: user.getLanguage() }
const language = user.getLanguage()
return {
template: 'user-registration-request',
to,
subject: t('A new user wants to register: {username}', to.language, { username: this.payload.username }),
locals: {
registration: this.payload,
instanceName: CONFIG.INSTANCE.NAME,
action: {
url: adminRegistrationsListUrl,
text: t('View registration request', language)
}
}
}
}
}