moving stuff and refactoring
This commit is contained in:
parent
7b4bdb7b97
commit
de148eaf19
@ -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 }
|
||||
|
||||
@ -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;
|
||||
}
|
||||
@ -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>> {
|
||||
@ -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' }
|
||||
@ -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";
|
||||
|
||||
@ -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";
|
||||
|
||||
@ -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";
|
||||
|
||||
@ -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";
|
||||
|
||||
@ -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";
|
||||
|
||||
Loading…
x
Reference in New Issue
Block a user