ActivityPub-federated video streaming platform using P2P directly in your web browser
Reorganize shared models
Chocobozzzbd45d503e5d0
diff --git a/client/src/app/+admin/plugins/shared/plugin-api.service.ts b/client/src/app/+admin/plugins/shared/plugin-api.service.tsindex bf9129e01f..1fb8278320 100644--- a/client/src/app/+admin/plugins/shared/plugin-api.service.ts+++ b/client/src/app/+admin/plugins/shared/plugin-api.service.ts@@ -5,12 +5,12 @@ import { Injectable } from '@angular/core'import { ComponentPagination, RestExtractor, RestService } from '@app/core'import { PluginService } from '@app/core/plugins/plugin.service'import { I18n } from '@ngx-translate/i18n-polyfill'+import { peertubeTranslate } from '@shared/core-utils/i18n'import {InstallOrUpdatePlugin,ManagePlugin,PeerTubePlugin,PeerTubePluginIndex,- peertubeTranslate,PluginType,RegisteredServerSettings,ResultListdiff --git a/client/src/app/+admin/users/user-edit/user-edit.ts b/client/src/app/+admin/users/user-edit/user-edit.tsindex 22ec425208..bdbb108141 100644--- a/client/src/app/+admin/users/user-edit/user-edit.ts+++ b/client/src/app/+admin/users/user-edit/user-edit.ts@@ -1,8 +1,9 @@-import { OnInit, Directive } from '@angular/core'+import { Directive, OnInit } from '@angular/core'import { ConfigService } from '@app/+admin/config/shared/config.service'import { AuthService, ScreenService, ServerService, User } from '@app/core'import { FormReactive } from '@app/shared/shared-forms'-import { ServerConfig, USER_ROLE_LABELS, UserAdminFlag, UserRole, VideoResolution } from '@shared/models'+import { USER_ROLE_LABELS } from '@shared/core-utils/users'+import { ServerConfig, UserAdminFlag, UserRole, VideoResolution } from '@shared/models'@Directive()export abstract class UserEdit extends FormReactive implements OnInit {diff --git a/client/src/app/+videos/video-list/overview/overview.service.ts b/client/src/app/+videos/video-list/overview/overview.service.tsindex 4458454d52..3aa64ebc81 100644--- a/client/src/app/+videos/video-list/overview/overview.service.ts+++ b/client/src/app/+videos/video-list/overview/overview.service.ts@@ -5,7 +5,8 @@ import { Injectable } from '@angular/core'import { RestExtractor, ServerService } from '@app/core'import { immutableAssign } from '@app/helpers'import { VideoService } from '@app/shared/shared-main'-import { peertubeTranslate, VideosOverview as VideosOverviewServer } from '@shared/models'+import { peertubeTranslate } from '@shared/core-utils/i18n'+import { VideosOverview as VideosOverviewServer } from '@shared/models'import { environment } from '../../../../environments/environment'import { VideosOverview } from './videos-overview.model'diff --git a/client/src/app/app.component.ts b/client/src/app/app.component.tsindex dee7fd0569..ff0e28aa5f 100644--- a/client/src/app/app.component.ts+++ b/client/src/app/app.component.ts@@ -13,7 +13,8 @@ import { InstanceConfigWarningModalComponent } from '@app/modal/instance-config-import { WelcomeModalComponent } from '@app/modal/welcome-modal.component'import { NgbModal } from '@ng-bootstrap/ng-bootstrap'import { I18n } from '@ngx-translate/i18n-polyfill'-import { BroadcastMessageLevel, getShortLocale, is18nPath, ServerConfig, UserRole } from '@shared/models'+import { getShortLocale, is18nPath } from '@shared/core-utils/i18n'+import { BroadcastMessageLevel, ServerConfig, UserRole } from '@shared/models'import { MenuService } from './core/menu/menu.service'import { POP_STATE_MODAL_DISMISS } from './helpers'import { peertubeLocalStorage } from '@root-helpers/peertube-web-storage'diff --git a/client/src/app/app.module.ts b/client/src/app/app.module.tsindex 9698de275b..b35cc1716c 100644--- a/client/src/app/app.module.ts+++ b/client/src/app/app.module.ts@@ -5,7 +5,7 @@ import { BrowserModule } from '@angular/platform-browser'import { ServerService } from '@app/core'import localeOc from '@app/helpers/locales/oc'import { MetaLoader, MetaModule, MetaStaticLoader, PageTitlePositioning } from '@ngx-meta/core'-import { buildFileLocale, getCompleteLocale, isDefaultLocale } from '@shared/models'+import { buildFileLocale, getCompleteLocale, isDefaultLocale } from '@shared/core-utils/i18n'import { AppRoutingModule } from './app-routing.module'import { AppComponent } from './app.component'import { CoreModule } from './core'diff --git a/client/src/app/core/auth/auth-user.model.ts b/client/src/app/core/auth/auth-user.model.tsindex ee61ff8811..5efc6e1abf 100644--- a/client/src/app/core/auth/auth-user.model.ts+++ b/client/src/app/core/auth/auth-user.model.ts@@ -1,9 +1,9 @@import { Observable, of } from 'rxjs'import { map } from 'rxjs/operators'import { User } from '@app/core/users/user.model'-import { peertubeLocalStorage } from '@root-helpers/peertube-web-storage'+import { peertubeLocalStorage } from '@app/helpers/peertube-web-storage'+import { hasUserRight } from '@shared/core-utils/users'import {- hasUserRight,MyUser as ServerMyUserModel,MyUserSpecialPlaylist,NSFWPolicyType,diff --git a/client/src/app/core/plugins/plugin.service.ts b/client/src/app/core/plugins/plugin.service.tsindex 3cab64142a..dc115c0e1d 100644--- a/client/src/app/core/plugins/plugin.service.ts+++ b/client/src/app/core/plugins/plugin.service.ts@@ -9,15 +9,13 @@ import { RestExtractor } from '@app/core/rest'import { ServerService } from '@app/core/server/server.service'import { getDevLocale, importModule, isOnDevLocale } from '@app/helpers'import { CustomModalComponent } from '@app/modal/custom-modal.component'+import { getCompleteLocale, isDefaultLocale, peertubeTranslate } from '@shared/core-utils/i18n'import { getHookType, internalRunHook } from '@shared/core-utils/plugins/hooks'import {ClientHook,ClientHookName,clientHookObject,ClientScript,- getCompleteLocale,- isDefaultLocale,- peertubeTranslate,PluginClientScope,PluginTranslation,PluginType,diff --git a/client/src/app/core/server/server.service.ts b/client/src/app/core/server/server.service.tsindex c69e0919ac..5bcf33c1bc 100644--- a/client/src/app/core/server/server.service.ts+++ b/client/src/app/core/server/server.service.ts@@ -4,15 +4,8 @@ import { HttpClient } from '@angular/common/http'import { Inject, Injectable, LOCALE_ID } from '@angular/core'import { getDevLocale, isOnDevLocale, sortBy } from '@app/helpers'import { peertubeLocalStorage } from '@root-helpers/peertube-web-storage'-import {- getCompleteLocale,- isDefaultLocale,- peertubeTranslate,- SearchTargetType,- ServerConfig,- ServerStats,- VideoConstant-} from '@shared/models'+import { getCompleteLocale, isDefaultLocale, peertubeTranslate } from '@shared/core-utils/i18n'+import { SearchTargetType, ServerConfig, ServerStats, VideoConstant } from '@shared/models'import { environment } from '../../../environments/environment'@Injectable()diff --git a/client/src/app/core/users/user.model.ts b/client/src/app/core/users/user.model.tsindex a94b35c469..f0d3a08b84 100644--- a/client/src/app/core/users/user.model.ts+++ b/client/src/app/core/users/user.model.ts@@ -1,7 +1,7 @@import { Account } from '@app/shared/shared-main/account/account.model'+import { hasUserRight } from '@shared/core-utils/users'import {Avatar,- hasUserRight,NSFWPolicyType,User as UserServerModel,UserAdminFlag,diff --git a/client/src/app/menu/language-chooser.component.ts b/client/src/app/menu/language-chooser.component.tsindex 3e89f72b84..e15aeff201 100644--- a/client/src/app/menu/language-chooser.component.ts+++ b/client/src/app/menu/language-chooser.component.ts@@ -1,7 +1,7 @@import { Component, ElementRef, Inject, LOCALE_ID, ViewChild } from '@angular/core'import { getDevLocale, isOnDevLocale, sortBy } from '@app/helpers'import { NgbModal } from '@ng-bootstrap/ng-bootstrap'-import { getCompleteLocale, getShortLocale, I18N_LOCALES } from '@shared/models'+import { getCompleteLocale, getShortLocale, I18N_LOCALES } from '@shared/core-utils/i18n'@Component({selector: 'my-language-chooser',diff --git a/client/src/app/shared/shared-instance/instance.service.ts b/client/src/app/shared/shared-instance/instance.service.tsindex ba9797bb5c..fcfa59f288 100644--- a/client/src/app/shared/shared-instance/instance.service.ts+++ b/client/src/app/shared/shared-instance/instance.service.ts@@ -3,7 +3,8 @@ import { catchError, map } from 'rxjs/operators'import { HttpClient } from '@angular/common/http'import { Injectable } from '@angular/core'import { MarkdownService, RestExtractor, ServerService } from '@app/core'-import { About, peertubeTranslate } from '@shared/models'+import { peertubeTranslate } from '@shared/core-utils/i18n'+import { About } from '@shared/models'import { environment } from '../../../environments/environment'@Injectable()diff --git a/client/src/app/shared/shared-main/video-caption/video-caption.service.ts b/client/src/app/shared/shared-main/video-caption/video-caption.service.tsindex d45fb837ae..283c63f980 100644--- a/client/src/app/shared/shared-main/video-caption/video-caption.service.ts+++ b/client/src/app/shared/shared-main/video-caption/video-caption.service.ts@@ -5,7 +5,8 @@ import { Injectable } from '@angular/core'import { RestExtractor, ServerService } from '@app/core'import { objectToFormData, sortBy } from '@app/helpers'import { VideoService } from '@app/shared/shared-main/video'-import { peertubeTranslate, ResultList, VideoCaption } from '@shared/models'+import { peertubeTranslate } from '@shared/core-utils/i18n'+import { ResultList, VideoCaption } from '@shared/models'import { VideoCaptionEdit } from './video-caption-edit.model'@Injectable()diff --git a/client/src/app/shared/shared-main/video/video-import.service.ts b/client/src/app/shared/shared-main/video/video-import.service.tsindex a700abacb0..99df78e3a0 100644--- a/client/src/app/shared/shared-main/video/video-import.service.ts+++ b/client/src/app/shared/shared-main/video/video-import.service.ts@@ -5,7 +5,8 @@ import { HttpClient, HttpParams } from '@angular/common/http'import { Injectable } from '@angular/core'import { RestExtractor, RestPagination, RestService, ServerService, UserService } from '@app/core'import { objectToFormData } from '@app/helpers'-import { peertubeTranslate, ResultList, VideoImport, VideoImportCreate, VideoUpdate } from '@shared/models'+import { peertubeTranslate } from '@shared/core-utils/i18n'+import { ResultList, VideoImport, VideoImportCreate, VideoUpdate } from '@shared/models'import { environment } from '../../../../environments/environment'@Injectable()diff --git a/client/src/app/shared/shared-main/video/video.model.ts b/client/src/app/shared/shared-main/video/video.model.tsindex 147d0817e2..73f0198e20 100644--- a/client/src/app/shared/shared-main/video/video.model.ts+++ b/client/src/app/shared/shared-main/video/video.model.ts@@ -1,9 +1,9 @@import { AuthUser } from '@app/core'import { User } from '@app/core/users/user.model'import { durationToString, getAbsoluteAPIUrl, getAbsoluteEmbedUrl } from '@app/helpers'+import { peertubeTranslate } from '@shared/core-utils/i18n'import {Avatar,- peertubeTranslate,ServerConfig,UserRight,Video as VideoServerModel,diff --git a/client/src/app/shared/shared-moderation/report-modals/account-report.component.ts b/client/src/app/shared/shared-moderation/report-modals/account-report.component.tsindex 78ca934c73..08dbe95381 100644--- a/client/src/app/shared/shared-moderation/report-modals/account-report.component.ts+++ b/client/src/app/shared/shared-moderation/report-modals/account-report.component.ts@@ -6,7 +6,8 @@ import { Account } from '@app/shared/shared-main'import { NgbModal } from '@ng-bootstrap/ng-bootstrap'import { NgbModalRef } from '@ng-bootstrap/ng-bootstrap/modal/modal-ref'import { I18n } from '@ngx-translate/i18n-polyfill'-import { abusePredefinedReasonsMap, AbusePredefinedReasonsString } from '@shared/models'+import { abusePredefinedReasonsMap } from '@shared/core-utils/abuse'+import { AbusePredefinedReasonsString } from '@shared/models'import { AbuseService } from '../abuse.service'@Component({diff --git a/client/src/app/shared/shared-moderation/report-modals/comment-report.component.ts b/client/src/app/shared/shared-moderation/report-modals/comment-report.component.tsindex 00d7b8d342..2769874d9a 100644--- a/client/src/app/shared/shared-moderation/report-modals/comment-report.component.ts+++ b/client/src/app/shared/shared-moderation/report-modals/comment-report.component.ts@@ -6,7 +6,8 @@ import { VideoComment } from '@app/shared/shared-video-comment'import { NgbModal } from '@ng-bootstrap/ng-bootstrap'import { NgbModalRef } from '@ng-bootstrap/ng-bootstrap/modal/modal-ref'import { I18n } from '@ngx-translate/i18n-polyfill'-import { abusePredefinedReasonsMap, AbusePredefinedReasonsString } from '@shared/models'+import { abusePredefinedReasonsMap } from '@shared/core-utils/abuse'+import { AbusePredefinedReasonsString } from '@shared/models'import { AbuseService } from '../abuse.service'@Component({diff --git a/client/src/app/shared/shared-moderation/report-modals/video-report.component.ts b/client/src/app/shared/shared-moderation/report-modals/video-report.component.tsindex 7d53ea3c9c..09ab98dfe9 100644--- a/client/src/app/shared/shared-moderation/report-modals/video-report.component.ts+++ b/client/src/app/shared/shared-moderation/report-modals/video-report.component.ts@@ -7,7 +7,8 @@ import { AbuseValidatorsService, FormReactive, FormValidatorService } from '@appimport { NgbModal } from '@ng-bootstrap/ng-bootstrap'import { NgbModalRef } from '@ng-bootstrap/ng-bootstrap/modal/modal-ref'import { I18n } from '@ngx-translate/i18n-polyfill'-import { abusePredefinedReasonsMap, AbusePredefinedReasonsString } from '@shared/models'+import { abusePredefinedReasonsMap } from '@shared/core-utils/abuse'+import { AbusePredefinedReasonsString } from '@shared/models'import { Video } from '../../shared-main'import { AbuseService } from '../abuse.service'diff --git a/client/src/app/shared/shared-video-playlist/video-playlist.model.ts b/client/src/app/shared/shared-video-playlist/video-playlist.model.tsindex 8f63d2abd2..7de379cdfc 100644--- a/client/src/app/shared/shared-video-playlist/video-playlist.model.ts+++ b/client/src/app/shared/shared-video-playlist/video-playlist.model.ts@@ -1,8 +1,8 @@import { getAbsoluteAPIUrl } from '@app/helpers'import { Actor } from '@app/shared/shared-main'+import { peertubeTranslate } from '@shared/core-utils/i18n'import {AccountSummary,- peertubeTranslate,VideoChannelSummary,VideoConstant,VideoPlaylist as ServerVideoPlaylist,diff --git a/client/src/assets/player/peertube-player-manager.ts b/client/src/assets/player/peertube-player-manager.tsindex e9597dde1a..6a6d634627 100644--- a/client/src/assets/player/peertube-player-manager.ts+++ b/client/src/assets/player/peertube-player-manager.ts@@ -19,7 +19,8 @@ import './videojs-components/settings-panel'import './videojs-components/settings-panel-child'import './videojs-components/theater-button'import videojs from 'video.js'-import { isDefaultLocale, VideoFile } from '@shared/models'+import { VideoFile } from '@shared/models'+import { isDefaultLocale } from '@shared/core-utils/i18n'import { RedundancyUrlManager } from './p2p-media-loader/redundancy-url-manager'import { segmentUrlBuilderFactory } from './p2p-media-loader/segment-url-builder'import { segmentValidatorFactory } from './p2p-media-loader/segment-validator'diff --git a/client/src/assets/player/translations-manager.ts b/client/src/assets/player/translations-manager.tsindex 2bde7d6caa..631e3feba1 100644--- a/client/src/assets/player/translations-manager.ts+++ b/client/src/assets/player/translations-manager.ts@@ -1,4 +1,4 @@-import { getCompleteLocale, getShortLocale, is18nLocale, isDefaultLocale } from '@shared/models'+import { getCompleteLocale, getShortLocale, is18nLocale, isDefaultLocale } from '@shared/core-utils/i18n'export class TranslationsManager {private static videojsLocaleCache: { [ path: string ]: any } = {}diff --git a/client/src/standalone/videos/embed.ts b/client/src/standalone/videos/embed.tsindex def6079164..89903aa359 100644--- a/client/src/standalone/videos/embed.ts+++ b/client/src/standalone/videos/embed.ts@@ -1,8 +1,8 @@import './embed.scss'import videojs from 'video.js'import { objectToUrlEncoded, peertubeLocalStorage, PureAuthUser } from '@root-helpers/index'+import { peertubeTranslate } from '../../../../shared/core-utils/i18n'import {- peertubeTranslate,ResultList,ServerConfig,UserRefreshToken,diff --git a/client/webpack/webpack.video-embed.js b/client/webpack/webpack.video-embed.jsindex 83622a9741..aa7c5e5500 100644--- a/client/webpack/webpack.video-embed.js+++ b/client/webpack/webpack.video-embed.js@@ -29,6 +29,7 @@ module.exports = function () {'video.js$': path.resolve('node_modules/video.js/core.js'),'@root-helpers': path.resolve('src/root-helpers'),'@shared/models': path.resolve('../shared/models'),+ '@shared/core-utils': path.resolve('../shared/core-utils')}},diff --git a/server/controllers/api/abuse.ts b/server/controllers/api/abuse.tsindex 03e6be8c8d..b97b99f16a 100644--- a/server/controllers/api/abuse.ts+++ b/server/controllers/api/abuse.ts@@ -1,9 +1,12 @@import * as express from 'express'+import { logger } from '@server/helpers/logger'import { createAccountAbuse, createVideoAbuse, createVideoCommentAbuse } from '@server/lib/moderation'+import { Notifier } from '@server/lib/notifier'import { AbuseModel } from '@server/models/abuse/abuse'import { AbuseMessageModel } from '@server/models/abuse/abuse-message'import { getServerActor } from '@server/models/application/application'-import { AbuseCreate, abusePredefinedReasonsMap, AbuseState, UserRight } from '../../../shared'+import { abusePredefinedReasonsMap } from '@shared/core-utils/abuse'+import { AbuseCreate, AbuseState, UserRight } from '../../../shared'import { getFormattedObjects } from '../../helpers/utils'import { sequelizeTypescript } from '../../initializers/database'import {@@ -25,8 +28,6 @@ import {setDefaultSort} from '../../middlewares'import { AccountModel } from '../../models/account/account'-import { Notifier } from '@server/lib/notifier'-import { logger } from '@server/helpers/logger'const abuseRouter = express.Router()diff --git a/server/controllers/client.ts b/server/controllers/client.tsindex 8c7f881a9e..7c80820f45 100644--- a/server/controllers/client.ts+++ b/server/controllers/client.ts@@ -1,13 +1,13 @@-import { constants, promises as fs } from 'fs'import * as express from 'express'+import { constants, promises as fs } from 'fs'import { join } from 'path'+import { CONFIG } from '@server/initializers/config'+import { buildFileLocale, getCompleteLocale, is18nLocale, LOCALE_FILES } from '@shared/core-utils/i18n'import { root } from '../helpers/core-utils'+import { logger } from '../helpers/logger'import { ACCEPT_HEADERS, STATIC_MAX_AGE } from '../initializers/constants'-import { asyncMiddleware, embedCSP } from '../middlewares'-import { buildFileLocale, getCompleteLocale, is18nLocale, LOCALE_FILES } from '../../shared/models/i18n/i18n'import { ClientHtml } from '../lib/client-html'-import { logger } from '../helpers/logger'-import { CONFIG } from '@server/initializers/config'+import { asyncMiddleware, embedCSP } from '../middlewares'const clientsRouter = express.Router()diff --git a/server/controllers/plugins.ts b/server/controllers/plugins.tsindex f88a1632d7..7b947bb6e7 100644--- a/server/controllers/plugins.ts+++ b/server/controllers/plugins.ts@@ -6,7 +6,7 @@ import { getPluginValidator, pluginStaticDirectoryValidator, getExternalAuthValiimport { serveThemeCSSValidator } from '../middlewares/validators/themes'import { PluginType } from '../../shared/models/plugins/plugin.type'import { isTestInstance } from '../helpers/core-utils'-import { getCompleteLocale, is18nLocale } from '../../shared/models/i18n'+import { getCompleteLocale, is18nLocale } from '../../shared/core-utils/i18n'import { logger } from '@server/helpers/logger'const sendFileOptions = {diff --git a/server/helpers/custom-validators/abuses.ts b/server/helpers/custom-validators/abuses.tsindex 0ddde4b066..94719641ab 100644--- a/server/helpers/custom-validators/abuses.ts+++ b/server/helpers/custom-validators/abuses.ts@@ -1,5 +1,6 @@import validator from 'validator'-import { AbuseFilter, abusePredefinedReasonsMap, AbusePredefinedReasonsString, AbuseVideoIs, AbuseCreate } from '@shared/models'+import { abusePredefinedReasonsMap } from '@shared/core-utils/abuse'+import { AbuseCreate, AbuseFilter, AbusePredefinedReasonsString, AbuseVideoIs } from '@shared/models'import { ABUSE_STATES, CONSTRAINTS_FIELDS } from '../../initializers/constants'import { exists, isArray } from './misc'diff --git a/server/helpers/custom-validators/plugins.ts b/server/helpers/custom-validators/plugins.tsindex d2fc039362..f2d4efb32a 100644--- a/server/helpers/custom-validators/plugins.ts+++ b/server/helpers/custom-validators/plugins.ts@@ -8,7 +8,8 @@ import { isUrlValid } from './activitypub/misc'const PLUGINS_CONSTRAINTS_FIELDS = CONSTRAINTS_FIELDS.PLUGINSfunction isPluginTypeValid (value: any) {- return exists(value) && validator.isInt('' + value) && PluginType[value] !== undefined+ return exists(value) &&+ (value === PluginType.PLUGIN || value === PluginType.THEME)}function isPluginNameValid (value: string) {diff --git a/server/helpers/custom-validators/video-blacklist.ts b/server/helpers/custom-validators/video-blacklist.tsindex 17cb3b00b6..34fcec38e3 100644--- a/server/helpers/custom-validators/video-blacklist.ts+++ b/server/helpers/custom-validators/video-blacklist.ts@@ -10,7 +10,8 @@ function isVideoBlacklistReasonValid (value: string) {}function isVideoBlacklistTypeValid (value: any) {- return exists(value) && validator.isInt('' + value) && VideoBlacklistType[value] !== undefined+ return exists(value) &&+ (value === VideoBlacklistType.AUTO_BEFORE_PUBLISHED || value === VideoBlacklistType.MANUAL)}// ---------------------------------------------------------------------------diff --git a/server/lib/activitypub/process/process-flag.ts b/server/lib/activitypub/process/process-flag.tsindex 6350cee128..40d07558c6 100644--- a/server/lib/activitypub/process/process-flag.ts+++ b/server/lib/activitypub/process/process-flag.ts@@ -2,7 +2,8 @@ import { createAccountAbuse, createVideoAbuse, createVideoCommentAbuse } from '@import { AccountModel } from '@server/models/account/account'import { VideoModel } from '@server/models/video/video'import { VideoCommentModel } from '@server/models/video/video-comment'-import { AbuseObject, abusePredefinedReasonsMap, AbuseState, ActivityCreate, ActivityFlag } from '../../../../shared'+import { abusePredefinedReasonsMap } from '@shared/core-utils/abuse'+import { AbuseObject, AbuseState, ActivityCreate, ActivityFlag } from '../../../../shared'import { getAPId } from '../../../helpers/activitypub'import { retryTransactionWrapper } from '../../../helpers/database-utils'import { logger } from '../../../helpers/logger'diff --git a/server/lib/client-html.ts b/server/lib/client-html.tsindex ffe53d0d50..d8ae73b5de 100644--- a/server/lib/client-html.ts+++ b/server/lib/client-html.ts@@ -1,5 +1,5 @@import * as express from 'express'-import { buildFileLocale, getDefaultLocale, is18nLocale, POSSIBLE_LOCALES } from '../../shared/models/i18n/i18n'+import { buildFileLocale, getDefaultLocale, is18nLocale, POSSIBLE_LOCALES } from '../../shared/core-utils/i18n/i18n'import {AVATARS_SIZE,CUSTOM_HTML_TAG_COMMENTS,diff --git a/server/middlewares/user-right.ts b/server/middlewares/user-right.tsindex 4d836485cc..aaf0b323a0 100644--- a/server/middlewares/user-right.ts+++ b/server/middlewares/user-right.ts@@ -6,7 +6,7 @@ function ensureUserHasRight (userRight: UserRight) {return function (req: express.Request, res: express.Response, next: express.NextFunction) {const user = res.locals.oauth.token.userif (user.hasRight(userRight) === false) {- const message = `User ${user.username} does not have right ${UserRight[userRight]} to access to ${req.path}.`+ const message = `User ${user.username} does not have right ${userRight} to access to ${req.path}.`logger.info(message)return res.status(403).json({ error: message })diff --git a/server/models/abuse/abuse.ts b/server/models/abuse/abuse.tsindex 1b599db629..2a407c3d26 100644--- a/server/models/abuse/abuse.ts+++ b/server/models/abuse/abuse.ts@@ -17,11 +17,11 @@ import {UpdatedAt} from 'sequelize-typescript'import { isAbuseModerationCommentValid, isAbuseReasonValid, isAbuseStateValid } from '@server/helpers/custom-validators/abuses'+import { abusePredefinedReasonsMap } from '@shared/core-utils/abuse'import {AbuseFilter,AbuseObject,AbusePredefinedReasons,- abusePredefinedReasonsMap,AbusePredefinedReasonsString,AbuseState,AbuseVideoIs,@@ -646,8 +646,10 @@ export class AbuseModel extends Model<AbuseModel> {}private static getPredefinedReasonsStrings (predefinedReasons: AbusePredefinedReasons[]): AbusePredefinedReasonsString[] {+ const invertedPredefinedReasons = invert(abusePredefinedReasonsMap)+return (predefinedReasons || [])- .filter(r => r in AbusePredefinedReasons)- .map(r => invert(abusePredefinedReasonsMap)[r] as AbusePredefinedReasonsString)+ .map(r => invertedPredefinedReasons[r] as AbusePredefinedReasonsString)+ .filter(v => !!v)}}diff --git a/server/models/account/user.ts b/server/models/account/user.tsindex 5f45f8e7cd..22e6715b46 100644--- a/server/models/account/user.ts+++ b/server/models/account/user.ts@@ -1,3 +1,5 @@+import * as Bluebird from 'bluebird'+import { values } from 'lodash'import { col, FindOptions, fn, literal, Op, QueryTypes, where, WhereOptions } from 'sequelize'import {AfterDestroy,@@ -19,8 +21,21 @@ import {Table,UpdatedAt} from 'sequelize-typescript'-import { hasUserRight, MyUser, USER_ROLE_LABELS, UserRight, AbuseState, VideoPlaylistType, VideoPrivacy } from '../../../shared'+import {+ MMyUserFormattable,+ MUserDefault,+ MUserFormattable,+ MUserId,+ MUserNotifSettingChannelDefault,+ MUserWithNotificationSetting,+ MVideoFullLight+} from '@server/types/models'+import { hasUserRight, USER_ROLE_LABELS } from '../../../shared/core-utils/users'+import { AbuseState, MyUser, UserRight, VideoPlaylistType, VideoPrivacy } from '../../../shared/models'import { User, UserRole } from '../../../shared/models/users'+import { UserAdminFlag } from '../../../shared/models/users/user-flag.model'+import { NSFWPolicyType } from '../../../shared/models/videos/nsfw-policy.type'+import { isThemeNameValid } from '../../helpers/custom-validators/plugins'import {isNoInstanceConfigWarningModal,isNoWelcomeModal,@@ -42,33 +57,19 @@ import {isUserWebTorrentEnabledValid} from '../../helpers/custom-validators/users'import { comparePassword, cryptPassword } from '../../helpers/peertube-crypto'+import { DEFAULT_USER_THEME_NAME, NSFW_POLICY_TYPES } from '../../initializers/constants'+import { clearCacheByUserId } from '../../lib/oauth-model'+import { getThemeOrDefault } from '../../lib/plugins/theme-utils'+import { ActorModel } from '../activitypub/actor'+import { ActorFollowModel } from '../activitypub/actor-follow'import { OAuthTokenModel } from '../oauth/oauth-token'import { getSort, throwIfNotValid } from '../utils'+import { VideoModel } from '../video/video'import { VideoChannelModel } from '../video/video-channel'+import { VideoImportModel } from '../video/video-import'import { VideoPlaylistModel } from '../video/video-playlist'import { AccountModel } from './account'-import { NSFWPolicyType } from '../../../shared/models/videos/nsfw-policy.type'-import { values } from 'lodash'-import { DEFAULT_USER_THEME_NAME, NSFW_POLICY_TYPES } from '../../initializers/constants'-import { clearCacheByUserId } from '../../lib/oauth-model'import { UserNotificationSettingModel } from './user-notification-setting'-import { VideoModel } from '../video/video'-import { ActorModel } from '../activitypub/actor'-import { ActorFollowModel } from '../activitypub/actor-follow'-import { VideoImportModel } from '../video/video-import'-import { UserAdminFlag } from '../../../shared/models/users/user-flag.model'-import { isThemeNameValid } from '../../helpers/custom-validators/plugins'-import { getThemeOrDefault } from '../../lib/plugins/theme-utils'-import * as Bluebird from 'bluebird'-import {- MMyUserFormattable,- MUserDefault,- MUserFormattable,- MUserId,- MUserNotifSettingChannelDefault,- MUserWithNotificationSetting,- MVideoFullLight-} from '@server/types/models'enum ScopeNames {FOR_ME_API = 'FOR_ME_API',diff --git a/shared/core-utils/abuse/abuse-predefined-reasons.ts b/shared/core-utils/abuse/abuse-predefined-reasons.tsnew file mode 100644index 0000000000..9967e54dd1--- /dev/null+++ b/shared/core-utils/abuse/abuse-predefined-reasons.ts@@ -0,0 +1,14 @@+import { AbusePredefinedReasons, AbusePredefinedReasonsString } from '../../models/moderation/abuse/abuse-reason.model'++export const abusePredefinedReasonsMap: {+ [key in AbusePredefinedReasonsString]: AbusePredefinedReasons+} = {+ violentOrRepulsive: AbusePredefinedReasons.VIOLENT_OR_REPULSIVE,+ hatefulOrAbusive: AbusePredefinedReasons.HATEFUL_OR_ABUSIVE,+ spamOrMisleading: AbusePredefinedReasons.SPAM_OR_MISLEADING,+ privacy: AbusePredefinedReasons.PRIVACY,+ rights: AbusePredefinedReasons.RIGHTS,+ serverRules: AbusePredefinedReasons.SERVER_RULES,+ thumbnails: AbusePredefinedReasons.THUMBNAILS,+ captions: AbusePredefinedReasons.CAPTIONS+}diff --git a/shared/core-utils/abuse/index.ts b/shared/core-utils/abuse/index.tsnew file mode 100644index 0000000000..244b83cff4--- /dev/null+++ b/shared/core-utils/abuse/index.ts@@ -0,0 +1 @@+export * from './abuse-predefined-reasons'diff --git a/shared/models/i18n/i18n.ts b/shared/core-utils/i18n/i18n.tssimilarity index 100%rename from shared/models/i18n/i18n.tsrename to shared/core-utils/i18n/i18n.tsdiff --git a/shared/models/i18n/index.ts b/shared/core-utils/i18n/index.tssimilarity index 100%rename from shared/models/i18n/index.tsrename to shared/core-utils/i18n/index.tsdiff --git a/shared/core-utils/users/index.ts b/shared/core-utils/users/index.tsnew file mode 100644index 0000000000..1cbf0af1b1--- /dev/null+++ b/shared/core-utils/users/index.ts@@ -0,0 +1 @@+export * from './user-role'diff --git a/shared/core-utils/users/user-role.ts b/shared/core-utils/users/user-role.tsnew file mode 100644index 0000000000..2b322faf35--- /dev/null+++ b/shared/core-utils/users/user-role.ts@@ -0,0 +1,35 @@+import { UserRight, UserRole } from '../../models/users'++export const USER_ROLE_LABELS: { [ id in UserRole ]: string } = {+ [UserRole.USER]: 'User',+ [UserRole.MODERATOR]: 'Moderator',+ [UserRole.ADMINISTRATOR]: 'Administrator'+}++const userRoleRights: { [ id in UserRole ]: UserRight[] } = {+ [UserRole.ADMINISTRATOR]: [+ UserRight.ALL+ ],++ [UserRole.MODERATOR]: [+ UserRight.MANAGE_VIDEO_BLACKLIST,+ UserRight.MANAGE_ABUSES,+ UserRight.REMOVE_ANY_VIDEO,+ UserRight.REMOVE_ANY_VIDEO_CHANNEL,+ UserRight.REMOVE_ANY_VIDEO_PLAYLIST,+ UserRight.REMOVE_ANY_VIDEO_COMMENT,+ UserRight.UPDATE_ANY_VIDEO,+ UserRight.SEE_ALL_VIDEOS,+ UserRight.MANAGE_ACCOUNTS_BLOCKLIST,+ UserRight.MANAGE_SERVERS_BLOCKLIST,+ UserRight.MANAGE_USERS+ ],++ [UserRole.USER]: []+}++export function hasUserRight (userRole: UserRole, userRight: UserRight) {+ const userRights = userRoleRights[userRole]++ return userRights.includes(UserRight.ALL) || userRights.includes(userRight)+}diff --git a/shared/models/feeds/feed-format.enum.ts b/shared/models/feeds/feed-format.enum.tsindex f3173a7813..d3d5743312 100644--- a/shared/models/feeds/feed-format.enum.ts+++ b/shared/models/feeds/feed-format.enum.ts@@ -1,4 +1,4 @@-export enum FeedFormat {+export const enum FeedFormat {RSS = 'xml',ATOM = 'atom',JSON = 'json'diff --git a/shared/models/index.ts b/shared/models/index.tsindex a68f57148d..2214f7ca3c 100644--- a/shared/models/index.ts+++ b/shared/models/index.ts@@ -7,7 +7,6 @@ export * from './redundancy'export * from './users'export * from './videos'export * from './feeds'-export * from './i18n'export * from './overviews'export * from './plugins'export * from './search'diff --git a/shared/models/moderation/abuse/abuse-reason.model.ts b/shared/models/moderation/abuse/abuse-reason.model.tsindex 36875969d2..57359aef66 100644--- a/shared/models/moderation/abuse/abuse-reason.model.ts+++ b/shared/models/moderation/abuse/abuse-reason.model.ts@@ -1,4 +1,4 @@-export enum AbusePredefinedReasons {+export const enum AbusePredefinedReasons {VIOLENT_OR_REPULSIVE = 1,HATEFUL_OR_ABUSIVE,SPAM_OR_MISLEADING,@@ -18,16 +18,3 @@ export type AbusePredefinedReasonsString ='serverRules' |'thumbnails' |'captions'--export const abusePredefinedReasonsMap: {- [key in AbusePredefinedReasonsString]: AbusePredefinedReasons-} = {- violentOrRepulsive: AbusePredefinedReasons.VIOLENT_OR_REPULSIVE,- hatefulOrAbusive: AbusePredefinedReasons.HATEFUL_OR_ABUSIVE,- spamOrMisleading: AbusePredefinedReasons.SPAM_OR_MISLEADING,- privacy: AbusePredefinedReasons.PRIVACY,- rights: AbusePredefinedReasons.RIGHTS,- serverRules: AbusePredefinedReasons.SERVER_RULES,- thumbnails: AbusePredefinedReasons.THUMBNAILS,- captions: AbusePredefinedReasons.CAPTIONS-}diff --git a/shared/models/moderation/abuse/abuse-state.model.ts b/shared/models/moderation/abuse/abuse-state.model.tsindex b00cccad85..8ef6fdada5 100644--- a/shared/models/moderation/abuse/abuse-state.model.ts+++ b/shared/models/moderation/abuse/abuse-state.model.ts@@ -1,4 +1,4 @@-export enum AbuseState {+export const enum AbuseState {PENDING = 1,REJECTED = 2,ACCEPTED = 3diff --git a/shared/models/plugins/hook-type.enum.ts b/shared/models/plugins/hook-type.enum.tsindex 66d24071cd..a96c943f1a 100644--- a/shared/models/plugins/hook-type.enum.ts+++ b/shared/models/plugins/hook-type.enum.ts@@ -1,4 +1,4 @@-export enum HookType {+export const enum HookType {STATIC = 1,ACTION = 2,FILTER = 3diff --git a/shared/models/users/user-flag.model.ts b/shared/models/users/user-flag.model.tsindex b94262d5e4..b791a1263c 100644--- a/shared/models/users/user-flag.model.ts+++ b/shared/models/users/user-flag.model.ts@@ -1,4 +1,4 @@-export enum UserAdminFlag {+export const enum UserAdminFlag {NONE = 0,BYPASS_VIDEO_AUTO_BLACKLIST = 1 << 0}diff --git a/shared/models/users/user-notification-setting.model.ts b/shared/models/users/user-notification-setting.model.tsindex c7590fa8a4..473148062b 100644--- a/shared/models/users/user-notification-setting.model.ts+++ b/shared/models/users/user-notification-setting.model.ts@@ -1,4 +1,4 @@-export enum UserNotificationSettingValue {+export const enum UserNotificationSettingValue {NONE = 0,WEB = 1 << 0,EMAIL = 1 << 1diff --git a/shared/models/users/user-right.enum.ts b/shared/models/users/user-right.enum.tsindex 4a7ae43738..4c3d9e7c8b 100644--- a/shared/models/users/user-right.enum.ts+++ b/shared/models/users/user-right.enum.ts@@ -1,4 +1,4 @@-export enum UserRight {+export const enum UserRight {ALL,MANAGE_USERS,diff --git a/shared/models/users/user-role.ts b/shared/models/users/user-role.tsindex 772988c0c5..94413abca3 100644--- a/shared/models/users/user-role.ts+++ b/shared/models/users/user-role.ts@@ -1,42 +1,6 @@-import { UserRight } from './user-right.enum'-// Keep the orderexport enum UserRole {ADMINISTRATOR = 0,MODERATOR = 1,USER = 2}--export const USER_ROLE_LABELS: { [ id in UserRole ]: string } = {- [UserRole.USER]: 'User',- [UserRole.MODERATOR]: 'Moderator',- [UserRole.ADMINISTRATOR]: 'Administrator'-}--const userRoleRights: { [ id in UserRole ]: UserRight[] } = {- [UserRole.ADMINISTRATOR]: [- UserRight.ALL- ],-- [UserRole.MODERATOR]: [- UserRight.MANAGE_VIDEO_BLACKLIST,- UserRight.MANAGE_ABUSES,- UserRight.REMOVE_ANY_VIDEO,- UserRight.REMOVE_ANY_VIDEO_CHANNEL,- UserRight.REMOVE_ANY_VIDEO_PLAYLIST,- UserRight.REMOVE_ANY_VIDEO_COMMENT,- UserRight.UPDATE_ANY_VIDEO,- UserRight.SEE_ALL_VIDEOS,- UserRight.MANAGE_ACCOUNTS_BLOCKLIST,- UserRight.MANAGE_SERVERS_BLOCKLIST,- UserRight.MANAGE_USERS- ],-- [UserRole.USER]: []-}--export function hasUserRight (userRole: UserRole, userRight: UserRight) {- const userRights = userRoleRights[userRole]-- return userRights.includes(UserRight.ALL) || userRights.includes(userRight)-}diff --git a/shared/models/videos/blacklist/video-blacklist.model.ts b/shared/models/videos/blacklist/video-blacklist.model.tsindex a6e0ef175a..982a34592d 100644--- a/shared/models/videos/blacklist/video-blacklist.model.ts+++ b/shared/models/videos/blacklist/video-blacklist.model.ts@@ -1,6 +1,6 @@import { Video } from '../video.model'-export enum VideoBlacklistType {+export const enum VideoBlacklistType {MANUAL = 1,AUTO_BEFORE_PUBLISHED = 2}diff --git a/shared/models/videos/import/video-import-state.enum.ts b/shared/models/videos/import/video-import-state.enum.tsindex 8421b8ca72..33dd83f888 100644--- a/shared/models/videos/import/video-import-state.enum.ts+++ b/shared/models/videos/import/video-import-state.enum.ts@@ -1,4 +1,4 @@-export enum VideoImportState {+export const enum VideoImportState {PENDING = 1,SUCCESS = 2,FAILED = 3,diff --git a/shared/models/videos/playlist/video-playlist-element.model.ts b/shared/models/videos/playlist/video-playlist-element.model.tsindex 9a12038920..df9e3b5cf7 100644--- a/shared/models/videos/playlist/video-playlist-element.model.ts+++ b/shared/models/videos/playlist/video-playlist-element.model.ts@@ -1,6 +1,6 @@import { Video } from '../video.model'-export enum VideoPlaylistElementType {+export const enum VideoPlaylistElementType {REGULAR = 0,DELETED = 1,PRIVATE = 2,diff --git a/shared/models/videos/playlist/video-playlist-privacy.model.ts b/shared/models/videos/playlist/video-playlist-privacy.model.tsindex 96e5e22115..480e1f1049 100644--- a/shared/models/videos/playlist/video-playlist-privacy.model.ts+++ b/shared/models/videos/playlist/video-playlist-privacy.model.ts@@ -1,4 +1,4 @@-export enum VideoPlaylistPrivacy {+export const enum VideoPlaylistPrivacy {PUBLIC = 1,UNLISTED = 2,PRIVATE = 3diff --git a/shared/models/videos/playlist/video-playlist-type.model.ts b/shared/models/videos/playlist/video-playlist-type.model.tsindex 49233b7435..7f51a6354a 100644--- a/shared/models/videos/playlist/video-playlist-type.model.ts+++ b/shared/models/videos/playlist/video-playlist-type.model.ts@@ -1,4 +1,4 @@-export enum VideoPlaylistType {+export const enum VideoPlaylistType {REGULAR = 1,WATCH_LATER = 2}diff --git a/shared/models/videos/thumbnail.type.ts b/shared/models/videos/thumbnail.type.tsindex d6c2bef7b6..6907b28027 100644--- a/shared/models/videos/thumbnail.type.ts+++ b/shared/models/videos/thumbnail.type.ts@@ -1,4 +1,4 @@-export enum ThumbnailType {+export const enum ThumbnailType {MINIATURE = 1,PREVIEW = 2}diff --git a/shared/models/videos/video-change-ownership.model.ts b/shared/models/videos/video-change-ownership.model.tsindex a9b1a17f3c..669c7f3e74 100644--- a/shared/models/videos/video-change-ownership.model.ts+++ b/shared/models/videos/video-change-ownership.model.ts@@ -10,7 +10,7 @@ export interface VideoChangeOwnership {createdAt: Date}-export enum VideoChangeOwnershipStatus {+export const enum VideoChangeOwnershipStatus {WAITING = 'WAITING',ACCEPTED = 'ACCEPTED',REFUSED = 'REFUSED'diff --git a/shared/models/videos/video-privacy.enum.ts b/shared/models/videos/video-privacy.enum.tsindex 17ed0c9bb6..39fd0529fc 100644--- a/shared/models/videos/video-privacy.enum.ts+++ b/shared/models/videos/video-privacy.enum.ts@@ -1,4 +1,4 @@-export enum VideoPrivacy {+export const enum VideoPrivacy {PUBLIC = 1,UNLISTED = 2,PRIVATE = 3,diff --git a/shared/models/videos/video-resolution.enum.ts b/shared/models/videos/video-resolution.enum.tsindex 8b5a96cb67..571ab5d8f1 100644--- a/shared/models/videos/video-resolution.enum.ts+++ b/shared/models/videos/video-resolution.enum.ts@@ -1,6 +1,6 @@import { VideoTranscodingFPS } from './video-transcoding-fps.model'-export enum VideoResolution {+export const enum VideoResolution {H_NOVIDEO = 0,H_240P = 240,H_360P = 360,diff --git a/shared/models/videos/video-state.enum.ts b/shared/models/videos/video-state.enum.tsindex a50e14e4b7..31c501932f 100644--- a/shared/models/videos/video-state.enum.ts+++ b/shared/models/videos/video-state.enum.ts@@ -1,4 +1,4 @@-export enum VideoState {+export const enum VideoState {PUBLISHED = 1,TO_TRANSCODE = 2,TO_IMPORT = 3diff --git a/shared/models/videos/video-streaming-playlist.type.ts b/shared/models/videos/video-streaming-playlist.type.tsindex 3b403f295a..e2e2b93ea2 100644--- a/shared/models/videos/video-streaming-playlist.type.ts+++ b/shared/models/videos/video-streaming-playlist.type.ts@@ -1,3 +1,3 @@-export enum VideoStreamingPlaylistType {+export const enum VideoStreamingPlaylistType {HLS = 1}