Compare commits
44 Commits
Author | SHA1 | Date | |
---|---|---|---|
cd6a1d3446 | |||
4a9fc0c8ed | |||
fada899b30 | |||
22b099fa8a | |||
e0bc0d2830 | |||
90768d30aa | |||
177c549493 | |||
5e1ee68189 | |||
175f6303bc | |||
cf9f2a5562 | |||
f04526baca | |||
f085ecedb3 | |||
0986301788 | |||
fe418d8d9a | |||
6009be34dc | |||
01a0a54a2c | |||
cfcaf77e21 | |||
3b37bdc0b9 | |||
ec07112f94 | |||
464faf2673 | |||
bde20a1a65 | |||
86c7276da9 | |||
fec988bb79 | |||
0702d0974b | |||
f443d36dbb | |||
dc02168f33 | |||
cc5c32b4d2 | |||
d35f62d0e4 | |||
09b8e81a77 | |||
3b38979a34 | |||
0fd8c86c24 | |||
38b75ad977 | |||
ba08d1aa53 | |||
fb1e2efbdd | |||
92e5cff285 | |||
ba9340a26b | |||
00119328f2 | |||
9021bb5694 | |||
f15878cc6f | |||
4edd9efc0b | |||
2913c7ccfb | |||
e1f460f90f | |||
70f927ea43 | |||
80d343bb0b |
@ -123,6 +123,7 @@ drive:
|
||||
# google_maps_api_key: example-google-maps-api-key
|
||||
|
||||
# Twitter integration
|
||||
# You need to set the oauth callback url as : https://<your-misskey-instance>/api/tw/cb
|
||||
# twitter:
|
||||
# consumer_key: example-twitter-consumer-key
|
||||
# consumer_secret: example-twitter-consumer-secret-key
|
||||
|
@ -62,6 +62,13 @@ npm install web-push -g
|
||||
web-push generate-vapid-keys
|
||||
```
|
||||
|
||||
*(optional)* Create a twitter application
|
||||
----------------------------------------------------------------
|
||||
If you want to enable the twitter integration, you need to create a twitter app at [apps.twitter.com](https://apps.twitter.com/).
|
||||
|
||||
In the app you need to set the oauth callback url as : https://misskey-instance/api/tw/cb
|
||||
|
||||
|
||||
*5.* Make configuration file
|
||||
----------------------------------------------------------------
|
||||
1. `cp .config/example.yml .config/default.yml` Copy the `.config/example.yml` and rename it to `default.yml`.
|
||||
|
@ -897,6 +897,24 @@ desktop/views/components/window.vue:
|
||||
popout: "ポップアウト"
|
||||
close: "閉じる"
|
||||
|
||||
desktop/views/pages/admin/admin.vue:
|
||||
dashboard: "ダッシュボード"
|
||||
drive: "ドライブ"
|
||||
users: "ユーザー"
|
||||
update: "更新"
|
||||
|
||||
desktop/views/pages/admin/admin.dashboard.vue:
|
||||
dashboard: "ダッシュボード"
|
||||
all-users: "全てのユーザー"
|
||||
original-users: "このインスタンスのユーザー"
|
||||
all-notes: "全てのノート"
|
||||
original-notes: "このインスタンスのノート"
|
||||
|
||||
desktop/views/pages/admin/admin.suspend-user.vue:
|
||||
suspend-user: "ユーザーの凍結"
|
||||
suspend: "凍結"
|
||||
suspended: "凍結しました"
|
||||
|
||||
desktop/views/pages/deck/deck.tl-column.vue:
|
||||
is-media-only: "メディア投稿のみ"
|
||||
is-media-view: "メディアビュー"
|
||||
|
20
package.json
20
package.json
@ -1,8 +1,8 @@
|
||||
{
|
||||
"name": "misskey",
|
||||
"author": "syuilo <i@syuilo.com>",
|
||||
"version": "5.23.2",
|
||||
"clientVersion": "1.0.8235",
|
||||
"version": "5.24.0",
|
||||
"clientVersion": "1.0.8279",
|
||||
"codename": "nighthike",
|
||||
"main": "./built/index.js",
|
||||
"private": true,
|
||||
@ -31,6 +31,7 @@
|
||||
"@types/dateformat": "1.0.1",
|
||||
"@types/debug": "0.0.30",
|
||||
"@types/deep-equal": "1.0.1",
|
||||
"@types/double-ended-queue": "2.1.0",
|
||||
"@types/elasticsearch": "5.0.25",
|
||||
"@types/file-type": "5.2.1",
|
||||
"@types/gulp": "3.8.36",
|
||||
@ -57,9 +58,9 @@
|
||||
"@types/minio": "6.0.2",
|
||||
"@types/mkdirp": "0.5.2",
|
||||
"@types/mocha": "5.2.3",
|
||||
"@types/mongodb": "3.1.3",
|
||||
"@types/mongodb": "3.1.4",
|
||||
"@types/ms": "0.7.30",
|
||||
"@types/node": "10.5.8",
|
||||
"@types/node": "10.7.0",
|
||||
"@types/portscanner": "2.1.0",
|
||||
"@types/pug": "2.0.4",
|
||||
"@types/qrcode": "1.2.0",
|
||||
@ -79,7 +80,7 @@
|
||||
"@types/webpack": "4.4.9",
|
||||
"@types/webpack-stream": "3.2.10",
|
||||
"@types/websocket": "0.0.39",
|
||||
"@types/ws": "5.1.2",
|
||||
"@types/ws": "6.0.0",
|
||||
"animejs": "2.2.0",
|
||||
"autosize": "4.0.2",
|
||||
"autwh": "0.1.0",
|
||||
@ -97,6 +98,7 @@
|
||||
"deepcopy": "0.6.3",
|
||||
"diskusage": "0.2.4",
|
||||
"dompurify": "1.0.5",
|
||||
"double-ended-queue": "2.1.0-0",
|
||||
"elasticsearch": "15.1.1",
|
||||
"element-ui": "2.4.6",
|
||||
"emojilib": "2.3.0",
|
||||
@ -151,7 +153,7 @@
|
||||
"mkdirp": "0.5.1",
|
||||
"mocha": "5.2.0",
|
||||
"moji": "0.5.1",
|
||||
"mongodb": "3.1.1",
|
||||
"mongodb": "3.1.3",
|
||||
"monk": "6.0.6",
|
||||
"ms": "2.1.1",
|
||||
"nan": "2.10.0",
|
||||
@ -178,7 +180,7 @@
|
||||
"rndstr": "1.0.0",
|
||||
"s-age": "1.1.2",
|
||||
"sass-loader": "7.1.0",
|
||||
"seedrandom": "2.4.3",
|
||||
"seedrandom": "2.4.4",
|
||||
"sharp": "0.20.5",
|
||||
"showdown": "1.8.6",
|
||||
"showdown-highlightjs-extension": "0.1.2",
|
||||
@ -199,7 +201,7 @@
|
||||
"typescript": "2.9.2",
|
||||
"typescript-eslint-parser": "18.0.0",
|
||||
"uglify-es": "3.3.9",
|
||||
"url-loader": "1.0.1",
|
||||
"url-loader": "1.1.0",
|
||||
"uuid": "3.3.2",
|
||||
"v-animate-css": "0.0.2",
|
||||
"vue": "2.5.17",
|
||||
@ -208,7 +210,7 @@
|
||||
"vue-json-tree-view": "2.1.4",
|
||||
"vue-loader": "15.3.0",
|
||||
"vue-router": "3.0.1",
|
||||
"vue-style-loader": "4.1.1",
|
||||
"vue-style-loader": "4.1.2",
|
||||
"vue-template-compiler": "2.5.17",
|
||||
"vuedraggable": "2.16.0",
|
||||
"vuex": "3.0.1",
|
||||
|
@ -1,5 +1,6 @@
|
||||
export default () => [
|
||||
'(=^・・^=)',
|
||||
'v(\'ω\')v',
|
||||
'🐡( \'-\' 🐡 )フグパンチ!!!!'
|
||||
][Math.floor(Math.random() * 3)];
|
||||
'🐡( \'-\' 🐡 )フグパンチ!!!!',
|
||||
'🖕(´・_・`)🖕'
|
||||
][Math.floor(Math.random() * 4)];
|
||||
|
@ -1,8 +1,16 @@
|
||||
<template>
|
||||
<span class="mk-avatar" :title="user | acct" :style="style" v-if="disableLink && !disablePreview" v-user-preview="user.id" @click="onClick"></span>
|
||||
<span class="mk-avatar" :title="user | acct" :style="style" v-else-if="disableLink && disablePreview" @click="onClick"></span>
|
||||
<router-link class="mk-avatar" :to="user | userPage" :title="user | acct" :target="target" :style="style" v-else-if="!disableLink && !disablePreview" v-user-preview="user.id"></router-link>
|
||||
<router-link class="mk-avatar" :to="user | userPage" :title="user | acct" :target="target" :style="style" v-else-if="!disableLink && disablePreview"></router-link>
|
||||
<span class="mk-avatar" :class="{ cat }" :title="user | acct" v-if="disableLink && !disablePreview" v-user-preview="user.id" @click="onClick">
|
||||
<span class="inner" :style="style"></span>
|
||||
</span>
|
||||
<span class="mk-avatar" :class="{ cat }" :title="user | acct" v-else-if="disableLink && disablePreview" @click="onClick">
|
||||
<span class="inner" :style="style"></span>
|
||||
</span>
|
||||
<router-link class="mk-avatar" :class="{ cat }" :to="user | userPage" :title="user | acct" :target="target" v-else-if="!disableLink && !disablePreview" v-user-preview="user.id">
|
||||
<span class="inner" :style="style"></span>
|
||||
</router-link>
|
||||
<router-link class="mk-avatar" :class="{ cat }" :to="user | userPage" :title="user | acct" :target="target" v-else-if="!disableLink && disablePreview">
|
||||
<span class="inner" :style="style"></span>
|
||||
</router-link>
|
||||
</template>
|
||||
|
||||
<script lang="ts">
|
||||
@ -30,14 +38,17 @@ export default Vue.extend({
|
||||
lightmode(): boolean {
|
||||
return this.$store.state.device.lightmode;
|
||||
},
|
||||
cat(): boolean {
|
||||
return this.user.isCat && this.$store.state.settings.circleIcons;
|
||||
},
|
||||
style(): any {
|
||||
return {
|
||||
backgroundColor: this.lightmode
|
||||
? `rgb(${ this.user.avatarColor.slice(0, 3).join(',') })`
|
||||
? `rgb(${this.user.avatarColor.slice(0, 3).join(',')})`
|
||||
: this.user.avatarColor && this.user.avatarColor.length == 3
|
||||
? `rgb(${ this.user.avatarColor.join(',') })`
|
||||
? `rgb(${this.user.avatarColor.join(',')})`
|
||||
: null,
|
||||
backgroundImage: this.lightmode ? null : `url(${ this.user.avatarUrl })`,
|
||||
backgroundImage: this.lightmode ? null : `url(${this.user.avatarUrl})`,
|
||||
borderRadius: this.$store.state.settings.circleIcons ? '100%' : null
|
||||
};
|
||||
}
|
||||
@ -51,10 +62,43 @@ export default Vue.extend({
|
||||
</script>
|
||||
|
||||
<style lang="stylus" scoped>
|
||||
.mk-avatar
|
||||
|
||||
root(isDark)
|
||||
display inline-block
|
||||
vertical-align bottom
|
||||
background-size cover
|
||||
background-position center center
|
||||
transition border-radius 1s ease
|
||||
|
||||
&.cat::before,
|
||||
&.cat::after
|
||||
background #df548f
|
||||
border solid 4px isDark ? #e0eefd : #202224
|
||||
box-sizing border-box
|
||||
content ''
|
||||
display inline-block
|
||||
height 50%
|
||||
width 50%
|
||||
|
||||
&.cat::before
|
||||
border-radius 0 75% 75%
|
||||
transform rotate(37.5deg) skew(30deg)
|
||||
|
||||
&.cat::after
|
||||
border-radius 75% 0 75% 75%
|
||||
transform rotate(-37.5deg) skew(-30deg)
|
||||
|
||||
.inner
|
||||
background-position center center
|
||||
background-size cover
|
||||
bottom 0
|
||||
left 0
|
||||
position absolute
|
||||
right 0
|
||||
top 0
|
||||
transition border-radius 1s ease
|
||||
z-index 1
|
||||
|
||||
.mk-avatar[data-darkmode]
|
||||
root(true)
|
||||
|
||||
.mk-avatar:not([data-darkmode])
|
||||
root(false)
|
||||
</style>
|
||||
|
@ -24,6 +24,7 @@ import updateBanner from './api/update-banner';
|
||||
|
||||
import MkIndex from './views/pages/index.vue';
|
||||
import MkDeck from './views/pages/deck/deck.vue';
|
||||
import MkAdmin from './views/pages/admin/admin.vue';
|
||||
import MkUser from './views/pages/user/user.vue';
|
||||
import MkFavorites from './views/pages/favorites.vue';
|
||||
import MkSelectDrive from './views/pages/selectdrive.vue';
|
||||
@ -55,6 +56,7 @@ init(async (launch) => {
|
||||
routes: [
|
||||
{ path: '/', name: 'index', component: MkIndex },
|
||||
{ path: '/deck', name: 'deck', component: MkDeck },
|
||||
{ path: '/admin', name: 'admin', component: MkAdmin },
|
||||
{ path: '/i/customize-home', component: MkHomeCustomize },
|
||||
{ path: '/i/favorites', component: MkFavorites },
|
||||
{ path: '/i/messaging/:user', component: MkMessagingRoom },
|
||||
|
37
src/client/app/desktop/views/pages/admin/admin.dashboard.vue
Normal file
37
src/client/app/desktop/views/pages/admin/admin.dashboard.vue
Normal file
@ -0,0 +1,37 @@
|
||||
<template>
|
||||
<div>
|
||||
<h1>%i18n:@dashboard%</h1>
|
||||
<div v-if="stats">
|
||||
<p><b>%i18n:@all-users%</b>: <span>{{ stats.usersCount | number }}</span></p>
|
||||
<p><b>%i18n:@original-users%</b>: <span>{{ stats.originalUsersCount | number }}</span></p>
|
||||
<p><b>%i18n:@all-notes%</b>: <span>{{ stats.notesCount | number }}</span></p>
|
||||
<p><b>%i18n:@original-notes%</b>: <span>{{ stats.originalNotesCount | number }}</span></p>
|
||||
</div>
|
||||
</div>
|
||||
</template>
|
||||
|
||||
<script lang="ts">
|
||||
import Vue from "vue";
|
||||
|
||||
export default Vue.extend({
|
||||
data() {
|
||||
return {
|
||||
stats: null
|
||||
};
|
||||
},
|
||||
created() {
|
||||
(this as any).api('stats').then(stats => {
|
||||
this.stats = stats;
|
||||
});
|
||||
}
|
||||
});
|
||||
</script>
|
||||
|
||||
<style lang="stylus" scoped>
|
||||
h1
|
||||
margin 0 0 1em 0
|
||||
padding 0 0 8px 0
|
||||
font-size 1em
|
||||
color #555
|
||||
border-bottom solid 1px #eee
|
||||
</style>
|
@ -0,0 +1,39 @@
|
||||
<template>
|
||||
<div>
|
||||
<header>%i18n:@suspend-user%</header>
|
||||
<input v-model="username"/>
|
||||
<button @click="suspendUser" :disabled="suspending">%i18n:@suspend%</button>
|
||||
</div>
|
||||
</template>
|
||||
|
||||
<script lang="ts">
|
||||
import Vue from "vue";
|
||||
import parseAcct from "../../../../../../misc/acct/parse";
|
||||
|
||||
export default Vue.extend({
|
||||
data() {
|
||||
return {
|
||||
username: null,
|
||||
suspending: false
|
||||
};
|
||||
},
|
||||
methods: {
|
||||
async suspendUser() {
|
||||
this.suspending = true;
|
||||
|
||||
const user = await (this as any).os.api(
|
||||
"users/show",
|
||||
parseAcct(this.username)
|
||||
);
|
||||
|
||||
await (this as any).os.api("admin/suspend-user", {
|
||||
userId: user.id
|
||||
});
|
||||
|
||||
this.suspending = false;
|
||||
|
||||
(this as any).os.apis.dialog({ text: "%i18n:@suspended%" });
|
||||
}
|
||||
}
|
||||
});
|
||||
</script>
|
90
src/client/app/desktop/views/pages/admin/admin.vue
Normal file
90
src/client/app/desktop/views/pages/admin/admin.vue
Normal file
@ -0,0 +1,90 @@
|
||||
<template>
|
||||
<div class="mk-admin">
|
||||
<nav>
|
||||
<ul>
|
||||
<li @click="nav('dashboard')" :class="{ active: page == 'dashboard' }">%fa:chalkboard .fw%%i18n:@dashboard%</li>
|
||||
<!-- <li @click="nav('users')" :class="{ active: page == 'users' }">%fa:users .fw%%i18n:@users%</li> -->
|
||||
<!-- <li @click="nav('drive')" :class="{ active: page == 'drive' }">%fa:cloud .fw%%i18n:@drive%</li> -->
|
||||
<!-- <li @click="nav('update')" :class="{ active: page == 'update' }">%i18n:@update%</li> -->
|
||||
</ul>
|
||||
</nav>
|
||||
<main>
|
||||
<div v-if="page == 'dashboard'">
|
||||
<x-dashboard/>
|
||||
</div>
|
||||
<div v-if="page == 'users'">
|
||||
<x-suspend-user/>
|
||||
</div>
|
||||
<div v-if="page == 'drive'"></div>
|
||||
<div v-if="page == 'update'"></div>
|
||||
</main>
|
||||
</div>
|
||||
</template>
|
||||
|
||||
<script lang="ts">
|
||||
import Vue from "vue";
|
||||
import XDashboard from "./admin.dashboard.vue";
|
||||
import XSuspendUser from "./admin.suspend-user.vue";
|
||||
|
||||
export default Vue.extend({
|
||||
components: {
|
||||
XDashboard,
|
||||
XSuspendUser
|
||||
},
|
||||
data() {
|
||||
return {
|
||||
page: 'dashboard'
|
||||
};
|
||||
},
|
||||
methods: {
|
||||
nav(page: string) {
|
||||
this.page = page;
|
||||
}
|
||||
}
|
||||
});
|
||||
</script>
|
||||
|
||||
<style lang="stylus" scoped>
|
||||
@import '~const.styl'
|
||||
|
||||
.mk-admin
|
||||
display flex
|
||||
height 100%
|
||||
margin 32px
|
||||
|
||||
> nav
|
||||
flex 0 0 250px
|
||||
width 100%
|
||||
height 100%
|
||||
padding 16px 0 0 0
|
||||
overflow auto
|
||||
border-right solid 1px #ddd
|
||||
|
||||
> ul
|
||||
list-style none
|
||||
|
||||
> li
|
||||
display block
|
||||
padding 10px 16px
|
||||
margin 0
|
||||
color #666
|
||||
cursor pointer
|
||||
user-select none
|
||||
transition margin-left 0.2s ease
|
||||
|
||||
> [data-fa]
|
||||
margin-right 4px
|
||||
|
||||
|
||||
&:hover
|
||||
color #555
|
||||
|
||||
&.active
|
||||
margin-left 8px
|
||||
color $theme-color !important
|
||||
|
||||
> main
|
||||
width 100%
|
||||
padding 16px 32px
|
||||
|
||||
</style>
|
@ -176,6 +176,10 @@ root(isDark)
|
||||
height 120px
|
||||
box-shadow 1px 1px 3px rgba(#000, 0.2)
|
||||
|
||||
> &.cat::before,
|
||||
> &.cat::after
|
||||
border-width 8px
|
||||
|
||||
> .body
|
||||
padding 16px 16px 16px 154px
|
||||
color isDark ? #c5ced6 : #555
|
||||
|
@ -1,5 +1,5 @@
|
||||
{
|
||||
"copyright": "Copyright (c) 2014-2018 syuilo",
|
||||
"themeColor": "#f66e4f",
|
||||
"themeColor": "#f6584f",
|
||||
"themeColorForeground": "#fff"
|
||||
}
|
||||
|
@ -1,21 +1,22 @@
|
||||
import * as childProcess from 'child_process';
|
||||
import * as Deque from 'double-ended-queue';
|
||||
import Xev from 'xev';
|
||||
|
||||
const ev = new Xev();
|
||||
|
||||
export default function() {
|
||||
const log: any[] = [];
|
||||
const log = new Deque<any>();
|
||||
|
||||
const p = childProcess.fork(__dirname + '/notes-stats-child.js');
|
||||
|
||||
p.on('message', stats => {
|
||||
ev.emit('notesStats', stats);
|
||||
log.push(stats);
|
||||
if (log.length > 100) log.shift();
|
||||
if (log.length > 100) log.pop();
|
||||
});
|
||||
|
||||
ev.on('requestNotesStatsLog', id => {
|
||||
ev.emit('notesStatsLog:' + id, log);
|
||||
ev.emit('notesStatsLog:' + id, log.toArray());
|
||||
});
|
||||
|
||||
process.on('exit', code => {
|
||||
|
@ -1,6 +1,7 @@
|
||||
import * as os from 'os';
|
||||
import * as sysUtils from 'systeminformation';
|
||||
import * as diskusage from 'diskusage';
|
||||
import * as Deque from 'double-ended-queue';
|
||||
import Xev from 'xev';
|
||||
const osUtils = require('os-utils');
|
||||
|
||||
@ -12,10 +13,10 @@ const interval = 1000;
|
||||
* Report server stats regularly
|
||||
*/
|
||||
export default function() {
|
||||
const log: any[] = [];
|
||||
const log = new Deque<any>();
|
||||
|
||||
ev.on('requestServerStatsLog', id => {
|
||||
ev.emit('serverStatsLog:' + id, log);
|
||||
ev.emit('serverStatsLog:' + id, log.toArray());
|
||||
});
|
||||
|
||||
async function tick() {
|
||||
@ -36,7 +37,7 @@ export default function() {
|
||||
};
|
||||
ev.emit('serverStats', stats);
|
||||
log.push(stats);
|
||||
if (log.length > 50) log.shift();
|
||||
if (log.length > 50) log.pop();
|
||||
}
|
||||
|
||||
tick();
|
||||
|
16
src/remote/activitypub/renderer/follow-user.ts
Normal file
16
src/remote/activitypub/renderer/follow-user.ts
Normal file
@ -0,0 +1,16 @@
|
||||
import config from '../../../config';
|
||||
import * as mongo from 'mongodb';
|
||||
import User, { isLocalUser } from '../../../models/user';
|
||||
|
||||
/**
|
||||
* Convert (local|remote)(Follower|Followee)ID to URL
|
||||
* @param id Follower|Followee ID
|
||||
*/
|
||||
export default async function renderFollowUser(id: mongo.ObjectID): Promise<any> {
|
||||
|
||||
const user = await User.findOne({
|
||||
_id: id
|
||||
});
|
||||
|
||||
return isLocalUser(user) ? `${config.url}/users/${user._id}` : user.uri;
|
||||
}
|
23
src/remote/activitypub/renderer/ordered-collection-page.ts
Normal file
23
src/remote/activitypub/renderer/ordered-collection-page.ts
Normal file
@ -0,0 +1,23 @@
|
||||
/**
|
||||
* Render OrderedCollectionPage
|
||||
* @param id URL of self
|
||||
* @param totalItems Number of total items
|
||||
* @param orderedItems Items
|
||||
* @param partOf URL of base
|
||||
* @param prev URL of prev page (optional)
|
||||
* @param next URL of next page (optional)
|
||||
*/
|
||||
export default function(id: string, totalItems: any, orderedItems: any, partOf: string, prev: string, next: string) {
|
||||
const page = {
|
||||
id,
|
||||
partOf,
|
||||
type: 'OrderedCollectionPage',
|
||||
totalItems,
|
||||
orderedItems
|
||||
} as any;
|
||||
|
||||
if (prev) page.prev = prev;
|
||||
if (next) page.next = next;
|
||||
|
||||
return page;
|
||||
}
|
@ -1,6 +1,19 @@
|
||||
export default (id: string, totalItems: any, orderedItems: any) => ({
|
||||
id,
|
||||
type: 'OrderedCollection',
|
||||
totalItems,
|
||||
orderedItems
|
||||
});
|
||||
/**
|
||||
* Render OrderedCollection
|
||||
* @param id URL of self
|
||||
* @param totalItems Total number of items
|
||||
* @param first URL of first page (optional)
|
||||
* @param last URL of last page (optional)
|
||||
*/
|
||||
export default function(id: string, totalItems: any, first: string, last: string) {
|
||||
const page: any = {
|
||||
id,
|
||||
type: 'OrderedCollection',
|
||||
totalItems,
|
||||
};
|
||||
|
||||
if (first) page.first = first;
|
||||
if (last) page.last = last;
|
||||
|
||||
return page;
|
||||
}
|
||||
|
@ -10,8 +10,9 @@ import User, { isLocalUser, ILocalUser, IUser } from '../models/user';
|
||||
import renderNote from '../remote/activitypub/renderer/note';
|
||||
import renderKey from '../remote/activitypub/renderer/key';
|
||||
import renderPerson from '../remote/activitypub/renderer/person';
|
||||
import renderOrderedCollection from '../remote/activitypub/renderer/ordered-collection';
|
||||
import config from '../config';
|
||||
import Outbox from './activitypub/outbox';
|
||||
import Followers from './activitypub/followers';
|
||||
import Following from './activitypub/following';
|
||||
|
||||
// Init router
|
||||
const router = new Router();
|
||||
@ -64,72 +65,14 @@ router.get('/notes/:note', async (ctx, next) => {
|
||||
ctx.body = pack(await renderNote(note));
|
||||
});
|
||||
|
||||
// outbot
|
||||
router.get('/users/:user/outbox', async ctx => {
|
||||
const userId = new mongo.ObjectID(ctx.params.user);
|
||||
|
||||
const user = await User.findOne({
|
||||
_id: userId,
|
||||
host: null
|
||||
});
|
||||
|
||||
if (user === null) {
|
||||
ctx.status = 404;
|
||||
return;
|
||||
}
|
||||
|
||||
const notes = await Note.find({ userId: user._id }, {
|
||||
limit: 10,
|
||||
sort: { _id: -1 }
|
||||
});
|
||||
|
||||
const renderedNotes = await Promise.all(notes.map(note => renderNote(note)));
|
||||
const rendered = renderOrderedCollection(`${config.url}/users/${userId}/inbox`, user.notesCount, renderedNotes);
|
||||
|
||||
ctx.body = pack(rendered);
|
||||
});
|
||||
// outbox
|
||||
router.get('/users/:user/outbox', Outbox);
|
||||
|
||||
// followers
|
||||
router.get('/users/:user/followers', async ctx => {
|
||||
const userId = new mongo.ObjectID(ctx.params.user);
|
||||
|
||||
const user = await User.findOne({
|
||||
_id: userId,
|
||||
host: null
|
||||
});
|
||||
|
||||
if (user === null) {
|
||||
ctx.status = 404;
|
||||
return;
|
||||
}
|
||||
|
||||
// TODO: Implement fetch and render
|
||||
|
||||
const rendered = renderOrderedCollection(`${config.url}/users/${userId}/followers`, 0, []);
|
||||
|
||||
ctx.body = pack(rendered);
|
||||
});
|
||||
router.get('/users/:user/followers', Followers);
|
||||
|
||||
// following
|
||||
router.get('/users/:user/following', async ctx => {
|
||||
const userId = new mongo.ObjectID(ctx.params.user);
|
||||
|
||||
const user = await User.findOne({
|
||||
_id: userId,
|
||||
host: null
|
||||
});
|
||||
|
||||
if (user === null) {
|
||||
ctx.status = 404;
|
||||
return;
|
||||
}
|
||||
|
||||
// TODO: Implement fetch and render
|
||||
|
||||
const rendered = renderOrderedCollection(`${config.url}/users/${userId}/following`, 0, []);
|
||||
|
||||
ctx.body = pack(rendered);
|
||||
});
|
||||
router.get('/users/:user/following', Following);
|
||||
|
||||
// publickey
|
||||
router.get('/users/:user/publickey', async ctx => {
|
||||
|
80
src/server/activitypub/followers.ts
Normal file
80
src/server/activitypub/followers.ts
Normal file
@ -0,0 +1,80 @@
|
||||
import * as mongo from 'mongodb';
|
||||
import * as Koa from 'koa';
|
||||
import config from '../../config';
|
||||
import $ from 'cafy'; import ID from '../../misc/cafy-id';
|
||||
import User from '../../models/user';
|
||||
import Following from '../../models/following';
|
||||
import pack from '../../remote/activitypub/renderer';
|
||||
import renderOrderedCollection from '../../remote/activitypub/renderer/ordered-collection';
|
||||
import renderOrderedCollectionPage from '../../remote/activitypub/renderer/ordered-collection-page';
|
||||
import renderFollowUser from '../../remote/activitypub/renderer/follow-user';
|
||||
|
||||
export default async (ctx: Koa.Context) => {
|
||||
const userId = new mongo.ObjectID(ctx.params.user);
|
||||
|
||||
// Get 'cursor' parameter
|
||||
const [cursor = null, cursorErr] = $.type(ID).optional.get(ctx.request.query.cursor);
|
||||
|
||||
// Get 'page' parameter
|
||||
const pageErr = !$.str.optional.or(['true', 'false']).ok(ctx.request.query.page);
|
||||
const page: boolean = ctx.request.query.page === 'true';
|
||||
|
||||
// Validate parameters
|
||||
if (cursorErr || pageErr) {
|
||||
ctx.status = 400;
|
||||
return;
|
||||
}
|
||||
|
||||
// Verify user
|
||||
const user = await User.findOne({
|
||||
_id: userId,
|
||||
host: null
|
||||
});
|
||||
|
||||
if (user === null) {
|
||||
ctx.status = 404;
|
||||
return;
|
||||
}
|
||||
|
||||
const limit = 10;
|
||||
const partOf = `${config.url}/users/${userId}/followers`;
|
||||
|
||||
if (page) {
|
||||
// Construct query
|
||||
const query = {
|
||||
followeeId: user._id
|
||||
} as any;
|
||||
|
||||
// カーソルが指定されている場合
|
||||
if (cursor) {
|
||||
query._id = {
|
||||
$lt: cursor
|
||||
};
|
||||
}
|
||||
|
||||
// Get followers
|
||||
const followings = await Following
|
||||
.find(query, {
|
||||
limit: limit + 1,
|
||||
sort: { _id: -1 }
|
||||
});
|
||||
|
||||
// 「次のページ」があるかどうか
|
||||
const inStock = followings.length === limit + 1;
|
||||
if (inStock) followings.pop();
|
||||
|
||||
const renderedFollowers = await Promise.all(followings.map(following => renderFollowUser(following.followerId)));
|
||||
const rendered = renderOrderedCollectionPage(
|
||||
`${partOf}?page=true${cursor ? `&cursor=${cursor}` : ''}`,
|
||||
user.followersCount, renderedFollowers, partOf,
|
||||
null,
|
||||
inStock ? `${partOf}?page=true&cursor=${followings[followings.length - 1]._id}` : null
|
||||
);
|
||||
|
||||
ctx.body = pack(rendered);
|
||||
} else {
|
||||
// index page
|
||||
const rendered = renderOrderedCollection(partOf, user.followersCount, `${partOf}?page=true`, null);
|
||||
ctx.body = pack(rendered);
|
||||
}
|
||||
};
|
80
src/server/activitypub/following.ts
Normal file
80
src/server/activitypub/following.ts
Normal file
@ -0,0 +1,80 @@
|
||||
import * as mongo from 'mongodb';
|
||||
import * as Koa from 'koa';
|
||||
import config from '../../config';
|
||||
import $ from 'cafy'; import ID from '../../misc/cafy-id';
|
||||
import User from '../../models/user';
|
||||
import Following from '../../models/following';
|
||||
import pack from '../../remote/activitypub/renderer';
|
||||
import renderOrderedCollection from '../../remote/activitypub/renderer/ordered-collection';
|
||||
import renderOrderedCollectionPage from '../../remote/activitypub/renderer/ordered-collection-page';
|
||||
import renderFollowUser from '../../remote/activitypub/renderer/follow-user';
|
||||
|
||||
export default async (ctx: Koa.Context) => {
|
||||
const userId = new mongo.ObjectID(ctx.params.user);
|
||||
|
||||
// Get 'cursor' parameter
|
||||
const [cursor = null, cursorErr] = $.type(ID).optional.get(ctx.request.query.cursor);
|
||||
|
||||
// Get 'page' parameter
|
||||
const pageErr = !$.str.optional.or(['true', 'false']).ok(ctx.request.query.page);
|
||||
const page: boolean = ctx.request.query.page === 'true';
|
||||
|
||||
// Validate parameters
|
||||
if (cursorErr || pageErr) {
|
||||
ctx.status = 400;
|
||||
return;
|
||||
}
|
||||
|
||||
// Verify user
|
||||
const user = await User.findOne({
|
||||
_id: userId,
|
||||
host: null
|
||||
});
|
||||
|
||||
if (user === null) {
|
||||
ctx.status = 404;
|
||||
return;
|
||||
}
|
||||
|
||||
const limit = 10;
|
||||
const partOf = `${config.url}/users/${userId}/following`;
|
||||
|
||||
if (page) {
|
||||
// Construct query
|
||||
const query = {
|
||||
followerId: user._id
|
||||
} as any;
|
||||
|
||||
// カーソルが指定されている場合
|
||||
if (cursor) {
|
||||
query._id = {
|
||||
$lt: cursor
|
||||
};
|
||||
}
|
||||
|
||||
// Get followings
|
||||
const followings = await Following
|
||||
.find(query, {
|
||||
limit: limit + 1,
|
||||
sort: { _id: -1 }
|
||||
});
|
||||
|
||||
// 「次のページ」があるかどうか
|
||||
const inStock = followings.length === limit + 1;
|
||||
if (inStock) followings.pop();
|
||||
|
||||
const renderedFollowees = await Promise.all(followings.map(following => renderFollowUser(following.followeeId)));
|
||||
const rendered = renderOrderedCollectionPage(
|
||||
`${partOf}?page=true${cursor ? `&cursor=${cursor}` : ''}`,
|
||||
user.followingCount, renderedFollowees, partOf,
|
||||
null,
|
||||
inStock ? `${partOf}?page=true&cursor=${followings[followings.length - 1]._id}` : null
|
||||
);
|
||||
|
||||
ctx.body = pack(rendered);
|
||||
} else {
|
||||
// index page
|
||||
const rendered = renderOrderedCollection(partOf, user.followingCount, `${partOf}?page=true`, null);
|
||||
ctx.body = pack(rendered);
|
||||
}
|
||||
};
|
103
src/server/activitypub/outbox.ts
Normal file
103
src/server/activitypub/outbox.ts
Normal file
@ -0,0 +1,103 @@
|
||||
import * as mongo from 'mongodb';
|
||||
import * as Koa from 'koa';
|
||||
import config from '../../config';
|
||||
import $ from 'cafy'; import ID from '../../misc/cafy-id';
|
||||
import User from '../../models/user';
|
||||
import pack from '../../remote/activitypub/renderer';
|
||||
import renderOrderedCollection from '../../remote/activitypub/renderer/ordered-collection';
|
||||
import renderOrderedCollectionPage from '../../remote/activitypub/renderer/ordered-collection-page';
|
||||
|
||||
import Note from '../../models/note';
|
||||
import renderNote from '../../remote/activitypub/renderer/note';
|
||||
|
||||
export default async (ctx: Koa.Context) => {
|
||||
const userId = new mongo.ObjectID(ctx.params.user);
|
||||
|
||||
// Get 'sinceId' parameter
|
||||
const [sinceId, sinceIdErr] = $.type(ID).optional.get(ctx.request.query.since_id);
|
||||
|
||||
// Get 'untilId' parameter
|
||||
const [untilId, untilIdErr] = $.type(ID).optional.get(ctx.request.query.until_id);
|
||||
|
||||
// Get 'page' parameter
|
||||
const pageErr = !$.str.optional.or(['true', 'false']).ok(ctx.request.query.page);
|
||||
const page: boolean = ctx.request.query.page === 'true';
|
||||
|
||||
// Validate parameters
|
||||
if (sinceIdErr || untilIdErr || pageErr || [sinceId, untilId].filter(x => x != null).length > 1) {
|
||||
ctx.status = 400;
|
||||
return;
|
||||
}
|
||||
|
||||
// Verify user
|
||||
const user = await User.findOne({
|
||||
_id: userId,
|
||||
host: null
|
||||
});
|
||||
|
||||
if (user === null) {
|
||||
ctx.status = 404;
|
||||
return;
|
||||
}
|
||||
|
||||
const limit = 20;
|
||||
const partOf = `${config.url}/users/${userId}/outbox`;
|
||||
|
||||
if (page) {
|
||||
//#region Construct query
|
||||
const sort = {
|
||||
_id: -1
|
||||
};
|
||||
|
||||
const query = {
|
||||
userId: user._id,
|
||||
$and: [{
|
||||
$or: [ { visibility: 'public' }, { visibility: 'home' } ]
|
||||
}, { // exclude renote, but include quote
|
||||
$or: [{
|
||||
text: { $ne: null }
|
||||
}, {
|
||||
mediaIds: { $ne: [] }
|
||||
}]
|
||||
}]
|
||||
} as any;
|
||||
|
||||
if (sinceId) {
|
||||
sort._id = 1;
|
||||
query._id = {
|
||||
$gt: sinceId
|
||||
};
|
||||
} else if (untilId) {
|
||||
query._id = {
|
||||
$lt: untilId
|
||||
};
|
||||
}
|
||||
//#endregion
|
||||
|
||||
// Issue query
|
||||
const notes = await Note
|
||||
.find(query, {
|
||||
limit: limit,
|
||||
sort: sort
|
||||
});
|
||||
|
||||
if (sinceId) notes.reverse();
|
||||
|
||||
const renderedNotes = await Promise.all(notes.map(note => renderNote(note)));
|
||||
const rendered = renderOrderedCollectionPage(
|
||||
`${partOf}?page=true${sinceId ? `&since_id=${sinceId}` : ''}${untilId ? `&until_id=${untilId}` : ''}`,
|
||||
user.notesCount, renderedNotes, partOf,
|
||||
notes.length > 0 ? `${partOf}?page=true&since_id=${notes[0]._id}` : null,
|
||||
notes.length > 0 ? `${partOf}?page=true&until_id=${notes[notes.length - 1]._id}` : null
|
||||
);
|
||||
|
||||
ctx.body = pack(rendered);
|
||||
} else {
|
||||
// index page
|
||||
const rendered = renderOrderedCollection(partOf, user.notesCount,
|
||||
`${partOf}?page=true`,
|
||||
`${partOf}?page=true&since_id=000000000000000000000000`
|
||||
);
|
||||
ctx.body = pack(rendered);
|
||||
}
|
||||
};
|
@ -1,6 +1,6 @@
|
||||
import { performance } from 'perf_hooks';
|
||||
import limitter from './limitter';
|
||||
import { IUser } from '../../models/user';
|
||||
import { IUser, isLocalUser } from '../../models/user';
|
||||
import { IApp } from '../../models/app';
|
||||
import endpoints from './endpoints';
|
||||
|
||||
@ -21,6 +21,10 @@ export default (endpoint: string, user: IUser, app: IApp, data: any, file?: any)
|
||||
return rej('YOUR_ACCOUNT_HAS_BEEN_SUSPENDED');
|
||||
}
|
||||
|
||||
if (ep.meta.requireAdmin && !(isLocalUser(user) && user.isAdmin)) {
|
||||
return rej('YOU_ARE_NOT_ADMIN');
|
||||
}
|
||||
|
||||
if (app && ep.meta.kind) {
|
||||
if (!app.permission.some(p => p === ep.meta.kind)) {
|
||||
return rej('PERMISSION_DENIED');
|
||||
@ -53,7 +57,7 @@ export default (endpoint: string, user: IUser, app: IApp, data: any, file?: any)
|
||||
const time = after - before;
|
||||
|
||||
if (time > 1000) {
|
||||
console.warn(`SLOW API CALL DETECTED: ${ep.name} (${ time }ms)`);
|
||||
console.warn(`SLOW API CALL DETECTED: ${ep.name} (${time}ms)`);
|
||||
}
|
||||
} catch (e) {
|
||||
rej(e);
|
||||
|
@ -14,6 +14,11 @@ export interface IEndpointMeta {
|
||||
*/
|
||||
requireCredential?: boolean;
|
||||
|
||||
/**
|
||||
* 管理者のみ使えるエンドポイントか否か
|
||||
*/
|
||||
requireAdmin?: boolean;
|
||||
|
||||
/**
|
||||
* エンドポイントのリミテーションに関するやつ
|
||||
* 省略した場合はリミテーションは無いものとして解釈されます。
|
||||
|
46
src/server/api/endpoints/admin/suspend-user.ts
Normal file
46
src/server/api/endpoints/admin/suspend-user.ts
Normal file
@ -0,0 +1,46 @@
|
||||
import $ from 'cafy';
|
||||
import ID from '../../../../misc/cafy-id';
|
||||
import getParams from '../../get-params';
|
||||
import User from '../../../../models/user';
|
||||
|
||||
export const meta = {
|
||||
desc: {
|
||||
ja: '指定したユーザーを凍結します。',
|
||||
en: 'Suspend a user.'
|
||||
},
|
||||
|
||||
requireCredential: true,
|
||||
requireAdmin: true,
|
||||
|
||||
params: {
|
||||
userId: $.type(ID).note({
|
||||
desc: {
|
||||
ja: '対象のユーザーID',
|
||||
en: 'The user ID which you want to suspend'
|
||||
}
|
||||
}),
|
||||
}
|
||||
};
|
||||
|
||||
export default (params: any) => new Promise(async (res, rej) => {
|
||||
const [ps, psErr] = getParams(meta, params);
|
||||
if (psErr) return rej(psErr);
|
||||
|
||||
const user = await User.findOne({
|
||||
_id: ps.userId
|
||||
});
|
||||
|
||||
if (user == null) {
|
||||
return rej('user not found');
|
||||
}
|
||||
|
||||
await User.findOneAndUpdate({
|
||||
_id: user._id
|
||||
}, {
|
||||
$set: {
|
||||
isSuspended: true
|
||||
}
|
||||
});
|
||||
|
||||
res();
|
||||
});
|
@ -95,6 +95,8 @@ type Option = {
|
||||
};
|
||||
|
||||
export default async (user: IUser, data: Option, silent = false) => new Promise<INote>(async (res, rej) => {
|
||||
const isFirstNote = user.notesCount === 0;
|
||||
|
||||
if (data.createdAt == null) data.createdAt = new Date();
|
||||
if (data.visibility == null) data.visibility = 'public';
|
||||
if (data.viaMobile == null) data.viaMobile = false;
|
||||
@ -164,6 +166,10 @@ export default async (user: IUser, data: Option, silent = false) => new Promise<
|
||||
// Pack the note
|
||||
const noteObj = await pack(note);
|
||||
|
||||
if (isFirstNote) {
|
||||
noteObj.isFirstNote = true;
|
||||
}
|
||||
|
||||
const nm = new NotificationManager(user, note);
|
||||
const nmRelatedPromises = [];
|
||||
|
||||
|
Reference in New Issue
Block a user