mirror of
https://github.com/docmost/docmost.git
synced 2026-07-24 04:42:54 +10:00
refactor(base): drop dedicated /bases/files/upload endpoint, reuse /files/upload
Base file-cell uploads were hitting a parallel POST /bases/files/upload endpoint that re-implemented the multipart parse, the size limit handling, and the spaceId resolution that the standard page-attachment endpoint (POST /files/upload) already does. The two diverged on minor points (no audit log, no attachmentId support, slightly different permission check) without good reason — bases are pages (isBase=true), so the existing endpoint already handles them correctly. Server: delete uploadBaseFile and the now-unused BaseRepo injection. Client: route the file-cell uploader through the existing uploadFile helper in page-service. The base's pageId is a valid page id, so the server's pageRepo.findById succeeds and pageAccessService.validateCanEdit runs — which lines up with the Base edit ability at the space-role level (Manage Page and Manage Base track together for admins/writers, Read for readers).
This commit is contained in:
@@ -8,7 +8,7 @@ import {
|
||||
} from "@tabler/icons-react";
|
||||
import { IBaseProperty } from "@/features/base/types/base.types";
|
||||
import cellClasses from "@/features/base/styles/cells.module.css";
|
||||
import api from "@/lib/api-client";
|
||||
import { uploadFile } from "@/features/page/services/page-service";
|
||||
|
||||
export type FileValue = {
|
||||
id: string;
|
||||
@@ -68,21 +68,15 @@ export function CellFile({
|
||||
|
||||
const newFiles: FileValue[] = [...files];
|
||||
|
||||
// Reuse the page-attachment upload pipeline. A base IS a page
|
||||
// (isBase=true) — the server's /files/upload endpoint accepts the
|
||||
// base's pageId, runs the standard pageAccessService.validateCanEdit
|
||||
// check (which lines up with Base edit at the space-role level per
|
||||
// the casl rules), and stores the attachment via the same flow as
|
||||
// any other page attachment.
|
||||
for (const file of Array.from(fileList)) {
|
||||
try {
|
||||
const formData = new FormData();
|
||||
formData.append("file", file);
|
||||
formData.append("pageId", property.pageId);
|
||||
|
||||
const res = await api.post<FileValue>(
|
||||
"/bases/files/upload",
|
||||
formData,
|
||||
{
|
||||
headers: { "Content-Type": "multipart/form-data" },
|
||||
},
|
||||
);
|
||||
|
||||
const attachment = res as unknown as FileValue;
|
||||
const attachment = await uploadFile(file, property.pageId);
|
||||
newFiles.push({
|
||||
id: attachment.id,
|
||||
fileName: attachment.fileName,
|
||||
|
||||
Reference in New Issue
Block a user