aboutsummaryrefslogtreecommitdiffhomepage
path: root/shared/core-utils
diff options
context:
space:
mode:
authorChocobozzz <me@florianbigard.com>2020-08-06 14:58:01 +0200
committerChocobozzz <chocobozzz@cpy.re>2020-08-07 08:28:14 +0200
commitbd45d503e5d007e730f4e81dccd7e7864c9a85cc (patch)
treeb78df768b8253ba401232c17da940cea016c9960 /shared/core-utils
parent583eb04b541175035d6d452ca626a96ebf2b7437 (diff)
downloadPeerTube-bd45d503e5d007e730f4e81dccd7e7864c9a85cc.tar.gz
PeerTube-bd45d503e5d007e730f4e81dccd7e7864c9a85cc.tar.zst
PeerTube-bd45d503e5d007e730f4e81dccd7e7864c9a85cc.zip
Reorganize shared models
Diffstat (limited to 'shared/core-utils')
-rw-r--r--shared/core-utils/abuse/abuse-predefined-reasons.ts14
-rw-r--r--shared/core-utils/abuse/index.ts1
-rw-r--r--shared/core-utils/i18n/i18n.ts105
-rw-r--r--shared/core-utils/i18n/index.ts1
-rw-r--r--shared/core-utils/users/index.ts1
-rw-r--r--shared/core-utils/users/user-role.ts35
6 files changed, 157 insertions, 0 deletions
diff --git a/shared/core-utils/abuse/abuse-predefined-reasons.ts b/shared/core-utils/abuse/abuse-predefined-reasons.ts
new file mode 100644
index 000000000..9967e54dd
--- /dev/null
+++ b/shared/core-utils/abuse/abuse-predefined-reasons.ts
@@ -0,0 +1,14 @@
1import { AbusePredefinedReasons, AbusePredefinedReasonsString } from '../../models/moderation/abuse/abuse-reason.model'
2
3export const abusePredefinedReasonsMap: {
4 [key in AbusePredefinedReasonsString]: AbusePredefinedReasons
5} = {
6 violentOrRepulsive: AbusePredefinedReasons.VIOLENT_OR_REPULSIVE,
7 hatefulOrAbusive: AbusePredefinedReasons.HATEFUL_OR_ABUSIVE,
8 spamOrMisleading: AbusePredefinedReasons.SPAM_OR_MISLEADING,
9 privacy: AbusePredefinedReasons.PRIVACY,
10 rights: AbusePredefinedReasons.RIGHTS,
11 serverRules: AbusePredefinedReasons.SERVER_RULES,
12 thumbnails: AbusePredefinedReasons.THUMBNAILS,
13 captions: AbusePredefinedReasons.CAPTIONS
14}
diff --git a/shared/core-utils/abuse/index.ts b/shared/core-utils/abuse/index.ts
new file mode 100644
index 000000000..244b83cff
--- /dev/null
+++ b/shared/core-utils/abuse/index.ts
@@ -0,0 +1 @@
export * from './abuse-predefined-reasons'
diff --git a/shared/core-utils/i18n/i18n.ts b/shared/core-utils/i18n/i18n.ts
new file mode 100644
index 000000000..9ad0f456d
--- /dev/null
+++ b/shared/core-utils/i18n/i18n.ts
@@ -0,0 +1,105 @@
1export const LOCALE_FILES = [ 'player', 'server' ]
2
3export const I18N_LOCALES = {
4 // Always first to avoid issues when using express acceptLanguages function when no accept language header is set
5 'en-US': 'English',
6
7 'ar': 'العربية',
8 'ca-ES': 'Català',
9 'cs-CZ': 'Čeština',
10 'de-DE': 'Deutsch',
11 'el-GR': 'ελληνικά',
12 'eo': 'Esperanto',
13 'es-ES': 'Español',
14 'eu-ES': 'Euskara',
15 'fi-FI': 'suomi',
16 'fr-FR': 'Français',
17 'gd': 'Gàidhlig',
18 'hu-HU': 'magyar',
19 'it-IT': 'Italiano',
20 'ja-JP': '日本語',
21 'kab': 'Taqbaylit',
22 'nl-NL': 'Nederlands',
23 'oc': 'Occitan',
24 'pl-PL': 'Polski',
25 'pt-BR': 'Português (Brasil)',
26 'pt-PT': 'Português (Portugal)',
27 'ru-RU': 'русский',
28 'sv-SE': 'svenska',
29 'th-TH': 'ไทย',
30 'vi-VN': 'Tiếng Việt',
31 'zh-Hans-CN': '简体中文(中国)',
32 'zh-Hant-TW': '繁體中文(台灣)'
33}
34
35const I18N_LOCALE_ALIAS = {
36 'ar-001': 'ar',
37 'ca': 'ca-ES',
38 'cs': 'cs-CZ',
39 'de': 'de-DE',
40 'el': 'el-GR',
41 'en': 'en-US',
42 'es': 'es-ES',
43 'eu': 'eu-ES',
44 'fi': 'fi-FI',
45 'fr': 'fr-FR',
46 'hu': 'hu-HU',
47 'it': 'it-IT',
48 'ja': 'ja-JP',
49 'nl': 'nl-NL',
50 'pl': 'pl-PL',
51 'pt': 'pt-BR',
52 'ru': 'ru-RU',
53 'sv': 'sv-SE',
54 'th': 'th-TH',
55 'vi': 'vi-VN',
56 'zh-CN': 'zh-Hans-CN',
57 'zh-Hans': 'zh-Hans-CN',
58 'zh-Hant': 'zh-Hant-TW',
59 'zh-TW': 'zh-Hant-TW',
60 'zh': 'zh-Hans-CN'
61}
62
63export const POSSIBLE_LOCALES = Object.keys(I18N_LOCALES)
64 .concat(Object.keys(I18N_LOCALE_ALIAS))
65
66export function getDefaultLocale () {
67 return 'en-US'
68}
69
70export function isDefaultLocale (locale: string) {
71 return getCompleteLocale(locale) === getCompleteLocale(getDefaultLocale())
72}
73
74export function peertubeTranslate (str: string, translations?: { [ id: string ]: string }) {
75 // FIXME: remove disable rule when the client is upgraded to typescript 3.7
76 // eslint-disable-next-line
77 return translations && translations[str] ? translations[str] : str
78}
79
80const possiblePaths = POSSIBLE_LOCALES.map(l => '/' + l)
81export function is18nPath (path: string) {
82 return possiblePaths.includes(path)
83}
84
85export function is18nLocale (locale: string) {
86 return POSSIBLE_LOCALES.includes(locale)
87}
88
89export function getCompleteLocale (locale: string) {
90 if (!locale) return locale
91
92 if (I18N_LOCALE_ALIAS[locale]) return I18N_LOCALE_ALIAS[locale]
93
94 return locale
95}
96
97export function getShortLocale (locale: string) {
98 if (locale.includes('-') === false) return locale
99
100 return locale.split('-')[0]
101}
102
103export function buildFileLocale (locale: string) {
104 return getCompleteLocale(locale)
105}
diff --git a/shared/core-utils/i18n/index.ts b/shared/core-utils/i18n/index.ts
new file mode 100644
index 000000000..8f7cbe2c7
--- /dev/null
+++ b/shared/core-utils/i18n/index.ts
@@ -0,0 +1 @@
export * from './i18n'
diff --git a/shared/core-utils/users/index.ts b/shared/core-utils/users/index.ts
new file mode 100644
index 000000000..1cbf0af1b
--- /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.ts
new file mode 100644
index 000000000..2b322faf3
--- /dev/null
+++ b/shared/core-utils/users/user-role.ts
@@ -0,0 +1,35 @@
1import { UserRight, UserRole } from '../../models/users'
2
3export const USER_ROLE_LABELS: { [ id in UserRole ]: string } = {
4 [UserRole.USER]: 'User',
5 [UserRole.MODERATOR]: 'Moderator',
6 [UserRole.ADMINISTRATOR]: 'Administrator'
7}
8
9const userRoleRights: { [ id in UserRole ]: UserRight[] } = {
10 [UserRole.ADMINISTRATOR]: [
11 UserRight.ALL
12 ],
13
14 [UserRole.MODERATOR]: [
15 UserRight.MANAGE_VIDEO_BLACKLIST,
16 UserRight.MANAGE_ABUSES,
17 UserRight.REMOVE_ANY_VIDEO,
18 UserRight.REMOVE_ANY_VIDEO_CHANNEL,
19 UserRight.REMOVE_ANY_VIDEO_PLAYLIST,
20 UserRight.REMOVE_ANY_VIDEO_COMMENT,
21 UserRight.UPDATE_ANY_VIDEO,
22 UserRight.SEE_ALL_VIDEOS,
23 UserRight.MANAGE_ACCOUNTS_BLOCKLIST,
24 UserRight.MANAGE_SERVERS_BLOCKLIST,
25 UserRight.MANAGE_USERS
26 ],
27
28 [UserRole.USER]: []
29}
30
31export function hasUserRight (userRole: UserRole, userRight: UserRight) {
32 const userRights = userRoleRights[userRole]
33
34 return userRights.includes(UserRight.ALL) || userRights.includes(userRight)
35}