Skip to content

Commit

Permalink
pub-relayなど (#94)
Browse files Browse the repository at this point in the history
  • Loading branch information
mei23 authored May 11, 2020
1 parent bd5fd67 commit b4e469e
Show file tree
Hide file tree
Showing 80 changed files with 2,185 additions and 752 deletions.
11 changes: 11 additions & 0 deletions locales/en-US.yml
Original file line number Diff line number Diff line change
Expand Up @@ -1191,6 +1191,7 @@ admin/views/index.vue:
moderators: "Moderators"
users: "Users"
federation: "Federation"
relays: "Relays"
announcements: "Announcements"
abuse: "Abuse"
queue: "Job Queue"
Expand Down Expand Up @@ -1553,6 +1554,16 @@ admin/views/federation.vue:
blocked-hosts: "Blocking"
blocked-hosts-info: "List up the hosts delimited by line breaks that you want to block."
save: "Save"
admin/views/relay.vue:
add-relay: "Add relay"
inbox: "inbox URL"
add: "Add"
remove: "Remove"
added-relays: "Added relays"
status:
requesting: "Requesting"
accepted: "Accepted"
rejected: "Rejected"
desktop/views/pages/welcome.vue:
about: "More details..."
timeline: "Timeline"
Expand Down
12 changes: 12 additions & 0 deletions locales/ja-JP.yml
Original file line number Diff line number Diff line change
Expand Up @@ -1319,6 +1319,7 @@ admin/views/index.vue:
moderators: "モデレーター"
users: "ユーザー"
federation: "連合"
relays: "リレー"
announcements: "お知らせ"
abuse: "スパム報告"
queue: "ジョブキュー"
Expand Down Expand Up @@ -1696,6 +1697,17 @@ admin/views/federation.vue:
blocked-hosts-info: "ブロックしたいホストを改行で区切って記述します。"
save: "保存"

admin/views/relay.vue:
add-relay: "リレーの追加"
inbox: "inboxのURL"
add: "追加"
remove: "削除"
added-relays: "追加済みのリレー"
status:
requesting: "承認待ち"
accepted: "承認済み"
rejected: "拒否済み"

desktop/views/pages/welcome.vue:
about: "詳しく..."
timeline: "タイムライン"
Expand Down
18 changes: 18 additions & 0 deletions migration/1589023282116-pubRelay.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,18 @@
import {MigrationInterface, QueryRunner} from "typeorm";

export class pubRelay1589023282116 implements MigrationInterface {
name = 'pubRelay1589023282116'

public async up(queryRunner: QueryRunner): Promise<void> {
await queryRunner.query(`CREATE TYPE "relay_status_enum" AS ENUM('requesting', 'accepted', 'rejected')`, undefined);
await queryRunner.query(`CREATE TABLE "relay" ("id" character varying(32) NOT NULL, "inbox" character varying(512) NOT NULL, "status" "relay_status_enum" NOT NULL, CONSTRAINT "PK_78ebc9cfddf4292633b7ba57aee" PRIMARY KEY ("id"))`, undefined);
await queryRunner.query(`CREATE UNIQUE INDEX "IDX_0d9a1738f2cf7f3b1c3334dfab" ON "relay" ("inbox") `, undefined);
}

public async down(queryRunner: QueryRunner): Promise<void> {
await queryRunner.query(`DROP INDEX "IDX_0d9a1738f2cf7f3b1c3334dfab"`, undefined);
await queryRunner.query(`DROP TABLE "relay"`, undefined);
await queryRunner.query(`DROP TYPE "relay_status_enum"`, undefined);
}

}
5 changes: 5 additions & 0 deletions package.json
Original file line number Diff line number Diff line change
Expand Up @@ -50,6 +50,7 @@
"@types/is-url": "1.2.28",
"@types/js-yaml": "3.12.3",
"@types/jsdom": "16.2.1",
"@types/jsonld": "1.5.1",
"@types/katex": "0.11.0",
"@types/koa": "2.11.3",
"@types/koa-bodyparser": "4.3.0",
Expand All @@ -65,6 +66,7 @@
"@types/lolex": "5.1.0",
"@types/mocha": "7.0.2",
"@types/node": "13.13.5",
"@types/node-fetch": "2.5.7",
"@types/nodemailer": "6.4.0",
"@types/nprogress": "0.2.0",
"@types/oauth": "0.9.1",
Expand Down Expand Up @@ -95,6 +97,7 @@
"@types/websocket": "1.0.0",
"@types/ws": "7.2.4",
"@typescript-eslint/parser": "2.31.0",
"abort-controller": "3.0.0",
"agentkeepalive": "4.1.0",
"animejs": "3.2.0",
"apexcharts": "3.12.0",
Expand Down Expand Up @@ -137,6 +140,7 @@
"gulp-typescript": "5.0.1",
"hard-source-webpack-plugin": "0.13.1",
"html-minifier": "4.0.0",
"http-proxy-agent": "4.0.1",
"http-signature": "1.3.4",
"https-proxy-agent": "5.0.0",
"insert-text-at-cursor": "0.3.0",
Expand All @@ -146,6 +150,7 @@
"jsdom": "16.2.2",
"json5": "2.1.3",
"json5-loader": "4.0.0",
"jsonld": "3.1.0",
"jsrsasign": "8.0.15",
"katex": "0.11.1",
"koa": "2.11.0",
Expand Down
4 changes: 3 additions & 1 deletion src/@types/http-signature.d.ts
Original file line number Diff line number Diff line change
Expand Up @@ -19,10 +19,12 @@ declare module 'http-signature' {
clockSkew?: number;
}

interface IParsedSignature {
interface IParsedSignature {
scheme: string;
params: ISignature;
signingString: string;
algorithm: string;
keyId: string;
}

type RequestSignerConstructorOptions =
Expand Down
7 changes: 6 additions & 1 deletion src/client/app/admin/views/index.vue
Original file line number Diff line number Diff line change
Expand Up @@ -27,6 +27,7 @@
<li><router-link to="/users" active-class="active"><fa icon="users" fixed-width/>{{ $t('users') }}</router-link></li>
<li><router-link to="/drive" active-class="active"><fa icon="cloud" fixed-width/>{{ $t('@.drive') }}</router-link></li>
<li><router-link to="/federation" active-class="active"><fa :icon="faGlobe" fixed-width/>{{ $t('federation') }}</router-link></li>
<li><router-link to="/relays" active-class="active"><fa :icon="faProjectDiagram" fixed-width/>{{ $t('relays') }}</router-link></li>
<li><router-link to="/emoji" active-class="active"><fa :icon="faGrin" fixed-width/>{{ $t('emoji') }}</router-link></li>
<li><router-link to="/announcements" active-class="active"><fa icon="broadcast-tower" fixed-width/>{{ $t('announcements') }}</router-link></li>
<li><router-link to="/abuse" active-class="active"><fa :icon="faExclamationCircle" fixed-width/>{{ $t('abuse') }}</router-link></li>
Expand All @@ -51,6 +52,7 @@
<div v-if="page == 'announcements'"><x-announcements/></div>
<div v-if="page == 'drive'"><x-drive/></div>
<div v-if="page == 'federation'"><x-federation/></div>
<div v-if="page == 'relays'"><x-relays/></div>
<div v-if="page == 'abuse'"><x-abuse/></div>
</div>
</main>
Expand All @@ -73,8 +75,9 @@ import XUsers from './users.vue';
import XDrive from './drive.vue';
import XAbuse from './abuse.vue';
import XFederation from './federation.vue';
import XRelays from "./relays.vue";
import { faHeadset, faArrowLeft, faGlobe, faExclamationCircle, faTasks, faStream, faDatabase } from '@fortawesome/free-solid-svg-icons';
import { faHeadset, faArrowLeft, faGlobe, faProjectDiagram, faExclamationCircle, faTasks, faStream, faDatabase } from '@fortawesome/free-solid-svg-icons';
import { faGrin } from '@fortawesome/free-regular-svg-icons';
// Detect the user agent
Expand All @@ -96,6 +99,7 @@ export default Vue.extend({
XDrive,
XAbuse,
XFederation,
XRelays,
},
provide: {
isMobile
Expand All @@ -109,6 +113,7 @@ export default Vue.extend({
faArrowLeft,
faHeadset,
faGlobe,
faProjectDiagram,
faExclamationCircle,
faTasks,
faStream,
Expand Down
89 changes: 89 additions & 0 deletions src/client/app/admin/views/relays.vue
Original file line number Diff line number Diff line change
@@ -0,0 +1,89 @@
<template>
<div>
<ui-card>
<template #title><fa icon="plus"/> {{ $t('add-relay') }}</template>
<section class="fit-top">
<ui-horizon-group inputs>
<ui-input v-model="inbox">
<span>{{ $t('inbox') }}</span>
</ui-input>
</ui-horizon-group>
<ui-button @click="add(inbox)">{{ $t('add') }}</ui-button>
</section>
</ui-card>

<ui-card>
<template #title><fa :icon="faProjectDiagram"/> {{ $t('added-relays') }}</template>
<section v-for="relay in relays" :key="relay.inbox" class="relayath">
<div>{{ relay.inbox }}</div>
<div>{{ $t(`status.${relay.status}`) }}</div>
<ui-button @click="remove(relay.inbox)">{{ $t('remove') }}</ui-button>
</section>
</ui-card>
</div>
</template>

<script lang="ts">
import Vue from 'vue';
import i18n from '../../i18n';
import { faProjectDiagram } from '@fortawesome/free-solid-svg-icons';
export default Vue.extend({
i18n: i18n('admin/views/relay.vue'),
data() {
return {
relays: [],
inbox: '',
faProjectDiagram
};
},
created() {
this.reload();
},
computed: {
},
methods: {
add(inbox: string) {
this.$root.api('admin/relays/add', {
inbox
}).then((relay: any) => {
this.inbox = '';
this.reload();
}).catch((e: any) => {
this.$root.dialog({
type: 'error',
text: e.message || e
});
});
},
remove(inbox: string) {
this.$root.api('admin/relays/remove', {
inbox
}).then(() => {
this.reload();
}).catch((e: any) => {
this.$root.dialog({
type: 'error',
text: e.message || e
});
});
},
reload() {
this.$root.api('admin/relays/list').then((relays: any) => {
this.relays = relays;
});
}
}
});
</script>

<style lang="stylus" scoped>
.relayath
> div
margin 0.3em
</style>
2 changes: 2 additions & 0 deletions src/db/postgre.ts
Original file line number Diff line number Diff line change
Expand Up @@ -49,6 +49,7 @@ import { Page } from '../models/entities/page';
import { PageLike } from '../models/entities/page-like';
import { ModerationLog } from '../models/entities/moderation-log';
import { UsedUsername } from '../models/entities/used-username';
import { Relay } from '../models/entities/relay';

const sqlLogger = dbLogger.createSubLogger('sql', 'white', false);

Expand Down Expand Up @@ -130,6 +131,7 @@ export const entities = [
ModerationLog,
ReversiGame,
ReversiMatching,
Relay,
...charts as any
];

Expand Down
12 changes: 5 additions & 7 deletions src/mfm/fromHtml.ts
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
import { parseFragment, DefaultTreeDocumentFragment } from 'parse5';
import { urlRegex } from './prelude';

export function fromHtml(html: string): string {
export function fromHtml(html: string, hashtagNames?: string[]): string {
const dom = parseFragment(html) as DefaultTreeDocumentFragment;

let text = '';
Expand Down Expand Up @@ -36,12 +36,10 @@ export function fromHtml(html: string): string {
const txt = getText(node);
const rel = node.attrs.find((x: any) => x.name == 'rel');
const href = node.attrs.find((x: any) => x.name == 'href');
const _class = node.attrs.find((x: any) => x.name == 'class');
const isHashtag = rel?.value?.match('tag') || _class?.value?.match('hashtag');

// ハッシュタグ / hrefがない / txtがURL
if (isHashtag || !href || href.value == txt) {
text += isHashtag || txt.match(urlRegex) ? txt : `<${txt}>`;
// ハッシュタグ
if (hashtagNames && href && hashtagNames.map(x => x.toLowerCase()).includes(txt.toLowerCase())) {
text += txt;
// メンション
} else if (txt.startsWith('@') && !(rel && rel.value.match(/^me /))) {
const part = txt.split('@');
Expand All @@ -56,7 +54,7 @@ export function fromHtml(html: string): string {
}
// その他
} else {
text += `[${txt}](${href.value})`;
text += (!href || (txt === href.value && txt.match(urlRegex))) ? txt : `[${txt}](${href.value})`;
}
break;

Expand Down
2 changes: 1 addition & 1 deletion src/misc/detect-url-mime.ts
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
import { createTemp } from './create-temp';
import { downloadUrl } from './donwload-url';
import { downloadUrl } from './download-url';
import { detectType } from './get-file-info';

export async function detectUrlMime(url: string) {
Expand Down
59 changes: 0 additions & 59 deletions src/misc/donwload-url.ts

This file was deleted.

2 changes: 1 addition & 1 deletion src/misc/download-text-file.ts
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@ import * as fs from 'fs';
import * as util from 'util';
import Logger from '../services/logger';
import { createTemp } from './create-temp';
import { downloadUrl } from './donwload-url';
import { downloadUrl } from './download-url';

const logger = new Logger('download-text-file');

Expand Down
Loading

0 comments on commit b4e469e

Please sign in to comment.