Modify backend for Calckey
This commit is contained in:
parent
baef1b8ca9
commit
27d1d96c9d
|
@ -1,9 +1,8 @@
|
||||||
import { Inject, Injectable } from "@nestjs/common";
|
import define from "../../define.js";
|
||||||
import { Brackets } from "typeorm";
|
import { Brackets } from "typeorm";
|
||||||
import { Endpoint } from "@/server/api/endpoint-base.js";
|
import { Endpoint } from "@/server/api/endpoint-base.js";
|
||||||
import { QueryService } from "@/core/QueryService.js";
|
import { makePaginationQuery } from "@/server/api/common/make-pagination-query.js";
|
||||||
import type { ChannelsRepository } from "@/models/index.js";
|
import { Channels } from "@/models/index.js";
|
||||||
import { ChannelEntityService } from "@/core/entities/ChannelEntityService.js";
|
|
||||||
import { DI } from "@/di-symbols.js";
|
import { DI } from "@/di-symbols.js";
|
||||||
import { sqlLikeEscape } from "@/misc/sql-like-escape.js";
|
import { sqlLikeEscape } from "@/misc/sql-like-escape.js";
|
||||||
|
|
||||||
|
@ -41,44 +40,32 @@ export const paramDef = {
|
||||||
required: ["query"],
|
required: ["query"],
|
||||||
} as const;
|
} as const;
|
||||||
|
|
||||||
// eslint-disable-next-line import/no-default-export
|
export default define(meta, paramDef, async (ps, me) => {
|
||||||
@Injectable()
|
const query = makePaginationQuery(
|
||||||
export default class extends Endpoint<typeof meta, typeof paramDef> {
|
Channels.createQueryBuilder("channel"),
|
||||||
constructor(
|
ps.sinceId,
|
||||||
@Inject(DI.channelsRepository)
|
ps.untilId,
|
||||||
private channelsRepository: ChannelsRepository,
|
);
|
||||||
|
|
||||||
private channelEntityService: ChannelEntityService,
|
if (ps.type === "nameAndDescription") {
|
||||||
private queryService: QueryService,
|
query.andWhere(
|
||||||
) {
|
new Brackets((qb) => {
|
||||||
super(meta, paramDef, async (ps, me) => {
|
qb.where("channel.name ILIKE :q", {
|
||||||
const query = this.queryService.makePaginationQuery(
|
q: `%${sqlLikeEscape(ps.query)}%`,
|
||||||
this.channelsRepository.createQueryBuilder("channel"),
|
}).orWhere("channel.description ILIKE :q", {
|
||||||
ps.sinceId,
|
|
||||||
ps.untilId,
|
|
||||||
);
|
|
||||||
|
|
||||||
if (ps.type === "nameAndDescription") {
|
|
||||||
query.andWhere(
|
|
||||||
new Brackets((qb) => {
|
|
||||||
qb.where("channel.name ILIKE :q", {
|
|
||||||
q: `%${sqlLikeEscape(ps.query)}%`,
|
|
||||||
}).orWhere("channel.description ILIKE :q", {
|
|
||||||
q: `%${sqlLikeEscape(ps.query)}%`,
|
|
||||||
});
|
|
||||||
}),
|
|
||||||
);
|
|
||||||
} else {
|
|
||||||
query.andWhere("channel.name ILIKE :q", {
|
|
||||||
q: `%${sqlLikeEscape(ps.query)}%`,
|
q: `%${sqlLikeEscape(ps.query)}%`,
|
||||||
});
|
});
|
||||||
}
|
}),
|
||||||
|
);
|
||||||
const channels = await query.take(ps.limit).getMany();
|
} else {
|
||||||
|
query.andWhere("channel.name ILIKE :q", {
|
||||||
return await Promise.all(
|
q: `%${sqlLikeEscape(ps.query)}%`,
|
||||||
channels.map((x) => this.channelEntityService.pack(x, me)),
|
|
||||||
);
|
|
||||||
});
|
});
|
||||||
}
|
}
|
||||||
}
|
|
||||||
|
const channels = await query.take(ps.limit).getMany();
|
||||||
|
|
||||||
|
return await Promise.all(
|
||||||
|
channels.map((x) => Channels.pack(x, me)),
|
||||||
|
);
|
||||||
|
});
|
||||||
|
|
|
@ -22,7 +22,6 @@
|
||||||
>
|
>
|
||||||
<swiper-slide>
|
<swiper-slide>
|
||||||
<div class="_content grwlizim search">
|
<div class="_content grwlizim search">
|
||||||
<div class="gaps">
|
|
||||||
<MkInput
|
<MkInput
|
||||||
v-model="searchQuery"
|
v-model="searchQuery"
|
||||||
:large="true"
|
:large="true"
|
||||||
|
@ -30,12 +29,15 @@
|
||||||
type="search"
|
type="search"
|
||||||
>
|
>
|
||||||
<template #prefix
|
<template #prefix
|
||||||
><i class="ph-search ph-bold ph-lg"></i
|
><i
|
||||||
|
class="ph-magnifying-glass ph-bold ph-lg"
|
||||||
|
></i
|
||||||
></template>
|
></template>
|
||||||
</MkInput>
|
</MkInput>
|
||||||
<MkRadios
|
<MkRadios
|
||||||
v-model="searchType"
|
v-model="searchType"
|
||||||
@update:model-value="search()"
|
@update:model-value="search()"
|
||||||
|
class="_gap"
|
||||||
>
|
>
|
||||||
<option value="nameAndDescription">
|
<option value="nameAndDescription">
|
||||||
{{ i18n.ts._channel.nameAndDescription }}
|
{{ i18n.ts._channel.nameAndDescription }}
|
||||||
|
@ -50,9 +52,9 @@
|
||||||
gradate
|
gradate
|
||||||
rounded
|
rounded
|
||||||
@click="search"
|
@click="search"
|
||||||
|
class="_gap"
|
||||||
>{{ i18n.ts.search }}</MkButton
|
>{{ i18n.ts.search }}</MkButton
|
||||||
>
|
>
|
||||||
</div>
|
|
||||||
<MkFoldableSection v-if="channelPagination">
|
<MkFoldableSection v-if="channelPagination">
|
||||||
<template #header>{{
|
<template #header>{{
|
||||||
i18n.ts.searchResult
|
i18n.ts.searchResult
|
||||||
|
@ -124,10 +126,10 @@ import { Swiper, SwiperSlide } from "swiper/vue";
|
||||||
import MkChannelPreview from "@/components/MkChannelPreview.vue";
|
import MkChannelPreview from "@/components/MkChannelPreview.vue";
|
||||||
import MkChannelList from "@/components/MkChannelList.vue";
|
import MkChannelList from "@/components/MkChannelList.vue";
|
||||||
import MkPagination from "@/components/MkPagination.vue";
|
import MkPagination from "@/components/MkPagination.vue";
|
||||||
import MkInput from "@/components/MkInput.vue";
|
import MkInput from "@/components/form/input.vue";
|
||||||
import MkRadios from "@/components/MkRadios.vue";
|
import MkRadios from "@/components/form/radios.vue";
|
||||||
import MkButton from "@/components/MkButton.vue";
|
import MkButton from "@/components/MkButton.vue";
|
||||||
import MkFoldableSection from "@/components/MkFoldableSection.vue";
|
import MkFolder from "@/components/MkFolder.vue";
|
||||||
import { useRouter } from "@/router";
|
import { useRouter } from "@/router";
|
||||||
import { definePageMetadata } from "@/scripts/page-metadata";
|
import { definePageMetadata } from "@/scripts/page-metadata";
|
||||||
import { deviceKind } from "@/scripts/device-kind";
|
import { deviceKind } from "@/scripts/device-kind";
|
||||||
|
@ -147,7 +149,6 @@ const props = defineProps<{
|
||||||
type?: string;
|
type?: string;
|
||||||
}>();
|
}>();
|
||||||
let key = $ref("");
|
let key = $ref("");
|
||||||
let tab = $ref("search");
|
|
||||||
let searchQuery = $ref("");
|
let searchQuery = $ref("");
|
||||||
let searchType = $ref("nameAndDescription");
|
let searchType = $ref("nameAndDescription");
|
||||||
let channelPagination = $ref();
|
let channelPagination = $ref();
|
||||||
|
@ -201,7 +202,7 @@ const headerTabs = $computed(() => [
|
||||||
{
|
{
|
||||||
key: "search",
|
key: "search",
|
||||||
title: i18n.ts.search,
|
title: i18n.ts.search,
|
||||||
icon: "ph-search ph-bold ph-lg",
|
icon: "ph-magnifying-glass ph-bold ph-lg",
|
||||||
},
|
},
|
||||||
{
|
{
|
||||||
key: "featured",
|
key: "featured",
|
||||||
|
|
Loading…
Reference in New Issue