enforcing single line if statements

This commit is contained in:
diced 2020-11-12 09:42:09 -08:00
parent 27ec3de3ac
commit bc7a7a8c24
No known key found for this signature in database
GPG key ID: 2CD9508012284494
12 changed files with 69 additions and 90 deletions

View file

@ -29,6 +29,7 @@ module.exports = {
'linebreak-style': ['error', 'unix'],
quotes: ['error', 'single'],
semi: ['error', 'always'],
'comma-dangle': ['error', 'never']
'comma-dangle': ['error', 'never'],
'nonblock-statement-body-position': ['error', 'beside']
}
};

View file

@ -40,6 +40,7 @@
"scripts": {
"format": "prettier --write .",
"lint": "eslint .",
"lint:fix": "eslint . --fix",
"dev": "ts-node src",
"dev:verbose": "VERBOSE=true ts-node src",
"build": "next build && tsc -p .",

View file

@ -27,8 +27,7 @@ import { MultiFactorController } from './lib/controllers/MultiFactorController';
const dev = process.env.NODE_ENV !== 'production';
(async () => {
if (await checkVersion())
Console.logger('Zipline').info(
if (await checkVersion()) Console.logger('Zipline').info(
'running an outdated version of zipline, please update soon!'
);
})();
@ -85,8 +84,7 @@ server.register(fastifyRateLimit, {
global: false
});
if (dev)
server.get('/_next/*', async (req, reply) => {
if (dev) server.get('/_next/*', async (req, reply) => {
await handle(req.raw, reply.raw);
return (reply.sent = true);
});

View file

@ -79,8 +79,7 @@ export class Configuration {
try {
const data = readFileSync(resolve(process.cwd(), 'Zipline.toml'), 'utf8');
const parsed = parse(data);
if (parsed.webhooks)
parsed.webhooks.events = Webhooks.convert(parsed.webhooks.events);
if (parsed.webhooks) parsed.webhooks.events = Webhooks.convert(parsed.webhooks.events);
return parsed;
} catch (e) {
return null;

View file

@ -15,8 +15,7 @@ export function createRandomId(
charset = 'ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz0123456789'
) {
let result = '';
for (let i = 0; i < length; i++)
result += charset.charAt(Math.floor(Math.random() * charset.length));
for (let i = 0; i < length; i++) result += charset.charAt(Math.floor(Math.random() * charset.length));
return result;
}

View file

@ -70,8 +70,7 @@ export class ImagesController {
unlinkSync(path);
Console.logger(Image).info(`image ${image.id} was deleted`);
if (this.webhooks.events.includes(WebhookType.DELETE_IMAGE))
Webhooks.sendWebhook(this.webhooks.upload.content, {
if (this.webhooks.events.includes(WebhookType.DELETE_IMAGE)) Webhooks.sendWebhook(this.webhooks.upload.content, {
image,
host: `${config.core.secure ? 'https' : 'http'}://${req.hostname}${
config.uploader.route

View file

@ -99,8 +99,7 @@ export class MultiFactorController {
}
});
if (!user)
return sendError(reply, `User "${req.body.username}" was not found.`);
if (!user) return sendError(reply, `User "${req.body.username}" was not found.`);
if (!checkPassword(req.body.password, user.password)) {
this.logger.error(
`${user.username} (${user.id}) tried to login but failed with mfa`
@ -122,8 +121,7 @@ export class MultiFactorController {
});
this.logger.info(`${user.username} (${user.id}) logged in with mfa`);
if (this.webhooks.events.includes(WebhookType.LOGIN))
Webhooks.sendWebhook(this.webhooks.login.content, {
if (this.webhooks.events.includes(WebhookType.LOGIN)) Webhooks.sendWebhook(this.webhooks.login.content, {
user
});

View file

@ -109,8 +109,7 @@ export class RootController {
@POST('/upload', rateLimiterConfig)
async loginStatus(req: FastifyRequest, reply: FastifyReply) {
if (!req.headers.authorization)
return sendError(reply, 'No authorization header!');
if (!req.headers.authorization) return sendError(reply, 'No authorization header!');
const user = await this.users.findOne({
where: {
@ -123,12 +122,10 @@ export class RootController {
//@ts-ignore stupid multipart types smh
const data: Multipart = await req.file();
if (!existsSync(config.uploader.directory))
mkdirSync(config.uploader.directory);
if (!existsSync(config.uploader.directory)) mkdirSync(config.uploader.directory);
const ext = data.filename.split('.')[1];
if (config.uploader.blacklisted.includes(ext))
return sendError(reply, 'Blacklisted file extension!');
if (config.uploader.blacklisted.includes(ext)) return sendError(reply, 'Blacklisted file extension!');
const fileName = config.uploader.original
? data.filename.split('.')[0]
@ -153,8 +150,7 @@ export class RootController {
: config.uploader.route
}/${fileName}.${ext}`;
if (this.webhooks.events.includes(WebhookType.UPLOAD))
Webhooks.sendWebhook(this.webhooks.upload.content, {
if (this.webhooks.events.includes(WebhookType.UPLOAD)) Webhooks.sendWebhook(this.webhooks.upload.content, {
image,
host
});

View file

@ -62,8 +62,7 @@ export class URLSController {
});
this.logger.info(`url ${url.id} was deleted`);
if (this.webhooks.events.includes(WebhookType.DELETE_URL))
Webhooks.sendWebhook(this.webhooks.delete_url.content, {
if (this.webhooks.events.includes(WebhookType.DELETE_URL)) Webhooks.sendWebhook(this.webhooks.delete_url.content, {
url,
host: `${config.core.secure ? 'https' : 'http'}://${req.hostname}${
config.urls.route
@ -86,8 +85,7 @@ export class URLSController {
vanity: req.body.vanity
}
});
if (existingVanity)
return sendError(reply, 'There is an existing vanity!');
if (existingVanity) return sendError(reply, 'There is an existing vanity!');
}
const user = await this.users.findOne({
@ -106,8 +104,7 @@ export class URLSController {
);
this.logger.info(`saved url ${url.id}`);
if (this.webhooks.events.includes(WebhookType.SHORTEN))
Webhooks.sendWebhook(this.webhooks.shorten.content, {
if (this.webhooks.events.includes(WebhookType.SHORTEN)) Webhooks.sendWebhook(this.webhooks.shorten.content, {
url,
host: `${config.core.secure ? 'https' : 'http'}://${req.hostname}${
config.urls.route

View file

@ -80,8 +80,7 @@ export class UserController {
await this.users.save(user);
this.logger.info(`saved ${user.username} (${user.id})`);
if (this.webhooks.events.includes(WebhookType.USER_EDIT))
Webhooks.sendWebhook(this.webhooks.user_edit.content, {
if (this.webhooks.events.includes(WebhookType.USER_EDIT)) Webhooks.sendWebhook(this.webhooks.user_edit.content, {
user
});
@ -104,8 +103,7 @@ export class UserController {
}
});
if (!user)
return sendError(reply, `User "${req.body.username}" was not found.`);
if (!user) return sendError(reply, `User "${req.body.username}" was not found.`);
if (!checkPassword(req.body.password, user.password)) {
this.logger.error(
`${user.username} (${user.id}) tried to verify their credentials but failed`
@ -133,8 +131,7 @@ export class UserController {
}
});
if (!user)
return sendError(reply, `User "${req.body.username}" was not found.`);
if (!user) return sendError(reply, `User "${req.body.username}" was not found.`);
if (!checkPassword(req.body.password, user.password)) {
this.logger.error(
`${user.username} (${user.id}) tried to login but failed`
@ -150,8 +147,7 @@ export class UserController {
});
this.logger.info(`${user.username} (${user.id}) logged in`);
if (this.webhooks.events.includes(WebhookType.LOGIN))
Webhooks.sendWebhook(this.webhooks.login.content, {
if (this.webhooks.events.includes(WebhookType.LOGIN)) Webhooks.sendWebhook(this.webhooks.login.content, {
user
});
@ -188,8 +184,7 @@ export class UserController {
await this.users.save(user);
this.logger.info(`reset token ${user.username} (${user.id})`);
if (this.webhooks.events.includes(WebhookType.TOKEN_RESET))
Webhooks.sendWebhook(this.webhooks.token_reset.content, {
if (this.webhooks.events.includes(WebhookType.TOKEN_RESET)) Webhooks.sendWebhook(this.webhooks.token_reset.content, {
user
});
@ -222,14 +217,12 @@ export class UserController {
)
);
this.logger.info(`created user ${user.username} (${user.id})`);
if (this.webhooks.events.includes(WebhookType.CREATE_USER))
Webhooks.sendWebhook(this.webhooks.create_user.content, {
if (this.webhooks.events.includes(WebhookType.CREATE_USER)) Webhooks.sendWebhook(this.webhooks.create_user.content, {
user
});
const firstSetup = await getFirst(this.instance.orm);
if (firstSetup)
await this.instance.orm.getRepository(Zipline).update(
if (firstSetup) await this.instance.orm.getRepository(Zipline).update(
{
id: 'zipline'
},
@ -266,8 +259,7 @@ export class UserController {
await this.users.remove(existing);
this.logger.info(`deleted ${existing.username} (${existing.id})`);
if (this.webhooks.events.includes(WebhookType.USER_DELETE))
Webhooks.sendWebhook(this.webhooks.user_delete.content, {
if (this.webhooks.events.includes(WebhookType.USER_DELETE)) Webhooks.sendWebhook(this.webhooks.user_delete.content, {
user: existing
});

View file

@ -10,8 +10,7 @@ export default function Manage({ config }) {
const router = useRouter();
const state = store.getState();
if (typeof window !== 'undefined' && !state.loggedIn)
router.push('/user/login');
if (typeof window !== 'undefined' && !state.loggedIn) router.push('/user/login');
else {
return (
<UI>