X-Git-Url: https://git.immae.eu/?a=blobdiff_plain;f=server%2Ftools%2Fpeertube-import-videos.ts;h=c7e85b570bc677257a9b8279406152d3b675b5dd;hb=837666fe48f9ed786db75c96e2025cbcf20a1e3b;hp=fcb90cca3f30af56493c1cc211d47eca62d23b7a;hpb=282e61e6c11f79e919c543871783fe1a00298d18;p=github%2FChocobozzz%2FPeerTube.git diff --git a/server/tools/peertube-import-videos.ts b/server/tools/peertube-import-videos.ts index fcb90cca3..c7e85b570 100644 --- a/server/tools/peertube-import-videos.ts +++ b/server/tools/peertube-import-videos.ts @@ -1,5 +1,5 @@ -// FIXME: https://github.com/nodejs/node/pull/16853 -require('tls').DEFAULT_ECDH_CURVE = 'auto' +import { registerTSPaths } from '../helpers/register-ts-paths' +registerTSPaths() import * as program from 'commander' import { join } from 'path' @@ -54,8 +54,8 @@ getServerCredentials(command) exitError('--tmpdir %s: directory does not exist or is not accessible', program[ 'tmpdir' ]) } - removeEndSlashes(url) - removeEndSlashes(program[ 'targetUrl' ]) + url = normalizeTargetUrl(url) + program[ 'targetUrl' ] = normalizeTargetUrl(program[ 'targetUrl' ]) const user = { username, password } @@ -81,11 +81,11 @@ async function run (url: string, user: UserInfo) { let infoArray: any[] // Normalize utf8 fields - infoArray = [].concat(info); + infoArray = [].concat(info) if (program[ 'first' ]) { infoArray = infoArray.slice(0, program[ 'first' ]) } else if (program[ 'last' ]) { - infoArray = infoArray.slice(- program[ 'last' ]) + infoArray = infoArray.slice(-program[ 'last' ]) } infoArray = infoArray.map(i => normalizeObject(i)) @@ -122,15 +122,15 @@ function processVideo (parameters: { if (program[ 'since' ]) { if (buildOriginallyPublishedAt(videoInfo).getTime() < program[ 'since' ].getTime()) { log.info('Video "%s" has been published before "%s", don\'t upload it.\n', - videoInfo.title, formatDate(program[ 'since' ])); - return res(); + videoInfo.title, formatDate(program[ 'since' ])) + return res() } } if (program[ 'until' ]) { if (buildOriginallyPublishedAt(videoInfo).getTime() > program[ 'until' ].getTime()) { log.info('Video "%s" has been published after "%s", don\'t upload it.\n', - videoInfo.title, formatDate(program[ 'until' ])); - return res(); + videoInfo.title, formatDate(program[ 'until' ])) + return res() } } @@ -326,10 +326,14 @@ function isNSFW (info: any) { return info.age_limit && info.age_limit >= 16 } -function removeEndSlashes (url: string) { - while (url.endsWith('/')) { - url.slice(0, -1) +function normalizeTargetUrl (url: string) { + let normalizedUrl = url.replace(/\/+$/, '') + + if (!normalizedUrl.startsWith('http://') && !normalizedUrl.startsWith('https://')) { + normalizedUrl = 'https://' + normalizedUrl } + + return normalizedUrl } async function promptPassword () { @@ -369,20 +373,21 @@ async function getAccessTokenOrDie (url: string, user: UserInfo) { function parseDate (dateAsStr: string): Date { if (!/\d{4}-\d{2}-\d{2}/.test(dateAsStr)) { - exitError(`Invalid date passed: ${dateAsStr}. Expected format: YYYY-MM-DD. See help for usage.`); + exitError(`Invalid date passed: ${dateAsStr}. Expected format: YYYY-MM-DD. See help for usage.`) } - const date = new Date(dateAsStr); + const date = new Date(dateAsStr) + date.setHours(0, 0, 0) if (isNaN(date.getTime())) { - exitError(`Invalid date passed: ${dateAsStr}. See help for usage.`); + exitError(`Invalid date passed: ${dateAsStr}. See help for usage.`) } - return date; + return date } function formatDate (date: Date): string { - return date.toISOString().split('T')[0]; + return date.toISOString().split('T')[ 0 ] } -function exitError (message:string, ...meta: any[]) { +function exitError (message: string, ...meta: any[]) { // use console.error instead of log.error here console.error(message, ...meta) process.exit(-1)