yatta
This commit is contained in:
parent
80e5645a84
commit
e66d7babc5
|
@ -1,4 +1,4 @@
|
||||||
import { IUser } from "../models/user";
|
import { IUser } from '../models/user';
|
||||||
|
|
||||||
export default (user: IUser) => {
|
export default (user: IUser) => {
|
||||||
return user.host === null ? user.username : `${user.username}@${user.host}`;
|
return user.host === null ? user.username : `${user.username}@${user.host}`;
|
||||||
|
|
|
@ -48,7 +48,7 @@ export default class Replacer {
|
||||||
if (error) {
|
if (error) {
|
||||||
console.warn(`key '${key}' not found in '${path}' of '${this.lang}'`);
|
console.warn(`key '${key}' not found in '${path}' of '${this.lang}'`);
|
||||||
return key; // Fallback
|
return key; // Fallback
|
||||||
} else if (typeof text !== "string") {
|
} else if (typeof text !== 'string') {
|
||||||
console.warn(`key '${key}' is not string in '${path}' of '${this.lang}'`);
|
console.warn(`key '${key}' is not string in '${path}' of '${this.lang}'`);
|
||||||
return key; // Fallback
|
return key; // Fallback
|
||||||
} else {
|
} else {
|
||||||
|
|
|
@ -220,7 +220,7 @@ export const pack = async (
|
||||||
hide = false;
|
hide = false;
|
||||||
} else {
|
} else {
|
||||||
// 指定されているかどうか
|
// 指定されているかどうか
|
||||||
const specified = _note.visibleUserIds.some(id => id.equals(meId));
|
const specified = _note.visibleUserIds.some((id: mongo.ObjectID) => id.equals(meId));
|
||||||
|
|
||||||
if (specified) {
|
if (specified) {
|
||||||
hide = false;
|
hide = false;
|
||||||
|
@ -272,7 +272,7 @@ export const pack = async (
|
||||||
}
|
}
|
||||||
|
|
||||||
// Populate media
|
// Populate media
|
||||||
_note.media = hide ? [] : Promise.all(_note.mediaIds.map(fileId =>
|
_note.media = hide ? [] : Promise.all(_note.mediaIds.map((fileId: mongo.ObjectID) =>
|
||||||
packFile(fileId)
|
packFile(fileId)
|
||||||
));
|
));
|
||||||
|
|
||||||
|
|
|
@ -1,6 +1,6 @@
|
||||||
import * as mongo from 'mongodb';
|
import * as mongo from 'mongodb';
|
||||||
const deepcopy = require('deepcopy');
|
const deepcopy = require('deepcopy');
|
||||||
import sequential = require('promise-sequential');
|
const sequential = require('promise-sequential');
|
||||||
import rap from '@prezzemolo/rap';
|
import rap from '@prezzemolo/rap';
|
||||||
import db from '../db/mongodb';
|
import db from '../db/mongodb';
|
||||||
import Note, { pack as packNote, deleteNote } from './note';
|
import Note, { pack as packNote, deleteNote } from './note';
|
||||||
|
|
|
@ -1,6 +1,6 @@
|
||||||
import * as nopt from 'nopt';
|
import * as nopt from 'nopt';
|
||||||
|
|
||||||
export default (vector, index) => {
|
export default (vector: any, index: any) => {
|
||||||
const parsed = nopt({
|
const parsed = nopt({
|
||||||
'only-processor': Boolean,
|
'only-processor': Boolean,
|
||||||
'only-server': Boolean
|
'only-server': Boolean
|
||||||
|
|
|
@ -11,7 +11,7 @@ if (config.sw) {
|
||||||
config.sw.private_key);
|
config.sw.private_key);
|
||||||
}
|
}
|
||||||
|
|
||||||
export default async function(userId: mongo.ObjectID | string, type, body?) {
|
export default async function(userId: mongo.ObjectID | string, type: string, body?: any) {
|
||||||
if (!config.sw) return;
|
if (!config.sw) return;
|
||||||
|
|
||||||
if (typeof userId === 'string') {
|
if (typeof userId === 'string') {
|
||||||
|
@ -34,7 +34,7 @@ export default async function(userId: mongo.ObjectID | string, type, body?) {
|
||||||
|
|
||||||
push.sendNotification(pushSubscription, JSON.stringify({
|
push.sendNotification(pushSubscription, JSON.stringify({
|
||||||
type, body
|
type, body
|
||||||
})).catch(err => {
|
})).catch((err: any) => {
|
||||||
//console.log(err.statusCode);
|
//console.log(err.statusCode);
|
||||||
//console.log(err.headers);
|
//console.log(err.headers);
|
||||||
//console.log(err.body);
|
//console.log(err.body);
|
||||||
|
|
|
@ -12,7 +12,7 @@ const queue = createQueue({
|
||||||
}
|
}
|
||||||
});
|
});
|
||||||
|
|
||||||
export function createHttp(data) {
|
export function createHttp(data: any) {
|
||||||
return queue
|
return queue
|
||||||
.create('http', data)
|
.create('http', data)
|
||||||
.removeOnComplete(true)
|
.removeOnComplete(true)
|
||||||
|
@ -21,7 +21,7 @@ export function createHttp(data) {
|
||||||
.backoff({ delay: 16384, type: 'exponential' });
|
.backoff({ delay: 16384, type: 'exponential' });
|
||||||
}
|
}
|
||||||
|
|
||||||
export function deliver(user: ILocalUser, content, to) {
|
export function deliver(user: ILocalUser, content: any, to: any) {
|
||||||
createHttp({
|
createHttp({
|
||||||
title: 'deliver',
|
title: 'deliver',
|
||||||
type: 'deliver',
|
type: 'deliver',
|
||||||
|
|
|
@ -2,7 +2,7 @@ import * as kue from 'kue';
|
||||||
|
|
||||||
import request from '../../../remote/activitypub/request';
|
import request from '../../../remote/activitypub/request';
|
||||||
|
|
||||||
export default async (job: kue.Job, done): Promise<void> => {
|
export default async (job: kue.Job, done: any): Promise<void> => {
|
||||||
try {
|
try {
|
||||||
await request(job.data.user, job.data.to, job.data.content);
|
await request(job.data.user, job.data.to, job.data.content);
|
||||||
done();
|
done();
|
||||||
|
|
|
@ -1,12 +1,12 @@
|
||||||
import deliver from './deliver';
|
import deliver from './deliver';
|
||||||
import processInbox from './process-inbox';
|
import processInbox from './process-inbox';
|
||||||
|
|
||||||
const handlers = {
|
const handlers: any = {
|
||||||
deliver,
|
deliver,
|
||||||
processInbox,
|
processInbox,
|
||||||
};
|
};
|
||||||
|
|
||||||
export default (job, done) => {
|
export default (job: any, done: any) => {
|
||||||
const handler = handlers[job.data.type];
|
const handler = handlers[job.data.type];
|
||||||
|
|
||||||
if (handler) {
|
if (handler) {
|
||||||
|
|
|
@ -10,7 +10,7 @@ import { resolvePerson } from '../../../remote/activitypub/models/person';
|
||||||
const log = debug('misskey:queue:inbox');
|
const log = debug('misskey:queue:inbox');
|
||||||
|
|
||||||
// ユーザーのinboxにアクティビティが届いた時の処理
|
// ユーザーのinboxにアクティビティが届いた時の処理
|
||||||
export default async (job: kue.Job, done): Promise<void> => {
|
export default async (job: kue.Job, done: any): Promise<void> => {
|
||||||
const signature = job.data.signature;
|
const signature = job.data.signature;
|
||||||
const activity = job.data.activity;
|
const activity = job.data.activity;
|
||||||
|
|
||||||
|
@ -22,7 +22,7 @@ export default async (job: kue.Job, done): Promise<void> => {
|
||||||
//#endregion
|
//#endregion
|
||||||
|
|
||||||
const keyIdLower = signature.keyId.toLowerCase();
|
const keyIdLower = signature.keyId.toLowerCase();
|
||||||
let user;
|
let user: IRemoteUser;
|
||||||
|
|
||||||
if (keyIdLower.startsWith('acct:')) {
|
if (keyIdLower.startsWith('acct:')) {
|
||||||
const { username, host } = parseAcct(keyIdLower.slice('acct:'.length));
|
const { username, host } = parseAcct(keyIdLower.slice('acct:'.length));
|
||||||
|
@ -36,7 +36,7 @@ export default async (job: kue.Job, done): Promise<void> => {
|
||||||
|
|
||||||
// アクティビティを送信してきたユーザーがまだMisskeyサーバーに登録されていなかったら登録する
|
// アクティビティを送信してきたユーザーがまだMisskeyサーバーに登録されていなかったら登録する
|
||||||
if (user === null) {
|
if (user === null) {
|
||||||
user = await resolvePerson(activity.actor);
|
user = await resolvePerson(activity.actor) as IRemoteUser;
|
||||||
}
|
}
|
||||||
} else {
|
} else {
|
||||||
user = await User.findOne({
|
user = await User.findOne({
|
||||||
|
@ -46,7 +46,7 @@ export default async (job: kue.Job, done): Promise<void> => {
|
||||||
|
|
||||||
// アクティビティを送信してきたユーザーがまだMisskeyサーバーに登録されていなかったら登録する
|
// アクティビティを送信してきたユーザーがまだMisskeyサーバーに登録されていなかったら登録する
|
||||||
if (user === null) {
|
if (user === null) {
|
||||||
user = await resolvePerson(signature.keyId);
|
user = await resolvePerson(signature.keyId) as IRemoteUser;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
|
@ -3,7 +3,7 @@ import * as debug from 'debug';
|
||||||
import Resolver from '../../resolver';
|
import Resolver from '../../resolver';
|
||||||
import { IRemoteUser } from '../../../../models/user';
|
import { IRemoteUser } from '../../../../models/user';
|
||||||
import acceptFollow from './follow';
|
import acceptFollow from './follow';
|
||||||
import { IAccept } from '../../type';
|
import { IAccept, IFollow } from '../../type';
|
||||||
|
|
||||||
const log = debug('misskey:activitypub');
|
const log = debug('misskey:activitypub');
|
||||||
|
|
||||||
|
@ -25,7 +25,7 @@ export default async (actor: IRemoteUser, activity: IAccept): Promise<void> => {
|
||||||
|
|
||||||
switch (object.type) {
|
switch (object.type) {
|
||||||
case 'Follow':
|
case 'Follow':
|
||||||
acceptFollow(actor, object);
|
acceptFollow(actor, object as IFollow);
|
||||||
break;
|
break;
|
||||||
|
|
||||||
default:
|
default:
|
||||||
|
|
|
@ -3,7 +3,7 @@ import * as debug from 'debug';
|
||||||
import Resolver from '../../resolver';
|
import Resolver from '../../resolver';
|
||||||
import { IRemoteUser } from '../../../../models/user';
|
import { IRemoteUser } from '../../../../models/user';
|
||||||
import announceNote from './note';
|
import announceNote from './note';
|
||||||
import { IAnnounce } from '../../type';
|
import { IAnnounce, INote } from '../../type';
|
||||||
|
|
||||||
const log = debug('misskey:activitypub');
|
const log = debug('misskey:activitypub');
|
||||||
|
|
||||||
|
@ -25,7 +25,7 @@ export default async (actor: IRemoteUser, activity: IAnnounce): Promise<void> =>
|
||||||
|
|
||||||
switch (object.type) {
|
switch (object.type) {
|
||||||
case 'Note':
|
case 'Note':
|
||||||
announceNote(resolver, actor, activity, object);
|
announceNote(resolver, actor, activity, object as INote);
|
||||||
break;
|
break;
|
||||||
|
|
||||||
default:
|
default:
|
||||||
|
|
|
@ -2,7 +2,7 @@ import * as debug from 'debug';
|
||||||
|
|
||||||
import Resolver from '../../resolver';
|
import Resolver from '../../resolver';
|
||||||
import post from '../../../../services/note/create';
|
import post from '../../../../services/note/create';
|
||||||
import { IRemoteUser } from '../../../../models/user';
|
import { IRemoteUser, IUser } from '../../../../models/user';
|
||||||
import { IAnnounce, INote } from '../../type';
|
import { IAnnounce, INote } from '../../type';
|
||||||
import { fetchNote, resolveNote } from '../../models/note';
|
import { fetchNote, resolveNote } from '../../models/note';
|
||||||
import { resolvePerson } from '../../models/person';
|
import { resolvePerson } from '../../models/person';
|
||||||
|
@ -36,7 +36,7 @@ export default async function(resolver: Resolver, actor: IRemoteUser, activity:
|
||||||
|
|
||||||
//#region Visibility
|
//#region Visibility
|
||||||
let visibility = 'public';
|
let visibility = 'public';
|
||||||
let visibleUsers = [];
|
let visibleUsers: IUser[] = [];
|
||||||
if (!note.to.includes('https://www.w3.org/ns/activitystreams#Public')) {
|
if (!note.to.includes('https://www.w3.org/ns/activitystreams#Public')) {
|
||||||
if (note.cc.includes('https://www.w3.org/ns/activitystreams#Public')) {
|
if (note.cc.includes('https://www.w3.org/ns/activitystreams#Public')) {
|
||||||
visibility = 'home';
|
visibility = 'home';
|
||||||
|
|
|
@ -1,6 +1,6 @@
|
||||||
import { IRemoteUser } from '../../../../models/user';
|
import { IRemoteUser } from '../../../../models/user';
|
||||||
import { createImage } from '../../models/image';
|
import { createImage } from '../../models/image';
|
||||||
|
|
||||||
export default async function(actor: IRemoteUser, image): Promise<void> {
|
export default async function(actor: IRemoteUser, image: any): Promise<void> {
|
||||||
await createImage(image.url, actor);
|
await createImage(image.url, actor);
|
||||||
}
|
}
|
||||||
|
|
|
@ -5,7 +5,7 @@ import { createNote, fetchNote } from '../../models/note';
|
||||||
/**
|
/**
|
||||||
* 投稿作成アクティビティを捌きます
|
* 投稿作成アクティビティを捌きます
|
||||||
*/
|
*/
|
||||||
export default async function(resolver: Resolver, actor: IRemoteUser, note, silent = false): Promise<void> {
|
export default async function(resolver: Resolver, actor: IRemoteUser, note: any, silent = false): Promise<void> {
|
||||||
const exist = await fetchNote(note);
|
const exist = await fetchNote(note);
|
||||||
if (exist == null) {
|
if (exist == null) {
|
||||||
await createNote(note);
|
await createNote(note);
|
||||||
|
|
|
@ -2,11 +2,12 @@ import Resolver from '../../resolver';
|
||||||
import deleteNote from './note';
|
import deleteNote from './note';
|
||||||
import Note from '../../../../models/note';
|
import Note from '../../../../models/note';
|
||||||
import { IRemoteUser } from '../../../../models/user';
|
import { IRemoteUser } from '../../../../models/user';
|
||||||
|
import { IDelete } from '../../type';
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* 削除アクティビティを捌きます
|
* 削除アクティビティを捌きます
|
||||||
*/
|
*/
|
||||||
export default async (actor: IRemoteUser, activity): Promise<void> => {
|
export default async (actor: IRemoteUser, activity: IDelete): Promise<void> => {
|
||||||
if ('actor' in activity && actor.uri !== activity.actor) {
|
if ('actor' in activity && actor.uri !== activity.actor) {
|
||||||
throw new Error('invalid actor');
|
throw new Error('invalid actor');
|
||||||
}
|
}
|
||||||
|
|
|
@ -3,7 +3,7 @@ import * as debug from 'debug';
|
||||||
import Resolver from '../../resolver';
|
import Resolver from '../../resolver';
|
||||||
import { IRemoteUser } from '../../../../models/user';
|
import { IRemoteUser } from '../../../../models/user';
|
||||||
import rejectFollow from './follow';
|
import rejectFollow from './follow';
|
||||||
import { IReject } from '../../type';
|
import { IReject, IFollow } from '../../type';
|
||||||
|
|
||||||
const log = debug('misskey:activitypub');
|
const log = debug('misskey:activitypub');
|
||||||
|
|
||||||
|
@ -25,7 +25,7 @@ export default async (actor: IRemoteUser, activity: IReject): Promise<void> => {
|
||||||
|
|
||||||
switch (object.type) {
|
switch (object.type) {
|
||||||
case 'Follow':
|
case 'Follow':
|
||||||
rejectFollow(actor, object);
|
rejectFollow(actor, object as IFollow);
|
||||||
break;
|
break;
|
||||||
|
|
||||||
default:
|
default:
|
||||||
|
|
|
@ -1,7 +1,7 @@
|
||||||
import * as debug from 'debug';
|
import * as debug from 'debug';
|
||||||
|
|
||||||
import { IRemoteUser } from '../../../../models/user';
|
import { IRemoteUser } from '../../../../models/user';
|
||||||
import { IUndo } from '../../type';
|
import { IUndo, IFollow } from '../../type';
|
||||||
import unfollow from './follow';
|
import unfollow from './follow';
|
||||||
import Resolver from '../../resolver';
|
import Resolver from '../../resolver';
|
||||||
|
|
||||||
|
@ -29,7 +29,7 @@ export default async (actor: IRemoteUser, activity: IUndo): Promise<void> => {
|
||||||
|
|
||||||
switch (object.type) {
|
switch (object.type) {
|
||||||
case 'Follow':
|
case 'Follow':
|
||||||
unfollow(actor, object);
|
unfollow(actor, object as IFollow);
|
||||||
break;
|
break;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
|
@ -1,4 +1,4 @@
|
||||||
import { INote } from "../../../models/note";
|
import { INote } from '../../../models/note';
|
||||||
import toHtml from '../../../text/html';
|
import toHtml from '../../../text/html';
|
||||||
import parse from '../../../text/parse';
|
import parse from '../../../text/parse';
|
||||||
import config from '../../../config';
|
import config from '../../../config';
|
||||||
|
|
|
@ -10,7 +10,7 @@ const log = debug('misskey:activitypub');
|
||||||
/**
|
/**
|
||||||
* Imageを作成します。
|
* Imageを作成します。
|
||||||
*/
|
*/
|
||||||
export async function createImage(actor: IRemoteUser, value): Promise<IDriveFile> {
|
export async function createImage(actor: IRemoteUser, value: any): Promise<IDriveFile> {
|
||||||
// 投稿者が凍結されていたらスキップ
|
// 投稿者が凍結されていたらスキップ
|
||||||
if (actor.isSuspended) {
|
if (actor.isSuspended) {
|
||||||
return null;
|
return null;
|
||||||
|
|
|
@ -1,5 +1,5 @@
|
||||||
import * as mongo from 'mongodb';
|
import * as mongo from 'mongodb';
|
||||||
import * as parse5 from 'parse5';
|
const parse5 = require('parse5');
|
||||||
import * as debug from 'debug';
|
import * as debug from 'debug';
|
||||||
|
|
||||||
import config from '../../../config';
|
import config from '../../../config';
|
||||||
|
@ -9,30 +9,30 @@ import post from '../../../services/note/create';
|
||||||
import { INote as INoteActivityStreamsObject, IObject } from '../type';
|
import { INote as INoteActivityStreamsObject, IObject } from '../type';
|
||||||
import { resolvePerson, updatePerson } from './person';
|
import { resolvePerson, updatePerson } from './person';
|
||||||
import { resolveImage } from './image';
|
import { resolveImage } from './image';
|
||||||
import { IRemoteUser } from '../../../models/user';
|
import { IRemoteUser, IUser } from '../../../models/user';
|
||||||
|
|
||||||
const log = debug('misskey:activitypub');
|
const log = debug('misskey:activitypub');
|
||||||
|
|
||||||
function parse(html: string): string {
|
function parse(html: string): string {
|
||||||
const dom = parse5.parseFragment(html) as parse5.AST.Default.Document;
|
const dom = parse5.parseFragment(html);
|
||||||
|
|
||||||
let text = '';
|
let text = '';
|
||||||
|
|
||||||
dom.childNodes.forEach(n => analyze(n));
|
dom.childNodes.forEach((n: any) => analyze(n));
|
||||||
|
|
||||||
return text.trim();
|
return text.trim();
|
||||||
|
|
||||||
function getText(node) {
|
function getText(node: any) {
|
||||||
if (node.nodeName == '#text') return node.value;
|
if (node.nodeName == '#text') return node.value;
|
||||||
|
|
||||||
if (node.childNodes) {
|
if (node.childNodes) {
|
||||||
return node.childNodes.map(n => getText(n)).join('');
|
return node.childNodes.map((n: any) => getText(n)).join('');
|
||||||
}
|
}
|
||||||
|
|
||||||
return '';
|
return '';
|
||||||
}
|
}
|
||||||
|
|
||||||
function analyze(node) {
|
function analyze(node: any) {
|
||||||
switch (node.nodeName) {
|
switch (node.nodeName) {
|
||||||
case '#text':
|
case '#text':
|
||||||
text += node.value;
|
text += node.value;
|
||||||
|
@ -51,7 +51,7 @@ function parse(html: string): string {
|
||||||
|
|
||||||
if (part.length == 2) {
|
if (part.length == 2) {
|
||||||
//#region ホスト名部分が省略されているので復元する
|
//#region ホスト名部分が省略されているので復元する
|
||||||
const href = new URL(node.attrs.find(x => x.name == 'href').value);
|
const href = new URL(node.attrs.find((x: any) => x.name == 'href').value);
|
||||||
const acct = txt + '@' + href.hostname;
|
const acct = txt + '@' + href.hostname;
|
||||||
text += acct;
|
text += acct;
|
||||||
break;
|
break;
|
||||||
|
@ -63,20 +63,20 @@ function parse(html: string): string {
|
||||||
}
|
}
|
||||||
|
|
||||||
if (node.childNodes) {
|
if (node.childNodes) {
|
||||||
node.childNodes.forEach(n => analyze(n));
|
node.childNodes.forEach((n: any) => analyze(n));
|
||||||
}
|
}
|
||||||
break;
|
break;
|
||||||
|
|
||||||
case 'p':
|
case 'p':
|
||||||
text += '\n\n';
|
text += '\n\n';
|
||||||
if (node.childNodes) {
|
if (node.childNodes) {
|
||||||
node.childNodes.forEach(n => analyze(n));
|
node.childNodes.forEach((n: any) => analyze(n));
|
||||||
}
|
}
|
||||||
break;
|
break;
|
||||||
|
|
||||||
default:
|
default:
|
||||||
if (node.childNodes) {
|
if (node.childNodes) {
|
||||||
node.childNodes.forEach(n => analyze(n));
|
node.childNodes.forEach((n: any) => analyze(n));
|
||||||
}
|
}
|
||||||
break;
|
break;
|
||||||
}
|
}
|
||||||
|
@ -135,7 +135,7 @@ export async function createNote(value: any, resolver?: Resolver, silent = false
|
||||||
|
|
||||||
//#region Visibility
|
//#region Visibility
|
||||||
let visibility = 'public';
|
let visibility = 'public';
|
||||||
let visibleUsers = [];
|
let visibleUsers: IUser[] = [];
|
||||||
if (!note.to.includes('https://www.w3.org/ns/activitystreams#Public')) {
|
if (!note.to.includes('https://www.w3.org/ns/activitystreams#Public')) {
|
||||||
if (note.cc.includes('https://www.w3.org/ns/activitystreams#Public')) {
|
if (note.cc.includes('https://www.w3.org/ns/activitystreams#Public')) {
|
||||||
visibility = 'home';
|
visibility = 'home';
|
||||||
|
|
|
@ -1,4 +1,4 @@
|
||||||
export default object => ({
|
export default (object: any) => ({
|
||||||
type: 'Accept',
|
type: 'Accept',
|
||||||
object
|
object
|
||||||
});
|
});
|
||||||
|
|
|
@ -1,4 +1,4 @@
|
||||||
export default object => ({
|
export default (object: any) => ({
|
||||||
type: 'Announce',
|
type: 'Announce',
|
||||||
object
|
object
|
||||||
});
|
});
|
||||||
|
|
|
@ -1,4 +1,4 @@
|
||||||
export default object => ({
|
export default (object: any) => ({
|
||||||
type: 'Create',
|
type: 'Create',
|
||||||
object
|
object
|
||||||
});
|
});
|
||||||
|
|
|
@ -1,4 +1,4 @@
|
||||||
export default object => ({
|
export default (object: any) => ({
|
||||||
type: 'Delete',
|
type: 'Delete',
|
||||||
object
|
object
|
||||||
});
|
});
|
||||||
|
|
|
@ -1,7 +1,8 @@
|
||||||
import config from '../../../config';
|
import config from '../../../config';
|
||||||
|
import { IDriveFile } from '../../../models/drive-file';
|
||||||
|
|
||||||
export default ({ _id, contentType }) => ({
|
export default (file: IDriveFile) => ({
|
||||||
type: 'Document',
|
type: 'Document',
|
||||||
mediaType: contentType,
|
mediaType: file.contentType,
|
||||||
url: `${config.drive_url}/${_id}`
|
url: `${config.drive_url}/${file._id}`
|
||||||
});
|
});
|
||||||
|
|
|
@ -1,6 +1,7 @@
|
||||||
import config from '../../../config';
|
import config from '../../../config';
|
||||||
|
import { IDriveFile } from '../../../models/drive-file';
|
||||||
|
|
||||||
export default ({ _id }) => ({
|
export default (fileId: IDriveFile['_id']) => ({
|
||||||
type: 'Image',
|
type: 'Image',
|
||||||
url: `${config.drive_url}/${_id}`
|
url: `${config.drive_url}/${fileId}`
|
||||||
});
|
});
|
||||||
|
|
|
@ -1,7 +1,8 @@
|
||||||
import config from '../../../config';
|
import config from '../../../config';
|
||||||
import { ILocalUser } from '../../../models/user';
|
import { ILocalUser } from '../../../models/user';
|
||||||
|
import { INote } from '../../../models/note';
|
||||||
|
|
||||||
export default (user: ILocalUser, note, reaction: string) => ({
|
export default (user: ILocalUser, note: INote, reaction: string) => ({
|
||||||
type: 'Like',
|
type: 'Like',
|
||||||
actor: `${config.url}/users/${user._id}`,
|
actor: `${config.url}/users/${user._id}`,
|
||||||
object: note.uri ? note.uri : `${config.url}/notes/${note._id}`,
|
object: note.uri ? note.uri : `${config.url}/notes/${note._id}`,
|
||||||
|
|
|
@ -1,5 +1,5 @@
|
||||||
import { IUser, isRemoteUser } from "../../../models/user";
|
import { IUser, isRemoteUser } from '../../../models/user';
|
||||||
import config from "../../../config";
|
import config from '../../../config';
|
||||||
|
|
||||||
export default (mention: IUser) => ({
|
export default (mention: IUser) => ({
|
||||||
type: 'Mention',
|
type: 'Mention',
|
||||||
|
|
|
@ -2,13 +2,13 @@ import renderDocument from './document';
|
||||||
import renderHashtag from './hashtag';
|
import renderHashtag from './hashtag';
|
||||||
import renderMention from './mention';
|
import renderMention from './mention';
|
||||||
import config from '../../../config';
|
import config from '../../../config';
|
||||||
import DriveFile from '../../../models/drive-file';
|
import DriveFile, { IDriveFile } from '../../../models/drive-file';
|
||||||
import Note, { INote } from '../../../models/note';
|
import Note, { INote } from '../../../models/note';
|
||||||
import User from '../../../models/user';
|
import User from '../../../models/user';
|
||||||
import toHtml from '../misc/get-note-html';
|
import toHtml from '../misc/get-note-html';
|
||||||
|
|
||||||
export default async function renderNote(note: INote, dive = true) {
|
export default async function renderNote(note: INote, dive = true): Promise<any> {
|
||||||
const promisedFiles = note.mediaIds
|
const promisedFiles: Promise<IDriveFile[]> = note.mediaIds
|
||||||
? DriveFile.find({ _id: { $in: note.mediaIds } })
|
? DriveFile.find({ _id: { $in: note.mediaIds } })
|
||||||
: Promise.resolve([]);
|
: Promise.resolve([]);
|
||||||
|
|
||||||
|
|
|
@ -16,8 +16,8 @@ export default (user: ILocalUser) => {
|
||||||
preferredUsername: user.username,
|
preferredUsername: user.username,
|
||||||
name: user.name,
|
name: user.name,
|
||||||
summary: user.description,
|
summary: user.description,
|
||||||
icon: user.avatarId && renderImage({ _id: user.avatarId }),
|
icon: user.avatarId && renderImage(user.avatarId),
|
||||||
image: user.bannerId && renderImage({ _id: user.bannerId }),
|
image: user.bannerId && renderImage(user.bannerId),
|
||||||
manuallyApprovesFollowers: user.isLocked,
|
manuallyApprovesFollowers: user.isLocked,
|
||||||
publicKey: renderKey(user)
|
publicKey: renderKey(user)
|
||||||
};
|
};
|
||||||
|
|
|
@ -1,4 +1,4 @@
|
||||||
export default object => ({
|
export default (object: any) => ({
|
||||||
type: 'Undo',
|
type: 'Undo',
|
||||||
object
|
object
|
||||||
});
|
});
|
||||||
|
|
|
@ -12,7 +12,7 @@ export default class Resolver {
|
||||||
this.history = new Set();
|
this.history = new Set();
|
||||||
}
|
}
|
||||||
|
|
||||||
public async resolveCollection(value) {
|
public async resolveCollection(value: any) {
|
||||||
const collection = typeof value === 'string'
|
const collection = typeof value === 'string'
|
||||||
? await this.resolve(value)
|
? await this.resolve(value)
|
||||||
: value;
|
: value;
|
||||||
|
@ -33,7 +33,7 @@ export default class Resolver {
|
||||||
return collection;
|
return collection;
|
||||||
}
|
}
|
||||||
|
|
||||||
public async resolve(value): Promise<IObject> {
|
public async resolve(value: any): Promise<IObject> {
|
||||||
if (value == null) {
|
if (value == null) {
|
||||||
throw new Error('resolvee is null (or undefined)');
|
throw new Error('resolvee is null (or undefined)');
|
||||||
}
|
}
|
||||||
|
|
|
@ -4,7 +4,7 @@ import webFinger from './webfinger';
|
||||||
import config from '../config';
|
import config from '../config';
|
||||||
import { createPerson } from './activitypub/models/person';
|
import { createPerson } from './activitypub/models/person';
|
||||||
|
|
||||||
export default async (username, _host, option?): Promise<IUser> => {
|
export default async (username: string, _host: string, option?: any): Promise<IUser> => {
|
||||||
const usernameLower = username.toLowerCase();
|
const usernameLower = username.toLowerCase();
|
||||||
|
|
||||||
if (_host == null) {
|
if (_host == null) {
|
||||||
|
|
|
@ -49,13 +49,13 @@ module.exports = (params: any) => new Promise(async (res, rej) => {
|
||||||
} }
|
} }
|
||||||
]);
|
]);
|
||||||
|
|
||||||
datas.forEach(data => {
|
datas.forEach((data: any) => {
|
||||||
data.date = data._id;
|
data.date = data._id;
|
||||||
delete data._id;
|
delete data._id;
|
||||||
|
|
||||||
data.notes = (data.data.filter(x => x.type == 'note')[0] || { count: 0 }).count;
|
data.notes = (data.data.filter((x: any) => x.type == 'note')[0] || { count: 0 }).count;
|
||||||
data.renotes = (data.data.filter(x => x.type == 'renote')[0] || { count: 0 }).count;
|
data.renotes = (data.data.filter((x: any) => x.type == 'renote')[0] || { count: 0 }).count;
|
||||||
data.replies = (data.data.filter(x => x.type == 'reply')[0] || { count: 0 }).count;
|
data.replies = (data.data.filter((x: any) => x.type == 'reply')[0] || { count: 0 }).count;
|
||||||
|
|
||||||
delete data.data;
|
delete data.data;
|
||||||
});
|
});
|
||||||
|
@ -65,7 +65,7 @@ module.exports = (params: any) => new Promise(async (res, rej) => {
|
||||||
for (let i = 0; i < limit; i++) {
|
for (let i = 0; i < limit; i++) {
|
||||||
const day = new Date(new Date().setDate(new Date().getDate() - i));
|
const day = new Date(new Date().setDate(new Date().getDate() - i));
|
||||||
|
|
||||||
const data = datas.filter(d =>
|
const data = datas.filter((d: any) =>
|
||||||
d.date.year == day.getFullYear() && d.date.month == day.getMonth() + 1 && d.date.day == day.getDate()
|
d.date.year == day.getFullYear() && d.date.month == day.getMonth() + 1 && d.date.day == day.getDate()
|
||||||
)[0];
|
)[0];
|
||||||
|
|
||||||
|
|
|
@ -4,11 +4,12 @@
|
||||||
import $ from 'cafy'; import ID from '../../../../../cafy-id';
|
import $ from 'cafy'; import ID from '../../../../../cafy-id';
|
||||||
import { pack } from '../../../../../models/drive-file';
|
import { pack } from '../../../../../models/drive-file';
|
||||||
import uploadFromUrl from '../../../../../services/drive/upload-from-url';
|
import uploadFromUrl from '../../../../../services/drive/upload-from-url';
|
||||||
|
import { ILocalUser } from '../../../../../models/user';
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Create a file from a URL
|
* Create a file from a URL
|
||||||
*/
|
*/
|
||||||
module.exports = async (params, user): Promise<any> => {
|
module.exports = async (params: any, user: ILocalUser): Promise<any> => {
|
||||||
// Get 'url' parameter
|
// Get 'url' parameter
|
||||||
// TODO: Validate this url
|
// TODO: Validate this url
|
||||||
const [url, urlErr] = $.str.get(params.url);
|
const [url, urlErr] = $.str.get(params.url);
|
||||||
|
|
|
@ -1,13 +1,11 @@
|
||||||
/**
|
|
||||||
* Module dependencies
|
|
||||||
*/
|
|
||||||
import $ from 'cafy'; import ID from '../../../../cafy-id';
|
import $ from 'cafy'; import ID from '../../../../cafy-id';
|
||||||
import DriveFolder, { pack } from '../../../../models/drive-folder';
|
import DriveFolder, { pack } from '../../../../models/drive-folder';
|
||||||
|
import { ILocalUser } from '../../../../models/user';
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Get drive folders
|
* Get drive folders
|
||||||
*/
|
*/
|
||||||
module.exports = (params: any, user: ILocalUser, app: IApp) => new Promise(async (res, rej) => {
|
module.exports = (params: any, user: ILocalUser) => new Promise(async (res, rej) => {
|
||||||
// Get 'limit' parameter
|
// Get 'limit' parameter
|
||||||
const [limit = 10, limitErr] = $.num.optional().range(1, 100).get(params.limit);
|
const [limit = 10, limitErr] = $.num.optional().range(1, 100).get(params.limit);
|
||||||
if (limitErr) return rej('invalid limit param');
|
if (limitErr) return rej('invalid limit param');
|
||||||
|
|
|
@ -1,4 +1,4 @@
|
||||||
import DriveFile, { DriveFileChunk, IDriveFile } from "../../models/drive-file";
|
import DriveFile, { DriveFileChunk, IDriveFile } from '../../models/drive-file';
|
||||||
import DriveFileThumbnail, { DriveFileThumbnailChunk } from '../../models/drive-file-thumbnail';
|
import DriveFileThumbnail, { DriveFileThumbnailChunk } from '../../models/drive-file-thumbnail';
|
||||||
|
|
||||||
export default async function(file: IDriveFile, isExpired = false) {
|
export default async function(file: IDriveFile, isExpired = false) {
|
||||||
|
|
|
@ -9,7 +9,7 @@ import { IDriveFile, validateFileName } from '../../models/drive-file';
|
||||||
import create from './add-file';
|
import create from './add-file';
|
||||||
import config from '../../config';
|
import config from '../../config';
|
||||||
import { IUser } from '../../models/user';
|
import { IUser } from '../../models/user';
|
||||||
import * as mongodb from "mongodb";
|
import * as mongodb from 'mongodb';
|
||||||
|
|
||||||
const log = debug('misskey:drive:upload-from-url');
|
const log = debug('misskey:drive:upload-from-url');
|
||||||
|
|
||||||
|
|
|
@ -1,5 +1,5 @@
|
||||||
import User, { IUser } from "../../../models/user";
|
import User, { IUser } from '../../../models/user';
|
||||||
import FollowRequest from "../../../models/follow-request";
|
import FollowRequest from '../../../models/follow-request';
|
||||||
import accept from './accept';
|
import accept from './accept';
|
||||||
|
|
||||||
/**
|
/**
|
||||||
|
|
|
@ -1,12 +1,12 @@
|
||||||
import User, { IUser, isRemoteUser, ILocalUser, pack as packUser } from "../../../models/user";
|
import User, { IUser, isRemoteUser, ILocalUser, pack as packUser } from '../../../models/user';
|
||||||
import FollowRequest from "../../../models/follow-request";
|
import FollowRequest from '../../../models/follow-request';
|
||||||
import pack from '../../../remote/activitypub/renderer';
|
import pack from '../../../remote/activitypub/renderer';
|
||||||
import renderFollow from '../../../remote/activitypub/renderer/follow';
|
import renderFollow from '../../../remote/activitypub/renderer/follow';
|
||||||
import renderAccept from '../../../remote/activitypub/renderer/accept';
|
import renderAccept from '../../../remote/activitypub/renderer/accept';
|
||||||
import { deliver } from '../../../queue';
|
import { deliver } from '../../../queue';
|
||||||
import Following from "../../../models/following";
|
import Following from '../../../models/following';
|
||||||
import FollowingLog from "../../../models/following-log";
|
import FollowingLog from '../../../models/following-log';
|
||||||
import FollowedLog from "../../../models/followed-log";
|
import FollowedLog from '../../../models/followed-log';
|
||||||
import event from '../../../publishers/stream';
|
import event from '../../../publishers/stream';
|
||||||
|
|
||||||
export default async function(followee: IUser, follower: IUser) {
|
export default async function(followee: IUser, follower: IUser) {
|
||||||
|
|
|
@ -1,5 +1,5 @@
|
||||||
import User, { IUser, isRemoteUser, ILocalUser, pack as packUser } from "../../../models/user";
|
import User, { IUser, isRemoteUser, ILocalUser, pack as packUser } from '../../../models/user';
|
||||||
import FollowRequest from "../../../models/follow-request";
|
import FollowRequest from '../../../models/follow-request';
|
||||||
import pack from '../../../remote/activitypub/renderer';
|
import pack from '../../../remote/activitypub/renderer';
|
||||||
import renderFollow from '../../../remote/activitypub/renderer/follow';
|
import renderFollow from '../../../remote/activitypub/renderer/follow';
|
||||||
import renderUndo from '../../../remote/activitypub/renderer/undo';
|
import renderUndo from '../../../remote/activitypub/renderer/undo';
|
||||||
|
|
|
@ -1,5 +1,5 @@
|
||||||
import User, { IUser, isRemoteUser, ILocalUser } from "../../../models/user";
|
import User, { IUser, isRemoteUser, ILocalUser } from '../../../models/user';
|
||||||
import FollowRequest from "../../../models/follow-request";
|
import FollowRequest from '../../../models/follow-request';
|
||||||
import pack from '../../../remote/activitypub/renderer';
|
import pack from '../../../remote/activitypub/renderer';
|
||||||
import renderFollow from '../../../remote/activitypub/renderer/follow';
|
import renderFollow from '../../../remote/activitypub/renderer/follow';
|
||||||
import renderReject from '../../../remote/activitypub/renderer/reject';
|
import renderReject from '../../../remote/activitypub/renderer/reject';
|
||||||
|
|
|
@ -4,7 +4,7 @@ import config from '../config';
|
||||||
import { INote } from '../models/note';
|
import { INote } from '../models/note';
|
||||||
import { TextElement } from './parse';
|
import { TextElement } from './parse';
|
||||||
|
|
||||||
const handlers: {[key: string]: (window: any, token: any, mentionedRemoteUsers: INote["mentionedRemoteUsers"]) => void} = {
|
const handlers: { [key: string]: (window: any, token: any, mentionedRemoteUsers: INote['mentionedRemoteUsers']) => void } = {
|
||||||
bold({ document }, { bold }) {
|
bold({ document }, { bold }) {
|
||||||
const b = document.createElement('b');
|
const b = document.createElement('b');
|
||||||
b.textContent = bold;
|
b.textContent = bold;
|
||||||
|
|
|
@ -3,7 +3,7 @@
|
||||||
*/
|
*/
|
||||||
|
|
||||||
export type TextElementBold = {
|
export type TextElementBold = {
|
||||||
type: "bold"
|
type: 'bold'
|
||||||
content: string
|
content: string
|
||||||
bold: string
|
bold: string
|
||||||
};
|
};
|
||||||
|
|
|
@ -5,7 +5,7 @@
|
||||||
import genHtml from '../core/syntax-highlighter';
|
import genHtml from '../core/syntax-highlighter';
|
||||||
|
|
||||||
export type TextElementCode = {
|
export type TextElementCode = {
|
||||||
type: "code"
|
type: 'code'
|
||||||
content: string
|
content: string
|
||||||
code: string
|
code: string
|
||||||
html: string
|
html: string
|
||||||
|
|
|
@ -3,7 +3,7 @@
|
||||||
*/
|
*/
|
||||||
|
|
||||||
export type TextElementEmoji = {
|
export type TextElementEmoji = {
|
||||||
type: "emoji"
|
type: 'emoji'
|
||||||
content: string
|
content: string
|
||||||
emoji: string
|
emoji: string
|
||||||
};
|
};
|
||||||
|
|
|
@ -3,7 +3,7 @@
|
||||||
*/
|
*/
|
||||||
|
|
||||||
export type TextElementHashtag = {
|
export type TextElementHashtag = {
|
||||||
type: "hashtag"
|
type: 'hashtag'
|
||||||
content: string
|
content: string
|
||||||
hashtag: string
|
hashtag: string
|
||||||
};
|
};
|
||||||
|
|
|
@ -5,7 +5,7 @@
|
||||||
import genHtml from '../core/syntax-highlighter';
|
import genHtml from '../core/syntax-highlighter';
|
||||||
|
|
||||||
export type TextElementInlineCode = {
|
export type TextElementInlineCode = {
|
||||||
type: "inline-code"
|
type: 'inline-code'
|
||||||
content: string
|
content: string
|
||||||
code: string
|
code: string
|
||||||
html: string
|
html: string
|
||||||
|
|
|
@ -3,7 +3,7 @@
|
||||||
*/
|
*/
|
||||||
|
|
||||||
export type TextElementLink = {
|
export type TextElementLink = {
|
||||||
type: "link"
|
type: 'link'
|
||||||
content: string
|
content: string
|
||||||
title: string
|
title: string
|
||||||
url: string
|
url: string
|
||||||
|
|
|
@ -4,7 +4,7 @@
|
||||||
import parseAcct from '../../../acct/parse';
|
import parseAcct from '../../../acct/parse';
|
||||||
|
|
||||||
export type TextElementMention = {
|
export type TextElementMention = {
|
||||||
type: "mention"
|
type: 'mention'
|
||||||
content: string
|
content: string
|
||||||
username: string
|
username: string
|
||||||
host: string
|
host: string
|
||||||
|
|
|
@ -3,7 +3,7 @@
|
||||||
*/
|
*/
|
||||||
|
|
||||||
export type TextElementQuote = {
|
export type TextElementQuote = {
|
||||||
type: "quote"
|
type: 'quote'
|
||||||
content: string
|
content: string
|
||||||
quote: string
|
quote: string
|
||||||
};
|
};
|
||||||
|
|
|
@ -3,7 +3,7 @@
|
||||||
*/
|
*/
|
||||||
|
|
||||||
export type TextElementSearch = {
|
export type TextElementSearch = {
|
||||||
type: "search"
|
type: 'search'
|
||||||
content: string
|
content: string
|
||||||
query: string
|
query: string
|
||||||
};
|
};
|
||||||
|
|
|
@ -3,7 +3,7 @@
|
||||||
*/
|
*/
|
||||||
|
|
||||||
export type TextElementTitle = {
|
export type TextElementTitle = {
|
||||||
type: "title"
|
type: 'title'
|
||||||
content: string
|
content: string
|
||||||
title: string
|
title: string
|
||||||
};
|
};
|
||||||
|
|
|
@ -3,7 +3,7 @@
|
||||||
*/
|
*/
|
||||||
|
|
||||||
export type TextElementUrl = {
|
export type TextElementUrl = {
|
||||||
type: "url"
|
type: 'url'
|
||||||
content: string
|
content: string
|
||||||
url: string
|
url: string
|
||||||
};
|
};
|
||||||
|
|
|
@ -2,17 +2,17 @@
|
||||||
* Misskey Text Analyzer
|
* Misskey Text Analyzer
|
||||||
*/
|
*/
|
||||||
|
|
||||||
import { TextElementBold } from "./elements/bold";
|
import { TextElementBold } from './elements/bold';
|
||||||
import { TextElementCode } from "./elements/code";
|
import { TextElementCode } from './elements/code';
|
||||||
import { TextElementEmoji } from "./elements/emoji";
|
import { TextElementEmoji } from './elements/emoji';
|
||||||
import { TextElementHashtag } from "./elements/hashtag";
|
import { TextElementHashtag } from './elements/hashtag';
|
||||||
import { TextElementInlineCode } from "./elements/inline-code";
|
import { TextElementInlineCode } from './elements/inline-code';
|
||||||
import { TextElementLink } from "./elements/link";
|
import { TextElementLink } from './elements/link';
|
||||||
import { TextElementMention } from "./elements/mention";
|
import { TextElementMention } from './elements/mention';
|
||||||
import { TextElementQuote } from "./elements/quote";
|
import { TextElementQuote } from './elements/quote';
|
||||||
import { TextElementSearch } from "./elements/search";
|
import { TextElementSearch } from './elements/search';
|
||||||
import { TextElementTitle } from "./elements/title";
|
import { TextElementTitle } from './elements/title';
|
||||||
import { TextElementUrl } from "./elements/url";
|
import { TextElementUrl } from './elements/url';
|
||||||
|
|
||||||
const elements = [
|
const elements = [
|
||||||
require('./elements/bold'),
|
require('./elements/bold'),
|
||||||
|
@ -28,7 +28,7 @@ const elements = [
|
||||||
require('./elements/search')
|
require('./elements/search')
|
||||||
].map(element => element.default as TextElementProcessor);
|
].map(element => element.default as TextElementProcessor);
|
||||||
|
|
||||||
export type TextElement = {type: "text", content: string}
|
export type TextElement = { type: 'text', content: string }
|
||||||
| TextElementBold
|
| TextElementBold
|
||||||
| TextElementCode
|
| TextElementCode
|
||||||
| TextElementEmoji
|
| TextElementEmoji
|
||||||
|
|
Loading…
Reference in New Issue