feat: admin lookup files/instance

This commit is contained in:
ThatOneCalculator 2023-04-11 10:03:25 -07:00
parent 50fc292c7e
commit c5b0b07027
No known key found for this signature in database
GPG key ID: 8703CACD01000000
4 changed files with 58 additions and 34 deletions

View file

@ -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,

View file

@ -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();
},
},
],

View file

@ -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,
});
}
});
}

View file

@ -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,
});
});
}