Add stuff talked about on MR

This commit is contained in:
KevinWh0 2024-07-16 22:06:38 +02:00
parent b5a69c3aea
commit f97417cfca
3 changed files with 9 additions and 9 deletions

View File

@ -9,6 +9,7 @@ import type { DriveFilesRepository } from '@/models/_.js';
import { QueryService } from '@/core/QueryService.js';
import { DriveFileEntityService } from '@/core/entities/DriveFileEntityService.js';
import { DI } from '@/di-symbols.js';
import { sqlLikeEscape } from '@/misc/sql-like-escape.js';
export const meta = {
tags: ['drive'],
@ -37,7 +38,7 @@ export const paramDef = {
folderId: { type: 'string', format: 'misskey:id', nullable: true, default: null },
type: { type: 'string', nullable: true, pattern: /^[a-zA-Z\/\-*]+$/.toString().slice(1, -1) },
sort: { type: 'string', nullable: true, enum: ['+createdAt', '-createdAt', '+name', '-name', '+size', '-size', null] },
searchQuery: {type : 'string', default: '' }
searchQuery: { type: 'string', default: '' }
},
required: [],
} as const;
@ -62,7 +63,7 @@ export default class extends Endpoint<typeof meta, typeof paramDef> { // eslint-
}
if (ps.searchQuery.length > 0) {
query.andWhere('file.name ILIKE :searchQuery OR file.comment ILIKE :searchQuery', { searchQuery: `%${ps.searchQuery}%` });
query.andWhere('file.name ILIKE :searchQuery OR file.comment ILIKE :searchQuery', { searchQuery: `%${sqlLikeEscape(ps.searchQuery)}%` });
}
if (ps.type) {

View File

@ -9,6 +9,7 @@ import type { DriveFoldersRepository } from '@/models/_.js';
import { QueryService } from '@/core/QueryService.js';
import { DriveFolderEntityService } from '@/core/entities/DriveFolderEntityService.js';
import { DI } from '@/di-symbols.js';
import { sqlLikeEscape } from '@/misc/sql-like-escape.js';
export const meta = {
tags: ['drive'],
@ -35,7 +36,7 @@ export const paramDef = {
sinceId: { type: 'string', format: 'misskey:id' },
untilId: { type: 'string', format: 'misskey:id' },
folderId: { type: 'string', format: 'misskey:id', nullable: true, default: null },
searchQuery: {type : 'string', default: '' }
searchQuery: { type: 'string', default: '' }
},
required: [],
} as const;
@ -60,7 +61,7 @@ export default class extends Endpoint<typeof meta, typeof paramDef> { // eslint-
}
if (ps.searchQuery.length > 0) {
query.andWhere('folder.name ILIKE :searchQuery', { searchQuery: `%${ps.searchQuery}%` });
query.andWhere('folder.name ILIKE :searchQuery', { searchQuery: `%${sqlLikeEscape(ps.searchQuery)}%` });
}
const folders = await query.limit(ps.limit).getMany();

View File

@ -32,7 +32,7 @@ SPDX-License-Identifier: AGPL-3.0-only
</div>
<div :class="$style.navMenu">
<!-- "Search drive via alt text or file names" -->
<MkInput v-model="searchQuery" :large="true" :autofocus="true" type="search" :placeholder="i18n.ts.driveSearchbarPlaceholder" @enter="search">
<MkInput v-model="searchQuery" :large="true" :autofocus="true" type="search" :placeholder="i18n.ts.driveSearchbarPlaceholder" @enter="fetch">
<template #prefix><i class="ph-magnifying-glass ph-bold ph-lg"></i></template>
</MkInput>
@ -162,10 +162,6 @@ const isDragSource = ref(false);
const fetching = ref(true);
async function search() {
fetch();
}
const ilFilesObserver = new IntersectionObserver(
(entries) => entries.some((entry) => entry.isIntersecting) && !fetching.value && moreFiles.value && fetchMoreFiles(),
);
@ -594,6 +590,7 @@ function fetchMoreFolders() {
type: props.type,
untilId: folders.value.at(-1)?.id,
limit: max + 1,
searchQuery: searchQuery.value.toString().trim(),
}).then(folders => {
if (folders.length === max + 1) {
moreFolders.value = true;
@ -617,6 +614,7 @@ function fetchMoreFiles() {
type: props.type,
untilId: files.value.at(-1)?.id,
limit: max + 1,
searchQuery: searchQuery.value.toString().trim(),
}).then(files => {
if (files.length === max + 1) {
moreFiles.value = true;