From 291beb45fcb7a4c856232b12848ebad8267e2840 Mon Sep 17 00:00:00 2001 From: Aya Morisawa Date: Sat, 1 Sep 2018 23:12:51 +0900 Subject: Use string interpolation --- src/remote/activitypub/renderer/hashtag.ts | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) (limited to 'src/remote') diff --git a/src/remote/activitypub/renderer/hashtag.ts b/src/remote/activitypub/renderer/hashtag.ts index a37ba63532..36563c2df5 100644 --- a/src/remote/activitypub/renderer/hashtag.ts +++ b/src/remote/activitypub/renderer/hashtag.ts @@ -3,5 +3,5 @@ import config from '../../../config'; export default (tag: string) => ({ type: 'Hashtag', href: `${config.url}/tags/${encodeURIComponent(tag)}`, - name: '#' + tag + name: `#${tag}` }); -- cgit v1.3.1-freya From 0177023ead75594c603e41f9c1f355e7f4b18369 Mon Sep 17 00:00:00 2001 From: mei23 Date: Sun, 2 Sep 2018 02:57:34 +0900 Subject: Use Tombstone for Delete --- src/remote/activitypub/renderer/tombstone.ts | 4 ++++ src/services/note/delete.ts | 5 +++-- 2 files changed, 7 insertions(+), 2 deletions(-) create mode 100644 src/remote/activitypub/renderer/tombstone.ts (limited to 'src/remote') diff --git a/src/remote/activitypub/renderer/tombstone.ts b/src/remote/activitypub/renderer/tombstone.ts new file mode 100644 index 0000000000..553406b93b --- /dev/null +++ b/src/remote/activitypub/renderer/tombstone.ts @@ -0,0 +1,4 @@ +export default (id: string) => ({ + id, + type: 'Tombstone' +}); diff --git a/src/services/note/delete.ts b/src/services/note/delete.ts index d0e2b12b41..dea306feec 100644 --- a/src/services/note/delete.ts +++ b/src/services/note/delete.ts @@ -5,8 +5,9 @@ import renderDelete from '../../remote/activitypub/renderer/delete'; import pack from '../../remote/activitypub/renderer'; import { deliver } from '../../queue'; import Following from '../../models/following'; -import renderNote from '../../remote/activitypub/renderer/note'; +import renderTombstone from '../../remote/activitypub/renderer/tombstone'; import { updateNoteStats } from '../update-chart'; +import config from '../../config'; /** * 投稿を削除します。 @@ -32,7 +33,7 @@ export default async function(user: IUser, note: INote) { //#region ローカルの投稿なら削除アクティビティを配送 if (isLocalUser(user)) { - const content = pack(renderDelete(await renderNote(note), user)); + const content = pack(renderDelete(renderTombstone(`${config.url}/notes/${note._id}`), user)); const followings = await Following.find({ followeeId: user._id, -- cgit v1.3.1-freya From 5b039a1beea20d300d1cb2579674383ac763176d Mon Sep 17 00:00:00 2001 From: MeiMei <30769358+mei23@users.noreply.github.com> Date: Tue, 4 Sep 2018 17:44:21 +0900 Subject: Add User-Agent header (#2602) --- src/config/load.ts | 2 ++ src/config/types.ts | 1 + src/remote/activitypub/request.ts | 1 + src/remote/activitypub/resolver.ts | 3 ++- src/services/drive/upload-from-url.ts | 7 ++++++- 5 files changed, 12 insertions(+), 2 deletions(-) (limited to 'src/remote') diff --git a/src/config/load.ts b/src/config/load.ts index 8929cf8d3e..3a1bac3201 100644 --- a/src/config/load.ts +++ b/src/config/load.ts @@ -7,6 +7,7 @@ import { URL } from 'url'; import * as yaml from 'js-yaml'; import { Source, Mixin } from './types'; import isUrl = require('is-url'); +const pkg = require('../../package.json'); /** * Path of configuration directory @@ -43,6 +44,7 @@ export default function load() { mixin.stats_url = `${mixin.scheme}://${mixin.host}/stats`; mixin.status_url = `${mixin.scheme}://${mixin.host}/status`; mixin.drive_url = `${mixin.scheme}://${mixin.host}/files`; + mixin.user_agent = `Misskey/${pkg.version} (${config.url})`; if (config.localDriveCapacityMb == null) config.localDriveCapacityMb = 256; if (config.remoteDriveCapacityMb == null) config.remoteDriveCapacityMb = 8; diff --git a/src/config/types.ts b/src/config/types.ts index a1dc9a5bd4..003185accd 100644 --- a/src/config/types.ts +++ b/src/config/types.ts @@ -114,6 +114,7 @@ export type Mixin = { status_url: string; dev_url: string; drive_url: string; + user_agent: string; }; export type Config = Source & Mixin; diff --git a/src/remote/activitypub/request.ts b/src/remote/activitypub/request.ts index d739d08e15..07f0ecca8b 100644 --- a/src/remote/activitypub/request.ts +++ b/src/remote/activitypub/request.ts @@ -27,6 +27,7 @@ export default (user: ILocalUser, url: string, object: any) => new Promise((reso method: 'POST', path: pathname + search, headers: { + 'User-Agent': config.user_agent, 'Content-Type': 'application/activity+json', 'Digest': `SHA-256=${hash}` } diff --git a/src/remote/activitypub/resolver.ts b/src/remote/activitypub/resolver.ts index 0b053ca774..9bbe474d35 100644 --- a/src/remote/activitypub/resolver.ts +++ b/src/remote/activitypub/resolver.ts @@ -1,7 +1,7 @@ import * as request from 'request-promise-native'; import * as debug from 'debug'; import { IObject } from './type'; -//import config from '../../config'; +import config from '../../config'; const log = debug('misskey:activitypub:resolver'); @@ -51,6 +51,7 @@ export default class Resolver { const object = await request({ url: value, headers: { + 'User-Agent': config.user_agent, Accept: 'application/activity+json, application/ld+json' }, json: true diff --git a/src/services/drive/upload-from-url.ts b/src/services/drive/upload-from-url.ts index 4e297d3bb1..0cf21ea5a2 100644 --- a/src/services/drive/upload-from-url.ts +++ b/src/services/drive/upload-from-url.ts @@ -34,7 +34,12 @@ export default async (url: string, user: IUser, folderId: mongodb.ObjectID = nul // write content at URL to temp file await new Promise((res, rej) => { const writable = fs.createWriteStream(path); - request(url) + request({ + url, + headers: { + 'User-Agent': config.user_agent + } + }) .on('error', rej) .on('end', () => { writable.close(); -- cgit v1.3.1-freya