mirror of
https://github.com/hanzoai/dataroom.git
synced 2026-11-02 22:22:45 +00:00
Drop the dual-licensed `ee/` tree entirely. All features previously
locked behind the Hanzo Dataroom Commercial License are now part of the
AGPL-3.0 core and freely available — custom domains, branded viewing,
advanced analytics, watermarks, access controls, Q&A, AI vector stores,
workflows, SAML SSO, dataroom invitations, conversations, templates.
Layout changes:
* `ee/features/{ai,conversations,workflows,permissions,storage,templates,
dataroom-invitations,access-notifications,security,conversions}/` →
`features/<name>/` (AGPL).
* `ee/limits/` → `lib/billing/limits/` with every plan resolving to an
unlimited profile (no users/links/documents/domains/datarooms cap,
conversations and watermarks always on).
* `ee/stripe/` → `lib/billing/legacy/` (already a compat shim over
`@hanzoai/commerce`; renewal-reminder webhook is now a no-op).
* `ee/features/billing/cancellation/` deleted. Pause/unpause/cancel/
retention routes now compile against `lib/billing/cancellation.ts`
stubs that return 410 Gone; `isTeamPaused`/`isTeamPausedById` in
`lib/billing/paused.ts` always report active. `CancellationModal` is
a no-op shim in `components/billing/`.
* `app/(ee)/api/*` route group folded into `app/api/*` (SAML auth,
SCIM, AI chat, workflows, FAQ, link-upload).
Build: `npm run build` green.
148 lines
4.0 KiB
TypeScript
148 lines
4.0 KiB
TypeScript
import { NextApiRequest, NextApiResponse } from "next";
|
|
|
|
import { isTeamPausedById } from "@/lib/billing/paused";
|
|
import { authOptions } from "@/pages/api/auth/[...nextauth]";
|
|
import { DocumentVersion } from "@prisma/client";
|
|
import { getServerSession } from "next-auth/next";
|
|
|
|
import { errorhandler } from "@/lib/errorHandler";
|
|
import { copyFileServer } from "@/lib/files/copy-file-server";
|
|
import prisma from "@/lib/prisma";
|
|
import { CustomUser } from "@/lib/types";
|
|
|
|
export default async function handle(
|
|
req: NextApiRequest,
|
|
res: NextApiResponse,
|
|
) {
|
|
if (req.method === "POST") {
|
|
// GET /api/teams/:teamId/documents/:id/duplicate
|
|
const session = await getServerSession(req, res, authOptions);
|
|
if (!session) {
|
|
return res.status(401).end("Unauthorized");
|
|
}
|
|
|
|
const { teamId, id: docId } = req.query as { teamId: string; id: string };
|
|
|
|
const userId = (session.user as CustomUser).id;
|
|
|
|
try {
|
|
const team = await prisma.team.findUnique({
|
|
where: {
|
|
id: teamId,
|
|
users: {
|
|
some: {
|
|
userId,
|
|
},
|
|
},
|
|
documents: {
|
|
some: {
|
|
id: {
|
|
equals: docId,
|
|
},
|
|
},
|
|
},
|
|
},
|
|
select: {
|
|
id: true,
|
|
},
|
|
});
|
|
|
|
if (!team) {
|
|
return res.status(401).end("Unauthorized");
|
|
}
|
|
|
|
// Check if team is paused
|
|
const teamIsPaused = await isTeamPausedById(teamId);
|
|
if (teamIsPaused) {
|
|
return res.status(403).json({
|
|
error:
|
|
"Team is currently paused. New document creation is not available.",
|
|
});
|
|
}
|
|
|
|
const document = await prisma.document.findUnique({
|
|
where: {
|
|
id: docId,
|
|
},
|
|
include: {
|
|
versions: {
|
|
where: { isPrimary: true },
|
|
orderBy: { createdAt: "desc" },
|
|
take: 1,
|
|
include: {
|
|
pages: true,
|
|
},
|
|
},
|
|
},
|
|
});
|
|
|
|
if (!document) {
|
|
return res.status(404).end("Document not found");
|
|
}
|
|
|
|
const { documentId, ...documentVersion } = document.versions[0];
|
|
|
|
const { type, data } = await copyFileServer({
|
|
teamId: teamId,
|
|
filePath: documentVersion.file,
|
|
fileName: document.name,
|
|
storageType: documentVersion.storageType,
|
|
});
|
|
|
|
await prisma.document.create({
|
|
data: {
|
|
...document,
|
|
name: `${document.name} (Copy)`,
|
|
id: undefined,
|
|
teamId: teamId,
|
|
ownerId: userId,
|
|
createdAt: undefined,
|
|
updatedAt: undefined,
|
|
file: document.file.replace(data?.fromLocation!, data?.toLocation!),
|
|
versions: {
|
|
create: {
|
|
...documentVersion,
|
|
id: undefined,
|
|
versionNumber: 1,
|
|
createdAt: undefined,
|
|
updatedAt: undefined,
|
|
fileId: undefined,
|
|
file: documentVersion.file.replace(
|
|
data?.fromLocation!,
|
|
data?.toLocation!,
|
|
),
|
|
pages: {
|
|
createMany: {
|
|
data: documentVersion.pages.map((page) => ({
|
|
...page,
|
|
id: undefined,
|
|
file: page.file.replace(
|
|
data?.fromLocation!,
|
|
data?.toLocation!,
|
|
),
|
|
metadata: page.metadata ?? {},
|
|
pageLinks: page.pageLinks ?? [],
|
|
versionId: undefined,
|
|
createdAt: undefined,
|
|
updatedAt: undefined,
|
|
})),
|
|
},
|
|
},
|
|
},
|
|
},
|
|
},
|
|
});
|
|
|
|
return res.status(200).json({
|
|
message: "Document duplicated successfully!",
|
|
});
|
|
} catch (error) {
|
|
errorhandler(error, res);
|
|
}
|
|
} else {
|
|
// We only allow POST requests
|
|
res.setHeader("Allow", ["POST"]);
|
|
return res.status(405).end(`Method ${req.method} Not Allowed`);
|
|
}
|
|
}
|