chore: code reformat

This commit is contained in:
Laura Hausmann 2023-07-27 00:44:38 +02:00
parent 5a2ca61f26
commit b462e9d1fc
No known key found for this signature in database
GPG key ID: D044E84C5BE01605
8 changed files with 141 additions and 78 deletions

View file

@ -295,8 +295,7 @@ export const NoteRepository = db.getRepository(Note).extend({
): Promise<Packed<"Note"> | undefined> { ): Promise<Packed<"Note"> | undefined> {
try { try {
return await this.pack(src, me, options); return await this.pack(src, me, options);
} } catch {
catch {
return undefined; return undefined;
} }
}, },

View file

@ -8,7 +8,11 @@ import { apiTimelineMastodon } from "./endpoints/timeline.js";
import { apiNotificationsMastodon } from "./endpoints/notifications.js"; import { apiNotificationsMastodon } from "./endpoints/notifications.js";
import { apiSearchMastodon } from "./endpoints/search.js"; import { apiSearchMastodon } from "./endpoints/search.js";
import { getInstance } from "./endpoints/meta.js"; import { getInstance } from "./endpoints/meta.js";
import {convertAccount, convertAnnouncement, convertFilter} from "./converters.js"; import {
convertAccount,
convertAnnouncement,
convertFilter,
} from "./converters.js";
import { convertId, IdType } from "../index.js"; import { convertId, IdType } from "../index.js";
import { Users } from "@/models/index.js"; import { Users } from "@/models/index.js";
import { IsNull } from "typeorm"; import { IsNull } from "typeorm";
@ -55,15 +59,18 @@ export function apiMastodonCompatible(router: Router): void {
try { try {
const data = await client.getInstance(); const data = await client.getInstance();
const admin = await Users.findOne({ const admin = await Users.findOne({
where: { where: {
host: IsNull(), host: IsNull(),
isAdmin: true, isAdmin: true,
isDeleted: false, isDeleted: false,
isSuspended: false, isSuspended: false,
}, },
order: { id: "ASC" }, order: { id: "ASC" },
}); });
const contact = admin == null ? null : convertAccount((await client.getAccount(admin.id)).data); const contact =
admin == null
? null
: convertAccount((await client.getAccount(admin.id)).data);
ctx.body = await getInstance(data.data, contact); ctx.body = await getInstance(data.data, contact);
} catch (e: any) { } catch (e: any) {
console.error(e); console.error(e);

View file

@ -6,13 +6,15 @@ import { IsNull } from "typeorm";
import { MAX_NOTE_TEXT_LENGTH, FILE_TYPE_BROWSERSAFE } from "@/const.js"; import { MAX_NOTE_TEXT_LENGTH, FILE_TYPE_BROWSERSAFE } from "@/const.js";
// TODO: add iceshrimp features // TODO: add iceshrimp features
export async function getInstance(response: Entity.Instance, contact: Entity.Account) { export async function getInstance(
const [meta, totalUsers, totalStatuses] = response: Entity.Instance,
await Promise.all([ contact: Entity.Account,
fetchMeta(true), ) {
Users.count({ where: { host: IsNull() } }), const [meta, totalUsers, totalStatuses] = await Promise.all([
Notes.count({ where: { userHost: IsNull() } }), fetchMeta(true),
]); Users.count({ where: { host: IsNull() } }),
Notes.count({ where: { userHost: IsNull() } }),
]);
return { return {
uri: response.uri, uri: response.uri,

View file

@ -26,7 +26,7 @@ export default defineComponent({
type: Boolean, type: Boolean,
required: false, required: false,
default: false, default: false,
} },
}, },
setup(props, { slots, expose }) { setup(props, { slots, expose }) {

View file

@ -78,16 +78,16 @@ const buttonsLeft = $computed(() => {
}); });
const buttonsRight = $computed(() => { const buttonsRight = $computed(() => {
const buttons = [ const buttons = [
{ {
icon: 'ph-arrow-clockwise ph-bold ph-lg', icon: "ph-arrow-clockwise ph-bold ph-lg",
title: i18n.ts.reload, title: i18n.ts.reload,
onClick: reload, onClick: reload,
}, },
{ {
icon: "ph-arrows-out-simple ph-bold ph-lg", icon: "ph-arrows-out-simple ph-bold ph-lg",
title: i18n.ts.showInPage, title: i18n.ts.showInPage,
onClick: expand, onClick: expand,
}, },
]; ];
return buttons; return buttons;

View file

@ -64,7 +64,9 @@
><i class="ph-code ph-bold ph-lg"></i ><i class="ph-code ph-bold ph-lg"></i
></template> ></template>
{{ i18n.ts._aboutIceshrimp.source }} {{ i18n.ts._aboutIceshrimp.source }}
<template #suffix>Iceshrimp development</template> <template #suffix
>Iceshrimp development</template
>
</FormLink> </FormLink>
</div> </div>
</FormSection> </FormSection>

View file

@ -8,7 +8,8 @@
<template #caption> <template #caption>
<I18n :src="i18n.ts.i18nInfo" tag="span"> <I18n :src="i18n.ts.i18nInfo" tag="span">
<template #link> <template #link>
<MkLink url="https://hosted.weblate.org/engage/firefish/" <MkLink
url="https://hosted.weblate.org/engage/firefish/"
>Weblate</MkLink >Weblate</MkLink
> >
</template> </template>

View file

@ -8,64 +8,103 @@
itemKey="id" itemKey="id"
:animation="150" :animation="150"
:handle="'.' + $style.itemHandle" :handle="'.' + $style.itemHandle"
@start="e => e.item.classList.add('active')" @start="(e) => e.item.classList.add('active')"
@end="e => e.item.classList.remove('active')" @end="(e) => e.item.classList.remove('active')"
> >
<template #item="{element,index}"> <template #item="{ element, index }">
<div <div
v-if="element.type === '-' || navbarItemDef[element.type]" v-if="
element.type === '-' ||
navbarItemDef[element.type]
"
:class="$style.item" :class="$style.item"
> >
<button class="_button" :class="$style.itemHandle"><i class="ph-list ph-bold ph-lg"></i></button> <button class="_button" :class="$style.itemHandle">
<i class="ti-fw" :class="[$style.itemIcon, navbarItemDef[element.type]?.icon]"></i><span :class="$style.itemText">{{ i18n.ts[navbarItemDef[element.type]?.title] ?? i18n.ts.divider }}</span> <i class="ph-list ph-bold ph-lg"></i>
<button class="_button" :class="$style.itemRemove" @click="removeItem(index)"><i class="ph-x ph-bold ph-lg"></i></button> </button>
<i
class="ti-fw"
:class="[
$style.itemIcon,
navbarItemDef[element.type]?.icon,
]"
></i
><span :class="$style.itemText">{{
i18n.ts[navbarItemDef[element.type]?.title] ??
i18n.ts.divider
}}</span>
<button
class="_button"
:class="$style.itemRemove"
@click="removeItem(index)"
>
<i class="ph-x ph-bold ph-lg"></i>
</button>
</div> </div>
</template> </template>
</Sortable> </Sortable>
</MkContainer> </MkContainer>
</FormSlot> </FormSlot>
<div class="buttons"> <div class="buttons">
<MkButton inline @click="addItem"><i class="ph-plus ph-bold ph-lg"></i> {{ i18n.ts.addItem }}</MkButton> <MkButton inline @click="addItem"
<MkButton inline danger @click="reset"><i class="ph-arrow-clockwise ph-bold ph-lg"></i> {{ i18n.ts.default }}</MkButton> ><i class="ph-plus ph-bold ph-lg"></i>
<MkButton inline primary class="save" @click="save"><i class="ph-floppy-disk ph-bold ph-lg"></i> {{ i18n.ts.save }}</MkButton> {{ i18n.ts.addItem }}</MkButton
>
<MkButton inline danger @click="reset"
><i class="ph-arrow-clockwise ph-bold ph-lg"></i>
{{ i18n.ts.default }}</MkButton
>
<MkButton inline primary class="save" @click="save"
><i class="ph-floppy-disk ph-bold ph-lg"></i>
{{ i18n.ts.save }}</MkButton
>
</div> </div>
<FormRadios v-model="menuDisplay"> <FormRadios v-model="menuDisplay">
<template #label>{{ i18n.ts.display }}</template> <template #label>{{ i18n.ts.display }}</template>
<option value="sideFull">{{ i18n.ts._menuDisplay.sideFull }}</option> <option value="sideFull">
<option value="sideIcon">{{ i18n.ts._menuDisplay.sideIcon }}</option> {{ i18n.ts._menuDisplay.sideFull }}
</option>
<option value="sideIcon">
{{ i18n.ts._menuDisplay.sideIcon }}
</option>
<!--<option value="top">{{ i18n.ts._menuDisplay.top }}</option>--> <!--<option value="top">{{ i18n.ts._menuDisplay.top }}</option>-->
<!-- <MkRadio v-model="menuDisplay" value="hide" disabled>{{ i18n.ts._menuDisplay.hide }}</MkRadio>--> <!-- TODO: サイドバーを完全に隠せるようにすると別途ハンバーガーボタンのようなものをUIに表示する必要があり面倒 --> <!-- <MkRadio v-model="menuDisplay" value="hide" disabled>{{ i18n.ts._menuDisplay.hide }}</MkRadio>-->
<!-- TODO: サイドバーを完全に隠せるようにすると別途ハンバーガーボタンのようなものをUIに表示する必要があり面倒 -->
</FormRadios> </FormRadios>
</div> </div>
</template> </template>
<script lang="ts" setup> <script lang="ts" setup>
import { computed, defineAsyncComponent, ref, watch } from 'vue'; import { computed, defineAsyncComponent, ref, watch } from "vue";
import FormRadios from "@/components/form/radios.vue"; import FormRadios from "@/components/form/radios.vue";
import MkButton from '@/components/MkButton.vue'; import MkButton from "@/components/MkButton.vue";
import FormSlot from '@/components/form/slot.vue'; import FormSlot from "@/components/form/slot.vue";
import MkContainer from '@/components/MkContainer.vue'; import MkContainer from "@/components/MkContainer.vue";
import * as os from '@/os'; import * as os from "@/os";
import { navbarItemDef } from '@/navbar'; import { navbarItemDef } from "@/navbar";
import { defaultStore } from '@/store'; import { defaultStore } from "@/store";
import { unisonReload } from '@/scripts/unison-reload'; import { unisonReload } from "@/scripts/unison-reload";
import { i18n } from '@/i18n'; import { i18n } from "@/i18n";
import { definePageMetadata } from '@/scripts/page-metadata'; import { definePageMetadata } from "@/scripts/page-metadata";
import { deepClone } from '@/scripts/clone'; import { deepClone } from "@/scripts/clone";
const Sortable = defineAsyncComponent(() => import('vuedraggable').then(x => x.default)); const Sortable = defineAsyncComponent(() =>
import("vuedraggable").then((x) => x.default),
);
const items = ref(defaultStore.state.menu.map(x => ({ const items = ref(
id: Math.random().toString(), defaultStore.state.menu.map((x) => ({
type: x, id: Math.random().toString(),
}))); type: x,
})),
);
const menuDisplay = computed(defaultStore.makeGetterSetter('menuDisplay')); const menuDisplay = computed(defaultStore.makeGetterSetter("menuDisplay"));
async function reloadAsk() { async function reloadAsk() {
const { canceled } = await os.confirm({ const { canceled } = await os.confirm({
type: 'info', type: "info",
text: i18n.ts.reloadToApplySetting, text: i18n.ts.reloadToApplySetting,
}); });
if (canceled) return; if (canceled) return;
@ -74,20 +113,30 @@ async function reloadAsk() {
} }
async function addItem() { async function addItem() {
const menu = Object.keys(navbarItemDef).filter(k => !defaultStore.state.menu.includes(k)); const menu = Object.keys(navbarItemDef).filter(
(k) => !defaultStore.state.menu.includes(k),
);
const { canceled, result: item } = await os.select({ const { canceled, result: item } = await os.select({
title: i18n.ts.addItem, title: i18n.ts.addItem,
items: [...menu.map(k => ({ items: [
value: k, text: i18n.ts[navbarItemDef[k].title], ...menu.map((k) => ({
})), { value: k,
value: '-', text: i18n.ts.divider, text: i18n.ts[navbarItemDef[k].title],
}], })),
{
value: "-",
text: i18n.ts.divider,
},
],
}); });
if (canceled) return; if (canceled) return;
items.value = [...items.value, { items.value = [
id: Math.random().toString(), ...items.value,
type: item, {
}]; id: Math.random().toString(),
type: item,
},
];
} }
function removeItem(index: number) { function removeItem(index: number) {
@ -95,12 +144,15 @@ function removeItem(index: number) {
} }
async function save() { async function save() {
defaultStore.set('menu', items.value.map(x => x.type)); defaultStore.set(
"menu",
items.value.map((x) => x.type),
);
await reloadAsk(); await reloadAsk();
} }
function reset() { function reset() {
items.value = defaultStore.def.menu.default.map(x => ({ items.value = defaultStore.def.menu.default.map((x) => ({
id: Math.random().toString(), id: Math.random().toString(),
type: x, type: x,
})); }));
@ -116,7 +168,7 @@ const headerTabs = $computed(() => []);
definePageMetadata({ definePageMetadata({
title: i18n.ts.navbar, title: i18n.ts.navbar,
icon: 'ti ti-list', icon: "ti ti-list",
}); });
</script> </script>
@ -159,4 +211,4 @@ definePageMetadata({
margin: 0 8px; margin: 0 8px;
opacity: 0.5; opacity: 0.5;
} }
</style> </style>