diff options
author | Rigel Kent <sendmemail@rigelk.eu> | 2018-07-21 23:00:25 +0200 |
---|---|---|
committer | Chocobozzz <me@florianbigard.com> | 2018-07-24 14:08:44 +0200 |
commit | 3f6d68d9671ddb7ba1c4f3a35021b84856dafb6a (patch) | |
tree | 4a84a6a532fa042710c88edbaa5a5613173e00e3 /server/helpers/utils.ts | |
parent | 4278710d5b48546709720fac46657b84bba52a18 (diff) | |
download | PeerTube-3f6d68d9671ddb7ba1c4f3a35021b84856dafb6a.tar.gz PeerTube-3f6d68d9671ddb7ba1c4f3a35021b84856dafb6a.tar.zst PeerTube-3f6d68d9671ddb7ba1c4f3a35021b84856dafb6a.zip |
adding initial support for nodeinfo
Diffstat (limited to 'server/helpers/utils.ts')
-rw-r--r-- | server/helpers/utils.ts | 30 |
1 files changed, 30 insertions, 0 deletions
diff --git a/server/helpers/utils.ts b/server/helpers/utils.ts index 8fa861281..834d788c8 100644 --- a/server/helpers/utils.ts +++ b/server/helpers/utils.ts | |||
@@ -104,6 +104,36 @@ function computeResolutionsToTranscode (videoFileHeight: number) { | |||
104 | return resolutionsEnabled | 104 | return resolutionsEnabled |
105 | } | 105 | } |
106 | 106 | ||
107 | const timeTable = { | ||
108 | ms: 1, | ||
109 | second: 1000, | ||
110 | minute: 60000, | ||
111 | hour: 3600000, | ||
112 | day: 3600000 * 24, | ||
113 | week: 3600000 * 24 * 7, | ||
114 | month: 3600000 * 24 * 30 | ||
115 | } | ||
116 | export function parseDuration (duration: number | string, defaultDuration: number): number { | ||
117 | if (typeof duration === 'number') return duration | ||
118 | |||
119 | if (typeof duration === 'string') { | ||
120 | const split = duration.match(/^([\d\.,]+)\s?(\w+)$/) | ||
121 | |||
122 | if (split.length === 3) { | ||
123 | const len = parseFloat(split[1]) | ||
124 | let unit = split[2].replace(/s$/i,'').toLowerCase() | ||
125 | if (unit === 'm') { | ||
126 | unit = 'ms' | ||
127 | } | ||
128 | |||
129 | return (len || 1) * (timeTable[unit] || 0) | ||
130 | } | ||
131 | } | ||
132 | |||
133 | logger.error('Duration could not be properly parsed, defaulting to ' + defaultDuration) | ||
134 | return defaultDuration | ||
135 | } | ||
136 | |||
107 | function resetSequelizeInstance (instance: Model<any>, savedFields: object) { | 137 | function resetSequelizeInstance (instance: Model<any>, savedFields: object) { |
108 | Object.keys(savedFields).forEach(key => { | 138 | Object.keys(savedFields).forEach(key => { |
109 | const value = savedFields[key] | 139 | const value = savedFields[key] |