From 9b657111930cb236a43361c58d47ca2fddc3c961 Mon Sep 17 00:00:00 2001 From: ThatOneCalculator Date: Tue, 11 Apr 2023 10:03:25 -0700 Subject: [PATCH] feat: admin lookup files/instance --- packages/client/src/pages/admin/files.vue | 34 ++----------------- packages/client/src/pages/admin/index.vue | 6 ++-- packages/client/src/scripts/lookup-file.ts | 27 +++++++++++++++ .../client/src/scripts/lookup-instance.ts | 25 ++++++++++++++ 4 files changed, 58 insertions(+), 34 deletions(-) create mode 100644 packages/client/src/scripts/lookup-file.ts create mode 100644 packages/client/src/scripts/lookup-instance.ts diff --git a/packages/client/src/pages/admin/files.vue b/packages/client/src/pages/admin/files.vue index e752eb82c..e808ab65f 100644 --- a/packages/client/src/pages/admin/files.vue +++ b/packages/client/src/pages/admin/files.vue @@ -86,7 +86,7 @@ import MkButton from "@/components/MkButton.vue"; import MkInput from "@/components/form/input.vue"; import MkSelect from "@/components/form/select.vue"; import MkFileListForAdmin from "@/components/MkFileListForAdmin.vue"; -import bytes from "@/filters/bytes"; +import { lookupFile } from "@/scripts/lookup-file"; import * as os from "@/os"; import { i18n } from "@/i18n"; import { definePageMetadata } from "@/scripts/page-metadata"; @@ -118,41 +118,11 @@ function clear() { }); } -function show(file) { - os.pageWindow(`/admin/file/${file.id}`); -} - -async function find() { - const { canceled, result: q } = await os.inputText({ - title: i18n.ts.fileIdOrUrl, - allowEmpty: false, - }); - if (canceled) return; - - os.api( - "admin/drive/show-file", - q.startsWith("http://") || q.startsWith("https://") - ? { url: q.trim() } - : { fileId: q.trim() } - ) - .then((file) => { - show(file); - }) - .catch((err) => { - if (err.code === "NO_SUCH_FILE") { - os.alert({ - type: "error", - text: i18n.ts.notFound, - }); - } - }); -} - const headerActions = $computed(() => [ { text: i18n.ts.lookup, icon: "ph-magnifying-glass ph-bold ph-lg", - handler: find, + handler: lookupFile, }, { text: i18n.ts.clearCachedFiles, diff --git a/packages/client/src/pages/admin/index.vue b/packages/client/src/pages/admin/index.vue index 07dac9c6b..7e88b64ab 100644 --- a/packages/client/src/pages/admin/index.vue +++ b/packages/client/src/pages/admin/index.vue @@ -79,6 +79,8 @@ import { version } from "@/config"; import { $i } from "@/account"; import * as os from "@/os"; import { lookupUser } from "@/scripts/lookup-user"; +import { lookupFile } from "@/scripts/lookup-file"; +import { lookupInstance } from "@/scripts/lookup-instance"; import { defaultStore } from "@/store"; import { useRouter } from "@/router"; import { @@ -371,14 +373,14 @@ const lookup = (ev) => { text: i18n.ts.file, icon: "ph-cloud ph-bold ph-lg", action: () => { - alert("TODO"); + lookupFile(); }, }, { text: i18n.ts.instance, icon: "ph-planet ph-bold ph-lg", action: () => { - alert("TODO"); + lookupInstance(); }, }, ], diff --git a/packages/client/src/scripts/lookup-file.ts b/packages/client/src/scripts/lookup-file.ts new file mode 100644 index 000000000..a151e097f --- /dev/null +++ b/packages/client/src/scripts/lookup-file.ts @@ -0,0 +1,27 @@ +import { i18n } from "@/i18n"; +import * as os from "@/os"; + +export async function lookupFile() { + const { canceled, result: q } = await os.inputText({ + title: i18n.ts.fileIdOrUrl, + }); + if (canceled) return; + + os.api( + "admin/drive/show-file", + q.startsWith("http://") || q.startsWith("https://") + ? { url: q.trim() } + : { fileId: q.trim() }, + ) + .then((file) => { + os.pageWindow(`/admin/file/${file.id}`); + }) + .catch((err) => { + if (err.code === "NO_SUCH_FILE") { + os.alert({ + type: "error", + text: i18n.ts.notFound, + }); + } + }); +} diff --git a/packages/client/src/scripts/lookup-instance.ts b/packages/client/src/scripts/lookup-instance.ts new file mode 100644 index 000000000..f3e92b02d --- /dev/null +++ b/packages/client/src/scripts/lookup-instance.ts @@ -0,0 +1,25 @@ +import { i18n } from "@/i18n"; +import * as os from "@/os"; + +export async function lookupInstance() { + const { canceled, result: q } = await os.inputText({ + title: i18n.ts.instance, + }); + if (canceled) return; + + os.api( + "federation/show-instance", + q.startsWith("http://") || q.startsWith("https://") + ? { url: q.trim() } + : { fileId: q.trim() }, + ) + .then((instance) => { + os.pageWindow(`/instance-info/${instance.host}`); + }) + .catch(() => { + os.alert({ + type: "error", + text: i18n.ts.notFound, + }); + }); +}