moving stuff and refactoring

This commit is contained in:
2024-06-28 09:49:39 +02:00
parent 7b4bdb7b97
commit de148eaf19
10 changed files with 26 additions and 20 deletions
+2 -9
View File
@@ -4,9 +4,10 @@ import { APIError, attemptAPIAction } from "@/util/api/error";
import { sequelize, Bucket, Auth, Post, PostTag, Tag, User, dbSync } from "@/models";
import { cookies } from "next/headers";
import { Attachment } from "@/models";
import { UUID, randomUUID } from "crypto";
import { UUID } from "crypto";
import { mkdir, mkdirSync, writeFile } from "fs";
import { where } from "@sequelize/core";
import { addToNewBucketForPost } from "../../lib/actions/entityManagement/attachment/attachmentActions";
async function writeFilesToFS(uuid: UUID, files: any[]): Promise<{ success: boolean, filePaths: string[] }> {
@@ -49,14 +50,6 @@ async function writeFilesToFS(uuid: UUID, files: any[]): Promise<{ success: bool
}
}
async function addToNewBucketForPost(postid: number): Promise<Bucket> {
Post.sync();
const post = await Post.findOne({ where: { id: postid } });
if (!post) throw new APIError({ status: 500, responseText: "invalid postid" });
const bucket = await post.createBucket({ id: randomUUID() });
return bucket;
}
async function addToExistingBucket(bucketid: number): Promise<Bucket> {
const bucket = await Bucket.findOne({
where: { id: bucketid }, include: { association: Bucket.associations.posts }