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

View file

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

View file

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