proper asset creation/deletion, also raw file view in admin as well
This commit is contained in:
48
apps/main/src/lib/domains/files/files.remote.ts
Normal file
48
apps/main/src/lib/domains/files/files.remote.ts
Normal file
@@ -0,0 +1,48 @@
|
||||
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 };
|
||||
});
|
||||
Reference in New Issue
Block a user