2017-03-08 20:50:09 +02:00
|
|
|
import $ from 'cafy';
|
2018-03-29 14:32:18 +03:00
|
|
|
import User from '../../../../models/user';
|
|
|
|
import { validateUsername } from '../../../../models/user';
|
2018-11-02 06:47:44 +02:00
|
|
|
import define from '../../define';
|
2018-11-02 05:49:08 +02:00
|
|
|
|
|
|
|
export const meta = {
|
|
|
|
requireCredential: false,
|
|
|
|
|
|
|
|
params: {
|
|
|
|
username: {
|
|
|
|
validator: $.str.pipe(validateUsername)
|
|
|
|
}
|
|
|
|
}
|
|
|
|
};
|
2016-12-29 00:49:51 +02:00
|
|
|
|
2018-11-02 06:47:44 +02:00
|
|
|
export default define(meta, (ps) => new Promise(async (res, rej) => {
|
2016-12-29 00:49:51 +02:00
|
|
|
// Get exist
|
|
|
|
const exist = await User
|
|
|
|
.count({
|
2018-03-27 10:51:12 +03:00
|
|
|
host: null,
|
2018-11-02 05:49:08 +02:00
|
|
|
usernameLower: ps.username.toLowerCase()
|
2016-12-29 00:49:51 +02:00
|
|
|
}, {
|
|
|
|
limit: 1
|
|
|
|
});
|
|
|
|
|
|
|
|
// Reply
|
|
|
|
res({
|
|
|
|
available: exist === 0
|
|
|
|
});
|
2018-11-02 06:47:44 +02:00
|
|
|
}));
|