summaryrefslogtreecommitdiff
path: root/src
diff options
context:
space:
mode:
authorsyuilo <syuilotan@yahoo.co.jp>2018-12-20 04:08:13 +0900
committersyuilo <syuilotan@yahoo.co.jp>2018-12-20 04:08:13 +0900
commit454632d785cbf031f54a9dc63a20af0d92302e0d (patch)
tree3ec3a8868caab821ea55a3360572ee6fca707b87 /src
parentBetter cw detection (diff)
downloadmisskey-454632d785cbf031f54a9dc63a20af0d92302e0d.tar.gz
misskey-454632d785cbf031f54a9dc63a20af0d92302e0d.tar.bz2
misskey-454632d785cbf031f54a9dc63a20af0d92302e0d.zip
Resolve #3687
Diffstat (limited to 'src')
-rw-r--r--src/client/app/admin/views/instance.vue24
-rw-r--r--src/config/types.ts8
-rw-r--r--src/misc/fetch-meta.ts3
-rw-r--r--src/models/meta.ts4
-rw-r--r--src/push-sw.ts25
-rw-r--r--src/server/api/endpoints/admin/update-meta.ts33
-rw-r--r--src/server/api/endpoints/meta.ts5
-rw-r--r--src/server/api/endpoints/sw/register.ts8
8 files changed, 85 insertions, 25 deletions
diff --git a/src/client/app/admin/views/instance.vue b/src/client/app/admin/views/instance.vue
index b34aa03e3a..5a29da0345 100644
--- a/src/client/app/admin/views/instance.vue
+++ b/src/client/app/admin/views/instance.vue
@@ -58,6 +58,15 @@
<ui-switch v-model="smtpSecure" :disabled="!enableEmail">{{ $t('smtp-secure') }}<span slot="desc">{{ $t('smtp-secure-info') }}</span></ui-switch>
</section>
<section>
+ <header><fa :icon="faBolt"/> {{ $t('serviceworker-config') }}</header>
+ <ui-switch v-model="enableServiceWorker">{{ $t('enable-serviceworker') }}<span slot="desc">{{ $t('serviceworker-info') }}</span></ui-switch>
+ <ui-info>{{ $t('vapid-info') }}<br><code>npm i web-push -g<br>web-push generate-vapid-keys</code></ui-info>
+ <ui-horizon-group inputs class="fit-bottom">
+ <ui-input v-model="swPublicKey" :disabled="!enableServiceWorker"><i slot="icon"><fa icon="key"/></i>{{ $t('vapid-publickey') }}</ui-input>
+ <ui-input v-model="swPrivateKey" :disabled="!enableServiceWorker"><i slot="icon"><fa icon="key"/></i>{{ $t('vapid-privatekey') }}</ui-input>
+ </ui-horizon-group>
+ </section>
+ <section>
<header>summaly Proxy</header>
<ui-input v-model="summalyProxy">URL</ui-input>
</section>
@@ -126,7 +135,7 @@ import Vue from 'vue';
import i18n from '../../i18n';
import { url, host } from '../../config';
import { toUnicode } from 'punycode';
-import { faHeadset, faShieldAlt, faGhost, faUserPlus } from '@fortawesome/free-solid-svg-icons';
+import { faHeadset, faShieldAlt, faGhost, faUserPlus, faBolt } from '@fortawesome/free-solid-svg-icons';
import { faEnvelope as farEnvelope } from '@fortawesome/free-regular-svg-icons';
export default Vue.extend({
@@ -174,7 +183,10 @@ export default Vue.extend({
smtpPort: null,
smtpUser: null,
smtpPass: null,
- faHeadset, faShieldAlt, faGhost, faUserPlus, farEnvelope
+ enableServiceWorker: false,
+ swPublicKey: null,
+ swPrivateKey: null,
+ faHeadset, faShieldAlt, faGhost, faUserPlus, farEnvelope, faBolt
};
},
@@ -217,6 +229,9 @@ export default Vue.extend({
this.smtpPort = meta.smtpPort;
this.smtpUser = meta.smtpUser;
this.smtpPass = meta.smtpPass;
+ this.enableServiceWorker = meta.enableServiceWorker;
+ this.swPublicKey = meta.swPublickey;
+ this.swPrivateKey = meta.swPrivateKey;
});
},
@@ -270,7 +285,10 @@ export default Vue.extend({
smtpHost: this.smtpHost,
smtpPort: parseInt(this.smtpPort, 10),
smtpUser: this.smtpUser,
- smtpPass: this.smtpPass
+ smtpPass: this.smtpPass,
+ enableServiceWorker: this.enableServiceWorker,
+ swPublicKey: this.swPublicKey,
+ swPrivateKey: this.swPrivateKey
}).then(() => {
this.$root.dialog({
type: 'success',
diff --git a/src/config/types.ts b/src/config/types.ts
index 6ca3e3b7f2..2ce9c0c80d 100644
--- a/src/config/types.ts
+++ b/src/config/types.ts
@@ -39,14 +39,6 @@ export type Source = {
accesslog?: string;
- /**
- * Service Worker
- */
- sw?: {
- publicKey: string;
- privateKey: string;
- };
-
clusterLimit?: number;
};
diff --git a/src/misc/fetch-meta.ts b/src/misc/fetch-meta.ts
index 229c00620f..a49e4dbe78 100644
--- a/src/misc/fetch-meta.ts
+++ b/src/misc/fetch-meta.ts
@@ -19,7 +19,8 @@ const defaultMeta: any = {
enableExternalUserRecommendation: false,
externalUserRecommendationEngine: 'https://vinayaka.distsn.org/cgi-bin/vinayaka-user-match-misskey-api.cgi?{{host}}+{{user}}+{{limit}}+{{offset}}',
externalUserRecommendationTimeout: 300000,
- errorImageUrl: 'https://ai.misskey.xyz/aiart/yubitun.png'
+ errorImageUrl: 'https://ai.misskey.xyz/aiart/yubitun.png',
+ enableServiceWorker: false
};
export default async function(): Promise<IMeta> {
diff --git a/src/models/meta.ts b/src/models/meta.ts
index 66cdf76d33..b40fabdfc1 100644
--- a/src/models/meta.ts
+++ b/src/models/meta.ts
@@ -223,4 +223,8 @@ export type IMeta = {
smtpPort?: number;
smtpUser?: string;
smtpPass?: string;
+
+ enableServiceWorker?: boolean;
+ swPublicKey?: string;
+ swPrivateKey?: string;
};
diff --git a/src/push-sw.ts b/src/push-sw.ts
index bfd3b94a57..58e695813d 100644
--- a/src/push-sw.ts
+++ b/src/push-sw.ts
@@ -2,17 +2,26 @@ const push = require('web-push');
import * as mongo from 'mongodb';
import Subscription from './models/sw-subscription';
import config from './config';
+import fetchMeta from './misc/fetch-meta';
+import { IMeta } from './models/meta';
-if (config.sw) {
- // アプリケーションの連絡先と、サーバーサイドの鍵ペアの情報を登録
- push.setVapidDetails(
- config.url,
- config.sw.publicKey,
- config.sw.privateKey);
-}
+let meta: IMeta = null;
+
+setInterval(() => {
+ fetchMeta().then(m => {
+ meta = m;
+
+ if (meta.enableServiceWorker) {
+ // アプリケーションの連絡先と、サーバーサイドの鍵ペアの情報を登録
+ push.setVapidDetails(config.url,
+ meta.swPublicKey,
+ meta.swPrivateKey);
+ }
+ });
+}, 3000);
export default async function(userId: mongo.ObjectID | string, type: string, body?: any) {
- if (!config.sw) return;
+ if (!meta.enableServiceWorker) return;
if (typeof userId === 'string') {
userId = new mongo.ObjectID(userId);
diff --git a/src/server/api/endpoints/admin/update-meta.ts b/src/server/api/endpoints/admin/update-meta.ts
index 5c156442ef..6ceb2a98dc 100644
--- a/src/server/api/endpoints/admin/update-meta.ts
+++ b/src/server/api/endpoints/admin/update-meta.ts
@@ -285,6 +285,27 @@ export const meta = {
'ja-JP': 'SMTPサーバのパスワード'
}
},
+
+ enableServiceWorker: {
+ validator: $.bool.optional,
+ desc: {
+ 'ja-JP': 'ServiceWorkerを有効にするか否か'
+ }
+ },
+
+ swPublicKey: {
+ validator: $.str.optional.nullable,
+ desc: {
+ 'ja-JP': 'ServiceWorkerのVAPIDキーペアの公開鍵'
+ }
+ },
+
+ swPrivateKey: {
+ validator: $.str.optional.nullable,
+ desc: {
+ 'ja-JP': 'ServiceWorkerのVAPIDキーペアの秘密鍵'
+ }
+ },
}
};
@@ -447,6 +468,18 @@ export default define(meta, (ps) => new Promise(async (res, rej) => {
set.errorImageUrl = ps.errorImageUrl;
}
+ if (ps.enableServiceWorker !== undefined) {
+ set.enableServiceWorker = ps.enableServiceWorker;
+ }
+
+ if (ps.swPublicKey !== undefined) {
+ set.swPublicKey = ps.swPublicKey;
+ }
+
+ if (ps.swPrivateKey !== undefined) {
+ set.swPrivateKey = ps.swPrivateKey;
+ }
+
await Meta.update({}, {
$set: set
}, { upsert: true });
diff --git a/src/server/api/endpoints/meta.ts b/src/server/api/endpoints/meta.ts
index 4df7280250..57311426a8 100644
--- a/src/server/api/endpoints/meta.ts
+++ b/src/server/api/endpoints/meta.ts
@@ -63,7 +63,7 @@ export default define(meta, (ps, me) => new Promise(async (res, rej) => {
cacheRemoteFiles: instance.cacheRemoteFiles,
enableRecaptcha: instance.enableRecaptcha,
recaptchaSiteKey: instance.recaptchaSiteKey,
- swPublickey: null,
+ swPublickey: instance.swPublicKey,
bannerUrl: instance.bannerUrl,
errorImageUrl: instance.errorImageUrl,
maxNoteTextLength: instance.maxNoteTextLength,
@@ -85,7 +85,7 @@ export default define(meta, (ps, me) => new Promise(async (res, rej) => {
twitter: instance.enableTwitterIntegration,
github: instance.enableGithubIntegration,
discord: instance.enableDiscordIntegration,
- serviceWorker: config.sw ? true : false,
+ serviceWorker: instance.enableServiceWorker,
userRecommendation: {
external: instance.enableExternalUserRecommendation,
engine: instance.externalUserRecommendationEngine,
@@ -114,6 +114,7 @@ export default define(meta, (ps, me) => new Promise(async (res, rej) => {
response.smtpPort = instance.smtpPort;
response.smtpUser = instance.smtpUser;
response.smtpPass = instance.smtpPass;
+ response.swPrivateKey = instance.swPrivateKey;
}
res(response);
diff --git a/src/server/api/endpoints/sw/register.ts b/src/server/api/endpoints/sw/register.ts
index c5c003bded..095c1b765d 100644
--- a/src/server/api/endpoints/sw/register.ts
+++ b/src/server/api/endpoints/sw/register.ts
@@ -1,7 +1,7 @@
import $ from 'cafy';
import Subscription from '../../../../models/sw-subscription';
-import config from '../../../../config';
import define from '../../define';
+import fetchMeta from '../../../../misc/fetch-meta';
export const meta = {
requireCredential: true,
@@ -31,10 +31,12 @@ export default define(meta, (ps, user) => new Promise(async (res, rej) => {
deletedAt: { $exists: false }
});
+ const instance = await fetchMeta();
+
if (exist != null) {
return res({
state: 'already-subscribed',
- key: config.sw.publicKey
+ key: instance.swPublicKey
});
}
@@ -47,6 +49,6 @@ export default define(meta, (ps, user) => new Promise(async (res, rej) => {
res({
state: 'subscribed',
- key: config.sw.publicKey
+ key: instance.swPublicKey
});
}));