mirror of
https://github.com/misskey-dev/misskey.git
synced 2024-12-23 00:29:22 +09:00
refactor
This commit is contained in:
parent
10dc244d93
commit
e7171d9ab2
@ -14,7 +14,13 @@ import EmEmoji from '@/components/EmEmoji.vue';
|
|||||||
import EmCustomEmoji from '@/components/EmCustomEmoji.vue';
|
import EmCustomEmoji from '@/components/EmCustomEmoji.vue';
|
||||||
import EmA from '@/components/EmA.vue';
|
import EmA from '@/components/EmA.vue';
|
||||||
import { host } from '@/config.js';
|
import { host } from '@/config.js';
|
||||||
import { safeParseFloat } from '@/to-be-shared/safe-parse.js';
|
|
||||||
|
function safeParseFloat(str: unknown): number | null {
|
||||||
|
if (typeof str !== 'string' || str === '') return null;
|
||||||
|
const num = parseFloat(str);
|
||||||
|
if (isNaN(num)) return null;
|
||||||
|
return num;
|
||||||
|
}
|
||||||
|
|
||||||
const QUOTE_STYLE = `
|
const QUOTE_STYLE = `
|
||||||
display: block;
|
display: block;
|
||||||
|
@ -28,7 +28,14 @@ import { defineAsyncComponent, ref } from 'vue';
|
|||||||
import { toUnicode as decodePunycode } from 'punycode/';
|
import { toUnicode as decodePunycode } from 'punycode/';
|
||||||
import EmA from './EmA.vue';
|
import EmA from './EmA.vue';
|
||||||
import { url as local } from '@/config.js';
|
import { url as local } from '@/config.js';
|
||||||
import { safeURIDecode } from '@/to-be-shared/safe-uri-decode.js';
|
|
||||||
|
function safeURIDecode(str: string): string {
|
||||||
|
try {
|
||||||
|
return decodeURIComponent(str);
|
||||||
|
} catch {
|
||||||
|
return str;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
const props = withDefaults(defineProps<{
|
const props = withDefaults(defineProps<{
|
||||||
url: string;
|
url: string;
|
||||||
|
@ -3,7 +3,7 @@
|
|||||||
* SPDX-License-Identifier: AGPL-3.0-only
|
* SPDX-License-Identifier: AGPL-3.0-only
|
||||||
*/
|
*/
|
||||||
|
|
||||||
import { query } from './url.js';
|
import { query } from '@@/js/url.js';
|
||||||
import { url } from '@/config.js';
|
import { url } from '@/config.js';
|
||||||
import { instance } from '@/instance.js';
|
import { instance } from '@/instance.js';
|
||||||
|
|
||||||
|
@ -1,11 +0,0 @@
|
|||||||
/*
|
|
||||||
* SPDX-FileCopyrightText: syuilo and misskey-project
|
|
||||||
* SPDX-License-Identifier: AGPL-3.0-only
|
|
||||||
*/
|
|
||||||
|
|
||||||
export function safeParseFloat(str: unknown): number | null {
|
|
||||||
if (typeof str !== 'string' || str === '') return null;
|
|
||||||
const num = parseFloat(str);
|
|
||||||
if (isNaN(num)) return null;
|
|
||||||
return num;
|
|
||||||
}
|
|
@ -1,12 +0,0 @@
|
|||||||
/*
|
|
||||||
* SPDX-FileCopyrightText: syuilo and misskey-project
|
|
||||||
* SPDX-License-Identifier: AGPL-3.0-only
|
|
||||||
*/
|
|
||||||
|
|
||||||
export function safeURIDecode(str: string): string {
|
|
||||||
try {
|
|
||||||
return decodeURIComponent(str);
|
|
||||||
} catch {
|
|
||||||
return str;
|
|
||||||
}
|
|
||||||
}
|
|
@ -66,6 +66,7 @@ import { defineAsyncComponent, ref } from 'vue';
|
|||||||
import { toUnicode } from 'punycode/';
|
import { toUnicode } from 'punycode/';
|
||||||
import * as Misskey from 'misskey-js';
|
import * as Misskey from 'misskey-js';
|
||||||
import { supported as webAuthnSupported, get as webAuthnRequest, parseRequestOptionsFromJSON } from '@github/webauthn-json/browser-ponyfill';
|
import { supported as webAuthnSupported, get as webAuthnRequest, parseRequestOptionsFromJSON } from '@github/webauthn-json/browser-ponyfill';
|
||||||
|
import { query, extractDomain } from '@@/js/url.js';
|
||||||
import type { OpenOnRemoteOptions } from '@/scripts/please-login.js';
|
import type { OpenOnRemoteOptions } from '@/scripts/please-login.js';
|
||||||
import { showSuspendedDialog } from '@/scripts/show-suspended-dialog.js';
|
import { showSuspendedDialog } from '@/scripts/show-suspended-dialog.js';
|
||||||
import MkButton from '@/components/MkButton.vue';
|
import MkButton from '@/components/MkButton.vue';
|
||||||
@ -74,7 +75,6 @@ import MkInfo from '@/components/MkInfo.vue';
|
|||||||
import { host as configHost } from '@/config.js';
|
import { host as configHost } from '@/config.js';
|
||||||
import * as os from '@/os.js';
|
import * as os from '@/os.js';
|
||||||
import { misskeyApi } from '@/scripts/misskey-api.js';
|
import { misskeyApi } from '@/scripts/misskey-api.js';
|
||||||
import { query, extractDomain } from '@/scripts/url.js';
|
|
||||||
import { login } from '@/account.js';
|
import { login } from '@/account.js';
|
||||||
import { i18n } from '@/i18n.js';
|
import { i18n } from '@/i18n.js';
|
||||||
|
|
||||||
|
@ -19,7 +19,13 @@ import MkSparkle from '@/components/MkSparkle.vue';
|
|||||||
import MkA, { MkABehavior } from '@/components/global/MkA.vue';
|
import MkA, { MkABehavior } from '@/components/global/MkA.vue';
|
||||||
import { host } from '@/config.js';
|
import { host } from '@/config.js';
|
||||||
import { defaultStore } from '@/store.js';
|
import { defaultStore } from '@/store.js';
|
||||||
import { safeParseFloat } from '@/scripts/safe-parse.js';
|
|
||||||
|
function safeParseFloat(str: unknown): number | null {
|
||||||
|
if (typeof str !== 'string' || str === '') return null;
|
||||||
|
const num = parseFloat(str);
|
||||||
|
if (isNaN(num)) return null;
|
||||||
|
return num;
|
||||||
|
}
|
||||||
|
|
||||||
const QUOTE_STYLE = `
|
const QUOTE_STYLE = `
|
||||||
display: block;
|
display: block;
|
||||||
|
@ -30,10 +30,17 @@ import { toUnicode as decodePunycode } from 'punycode/';
|
|||||||
import { url as local } from '@/config.js';
|
import { url as local } from '@/config.js';
|
||||||
import * as os from '@/os.js';
|
import * as os from '@/os.js';
|
||||||
import { useTooltip } from '@/scripts/use-tooltip.js';
|
import { useTooltip } from '@/scripts/use-tooltip.js';
|
||||||
import { safeURIDecode } from '@/scripts/safe-uri-decode.js';
|
|
||||||
import { isEnabledUrlPreview } from '@/instance.js';
|
import { isEnabledUrlPreview } from '@/instance.js';
|
||||||
import { MkABehavior } from '@/components/global/MkA.vue';
|
import { MkABehavior } from '@/components/global/MkA.vue';
|
||||||
|
|
||||||
|
function safeURIDecode(str: string): string {
|
||||||
|
try {
|
||||||
|
return decodeURIComponent(str);
|
||||||
|
} catch {
|
||||||
|
return str;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
const props = withDefaults(defineProps<{
|
const props = withDefaults(defineProps<{
|
||||||
url: string;
|
url: string;
|
||||||
rel?: string;
|
rel?: string;
|
||||||
|
@ -7,7 +7,14 @@
|
|||||||
|
|
||||||
import { Component, onMounted, shallowRef, ShallowRef } from 'vue';
|
import { Component, onMounted, shallowRef, ShallowRef } from 'vue';
|
||||||
import { EventEmitter } from 'eventemitter3';
|
import { EventEmitter } from 'eventemitter3';
|
||||||
import { safeURIDecode } from '@/scripts/safe-uri-decode.js';
|
|
||||||
|
function safeURIDecode(str: string): string {
|
||||||
|
try {
|
||||||
|
return decodeURIComponent(str);
|
||||||
|
} catch {
|
||||||
|
return str;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
interface RouteDefBase {
|
interface RouteDefBase {
|
||||||
path: string;
|
path: string;
|
||||||
|
@ -3,7 +3,7 @@
|
|||||||
* SPDX-License-Identifier: AGPL-3.0-only
|
* SPDX-License-Identifier: AGPL-3.0-only
|
||||||
*/
|
*/
|
||||||
|
|
||||||
import { query } from '@/scripts/url.js';
|
import { query } from '@@/js/url.js';
|
||||||
import { url } from '@/config.js';
|
import { url } from '@/config.js';
|
||||||
import { instance } from '@/instance.js';
|
import { instance } from '@/instance.js';
|
||||||
|
|
||||||
|
@ -3,7 +3,7 @@
|
|||||||
* SPDX-License-Identifier: AGPL-3.0-only
|
* SPDX-License-Identifier: AGPL-3.0-only
|
||||||
*/
|
*/
|
||||||
|
|
||||||
import { appendQuery } from './url.js';
|
import { appendQuery } from '@@/js/url.js';
|
||||||
import * as config from '@/config.js';
|
import * as config from '@/config.js';
|
||||||
|
|
||||||
export function popout(path: string, w?: HTMLElement) {
|
export function popout(path: string, w?: HTMLElement) {
|
||||||
|
@ -1,11 +0,0 @@
|
|||||||
/*
|
|
||||||
* SPDX-FileCopyrightText: syuilo and misskey-project
|
|
||||||
* SPDX-License-Identifier: AGPL-3.0-only
|
|
||||||
*/
|
|
||||||
|
|
||||||
export function safeParseFloat(str: unknown): number | null {
|
|
||||||
if (typeof str !== 'string' || str === '') return null;
|
|
||||||
const num = parseFloat(str);
|
|
||||||
if (isNaN(num)) return null;
|
|
||||||
return num;
|
|
||||||
}
|
|
@ -1,12 +0,0 @@
|
|||||||
/*
|
|
||||||
* SPDX-FileCopyrightText: syuilo and misskey-project
|
|
||||||
* SPDX-License-Identifier: AGPL-3.0-only
|
|
||||||
*/
|
|
||||||
|
|
||||||
export function safeURIDecode(str: string): string {
|
|
||||||
try {
|
|
||||||
return decodeURIComponent(str);
|
|
||||||
} catch {
|
|
||||||
return str;
|
|
||||||
}
|
|
||||||
}
|
|
@ -1,28 +0,0 @@
|
|||||||
/*
|
|
||||||
* SPDX-FileCopyrightText: syuilo and misskey-project
|
|
||||||
* SPDX-License-Identifier: AGPL-3.0-only
|
|
||||||
*/
|
|
||||||
|
|
||||||
/* objを検査して
|
|
||||||
* 1. 配列に何も入っていない時はクエリを付けない
|
|
||||||
* 2. プロパティがundefinedの時はクエリを付けない
|
|
||||||
* (new URLSearchParams(obj)ではそこまで丁寧なことをしてくれない)
|
|
||||||
*/
|
|
||||||
export function query(obj: Record<string, any>): string {
|
|
||||||
const params = Object.entries(obj)
|
|
||||||
.filter(([, v]) => Array.isArray(v) ? v.length : v !== undefined)
|
|
||||||
.reduce((a, [k, v]) => (a[k] = v, a), {} as Record<string, any>);
|
|
||||||
|
|
||||||
return Object.entries(params)
|
|
||||||
.map((p) => `${p[0]}=${encodeURIComponent(p[1])}`)
|
|
||||||
.join('&');
|
|
||||||
}
|
|
||||||
|
|
||||||
export function appendQuery(url: string, query: string): string {
|
|
||||||
return `${url}${/\?/.test(url) ? url.endsWith('?') ? '' : '&' : '?'}${query}`;
|
|
||||||
}
|
|
||||||
|
|
||||||
export function extractDomain(url: string) {
|
|
||||||
const match = url.match(/^(?:https?:)?(?:\/\/)?(?:[^@\n]+@)?([^:\/\n]+)/im);
|
|
||||||
return match ? match[1] : null;
|
|
||||||
}
|
|
Loading…
Reference in New Issue
Block a user