revert: remove frontend changes

This commit is contained in:
MomentQYC 2023-08-11 21:54:24 +08:00
parent 5428019061
commit fed33b92e2
13 changed files with 23 additions and 43 deletions

View File

@ -85,7 +85,6 @@ import { deviceKind } from '@/scripts/device-kind';
import MkButton from '@/components/MkButton.vue';
import { versatileLang } from '@/scripts/intl-const';
import { defaultStore } from '@/store';
import { ErrorHandling } from '@/error';
type SummalyResult = Awaited<ReturnType<typeof summaly>>;
@ -125,7 +124,7 @@ let tweetHeight = $ref(150);
let unknownUrl = $ref(false);
const requestUrl = new URL(props.url);
if (!['http:', 'https:'].includes(requestUrl.protocol)) throw ErrorHandling('invalid url');
if (!['http:', 'https:'].includes(requestUrl.protocol)) throw new Error('invalid url');
if (requestUrl.hostname === 'twitter.com' || requestUrl.hostname === 'mobile.twitter.com') {
const m = requestUrl.pathname.match(/^\/.+\/status(?:es)?\/(\d+)/);

View File

@ -27,14 +27,13 @@ SPDX-License-Identifier: AGPL-3.0-only
import MkWindow from '@/components/MkWindow.vue';
import { versatileLang } from '@/scripts/intl-const';
import { defaultStore } from '@/store';
import { ErrorHandling } from '@/error';
const props = defineProps<{
url: string;
}>();
const requestUrl = new URL(props.url);
if (!['http:', 'https:'].includes(requestUrl.protocol)) throw ErrorHandling('invalid url');
if (!['http:', 'https:'].includes(requestUrl.protocol)) throw new Error('invalid url');
let fetching = $ref(true);
let title = $ref<string | null>(null);

View File

@ -30,7 +30,6 @@ import { url as local } from '@/config';
import * as os from '@/os';
import { useTooltip } from '@/scripts/use-tooltip';
import { safeURIDecode } from '@/scripts/safe-uri-decode';
import { ErrorHandling } from '@/error';
const props = defineProps<{
url: string;
@ -39,7 +38,7 @@ const props = defineProps<{
const self = props.url.startsWith(local);
const url = new URL(props.url);
if (!['http:', 'https:'].includes(url.protocol)) throw ErrorHandling('invalid url');
if (!['http:', 'https:'].includes(url.protocol)) throw new Error('invalid url');
const el = ref();
useTooltip(el, (showing) => {

View File

@ -1,7 +0,0 @@
export function ErrorHandling(message: string): Error {
const error = new Error(message);
if (process.env.NODE_ENV === 'production') {
error.stack = undefined;
}
return error;
}

View File

@ -50,7 +50,6 @@ import * as os from '@/os';
import { $i, login } from '@/account';
import { definePageMetadata } from '@/scripts/page-metadata';
import { i18n } from '@/i18n';
import { ErrorHandling } from '@/error';
const props = defineProps<{
token: string;
@ -63,7 +62,7 @@ function accepted() {
state = 'accepted';
if (session && session.app.callbackUrl) {
const url = new URL(session.app.callbackUrl);
if (['javascript:', 'file:', 'data:', 'mailto:', 'tel:'].includes(url.protocol)) throw ErrorHandling('invalid url');
if (['javascript:', 'file:', 'data:', 'mailto:', 'tel:'].includes(url.protocol)) throw new Error('invalid url');
location.href = `${session.app.callbackUrl}?token=${session.token}`;
}
}

View File

@ -14,7 +14,6 @@ import * as Acct from 'misskey-js/built/acct';
import * as os from '@/os';
import { mainRouter } from '@/router';
import { i18n } from '@/i18n';
import { ErrorHandling } from '@/error';
async function follow(user): Promise<void> {
const { canceled } = await os.confirm({
@ -34,7 +33,7 @@ async function follow(user): Promise<void> {
const acct = new URL(location.href).searchParams.get('acct');
if (acct == null) {
throw ErrorHandling('acct required');
throw new Error('acct required');
}
let promise;

View File

@ -136,7 +136,6 @@ import MkUserCardMini from '@/components/MkUserCardMini.vue';
import MkPagination from '@/components/MkPagination.vue';
import { getProxiedImageUrlNullable } from '@/scripts/media-proxy';
import { dateString } from '@/filters/date';
import { ErrorHandling } from '@/error';
const props = defineProps<{
host: string;
@ -174,8 +173,8 @@ async function fetch(): Promise<void> {
}
async function toggleBlock(): Promise<void> {
if (!meta) throw ErrorHandling('No meta?');
if (!instance) throw ErrorHandling('No instance?');
if (!meta) throw new Error('No meta?');
if (!instance) throw new Error('No instance?');
const { host } = instance;
await os.api('admin/update-meta', {
blockedHosts: isBlocked ? meta.blockedHosts.concat([host]) : meta.blockedHosts.filter(x => x !== host),
@ -183,7 +182,7 @@ async function toggleBlock(): Promise<void> {
}
async function toggleSuspend(): Promise<void> {
if (!instance) throw ErrorHandling('No instance?');
if (!instance) throw new Error('No instance?');
await os.api('admin/federation/update-instance', {
host: instance.host,
isSuspended: suspended,
@ -191,7 +190,7 @@ async function toggleSuspend(): Promise<void> {
}
function refreshMetadata(): void {
if (!instance) throw ErrorHandling('No instance?');
if (!instance) throw new Error('No instance?');
os.api('admin/federation/refresh-remote-instance-metadata', {
host: instance.host,
});

View File

@ -50,7 +50,6 @@ import * as os from '@/os';
import { $i, login } from '@/account';
import { i18n } from '@/i18n';
import { definePageMetadata } from '@/scripts/page-metadata';
import { ErrorHandling } from '@/error';
const props = defineProps<{
session: string;
@ -76,7 +75,7 @@ async function accept(): Promise<void> {
state = 'accepted';
if (props.callback) {
const cbUrl = new URL(props.callback);
if (['javascript:', 'file:', 'data:', 'mailto:', 'tel:'].includes(cbUrl.protocol)) throw ErrorHandling('invalid url');
if (['javascript:', 'file:', 'data:', 'mailto:', 'tel:'].includes(cbUrl.protocol)) throw new Error('invalid url');
cbUrl.searchParams.set('session', props.session);
location.href = cbUrl.href;
}

View File

@ -185,7 +185,6 @@ import { unisonReload } from '@/scripts/unison-reload';
import { i18n } from '@/i18n';
import { definePageMetadata } from '@/scripts/page-metadata';
import { miLocalStorage } from '@/local-storage';
import { ErrorHandling } from '@/error';
const lang = ref(miLocalStorage.getItem('lang'));
const fontSize = ref(miLocalStorage.getItem('fontSize'));
@ -277,7 +276,7 @@ function downloadEmojiIndex(lang: string) {
function download() {
switch (lang) {
case 'en-US': return import('../../unicode-emoji-indexes/en-US.json').then(x => x.default);
default: throw ErrorHandling('unrecognized lang: ' + lang);
default: throw new Error('unrecognized lang: ' + lang);
}
}
currentIndexes[lang] = await download();

View File

@ -51,8 +51,6 @@ import { i18n } from '@/i18n';
import { version, host } from '@/config';
import { definePageMetadata } from '@/scripts/page-metadata';
import { miLocalStorage } from '@/local-storage';
import { ErrorHandling } from '@/error';
const { t, ts } = i18n;
const defaultStoreSaveKeys: (keyof typeof defaultStore['state'])[] = [
@ -135,27 +133,27 @@ function isObject(value: unknown): value is Record<string, unknown> {
}
function validate(profile: any): void {
if (!isObject(profile)) throw ErrorHandling('not an object');
if (!isObject(profile)) throw new Error('not an object');
// Check if unnecessary properties exist
if (Object.keys(profile).some(key => !profileProps.includes(key))) throw ErrorHandling('Unnecessary properties exist');
if (Object.keys(profile).some(key => !profileProps.includes(key))) throw new Error('Unnecessary properties exist');
if (!profile.name) throw ErrorHandling('Missing required prop: name');
if (!profile.misskeyVersion) throw ErrorHandling('Missing required prop: misskeyVersion');
if (!profile.name) throw new Error('Missing required prop: name');
if (!profile.misskeyVersion) throw new Error('Missing required prop: misskeyVersion');
// Check if createdAt and updatedAt is Date
// https://zenn.dev/lollipop_onl/articles/eoz-judge-js-invalid-date
if (!profile.createdAt || Number.isNaN(new Date(profile.createdAt as any).getTime())) throw ErrorHandling('createdAt is falsy or not Date');
if (!profile.createdAt || Number.isNaN(new Date(profile.createdAt as any).getTime())) throw new Error('createdAt is falsy or not Date');
if (profile.updatedAt) {
if (Number.isNaN(new Date(profile.updatedAt as any).getTime())) {
throw ErrorHandling('updatedAt is not Date');
throw new Error('updatedAt is not Date');
}
} else if (profile.updatedAt !== null) {
throw ErrorHandling('updatedAt is not null');
throw new Error('updatedAt is not null');
}
if (!profile.settings) throw ErrorHandling('Missing required prop: settings');
if (!isObject(profile.settings)) throw ErrorHandling('Invalid prop: settings');
if (!profile.settings) throw new Error('Missing required prop: settings');
if (!isObject(profile.settings)) throw new Error('Invalid prop: settings');
}
function getSettings(): Profile['settings'] {

View File

@ -22,5 +22,5 @@ export function pleaseLogin(path?: string) {
},
}, 'closed');
console.log('signin required');
throw new Error('signin required');
}

View File

@ -3,8 +3,6 @@
* SPDX-License-Identifier: AGPL-3.0-only
*/
import { ErrorHandling } from '@/error';
const dateTimeIntervals = {
'day': 86400000,
'hour': 3600000,
@ -21,7 +19,7 @@ export function dateUTC(time: number[]): Date {
: time.length === 7 ? Date.UTC(time[0], time[1], time[2], time[3], time[4], time[5], time[6])
: null;
if (!d) throw ErrorHandling('wrong number of arguments');
if (!d) throw new Error('wrong number of arguments');
return new Date(d);
}

View File

@ -12,7 +12,6 @@ import { apiUrl } from '@/config';
import { $i } from '@/account';
import { alert } from '@/os';
import { i18n } from '@/i18n';
import { ErrorHandling } from '@/error';
type Uploading = {
id: string;
@ -35,7 +34,7 @@ export function uploadFile(
name?: string,
keepOriginal: boolean = defaultStore.state.keepOriginalUploading,
): Promise<Misskey.entities.DriveFile> {
if ($i == null) console.log('Not logged in');
if ($i == null) throw new Error('Not logged in');
if (folder && typeof folder === 'object') folder = folder.id;