mirror of
https://github.com/kokonect-link/cherrypick
synced 2024-12-12 13:48:28 +09:00
Improve performance
This commit is contained in:
parent
253747ecfb
commit
93c0af613f
@ -232,7 +232,7 @@ class SigninContext extends Context {
|
|||||||
}
|
}
|
||||||
} else {
|
} else {
|
||||||
// Compare password
|
// Compare password
|
||||||
const same = bcrypt.compareSync(query, this.temporaryUser.password);
|
const same = await bcrypt.compare(query, this.temporaryUser.password);
|
||||||
|
|
||||||
if (same) {
|
if (same) {
|
||||||
this.bot.signin(this.temporaryUser);
|
this.bot.signin(this.temporaryUser);
|
||||||
|
@ -20,6 +20,7 @@ module.exports = (file, params, user) => new Promise(async (res, rej) => {
|
|||||||
return rej('file is required');
|
return rej('file is required');
|
||||||
}
|
}
|
||||||
|
|
||||||
|
// TODO: 非同期にしたい。Promise対応してないんだろうか...
|
||||||
const buffer = fs.readFileSync(file.path);
|
const buffer = fs.readFileSync(file.path);
|
||||||
fs.unlink(file.path, (err) => { if (err) console.log(err); });
|
fs.unlink(file.path, (err) => { if (err) console.log(err); });
|
||||||
|
|
||||||
|
@ -22,15 +22,15 @@ module.exports = async (params, user) => new Promise(async (res, rej) => {
|
|||||||
if (newPasswordErr) return rej('invalid new_password param');
|
if (newPasswordErr) return rej('invalid new_password param');
|
||||||
|
|
||||||
// Compare password
|
// Compare password
|
||||||
const same = bcrypt.compareSync(currentPassword, user.password);
|
const same = await bcrypt.compare(currentPassword, user.password);
|
||||||
|
|
||||||
if (!same) {
|
if (!same) {
|
||||||
return rej('incorrect password');
|
return rej('incorrect password');
|
||||||
}
|
}
|
||||||
|
|
||||||
// Generate hash of password
|
// Generate hash of password
|
||||||
const salt = bcrypt.genSaltSync(8);
|
const salt = await bcrypt.genSalt(8);
|
||||||
const hash = bcrypt.hashSync(newPassword, salt);
|
const hash = await bcrypt.hash(newPassword, salt);
|
||||||
|
|
||||||
await User.update(user._id, {
|
await User.update(user._id, {
|
||||||
$set: {
|
$set: {
|
||||||
|
@ -20,7 +20,7 @@ module.exports = async (params, user) => new Promise(async (res, rej) => {
|
|||||||
if (passwordErr) return rej('invalid password param');
|
if (passwordErr) return rej('invalid password param');
|
||||||
|
|
||||||
// Compare password
|
// Compare password
|
||||||
const same = bcrypt.compareSync(password, user.password);
|
const same = await bcrypt.compare(password, user.password);
|
||||||
|
|
||||||
if (!same) {
|
if (!same) {
|
||||||
return rej('incorrect password');
|
return rej('incorrect password');
|
||||||
|
@ -40,7 +40,7 @@ export default async (req: express.Request, res: express.Response) => {
|
|||||||
}
|
}
|
||||||
|
|
||||||
// Compare password
|
// Compare password
|
||||||
const same = bcrypt.compareSync(password, user.password);
|
const same = await bcrypt.compare(password, user.password);
|
||||||
|
|
||||||
if (same) {
|
if (same) {
|
||||||
const expires = 1000 * 60 * 60 * 24 * 365; // One Year
|
const expires = 1000 * 60 * 60 * 24 * 365; // One Year
|
||||||
|
@ -54,8 +54,8 @@ export default async (req: express.Request, res: express.Response) => {
|
|||||||
}
|
}
|
||||||
|
|
||||||
// Generate hash of password
|
// Generate hash of password
|
||||||
const salt = bcrypt.genSaltSync(8);
|
const salt = await bcrypt.genSalt(8);
|
||||||
const hash = bcrypt.hashSync(password, salt);
|
const hash = await bcrypt.hash(password, salt);
|
||||||
|
|
||||||
// Generate secret
|
// Generate secret
|
||||||
const secret = generateUserToken();
|
const secret = generateUserToken();
|
||||||
|
@ -33,11 +33,13 @@ app.get('/', (req, res) => {
|
|||||||
});
|
});
|
||||||
|
|
||||||
app.get('/default-avatar.jpg', (req, res) => {
|
app.get('/default-avatar.jpg', (req, res) => {
|
||||||
|
// TODO: 非同期にしたい。Promise対応してないんだろうか...
|
||||||
const file = fs.readFileSync(`${__dirname}/assets/avatar.jpg`);
|
const file = fs.readFileSync(`${__dirname}/assets/avatar.jpg`);
|
||||||
send(file, 'image/jpeg', req, res);
|
send(file, 'image/jpeg', req, res);
|
||||||
});
|
});
|
||||||
|
|
||||||
app.get('/app-default.jpg', (req, res) => {
|
app.get('/app-default.jpg', (req, res) => {
|
||||||
|
// TODO: 非同期にしたい。Promise対応してないんだろうか...
|
||||||
const file = fs.readFileSync(`${__dirname}/assets/dummy.png`);
|
const file = fs.readFileSync(`${__dirname}/assets/dummy.png`);
|
||||||
send(file, 'image/png', req, res);
|
send(file, 'image/png', req, res);
|
||||||
});
|
});
|
||||||
@ -54,6 +56,7 @@ async function raw(data: Buffer, type: string, download: boolean, res: express.R
|
|||||||
|
|
||||||
async function thumbnail(data: Buffer, type: string, resize: number, res: express.Response): Promise<any> {
|
async function thumbnail(data: Buffer, type: string, resize: number, res: express.Response): Promise<any> {
|
||||||
if (!/^image\/.*$/.test(type)) {
|
if (!/^image\/.*$/.test(type)) {
|
||||||
|
// TODO: 非同期にしたい。Promise対応してないんだろうか...
|
||||||
data = fs.readFileSync(`${__dirname}/assets/not-an-image.png`);
|
data = fs.readFileSync(`${__dirname}/assets/not-an-image.png`);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
Loading…
Reference in New Issue
Block a user