Skip to content

Commit

Permalink
Fix remaining eslint errors
Browse files Browse the repository at this point in the history
  • Loading branch information
rijkvanzanten committed Apr 29, 2021
1 parent 5b7bd55 commit 801e868
Show file tree
Hide file tree
Showing 308 changed files with 986 additions and 1,176 deletions.
46 changes: 20 additions & 26 deletions api/src/app.ts
Original file line number Diff line number Diff line change
@@ -1,23 +1,10 @@
import expressLogger from 'express-pino-logger';
import cookieParser from 'cookie-parser';
import bodyParser from 'body-parser';
import cookieParser from 'cookie-parser';
import express from 'express';
import logger from './logger';
import expressLogger from 'express-pino-logger';
import fse from 'fs-extra';
import path from 'path';
import qs from 'qs';

import { validateDBConnection, isInstalled } from './database';

import { validateEnv } from './utils/validate-env';
import env from './env';
import { track } from './utils/track';

import errorHandler from './middleware/error-handler';
import cors from './middleware/cors';
import rateLimiter from './middleware/rate-limiter';
import cache from './middleware/cache';
import extractToken from './middleware/extract-token';
import authenticate from './middleware/authenticate';
import activityRouter from './controllers/activity';
import assetsRouter from './controllers/assets';
import authRouter from './controllers/auth';
Expand All @@ -26,7 +13,9 @@ import extensionsRouter from './controllers/extensions';
import fieldsRouter from './controllers/fields';
import filesRouter from './controllers/files';
import foldersRouter from './controllers/folders';
import graphqlRouter from './controllers/graphql';
import itemsRouter from './controllers/items';
import notFoundHandler from './controllers/not-found';
import permissionsRouter from './controllers/permissions';
import presetsRouter from './controllers/presets';
import relationsRouter from './controllers/relations';
Expand All @@ -37,19 +26,24 @@ import settingsRouter from './controllers/settings';
import usersRouter from './controllers/users';
import utilsRouter from './controllers/utils';
import webhooksRouter from './controllers/webhooks';
import graphqlRouter from './controllers/graphql';
import schema from './middleware/schema';

import notFoundHandler from './controllers/not-found';
import sanitizeQuery from './middleware/sanitize-query';
import { checkIP } from './middleware/check-ip';
import { isInstalled, validateDBConnection } from './database';
import { emitAsyncSafe } from './emitter';
import env from './env';
import { InvalidPayloadException } from './exceptions';

import { initializeExtensions, registerExtensionEndpoints, registerExtensionHooks } from './extensions';
import logger from './logger';
import authenticate from './middleware/authenticate';
import cache from './middleware/cache';
import { checkIP } from './middleware/check-ip';
import cors from './middleware/cors';
import errorHandler from './middleware/error-handler';
import extractToken from './middleware/extract-token';
import rateLimiter from './middleware/rate-limiter';
import sanitizeQuery from './middleware/sanitize-query';
import schema from './middleware/schema';
import { track } from './utils/track';
import { validateEnv } from './utils/validate-env';
import { register as registerWebhooks } from './webhooks';
import { emitAsyncSafe } from './emitter';

import fse from 'fs-extra';

