Implement remote account resolution

This commit is contained in:
Akihiko Odaki
2018-03-27 16:51:12 +09:00
parent bee892d446
commit 68ce6d5748
73 changed files with 735 additions and 334 deletions

View File

@@ -39,6 +39,39 @@ export function isValidBirthday(birthday: string): boolean {
return typeof birthday == 'string' && /^([0-9]{4})\-([0-9]{2})-([0-9]{2})$/.test(birthday);
}
export type ILocalAccount = {
keypair: string;
email: string;
links: string[];
password: string;
token: string;
twitter: {
access_token: string;
access_token_secret: string;
user_id: string;
screen_name: string;
};
line: {
user_id: string;
};
profile: {
location: string;
birthday: string; // 'YYYY-MM-DD'
tags: string[];
};
last_used_at: Date;
is_bot: boolean;
is_pro: boolean;
two_factor_secret: string;
two_factor_enabled: boolean;
client_settings: any;
settings: any;
};
export type IRemoteAccount = {
uri: string;
};
export type IUser = {
_id: mongo.ObjectID;
created_at: Date;
@@ -60,34 +93,7 @@ export type IUser = {
keywords: string[];
host: string;
host_lower: string;
account: {
keypair: string;
email: string;
links: string[];
password: string;
token: string;
twitter: {
access_token: string;
access_token_secret: string;
user_id: string;
screen_name: string;
};
line: {
user_id: string;
};
profile: {
location: string;
birthday: string; // 'YYYY-MM-DD'
tags: string[];
};
last_used_at: Date;
is_bot: boolean;
is_pro: boolean;
two_factor_secret: string;
two_factor_enabled: boolean;
client_settings: any;
settings: any;
};
account: ILocalAccount | IRemoteAccount;
};
export function init(user): IUser {
@@ -162,28 +168,30 @@ export const pack = (
// Remove needless properties
delete _user.latest_post;
// Remove private properties
delete _user.account.keypair;
delete _user.account.password;
delete _user.account.token;
delete _user.account.two_factor_temp_secret;
delete _user.account.two_factor_secret;
delete _user.username_lower;
if (_user.account.twitter) {
delete _user.account.twitter.access_token;
delete _user.account.twitter.access_token_secret;
}
delete _user.account.line;
if (!_user.host) {
// Remove private properties
delete _user.account.keypair;
delete _user.account.password;
delete _user.account.token;
delete _user.account.two_factor_temp_secret;
delete _user.account.two_factor_secret;
delete _user.username_lower;
if (_user.account.twitter) {
delete _user.account.twitter.access_token;
delete _user.account.twitter.access_token_secret;
}
delete _user.account.line;
// Visible via only the official client
if (!opts.includeSecrets) {
delete _user.account.email;
delete _user.account.settings;
delete _user.account.client_settings;
}
// Visible via only the official client
if (!opts.includeSecrets) {
delete _user.account.email;
delete _user.account.settings;
delete _user.account.client_settings;
}
if (!opts.detail) {
delete _user.account.two_factor_enabled;
if (!opts.detail) {
delete _user.account.two_factor_enabled;
}
}
_user.avatar_url = _user.avatar_id != null