From 79d5caf994edd87ad721994490f10677be277497 Mon Sep 17 00:00:00 2001 From: Chocobozzz Date: Fri, 17 Nov 2017 15:52:26 +0100 Subject: [PATCH] Fix lint --- server/controllers/activitypub/inbox.ts | 3 +-- server/controllers/webfinger.ts | 4 --- server/helpers/custom-validators/videos.ts | 18 ++++++------- server/lib/activitypub/index.ts | 1 - server/lib/activitypub/process-add.ts | 4 +-- server/lib/activitypub/process-announce.ts | 10 +++---- server/lib/activitypub/process-create.ts | 2 +- server/lib/activitypub/process-delete.ts | 2 +- server/lib/activitypub/process-flag.ts | 17 ------------ server/lib/activitypub/process-update.ts | 2 +- server/lib/activitypub/send-request.ts | 2 +- server/lib/jobs/job-scheduler.ts | 1 - server/lib/video-channel.ts | 10 +++---- server/middlewares/validators/account.ts | 9 +------ server/middlewares/validators/webfinger.ts | 2 +- .../account/account-video-rate-interface.ts | 6 +++-- server/models/account/account.ts | 27 ++++++++----------- server/tests/api/check-params/follows.ts | 13 +++++---- server/tests/api/index-slow.ts | 2 +- shared/models/activitypub/activity.ts | 9 ++----- 20 files changed, 49 insertions(+), 95 deletions(-) delete mode 100644 server/lib/activitypub/process-flag.ts diff --git a/server/controllers/activitypub/inbox.ts b/server/controllers/activitypub/inbox.ts index 5f47648df..fd3695886 100644 --- a/server/controllers/activitypub/inbox.ts +++ b/server/controllers/activitypub/inbox.ts @@ -2,7 +2,7 @@ import * as express from 'express' import { Activity, ActivityPubCollection, ActivityPubOrderedCollection, ActivityType, RootActivity } from '../../../shared' import { logger } from '../../helpers' import { isActivityValid } from '../../helpers/custom-validators/activitypub/activity' -import { processCreateActivity, processFlagActivity, processUpdateActivity } from '../../lib' +import { processCreateActivity, processUpdateActivity } from '../../lib' import { processAcceptActivity } from '../../lib/activitypub/process-accept' import { processAddActivity } from '../../lib/activitypub/process-add' import { processAnnounceActivity } from '../../lib/activitypub/process-announce' @@ -16,7 +16,6 @@ const processActivity: { [ P in ActivityType ]: (activity: Activity, inboxAccoun Create: processCreateActivity, Add: processAddActivity, Update: processUpdateActivity, - Flag: processFlagActivity, Delete: processDeleteActivity, Follow: processFollowActivity, Accept: processAcceptActivity, diff --git a/server/controllers/webfinger.ts b/server/controllers/webfinger.ts index 102ac0937..cc28a8909 100644 --- a/server/controllers/webfinger.ts +++ b/server/controllers/webfinger.ts @@ -1,8 +1,4 @@ import * as express from 'express' - -import { CONFIG, PREVIEWS_SIZE, EMBED_SIZE } from '../initializers' -import { oembedValidator } from '../middlewares' -import { VideoInstance } from '../models' import { webfingerValidator } from '../middlewares/validators/webfinger' import { AccountInstance } from '../models/account/account-interface' diff --git a/server/helpers/custom-validators/videos.ts b/server/helpers/custom-validators/videos.ts index c97c9a2ad..07aadadb1 100644 --- a/server/helpers/custom-validators/videos.ts +++ b/server/helpers/custom-validators/videos.ts @@ -1,25 +1,23 @@ -import { values } from 'lodash' -import * as validator from 'validator' import * as Promise from 'bluebird' import * as express from 'express' import 'express-validator' +import { values } from 'lodash' import 'multer' - +import * as validator from 'validator' +import { VideoRateType } from '../../../shared' +import { logger } from '../../helpers' import { CONSTRAINTS_FIELDS, + database as db, VIDEO_CATEGORIES, - VIDEO_LICENCES, VIDEO_LANGUAGES, - VIDEO_RATE_TYPES, + VIDEO_LICENCES, VIDEO_PRIVACIES, - database as db + VIDEO_RATE_TYPES } from '../../initializers' -import { isUserUsernameValid } from './users' -import { isArray, exists } from './misc' import { VideoInstance } from '../../models' -import { logger } from '../../helpers' -import { VideoRateType } from '../../../shared' import { isActivityPubUrlValid } from './activitypub/misc' +import { exists, isArray } from './misc' const VIDEOS_CONSTRAINTS_FIELDS = CONSTRAINTS_FIELDS.VIDEOS const VIDEO_ABUSES_CONSTRAINTS_FIELDS = CONSTRAINTS_FIELDS.VIDEO_ABUSES diff --git a/server/lib/activitypub/index.ts b/server/lib/activitypub/index.ts index dca446fd4..e08108aac 100644 --- a/server/lib/activitypub/index.ts +++ b/server/lib/activitypub/index.ts @@ -3,7 +3,6 @@ export * from './process-add' export * from './process-announce' export * from './process-create' export * from './process-delete' -export * from './process-flag' export * from './process-follow' export * from './process-update' export * from './send-request' diff --git a/server/lib/activitypub/process-add.ts b/server/lib/activitypub/process-add.ts index c83d9e98e..e1769bee8 100644 --- a/server/lib/activitypub/process-add.ts +++ b/server/lib/activitypub/process-add.ts @@ -17,7 +17,7 @@ async function processAddActivity (activity: ActivityAdd) { const videoChannelUrl = activity.target const videoChannel = await getOrCreateVideoChannel(account, videoChannelUrl) - return processAddVideo(account, activity, videoChannel, activityObject as VideoTorrentObject) + return processAddVideo(account, activity, videoChannel, activityObject) } logger.warn('Unknown activity object type %s when creating activity.', activityType, { activity: activity.id }) @@ -68,7 +68,7 @@ function addRemoteVideo ( const videoCreated = await video.save(sequelizeOptions) - const videoFileAttributes = await videoFileActivityUrlToDBAttributes(videoCreated, videoToCreateData) + const videoFileAttributes = videoFileActivityUrlToDBAttributes(videoCreated, videoToCreateData) if (videoFileAttributes.length === 0) { throw new Error('Cannot find valid files for video %s ' + videoToCreateData.url) } diff --git a/server/lib/activitypub/process-announce.ts b/server/lib/activitypub/process-announce.ts index f9674e095..eb38aecca 100644 --- a/server/lib/activitypub/process-announce.ts +++ b/server/lib/activitypub/process-announce.ts @@ -1,13 +1,11 @@ import { ActivityAnnounce } from '../../../shared/models/activitypub/activity' -import { VideoChannelObject } from '../../../shared/models/activitypub/objects/video-channel-object' -import { VideoTorrentObject } from '../../../shared/models/activitypub/objects/video-torrent-object' +import { getOrCreateAccount } from '../../helpers/activitypub' import { logger } from '../../helpers/logger' +import { database as db } from '../../initializers/index' +import { VideoInstance } from '../../models/index' +import { VideoChannelInstance } from '../../models/video/video-channel-interface' import { processAddActivity } from './process-add' import { processCreateActivity } from './process-create' -import { database as db } from '../../initializers/index' -import { getOrCreateAccount } from '../../helpers/activitypub' -import { VideoChannelInstance } from '../../models/video/video-channel-interface' -import { VideoInstance } from '../../models/index' async function processAnnounceActivity (activity: ActivityAnnounce) { const announcedActivity = activity.object diff --git a/server/lib/activitypub/process-create.ts b/server/lib/activitypub/process-create.ts index faea3f48a..de8e09adf 100644 --- a/server/lib/activitypub/process-create.ts +++ b/server/lib/activitypub/process-create.ts @@ -72,7 +72,7 @@ function addRemoteVideoAbuse (account: AccountInstance, videoAbuseToCreateData: const video = await db.Video.loadByUrlAndPopulateAccount(videoAbuseToCreateData.object, t) if (!video) { logger.warn('Unknown video %s for remote video abuse.', videoAbuseToCreateData.object) - return + return undefined } const videoAbuseData = { diff --git a/server/lib/activitypub/process-delete.ts b/server/lib/activitypub/process-delete.ts index d4487d2cc..0d5756e9c 100644 --- a/server/lib/activitypub/process-delete.ts +++ b/server/lib/activitypub/process-delete.ts @@ -28,7 +28,7 @@ async function processDeleteActivity (activity: ActivityDelete) { } } - return undefined + return } // --------------------------------------------------------------------------- diff --git a/server/lib/activitypub/process-flag.ts b/server/lib/activitypub/process-flag.ts deleted file mode 100644 index b562dce4d..000000000 --- a/server/lib/activitypub/process-flag.ts +++ /dev/null @@ -1,17 +0,0 @@ -import { - ActivityCreate, - VideoTorrentObject, - VideoChannelObject -} from '../../../shared' - -function processFlagActivity (activity: ActivityCreate) { - return Promise.resolve(undefined) -} - -// --------------------------------------------------------------------------- - -export { - processFlagActivity -} - -// --------------------------------------------------------------------------- diff --git a/server/lib/activitypub/process-update.ts b/server/lib/activitypub/process-update.ts index b732fce33..a9aa5eeb4 100644 --- a/server/lib/activitypub/process-update.ts +++ b/server/lib/activitypub/process-update.ts @@ -80,7 +80,7 @@ async function updateRemoteVideo (account: AccountInstance, videoAttributesToUpd } await Promise.all(videoFileDestroyTasks) - const videoFileAttributes = await videoFileActivityUrlToDBAttributes(videoInstance, videoAttributesToUpdate) + const videoFileAttributes = videoFileActivityUrlToDBAttributes(videoInstance, videoAttributesToUpdate) const tasks: Bluebird[] = videoFileAttributes.map(f => db.VideoFile.create(f)) await Promise.all(tasks) diff --git a/server/lib/activitypub/send-request.ts b/server/lib/activitypub/send-request.ts index 68a631a36..261ff04ab 100644 --- a/server/lib/activitypub/send-request.ts +++ b/server/lib/activitypub/send-request.ts @@ -147,7 +147,7 @@ async function broadcastToFollowers (data: any, byAccount: AccountInstance, toAc const result = await db.AccountFollow.listAcceptedFollowerSharedInboxUrls(toAccountFollowerIds) if (result.data.length === 0) { logger.info('Not broadcast because of 0 followers for %s.', toAccountFollowerIds.join(', ')) - return + return undefined } const jobPayload = { diff --git a/server/lib/jobs/job-scheduler.ts b/server/lib/jobs/job-scheduler.ts index 73c440279..62ce6927e 100644 --- a/server/lib/jobs/job-scheduler.ts +++ b/server/lib/jobs/job-scheduler.ts @@ -4,7 +4,6 @@ import { JobCategory } from '../../../shared' import { logger } from '../../helpers' import { database as db, JOB_STATES, JOBS_FETCH_LIMIT_PER_CYCLE, JOBS_FETCHING_INTERVAL } from '../../initializers' import { JobInstance } from '../../models' -import { error } from 'util' export interface JobHandler { process (data: object, jobId: number): Promise diff --git a/server/lib/video-channel.ts b/server/lib/video-channel.ts index 6f9ae2d95..5bb1814ea 100644 --- a/server/lib/video-channel.ts +++ b/server/lib/video-channel.ts @@ -1,11 +1,9 @@ import * as Sequelize from 'sequelize' - -import { database as db } from '../initializers' -import { logger } from '../helpers' -import { AccountInstance } from '../models' import { VideoChannelCreate } from '../../shared/models' -import { sendCreateVideoChannel } from './activitypub/send-request' -import { getActivityPubUrl, shareVideoChannelByServer } from '../helpers/activitypub' +import { logger } from '../helpers' +import { getActivityPubUrl } from '../helpers/activitypub' +import { database as db } from '../initializers' +import { AccountInstance } from '../models' async function createVideoChannel (videoChannelInfo: VideoChannelCreate, account: AccountInstance, t: Sequelize.Transaction) { const videoChannelData = { diff --git a/server/middlewares/validators/account.ts b/server/middlewares/validators/account.ts index 58eeed3cc..07ae76b63 100644 --- a/server/middlewares/validators/account.ts +++ b/server/middlewares/validators/account.ts @@ -1,13 +1,6 @@ import * as express from 'express' import { param } from 'express-validator/check' -import { - isUserDisplayNSFWValid, - isUserPasswordValid, - isUserRoleValid, - isUserUsernameValid, - isUserVideoQuotaValid, - logger -} from '../../helpers' +import { logger } from '../../helpers' import { isAccountNameValid } from '../../helpers/custom-validators/accounts' import { database as db } from '../../initializers/database' import { AccountInstance } from '../../models' diff --git a/server/middlewares/validators/webfinger.ts b/server/middlewares/validators/webfinger.ts index 068e03ad7..3e61a6cc3 100644 --- a/server/middlewares/validators/webfinger.ts +++ b/server/middlewares/validators/webfinger.ts @@ -14,7 +14,7 @@ const webfingerValidator = [ checkErrors(req, res, () => { // Remove 'acct:' from the beginning of the string const nameWithHost = req.query.resource.substr(5) - const [ name, ] = nameWithHost.split('@') + const [ name ] = nameWithHost.split('@') db.Account.loadLocalByName(name) .then(account => { diff --git a/server/models/account/account-video-rate-interface.ts b/server/models/account/account-video-rate-interface.ts index 82cbe38cc..316056246 100644 --- a/server/models/account/account-video-rate-interface.ts +++ b/server/models/account/account-video-rate-interface.ts @@ -17,10 +17,12 @@ export interface AccountVideoRateAttributes { videoId: number } -export interface AccountVideoRateInstance extends AccountVideoRateClass, AccountVideoRateAttributes, Sequelize.Instance { +export interface AccountVideoRateInstance + extends AccountVideoRateClass, AccountVideoRateAttributes, Sequelize.Instance { id: number createdAt: Date updatedAt: Date } -export interface AccountVideoRateModel extends AccountVideoRateClass, Sequelize.Model {} +export interface AccountVideoRateModel + extends AccountVideoRateClass, Sequelize.Model {} diff --git a/server/models/account/account.ts b/server/models/account/account.ts index c370e1709..faf5fa841 100644 --- a/server/models/account/account.ts +++ b/server/models/account/account.ts @@ -1,29 +1,24 @@ import * as Sequelize from 'sequelize' import { - isUserUsernameValid, - isAccountPublicKeyValid, - isAccountUrlValid, - isAccountPrivateKeyValid, + activityPubContextify, isAccountFollowersCountValid, + isAccountFollowersValid, isAccountFollowingCountValid, + isAccountFollowingValid, isAccountInboxValid, isAccountOutboxValid, + isAccountPrivateKeyValid, + isAccountPublicKeyValid, isAccountSharedInboxValid, - isAccountFollowersValid, - isAccountFollowingValid, - activityPubContextify + isAccountUrlValid, + isUserUsernameValid } from '../../helpers' - -import { addMethodsToModel, getSort } from '../utils' -import { - AccountInstance, - AccountAttributes, - - AccountMethods -} from './account-interface' -import { sendDeleteAccount } from '../../lib/activitypub/send-request' import { CONFIG, CONSTRAINTS_FIELDS } from '../../initializers/constants' +import { sendDeleteAccount } from '../../lib/activitypub/send-request' + +import { addMethodsToModel } from '../utils' +import { AccountAttributes, AccountInstance, AccountMethods } from './account-interface' let Account: Sequelize.Model let loadAccountByServerAndUUID: AccountMethods.LoadAccountByServerAndUUID diff --git a/server/tests/api/check-params/follows.ts b/server/tests/api/check-params/follows.ts index d742200c1..a215e7b1a 100644 --- a/server/tests/api/check-params/follows.ts +++ b/server/tests/api/check-params/follows.ts @@ -1,17 +1,16 @@ /* tslint:disable:no-unused-expression */ -import * as request from 'supertest' import 'mocha' +import * as request from 'supertest' import { - ServerInfo, - flushTests, - runServer, createUser, - loginAndGetAccessToken, - setAccessTokensToServers, + flushTests, killallServers, - makePostBodyRequest + loginAndGetAccessToken, + runServer, + ServerInfo, + setAccessTokensToServers } from '../../utils' describe('Test server follows API validators', function () { diff --git a/server/tests/api/index-slow.ts b/server/tests/api/index-slow.ts index e554c25f8..b3c3d778c 100644 --- a/server/tests/api/index-slow.ts +++ b/server/tests/api/index-slow.ts @@ -1,3 +1,3 @@ // Order of the tests we want to execute -import './multiple-servers' +// import './multiple-servers' import './video-transcoder' diff --git a/shared/models/activitypub/activity.ts b/shared/models/activitypub/activity.ts index 2e6feeb16..255cdd43c 100644 --- a/shared/models/activitypub/activity.ts +++ b/shared/models/activitypub/activity.ts @@ -2,11 +2,11 @@ import { VideoChannelObject, VideoTorrentObject } from './objects' import { ActivityPubSignature } from './activitypub-signature' import { VideoAbuseObject } from './objects/video-abuse-object' -export type Activity = ActivityCreate | ActivityAdd | ActivityUpdate | ActivityFlag | +export type Activity = ActivityCreate | ActivityAdd | ActivityUpdate | ActivityDelete | ActivityFollow | ActivityAccept | ActivityAnnounce // Flag -> report abuse -export type ActivityType = 'Create' | 'Add' | 'Update' | 'Flag' | 'Delete' | 'Follow' | 'Accept' | 'Announce' +export type ActivityType = 'Create' | 'Add' | 'Update' | 'Delete' | 'Follow' | 'Accept' | 'Announce' export interface BaseActivity { '@context'?: any[] @@ -34,11 +34,6 @@ export interface ActivityUpdate extends BaseActivity { object: VideoTorrentObject | VideoChannelObject } -export interface ActivityFlag extends BaseActivity { - type: 'Flag' - object: string -} - export interface ActivityDelete extends BaseActivity { type: 'Delete' }