mirror of
https://github.com/diced/zipline.git
synced 2025-05-11 10:26:05 +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'],
|
'linebreak-style': ['error', 'unix'],
|
||||||
quotes: ['error', 'single'],
|
quotes: ['error', 'single'],
|
||||||
semi: ['error', 'always'],
|
semi: ['error', 'always'],
|
||||||
'comma-dangle': ['error', 'never']
|
'comma-dangle': ['error', 'never'],
|
||||||
|
'nonblock-statement-body-position': ['error', 'beside']
|
||||||
}
|
}
|
||||||
};
|
};
|
||||||
|
|
|
@ -40,6 +40,7 @@
|
||||||
"scripts": {
|
"scripts": {
|
||||||
"format": "prettier --write .",
|
"format": "prettier --write .",
|
||||||
"lint": "eslint .",
|
"lint": "eslint .",
|
||||||
|
"lint:fix": "eslint . --fix",
|
||||||
"dev": "ts-node src",
|
"dev": "ts-node src",
|
||||||
"dev:verbose": "VERBOSE=true ts-node src",
|
"dev:verbose": "VERBOSE=true ts-node src",
|
||||||
"build": "next build && tsc -p .",
|
"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';
|
const dev = process.env.NODE_ENV !== 'production';
|
||||||
|
|
||||||
(async () => {
|
(async () => {
|
||||||
if (await checkVersion())
|
if (await checkVersion()) Console.logger('Zipline').info(
|
||||||
Console.logger('Zipline').info(
|
'running an outdated version of zipline, please update soon!'
|
||||||
'running an outdated version of zipline, please update soon!'
|
);
|
||||||
);
|
|
||||||
})();
|
})();
|
||||||
|
|
||||||
console.log(`
|
console.log(`
|
||||||
|
@ -85,11 +84,10 @@ server.register(fastifyRateLimit, {
|
||||||
global: false
|
global: false
|
||||||
});
|
});
|
||||||
|
|
||||||
if (dev)
|
if (dev) server.get('/_next/*', async (req, reply) => {
|
||||||
server.get('/_next/*', async (req, reply) => {
|
await handle(req.raw, reply.raw);
|
||||||
await handle(req.raw, reply.raw);
|
return (reply.sent = true);
|
||||||
return (reply.sent = true);
|
});
|
||||||
});
|
|
||||||
|
|
||||||
server.all('/*', async (req, reply) => {
|
server.all('/*', async (req, reply) => {
|
||||||
await handle(req.raw, reply.raw);
|
await handle(req.raw, reply.raw);
|
||||||
|
|
|
@ -79,8 +79,7 @@ export class Configuration {
|
||||||
try {
|
try {
|
||||||
const data = readFileSync(resolve(process.cwd(), 'Zipline.toml'), 'utf8');
|
const data = readFileSync(resolve(process.cwd(), 'Zipline.toml'), 'utf8');
|
||||||
const parsed = parse(data);
|
const parsed = parse(data);
|
||||||
if (parsed.webhooks)
|
if (parsed.webhooks) parsed.webhooks.events = Webhooks.convert(parsed.webhooks.events);
|
||||||
parsed.webhooks.events = Webhooks.convert(parsed.webhooks.events);
|
|
||||||
return parsed;
|
return parsed;
|
||||||
} catch (e) {
|
} catch (e) {
|
||||||
return null;
|
return null;
|
||||||
|
|
|
@ -15,8 +15,7 @@ export function createRandomId(
|
||||||
charset = 'ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz0123456789'
|
charset = 'ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz0123456789'
|
||||||
) {
|
) {
|
||||||
let result = '';
|
let result = '';
|
||||||
for (let i = 0; i < length; i++)
|
for (let i = 0; i < length; i++) result += charset.charAt(Math.floor(Math.random() * charset.length));
|
||||||
result += charset.charAt(Math.floor(Math.random() * charset.length));
|
|
||||||
return result;
|
return result;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
|
@ -70,13 +70,12 @@ export class ImagesController {
|
||||||
unlinkSync(path);
|
unlinkSync(path);
|
||||||
|
|
||||||
Console.logger(Image).info(`image ${image.id} was deleted`);
|
Console.logger(Image).info(`image ${image.id} was deleted`);
|
||||||
if (this.webhooks.events.includes(WebhookType.DELETE_IMAGE))
|
if (this.webhooks.events.includes(WebhookType.DELETE_IMAGE)) Webhooks.sendWebhook(this.webhooks.upload.content, {
|
||||||
Webhooks.sendWebhook(this.webhooks.upload.content, {
|
image,
|
||||||
image,
|
host: `${config.core.secure ? 'https' : 'http'}://${req.hostname}${
|
||||||
host: `${config.core.secure ? 'https' : 'http'}://${req.hostname}${
|
config.uploader.route
|
||||||
config.uploader.route
|
}/`
|
||||||
}/`
|
});
|
||||||
});
|
|
||||||
|
|
||||||
return reply.send(image);
|
return reply.send(image);
|
||||||
} catch (e) {
|
} catch (e) {
|
||||||
|
|
|
@ -99,8 +99,7 @@ export class MultiFactorController {
|
||||||
}
|
}
|
||||||
});
|
});
|
||||||
|
|
||||||
if (!user)
|
if (!user) return sendError(reply, `User "${req.body.username}" was not found.`);
|
||||||
return sendError(reply, `User "${req.body.username}" was not found.`);
|
|
||||||
if (!checkPassword(req.body.password, user.password)) {
|
if (!checkPassword(req.body.password, user.password)) {
|
||||||
this.logger.error(
|
this.logger.error(
|
||||||
`${user.username} (${user.id}) tried to login but failed with mfa`
|
`${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`);
|
this.logger.info(`${user.username} (${user.id}) logged in with mfa`);
|
||||||
if (this.webhooks.events.includes(WebhookType.LOGIN))
|
if (this.webhooks.events.includes(WebhookType.LOGIN)) Webhooks.sendWebhook(this.webhooks.login.content, {
|
||||||
Webhooks.sendWebhook(this.webhooks.login.content, {
|
user
|
||||||
user
|
});
|
||||||
});
|
|
||||||
|
|
||||||
return reply.send({ user, passed });
|
return reply.send({ user, passed });
|
||||||
}
|
}
|
||||||
|
|
|
@ -109,8 +109,7 @@ export class RootController {
|
||||||
|
|
||||||
@POST('/upload', rateLimiterConfig)
|
@POST('/upload', rateLimiterConfig)
|
||||||
async loginStatus(req: FastifyRequest, reply: FastifyReply) {
|
async loginStatus(req: FastifyRequest, reply: FastifyReply) {
|
||||||
if (!req.headers.authorization)
|
if (!req.headers.authorization) return sendError(reply, 'No authorization header!');
|
||||||
return sendError(reply, 'No authorization header!');
|
|
||||||
|
|
||||||
const user = await this.users.findOne({
|
const user = await this.users.findOne({
|
||||||
where: {
|
where: {
|
||||||
|
@ -123,12 +122,10 @@ export class RootController {
|
||||||
//@ts-ignore stupid multipart types smh
|
//@ts-ignore stupid multipart types smh
|
||||||
const data: Multipart = await req.file();
|
const data: Multipart = await req.file();
|
||||||
|
|
||||||
if (!existsSync(config.uploader.directory))
|
if (!existsSync(config.uploader.directory)) mkdirSync(config.uploader.directory);
|
||||||
mkdirSync(config.uploader.directory);
|
|
||||||
|
|
||||||
const ext = data.filename.split('.')[1];
|
const ext = data.filename.split('.')[1];
|
||||||
if (config.uploader.blacklisted.includes(ext))
|
if (config.uploader.blacklisted.includes(ext)) return sendError(reply, 'Blacklisted file extension!');
|
||||||
return sendError(reply, 'Blacklisted file extension!');
|
|
||||||
|
|
||||||
const fileName = config.uploader.original
|
const fileName = config.uploader.original
|
||||||
? data.filename.split('.')[0]
|
? data.filename.split('.')[0]
|
||||||
|
@ -153,11 +150,10 @@ export class RootController {
|
||||||
: config.uploader.route
|
: config.uploader.route
|
||||||
}/${fileName}.${ext}`;
|
}/${fileName}.${ext}`;
|
||||||
|
|
||||||
if (this.webhooks.events.includes(WebhookType.UPLOAD))
|
if (this.webhooks.events.includes(WebhookType.UPLOAD)) Webhooks.sendWebhook(this.webhooks.upload.content, {
|
||||||
Webhooks.sendWebhook(this.webhooks.upload.content, {
|
image,
|
||||||
image,
|
host
|
||||||
host
|
});
|
||||||
});
|
|
||||||
|
|
||||||
reply.send(host);
|
reply.send(host);
|
||||||
}
|
}
|
||||||
|
|
|
@ -62,13 +62,12 @@ export class URLSController {
|
||||||
});
|
});
|
||||||
|
|
||||||
this.logger.info(`url ${url.id} was deleted`);
|
this.logger.info(`url ${url.id} was deleted`);
|
||||||
if (this.webhooks.events.includes(WebhookType.DELETE_URL))
|
if (this.webhooks.events.includes(WebhookType.DELETE_URL)) Webhooks.sendWebhook(this.webhooks.delete_url.content, {
|
||||||
Webhooks.sendWebhook(this.webhooks.delete_url.content, {
|
url,
|
||||||
url,
|
host: `${config.core.secure ? 'https' : 'http'}://${req.hostname}${
|
||||||
host: `${config.core.secure ? 'https' : 'http'}://${req.hostname}${
|
config.urls.route
|
||||||
config.urls.route
|
}/`
|
||||||
}/`
|
});
|
||||||
});
|
|
||||||
|
|
||||||
return reply.send(url);
|
return reply.send(url);
|
||||||
}
|
}
|
||||||
|
@ -86,8 +85,7 @@ export class URLSController {
|
||||||
vanity: req.body.vanity
|
vanity: req.body.vanity
|
||||||
}
|
}
|
||||||
});
|
});
|
||||||
if (existingVanity)
|
if (existingVanity) return sendError(reply, 'There is an existing vanity!');
|
||||||
return sendError(reply, 'There is an existing vanity!');
|
|
||||||
}
|
}
|
||||||
|
|
||||||
const user = await this.users.findOne({
|
const user = await this.users.findOne({
|
||||||
|
@ -106,13 +104,12 @@ export class URLSController {
|
||||||
);
|
);
|
||||||
|
|
||||||
this.logger.info(`saved url ${url.id}`);
|
this.logger.info(`saved url ${url.id}`);
|
||||||
if (this.webhooks.events.includes(WebhookType.SHORTEN))
|
if (this.webhooks.events.includes(WebhookType.SHORTEN)) Webhooks.sendWebhook(this.webhooks.shorten.content, {
|
||||||
Webhooks.sendWebhook(this.webhooks.shorten.content, {
|
url,
|
||||||
url,
|
host: `${config.core.secure ? 'https' : 'http'}://${req.hostname}${
|
||||||
host: `${config.core.secure ? 'https' : 'http'}://${req.hostname}${
|
config.urls.route
|
||||||
config.urls.route
|
}/`
|
||||||
}/`
|
});
|
||||||
});
|
|
||||||
|
|
||||||
return reply.send(url);
|
return reply.send(url);
|
||||||
}
|
}
|
||||||
|
|
|
@ -80,10 +80,9 @@ export class UserController {
|
||||||
await this.users.save(user);
|
await this.users.save(user);
|
||||||
|
|
||||||
this.logger.info(`saved ${user.username} (${user.id})`);
|
this.logger.info(`saved ${user.username} (${user.id})`);
|
||||||
if (this.webhooks.events.includes(WebhookType.USER_EDIT))
|
if (this.webhooks.events.includes(WebhookType.USER_EDIT)) Webhooks.sendWebhook(this.webhooks.user_edit.content, {
|
||||||
Webhooks.sendWebhook(this.webhooks.user_edit.content, {
|
user
|
||||||
user
|
});
|
||||||
});
|
|
||||||
|
|
||||||
delete user.password;
|
delete user.password;
|
||||||
return reply.send(user);
|
return reply.send(user);
|
||||||
|
@ -104,8 +103,7 @@ export class UserController {
|
||||||
}
|
}
|
||||||
});
|
});
|
||||||
|
|
||||||
if (!user)
|
if (!user) return sendError(reply, `User "${req.body.username}" was not found.`);
|
||||||
return sendError(reply, `User "${req.body.username}" was not found.`);
|
|
||||||
if (!checkPassword(req.body.password, user.password)) {
|
if (!checkPassword(req.body.password, user.password)) {
|
||||||
this.logger.error(
|
this.logger.error(
|
||||||
`${user.username} (${user.id}) tried to verify their credentials but failed`
|
`${user.username} (${user.id}) tried to verify their credentials but failed`
|
||||||
|
@ -133,8 +131,7 @@ export class UserController {
|
||||||
}
|
}
|
||||||
});
|
});
|
||||||
|
|
||||||
if (!user)
|
if (!user) return sendError(reply, `User "${req.body.username}" was not found.`);
|
||||||
return sendError(reply, `User "${req.body.username}" was not found.`);
|
|
||||||
if (!checkPassword(req.body.password, user.password)) {
|
if (!checkPassword(req.body.password, user.password)) {
|
||||||
this.logger.error(
|
this.logger.error(
|
||||||
`${user.username} (${user.id}) tried to login but failed`
|
`${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`);
|
this.logger.info(`${user.username} (${user.id}) logged in`);
|
||||||
if (this.webhooks.events.includes(WebhookType.LOGIN))
|
if (this.webhooks.events.includes(WebhookType.LOGIN)) Webhooks.sendWebhook(this.webhooks.login.content, {
|
||||||
Webhooks.sendWebhook(this.webhooks.login.content, {
|
user
|
||||||
user
|
});
|
||||||
});
|
|
||||||
|
|
||||||
return reply.send(user);
|
return reply.send(user);
|
||||||
}
|
}
|
||||||
|
@ -188,10 +184,9 @@ export class UserController {
|
||||||
await this.users.save(user);
|
await this.users.save(user);
|
||||||
|
|
||||||
this.logger.info(`reset token ${user.username} (${user.id})`);
|
this.logger.info(`reset token ${user.username} (${user.id})`);
|
||||||
if (this.webhooks.events.includes(WebhookType.TOKEN_RESET))
|
if (this.webhooks.events.includes(WebhookType.TOKEN_RESET)) Webhooks.sendWebhook(this.webhooks.token_reset.content, {
|
||||||
Webhooks.sendWebhook(this.webhooks.token_reset.content, {
|
user
|
||||||
user
|
});
|
||||||
});
|
|
||||||
|
|
||||||
return reply.send({ updated: true });
|
return reply.send({ updated: true });
|
||||||
}
|
}
|
||||||
|
@ -222,21 +217,19 @@ export class UserController {
|
||||||
)
|
)
|
||||||
);
|
);
|
||||||
this.logger.info(`created user ${user.username} (${user.id})`);
|
this.logger.info(`created user ${user.username} (${user.id})`);
|
||||||
if (this.webhooks.events.includes(WebhookType.CREATE_USER))
|
if (this.webhooks.events.includes(WebhookType.CREATE_USER)) Webhooks.sendWebhook(this.webhooks.create_user.content, {
|
||||||
Webhooks.sendWebhook(this.webhooks.create_user.content, {
|
user
|
||||||
user
|
});
|
||||||
});
|
|
||||||
|
|
||||||
const firstSetup = await getFirst(this.instance.orm);
|
const firstSetup = await getFirst(this.instance.orm);
|
||||||
if (firstSetup)
|
if (firstSetup) await this.instance.orm.getRepository(Zipline).update(
|
||||||
await this.instance.orm.getRepository(Zipline).update(
|
{
|
||||||
{
|
id: 'zipline'
|
||||||
id: 'zipline'
|
},
|
||||||
},
|
{
|
||||||
{
|
first: false
|
||||||
first: false
|
}
|
||||||
}
|
);
|
||||||
);
|
|
||||||
|
|
||||||
delete user.password;
|
delete user.password;
|
||||||
return reply.send(user);
|
return reply.send(user);
|
||||||
|
@ -266,10 +259,9 @@ export class UserController {
|
||||||
await this.users.remove(existing);
|
await this.users.remove(existing);
|
||||||
|
|
||||||
this.logger.info(`deleted ${existing.username} (${existing.id})`);
|
this.logger.info(`deleted ${existing.username} (${existing.id})`);
|
||||||
if (this.webhooks.events.includes(WebhookType.USER_DELETE))
|
if (this.webhooks.events.includes(WebhookType.USER_DELETE)) Webhooks.sendWebhook(this.webhooks.user_delete.content, {
|
||||||
Webhooks.sendWebhook(this.webhooks.user_delete.content, {
|
user: existing
|
||||||
user: existing
|
});
|
||||||
});
|
|
||||||
|
|
||||||
return reply.send({ ok: true });
|
return reply.send({ ok: true });
|
||||||
} catch (e) {
|
} catch (e) {
|
||||||
|
|
|
@ -219,7 +219,7 @@ export default function Users() {
|
||||||
}
|
}
|
||||||
title={`${u.username} (${u.id})`}
|
title={`${u.username} (${u.id})`}
|
||||||
subheader={`${u.administrator ? 'Administrator' : 'User'
|
subheader={`${u.administrator ? 'Administrator' : 'User'
|
||||||
}`}
|
}`}
|
||||||
/>
|
/>
|
||||||
</Card>
|
</Card>
|
||||||
</Grid>
|
</Grid>
|
||||||
|
|
|
@ -10,8 +10,7 @@ export default function Manage({ config }) {
|
||||||
const router = useRouter();
|
const router = useRouter();
|
||||||
const state = store.getState();
|
const state = store.getState();
|
||||||
|
|
||||||
if (typeof window !== 'undefined' && !state.loggedIn)
|
if (typeof window !== 'undefined' && !state.loggedIn) router.push('/user/login');
|
||||||
router.push('/user/login');
|
|
||||||
else {
|
else {
|
||||||
return (
|
return (
|
||||||
<UI>
|
<UI>
|
||||||
|
|
Loading…
Add table
Add a link
Reference in a new issue