mirror of
https://github.com/diced/zipline.git
synced 2025-05-10 18:05:54 +02:00
enforcing single line if statements
This commit is contained in:
parent
27ec3de3ac
commit
bc7a7a8c24
12 changed files with 69 additions and 90 deletions
|
@ -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']
|
||||
}
|
||||
};
|
||||
|
|
|
@ -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 .",
|
||||
|
|
16
src/index.ts
16
src/index.ts
|
@ -27,10 +27,9 @@ import { MultiFactorController } from './lib/controllers/MultiFactorController';
|
|||
const dev = process.env.NODE_ENV !== 'production';
|
||||
|
||||
(async () => {
|
||||
if (await checkVersion())
|
||||
Console.logger('Zipline').info(
|
||||
'running an outdated version of zipline, please update soon!'
|
||||
);
|
||||
if (await checkVersion()) Console.logger('Zipline').info(
|
||||
'running an outdated version of zipline, please update soon!'
|
||||
);
|
||||
})();
|
||||
|
||||
console.log(`
|
||||
|
@ -85,11 +84,10 @@ server.register(fastifyRateLimit, {
|
|||
global: false
|
||||
});
|
||||
|
||||
if (dev)
|
||||
server.get('/_next/*', async (req, reply) => {
|
||||
await handle(req.raw, reply.raw);
|
||||
return (reply.sent = true);
|
||||
});
|
||||
if (dev) server.get('/_next/*', async (req, reply) => {
|
||||
await handle(req.raw, reply.raw);
|
||||
return (reply.sent = true);
|
||||
});
|
||||
|
||||
server.all('/*', async (req, reply) => {
|
||||
await handle(req.raw, reply.raw);
|
||||
|
|
|
@ -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;
|
||||
|
|
|
@ -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;
|
||||
}
|
||||
|
||||
|
|
|
@ -70,13 +70,12 @@ 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, {
|
||||
image,
|
||||
host: `${config.core.secure ? 'https' : 'http'}://${req.hostname}${
|
||||
config.uploader.route
|
||||
}/`
|
||||
});
|
||||
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
|
||||
}/`
|
||||
});
|
||||
|
||||
return reply.send(image);
|
||||
} catch (e) {
|
||||
|
|
|
@ -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,10 +121,9 @@ 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, {
|
||||
user
|
||||
});
|
||||
if (this.webhooks.events.includes(WebhookType.LOGIN)) Webhooks.sendWebhook(this.webhooks.login.content, {
|
||||
user
|
||||
});
|
||||
|
||||
return reply.send({ user, passed });
|
||||
}
|
||||
|
|
|
@ -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,11 +150,10 @@ export class RootController {
|
|||
: config.uploader.route
|
||||
}/${fileName}.${ext}`;
|
||||
|
||||
if (this.webhooks.events.includes(WebhookType.UPLOAD))
|
||||
Webhooks.sendWebhook(this.webhooks.upload.content, {
|
||||
image,
|
||||
host
|
||||
});
|
||||
if (this.webhooks.events.includes(WebhookType.UPLOAD)) Webhooks.sendWebhook(this.webhooks.upload.content, {
|
||||
image,
|
||||
host
|
||||
});
|
||||
|
||||
reply.send(host);
|
||||
}
|
||||
|
|
|
@ -62,13 +62,12 @@ 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, {
|
||||
url,
|
||||
host: `${config.core.secure ? 'https' : 'http'}://${req.hostname}${
|
||||
config.urls.route
|
||||
}/`
|
||||
});
|
||||
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
|
||||
}/`
|
||||
});
|
||||
|
||||
return reply.send(url);
|
||||
}
|
||||
|
@ -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,13 +104,12 @@ export class URLSController {
|
|||
);
|
||||
|
||||
this.logger.info(`saved url ${url.id}`);
|
||||
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
|
||||
}/`
|
||||
});
|
||||
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
|
||||
}/`
|
||||
});
|
||||
|
||||
return reply.send(url);
|
||||
}
|
||||
|
|
|
@ -80,10 +80,9 @@ 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, {
|
||||
user
|
||||
});
|
||||
if (this.webhooks.events.includes(WebhookType.USER_EDIT)) Webhooks.sendWebhook(this.webhooks.user_edit.content, {
|
||||
user
|
||||
});
|
||||
|
||||
delete user.password;
|
||||
return reply.send(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,10 +147,9 @@ 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, {
|
||||
user
|
||||
});
|
||||
if (this.webhooks.events.includes(WebhookType.LOGIN)) Webhooks.sendWebhook(this.webhooks.login.content, {
|
||||
user
|
||||
});
|
||||
|
||||
return reply.send(user);
|
||||
}
|
||||
|
@ -188,10 +184,9 @@ 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, {
|
||||
user
|
||||
});
|
||||
if (this.webhooks.events.includes(WebhookType.TOKEN_RESET)) Webhooks.sendWebhook(this.webhooks.token_reset.content, {
|
||||
user
|
||||
});
|
||||
|
||||
return reply.send({ updated: true });
|
||||
}
|
||||
|
@ -222,21 +217,19 @@ 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, {
|
||||
user
|
||||
});
|
||||
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(
|
||||
{
|
||||
id: 'zipline'
|
||||
},
|
||||
{
|
||||
first: false
|
||||
}
|
||||
);
|
||||
if (firstSetup) await this.instance.orm.getRepository(Zipline).update(
|
||||
{
|
||||
id: 'zipline'
|
||||
},
|
||||
{
|
||||
first: false
|
||||
}
|
||||
);
|
||||
|
||||
delete user.password;
|
||||
return reply.send(user);
|
||||
|
@ -266,10 +259,9 @@ 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, {
|
||||
user: existing
|
||||
});
|
||||
if (this.webhooks.events.includes(WebhookType.USER_DELETE)) Webhooks.sendWebhook(this.webhooks.user_delete.content, {
|
||||
user: existing
|
||||
});
|
||||
|
||||
return reply.send({ ok: true });
|
||||
} catch (e) {
|
||||
|
|
|
@ -219,7 +219,7 @@ export default function Users() {
|
|||
}
|
||||
title={`${u.username} (${u.id})`}
|
||||
subheader={`${u.administrator ? 'Administrator' : 'User'
|
||||
}`}
|
||||
}`}
|
||||
/>
|
||||
</Card>
|
||||
</Grid>
|
||||
|
|
|
@ -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>
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue