mirror of
https://github.com/MisskeyIO/misskey
synced 2024-12-23 02:58:18 +09:00
c2370a1be6
* chore: Add the SPDX information to each file Add copyright and licensing information as defined in version 3.0 of the REUSE Specification. * tweak format --------- Co-authored-by: syuilo <Syuilotan@yahoo.co.jp>
48 lines
1.1 KiB
TypeScript
48 lines
1.1 KiB
TypeScript
/*
|
|
* SPDX-FileCopyrightText: syuilo and other misskey contributors
|
|
* SPDX-License-Identifier: AGPL-3.0-only
|
|
*/
|
|
|
|
import * as os from '@/os';
|
|
import { i18n } from '@/i18n';
|
|
import { mainRouter } from '@/router';
|
|
import { Router } from '@/nirax';
|
|
|
|
export async function lookup(router?: Router) {
|
|
const _router = router ?? mainRouter;
|
|
|
|
const { canceled, result: temp } = await os.inputText({
|
|
title: i18n.ts.lookup,
|
|
});
|
|
const query = temp ? temp.trim() : '';
|
|
if (canceled) return;
|
|
|
|
if (query.startsWith('@') && !query.includes(' ')) {
|
|
_router.push(`/${query}`);
|
|
return;
|
|
}
|
|
|
|
if (query.startsWith('#')) {
|
|
_router.push(`/tags/${encodeURIComponent(query.substring(1))}`);
|
|
return;
|
|
}
|
|
|
|
if (query.startsWith('https://')) {
|
|
const promise = os.api('ap/show', {
|
|
uri: query,
|
|
});
|
|
|
|
os.promiseDialog(promise, null, null, i18n.ts.fetchingAsApObject);
|
|
|
|
const res = await promise;
|
|
|
|
if (res.type === 'User') {
|
|
_router.push(`/@${res.object.username}@${res.object.host}`);
|
|
} else if (res.type === 'Note') {
|
|
_router.push(`/notes/${res.object.id}`);
|
|
}
|
|
|
|
return;
|
|
}
|
|
}
|