export default async function createApp(): Promise<express.Application> {
validateEnv(['KEY', 'SECRET']);
Expand Down
6 changes: 3 additions & 3 deletions api/src/cache.ts
Original file line number Diff line number Diff line change
@@ -1,9 +1,9 @@
import env from './env';
import Keyv, { Options } from 'keyv';
import { validateEnv } from './utils/validate-env';
import { getConfigFromEnv } from './utils/get-config-from-env';
import ms from 'ms';
import env from './env';
import logger from './logger';
import { getConfigFromEnv } from './utils/get-config-from-env';
import { validateEnv } from './utils/validate-env';

let cache: Keyv | null = null;

Expand Down
8 changes: 4 additions & 4 deletions api/src/cli/commands/bootstrap/index.ts
Original file line number Diff line number Diff line change
@@ -1,9 +1,9 @@
import { nanoid } from 'nanoid';
import runMigrations from '../../../database/migrations/run';
import installDatabase from '../../../database/seeds/run';
import env from '../../../env';
import logger from '../../../logger';
import installDatabase from '../../../database/seeds/run';
import runMigrations from '../../../database/migrations/run';
import { getSchema } from '../../../utils/get-schema';
import { nanoid } from 'nanoid';

export default async function bootstrap(): Promise<void> {
logger.info('Initializing bootstrap...');
Expand Down Expand Up @@ -71,7 +71,7 @@ async function isDatabaseAvailable() {
const tries = 5;
const secondsBetweenTries = 5;

for (var i = 0; i < tries; i++) {
for (let i = 0; i < tries; i++) {
if (await hasDatabaseConnection()) {
return true;
}
Expand Down
2 changes: 1 addition & 1 deletion api/src/cli/commands/database/install.ts
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
import { Knex } from 'knex';
import installSeeds from '../../../database/seeds/run';
import runMigrations from '../../../database/migrations/run';
import installSeeds from '../../../database/seeds/run';

export default async function start(): Promise<void> {
const database = require('../../../database/index').default as Knex;
Expand Down
21 changes: 9 additions & 12 deletions api/src/cli/commands/init/index.ts
Original file line number Diff line number Diff line change
@@ -1,24 +1,21 @@
import argon2 from 'argon2';
import chalk from 'chalk';
import inquirer from 'inquirer';
import { databaseQuestions } from './questions';
import { drivers, getDriverForClient } from '../../utils/drivers';
import createEnv from '../../utils/create-env';
import { v4 as uuidV4 } from 'uuid';
import execa from 'execa';
import inquirer from 'inquirer';
import { Knex } from 'knex';
import ora from 'ora';

import argon2 from 'argon2';

import runSeed from '../../../database/seeds/run';
import { v4 as uuidV4 } from 'uuid';
import runMigrations from '../../../database/migrations/run';

import runSeed from '../../../database/seeds/run';
import createDBConnection, { Credentials } from '../../utils/create-db-connection';
import { Knex } from 'knex';
import createEnv from '../../utils/create-env';
import { drivers, getDriverForClient } from '../../utils/drivers';
import { databaseQuestions } from './questions';

export default async function init(): Promise<void> {
const rootPath = process.cwd();

let { client } = await inquirer.prompt([
const { client } = await inquirer.prompt([
{
type: 'list',
name: 'client',
Expand Down
2 changes: 1 addition & 1 deletion api/src/cli/commands/roles/create.ts
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
import { getSchema } from '../../../utils/get-schema';

export default async function rolesCreate({ name, admin }: any): Promise<void> {
export default async function rolesCreate({ name, admin }: { name: string; admin: boolean }): Promise<void> {
const { default: database } = require('../../../database/index');
const { RolesService } = require('../../../services/roles');

Expand Down
12 changes: 10 additions & 2 deletions api/src/cli/commands/users/create.ts
Original file line number Diff line number Diff line change
@@ -1,7 +1,15 @@
import { getSchema } from '../../../utils/get-schema';

export default async function usersCreate({ email, password, role }: any): Promise<void> {
const { default: database, schemaInspector } = require('../../../database/index');
export default async function usersCreate({
email,
password,
role,
}: {
email?: string;
password?: string;
role?: string;
}): Promise<void> {
const { default: database } = require('../../../database/index');
const { UsersService } = require('../../../services/users');

if (!email || !password || !role) {
Expand Down
2 changes: 1 addition & 1 deletion api/src/cli/commands/users/passwd.ts
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
import argon2 from 'argon2';
import { getSchema } from '../../../utils/get-schema';

export default async function usersPasswd({ email, password }: any): Promise<void> {
export default async function usersPasswd({ email, password }: { email?: string; password?: string }): Promise<void> {
const { default: database } = require('../../../database/index');
const { UsersService } = require('../../../services/users');

Expand Down
13 changes: 6 additions & 7 deletions api/src/cli/index.ts
Original file line number Diff line number Diff line change
@@ -1,18 +1,17 @@
#!/usr/bin/env node

import program from 'commander';

const pkg = require('../../package.json');

import start from '../start';
import init from './commands/init';
import bootstrap from './commands/bootstrap';
import count from './commands/count';
import dbInstall from './commands/database/install';
import dbMigrate from './commands/database/migrate';
import init from './commands/init';
import rolesCreate from './commands/roles/create';
import usersCreate from './commands/users/create';
import usersPasswd from './commands/users/passwd';
import rolesCreate from './commands/roles/create';
import count from './commands/count';
import bootstrap from './commands/bootstrap';

const pkg = require('../../package.json');

program.name('directus').usage('[command] [options]');
program.version(pkg.version, '-v, --version');
Expand Down
12 changes: 6 additions & 6 deletions api/src/cli/utils/create-env/index.ts
Original file line number Diff line number Diff line change
@@ -1,11 +1,11 @@
import { drivers } from '../drivers';
import { Credentials } from '../create-db-connection';
import { v4 as uuidv4 } from 'uuid';
import { nanoid } from 'nanoid';
import { Liquid } from 'liquidjs';
import fs from 'fs';
import { promisify } from 'util';
import { Liquid } from 'liquidjs';
import { nanoid } from 'nanoid';
import path from 'path';
import { promisify } from 'util';
import { v4 as uuidv4 } from 'uuid';
import { Credentials } from '../create-db-connection';
import { drivers } from '../drivers';

const readFile = promisify(fs.readFile);
const writeFile = promisify(fs.writeFile);
Expand Down
2 changes: 1 addition & 1 deletion api/src/cli/utils/drivers.ts
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@ export const drivers = {
pg: 'PostgreSQL / Redshift',
mysql: 'MySQL / MariaDB / Aurora',
sqlite3: 'SQLite',
mssql: 'Microsoft SQL Server',
mssql: 'Microsoft SQL Server',
oracledb: 'Oracle Database (Alpha)',
};

Expand Down
10 changes: 5 additions & 5 deletions api/src/controllers/activity.ts
Original file line number Diff line number Diff line change
@@ -1,12 +1,12 @@
import express from 'express';
import asyncHandler from '../utils/async-handler';
import { ActivityService, MetaService } from '../services';
import { Action } from '../types';
import Joi from 'joi';
import { ForbiddenException, InvalidPayloadException } from '../exceptions';
import useCollection from '../middleware/use-collection';
import { respond } from '../middleware/respond';
import Joi from 'joi';
import useCollection from '../middleware/use-collection';
import { validateBatch } from '../middleware/validate-batch';
import { ActivityService, MetaService } from '../services';
import { Action } from '../types';
import asyncHandler from '../utils/async-handler';

const router = express.Router();

Expand Down
35 changes: 16 additions & 19 deletions api/src/controllers/assets.ts
Original file line number Diff line number Diff line change
@@ -1,17 +1,17 @@
import { Range } from '@directus/drive';
import { Router } from 'express';
import asyncHandler from '../utils/async-handler';
import database from '../database';
import { SYSTEM_ASSET_ALLOW_LIST, ASSET_TRANSFORM_QUERY_KEYS } from '../constants';
import { InvalidQueryException, ForbiddenException, RangeNotSatisfiableException } from '../exceptions';
import validate from 'uuid-validate';
import { pick } from 'lodash';
import { Transformation } from '../types/assets';
import storage from '../storage';
import { PayloadService, AssetsService } from '../services';
import useCollection from '../middleware/use-collection';
import env from '../env';
import ms from 'ms';
import { Range } from '@directus/drive';
import validate from 'uuid-validate';
import { ASSET_TRANSFORM_QUERY_KEYS, SYSTEM_ASSET_ALLOW_LIST } from '../constants';
import database from '../database';
import env from '../env';
import { ForbiddenException, InvalidQueryException, RangeNotSatisfiableException } from '../exceptions';
import useCollection from '../middleware/use-collection';
import { AssetsService, PayloadService } from '../services';
import storage from '../storage';
import { Transformation } from '../types/assets';
import asyncHandler from '../utils/async-handler';

const router = Router();

Expand Down Expand Up @@ -51,7 +51,7 @@ router.get(
const payloadService = new PayloadService('directus_settings', { schema: req.schema });
const defaults = { storage_asset_presets: [], storage_asset_transform: 'all' };

let savedAssetSettings = await database
const savedAssetSettings = await database
.select('storage_asset_presets', 'storage_asset_transform')
.from('directus_settings')
.first();
Expand All @@ -64,13 +64,10 @@ router.get(

const transformation = pick(req.query, ASSET_TRANSFORM_QUERY_KEYS);

if (transformation.hasOwnProperty('key') && Object.keys(transformation).length > 1) {
if ('key' in transformation && Object.keys(transformation).length > 1) {
throw new InvalidQueryException(`You can't combine the "key" query parameter with any other transformation.`);
}
if (
transformation.hasOwnProperty('quality') &&
(Number(transformation.quality) < 1 || Number(transformation.quality) > 100)
) {
if ('quality' in transformation && (Number(transformation.quality) < 1 || Number(transformation.quality) > 100)) {
throw new InvalidQueryException(`"quality" Parameter has to between 1 to 100`);
}

Expand Down Expand Up @@ -133,7 +130,7 @@ router.get(

const { stream, file, stat } = await service.getAsset(id, transformation, range);

const access = !!req.accountability?.role ? 'private' : 'public';
const access = req.accountability?.role ? 'private' : 'public';

res.attachment(file.filename_download);
res.setHeader('Content-Type', file.type);
Expand All @@ -148,7 +145,7 @@ router.get(
res.setHeader('Content-Length', stat.size);
}

if (req.query.hasOwnProperty('download') === false) {
if ('download' in req.query === false) {
res.removeHeader('Content-Disposition');
}

Expand Down
18 changes: 9 additions & 9 deletions api/src/controllers/auth.ts
Original file line number Diff line number Diff line change
@@ -1,18 +1,18 @@
import { Router } from 'express';
import session from 'express-session';
import asyncHandler from '../utils/async-handler';
import Joi from 'joi';
import grant from 'grant';
import getEmailFromProfile from '../utils/get-email-from-profile';
import { InvalidPayloadException } from '../exceptions/invalid-payload';
import Joi from 'joi';
import ms from 'ms';
import emitter, { emitAsyncSafe } from '../emitter';
import env from '../env';
import { UsersService, AuthenticationService } from '../services';
import grantConfig from '../grant';
import { InvalidCredentialsException, RouteNotFoundException, ServiceUnavailableException } from '../exceptions';
import { InvalidPayloadException } from '../exceptions/invalid-payload';
import grantConfig from '../grant';
import { respond } from '../middleware/respond';
import { AuthenticationService, UsersService } from '../services';
import asyncHandler from '../utils/async-handler';
import getEmailFromProfile from '../utils/get-email-from-profile';
import { toArray } from '../utils/to-array';
import emitter, { emitAsyncSafe } from '../emitter';

const router = Router();

Expand Down Expand Up @@ -237,7 +237,7 @@ router.get(
req.session.redirect = req.query.redirect as string;
}

let hookPayload = {
const hookPayload = {
provider: req.params.provider,
redirect: req.query?.redirect,
};
Expand Down Expand Up @@ -284,7 +284,7 @@ router.get(

let authResponse: { accessToken: any; refreshToken: any; expires: any; id?: any };

let hookPayload = req.session.grant.response;
const hookPayload = req.session.grant.response;

await emitter.emitAsync(`oauth.${req.params.provider}.login.before`, hookPayload, {
event: `oauth.${req.params.provider}.login.before`,
Expand Down
4 changes: 2 additions & 2 deletions api/src/controllers/collections.ts
Original file line number Diff line number Diff line change
@@ -1,10 +1,10 @@
import { Router } from 'express';
import asyncHandler from '../utils/async-handler';
import { CollectionsService, MetaService } from '../services';
import { ForbiddenException } from '../exceptions';
import { respond } from '../middleware/respond';
import { validateBatch } from '../middleware/validate-batch';
import { CollectionsService, MetaService } from '../services';
import { Item } from '../types';
import asyncHandler from '../utils/async-handler';

const router = Router();

Expand Down
4 changes: 2 additions & 2 deletions api/src/controllers/extensions.ts
Original file line number Diff line number Diff line change
@@ -1,9 +1,9 @@
import express, { Router } from 'express';
import asyncHandler from '../utils/async-handler';
import env from '../env';
import { RouteNotFoundException } from '../exceptions';
import { listExtensions } from '../extensions';
import env from '../env';
import { respond } from '../middleware/respond';
import asyncHandler from '../utils/async-handler';

const router = Router();

Expand Down
Loading

0 comments on commit 801e868

Please sign in to comment.