digital ocean spaces/aws S3 integratoin
This commit is contained in:
@@ -1,7 +1,7 @@
|
||||
import { prisma } from "@/lib/api/db";
|
||||
import getPermission from "@/lib/api/getPermission";
|
||||
import { Collection, UsersAndCollections } from "@prisma/client";
|
||||
import fs from "fs";
|
||||
import removeFolder from "@/lib/api/storage/removeFolder";
|
||||
|
||||
export default async function deleteCollection(
|
||||
collection: { id: number },
|
||||
@@ -56,13 +56,7 @@ export default async function deleteCollection(
|
||||
},
|
||||
});
|
||||
|
||||
try {
|
||||
fs.rmdirSync(`data/archives/${collectionId}`, { recursive: true });
|
||||
} catch (error) {
|
||||
console.log(
|
||||
"Collection's archive directory wasn't deleted most likely because it didn't exist..."
|
||||
);
|
||||
}
|
||||
removeFolder({ filePath: `archives/${collectionId}` });
|
||||
|
||||
return await prisma.collection.delete({
|
||||
where: {
|
||||
|
||||
@@ -1,6 +1,6 @@
|
||||
import { prisma } from "@/lib/api/db";
|
||||
import { CollectionIncludingMembersAndLinkCount } from "@/types/global";
|
||||
import { existsSync, mkdirSync } from "fs";
|
||||
import createFolder from "@/lib/api/storage/createFolder";
|
||||
|
||||
export default async function postCollection(
|
||||
collection: CollectionIncludingMembersAndLinkCount,
|
||||
@@ -66,9 +66,7 @@ export default async function postCollection(
|
||||
},
|
||||
});
|
||||
|
||||
const collectionPath = `data/archives/${newCollection.id}`;
|
||||
if (!existsSync(collectionPath))
|
||||
mkdirSync(collectionPath, { recursive: true });
|
||||
createFolder({ filePath: `archives/${newCollection.id}` });
|
||||
|
||||
return { response: newCollection, status: 200 };
|
||||
}
|
||||
|
||||
@@ -1,8 +1,8 @@
|
||||
import { prisma } from "@/lib/api/db";
|
||||
import { LinkIncludingShortenedCollectionAndTags } from "@/types/global";
|
||||
import fs from "fs";
|
||||
import { Collection, Link, UsersAndCollections } from "@prisma/client";
|
||||
import getPermission from "@/lib/api/getPermission";
|
||||
import removeFile from "@/lib/api/storage/removeFile";
|
||||
|
||||
export default async function deleteLink(
|
||||
link: LinkIncludingShortenedCollectionAndTags,
|
||||
@@ -33,13 +33,8 @@ export default async function deleteLink(
|
||||
},
|
||||
});
|
||||
|
||||
fs.unlink(`data/archives/${link.collectionId}/${link.id}.pdf`, (err) => {
|
||||
if (err) console.log(err);
|
||||
});
|
||||
|
||||
fs.unlink(`data/archives/${link.collectionId}/${link.id}.png`, (err) => {
|
||||
if (err) console.log(err);
|
||||
});
|
||||
removeFile({ filePath: `archives/${link.collectionId}/${link.id}.pdf` });
|
||||
removeFile({ filePath: `archives/${link.collectionId}/${link.id}.png` });
|
||||
|
||||
return { response: deleteLink, status: 200 };
|
||||
}
|
||||
|
||||
@@ -1,10 +1,9 @@
|
||||
import { prisma } from "@/lib/api/db";
|
||||
import { LinkIncludingShortenedCollectionAndTags } from "@/types/global";
|
||||
import getTitle from "../../getTitle";
|
||||
import archive from "../../archive";
|
||||
import getTitle from "@/lib/api/getTitle";
|
||||
import archive from "@/lib/api/archive";
|
||||
import { Collection, Link, UsersAndCollections } from "@prisma/client";
|
||||
import getPermission from "@/lib/api/getPermission";
|
||||
import { existsSync, mkdirSync } from "fs";
|
||||
|
||||
export default async function postLink(
|
||||
link: LinkIncludingShortenedCollectionAndTags,
|
||||
@@ -84,10 +83,6 @@ export default async function postLink(
|
||||
include: { tags: true, collection: true },
|
||||
});
|
||||
|
||||
const collectionPath = `data/archives/${newLink.collectionId}`;
|
||||
if (!existsSync(collectionPath))
|
||||
mkdirSync(collectionPath, { recursive: true });
|
||||
|
||||
archive(newLink.url, newLink.collectionId, newLink.id);
|
||||
|
||||
return { response: newLink, status: 200 };
|
||||
|
||||
@@ -1,8 +1,8 @@
|
||||
import { prisma } from "@/lib/api/db";
|
||||
import { AccountSettings } from "@/types/global";
|
||||
import fs from "fs";
|
||||
import path from "path";
|
||||
import bcrypt from "bcrypt";
|
||||
import removeFile from "@/lib/api/storage/removeFile";
|
||||
import createFile from "@/lib/api/storage/createFile";
|
||||
|
||||
export default async function updateUser(
|
||||
user: AccountSettings,
|
||||
@@ -43,15 +43,12 @@ export default async function updateUser(
|
||||
if (profilePic.startsWith("data:image/jpeg;base64")) {
|
||||
if (user.profilePic.length < 1572864) {
|
||||
try {
|
||||
const filePath = path.join(
|
||||
process.cwd(),
|
||||
`data/uploads/avatar/${userId}.jpg`
|
||||
);
|
||||
|
||||
const base64Data = profilePic.replace(/^data:image\/jpeg;base64,/, "");
|
||||
|
||||
fs.writeFile(filePath, base64Data, "base64", function (err) {
|
||||
console.log(err);
|
||||
await createFile({
|
||||
filePath: `uploads/avatar/${userId}.jpg`,
|
||||
data: base64Data,
|
||||
isBase64: true,
|
||||
});
|
||||
} catch (err) {
|
||||
console.log("Error saving image:", err);
|
||||
@@ -64,9 +61,7 @@ export default async function updateUser(
|
||||
};
|
||||
}
|
||||
} else if (profilePic == "") {
|
||||
fs.unlink(`data/uploads/avatar/${userId}.jpg`, (err) => {
|
||||
if (err) console.log(err);
|
||||
});
|
||||
removeFile({ filePath: `uploads/avatar/${userId}.jpg` });
|
||||
}
|
||||
|
||||
// Other settings
|
||||
|
||||
Reference in New Issue
Block a user