49 lines
1.4 KiB
TypeScript
49 lines
1.4 KiB
TypeScript
import { getFileController } from "@pkg/logic/domains/files/controller";
|
|
import {
|
|
getFlowExecCtxForRemoteFuncs,
|
|
unauthorized,
|
|
} from "$lib/core/server.utils";
|
|
import { getRequestEvent, query } from "$app/server";
|
|
import * as v from "valibot";
|
|
|
|
const fc = getFileController();
|
|
|
|
const filesPaginationSchema = v.object({
|
|
page: v.pipe(v.number(), v.integer()),
|
|
pageSize: v.pipe(v.number(), v.integer()),
|
|
sortBy: v.optional(v.string()),
|
|
sortOrder: v.optional(v.picklist(["asc", "desc"])),
|
|
});
|
|
|
|
const getFilesInputSchema = v.object({
|
|
search: v.optional(v.string()),
|
|
mimeType: v.optional(v.string()),
|
|
status: v.optional(v.string()),
|
|
visibility: v.optional(v.string()),
|
|
pagination: filesPaginationSchema,
|
|
});
|
|
|
|
export const getFilesSQ = query(getFilesInputSchema, async (input) => {
|
|
const event = getRequestEvent();
|
|
const fctx = await getFlowExecCtxForRemoteFuncs(event.locals);
|
|
if (!fctx.userId) {
|
|
return unauthorized(fctx);
|
|
}
|
|
|
|
const res = await fc.getFiles(
|
|
fctx,
|
|
{
|
|
userId: fctx.userId,
|
|
search: input.search,
|
|
mimeType: input.mimeType,
|
|
status: input.status,
|
|
visibility: input.visibility,
|
|
},
|
|
input.pagination,
|
|
);
|
|
|
|
return res.isOk()
|
|
? { data: res.value, error: null }
|
|
: { data: null, error: res.error };
|
|
});
|