updated verify max link logic
This commit is contained in:
@@ -1,8 +1,7 @@
|
||||
import { prisma } from "@/lib/api/db";
|
||||
import { Backup } from "@/types/global";
|
||||
import createFolder from "@/lib/api/storage/createFolder";
|
||||
|
||||
const MAX_LINKS_PER_USER = Number(process.env.MAX_LINKS_PER_USER) || 30000;
|
||||
import { hasPassedLimit } from "../../verifyCapacity";
|
||||
|
||||
export default async function importFromLinkwarden(
|
||||
userId: number,
|
||||
@@ -16,19 +15,14 @@ export default async function importFromLinkwarden(
|
||||
totalImports += collection.links.length;
|
||||
});
|
||||
|
||||
const numberOfLinksTheUserHas = await prisma.link.count({
|
||||
where: {
|
||||
collection: {
|
||||
ownerId: userId,
|
||||
},
|
||||
},
|
||||
});
|
||||
const hasTooManyLinks = await hasPassedLimit(userId, totalImports);
|
||||
|
||||
if (totalImports + numberOfLinksTheUserHas > MAX_LINKS_PER_USER)
|
||||
if (hasTooManyLinks) {
|
||||
return {
|
||||
response: `Each collection owner can only have a maximum of ${MAX_LINKS_PER_USER} Links.`,
|
||||
response: `Your subscription have reached the maximum number of links allowed.`,
|
||||
status: 400,
|
||||
};
|
||||
}
|
||||
|
||||
await prisma
|
||||
.$transaction(
|
||||
@@ -47,6 +41,11 @@ export default async function importFromLinkwarden(
|
||||
name: e.name?.trim().slice(0, 254),
|
||||
description: e.description?.trim().slice(0, 254),
|
||||
color: e.color?.trim().slice(0, 50),
|
||||
createdBy: {
|
||||
connect: {
|
||||
id: userId,
|
||||
},
|
||||
},
|
||||
},
|
||||
});
|
||||
|
||||
@@ -72,6 +71,11 @@ export default async function importFromLinkwarden(
|
||||
id: newCollection.id,
|
||||
},
|
||||
},
|
||||
createdBy: {
|
||||
connect: {
|
||||
id: userId,
|
||||
},
|
||||
},
|
||||
// Import Tags
|
||||
tags: {
|
||||
connectOrCreate: link.tags.map((tag) => ({
|
||||
|
||||
Reference in New Issue
Block a user