moving stuff and refactoring

This commit is contained in:
Andreas 2024-06-28 09:49:39 +02:00
parent 7b4bdb7b97
commit de148eaf19
10 changed files with 26 additions and 20 deletions

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 }

View File

@ -0,0 +1,13 @@
'use server';
import { APIError } from "@/util/api/error";
import { Bucket, Post } from "@/models";
import { randomUUID } from "crypto";
export 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;
}

View File

@ -3,8 +3,8 @@
import { revalidatePath, revalidateTag } from 'next/cache'
import { Bucket, Post, PostBucket, Project, User, dbSync } from "@/models";
import { Attributes, where } from "@sequelize/core";
import { getCookieAuth, userIsAdmin } from '../actions';
import { ActionResult } from '../ActionResult';
import { getCookieAuth, userIsAdmin } from '../../actions';
import { ActionResult } from '../../ActionResult';
import { PostAttributesWithBuckets } from '@/models';
export async function deletePost(postID: number): Promise<ActionResult<boolean>> {

View File

@ -1,8 +1,8 @@
'use server';
import { Project } from "@/models";
import { ActionResult } from "../ActionResult";
import { ActionResult } from "../../ActionResult";
import { Attributes } from "@sequelize/core";
import { userIsAdmin } from "../actions";
import { userIsAdmin } from "../../actions";
export async function getProjects(): Promise<ActionResult<Attributes<Project>[]>> {
if (! await userIsAdmin()) return { error: 'Unauthorized, not fetching Projects' }

View File

@ -1,4 +1,4 @@
import { GetPostsAttributes } from "@/app/lib/actions/entityManagement/postActions";
import { GetPostsAttributes } from "@/app/lib/actions/entityManagement/post/postActions";
import { Post, Project, Bucket, PostBucket, Attachment } from "@/models";
import { Attributes } from "@sequelize/core";
import { UUID } from "crypto";

View File

@ -11,7 +11,7 @@ import {
getPostsWithBucketsAndProject,
GetPostsAttributes,
PostServerActions,
} from "@/app/lib/actions/entityManagement/postActions";
} from "@/app/lib/actions/entityManagement/post/postActions";
import { PostViewProps } from "@/views/admin/ClientPostView";
import { aifa } from "@/util/Utils";
import { StateHook } from "@/util/state/stateUtils";

View File

@ -6,7 +6,7 @@ import PostTable, {
import {
GetPostsAttributes,
PostServerActions,
} from "@/app/lib/actions/entityManagement/postActions";
} from "@/app/lib/actions/entityManagement/post/postActions";
import { EditorState } from "@/components/client/admin/PostEditor";
import { Project } from "@/models";
import { Dispatch, ReactNode, SetStateAction, useState } from "react";

View File

@ -9,8 +9,8 @@ import {
updatePost,
GetPostsAttributes,
PostServerActions,
} from "@/app/lib/actions/entityManagement/postActions";
import { getProjects } from "@/app/lib/actions/entityManagement/projectActions";
} from "@/app/lib/actions/entityManagement/post/postActions";
import { getProjects } from "@/app/lib/actions/entityManagement/post/projectActions";
import { Bucket, Project, Post, dbSync, Attachment } from "@/models";
import { handleActionResult } from "../../app/lib/actions/clientActionHandler";
import { ClientPostView } from "./ClientPostView";

View File

@ -9,8 +9,8 @@ import {
deletePost,
getPostsWithBucketsAndProject,
updatePost,
} from "@/app/lib/actions/entityManagement/postActions";
import { getProjects } from "@/app/lib/actions/entityManagement/projectActions";
} from "@/app/lib/actions/entityManagement/post/postActions";
import { getProjects } from "@/app/lib/actions/entityManagement/post/projectActions";
import { Bucket, Project, Post, dbSync, Attachment } from "@/models";
import { tryCreateAttachment } from "@/app/api/attachment/route";
import { Attributes } from "@sequelize/core";