updated verify max link logic
This commit is contained in:
@@ -44,11 +44,6 @@ export default async function postCollection(
|
||||
|
||||
const newCollection = await prisma.collection.create({
|
||||
data: {
|
||||
owner: {
|
||||
connect: {
|
||||
id: userId,
|
||||
},
|
||||
},
|
||||
name: collection.name.trim(),
|
||||
description: collection.description,
|
||||
color: collection.color,
|
||||
@@ -61,6 +56,16 @@ export default async function postCollection(
|
||||
},
|
||||
}
|
||||
: undefined,
|
||||
owner: {
|
||||
connect: {
|
||||
id: userId,
|
||||
},
|
||||
},
|
||||
createdBy: {
|
||||
connect: {
|
||||
id: userId,
|
||||
},
|
||||
},
|
||||
},
|
||||
include: {
|
||||
_count: {
|
||||
|
||||
@@ -6,8 +6,7 @@ import {
|
||||
PostLinkSchema,
|
||||
PostLinkSchemaType,
|
||||
} from "@/lib/shared/schemaValidation";
|
||||
|
||||
const MAX_LINKS_PER_USER = Number(process.env.MAX_LINKS_PER_USER) || 30000;
|
||||
import { hasPassedLimit } from "../../verifyCapacity";
|
||||
|
||||
export default async function postLink(
|
||||
body: PostLinkSchemaType,
|
||||
@@ -59,19 +58,14 @@ export default async function postLink(
|
||||
};
|
||||
}
|
||||
|
||||
const numberOfLinksTheUserHas = await prisma.link.count({
|
||||
where: {
|
||||
collection: {
|
||||
ownerId: linkCollection.ownerId,
|
||||
},
|
||||
},
|
||||
});
|
||||
const hasTooManyLinks = await hasPassedLimit(userId, 1);
|
||||
|
||||
if (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,
|
||||
};
|
||||
}
|
||||
|
||||
const { title, headers } = await fetchTitleAndHeaders(link.url || "");
|
||||
|
||||
@@ -98,6 +92,11 @@ export default async function postLink(
|
||||
name,
|
||||
description: link.description,
|
||||
type: linkType,
|
||||
createdBy: {
|
||||
connect: {
|
||||
id: userId,
|
||||
},
|
||||
},
|
||||
collection: {
|
||||
connect: {
|
||||
id: linkCollection.id,
|
||||
|
||||
@@ -2,8 +2,7 @@ import { prisma } from "@/lib/api/db";
|
||||
import createFolder from "@/lib/api/storage/createFolder";
|
||||
import { JSDOM } from "jsdom";
|
||||
import { parse, Node, Element, TextNode } from "himalaya";
|
||||
|
||||
const MAX_LINKS_PER_USER = Number(process.env.MAX_LINKS_PER_USER) || 30000;
|
||||
import { hasPassedLimit } from "../../verifyCapacity";
|
||||
|
||||
export default async function importFromHTMLFile(
|
||||
userId: number,
|
||||
@@ -20,19 +19,14 @@ export default async function importFromHTMLFile(
|
||||
const bookmarks = document.querySelectorAll("A");
|
||||
const totalImports = bookmarks.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,
|
||||
};
|
||||
}
|
||||
|
||||
const jsonData = parse(document.documentElement.outerHTML);
|
||||
|
||||
@@ -183,6 +177,11 @@ const createCollection = async (
|
||||
id: userId,
|
||||
},
|
||||
},
|
||||
createdBy: {
|
||||
connect: {
|
||||
id: userId,
|
||||
},
|
||||
},
|
||||
},
|
||||
});
|
||||
|
||||
@@ -222,28 +221,27 @@ const createLink = async (
|
||||
url,
|
||||
description,
|
||||
collectionId,
|
||||
createdById: userId,
|
||||
tags:
|
||||
tags && tags[0]
|
||||
? {
|
||||
connectOrCreate: tags.map((tag: string) => {
|
||||
return (
|
||||
{
|
||||
where: {
|
||||
name_ownerId: {
|
||||
name: tag.trim(),
|
||||
ownerId: userId,
|
||||
},
|
||||
},
|
||||
create: {
|
||||
return {
|
||||
where: {
|
||||
name_ownerId: {
|
||||
name: tag.trim(),
|
||||
owner: {
|
||||
connect: {
|
||||
id: userId,
|
||||
},
|
||||
ownerId: userId,
|
||||
},
|
||||
},
|
||||
create: {
|
||||
name: tag.trim(),
|
||||
owner: {
|
||||
connect: {
|
||||
id: userId,
|
||||
},
|
||||
},
|
||||
} || undefined
|
||||
);
|
||||
},
|
||||
};
|
||||
}),
|
||||
}
|
||||
: undefined,
|
||||
|
||||
@@ -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) => ({
|
||||
|
||||
@@ -1,7 +1,6 @@
|
||||
import { prisma } from "@/lib/api/db";
|
||||
import createFolder from "@/lib/api/storage/createFolder";
|
||||
|
||||
const MAX_LINKS_PER_USER = Number(process.env.MAX_LINKS_PER_USER) || 30000;
|
||||
import { hasPassedLimit } from "../../verifyCapacity";
|
||||
|
||||
type WallabagBackup = {
|
||||
is_archived: number;
|
||||
@@ -36,19 +35,14 @@ export default async function importFromWallabag(
|
||||
|
||||
let totalImports = backup.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(
|
||||
@@ -61,6 +55,11 @@ export default async function importFromWallabag(
|
||||
},
|
||||
},
|
||||
name: "Imports",
|
||||
createdBy: {
|
||||
connect: {
|
||||
id: userId,
|
||||
},
|
||||
},
|
||||
},
|
||||
});
|
||||
|
||||
@@ -89,6 +88,11 @@ export default async function importFromWallabag(
|
||||
id: newCollection.id,
|
||||
},
|
||||
},
|
||||
createdBy: {
|
||||
connect: {
|
||||
id: userId,
|
||||
},
|
||||
},
|
||||
tags:
|
||||
link.tags && link.tags[0]
|
||||
? {
|
||||
|
||||
Reference in New Issue
Block a user