diff options
Diffstat (limited to 'server/helpers')
-rw-r--r-- | server/helpers/audit-logger.ts | 12 | ||||
-rw-r--r-- | server/helpers/core-utils.ts | 37 | ||||
-rw-r--r-- | server/helpers/image-utils.ts | 27 | ||||
-rw-r--r-- | server/helpers/logger.ts | 2 | ||||
-rw-r--r-- | server/helpers/requests.ts | 19 | ||||
-rw-r--r-- | server/helpers/upload.ts | 9 |
6 files changed, 53 insertions, 53 deletions
diff --git a/server/helpers/audit-logger.ts b/server/helpers/audit-logger.ts index 79ef44be1..076b7f11d 100644 --- a/server/helpers/audit-logger.ts +++ b/server/helpers/audit-logger.ts | |||
@@ -120,7 +120,7 @@ const videoKeysToKeep = [ | |||
120 | 'downloadEnabled' | 120 | 'downloadEnabled' |
121 | ] | 121 | ] |
122 | class VideoAuditView extends EntityAuditView { | 122 | class VideoAuditView extends EntityAuditView { |
123 | constructor (private readonly video: VideoDetails) { | 123 | constructor (video: VideoDetails) { |
124 | super(videoKeysToKeep, 'video', video) | 124 | super(videoKeysToKeep, 'video', video) |
125 | } | 125 | } |
126 | } | 126 | } |
@@ -131,7 +131,7 @@ const videoImportKeysToKeep = [ | |||
131 | 'video-name' | 131 | 'video-name' |
132 | ] | 132 | ] |
133 | class VideoImportAuditView extends EntityAuditView { | 133 | class VideoImportAuditView extends EntityAuditView { |
134 | constructor (private readonly videoImport: VideoImport) { | 134 | constructor (videoImport: VideoImport) { |
135 | super(videoImportKeysToKeep, 'video-import', videoImport) | 135 | super(videoImportKeysToKeep, 'video-import', videoImport) |
136 | } | 136 | } |
137 | } | 137 | } |
@@ -150,7 +150,7 @@ const commentKeysToKeep = [ | |||
150 | 'account-name' | 150 | 'account-name' |
151 | ] | 151 | ] |
152 | class CommentAuditView extends EntityAuditView { | 152 | class CommentAuditView extends EntityAuditView { |
153 | constructor (private readonly comment: VideoComment) { | 153 | constructor (comment: VideoComment) { |
154 | super(commentKeysToKeep, 'comment', comment) | 154 | super(commentKeysToKeep, 'comment', comment) |
155 | } | 155 | } |
156 | } | 156 | } |
@@ -179,7 +179,7 @@ const userKeysToKeep = [ | |||
179 | 'videoChannels' | 179 | 'videoChannels' |
180 | ] | 180 | ] |
181 | class UserAuditView extends EntityAuditView { | 181 | class UserAuditView extends EntityAuditView { |
182 | constructor (private readonly user: User) { | 182 | constructor (user: User) { |
183 | super(userKeysToKeep, 'user', user) | 183 | super(userKeysToKeep, 'user', user) |
184 | } | 184 | } |
185 | } | 185 | } |
@@ -205,7 +205,7 @@ const channelKeysToKeep = [ | |||
205 | 'ownerAccount-displayedName' | 205 | 'ownerAccount-displayedName' |
206 | ] | 206 | ] |
207 | class VideoChannelAuditView extends EntityAuditView { | 207 | class VideoChannelAuditView extends EntityAuditView { |
208 | constructor (private readonly channel: VideoChannel) { | 208 | constructor (channel: VideoChannel) { |
209 | super(channelKeysToKeep, 'channel', channel) | 209 | super(channelKeysToKeep, 'channel', channel) |
210 | } | 210 | } |
211 | } | 211 | } |
@@ -217,7 +217,7 @@ const abuseKeysToKeep = [ | |||
217 | 'createdAt' | 217 | 'createdAt' |
218 | ] | 218 | ] |
219 | class AbuseAuditView extends EntityAuditView { | 219 | class AbuseAuditView extends EntityAuditView { |
220 | constructor (private readonly abuse: AdminAbuse) { | 220 | constructor (abuse: AdminAbuse) { |
221 | super(abuseKeysToKeep, 'abuse', abuse) | 221 | super(abuseKeysToKeep, 'abuse', abuse) |
222 | } | 222 | } |
223 | } | 223 | } |
diff --git a/server/helpers/core-utils.ts b/server/helpers/core-utils.ts index 0ec45eb2e..6ebe8e2ac 100644 --- a/server/helpers/core-utils.ts +++ b/server/helpers/core-utils.ts | |||
@@ -56,6 +56,7 @@ const timeTable = { | |||
56 | export function parseDurationToMs (duration: number | string): number { | 56 | export function parseDurationToMs (duration: number | string): number { |
57 | if (duration === null) return null | 57 | if (duration === null) return null |
58 | if (typeof duration === 'number') return duration | 58 | if (typeof duration === 'number') return duration |
59 | if (!isNaN(+duration)) return +duration | ||
59 | 60 | ||
60 | if (typeof duration === 'string') { | 61 | if (typeof duration === 'string') { |
61 | const split = duration.match(/^([\d.,]+)\s?(\w+)$/) | 62 | const split = duration.match(/^([\d.,]+)\s?(\w+)$/) |
@@ -76,6 +77,7 @@ export function parseDurationToMs (duration: number | string): number { | |||
76 | 77 | ||
77 | export function parseBytes (value: string | number): number { | 78 | export function parseBytes (value: string | number): number { |
78 | if (typeof value === 'number') return value | 79 | if (typeof value === 'number') return value |
80 | if (!isNaN(+value)) return +value | ||
79 | 81 | ||
80 | const tgm = /^(\d+)\s*TB\s*(\d+)\s*GB\s*(\d+)\s*MB$/ | 82 | const tgm = /^(\d+)\s*TB\s*(\d+)\s*GB\s*(\d+)\s*MB$/ |
81 | const tg = /^(\d+)\s*TB\s*(\d+)\s*GB$/ | 83 | const tg = /^(\d+)\s*TB\s*(\d+)\s*GB$/ |
@@ -85,40 +87,55 @@ export function parseBytes (value: string | number): number { | |||
85 | const g = /^(\d+)\s*GB$/ | 87 | const g = /^(\d+)\s*GB$/ |
86 | const m = /^(\d+)\s*MB$/ | 88 | const m = /^(\d+)\s*MB$/ |
87 | const b = /^(\d+)\s*B$/ | 89 | const b = /^(\d+)\s*B$/ |
88 | let match | 90 | |
91 | let match: RegExpMatchArray | ||
89 | 92 | ||
90 | if (value.match(tgm)) { | 93 | if (value.match(tgm)) { |
91 | match = value.match(tgm) | 94 | match = value.match(tgm) |
92 | return parseInt(match[1], 10) * 1024 * 1024 * 1024 * 1024 + | 95 | return parseInt(match[1], 10) * 1024 * 1024 * 1024 * 1024 + |
93 | parseInt(match[2], 10) * 1024 * 1024 * 1024 + | 96 | parseInt(match[2], 10) * 1024 * 1024 * 1024 + |
94 | parseInt(match[3], 10) * 1024 * 1024 | 97 | parseInt(match[3], 10) * 1024 * 1024 |
95 | } else if (value.match(tg)) { | 98 | } |
99 | |||
100 | if (value.match(tg)) { | ||
96 | match = value.match(tg) | 101 | match = value.match(tg) |
97 | return parseInt(match[1], 10) * 1024 * 1024 * 1024 * 1024 + | 102 | return parseInt(match[1], 10) * 1024 * 1024 * 1024 * 1024 + |
98 | parseInt(match[2], 10) * 1024 * 1024 * 1024 | 103 | parseInt(match[2], 10) * 1024 * 1024 * 1024 |
99 | } else if (value.match(tm)) { | 104 | } |
105 | |||
106 | if (value.match(tm)) { | ||
100 | match = value.match(tm) | 107 | match = value.match(tm) |
101 | return parseInt(match[1], 10) * 1024 * 1024 * 1024 * 1024 + | 108 | return parseInt(match[1], 10) * 1024 * 1024 * 1024 * 1024 + |
102 | parseInt(match[2], 10) * 1024 * 1024 | 109 | parseInt(match[2], 10) * 1024 * 1024 |
103 | } else if (value.match(gm)) { | 110 | } |
111 | |||
112 | if (value.match(gm)) { | ||
104 | match = value.match(gm) | 113 | match = value.match(gm) |
105 | return parseInt(match[1], 10) * 1024 * 1024 * 1024 + | 114 | return parseInt(match[1], 10) * 1024 * 1024 * 1024 + |
106 | parseInt(match[2], 10) * 1024 * 1024 | 115 | parseInt(match[2], 10) * 1024 * 1024 |
107 | } else if (value.match(t)) { | 116 | } |
117 | |||
118 | if (value.match(t)) { | ||
108 | match = value.match(t) | 119 | match = value.match(t) |
109 | return parseInt(match[1], 10) * 1024 * 1024 * 1024 * 1024 | 120 | return parseInt(match[1], 10) * 1024 * 1024 * 1024 * 1024 |
110 | } else if (value.match(g)) { | 121 | } |
122 | |||
123 | if (value.match(g)) { | ||
111 | match = value.match(g) | 124 | match = value.match(g) |
112 | return parseInt(match[1], 10) * 1024 * 1024 * 1024 | 125 | return parseInt(match[1], 10) * 1024 * 1024 * 1024 |
113 | } else if (value.match(m)) { | 126 | } |
127 | |||
128 | if (value.match(m)) { | ||
114 | match = value.match(m) | 129 | match = value.match(m) |
115 | return parseInt(match[1], 10) * 1024 * 1024 | 130 | return parseInt(match[1], 10) * 1024 * 1024 |
116 | } else if (value.match(b)) { | 131 | } |
132 | |||
133 | if (value.match(b)) { | ||
117 | match = value.match(b) | 134 | match = value.match(b) |
118 | return parseInt(match[1], 10) * 1024 | 135 | return parseInt(match[1], 10) * 1024 |
119 | } else { | ||
120 | return parseInt(value, 10) | ||
121 | } | 136 | } |
137 | |||
138 | return parseInt(value, 10) | ||
122 | } | 139 | } |
123 | 140 | ||
124 | // --------------------------------------------------------------------------- | 141 | // --------------------------------------------------------------------------- |
diff --git a/server/helpers/image-utils.ts b/server/helpers/image-utils.ts index 7d6451db9..bbd4692ef 100644 --- a/server/helpers/image-utils.ts +++ b/server/helpers/image-utils.ts | |||
@@ -12,12 +12,14 @@ function generateImageFilename (extension = '.jpg') { | |||
12 | return buildUUID() + extension | 12 | return buildUUID() + extension |
13 | } | 13 | } |
14 | 14 | ||
15 | async function processImage ( | 15 | async function processImage (options: { |
16 | path: string, | 16 | path: string |
17 | destination: string, | 17 | destination: string |
18 | newSize: { width: number, height: number }, | 18 | newSize: { width: number, height: number } |
19 | keepOriginal = false | 19 | keepOriginal?: boolean // default false |
20 | ) { | 20 | }) { |
21 | const { path, destination, newSize, keepOriginal = false } = options | ||
22 | |||
21 | const extension = getLowercaseExtension(path) | 23 | const extension = getLowercaseExtension(path) |
22 | 24 | ||
23 | if (path === destination) { | 25 | if (path === destination) { |
@@ -36,7 +38,14 @@ async function processImage ( | |||
36 | if (keepOriginal !== true) await remove(path) | 38 | if (keepOriginal !== true) await remove(path) |
37 | } | 39 | } |
38 | 40 | ||
39 | async function generateImageFromVideoFile (fromPath: string, folder: string, imageName: string, size: { width: number, height: number }) { | 41 | async function generateImageFromVideoFile (options: { |
42 | fromPath: string | ||
43 | folder: string | ||
44 | imageName: string | ||
45 | size: { width: number, height: number } | ||
46 | }) { | ||
47 | const { fromPath, folder, imageName, size } = options | ||
48 | |||
40 | const pendingImageName = 'pending-' + imageName | 49 | const pendingImageName = 'pending-' + imageName |
41 | const pendingImagePath = join(folder, pendingImageName) | 50 | const pendingImagePath = join(folder, pendingImageName) |
42 | 51 | ||
@@ -44,7 +53,7 @@ async function generateImageFromVideoFile (fromPath: string, folder: string, ima | |||
44 | await generateThumbnailFromVideo(fromPath, folder, imageName) | 53 | await generateThumbnailFromVideo(fromPath, folder, imageName) |
45 | 54 | ||
46 | const destination = join(folder, imageName) | 55 | const destination = join(folder, imageName) |
47 | await processImage(pendingImagePath, destination, size) | 56 | await processImage({ path: pendingImagePath, destination, newSize: size }) |
48 | } catch (err) { | 57 | } catch (err) { |
49 | logger.error('Cannot generate image from video %s.', fromPath, { err, ...lTags() }) | 58 | logger.error('Cannot generate image from video %s.', fromPath, { err, ...lTags() }) |
50 | 59 | ||
@@ -114,7 +123,7 @@ async function autoResize (options: { | |||
114 | }) { | 123 | }) { |
115 | const { sourceImage, newSize, destination } = options | 124 | const { sourceImage, newSize, destination } = options |
116 | 125 | ||
117 | // Portrait mode targetting a landscape, apply some effect on the image | 126 | // Portrait mode targeting a landscape, apply some effect on the image |
118 | const sourceIsPortrait = sourceImage.getWidth() < sourceImage.getHeight() | 127 | const sourceIsPortrait = sourceImage.getWidth() < sourceImage.getHeight() |
119 | const destIsPortraitOrSquare = newSize.width <= newSize.height | 128 | const destIsPortraitOrSquare = newSize.width <= newSize.height |
120 | 129 | ||
diff --git a/server/helpers/logger.ts b/server/helpers/logger.ts index 5fe3646c5..4fbaf8a73 100644 --- a/server/helpers/logger.ts +++ b/server/helpers/logger.ts | |||
@@ -57,7 +57,7 @@ const consoleLoggerFormat = format.printf(info => { | |||
57 | if (CONFIG.LOG.PRETTIFY_SQL) { | 57 | if (CONFIG.LOG.PRETTIFY_SQL) { |
58 | additionalInfos += '\n' + sqlFormat(info.sql, { | 58 | additionalInfos += '\n' + sqlFormat(info.sql, { |
59 | language: 'sql', | 59 | language: 'sql', |
60 | indent: ' ' | 60 | tabWidth: 2 |
61 | }) | 61 | }) |
62 | } else { | 62 | } else { |
63 | additionalInfos += ' - ' + info.sql | 63 | additionalInfos += ' - ' + info.sql |
diff --git a/server/helpers/requests.ts b/server/helpers/requests.ts index a9869e987..495e83558 100644 --- a/server/helpers/requests.ts +++ b/server/helpers/requests.ts | |||
@@ -1,11 +1,8 @@ | |||
1 | import { createWriteStream, remove } from 'fs-extra' | 1 | import { createWriteStream, remove } from 'fs-extra' |
2 | import got, { CancelableRequest, NormalizedOptions, Options as GotOptions, RequestError, Response } from 'got' | 2 | import got, { CancelableRequest, NormalizedOptions, Options as GotOptions, RequestError, Response } from 'got' |
3 | import { HttpProxyAgent, HttpsProxyAgent } from 'hpagent' | 3 | import { HttpProxyAgent, HttpsProxyAgent } from 'hpagent' |
4 | import { join } from 'path' | ||
5 | import { CONFIG } from '../initializers/config' | ||
6 | import { ACTIVITY_PUB, BINARY_CONTENT_TYPES, PEERTUBE_VERSION, REQUEST_TIMEOUTS, WEBSERVER } from '../initializers/constants' | 4 | import { ACTIVITY_PUB, BINARY_CONTENT_TYPES, PEERTUBE_VERSION, REQUEST_TIMEOUTS, WEBSERVER } from '../initializers/constants' |
7 | import { pipelinePromise } from './core-utils' | 5 | import { pipelinePromise } from './core-utils' |
8 | import { processImage } from './image-utils' | ||
9 | import { logger, loggerTagsFactory } from './logger' | 6 | import { logger, loggerTagsFactory } from './logger' |
10 | import { getProxy, isProxyEnabled } from './proxy' | 7 | import { getProxy, isProxyEnabled } from './proxy' |
11 | 8 | ||
@@ -147,21 +144,6 @@ async function doRequestAndSaveToFile ( | |||
147 | } | 144 | } |
148 | } | 145 | } |
149 | 146 | ||
150 | async function downloadImage (url: string, destDir: string, destName: string, size: { width: number, height: number }) { | ||
151 | const tmpPath = join(CONFIG.STORAGE.TMP_DIR, 'pending-' + destName) | ||
152 | await doRequestAndSaveToFile(url, tmpPath) | ||
153 | |||
154 | const destPath = join(destDir, destName) | ||
155 | |||
156 | try { | ||
157 | await processImage(tmpPath, destPath, size) | ||
158 | } catch (err) { | ||
159 | await remove(tmpPath) | ||
160 | |||
161 | throw err | ||
162 | } | ||
163 | } | ||
164 | |||
165 | function getAgent () { | 147 | function getAgent () { |
166 | if (!isProxyEnabled()) return {} | 148 | if (!isProxyEnabled()) return {} |
167 | 149 | ||
@@ -211,7 +193,6 @@ export { | |||
211 | doJSONRequest, | 193 | doJSONRequest, |
212 | doRequestAndSaveToFile, | 194 | doRequestAndSaveToFile, |
213 | isBinaryResponse, | 195 | isBinaryResponse, |
214 | downloadImage, | ||
215 | getAgent, | 196 | getAgent, |
216 | findLatestRedirection, | 197 | findLatestRedirection, |
217 | peertubeGot | 198 | peertubeGot |
diff --git a/server/helpers/upload.ts b/server/helpers/upload.ts index c94c7ab82..3cb17edd0 100644 --- a/server/helpers/upload.ts +++ b/server/helpers/upload.ts | |||
@@ -1,5 +1,4 @@ | |||
1 | import { join } from 'path' | 1 | import { join } from 'path' |
2 | import { JobQueue } from '@server/lib/job-queue' | ||
3 | import { RESUMABLE_UPLOAD_DIRECTORY } from '../initializers/constants' | 2 | import { RESUMABLE_UPLOAD_DIRECTORY } from '../initializers/constants' |
4 | 3 | ||
5 | function getResumableUploadPath (filename?: string) { | 4 | function getResumableUploadPath (filename?: string) { |
@@ -8,14 +7,8 @@ function getResumableUploadPath (filename?: string) { | |||
8 | return RESUMABLE_UPLOAD_DIRECTORY | 7 | return RESUMABLE_UPLOAD_DIRECTORY |
9 | } | 8 | } |
10 | 9 | ||
11 | function scheduleDeleteResumableUploadMetaFile (filepath: string) { | ||
12 | const payload = { filepath } | ||
13 | JobQueue.Instance.createJob({ type: 'delete-resumable-upload-meta-file', payload }, { delay: 900 * 1000 }) // executed in 15 min | ||
14 | } | ||
15 | |||
16 | // --------------------------------------------------------------------------- | 10 | // --------------------------------------------------------------------------- |
17 | 11 | ||
18 | export { | 12 | export { |
19 | getResumableUploadPath, | 13 | getResumableUploadPath |
20 | scheduleDeleteResumableUploadMetaFile | ||
21 | } | 14 | } |