Verified Commit a1587156 authored by Chocobozzz's avatar Chocobozzz
Browse files

Move to eslint

parent a22046d1
Pipeline #400823 passed with stage
in 55 minutes and 41 seconds
{
"extends": "standard-with-typescript",
"rules": {
"eol-last": [
"error",
"always"
],
"indent": "off",
"no-lone-blocks": "off",
"no-mixed-operators": "off",
"max-len": [
"error",
{
"code": 140
}
],
"array-bracket-spacing": [
"error",
"always"
],
"quote-props": [
"error",
"consistent-as-needed"
],
"padded-blocks": "off",
"no-async-promise-executor": "off",
"dot-notation": "off",
"promise/param-names": "off",
"import/first": "off",
"operator-linebreak": [
"error",
"after",
{
"overrides": {
"?": "before",
":": "before"
}
}
],
"@typescript-eslint/indent": [
"error",
2,
{
"SwitchCase": 1,
"MemberExpression": "off"
}
],
"@typescript-eslint/consistent-type-assertions": [
"error",
{
"assertionStyle": "as"
}
],
"@typescript-eslint/array-type": [
"error",
{
"default": "array"
}
],
"@typescript-eslint/restrict-template-expressions": [
"off",
{
"allowNumber": "true"
}
],
"@typescript-eslint/quotes": "off",
"@typescript-eslint/no-var-requires": "off",
"@typescript-eslint/explicit-function-return-type": "off",
"@typescript-eslint/promise-function-async": "off",
"@typescript-eslint/no-dynamic-delete": "off",
"@typescript-eslint/strict-boolean-expressions": "off",
"@typescript-eslint/consistent-type-definitions": "off",
"@typescript-eslint/no-misused-promises": "off",
"@typescript-eslint/no-namespace": "off",
"@typescript-eslint/no-extraneous-class": "off",
// bugged but useful
"@typescript-eslint/restrict-plus-operands": "off"
},
"ignorePatterns": [
"node_modules/"
],
"parserOptions": {
"project": [
"./tsconfig.json",
"./server/tools/tsconfig.json"
]
}
}
......@@ -63,7 +63,7 @@
"ng": "ng",
"nodemon": "nodemon",
"ts-node": "ts-node",
"tslint": "tslint",
"eslint": "eslint",
"concurrently": "concurrently",
"mocha-parallel-tests": "mocha-parallel-tests",
"sasslint": "sass-lint --verbose --no-exit",
......@@ -96,7 +96,7 @@
"express": "^4.12.4",
"express-oauth-server": "^2.0.0",
"express-rate-limit": "^4.0.4",
"express-validator": "^6.1.1",
"express-validator": "^6.4.0",
"flat": "^5.0.0",
"fluent-ffmpeg": "^2.1.0",
"fs-extra": "^8.0.1",
......@@ -139,7 +139,7 @@
"webtorrent": "^0.107.16",
"winston": "3.2.1",
"ws": "^7.0.0",
"youtube-dl": "^3.0.1"
"youtube-dl": "^3.0.2"
},
"devDependencies": {
"@types/apicache": "^1.2.0",
......@@ -180,10 +180,17 @@
"@types/validator": "^12.0.1",
"@types/webtorrent": "^0.107.0",
"@types/ws": "^7.2.1",
"@typescript-eslint/eslint-plugin": "^2.18.0",
"chai": "^4.1.1",
"chai-json-schema": "^1.5.0",
"chai-xml": "^0.3.2",
"concurrently": "^5.0.0",
"eslint": "^6.8.0",
"eslint-config-standard-with-typescript": "^12.0.1",
"eslint-plugin-import": "^2.20.1",
"eslint-plugin-node": "^11.0.0",
"eslint-plugin-promise": "^4.2.1",
"eslint-plugin-standard": "^4.0.1",
"libxmljs": "0.19.7",
"maildev": "^1.0.0-rc3",
"marked": "^0.8.0",
......@@ -195,8 +202,6 @@
"supertest": "^4.0.2",
"swagger-cli": "^3.0.1",
"ts-node": "8.6.2",
"tslint": "^6.0.0",
"tslint-config-standard": "^9.0.0",
"typescript": "^3.7.2"
},
"scripty": {
......
......@@ -35,7 +35,7 @@ elif [ "$1" = "api-4" ]; then
npm run build:server
sh ./server/tests/api/ci-4.sh 2
elif [ "$1" = "lint" ]; then
npm run tslint -- --project ./tsconfig.json -c ./tslint.json server.ts "server/**/*.ts" "shared/**/*.ts"
npm run eslint -- --ext .ts "server/**/*.ts" "shared/**/*.ts"
npm run swagger-cli -- validate support/doc/api/openapi.yaml
( cd client
......
......@@ -38,6 +38,6 @@ async function run () {
}
await JobQueue.Instance.init()
await JobQueue.Instance.createJob({ type: 'video-file-import', payload: dataInput })
await JobQueue.Instance.createJobWithPromise({ type: 'video-file-import', payload: dataInput })
console.log('Import job for video %s created.', video.uuid)
}
......@@ -72,7 +72,7 @@ async function run () {
await JobQueue.Instance.init()
for (const d of dataInput) {
await JobQueue.Instance.createJob({ type: 'video-transcoding', payload: d })
await JobQueue.Instance.createJobWithPromise({ type: 'video-transcoding', payload: d })
console.log('Transcoding job for video %s created.', video.uuid)
}
}
......@@ -122,7 +122,7 @@ activityPubClientRouter.get('/videos/watch/:videoId/comments/:commentId/activity
activityPubClientRouter.get('/video-channels/:name',
executeIfActivityPub,
asyncMiddleware(localVideoChannelValidator),
asyncMiddleware(videoChannelController)
videoChannelController
)
activityPubClientRouter.get('/video-channels/:name/followers',
executeIfActivityPub,
......@@ -154,7 +154,7 @@ activityPubClientRouter.get('/video-playlists/:playlistId',
activityPubClientRouter.get('/video-playlists/:playlistId/:videoId',
executeIfActivityPub,
asyncMiddleware(videoPlaylistElementAPGetValidator),
asyncMiddleware(videoPlaylistElementController)
videoPlaylistElementController
)
// ---------------------------------------------------------------------------
......@@ -281,7 +281,7 @@ async function videoCommentsController (req: express.Request, res: express.Respo
return activityPubResponse(activityPubContextify(json), res)
}
async function videoChannelController (req: express.Request, res: express.Response) {
function videoChannelController (req: express.Request, res: express.Response) {
const videoChannel = res.locals.videoChannel
return activityPubResponse(activityPubContextify(videoChannel.toActivityPubObject()), res)
......@@ -353,7 +353,7 @@ async function videoPlaylistController (req: express.Request, res: express.Respo
return activityPubResponse(activityPubContextify(object), res)
}
async function videoPlaylistElementController (req: express.Request, res: express.Response) {
function videoPlaylistElementController (req: express.Request, res: express.Response) {
const videoPlaylistElement = res.locals.videoPlaylistElementAP
const json = videoPlaylistElement.toActivityPubObject()
......
......@@ -46,6 +46,10 @@ const inboxQueue = queue<QueueParam, Error>((task, cb) => {
processActivities(task.activities, options)
.then(() => cb())
.catch(err => {
logger.error('Error in process activities.', { err })
cb()
})
})
function inboxController (req: express.Request, res: express.Response) {
......
......@@ -16,21 +16,17 @@ import {
accountNameWithHostGetValidator,
accountsSortValidator,
ensureAuthUserOwnsAccountValidator,
videosSortValidator,
videoChannelsSortValidator
videoChannelsSortValidator,
videosSortValidator
} from '../../middlewares/validators'
import { AccountModel } from '../../models/account/account'
import { AccountVideoRateModel } from '../../models/account/account-video-rate'
import { VideoModel } from '../../models/video/video'
import { buildNSFWFilter, isUserAbleToSearchRemoteURI, getCountVideos } from '../../helpers/express-utils'
import { buildNSFWFilter, getCountVideos, isUserAbleToSearchRemoteURI } from '../../helpers/express-utils'
import { VideoChannelModel } from '../../models/video/video-channel'
import { JobQueue } from '../../lib/job-queue'
import { logger } from '../../helpers/logger'
import { VideoPlaylistModel } from '../../models/video/video-playlist'
import {
commonVideoPlaylistFiltersValidator,
videoPlaylistsSearchValidator
} from '../../middlewares/validators/videos/video-playlists'
import { commonVideoPlaylistFiltersValidator, videoPlaylistsSearchValidator } from '../../middlewares/validators/videos/video-playlists'
const accountsRouter = express.Router()
......@@ -104,7 +100,6 @@ function getAccount (req: express.Request, res: express.Response) {
if (account.isOutdated()) {
JobQueue.Instance.createJob({ type: 'activitypub-refresher', payload: { type: 'actor', url: account.Actor.url } })
.catch(err => logger.error('Cannot create AP refresher job for actor %s.', account.Actor.url, { err }))
}
return res.json(account.toFormattedJSON())
......
......@@ -31,12 +31,12 @@ configRouter.get('/',
configRouter.get('/custom',
authenticate,
ensureUserHasRight(UserRight.MANAGE_CONFIGURATION),
asyncMiddleware(getCustomConfig)
getCustomConfig
)
configRouter.put('/custom',
authenticate,
ensureUserHasRight(UserRight.MANAGE_CONFIGURATION),
asyncMiddleware(customConfigUpdateValidator),
customConfigUpdateValidator,
asyncMiddleware(updateCustomConfig)
)
configRouter.delete('/custom',
......@@ -196,7 +196,7 @@ function getAbout (req: express.Request, res: express.Response) {
return res.json(about).end()
}
async function getCustomConfig (req: express.Request, res: express.Response) {
function getCustomConfig (req: express.Request, res: express.Response) {
const data = customConfig()
return res.json(data).end()
......@@ -250,7 +250,7 @@ function getRegisteredThemes () {
function getEnabledResolutions () {
return Object.keys(CONFIG.TRANSCODING.RESOLUTIONS)
.filter(key => CONFIG.TRANSCODING.ENABLED && CONFIG.TRANSCODING.RESOLUTIONS[ key ] === true)
.filter(key => CONFIG.TRANSCODING.ENABLED && CONFIG.TRANSCODING.RESOLUTIONS[key] === true)
.map(r => parseInt(r, 10))
}
......@@ -340,13 +340,13 @@ function customConfig (): CustomConfig {
allowAudioFiles: CONFIG.TRANSCODING.ALLOW_AUDIO_FILES,
threads: CONFIG.TRANSCODING.THREADS,
resolutions: {
'0p': CONFIG.TRANSCODING.RESOLUTIONS[ '0p' ],
'240p': CONFIG.TRANSCODING.RESOLUTIONS[ '240p' ],
'360p': CONFIG.TRANSCODING.RESOLUTIONS[ '360p' ],
'480p': CONFIG.TRANSCODING.RESOLUTIONS[ '480p' ],
'720p': CONFIG.TRANSCODING.RESOLUTIONS[ '720p' ],
'1080p': CONFIG.TRANSCODING.RESOLUTIONS[ '1080p' ],
'2160p': CONFIG.TRANSCODING.RESOLUTIONS[ '2160p' ]
'0p': CONFIG.TRANSCODING.RESOLUTIONS['0p'],
'240p': CONFIG.TRANSCODING.RESOLUTIONS['240p'],
'360p': CONFIG.TRANSCODING.RESOLUTIONS['360p'],
'480p': CONFIG.TRANSCODING.RESOLUTIONS['480p'],
'720p': CONFIG.TRANSCODING.RESOLUTIONS['720p'],
'1080p': CONFIG.TRANSCODING.RESOLUTIONS['1080p'],
'2160p': CONFIG.TRANSCODING.RESOLUTIONS['2160p']
},
webtorrent: {
enabled: CONFIG.TRANSCODING.WEBTORRENT.ENABLED
......
......@@ -50,7 +50,7 @@ async function listJobs (req: express.Request, res: express.Response) {
})
const total = await JobQueue.Instance.count(state)
const result: ResultList<any> = {
const result: ResultList<Job> = {
total,
data: jobs.map(j => formatJob(j, state))
}
......
......@@ -24,7 +24,7 @@ export { overviewsRouter }
const buildSamples = memoizee(async function () {
const [ categories, channels, tags ] = await Promise.all([
VideoModel.getRandomFieldSamples('category', OVERVIEWS.VIDEOS.SAMPLE_THRESHOLD, OVERVIEWS.VIDEOS.SAMPLES_COUNT),
VideoModel.getRandomFieldSamples('channelId', OVERVIEWS.VIDEOS.SAMPLE_THRESHOLD ,OVERVIEWS.VIDEOS.SAMPLES_COUNT),
VideoModel.getRandomFieldSamples('channelId', OVERVIEWS.VIDEOS.SAMPLE_THRESHOLD, OVERVIEWS.VIDEOS.SAMPLES_COUNT),
TagModel.getRandomSamples(OVERVIEWS.VIDEOS.SAMPLE_THRESHOLD, OVERVIEWS.VIDEOS.SAMPLES_COUNT)
])
......
import * as express from 'express'
import { UserRight } from '../../../../shared/models/users'
import { asyncMiddleware, authenticate, ensureUserHasRight } from '../../../middlewares'
import { authenticate, ensureUserHasRight } from '../../../middlewares'
const debugRouter = express.Router()
debugRouter.get('/debug',
authenticate,
ensureUserHasRight(UserRight.MANAGE_DEBUG),
asyncMiddleware(getDebug)
getDebug
)
// ---------------------------------------------------------------------------
......@@ -18,7 +18,7 @@ export {
// ---------------------------------------------------------------------------
async function getDebug (req: express.Request, res: express.Response) {
function getDebug (req: express.Request, res: express.Response) {
return res.json({
ip: req.ip
}).end()
......
......@@ -135,7 +135,6 @@ async function followInstance (req: express.Request, res: express.Response) {
}
JobQueue.Instance.createJob({ type: 'activitypub-follow', payload })
.catch(err => logger.error('Cannot create follow job for %s.', host, err))
}
return res.status(204).end()
......
......@@ -59,9 +59,9 @@ async function getLogs (req: express.Request, res: express.Response) {
}
async function generateOutput (options: {
startDateQuery: string,
endDateQuery?: string,
level: LogLevel,
startDateQuery: string
endDateQuery?: string
level: LogLevel
nameFilter: RegExp
}) {
const { startDateQuery, level, nameFilter } = options
......@@ -111,7 +111,7 @@ async function getOutputFromFile (path: string, startDate: Date, endDate: Date,
const output: any[] = []
for (let i = lines.length - 1; i >= 0; i--) {
const line = lines[ i ]
const line = lines[i]
let log: any
try {
......@@ -122,7 +122,7 @@ async function getOutputFromFile (path: string, startDate: Date, endDate: Date,
}
logTime = new Date(log.timestamp).getTime()
if (logTime >= startTime && logTime <= endTime && logsLevel[ log.level ] >= logsLevel[ level ]) {
if (logTime >= startTime && logTime <= endTime && logsLevel[log.level] >= logsLevel[level]) {
output.push(log)
currentSize += line.length
......
......@@ -84,7 +84,7 @@ async function addVideoRedundancy (req: express.Request, res: express.Response)
videoId: res.locals.onlyVideo.id
}
await JobQueue.Instance.createJob({
await JobQueue.Instance.createJobWithPromise({
type: 'video-redundancy',
payload
})
......
......@@ -39,7 +39,7 @@ meRouter.get('/me',
)
meRouter.delete('/me',
authenticate,
asyncMiddleware(deleteMeValidator),
deleteMeValidator,
asyncMiddleware(deleteMe)
)
......@@ -214,7 +214,7 @@ async function updateMe (req: express.Request, res: express.Response) {
}
async function updateMyAvatar (req: express.Request, res: express.Response) {
const avatarPhysicalFile = req.files[ 'avatarfile' ][ 0 ]
const avatarPhysicalFile = req.files['avatarfile'][0]
const user = res.locals.oauth.token.user
const userAccount = await AccountModel.load(user.Account.id)
......
......@@ -19,7 +19,6 @@ import { buildNSFWFilter, getCountVideos } from '../../../helpers/express-utils'
import { VideoFilter } from '../../../../shared/models/videos/video-query.type'
import { ActorFollowModel } from '../../../models/activitypub/actor-follow'
import { JobQueue } from '../../../lib/job-queue'
import { logger } from '../../../helpers/logger'
import { sequelizeTypescript } from '../../../initializers/database'
const mySubscriptionsRouter = express.Router()
......@@ -52,7 +51,7 @@ mySubscriptionsRouter.get('/me/subscriptions',
mySubscriptionsRouter.post('/me/subscriptions',
authenticate,
userSubscriptionAddValidator,
asyncMiddleware(addUserSubscription)
addUserSubscription
)
mySubscriptionsRouter.get('/me/subscriptions/:uri',
......@@ -106,7 +105,7 @@ async function areSubscriptionsExist (req: express.Request, res: express.Respons
return res.json(existObject)
}
async function addUserSubscription (req: express.Request, res: express.Response) {
function addUserSubscription (req: express.Request, res: express.Response) {
const user = res.locals.oauth.token.User
const [ name, host ] = req.body.uri.split('@')
......@@ -117,7 +116,6 @@ async function addUserSubscription (req: express.Request, res: express.Response)
}
JobQueue.Instance.createJob({ type: 'activitypub-follow', payload })
.catch(err => logger.error('Cannot create follow job for subscription %s.', req.body.uri, err))
return res.status(204).end()
}
......
......@@ -119,7 +119,7 @@ async function listVideoChannels (req: express.Request, res: express.Response) {
}
async function updateVideoChannelAvatar (req: express.Request, res: express.Response) {
const avatarPhysicalFile = req.files[ 'avatarfile' ][ 0 ]
const avatarPhysicalFile = req.files['avatarfile'][0]
const videoChannel = res.locals.videoChannel
const oldVideoChannelAuditKeys = new VideoChannelAuditView(videoChannel.toFormattedJSON())
......@@ -232,7 +232,6 @@ async function getVideoChannel (req: express.Request, res: express.Response) {
if (videoChannelWithVideos.isOutdated()) {
JobQueue.Instance.createJob({ type: 'activitypub-refresher', payload: { type: 'actor', url: videoChannelWithVideos.Actor.url } })
.catch(err => logger.error('Cannot create AP refresher job for actor %s.', videoChannelWithVideos.Actor.url, { err }))
}
return res.json(videoChannelWithVideos.toFormattedJSON())
......
......@@ -144,7 +144,6 @@ function getVideoPlaylist (req: express.Request, res: express.Response) {
if (videoPlaylist.isOutdated()) {
JobQueue.Instance.createJob({ type: 'activitypub-refresher', payload: { type: 'video-playlist', url: videoPlaylist.url } })
.catch(err => logger.error('Cannot create AP refresher job for playlist %s.', videoPlaylist.url, { err }))
}
return res.json(videoPlaylist.toFormattedJSON())
......
......@@ -88,12 +88,12 @@ async function addTorrentImport (req: express.Request, res: express.Response, to
const buf = await readFile(torrentfile.path)
const parsedTorrent = parseTorrent(buf)
videoName = isArray(parsedTorrent.name) ? parsedTorrent.name[ 0 ] : parsedTorrent.name as string
videoName = isArray(parsedTorrent.name) ? parsedTorrent.name[0] : parsedTorrent.name as string
} else {
magnetUri = body.magnetUri
const parsed = magnetUtil.decode(magnetUri)
videoName = isArray(parsed.name) ? parsed.name[ 0 ] : parsed.name as string
videoName = isArray(parsed.name) ? parsed.name[0] : parsed.name as string
}
const video = buildVideo(res.locals.videoChannel.id, body, { name: videoName })
......@@ -124,7 +124,7 @@ async function addTorrentImport (req: express.Request, res: express.Response, to
videoImportId: videoImport.id,
magnetUri
}
await JobQueue.Instance.createJob({ type: 'video-import', payload })
await JobQueue.Instance.createJobWithPromise({ type: 'video-import', payload })
auditLogger.create(getAuditIdFromRes(res), new VideoImportAuditView(videoImport.toFormattedJSON()))
......@@ -176,7 +176,7 @@ async function addYoutubeDLImport (req: express.Request, res: express.Response)
downloadThumbnail: !thumbnailModel,
downloadPreview: !previewModel
}
await JobQueue.Instance.createJob({ type: 'video-import', payload })
await JobQueue.Instance.createJobWithPromise({ type: 'video-import', payload })
auditLogger.create(getAuditIdFromRes(res), new VideoImportAuditView(videoImport.toFormattedJSON()))
......@@ -211,7 +211,7 @@ function buildVideo (channelId: number, body: VideoImportCreate, importData: You
async function processThumbnail (req: express.Request, video: VideoModel) {
const thumbnailField = req.files ? req.files['thumbnailfile'] : undefined
if (thumbnailField) {
const thumbnailPhysicalFile = thumbnailField[ 0 ]
const thumbnailPhysicalFile = thumbnailField[0]
return createVideoMiniatureFromExisting(thumbnailPhysicalFile.path, video, ThumbnailType.MINIATURE, false)
}
......@@ -231,12 +231,12 @@ async function processPreview (req: express.Request, video: VideoModel) {
}
function insertIntoDB (parameters: {
video: MVideoThumbnailAccountDefault,
thumbnailModel: MThumbnail,
previewModel: MThumbnail,
videoChannel: MChannelAccountDefault,
tags: string[],
videoImportAttributes: Partial<MVideoImport>,
video: MVideoThumbnailAccountDefault
thumbnailModel: MThumbnail
previewModel: MThumbnail
videoChannel: MChannelAccountDefault
tags: string[]
videoImportAttributes: Partial<MVideoImport>
user: MUser
}): Bluebird<MVideoImportFormattable> {
const { video, thumbnailModel, previewModel, videoChannel, tags, videoImportAttributes, user } = parameters
......
Markdown is supported
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment