Merge branch 'signout-to-welcome-page' into swn

This commit is contained in:
tamaina
2021-08-24 14:20:00 +09:00
26 changed files with 136 additions and 34 deletions

View File

@@ -47,7 +47,7 @@ export async function signout() {
document.cookie = `igi=; path=/`;
if (accounts.length > 0) login(accounts[0].token);
else unisonReload();
else unisonReload('/');
}
export async function getAccounts(): Promise<{ id: Account['id'], token: Account['token'] }[]> {

View File

@@ -1,12 +1,12 @@
<template>
<form class="mk-signup" @submit.prevent="onSubmit" :autocomplete="Math.random()">
<form class="qlvuhzng" @submit.prevent="onSubmit" :autocomplete="Math.random()">
<template v-if="meta">
<MkInput v-if="meta.disableRegistration" v-model="invitationCode" type="text" :autocomplete="Math.random()" spellcheck="false" required>
<MkInput class="_inputNoTopMargin" v-if="meta.disableRegistration" v-model="invitationCode" type="text" :autocomplete="Math.random()" spellcheck="false" required>
<template #label>{{ $ts.invitationCode }}</template>
<template #prefix><i class="fas fa-key"></i></template>
</MkInput>
<MkInput v-model="username" type="text" pattern="^[a-zA-Z0-9_]{1,20}$" :autocomplete="Math.random()" spellcheck="false" required @update:modelValue="onChangeUsername" data-cy-signup-username>
<template #label>{{ $ts.username }}</template>
<MkInput class="_inputNoTopMargin" v-model="username" type="text" pattern="^[a-zA-Z0-9_]{1,20}$" :autocomplete="Math.random()" spellcheck="false" required @update:modelValue="onChangeUsername" data-cy-signup-username>
<template #label>{{ $ts.username }} <div class="_button _help" v-tooltip:dialog="$ts.usernameInfo"><i class="far fa-question-circle"></i></div></template>
<template #prefix>@</template>
<template #suffix>@{{ host }}</template>
<template #caption>
@@ -204,7 +204,7 @@ export default defineComponent({
</script>
<style lang="scss" scoped>
.mk-signup {
.qlvuhzng {
.captcha {
margin: 16px 0;
}

View File

@@ -1,6 +1,6 @@
import { Directive, ref } from 'vue';
import { isDeviceTouch } from '@client/scripts/is-device-touch';
import { popup } from '@client/os';
import { popup, dialog } from '@client/os';
const start = isDeviceTouch ? 'touchstart' : 'mouseover';
const end = isDeviceTouch ? 'touchend' : 'mouseleave';
@@ -24,6 +24,18 @@ export default {
}
};
if (binding.arg === 'dialog') {
el.addEventListener('click', (ev) => {
ev.preventDefault();
ev.stopPropagation();
dialog({
type: 'info',
text: binding.value,
});
return false;
});
}
const show = e => {
if (!document.body.contains(el)) return;
if (self._close) return;

View File

@@ -91,7 +91,10 @@ if (defaultStore.state.reportError && !_DEV_) {
document.addEventListener('touchend', () => {}, { passive: true });
// 一斉リロード
reloadChannel.addEventListener('message', shouldRedirectToRoot => reload(shouldRedirectToRoot));
reloadChannel.addEventListener('message', path => {
if (path === 'reload')
location.reload()
});
//#region SEE: https://css-tricks.com/the-trick-to-viewport-units-on-mobile/
// TODO: いつの日にか消したい
@@ -103,15 +106,12 @@ window.addEventListener('resize', () => {
});
//#endregion
// Get the <head> element
const head = document.getElementsByTagName('head')[0];
// If mobile, insert the viewport meta tag
if (isMobile || window.innerWidth <= 1024) {
const viewport = document.getElementsByName('viewport').item(0);
viewport.setAttribute('content',
`${viewport.getAttribute('content')},minimum-scale=1,maximum-scale=1,user-scalable=no`);
head.appendChild(viewport);
document.head.appendChild(viewport);
}
//#region Set lang attr

View File

@@ -214,7 +214,11 @@ export function modalPageWindow(path: string) {
}, {}, 'closed');
}
export function dialog(props: Record<string, any>) {
export function dialog(props: {
type: 'error' | 'info' | 'success' | 'warning' | 'waiting';
title?: string | null;
text?: string | null;
}) {
return new Promise((resolve, reject) => {
popup(import('@client/components/dialog.vue'), props, {
done: result => {

View File

@@ -60,7 +60,7 @@ import FormBase from '@client/components/form/base.vue';
import FormGroup from '@client/components/form/group.vue';
import FormKeyValueView from '@client/components/form/key-value-view.vue';
import MkLink from '@client/components/link.vue';
import { physics } from '@client/scripts/physics.ts';
import { physics } from '@client/scripts/physics';
import * as symbols from '@client/symbols';
const patrons = [

View File

@@ -12,6 +12,9 @@
<template #prefix><i class="fas fa-key"></i></template>
DeepL Auth Key
</FormInput>
<FormSwitch v-model:value="deeplIsPro">
Pro account
</FormSwitch>
</FormGroup>
<FormButton @click="save" primary><i class="fas fa-save"></i> {{ $ts.save }}</FormButton>
</FormSuspense>
@@ -50,6 +53,7 @@ export default defineComponent({
},
summalyProxy: '',
deeplAuthKey: '',
deeplIsPro: false,
}
},
@@ -62,11 +66,13 @@ export default defineComponent({
const meta = await os.api('meta', { detail: true });
this.summalyProxy = meta.summalyProxy;
this.deeplAuthKey = meta.deeplAuthKey;
this.deeplIsPro = meta.deeplIsPro;
},
save() {
os.apiWithDialog('admin/update-meta', {
summalyProxy: this.summalyProxy,
deeplAuthKey: this.deeplAuthKey,
deeplIsPro: this.deeplIsPro,
}).then(() => {
fetchInstance();
});

View File

@@ -1,18 +1,15 @@
// SafariがBroadcastChannel未実装なのでライブラリを使う
import { BroadcastChannel } from 'broadcast-channel';
export const reloadChannel = new BroadcastChannel<boolean>('reload');
export const reloadChannel = new BroadcastChannel<string>('reload');
// BroadcastChannelを用いて、クライアントが一斉にreloadするようにします。
export function unisonReload(redirectToRoot: boolean = false) {
reloadChannel.postMessage(!!redirectToRoot);
reload();
}
export function reload(redirectToRoot: boolean = false) {
if (redirectToRoot) {
location.href = '/';
export function unisonReload(path?: string) {
if (path !== undefined) {
reloadChannel.postMessage(path);
location.href = path;
} else {
reloadChannel.postMessage('reload');
location.reload();
}
}

View File

@@ -156,8 +156,10 @@ hr {
._button {
appearance: none;
display: inline-block;
padding: 0;
margin: 0; // for Safari
width: max-content;
background: none;
border: none;
cursor: pointer;
@@ -201,6 +203,11 @@ hr {
}
}
._help {
color: var(--accent);
cursor: help
}
._textButton {
@extend ._button;
color: var(--accent);

View File

@@ -5,7 +5,7 @@ Misskey Webクライアントのプラグイン機能を使うと、クライア
プラグインは、AiScriptのメタデータ埋め込み機能を使って、デフォルトとしてプラグインのメタデータを定義する必要があります。 メタデータは次のプロパティを含むオブジェクトです。
### name
プラグイン名
Nomo de kromaĵo
### author
プラグイン作者

View File

@@ -319,6 +319,11 @@ export class Meta {
})
public deeplAuthKey: string | null;
@Column('boolean', {
default: false,
})
public deeplIsPro: boolean;
@Column('varchar', {
length: 512,
nullable: true

View File

@@ -149,6 +149,10 @@ export const meta = {
validator: $.optional.nullable.str,
},
deeplIsPro: {
validator: $.optional.bool,
},
enableTwitterIntegration: {
validator: $.optional.bool,
},
@@ -574,6 +578,10 @@ export default define(meta, async (ps, me) => {
}
}
if (ps.deeplIsPro !== undefined) {
set.deeplIsPro = ps.deeplIsPro;
}
await getConnection().transaction(async transactionalEntityManager => {
const meta = await transactionalEntityManager.findOne(Meta, {
order: {

View File

@@ -583,6 +583,8 @@ export default define(meta, async (ps, me) => {
response.objectStorageUseProxy = instance.objectStorageUseProxy;
response.objectStorageSetPublicRead = instance.objectStorageSetPublicRead;
response.objectStorageS3ForcePathStyle = instance.objectStorageS3ForcePathStyle;
response.deeplAuthKey = instance.deeplAuthKey;
response.deeplIsPro = instance.deeplIsPro;
}
}

View File

@@ -61,7 +61,9 @@ export default define(meta, async (ps, user) => {
params.append('text', note.text);
params.append('target_lang', targetLang);
const res = await fetch('https://api-free.deepl.com/v2/translate', {
const endpoint = instance.deeplIsPro ? 'https://api.deepl.com/v2/translate' : 'https://api-free.deepl.com/v2/translate';
const res = await fetch(endpoint, {
method: 'POST',
headers: {
'Content-Type': 'application/x-www-form-urlencoded',

View File

@@ -17,6 +17,10 @@ const _dirname = dirname(_filename);
// Init app
const app = new Koa();
app.use(cors());
app.use(async (ctx, next) => {
ctx.set('Content-Security-Policy', `default-src 'none'; style-src 'unsafe-inline'`);
await next();
});
// Init router
const router = new Router();

View File

@@ -10,6 +10,10 @@ import { proxyMedia } from './proxy-media';
// Init app
const app = new Koa();
app.use(cors());
app.use(async (ctx, next) => {
ctx.set('Content-Security-Policy', `default-src 'none'; style-src 'unsafe-inline'`);
await next();
});
// Init router
const router = new Router();

View File

@@ -60,8 +60,6 @@
? `?salt=${localStorage.getItem('salt')}`
: '';
const head = document.getElementsByTagName('head')[0];
const script = document.createElement('script');
script.setAttribute('src', `/assets/app.${v}.js${salt}`);
script.setAttribute('async', 'true');
@@ -70,7 +68,7 @@
renderError('APP_FETCH_FAILED');
checkUpdate();
});
head.appendChild(script);
document.head.appendChild(script);
//#endregion
//#region Theme