Compare commits
16 Commits
11.0.0-alp
...
11.0.0-bet
Author | SHA1 | Date | |
---|---|---|---|
8e344f2deb | |||
c28f4ffb3f | |||
2a40240310 | |||
0e9fba9287 | |||
2e3dd2a30a | |||
dda5f6559d | |||
4152e59638 | |||
9d5a92bce6 | |||
30172b92e6 | |||
8468a9d4c7 | |||
626cfb61ac | |||
9603f3fa4f | |||
619a1b9e53 | |||
62e76ad588 | |||
236d72685d | |||
72a5f7b1e2 |
@ -1,7 +1,7 @@
|
||||
{
|
||||
"name": "misskey",
|
||||
"author": "syuilo <i@syuilo.com>",
|
||||
"version": "11.0.0-alpha.7",
|
||||
"version": "11.0.0-beta.2",
|
||||
"codename": "daybreak",
|
||||
"repository": {
|
||||
"type": "git",
|
||||
@ -258,7 +258,6 @@
|
||||
"vuex": "3.1.0",
|
||||
"vuex-persistedstate": "2.5.4",
|
||||
"web-push": "3.3.3",
|
||||
"webfinger.js": "2.7.0",
|
||||
"webpack": "4.28.4",
|
||||
"webpack-cli": "3.2.3",
|
||||
"websocket": "1.0.28",
|
||||
|
65
src/@types/webfinger.js.d.ts
vendored
65
src/@types/webfinger.js.d.ts
vendored
@ -1,65 +0,0 @@
|
||||
declare module 'webfinger.js' {
|
||||
interface IWebFingerConstructorConfig {
|
||||
tls_only?: boolean;
|
||||
webfist_fallback?: boolean;
|
||||
uri_fallback?: boolean;
|
||||
request_timeout?: number;
|
||||
}
|
||||
|
||||
type JRDProperties = { [type: string]: string };
|
||||
|
||||
interface IJRDLink {
|
||||
rel: string;
|
||||
type?: string;
|
||||
href?: string;
|
||||
template?: string;
|
||||
titles?: { [lang: string]: string };
|
||||
properties?: JRDProperties;
|
||||
}
|
||||
|
||||
interface IJRD {
|
||||
subject?: string;
|
||||
expires?: Date;
|
||||
aliases?: string[];
|
||||
properties?: JRDProperties;
|
||||
links?: IJRDLink[];
|
||||
}
|
||||
|
||||
interface IIDXLinks {
|
||||
'avatar': IJRDLink[];
|
||||
'remotestorage': IJRDLink[];
|
||||
'blog': IJRDLink[];
|
||||
'vcard': IJRDLink[];
|
||||
'updates': IJRDLink[];
|
||||
'share': IJRDLink[];
|
||||
'profile': IJRDLink[];
|
||||
'webfist': IJRDLink[];
|
||||
'camlistore': IJRDLink[];
|
||||
[type: string]: IJRDLink[];
|
||||
}
|
||||
|
||||
interface IIDXProperties {
|
||||
'name': string;
|
||||
[type: string]: string;
|
||||
}
|
||||
|
||||
interface IIDX {
|
||||
links: IIDXLinks;
|
||||
properties: IIDXProperties;
|
||||
}
|
||||
|
||||
interface ILookupCallbackResult {
|
||||
object: IJRD;
|
||||
json: string;
|
||||
idx: IIDX;
|
||||
}
|
||||
|
||||
type LookupCallback = (err: Error | string, result?: ILookupCallbackResult) => void;
|
||||
|
||||
export class WebFinger {
|
||||
constructor(config?: IWebFingerConstructorConfig);
|
||||
|
||||
public lookup(address: string, cb: LookupCallback): NodeJS.Timeout;
|
||||
public lookupLink(address: string, rel: string, cb: IJRDLink): void;
|
||||
}
|
||||
}
|
@ -7,7 +7,6 @@ import { URL } from 'url';
|
||||
import * as yaml from 'js-yaml';
|
||||
import { Source, Mixin } from './types';
|
||||
import * as pkg from '../../package.json';
|
||||
import { toPuny } from '../misc/convert-host';
|
||||
|
||||
/**
|
||||
* Path of configuration directory
|
||||
@ -26,14 +25,14 @@ export default function load() {
|
||||
|
||||
const mixin = {} as Mixin;
|
||||
|
||||
const url = validateUrl(config.url);
|
||||
const url = tryCreateUrl(config.url);
|
||||
|
||||
config.url = toPuny(normalizeUrl(config.url));
|
||||
config.url = url.origin;
|
||||
|
||||
config.port = config.port || parseInt(process.env.PORT, 10);
|
||||
|
||||
mixin.host = toPuny(url.host);
|
||||
mixin.hostname = toPuny(url.hostname);
|
||||
mixin.host = url.host;
|
||||
mixin.hostname = url.hostname;
|
||||
mixin.scheme = url.protocol.replace(/:$/, '');
|
||||
mixin.wsScheme = mixin.scheme.replace('http', 'ws');
|
||||
mixin.wsUrl = `${mixin.wsScheme}://${mixin.host}`;
|
||||
@ -54,14 +53,3 @@ function tryCreateUrl(url: string) {
|
||||
throw `url="${url}" is not a valid URL.`;
|
||||
}
|
||||
}
|
||||
|
||||
function validateUrl(url: string) {
|
||||
const result = tryCreateUrl(url);
|
||||
if (result.pathname.replace('/', '').length) throw `url="${url}" is not a valid URL, has a pathname.`;
|
||||
if (!url.includes(result.host)) throw `url="${url}" is not a valid URL, has an invalid hostname.`;
|
||||
return result;
|
||||
}
|
||||
|
||||
function normalizeUrl(url: string) {
|
||||
return url.endsWith('/') ? url.substr(0, url.length - 1) : url;
|
||||
}
|
||||
|
@ -36,10 +36,10 @@ import { Emoji } from '../models/entities/emoji';
|
||||
import { ReversiGame } from '../models/entities/games/reversi/game';
|
||||
import { ReversiMatching } from '../models/entities/games/reversi/matching';
|
||||
import { UserNotePining } from '../models/entities/user-note-pinings';
|
||||
import { UserServiceLinking } from '../models/entities/user-service-linking';
|
||||
import { Poll } from '../models/entities/poll';
|
||||
import { UserKeypair } from '../models/entities/user-keypair';
|
||||
import { UserPublickey } from '../models/entities/user-publickey';
|
||||
import { UserProfile } from '../models/entities/user-profile';
|
||||
|
||||
const sqlLogger = dbLogger.createSubLogger('sql', 'white', false);
|
||||
|
||||
@ -101,12 +101,12 @@ export function initDb(justBorrow = false, sync = false, log = false) {
|
||||
AuthSession,
|
||||
AccessToken,
|
||||
User,
|
||||
UserProfile,
|
||||
UserKeypair,
|
||||
UserPublickey,
|
||||
UserList,
|
||||
UserListJoining,
|
||||
UserNotePining,
|
||||
UserServiceLinking,
|
||||
Following,
|
||||
FollowRequest,
|
||||
Muting,
|
||||
|
@ -26,6 +26,7 @@ import { UserKeypair } from './models/entities/user-keypair';
|
||||
import { extractPublic } from './crypto_key';
|
||||
import { Emoji } from './models/entities/emoji';
|
||||
import { toPuny } from './misc/convert-host';
|
||||
import { UserProfile } from './models/entities/user-profile';
|
||||
|
||||
const u = (config as any).mongodb.user ? encodeURIComponent((config as any).mongodb.user) : null;
|
||||
const p = (config as any).mongodb.pass ? encodeURIComponent((config as any).mongodb.pass) : null;
|
||||
@ -70,6 +71,7 @@ const getDriveFileBucket = async (): Promise<mongo.GridFSBucket> => {
|
||||
async function main() {
|
||||
await initDb();
|
||||
const Users = getRepository(User);
|
||||
const UserProfiles = getRepository(UserProfile);
|
||||
const DriveFiles = getRepository(DriveFile);
|
||||
const DriveFolders = getRepository(DriveFolder);
|
||||
const Notes = getRepository(Note);
|
||||
@ -90,17 +92,11 @@ async function main() {
|
||||
usernameLower: user.username.toLowerCase(),
|
||||
host: toPuny(user.host),
|
||||
token: generateUserToken(),
|
||||
password: user.password,
|
||||
isAdmin: user.isAdmin,
|
||||
autoAcceptFollowed: true,
|
||||
autoWatch: false,
|
||||
name: user.name,
|
||||
location: user.profile ? user.profile.location : null,
|
||||
birthday: user.profile ? user.profile.birthday : null,
|
||||
followersCount: user.followersCount,
|
||||
followingCount: user.followingCount,
|
||||
notesCount: user.notesCount,
|
||||
description: user.description,
|
||||
isBot: user.isBot,
|
||||
isCat: user.isCat,
|
||||
isVerified: user.isVerified,
|
||||
@ -108,9 +104,18 @@ async function main() {
|
||||
sharedInbox: user.sharedInbox,
|
||||
uri: user.uri,
|
||||
});
|
||||
await UserProfiles.save({
|
||||
userId: user._id.toHexString(),
|
||||
description: user.description,
|
||||
userHost: toPuny(user.host),
|
||||
autoAcceptFollowed: true,
|
||||
autoWatch: false,
|
||||
password: user.password,
|
||||
location: user.profile ? user.profile.location : null,
|
||||
birthday: user.profile ? user.profile.birthday : null,
|
||||
});
|
||||
if (user.publicKey) {
|
||||
await UserPublickeys.save({
|
||||
id: genId(),
|
||||
userId: user._id.toHexString(),
|
||||
keyId: user.publicKey.id,
|
||||
keyPem: user.publicKey.publicKeyPem
|
||||
@ -118,7 +123,6 @@ async function main() {
|
||||
}
|
||||
if (user.keypair) {
|
||||
await UserKeypairs.save({
|
||||
id: genId(),
|
||||
userId: user._id.toHexString(),
|
||||
publicKey: extractPublic(user.keypair),
|
||||
privateKey: user.keypair,
|
||||
|
@ -1,19 +0,0 @@
|
||||
import getAcct from './acct/render';
|
||||
import getUserName from './get-user-name';
|
||||
import { User } from '../models/entities/user';
|
||||
import { Users } from '../models';
|
||||
|
||||
/**
|
||||
* ユーザーを表す文字列を取得します。
|
||||
* @param user ユーザー
|
||||
*/
|
||||
export default function(user: User): string {
|
||||
let string = `${getUserName(user)} (@${getAcct(user)})\n` +
|
||||
`${user.notesCount}投稿、${user.followingCount}フォロー、${user.followersCount}フォロワー\n`;
|
||||
|
||||
if (Users.isLocalUser(user)) {
|
||||
string += `場所: ${user.location}、誕生日: ${user.birthday}\n`;
|
||||
}
|
||||
|
||||
return string + `「${user.description}」`;
|
||||
}
|
@ -6,10 +6,6 @@ import { User } from './user';
|
||||
@Entity()
|
||||
export class Poll {
|
||||
@PrimaryColumn(id())
|
||||
public id: string;
|
||||
|
||||
@Index({ unique: true })
|
||||
@Column(id())
|
||||
public noteId: Note['id'];
|
||||
|
||||
@OneToOne(type => Note, {
|
||||
|
@ -1,14 +1,10 @@
|
||||
import { PrimaryColumn, Entity, Index, JoinColumn, Column, OneToOne } from 'typeorm';
|
||||
import { PrimaryColumn, Entity, JoinColumn, Column, OneToOne } from 'typeorm';
|
||||
import { User } from './user';
|
||||
import { id } from '../id';
|
||||
|
||||
@Entity()
|
||||
export class UserKeypair {
|
||||
@PrimaryColumn(id())
|
||||
public id: string;
|
||||
|
||||
@Index({ unique: true })
|
||||
@Column(id())
|
||||
public userId: User['id'];
|
||||
|
||||
@OneToOne(type => User, {
|
||||
|
@ -1,14 +1,10 @@
|
||||
import { PrimaryColumn, Entity, Index, JoinColumn, Column, OneToOne } from 'typeorm';
|
||||
import { User } from './user';
|
||||
import { Entity, Column, Index, OneToOne, JoinColumn, PrimaryColumn } from 'typeorm';
|
||||
import { id } from '../id';
|
||||
import { User } from './user';
|
||||
|
||||
@Entity()
|
||||
export class UserServiceLinking {
|
||||
export class UserProfile {
|
||||
@PrimaryColumn(id())
|
||||
public id: string;
|
||||
|
||||
@Index({ unique: true })
|
||||
@Column(id())
|
||||
public userId: User['id'];
|
||||
|
||||
@OneToOne(type => User, {
|
||||
@ -17,6 +13,96 @@ export class UserServiceLinking {
|
||||
@JoinColumn()
|
||||
public user: User | null;
|
||||
|
||||
@Column('varchar', {
|
||||
length: 128, nullable: true,
|
||||
comment: 'The location of the User.'
|
||||
})
|
||||
public location: string | null;
|
||||
|
||||
@Column('char', {
|
||||
length: 10, nullable: true,
|
||||
comment: 'The birthday (YYYY-MM-DD) of the User.'
|
||||
})
|
||||
public birthday: string | null;
|
||||
|
||||
@Column('varchar', {
|
||||
length: 1024, nullable: true,
|
||||
comment: 'The description (bio) of the User.'
|
||||
})
|
||||
public description: string | null;
|
||||
|
||||
@Column('jsonb', {
|
||||
default: [],
|
||||
})
|
||||
public fields: {
|
||||
name: string;
|
||||
value: string;
|
||||
}[];
|
||||
|
||||
@Column('varchar', {
|
||||
length: 128, nullable: true,
|
||||
comment: 'The email address of the User.'
|
||||
})
|
||||
public email: string | null;
|
||||
|
||||
@Column('varchar', {
|
||||
length: 128, nullable: true,
|
||||
})
|
||||
public emailVerifyCode: string | null;
|
||||
|
||||
@Column('boolean', {
|
||||
default: false,
|
||||
})
|
||||
public emailVerified: boolean;
|
||||
|
||||
@Column('varchar', {
|
||||
length: 128, nullable: true,
|
||||
})
|
||||
public twoFactorTempSecret: string | null;
|
||||
|
||||
@Column('varchar', {
|
||||
length: 128, nullable: true,
|
||||
})
|
||||
public twoFactorSecret: string | null;
|
||||
|
||||
@Column('boolean', {
|
||||
default: false,
|
||||
})
|
||||
public twoFactorEnabled: boolean;
|
||||
|
||||
@Column('varchar', {
|
||||
length: 128, nullable: true,
|
||||
comment: 'The password hash of the User. It will be null if the origin of the user is local.'
|
||||
})
|
||||
public password: string | null;
|
||||
|
||||
@Column('jsonb', {
|
||||
default: {},
|
||||
comment: 'The client-specific data of the User.'
|
||||
})
|
||||
public clientData: Record<string, any>;
|
||||
|
||||
@Column('boolean', {
|
||||
default: false,
|
||||
})
|
||||
public autoWatch: boolean;
|
||||
|
||||
@Column('boolean', {
|
||||
default: false,
|
||||
})
|
||||
public autoAcceptFollowed: boolean;
|
||||
|
||||
@Column('boolean', {
|
||||
default: false,
|
||||
})
|
||||
public alwaysMarkNsfw: boolean;
|
||||
|
||||
@Column('boolean', {
|
||||
default: false,
|
||||
})
|
||||
public carefulBot: boolean;
|
||||
|
||||
//#region Linking
|
||||
@Column('boolean', {
|
||||
default: false,
|
||||
})
|
||||
@ -96,6 +182,7 @@ export class UserServiceLinking {
|
||||
length: 64, nullable: true, default: null,
|
||||
})
|
||||
public discordDiscriminator: string | null;
|
||||
//#endregion
|
||||
|
||||
//#region Denormalized fields
|
||||
@Index()
|
@ -5,10 +5,6 @@ import { id } from '../id';
|
||||
@Entity()
|
||||
export class UserPublickey {
|
||||
@PrimaryColumn(id())
|
||||
public id: string;
|
||||
|
||||
@Index({ unique: true })
|
||||
@Column(id())
|
||||
public userId: User['id'];
|
||||
|
||||
@OneToOne(type => User, {
|
||||
|
@ -45,18 +45,6 @@ export class User {
|
||||
})
|
||||
public name: string | null;
|
||||
|
||||
@Column('varchar', {
|
||||
length: 128, nullable: true,
|
||||
comment: 'The location of the User.'
|
||||
})
|
||||
public location: string | null;
|
||||
|
||||
@Column('char', {
|
||||
length: 10, nullable: true,
|
||||
comment: 'The birthday (YYYY-MM-DD) of the User.'
|
||||
})
|
||||
public birthday: string | null;
|
||||
|
||||
@Column('integer', {
|
||||
default: 0,
|
||||
comment: 'The count of followers.'
|
||||
@ -101,44 +89,12 @@ export class User {
|
||||
@JoinColumn()
|
||||
public banner: DriveFile | null;
|
||||
|
||||
@Column('varchar', {
|
||||
length: 1024, nullable: true,
|
||||
comment: 'The description (bio) of the User.'
|
||||
})
|
||||
public description: string | null;
|
||||
|
||||
@Index()
|
||||
@Column('varchar', {
|
||||
length: 128, array: true, default: '{}'
|
||||
})
|
||||
public tags: string[];
|
||||
|
||||
@Column('varchar', {
|
||||
length: 128, nullable: true,
|
||||
comment: 'The email address of the User.'
|
||||
})
|
||||
public email: string | null;
|
||||
|
||||
@Column('varchar', {
|
||||
length: 128, nullable: true,
|
||||
})
|
||||
public emailVerifyCode: string | null;
|
||||
|
||||
@Column('boolean', {
|
||||
default: false,
|
||||
})
|
||||
public emailVerified: boolean;
|
||||
|
||||
@Column('varchar', {
|
||||
length: 128, nullable: true,
|
||||
})
|
||||
public twoFactorTempSecret: string | null;
|
||||
|
||||
@Column('varchar', {
|
||||
length: 128, nullable: true,
|
||||
})
|
||||
public twoFactorSecret: string | null;
|
||||
|
||||
@Column('varchar', {
|
||||
length: 256, nullable: true,
|
||||
})
|
||||
@ -206,11 +162,6 @@ export class User {
|
||||
})
|
||||
public isVerified: boolean;
|
||||
|
||||
@Column('boolean', {
|
||||
default: false,
|
||||
})
|
||||
public twoFactorEnabled: boolean;
|
||||
|
||||
@Column('varchar', {
|
||||
length: 128, array: true, default: '{}'
|
||||
})
|
||||
@ -248,44 +199,12 @@ export class User {
|
||||
})
|
||||
public uri: string | null;
|
||||
|
||||
@Column('varchar', {
|
||||
length: 128, nullable: true,
|
||||
comment: 'The password hash of the User. It will be null if the origin of the user is local.'
|
||||
})
|
||||
public password: string | null;
|
||||
|
||||
@Index({ unique: true })
|
||||
@Column('char', {
|
||||
length: 16, nullable: true, unique: true,
|
||||
comment: 'The native access token of the User. It will be null if the origin of the user is local.'
|
||||
})
|
||||
public token: string | null;
|
||||
|
||||
@Column('jsonb', {
|
||||
default: {},
|
||||
comment: 'The client-specific data of the User.'
|
||||
})
|
||||
public clientData: Record<string, any>;
|
||||
|
||||
@Column('boolean', {
|
||||
default: false,
|
||||
})
|
||||
public autoWatch: boolean;
|
||||
|
||||
@Column('boolean', {
|
||||
default: false,
|
||||
})
|
||||
public autoAcceptFollowed: boolean;
|
||||
|
||||
@Column('boolean', {
|
||||
default: false,
|
||||
})
|
||||
public alwaysMarkNsfw: boolean;
|
||||
|
||||
@Column('boolean', {
|
||||
default: false,
|
||||
})
|
||||
public carefulBot: boolean;
|
||||
}
|
||||
|
||||
export interface ILocalUser extends User {
|
||||
|
@ -25,7 +25,6 @@ import { FollowRequestRepository } from './repositories/follow-request';
|
||||
import { MutingRepository } from './repositories/muting';
|
||||
import { BlockingRepository } from './repositories/blocking';
|
||||
import { NoteReactionRepository } from './repositories/note-reaction';
|
||||
import { UserServiceLinking } from './entities/user-service-linking';
|
||||
import { NotificationRepository } from './repositories/notification';
|
||||
import { NoteFavoriteRepository } from './repositories/note-favorite';
|
||||
import { ReversiMatchingRepository } from './repositories/games/reversi/matching';
|
||||
@ -35,6 +34,7 @@ import { AppRepository } from './repositories/app';
|
||||
import { FollowingRepository } from './repositories/following';
|
||||
import { AbuseUserReportRepository } from './repositories/abuse-user-report';
|
||||
import { AuthSessionRepository } from './repositories/auth-session';
|
||||
import { UserProfile } from './entities/user-profile';
|
||||
|
||||
export const Apps = getCustomRepository(AppRepository);
|
||||
export const Notes = getCustomRepository(NoteRepository);
|
||||
@ -45,12 +45,12 @@ export const NoteUnreads = getRepository(NoteUnread);
|
||||
export const Polls = getRepository(Poll);
|
||||
export const PollVotes = getRepository(PollVote);
|
||||
export const Users = getCustomRepository(UserRepository);
|
||||
export const UserProfiles = getRepository(UserProfile);
|
||||
export const UserKeypairs = getRepository(UserKeypair);
|
||||
export const UserPublickeys = getRepository(UserPublickey);
|
||||
export const UserLists = getCustomRepository(UserListRepository);
|
||||
export const UserListJoinings = getRepository(UserListJoining);
|
||||
export const UserNotePinings = getRepository(UserNotePining);
|
||||
export const UserServiceLinkings = getRepository(UserServiceLinking);
|
||||
export const Followings = getCustomRepository(FollowingRepository);
|
||||
export const FollowRequests = getCustomRepository(FollowRequestRepository);
|
||||
export const Instances = getRepository(Instance);
|
||||
|
@ -3,6 +3,7 @@ import { DriveFile } from '../entities/drive-file';
|
||||
import { Users, DriveFolders } from '..';
|
||||
import rap from '@prezzemolo/rap';
|
||||
import { User } from '../entities/user';
|
||||
import { toPuny } from '../../misc/convert-host';
|
||||
|
||||
@EntityRepository(DriveFile)
|
||||
export class DriveFileRepository extends Repository<DriveFile> {
|
||||
@ -39,7 +40,7 @@ export class DriveFileRepository extends Repository<DriveFile> {
|
||||
public async clacDriveUsageOfHost(host: string): Promise<number> {
|
||||
const { sum } = await this
|
||||
.createQueryBuilder('file')
|
||||
.where('file.userHost = :host', { host: host })
|
||||
.where('file.userHost = :host', { host: toPuny(host) })
|
||||
.select('SUM(file.size)', 'sum')
|
||||
.getRawOne();
|
||||
|
||||
|
@ -1,6 +1,6 @@
|
||||
import { EntityRepository, Repository, In } from 'typeorm';
|
||||
import { User, ILocalUser, IRemoteUser } from '../entities/user';
|
||||
import { Emojis, Notes, NoteUnreads, FollowRequests, Notifications, MessagingMessages, UserNotePinings, Followings, Blockings, Mutings } from '..';
|
||||
import { Emojis, Notes, NoteUnreads, FollowRequests, Notifications, MessagingMessages, UserNotePinings, Followings, Blockings, Mutings, UserProfiles } from '..';
|
||||
import rap from '@prezzemolo/rap';
|
||||
|
||||
@EntityRepository(User)
|
||||
@ -80,6 +80,7 @@ export class UserRepository extends Repository<User> {
|
||||
|
||||
const relation = meId && (meId !== user.id) && opts.detail ? await this.getRelation(meId, user.id) : null;
|
||||
const pins = opts.detail ? await UserNotePinings.find({ userId: user.id }) : [];
|
||||
const profile = opts.detail ? await UserProfiles.findOne({ userId: user.id }) : null;
|
||||
|
||||
return await rap({
|
||||
id: user.id,
|
||||
@ -116,9 +117,9 @@ export class UserRepository extends Repository<User> {
|
||||
} : {}),
|
||||
|
||||
...(opts.detail ? {
|
||||
description: user.description,
|
||||
location: user.location,
|
||||
birthday: user.birthday,
|
||||
description: profile.description,
|
||||
location: profile.location,
|
||||
birthday: profile.birthday,
|
||||
followersCount: user.followersCount,
|
||||
followingCount: user.followingCount,
|
||||
notesCount: user.notesCount,
|
||||
@ -131,9 +132,9 @@ export class UserRepository extends Repository<User> {
|
||||
...(opts.detail && meId === user.id ? {
|
||||
avatarId: user.avatarId,
|
||||
bannerId: user.bannerId,
|
||||
autoWatch: user.autoWatch,
|
||||
alwaysMarkNsfw: user.alwaysMarkNsfw,
|
||||
carefulBot: user.carefulBot,
|
||||
autoWatch: profile.autoWatch,
|
||||
alwaysMarkNsfw: profile.alwaysMarkNsfw,
|
||||
carefulBot: profile.carefulBot,
|
||||
hasUnreadMessagingMessage: MessagingMessages.count({
|
||||
where: {
|
||||
recipientId: user.id,
|
||||
@ -153,6 +154,12 @@ export class UserRepository extends Repository<User> {
|
||||
}),
|
||||
} : {}),
|
||||
|
||||
...(opts.includeSecrets ? {
|
||||
clientData: profile.clientData,
|
||||
email: profile.email,
|
||||
emailVerified: profile.emailVerified,
|
||||
} : {}),
|
||||
|
||||
...(relation ? {
|
||||
isFollowing: relation.isFollowing,
|
||||
isFollowed: relation.isFollowed,
|
||||
|
@ -4,7 +4,6 @@ import parseAcct from '../../misc/acct/parse';
|
||||
import { IRemoteUser } from '../../models/entities/user';
|
||||
import perform from '../../remote/activitypub/perform';
|
||||
import { resolvePerson, updatePerson } from '../../remote/activitypub/models/person';
|
||||
import { toUnicode } from 'punycode';
|
||||
import { URL } from 'url';
|
||||
import { publishApLogStream } from '../../services/stream';
|
||||
import Logger from '../../services/logger';
|
||||
@ -13,6 +12,7 @@ import { Instances, Users, UserPublickeys } from '../../models';
|
||||
import { instanceChart } from '../../services/chart';
|
||||
import { UserPublickey } from '../../models/entities/user-publickey';
|
||||
import fetchMeta from '../../misc/fetch-meta';
|
||||
import { toPuny } from '../../misc/convert-host';
|
||||
|
||||
const logger = new Logger('inbox');
|
||||
|
||||
@ -33,7 +33,10 @@ export default async (job: Bull.Job): Promise<void> => {
|
||||
let key: UserPublickey;
|
||||
|
||||
if (keyIdLower.startsWith('acct:')) {
|
||||
const { username, host } = parseAcct(keyIdLower.slice('acct:'.length));
|
||||
const acct = parseAcct(keyIdLower.slice('acct:'.length));
|
||||
const host = toPuny(acct.host);
|
||||
const username = toPuny(acct.username);
|
||||
|
||||
if (host === null) {
|
||||
logger.warn(`request was made by local user: @${username}`);
|
||||
return;
|
||||
@ -50,19 +53,22 @@ export default async (job: Bull.Job): Promise<void> => {
|
||||
// ブロックしてたら中断
|
||||
// TODO: いちいちデータベースにアクセスするのはコスト高そうなのでどっかにキャッシュしておく
|
||||
const meta = await fetchMeta();
|
||||
if (meta.blockedHosts.includes(host.toLowerCase())) {
|
||||
if (meta.blockedHosts.includes(host)) {
|
||||
logger.info(`Blocked request: ${host}`);
|
||||
return;
|
||||
}
|
||||
|
||||
user = await Users.findOne({ usernameLower: username, host: host.toLowerCase() }) as IRemoteUser;
|
||||
user = await Users.findOne({
|
||||
usernameLower: username.toLowerCase(),
|
||||
host: host
|
||||
}) as IRemoteUser;
|
||||
|
||||
key = await UserPublickeys.findOne({
|
||||
userId: user.id
|
||||
});
|
||||
} else {
|
||||
// アクティビティ内のホストの検証
|
||||
const host = toUnicode(new URL(signature.keyId).hostname.toLowerCase());
|
||||
const host = toPuny(new URL(signature.keyId).hostname);
|
||||
try {
|
||||
ValidateActivity(activity, host);
|
||||
} catch (e) {
|
||||
@ -73,7 +79,7 @@ export default async (job: Bull.Job): Promise<void> => {
|
||||
// ブロックしてたら中断
|
||||
// TODO: いちいちデータベースにアクセスするのはコスト高そうなのでどっかにキャッシュしておく
|
||||
const meta = await fetchMeta();
|
||||
if (meta.blockedHosts.includes(host.toLowerCase())) {
|
||||
if (meta.blockedHosts.includes(host)) {
|
||||
logger.info(`Blocked request: ${host}`);
|
||||
return;
|
||||
}
|
||||
@ -145,7 +151,7 @@ export default async (job: Bull.Job): Promise<void> => {
|
||||
function ValidateActivity(activity: any, host: string) {
|
||||
// id (if exists)
|
||||
if (typeof activity.id === 'string') {
|
||||
const uriHost = toUnicode(new URL(activity.id).hostname.toLowerCase());
|
||||
const uriHost = toPuny(new URL(activity.id).hostname);
|
||||
if (host !== uriHost) {
|
||||
const diag = activity.signature ? '. Has LD-Signature. Forwarded?' : '';
|
||||
throw new Error(`activity.id(${activity.id}) has different host(${host})${diag}`);
|
||||
@ -154,7 +160,7 @@ function ValidateActivity(activity: any, host: string) {
|
||||
|
||||
// actor (if exists)
|
||||
if (typeof activity.actor === 'string') {
|
||||
const uriHost = toUnicode(new URL(activity.actor).hostname.toLowerCase());
|
||||
const uriHost = toPuny(new URL(activity.actor).hostname);
|
||||
if (host !== uriHost) throw new Error('activity.actor has different host');
|
||||
}
|
||||
|
||||
@ -162,13 +168,13 @@ function ValidateActivity(activity: any, host: string) {
|
||||
if (activity.type === 'Create' && activity.object) {
|
||||
// object.id (if exists)
|
||||
if (typeof activity.object.id === 'string') {
|
||||
const uriHost = toUnicode(new URL(activity.object.id).hostname.toLowerCase());
|
||||
const uriHost = toPuny(new URL(activity.object.id).hostname);
|
||||
if (host !== uriHost) throw new Error('activity.object.id has different host');
|
||||
}
|
||||
|
||||
// object.attributedTo (if exists)
|
||||
if (typeof activity.object.attributedTo === 'string') {
|
||||
const uriHost = toUnicode(new URL(activity.object.attributedTo).hostname.toLowerCase());
|
||||
const uriHost = toPuny(new URL(activity.object.attributedTo).hostname);
|
||||
if (host !== uriHost) throw new Error('activity.object.attributedTo has different host');
|
||||
}
|
||||
}
|
||||
|
@ -8,14 +8,13 @@ import { resolveImage } from './image';
|
||||
import { IRemoteUser, User } from '../../../models/entities/user';
|
||||
import { fromHtml } from '../../../mfm/fromHtml';
|
||||
import { ITag, extractHashtags } from './tag';
|
||||
import { toUnicode } from 'punycode';
|
||||
import { unique, concat, difference } from '../../../prelude/array';
|
||||
import { extractPollFromQuestion } from './question';
|
||||
import vote from '../../../services/note/polls/vote';
|
||||
import { apLogger } from '../logger';
|
||||
import { DriveFile } from '../../../models/entities/drive-file';
|
||||
import { deliverQuestionUpdate } from '../../../services/note/polls/update';
|
||||
import { extractDbHost } from '../../../misc/convert-host';
|
||||
import { extractDbHost, toPuny } from '../../../misc/convert-host';
|
||||
import { Notes, Emojis, Polls } from '../../../models';
|
||||
import { Note } from '../../../models/entities/note';
|
||||
import { IObject, INote } from '../type';
|
||||
@ -246,8 +245,8 @@ export async function resolveNote(value: string | IObject, resolver?: Resolver):
|
||||
return await createNote(uri, resolver);
|
||||
}
|
||||
|
||||
export async function extractEmojis(tags: ITag[], host_: string) {
|
||||
const host = toUnicode(host_.toLowerCase());
|
||||
export async function extractEmojis(tags: ITag[], host: string) {
|
||||
host = toPuny(host);
|
||||
|
||||
if (!tags) return [];
|
||||
|
||||
|
@ -1,5 +1,4 @@
|
||||
import * as promiseLimit from 'promise-limit';
|
||||
import { toUnicode } from 'punycode';
|
||||
|
||||
import config from '../../../config';
|
||||
import Resolver from '../resolver';
|
||||
@ -15,16 +14,16 @@ import { IIdentifier } from './identifier';
|
||||
import { apLogger } from '../logger';
|
||||
import { Note } from '../../../models/entities/note';
|
||||
import { updateHashtag } from '../../../services/update-hashtag';
|
||||
import { Users, UserNotePinings, Instances, DriveFiles, Followings, UserServiceLinkings, UserPublickeys } from '../../../models';
|
||||
import { Users, UserNotePinings, Instances, DriveFiles, Followings, UserProfiles, UserPublickeys } from '../../../models';
|
||||
import { User, IRemoteUser } from '../../../models/entities/user';
|
||||
import { Emoji } from '../../../models/entities/emoji';
|
||||
import { UserNotePining } from '../../../models/entities/user-note-pinings';
|
||||
import { genId } from '../../../misc/gen-id';
|
||||
import { UserServiceLinking } from '../../../models/entities/user-service-linking';
|
||||
import { instanceChart, usersChart } from '../../../services/chart';
|
||||
import { UserPublickey } from '../../../models/entities/user-publickey';
|
||||
import { isDuplicateKeyValueError } from '../../../misc/is-duplicate-key-value-error';
|
||||
import { toPuny } from '../../../misc/convert-host';
|
||||
import { UserProfile } from '../../../models/entities/user-profile';
|
||||
const logger = apLogger;
|
||||
|
||||
/**
|
||||
@ -33,7 +32,7 @@ const logger = apLogger;
|
||||
* @param uri Fetch target URI
|
||||
*/
|
||||
function validatePerson(x: any, uri: string) {
|
||||
const expectHost = toUnicode(new URL(uri).hostname.toLowerCase());
|
||||
const expectHost = toPuny(new URL(uri).hostname);
|
||||
|
||||
if (x == null) {
|
||||
return new Error('invalid person: object is null');
|
||||
@ -63,7 +62,7 @@ function validatePerson(x: any, uri: string) {
|
||||
return new Error('invalid person: id is not a string');
|
||||
}
|
||||
|
||||
const idHost = toUnicode(new URL(x.id).hostname.toLowerCase());
|
||||
const idHost = toPuny(new URL(x.id).hostname);
|
||||
if (idHost !== expectHost) {
|
||||
return new Error('invalid person: id has different host');
|
||||
}
|
||||
@ -72,7 +71,7 @@ function validatePerson(x: any, uri: string) {
|
||||
return new Error('invalid person: publicKey.id is not a string');
|
||||
}
|
||||
|
||||
const publicKeyIdHost = toUnicode(new URL(x.publicKey.id).hostname.toLowerCase());
|
||||
const publicKeyIdHost = toPuny(new URL(x.publicKey.id).hostname);
|
||||
if (publicKeyIdHost !== expectHost) {
|
||||
return new Error('invalid person: publicKey.id has different host');
|
||||
}
|
||||
@ -127,7 +126,7 @@ export async function createPerson(uri: string, resolver?: Resolver): Promise<Us
|
||||
|
||||
const host = toPuny(new URL(object.id).hostname);
|
||||
|
||||
const { fields, services } = analyzeAttachments(person.attachment);
|
||||
const { fields } = analyzeAttachments(person.attachment);
|
||||
|
||||
const tags = extractHashtags(person.tag).map(tag => tag.toLowerCase());
|
||||
|
||||
@ -142,7 +141,6 @@ export async function createPerson(uri: string, resolver?: Resolver): Promise<Us
|
||||
bannerId: null,
|
||||
createdAt: Date.parse(person.published) || new Date(),
|
||||
lastFetchedAt: new Date(),
|
||||
description: fromHtml(person.summary),
|
||||
name: person.name,
|
||||
isLocked: person.manuallyApprovesFollowers,
|
||||
username: person.preferredUsername,
|
||||
@ -154,8 +152,6 @@ export async function createPerson(uri: string, resolver?: Resolver): Promise<Us
|
||||
endpoints: person.endpoints,
|
||||
uri: person.id,
|
||||
url: person.url,
|
||||
fields,
|
||||
...services,
|
||||
tags,
|
||||
isBot,
|
||||
isCat: (person as any).isCat === true
|
||||
@ -170,18 +166,19 @@ export async function createPerson(uri: string, resolver?: Resolver): Promise<Us
|
||||
throw e;
|
||||
}
|
||||
|
||||
await UserProfiles.save({
|
||||
userId: user.id,
|
||||
description: fromHtml(person.summary),
|
||||
fields,
|
||||
userHost: host
|
||||
} as Partial<UserProfile>);
|
||||
|
||||
await UserPublickeys.save({
|
||||
id: genId(),
|
||||
userId: user.id,
|
||||
keyId: person.publicKey.id,
|
||||
keyPem: person.publicKey.publicKeyPem
|
||||
} as UserPublickey);
|
||||
|
||||
await UserServiceLinkings.save({
|
||||
id: genId(),
|
||||
userId: user.id
|
||||
} as UserServiceLinking);
|
||||
|
||||
// Register host
|
||||
registerOrFetchInstanceDoc(host).then(i => {
|
||||
Instances.increment({ id: i.id }, 'usersCount', 1);
|
||||
@ -206,8 +203,8 @@ export async function createPerson(uri: string, resolver?: Resolver): Promise<Us
|
||||
|
||||
const avatarId = avatar ? avatar.id : null;
|
||||
const bannerId = banner ? banner.id : null;
|
||||
const avatarUrl = DriveFiles.getPublicUrl(avatar);
|
||||
const bannerUrl = DriveFiles.getPublicUrl(banner);
|
||||
const avatarUrl = avatar ? DriveFiles.getPublicUrl(avatar) : null;
|
||||
const bannerUrl = banner ? DriveFiles.getPublicUrl(banner) : null;
|
||||
const avatarColor = avatar && avatar.properties.avgColor ? avatar.properties.avgColor : null;
|
||||
const bannerColor = banner && avatar.properties.avgColor ? banner.properties.avgColor : null;
|
||||
|
||||
@ -348,7 +345,7 @@ export async function updatePerson(uri: string, resolver?: Resolver, hint?: obje
|
||||
keyPem: person.publicKey.publicKeyPem
|
||||
});
|
||||
|
||||
await UserServiceLinkings.update({ userId: exist.id }, {
|
||||
await UserProfiles.update({ userId: exist.id }, {
|
||||
twitterUserId: services.twitter.userId,
|
||||
twitterScreenName: services.twitter.screenName,
|
||||
githubId: services.github.id,
|
||||
|
@ -72,7 +72,7 @@ export async function updateQuestion(value: any) {
|
||||
updatedAt: new Date(),
|
||||
});
|
||||
|
||||
await Polls.update(poll.id, {
|
||||
await Polls.update({ noteId: note.id }, {
|
||||
votes: poll.votes
|
||||
});
|
||||
|
||||
|
@ -8,15 +8,15 @@ import { getEmojis } from './note';
|
||||
import renderEmoji from './emoji';
|
||||
import { IIdentifier } from '../models/identifier';
|
||||
import renderHashtag from './hashtag';
|
||||
import { DriveFiles, UserServiceLinkings, UserKeypairs } from '../../../models';
|
||||
import { DriveFiles, UserProfiles, UserKeypairs } from '../../../models';
|
||||
|
||||
export async function renderPerson(user: ILocalUser) {
|
||||
const id = `${config.url}/users/${user.id}`;
|
||||
|
||||
const [avatar, banner, links] = await Promise.all([
|
||||
const [avatar, banner, profile] = await Promise.all([
|
||||
DriveFiles.findOne(user.avatarId),
|
||||
DriveFiles.findOne(user.bannerId),
|
||||
UserServiceLinkings.findOne({ userId: user.id })
|
||||
UserProfiles.findOne({ userId: user.id })
|
||||
]);
|
||||
|
||||
const attachment: {
|
||||
@ -27,41 +27,41 @@ export async function renderPerson(user: ILocalUser) {
|
||||
identifier?: IIdentifier
|
||||
}[] = [];
|
||||
|
||||
if (links.twitter) {
|
||||
if (profile.twitter) {
|
||||
attachment.push({
|
||||
type: 'PropertyValue',
|
||||
name: 'Twitter',
|
||||
value: `<a href="https://twitter.com/intent/user?user_id=${links.twitterUserId}" rel="me nofollow noopener" target="_blank"><span>@${links.twitterScreenName}</span></a>`,
|
||||
value: `<a href="https://twitter.com/intent/user?user_id=${profile.twitterUserId}" rel="me nofollow noopener" target="_blank"><span>@${profile.twitterScreenName}</span></a>`,
|
||||
identifier: {
|
||||
type: 'PropertyValue',
|
||||
name: 'misskey:authentication:twitter',
|
||||
value: `${links.twitterUserId}@${links.twitterScreenName}`
|
||||
value: `${profile.twitterUserId}@${profile.twitterScreenName}`
|
||||
}
|
||||
});
|
||||
}
|
||||
|
||||
if (links.github) {
|
||||
if (profile.github) {
|
||||
attachment.push({
|
||||
type: 'PropertyValue',
|
||||
name: 'GitHub',
|
||||
value: `<a href="https://github.com/${links.githubLogin}" rel="me nofollow noopener" target="_blank"><span>@${links.githubLogin}</span></a>`,
|
||||
value: `<a href="https://github.com/${profile.githubLogin}" rel="me nofollow noopener" target="_blank"><span>@${profile.githubLogin}</span></a>`,
|
||||
identifier: {
|
||||
type: 'PropertyValue',
|
||||
name: 'misskey:authentication:github',
|
||||
value: `${links.githubId}@${links.githubLogin}`
|
||||
value: `${profile.githubId}@${profile.githubLogin}`
|
||||
}
|
||||
});
|
||||
}
|
||||
|
||||
if (links.discord) {
|
||||
if (profile.discord) {
|
||||
attachment.push({
|
||||
type: 'PropertyValue',
|
||||
name: 'Discord',
|
||||
value: `<a href="https://discordapp.com/users/${links.discordId}" rel="me nofollow noopener" target="_blank"><span>${links.discordUsername}#${links.discordDiscriminator}</span></a>`,
|
||||
value: `<a href="https://discordapp.com/users/${profile.discordId}" rel="me nofollow noopener" target="_blank"><span>${profile.discordUsername}#${profile.discordDiscriminator}</span></a>`,
|
||||
identifier: {
|
||||
type: 'PropertyValue',
|
||||
name: 'misskey:authentication:discord',
|
||||
value: `${links.discordId}@${links.discordUsername}#${links.discordDiscriminator}`
|
||||
value: `${profile.discordId}@${profile.discordUsername}#${profile.discordDiscriminator}`
|
||||
}
|
||||
});
|
||||
}
|
||||
@ -93,7 +93,7 @@ export async function renderPerson(user: ILocalUser) {
|
||||
url: `${config.url}/@${user.username}`,
|
||||
preferredUsername: user.username,
|
||||
name: user.name,
|
||||
summary: toHtml(parse(user.description)),
|
||||
summary: toHtml(parse(profile.description)),
|
||||
icon: user.avatarId && renderImage(avatar),
|
||||
image: user.bannerId && renderImage(banner),
|
||||
tag,
|
||||
|
@ -4,7 +4,6 @@ import { URL } from 'url';
|
||||
import * as crypto from 'crypto';
|
||||
import { lookup, IRunOptions } from 'lookup-dns-cache';
|
||||
import * as promiseAny from 'promise-any';
|
||||
import { toUnicode } from 'punycode';
|
||||
|
||||
import config from '../../config';
|
||||
import { ILocalUser } from '../../models/entities/user';
|
||||
@ -12,6 +11,7 @@ import { publishApLogStream } from '../../services/stream';
|
||||
import { apLogger } from './logger';
|
||||
import { UserKeypairs } from '../../models';
|
||||
import fetchMeta from '../../misc/fetch-meta';
|
||||
import { toPuny } from '../../misc/convert-host';
|
||||
|
||||
export const logger = apLogger.createSubLogger('deliver');
|
||||
|
||||
@ -25,7 +25,7 @@ export default async (user: ILocalUser, url: string, object: any) => {
|
||||
// ブロックしてたら中断
|
||||
// TODO: いちいちデータベースにアクセスするのはコスト高そうなのでどっかにキャッシュしておく
|
||||
const meta = await fetchMeta();
|
||||
if (meta.blockedHosts.includes(toUnicode(host))) return;
|
||||
if (meta.blockedHosts.includes(toPuny(host))) return;
|
||||
|
||||
const data = JSON.stringify(object);
|
||||
|
||||
|
@ -1,4 +1,3 @@
|
||||
import { toUnicode, toASCII } from 'punycode';
|
||||
import webFinger from './webfinger';
|
||||
import config from '../config';
|
||||
import { createPerson, updatePerson } from './activitypub/models/person';
|
||||
@ -7,31 +6,27 @@ import { remoteLogger } from './logger';
|
||||
import chalk from 'chalk';
|
||||
import { User, IRemoteUser } from '../models/entities/user';
|
||||
import { Users } from '../models';
|
||||
import { toPuny } from '../misc/convert-host';
|
||||
|
||||
const logger = remoteLogger.createSubLogger('resolve-user');
|
||||
|
||||
export async function resolveUser(username: string, _host: string, option?: any, resync = false): Promise<User> {
|
||||
export async function resolveUser(username: string, host: string, option?: any, resync = false): Promise<User> {
|
||||
const usernameLower = username.toLowerCase();
|
||||
host = toPuny(host);
|
||||
|
||||
if (_host == null) {
|
||||
if (host == null) {
|
||||
logger.info(`return local user: ${usernameLower}`);
|
||||
return await Users.findOne({ usernameLower, host: null });
|
||||
}
|
||||
|
||||
const configHostAscii = toASCII(config.host).toLowerCase();
|
||||
const configHost = toUnicode(configHostAscii);
|
||||
|
||||
const hostAscii = toASCII(_host).toLowerCase();
|
||||
const host = toUnicode(hostAscii);
|
||||
|
||||
if (configHost == host) {
|
||||
if (config.host == host) {
|
||||
logger.info(`return local user: ${usernameLower}`);
|
||||
return await Users.findOne({ usernameLower, host: null });
|
||||
}
|
||||
|
||||
const user = await Users.findOne({ usernameLower, host }, option);
|
||||
|
||||
const acctLower = `${usernameLower}@${hostAscii}`;
|
||||
const acctLower = `${usernameLower}@${host}`;
|
||||
|
||||
if (user == null) {
|
||||
const self = await resolveSelf(acctLower);
|
||||
@ -51,7 +46,7 @@ export async function resolveUser(username: string, _host: string, option?: any,
|
||||
|
||||
// validate uri
|
||||
const uri = new URL(self.href);
|
||||
if (uri.hostname !== hostAscii) {
|
||||
if (uri.hostname !== host) {
|
||||
throw new Error(`Invalied uri`);
|
||||
}
|
||||
|
||||
@ -78,8 +73,8 @@ export async function resolveUser(username: string, _host: string, option?: any,
|
||||
async function resolveSelf(acctLower: string) {
|
||||
logger.info(`WebFinger for ${chalk.yellow(acctLower)}`);
|
||||
const finger = await webFinger(acctLower).catch(e => {
|
||||
logger.error(`Failed to WebFinger for ${chalk.yellow(acctLower)}: ${e.message} (${e.status})`);
|
||||
throw e;
|
||||
logger.error(`Failed to WebFinger for ${chalk.yellow(acctLower)}: ${ e.statusCode || e.message }`);
|
||||
throw new Error(`Failed to WebFinger for ${acctLower}: ${ e.statusCode || e.message }`);
|
||||
});
|
||||
const self = finger.links.find(link => link.rel && link.rel.toLowerCase() === 'self');
|
||||
if (!self) {
|
||||
|
@ -1,6 +1,7 @@
|
||||
import { WebFinger } from 'webfinger.js';
|
||||
|
||||
const webFinger = new WebFinger({ });
|
||||
import config from '../config';
|
||||
import * as request from 'request-promise-native';
|
||||
import { URL } from 'url';
|
||||
import { query as urlQuery } from '../prelude/url';
|
||||
|
||||
type ILink = {
|
||||
href: string;
|
||||
@ -12,12 +13,33 @@ type IWebFinger = {
|
||||
subject: string;
|
||||
};
|
||||
|
||||
export default async function resolve(query: any): Promise<IWebFinger> {
|
||||
return await new Promise((res, rej) => webFinger.lookup(query, (error: Error | string, result: any) => {
|
||||
if (error) {
|
||||
return rej(error);
|
||||
}
|
||||
export default async function(query: string): Promise<IWebFinger> {
|
||||
const url = genUrl(query);
|
||||
|
||||
res(result.object);
|
||||
})) as IWebFinger;
|
||||
return await request({
|
||||
url,
|
||||
proxy: config.proxy,
|
||||
timeout: 10 * 1000,
|
||||
forever: true,
|
||||
headers: {
|
||||
'User-Agent': config.userAgent,
|
||||
Accept: 'application/jrd+json, application/json'
|
||||
},
|
||||
json: true
|
||||
});
|
||||
}
|
||||
|
||||
function genUrl(query: string) {
|
||||
if (query.match(/^https?:\/\//)) {
|
||||
const u = new URL(query);
|
||||
return `${u.protocol}//${u.hostname}/.well-known/webfinger?` + urlQuery({ resource: query });
|
||||
}
|
||||
|
||||
const m = query.match(/^([^@]+)@(.*)/);
|
||||
if (m) {
|
||||
const hostname = m[2];
|
||||
return `https://${hostname}/.well-known/webfinger?` + urlQuery({ resource: `acct:${query}` });
|
||||
}
|
||||
|
||||
throw new Error(`Invalied query (${query})`);
|
||||
}
|
||||
|
@ -1,6 +0,0 @@
|
||||
import { toUnicode } from 'punycode';
|
||||
|
||||
export default (host: string) => {
|
||||
if (host == null) return null;
|
||||
return toUnicode(host).toLowerCase();
|
||||
};
|
@ -1,6 +1,7 @@
|
||||
import $ from 'cafy';
|
||||
import define from '../../../define';
|
||||
import { Emojis } from '../../../../../models';
|
||||
import { toPuny } from '../../../../../misc/convert-host';
|
||||
|
||||
export const meta = {
|
||||
desc: {
|
||||
@ -22,7 +23,7 @@ export const meta = {
|
||||
|
||||
export default define(meta, async (ps) => {
|
||||
const emojis = await Emojis.find({
|
||||
host: ps.host
|
||||
host: toPuny(ps.host)
|
||||
});
|
||||
|
||||
return emojis.map(e => ({
|
||||
|
@ -1,6 +1,7 @@
|
||||
import $ from 'cafy';
|
||||
import define from '../../../define';
|
||||
import { Instances } from '../../../../../models';
|
||||
import { toPuny } from '../../../../../misc/convert-host';
|
||||
|
||||
export const meta = {
|
||||
tags: ['admin'],
|
||||
@ -20,13 +21,13 @@ export const meta = {
|
||||
};
|
||||
|
||||
export default define(meta, async (ps, me) => {
|
||||
const instance = await Instances.findOne({ host: ps.host });
|
||||
const instance = await Instances.findOne({ host: toPuny(ps.host) });
|
||||
|
||||
if (instance == null) {
|
||||
throw new Error('instance not found');
|
||||
}
|
||||
|
||||
Instances.update({ host: ps.host }, {
|
||||
Instances.update({ host: toPuny(ps.host) }, {
|
||||
isMarkedAsClosed: ps.isClosed
|
||||
});
|
||||
});
|
||||
|
@ -3,7 +3,7 @@ import { ID } from '../../../../misc/cafy-id';
|
||||
import define from '../../define';
|
||||
import * as bcrypt from 'bcryptjs';
|
||||
import rndstr from 'rndstr';
|
||||
import { Users } from '../../../../models';
|
||||
import { Users, UserProfiles } from '../../../../models';
|
||||
|
||||
export const meta = {
|
||||
desc: {
|
||||
@ -42,7 +42,9 @@ export default define(meta, async (ps) => {
|
||||
// Generate hash of password
|
||||
const hash = bcrypt.hashSync(passwd);
|
||||
|
||||
await Users.update(user.id, {
|
||||
await UserProfiles.update({
|
||||
userId: user.id
|
||||
}, {
|
||||
password: hash
|
||||
});
|
||||
|
||||
|
@ -1,6 +1,7 @@
|
||||
import $ from 'cafy';
|
||||
import define from '../../define';
|
||||
import { Instances } from '../../../../models';
|
||||
import { toPuny } from '../../../../misc/convert-host';
|
||||
|
||||
export const meta = {
|
||||
tags: ['federation'],
|
||||
@ -16,7 +17,7 @@ export const meta = {
|
||||
|
||||
export default define(meta, async (ps, me) => {
|
||||
const instance = await Instances
|
||||
.findOne({ host: ps.host });
|
||||
.findOne({ host: toPuny(ps.host) });
|
||||
|
||||
return instance;
|
||||
});
|
||||
|
@ -1,7 +1,7 @@
|
||||
import $ from 'cafy';
|
||||
import * as speakeasy from 'speakeasy';
|
||||
import define from '../../../define';
|
||||
import { Users } from '../../../../../models';
|
||||
import { UserProfiles } from '../../../../../models';
|
||||
|
||||
export const meta = {
|
||||
requireCredential: true,
|
||||
@ -16,24 +16,26 @@ export const meta = {
|
||||
};
|
||||
|
||||
export default define(meta, async (ps, user) => {
|
||||
const _token = ps.token.replace(/\s/g, '');
|
||||
const token = ps.token.replace(/\s/g, '');
|
||||
|
||||
if (user.twoFactorTempSecret == null) {
|
||||
const profile = await UserProfiles.findOne({ userId: user.id });
|
||||
|
||||
if (profile.twoFactorTempSecret == null) {
|
||||
throw new Error('二段階認証の設定が開始されていません');
|
||||
}
|
||||
|
||||
const verified = (speakeasy as any).totp.verify({
|
||||
secret: user.twoFactorTempSecret,
|
||||
secret: profile.twoFactorTempSecret,
|
||||
encoding: 'base32',
|
||||
token: _token
|
||||
token: token
|
||||
});
|
||||
|
||||
if (!verified) {
|
||||
throw new Error('not verified');
|
||||
}
|
||||
|
||||
await Users.update(user.id, {
|
||||
twoFactorSecret: user.twoFactorTempSecret,
|
||||
await UserProfiles.update({ userId: user.id }, {
|
||||
twoFactorSecret: profile.twoFactorTempSecret,
|
||||
twoFactorEnabled: true
|
||||
});
|
||||
});
|
||||
|
@ -4,7 +4,7 @@ import * as speakeasy from 'speakeasy';
|
||||
import * as QRCode from 'qrcode';
|
||||
import config from '../../../../../config';
|
||||
import define from '../../../define';
|
||||
import { Users } from '../../../../../models';
|
||||
import { UserProfiles } from '../../../../../models';
|
||||
|
||||
export const meta = {
|
||||
requireCredential: true,
|
||||
@ -19,8 +19,10 @@ export const meta = {
|
||||
};
|
||||
|
||||
export default define(meta, async (ps, user) => {
|
||||
const profile = await UserProfiles.findOne({ userId: user.id });
|
||||
|
||||
// Compare password
|
||||
const same = await bcrypt.compare(ps.password, user.password);
|
||||
const same = await bcrypt.compare(ps.password, profile.password);
|
||||
|
||||
if (!same) {
|
||||
throw new Error('incorrect password');
|
||||
@ -31,7 +33,7 @@ export default define(meta, async (ps, user) => {
|
||||
length: 32
|
||||
});
|
||||
|
||||
await Users.update(user.id, {
|
||||
await UserProfiles.update({ userId: user.id }, {
|
||||
twoFactorTempSecret: secret.base32
|
||||
});
|
||||
|
||||
|
@ -1,7 +1,7 @@
|
||||
import $ from 'cafy';
|
||||
import * as bcrypt from 'bcryptjs';
|
||||
import define from '../../../define';
|
||||
import { Users } from '../../../../../models';
|
||||
import { UserProfiles } from '../../../../../models';
|
||||
|
||||
export const meta = {
|
||||
requireCredential: true,
|
||||
@ -16,17 +16,17 @@ export const meta = {
|
||||
};
|
||||
|
||||
export default define(meta, async (ps, user) => {
|
||||
const profile = await UserProfiles.findOne({ userId: user.id });
|
||||
|
||||
// Compare password
|
||||
const same = await bcrypt.compare(ps.password, user.password);
|
||||
const same = await bcrypt.compare(ps.password, profile.password);
|
||||
|
||||
if (!same) {
|
||||
throw new Error('incorrect password');
|
||||
}
|
||||
|
||||
await Users.update(user.id, {
|
||||
await UserProfiles.update({ userId: user.id }, {
|
||||
twoFactorSecret: null,
|
||||
twoFactorEnabled: false
|
||||
});
|
||||
|
||||
return;
|
||||
});
|
||||
|
@ -1,7 +1,7 @@
|
||||
import $ from 'cafy';
|
||||
import * as bcrypt from 'bcryptjs';
|
||||
import define from '../../define';
|
||||
import { Users } from '../../../../models';
|
||||
import { UserProfiles } from '../../../../models';
|
||||
|
||||
export const meta = {
|
||||
requireCredential: true,
|
||||
@ -20,8 +20,10 @@ export const meta = {
|
||||
};
|
||||
|
||||
export default define(meta, async (ps, user) => {
|
||||
const profile = await UserProfiles.findOne({ userId: user.id });
|
||||
|
||||
// Compare password
|
||||
const same = await bcrypt.compare(ps.currentPassword, user.password);
|
||||
const same = await bcrypt.compare(ps.currentPassword, profile.password);
|
||||
|
||||
if (!same) {
|
||||
throw new Error('incorrect password');
|
||||
@ -31,7 +33,7 @@ export default define(meta, async (ps, user) => {
|
||||
const salt = await bcrypt.genSalt(8);
|
||||
const hash = await bcrypt.hash(ps.newPassword, salt);
|
||||
|
||||
await Users.update(user.id, {
|
||||
await UserProfiles.update({ userId: user.id }, {
|
||||
password: hash
|
||||
});
|
||||
});
|
||||
|
@ -1,7 +1,7 @@
|
||||
import $ from 'cafy';
|
||||
import * as bcrypt from 'bcryptjs';
|
||||
import define from '../../define';
|
||||
import { Users } from '../../../../models';
|
||||
import { Users, UserProfiles } from '../../../../models';
|
||||
|
||||
export const meta = {
|
||||
requireCredential: true,
|
||||
@ -16,8 +16,10 @@ export const meta = {
|
||||
};
|
||||
|
||||
export default define(meta, async (ps, user) => {
|
||||
const profile = await UserProfiles.findOne({ userId: user.id });
|
||||
|
||||
// Compare password
|
||||
const same = await bcrypt.compare(ps.password, user.password);
|
||||
const same = await bcrypt.compare(ps.password, profile.password);
|
||||
|
||||
if (!same) {
|
||||
throw new Error('incorrect password');
|
||||
|
@ -3,7 +3,7 @@ import * as bcrypt from 'bcryptjs';
|
||||
import { publishMainStream } from '../../../../services/stream';
|
||||
import generateUserToken from '../../common/generate-native-user-token';
|
||||
import define from '../../define';
|
||||
import { Users } from '../../../../models';
|
||||
import { Users, UserProfiles } from '../../../../models';
|
||||
|
||||
export const meta = {
|
||||
requireCredential: true,
|
||||
@ -18,8 +18,10 @@ export const meta = {
|
||||
};
|
||||
|
||||
export default define(meta, async (ps, user) => {
|
||||
const profile = await UserProfiles.findOne({ userId: user.id });
|
||||
|
||||
// Compare password
|
||||
const same = await bcrypt.compare(ps.password, user.password);
|
||||
const same = await bcrypt.compare(ps.password, profile.password);
|
||||
|
||||
if (!same) {
|
||||
throw new Error('incorrect password');
|
||||
|
@ -1,7 +1,7 @@
|
||||
import $ from 'cafy';
|
||||
import { publishMainStream } from '../../../../services/stream';
|
||||
import define from '../../define';
|
||||
import { Users } from '../../../../models';
|
||||
import { UserProfiles } from '../../../../models';
|
||||
|
||||
export const meta = {
|
||||
requireCredential: true,
|
||||
@ -20,13 +20,13 @@ export const meta = {
|
||||
};
|
||||
|
||||
export default define(meta, async (ps, user) => {
|
||||
await Users.createQueryBuilder().update()
|
||||
await UserProfiles.createQueryBuilder().update()
|
||||
.set({
|
||||
clientData: {
|
||||
[ps.name]: ps.value
|
||||
},
|
||||
})
|
||||
.where('id = :id', { id: user.id })
|
||||
.where('userId = :id', { id: user.id })
|
||||
.execute();
|
||||
|
||||
// Publish event
|
||||
|
@ -8,7 +8,7 @@ import config from '../../../../config';
|
||||
import * as ms from 'ms';
|
||||
import * as bcrypt from 'bcryptjs';
|
||||
import { apiLogger } from '../../logger';
|
||||
import { Users } from '../../../../models';
|
||||
import { Users, UserProfiles } from '../../../../models';
|
||||
|
||||
export const meta = {
|
||||
requireCredential: true,
|
||||
@ -32,14 +32,16 @@ export const meta = {
|
||||
};
|
||||
|
||||
export default define(meta, async (ps, user) => {
|
||||
const profile = await UserProfiles.findOne({ userId: user.id });
|
||||
|
||||
// Compare password
|
||||
const same = await bcrypt.compare(ps.password, user.password);
|
||||
const same = await bcrypt.compare(ps.password, profile.password);
|
||||
|
||||
if (!same) {
|
||||
throw new Error('incorrect password');
|
||||
}
|
||||
|
||||
await Users.update(user.id, {
|
||||
await UserProfiles.update({ userId: user.id }, {
|
||||
email: ps.email,
|
||||
emailVerified: false,
|
||||
emailVerifyCode: null
|
||||
@ -56,7 +58,7 @@ export default define(meta, async (ps, user) => {
|
||||
if (ps.email != null) {
|
||||
const code = rndstr('a-z0-9', 16);
|
||||
|
||||
await Users.update(user.id, {
|
||||
await UserProfiles.update({ userId: user.id }, {
|
||||
emailVerifyCode: code
|
||||
});
|
||||
|
||||
|
@ -10,7 +10,9 @@ import extractHashtags from '../../../../misc/extract-hashtags';
|
||||
import * as langmap from 'langmap';
|
||||
import { updateHashtag } from '../../../../services/update-hashtag';
|
||||
import { ApiError } from '../../error';
|
||||
import { Users, DriveFiles } from '../../../../models';
|
||||
import { Users, DriveFiles, UserProfiles } from '../../../../models';
|
||||
import { User } from '../../../../models/entities/user';
|
||||
import { UserProfile } from '../../../../models/entities/user-profile';
|
||||
|
||||
export const meta = {
|
||||
desc: {
|
||||
@ -154,22 +156,23 @@ export const meta = {
|
||||
export default define(meta, async (ps, user, app) => {
|
||||
const isSecure = user != null && app == null;
|
||||
|
||||
const updates = {} as any;
|
||||
const updates = {} as Partial<User>;
|
||||
const profile = {} as Partial<UserProfile>;
|
||||
|
||||
if (ps.name !== undefined) updates.name = ps.name;
|
||||
if (ps.description !== undefined) updates.description = ps.description;
|
||||
if (ps.lang !== undefined) updates.lang = ps.lang;
|
||||
if (ps.location !== undefined) updates.location = ps.location;
|
||||
if (ps.birthday !== undefined) updates.birthday = ps.birthday;
|
||||
if (ps.description !== undefined) profile.description = ps.description;
|
||||
//if (ps.lang !== undefined) updates.lang = ps.lang;
|
||||
if (ps.location !== undefined) profile.location = ps.location;
|
||||
if (ps.birthday !== undefined) profile.birthday = ps.birthday;
|
||||
if (ps.avatarId !== undefined) updates.avatarId = ps.avatarId;
|
||||
if (ps.bannerId !== undefined) updates.bannerId = ps.bannerId;
|
||||
if (typeof ps.isLocked == 'boolean') updates.isLocked = ps.isLocked;
|
||||
if (typeof ps.isBot == 'boolean') updates.isBot = ps.isBot;
|
||||
if (typeof ps.carefulBot == 'boolean') updates.carefulBot = ps.carefulBot;
|
||||
if (typeof ps.autoAcceptFollowed == 'boolean') updates.autoAcceptFollowed = ps.autoAcceptFollowed;
|
||||
if (typeof ps.carefulBot == 'boolean') profile.carefulBot = ps.carefulBot;
|
||||
if (typeof ps.autoAcceptFollowed == 'boolean') profile.autoAcceptFollowed = ps.autoAcceptFollowed;
|
||||
if (typeof ps.isCat == 'boolean') updates.isCat = ps.isCat;
|
||||
if (typeof ps.autoWatch == 'boolean') updates.autoWatch = ps.autoWatch;
|
||||
if (typeof ps.alwaysMarkNsfw == 'boolean') updates.alwaysMarkNsfw = ps.alwaysMarkNsfw;
|
||||
if (typeof ps.autoWatch == 'boolean') profile.autoWatch = ps.autoWatch;
|
||||
if (typeof ps.alwaysMarkNsfw == 'boolean') profile.alwaysMarkNsfw = ps.alwaysMarkNsfw;
|
||||
|
||||
if (ps.avatarId) {
|
||||
const avatar = await DriveFiles.findOne(ps.avatarId);
|
||||
@ -206,8 +209,8 @@ export default define(meta, async (ps, user, app) => {
|
||||
emojis = emojis.concat(extractEmojis(tokens));
|
||||
}
|
||||
|
||||
if (updates.description != null) {
|
||||
const tokens = parse(updates.description);
|
||||
if (profile.description != null) {
|
||||
const tokens = parse(profile.description);
|
||||
emojis = emojis.concat(extractEmojis(tokens));
|
||||
tags = extractHashtags(tokens).map(tag => tag.toLowerCase());
|
||||
}
|
||||
@ -220,7 +223,8 @@ export default define(meta, async (ps, user, app) => {
|
||||
for (const tag of user.tags.filter(x => !tags.includes(x))) updateHashtag(user, tag, true, false);
|
||||
//#endregion
|
||||
|
||||
await Users.update(user.id, updates);
|
||||
if (Object.keys(updates).length > 0) await Users.update(user.id, updates);
|
||||
if (Object.keys(profile).length > 0) await UserProfiles.update({ userId: user.id }, profile);
|
||||
|
||||
const iObj = await Users.pack(user.id, user, {
|
||||
detail: true,
|
||||
|
@ -10,7 +10,7 @@ import { deliver } from '../../../../../queue';
|
||||
import { renderActivity } from '../../../../../remote/activitypub/renderer';
|
||||
import renderVote from '../../../../../remote/activitypub/renderer/vote';
|
||||
import { deliverQuestionUpdate } from '../../../../../services/note/polls/update';
|
||||
import { PollVotes, NoteWatchings, Users, Polls } from '../../../../../models';
|
||||
import { PollVotes, NoteWatchings, Users, Polls, UserProfiles } from '../../../../../models';
|
||||
import { Not } from 'typeorm';
|
||||
import { IRemoteUser } from '../../../../../models/entities/user';
|
||||
import { genId } from '../../../../../misc/gen-id';
|
||||
@ -123,7 +123,7 @@ export default define(meta, async (ps, user) => {
|
||||
|
||||
// Increment votes count
|
||||
const index = ps.choice + 1; // In SQL, array index is 1 based
|
||||
await Polls.query(`UPDATE poll SET votes[${index}] = votes[${index}] + 1 WHERE id = '${poll.id}'`);
|
||||
await Polls.query(`UPDATE poll SET votes[${index}] = votes[${index}] + 1 WHERE noteId = '${poll.noteId}'`);
|
||||
|
||||
publishNoteStream(note.id, 'pollVoted', {
|
||||
choice: ps.choice,
|
||||
@ -149,8 +149,10 @@ export default define(meta, async (ps, user) => {
|
||||
}
|
||||
});
|
||||
|
||||
const profile = await UserProfiles.findOne({ userId: user.id });
|
||||
|
||||
// この投稿をWatchする
|
||||
if (user.autoWatch !== false) {
|
||||
if (profile.autoWatch !== false) {
|
||||
watch(user.id, note);
|
||||
}
|
||||
|
||||
|
@ -4,6 +4,7 @@ import define from '../../define';
|
||||
import { ApiError } from '../../error';
|
||||
import { Users, Followings } from '../../../../models';
|
||||
import { makePaginationQuery } from '../../common/make-pagination-query';
|
||||
import { toPuny } from '../../../../misc/convert-host';
|
||||
|
||||
export const meta = {
|
||||
desc: {
|
||||
@ -65,7 +66,7 @@ export const meta = {
|
||||
export default define(meta, async (ps, me) => {
|
||||
const user = await Users.findOne(ps.userId != null
|
||||
? { id: ps.userId }
|
||||
: { usernameLower: ps.username.toLowerCase(), host: ps.host });
|
||||
: { usernameLower: ps.username.toLowerCase(), host: toPuny(ps.host) });
|
||||
|
||||
if (user == null) {
|
||||
throw new ApiError(meta.errors.noSuchUser);
|
||||
|
@ -4,6 +4,7 @@ import define from '../../define';
|
||||
import { ApiError } from '../../error';
|
||||
import { Users, Followings } from '../../../../models';
|
||||
import { makePaginationQuery } from '../../common/make-pagination-query';
|
||||
import { toPuny } from '../../../../misc/convert-host';
|
||||
|
||||
export const meta = {
|
||||
desc: {
|
||||
@ -65,7 +66,7 @@ export const meta = {
|
||||
export default define(meta, async (ps, me) => {
|
||||
const user = await Users.findOne(ps.userId != null
|
||||
? { id: ps.userId }
|
||||
: { usernameLower: ps.username.toLowerCase(), host: ps.host });
|
||||
: { usernameLower: ps.username.toLowerCase(), host: toPuny(ps.host) });
|
||||
|
||||
if (user == null) {
|
||||
throw new ApiError(meta.errors.noSuchUser);
|
||||
|
@ -15,7 +15,6 @@ import signin from './private/signin';
|
||||
import discord from './service/discord';
|
||||
import github from './service/github';
|
||||
import twitter from './service/twitter';
|
||||
import { toASCII } from 'punycode';
|
||||
import { Instances } from '../../models';
|
||||
|
||||
// Init app
|
||||
@ -71,9 +70,7 @@ router.get('/v1/instance/peers', async ctx => {
|
||||
select: ['host']
|
||||
});
|
||||
|
||||
const punyCodes = instances.map(instance => toASCII(instance.host));
|
||||
|
||||
ctx.body = punyCodes;
|
||||
ctx.body = instances.map(instance => instance.host);
|
||||
});
|
||||
|
||||
// Return 404 for unknown API
|
||||
|
@ -4,7 +4,7 @@ import * as speakeasy from 'speakeasy';
|
||||
import { publishMainStream } from '../../../services/stream';
|
||||
import signin from '../common/signin';
|
||||
import config from '../../../config';
|
||||
import { Users, Signins } from '../../../models';
|
||||
import { Users, Signins, UserProfiles } from '../../../models';
|
||||
import { ILocalUser } from '../../../models/entities/user';
|
||||
import { genId } from '../../../misc/gen-id';
|
||||
|
||||
@ -45,13 +45,15 @@ export default async (ctx: Koa.BaseContext) => {
|
||||
return;
|
||||
}
|
||||
|
||||
const profile = await UserProfiles.findOne({ userId: user.id });
|
||||
|
||||
// Compare password
|
||||
const same = await bcrypt.compare(password, user.password);
|
||||
const same = await bcrypt.compare(password, profile.password);
|
||||
|
||||
if (same) {
|
||||
if (user.twoFactorEnabled) {
|
||||
if (profile.twoFactorEnabled) {
|
||||
const verified = (speakeasy as any).totp.verify({
|
||||
secret: user.twoFactorSecret,
|
||||
secret: profile.twoFactorSecret,
|
||||
encoding: 'base32',
|
||||
token: token
|
||||
});
|
||||
|
@ -5,13 +5,13 @@ import generateUserToken from '../common/generate-native-user-token';
|
||||
import config from '../../../config';
|
||||
import fetchMeta from '../../../misc/fetch-meta';
|
||||
import * as recaptcha from 'recaptcha-promise';
|
||||
import { Users, RegistrationTickets, UserServiceLinkings, UserKeypairs } from '../../../models';
|
||||
import { Users, RegistrationTickets, UserProfiles, UserKeypairs } from '../../../models';
|
||||
import { genId } from '../../../misc/gen-id';
|
||||
import { usersChart } from '../../../services/chart';
|
||||
import { UserServiceLinking } from '../../../models/entities/user-service-linking';
|
||||
import { User } from '../../../models/entities/user';
|
||||
import { UserKeypair } from '../../../models/entities/user-keypair';
|
||||
import { toPuny } from '../../../misc/convert-host';
|
||||
import { UserProfile } from '../../../models/entities/user-profile';
|
||||
|
||||
export default async (ctx: Koa.BaseContext) => {
|
||||
const body = ctx.request.body as any;
|
||||
@ -106,23 +106,21 @@ export default async (ctx: Koa.BaseContext) => {
|
||||
usernameLower: username.toLowerCase(),
|
||||
host: toPuny(host),
|
||||
token: secret,
|
||||
password: hash,
|
||||
isAdmin: config.autoAdmin && usersCount === 0,
|
||||
autoAcceptFollowed: true,
|
||||
autoWatch: false
|
||||
} as User);
|
||||
|
||||
await UserKeypairs.save({
|
||||
id: genId(),
|
||||
publicKey: keyPair[0],
|
||||
privateKey: keyPair[1],
|
||||
userId: account.id
|
||||
} as UserKeypair);
|
||||
|
||||
await UserServiceLinkings.save({
|
||||
id: genId(),
|
||||
userId: account.id
|
||||
} as UserServiceLinking);
|
||||
await UserProfiles.save({
|
||||
userId: account.id,
|
||||
autoAcceptFollowed: true,
|
||||
autoWatch: false,
|
||||
password: hash,
|
||||
} as Partial<UserProfile>);
|
||||
|
||||
usersChart.update(account, true);
|
||||
|
||||
|
@ -8,7 +8,7 @@ import redis from '../../../db/redis';
|
||||
import * as uuid from 'uuid';
|
||||
import signin from '../common/signin';
|
||||
import fetchMeta from '../../../misc/fetch-meta';
|
||||
import { Users, UserServiceLinkings } from '../../../models';
|
||||
import { Users, UserProfiles } from '../../../models';
|
||||
import { ILocalUser } from '../../../models/entities/user';
|
||||
|
||||
function getUserToken(ctx: Koa.BaseContext) {
|
||||
@ -45,7 +45,7 @@ router.get('/disconnect/discord', async ctx => {
|
||||
token: userToken
|
||||
});
|
||||
|
||||
await UserServiceLinkings.update({
|
||||
await UserProfiles.update({
|
||||
userId: user.id
|
||||
}, {
|
||||
discord: false,
|
||||
@ -202,7 +202,7 @@ router.get('/dc/cb', async ctx => {
|
||||
return;
|
||||
}
|
||||
|
||||
const link = await UserServiceLinkings.createQueryBuilder()
|
||||
const profile = await UserProfiles.createQueryBuilder()
|
||||
.where('discord @> :discord', {
|
||||
discord: {
|
||||
id: id,
|
||||
@ -211,12 +211,12 @@ router.get('/dc/cb', async ctx => {
|
||||
.andWhere('userHost IS NULL')
|
||||
.getOne();
|
||||
|
||||
if (link == null) {
|
||||
if (profile == null) {
|
||||
ctx.throw(404, `@${username}#${discriminator}と連携しているMisskeyアカウントはありませんでした...`);
|
||||
return;
|
||||
}
|
||||
|
||||
await UserServiceLinkings.update(link.id, {
|
||||
await UserProfiles.update({ userId: profile.userId }, {
|
||||
discord: true,
|
||||
discordAccessToken: accessToken,
|
||||
discordRefreshToken: refreshToken,
|
||||
@ -225,7 +225,7 @@ router.get('/dc/cb', async ctx => {
|
||||
discordDiscriminator: discriminator
|
||||
});
|
||||
|
||||
signin(ctx, await Users.findOne(link.userId) as ILocalUser, true);
|
||||
signin(ctx, await Users.findOne(profile.userId) as ILocalUser, true);
|
||||
} else {
|
||||
const code = ctx.query.code;
|
||||
|
||||
@ -289,7 +289,7 @@ router.get('/dc/cb', async ctx => {
|
||||
token: userToken
|
||||
});
|
||||
|
||||
await UserServiceLinkings.update({ userId: user.id }, {
|
||||
await UserProfiles.update({ userId: user.id }, {
|
||||
discord: true,
|
||||
discordAccessToken: accessToken,
|
||||
discordRefreshToken: refreshToken,
|
||||
|
@ -8,7 +8,7 @@ import redis from '../../../db/redis';
|
||||
import * as uuid from 'uuid';
|
||||
import signin from '../common/signin';
|
||||
import fetchMeta from '../../../misc/fetch-meta';
|
||||
import { Users, UserServiceLinkings } from '../../../models';
|
||||
import { Users, UserProfiles } from '../../../models';
|
||||
import { ILocalUser } from '../../../models/entities/user';
|
||||
|
||||
function getUserToken(ctx: Koa.BaseContext) {
|
||||
@ -45,7 +45,7 @@ router.get('/disconnect/github', async ctx => {
|
||||
token: userToken
|
||||
});
|
||||
|
||||
await UserServiceLinkings.update({
|
||||
await UserProfiles.update({
|
||||
userId: user.id
|
||||
}, {
|
||||
github: false,
|
||||
@ -191,7 +191,7 @@ router.get('/gh/cb', async ctx => {
|
||||
return;
|
||||
}
|
||||
|
||||
const link = await UserServiceLinkings.createQueryBuilder()
|
||||
const link = await UserProfiles.createQueryBuilder()
|
||||
.where('github @> :github', {
|
||||
github: {
|
||||
id: id,
|
||||
@ -263,7 +263,7 @@ router.get('/gh/cb', async ctx => {
|
||||
token: userToken
|
||||
});
|
||||
|
||||
await UserServiceLinkings.update({ userId: user.id }, {
|
||||
await UserProfiles.update({ userId: user.id }, {
|
||||
github: true,
|
||||
githubAccessToken: accessToken,
|
||||
githubId: id,
|
||||
|
@ -7,7 +7,7 @@ import { publishMainStream } from '../../../services/stream';
|
||||
import config from '../../../config';
|
||||
import signin from '../common/signin';
|
||||
import fetchMeta from '../../../misc/fetch-meta';
|
||||
import { Users, UserServiceLinkings } from '../../../models';
|
||||
import { Users, UserProfiles } from '../../../models';
|
||||
import { ILocalUser } from '../../../models/entities/user';
|
||||
|
||||
function getUserToken(ctx: Koa.BaseContext) {
|
||||
@ -44,7 +44,7 @@ router.get('/disconnect/twitter', async ctx => {
|
||||
token: userToken
|
||||
});
|
||||
|
||||
await UserServiceLinkings.update({
|
||||
await UserProfiles.update({
|
||||
userId: user.id
|
||||
}, {
|
||||
twitter: false,
|
||||
@ -139,7 +139,7 @@ router.get('/tw/cb', async ctx => {
|
||||
|
||||
const result = await twAuth.done(JSON.parse(twCtx), ctx.query.oauth_verifier);
|
||||
|
||||
const link = await UserServiceLinkings.createQueryBuilder()
|
||||
const link = await UserProfiles.createQueryBuilder()
|
||||
.where('twitter @> :twitter', {
|
||||
twitter: {
|
||||
userId: result.userId,
|
||||
@ -177,7 +177,7 @@ router.get('/tw/cb', async ctx => {
|
||||
token: userToken
|
||||
});
|
||||
|
||||
await UserServiceLinkings.update({ userId: user.id }, {
|
||||
await UserProfiles.update({ userId: user.id }, {
|
||||
twitter: true,
|
||||
twitterAccessToken: result.accessToken,
|
||||
twitterAccessTokenSecret: result.accessTokenSecret,
|
||||
|
@ -23,7 +23,7 @@ import apiServer from './api';
|
||||
import { sum } from '../prelude/array';
|
||||
import Logger from '../services/logger';
|
||||
import { program } from '../argv';
|
||||
import { Users } from '../models';
|
||||
import { UserProfiles } from '../models';
|
||||
import { networkChart } from '../services/chart';
|
||||
|
||||
export const serverLogger = new Logger('server', 'gray', false);
|
||||
@ -73,15 +73,15 @@ router.use(nodeinfo.routes());
|
||||
router.use(wellKnown.routes());
|
||||
|
||||
router.get('/verify-email/:code', async ctx => {
|
||||
const user = await Users.findOne({
|
||||
const profile = await UserProfiles.findOne({
|
||||
emailVerifyCode: ctx.params.code
|
||||
});
|
||||
|
||||
if (user != null) {
|
||||
if (profile != null) {
|
||||
ctx.body = 'Verify succeeded!';
|
||||
ctx.status = 200;
|
||||
|
||||
Users.update(user.id, {
|
||||
UserProfiles.update({ userId: profile.userId }, {
|
||||
emailVerified: true,
|
||||
emailVerifyCode: null
|
||||
});
|
||||
|
@ -1,7 +1,7 @@
|
||||
import { Feed } from 'feed';
|
||||
import config from '../../config';
|
||||
import { User } from '../../models/entities/user';
|
||||
import { Notes, DriveFiles } from '../../models';
|
||||
import { Notes, DriveFiles, UserProfiles } from '../../models';
|
||||
import { In } from 'typeorm';
|
||||
|
||||
export default async function(user: User) {
|
||||
@ -10,6 +10,8 @@ export default async function(user: User) {
|
||||
name: user.name || user.username
|
||||
};
|
||||
|
||||
const profile = await UserProfiles.findOne({ userId: user.id });
|
||||
|
||||
const notes = await Notes.find({
|
||||
where: {
|
||||
userId: user.id,
|
||||
@ -25,7 +27,7 @@ export default async function(user: User) {
|
||||
title: `${author.name} (@${user.username}@${config.host})`,
|
||||
updated: notes[0].createdAt,
|
||||
generator: 'Misskey',
|
||||
description: `${user.notesCount} Notes, ${user.followingCount} Following, ${user.followersCount} Followers${user.description ? ` · ${user.description}` : ''}`,
|
||||
description: `${user.notesCount} Notes, ${user.followingCount} Following, ${user.followersCount} Followers${profile.description ? ` · ${profile.description}` : ''}`,
|
||||
link: author.link,
|
||||
image: user.avatarUrl,
|
||||
feedLinks: {
|
||||
|
@ -5,6 +5,7 @@ import { DriveFiles, Followings, Users, Notes } from '../../../../models';
|
||||
import { DriveFile } from '../../../../models/entities/drive-file';
|
||||
import { name, schema } from '../schemas/instance';
|
||||
import { Note } from '../../../../models/entities/note';
|
||||
import { toPuny } from '../../../../misc/convert-host';
|
||||
|
||||
type InstanceLog = SchemaType<typeof schema>;
|
||||
|
||||
@ -79,7 +80,7 @@ export default class InstanceChart extends Chart<InstanceLog> {
|
||||
requests: {
|
||||
received: 1
|
||||
}
|
||||
}, host);
|
||||
}, toPuny(host));
|
||||
}
|
||||
|
||||
@autobind
|
||||
@ -94,7 +95,7 @@ export default class InstanceChart extends Chart<InstanceLog> {
|
||||
|
||||
await this.inc({
|
||||
requests: update
|
||||
}, host);
|
||||
}, toPuny(host));
|
||||
}
|
||||
|
||||
@autobind
|
||||
@ -104,7 +105,7 @@ export default class InstanceChart extends Chart<InstanceLog> {
|
||||
total: 1,
|
||||
inc: 1
|
||||
}
|
||||
}, host);
|
||||
}, toPuny(host));
|
||||
}
|
||||
|
||||
@autobind
|
||||
@ -126,7 +127,7 @@ export default class InstanceChart extends Chart<InstanceLog> {
|
||||
dec: isAdditional ? 0 : 1,
|
||||
diffs: diffs
|
||||
}
|
||||
}, host);
|
||||
}, toPuny(host));
|
||||
}
|
||||
|
||||
@autobind
|
||||
@ -137,7 +138,7 @@ export default class InstanceChart extends Chart<InstanceLog> {
|
||||
inc: isAdditional ? 1 : 0,
|
||||
dec: isAdditional ? 0 : 1,
|
||||
}
|
||||
}, host);
|
||||
}, toPuny(host));
|
||||
}
|
||||
|
||||
@autobind
|
||||
@ -148,7 +149,7 @@ export default class InstanceChart extends Chart<InstanceLog> {
|
||||
inc: isAdditional ? 1 : 0,
|
||||
dec: isAdditional ? 0 : 1,
|
||||
}
|
||||
}, host);
|
||||
}, toPuny(host));
|
||||
}
|
||||
|
||||
@autobind
|
||||
|
@ -15,7 +15,7 @@ import { driveLogger } from './logger';
|
||||
import { IImage, ConvertToJpeg, ConvertToWebp, ConvertToPng } from './image-processor';
|
||||
import { contentDisposition } from '../../misc/content-disposition';
|
||||
import { detectMine } from '../../misc/detect-mine';
|
||||
import { DriveFiles, DriveFolders, Users, Instances } from '../../models';
|
||||
import { DriveFiles, DriveFolders, Users, Instances, UserProfiles } from '../../models';
|
||||
import { InternalStorage } from './internal-storage';
|
||||
import { DriveFile } from '../../models/entities/drive-file';
|
||||
import { IRemoteUser, User } from '../../models/entities/user';
|
||||
@ -365,6 +365,8 @@ export default async function(
|
||||
propPromises = [calcWh(), calcAvg()];
|
||||
}
|
||||
|
||||
const profile = await UserProfiles.findOne({ userId: user.id });
|
||||
|
||||
const [folder] = await Promise.all([fetchFolder(), Promise.all(propPromises)]);
|
||||
|
||||
let file = new DriveFile();
|
||||
@ -376,7 +378,7 @@ export default async function(
|
||||
file.comment = comment;
|
||||
file.properties = properties;
|
||||
file.isLink = isLink;
|
||||
file.isSensitive = Users.isLocalUser(user) && user.alwaysMarkNsfw ? true :
|
||||
file.isSensitive = Users.isLocalUser(user) && profile.alwaysMarkNsfw ? true :
|
||||
(sensitive !== null && sensitive !== undefined)
|
||||
? sensitive
|
||||
: false;
|
||||
|
@ -9,7 +9,7 @@ import { registerOrFetchInstanceDoc } from '../register-or-fetch-instance-doc';
|
||||
import Logger from '../logger';
|
||||
import { IdentifiableError } from '../../misc/identifiable-error';
|
||||
import { User } from '../../models/entities/user';
|
||||
import { Followings, Users, FollowRequests, Blockings, Instances } from '../../models';
|
||||
import { Followings, Users, FollowRequests, Blockings, Instances, UserProfiles } from '../../models';
|
||||
import { instanceChart, perUserFollowingChart } from '../chart';
|
||||
import { genId } from '../../misc/gen-id';
|
||||
import { createNotification } from '../create-notification';
|
||||
@ -115,11 +115,13 @@ export default async function(follower: User, followee: User, requestId?: string
|
||||
if (blocked != null) throw new IdentifiableError('3338392a-f764-498d-8855-db939dcf8c48', 'blocked');
|
||||
}
|
||||
|
||||
const followeeProfile = await UserProfiles.findOne({ userId: followee.id });
|
||||
|
||||
// フォロー対象が鍵アカウントである or
|
||||
// フォロワーがBotであり、フォロー対象がBotからのフォローに慎重である or
|
||||
// フォロワーがローカルユーザーであり、フォロー対象がリモートユーザーである
|
||||
// 上記のいずれかに当てはまる場合はすぐフォローせずにフォローリクエストを発行しておく
|
||||
if (followee.isLocked || (followee.carefulBot && follower.isBot) || (Users.isLocalUser(follower) && Users.isRemoteUser(followee))) {
|
||||
if (followee.isLocked || (followeeProfile.carefulBot && follower.isBot) || (Users.isLocalUser(follower) && Users.isRemoteUser(followee))) {
|
||||
let autoAccept = false;
|
||||
|
||||
// 鍵アカウントであっても、既にフォローされていた場合はスルー
|
||||
@ -132,7 +134,7 @@ export default async function(follower: User, followee: User, requestId?: string
|
||||
}
|
||||
|
||||
// フォローしているユーザーは自動承認オプション
|
||||
if (!autoAccept && (Users.isLocalUser(followee) && followee.autoAcceptFollowed)) {
|
||||
if (!autoAccept && (Users.isLocalUser(followee) && followeeProfile.autoAcceptFollowed)) {
|
||||
const followed = await Followings.findOne({
|
||||
followerId: followee.id,
|
||||
followeeId: follower.id
|
||||
|
@ -17,7 +17,7 @@ import extractMentions from '../../misc/extract-mentions';
|
||||
import extractEmojis from '../../misc/extract-emojis';
|
||||
import extractHashtags from '../../misc/extract-hashtags';
|
||||
import { Note } from '../../models/entities/note';
|
||||
import { Mutings, Users, NoteWatchings, Followings, Notes, Instances, Polls } from '../../models';
|
||||
import { Mutings, Users, NoteWatchings, Followings, Notes, Instances, Polls, UserProfiles } from '../../models';
|
||||
import { DriveFile } from '../../models/entities/drive-file';
|
||||
import { App } from '../../models/entities/app';
|
||||
import { Not } from 'typeorm';
|
||||
@ -256,13 +256,15 @@ export default async (user: User, data: Option, silent = false) => new Promise<N
|
||||
deliverNoteToMentionedRemoteUsers(mentionedUsers, user, noteActivity);
|
||||
}
|
||||
|
||||
const profile = await UserProfiles.findOne({ userId: user.id });
|
||||
|
||||
// If has in reply to note
|
||||
if (data.reply) {
|
||||
// Fetch watchers
|
||||
nmRelatedPromises.push(notifyToWatchersOfReplyee(data.reply, user, nm));
|
||||
|
||||
// この投稿をWatchする
|
||||
if (Users.isLocalUser(user) && user.autoWatch !== false) {
|
||||
if (Users.isLocalUser(user) && profile.autoWatch) {
|
||||
watch(user.id, data.reply);
|
||||
}
|
||||
|
||||
@ -286,7 +288,7 @@ export default async (user: User, data: Option, silent = false) => new Promise<N
|
||||
nmRelatedPromises.push(notifyToWatchersOfRenotee(data.renote, user, nm, type));
|
||||
|
||||
// この投稿をWatchする
|
||||
if (Users.isLocalUser(user) && user.autoWatch !== false) {
|
||||
if (Users.isLocalUser(user) && profile.autoWatch) {
|
||||
watch(user.id, data.renote);
|
||||
}
|
||||
|
||||
@ -396,7 +398,6 @@ async function insertNote(user: User, data: Option, tags: string[], emojis: stri
|
||||
|
||||
if (note.hasPoll) {
|
||||
await Polls.save({
|
||||
id: genId(),
|
||||
noteId: note.id,
|
||||
choices: data.poll.choices,
|
||||
expiresAt: data.poll.expiresAt,
|
||||
|
@ -2,7 +2,7 @@ import watch from '../../../services/note/watch';
|
||||
import { publishNoteStream } from '../../stream';
|
||||
import { User } from '../../../models/entities/user';
|
||||
import { Note } from '../../../models/entities/note';
|
||||
import { PollVotes, Users, NoteWatchings, Polls } from '../../../models';
|
||||
import { PollVotes, Users, NoteWatchings, Polls, UserProfiles } from '../../../models';
|
||||
import { Not } from 'typeorm';
|
||||
import { genId } from '../../../misc/gen-id';
|
||||
import { createNotification } from '../../create-notification';
|
||||
@ -40,7 +40,7 @@ export default (user: User, note: Note, choice: number) => new Promise(async (re
|
||||
|
||||
// Increment votes count
|
||||
const index = choice + 1; // In SQL, array index is 1 based
|
||||
await Polls.query(`UPDATE poll SET votes[${index}] = votes[${index}] + 1 WHERE id = '${poll.id}'`);
|
||||
await Polls.query(`UPDATE poll SET votes[${index}] = votes[${index}] + 1 WHERE noteId = '${poll.noteId}'`);
|
||||
|
||||
publishNoteStream(note.id, 'pollVoted', {
|
||||
choice: choice,
|
||||
@ -67,8 +67,10 @@ export default (user: User, note: Note, choice: number) => new Promise(async (re
|
||||
}
|
||||
});
|
||||
|
||||
const profile = await UserProfiles.findOne({ userId: user.id });
|
||||
|
||||
// ローカルユーザーが投票した場合この投稿をWatchする
|
||||
if (Users.isLocalUser(user) && user.autoWatch) {
|
||||
if (Users.isLocalUser(user) && profile.autoWatch) {
|
||||
watch(user.id, note);
|
||||
}
|
||||
});
|
||||
|
@ -8,7 +8,7 @@ import { toDbReaction } from '../../../misc/reaction-lib';
|
||||
import fetchMeta from '../../../misc/fetch-meta';
|
||||
import { User } from '../../../models/entities/user';
|
||||
import { Note } from '../../../models/entities/note';
|
||||
import { NoteReactions, Users, NoteWatchings, Notes } from '../../../models';
|
||||
import { NoteReactions, Users, NoteWatchings, Notes, UserProfiles } from '../../../models';
|
||||
import { Not } from 'typeorm';
|
||||
import { perUserReactionsChart } from '../../chart';
|
||||
import { genId } from '../../../misc/gen-id';
|
||||
@ -79,8 +79,10 @@ export default async (user: User, note: Note, reaction: string) => {
|
||||
}
|
||||
});
|
||||
|
||||
const profile = await UserProfiles.findOne({ userId: user.id });
|
||||
|
||||
// ユーザーがローカルユーザーかつ自動ウォッチ設定がオンならばこの投稿をWatchする
|
||||
if (Users.isLocalUser(user) && user.autoWatch !== false) {
|
||||
if (Users.isLocalUser(user) && profile.autoWatch) {
|
||||
watch(user.id, note);
|
||||
}
|
||||
|
||||
|
Reference in New Issue
Block a user