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 { sequelize, Bucket, Auth, Post, PostTag, Tag, User, dbSync } from "@/models"; | ||||||
| import { cookies } from "next/headers"; | import { cookies } from "next/headers"; | ||||||
| import { Attachment } from "@/models"; | import { Attachment } from "@/models"; | ||||||
| import { UUID, randomUUID } from "crypto"; | import { UUID } from "crypto"; | ||||||
| import { mkdir, mkdirSync, writeFile } from "fs"; | import { mkdir, mkdirSync, writeFile } from "fs"; | ||||||
| import { where } from "@sequelize/core"; | 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[] }> { | 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> { | async function addToExistingBucket(bucketid: number): Promise<Bucket> { | ||||||
|     const bucket = await Bucket.findOne({ |     const bucket = await Bucket.findOne({ | ||||||
|         where: { id: bucketid }, include: { association: Bucket.associations.posts } |         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 { revalidatePath, revalidateTag } from 'next/cache' | ||||||
| import { Bucket, Post, PostBucket, Project, User, dbSync } from "@/models"; | import { Bucket, Post, PostBucket, Project, User, dbSync } from "@/models"; | ||||||
| import { Attributes, where } from "@sequelize/core"; | import { Attributes, where } from "@sequelize/core"; | ||||||
| import { getCookieAuth, userIsAdmin } from '../actions'; | import { getCookieAuth, userIsAdmin } from '../../actions'; | ||||||
| import { ActionResult } from '../ActionResult'; | import { ActionResult } from '../../ActionResult'; | ||||||
| import { PostAttributesWithBuckets } from '@/models'; | import { PostAttributesWithBuckets } from '@/models'; | ||||||
| 
 | 
 | ||||||
| export async function deletePost(postID: number): Promise<ActionResult<boolean>> { | export async function deletePost(postID: number): Promise<ActionResult<boolean>> { | ||||||
| @ -1,8 +1,8 @@ | |||||||
| 'use server'; | 'use server'; | ||||||
| import { Project } from "@/models"; | import { Project } from "@/models"; | ||||||
| import { ActionResult } from "../ActionResult"; | import { ActionResult } from "../../ActionResult"; | ||||||
| import { Attributes } from "@sequelize/core"; | import { Attributes } from "@sequelize/core"; | ||||||
| import { userIsAdmin } from "../actions"; | import { userIsAdmin } from "../../actions"; | ||||||
| 
 | 
 | ||||||
| export async function getProjects(): Promise<ActionResult<Attributes<Project>[]>> { | export async function getProjects(): Promise<ActionResult<Attributes<Project>[]>> { | ||||||
|   if (! await userIsAdmin()) return { error: 'Unauthorized, not fetching Projects' } |   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 { Post, Project, Bucket, PostBucket, Attachment } from "@/models"; | ||||||
| import { Attributes } from "@sequelize/core"; | import { Attributes } from "@sequelize/core"; | ||||||
| import { UUID } from "crypto"; | import { UUID } from "crypto"; | ||||||
|  | |||||||
| @ -11,7 +11,7 @@ import { | |||||||
| 	getPostsWithBucketsAndProject, | 	getPostsWithBucketsAndProject, | ||||||
| 	GetPostsAttributes, | 	GetPostsAttributes, | ||||||
| 	PostServerActions, | 	PostServerActions, | ||||||
| } from "@/app/lib/actions/entityManagement/postActions"; | } from "@/app/lib/actions/entityManagement/post/postActions"; | ||||||
| import { PostViewProps } from "@/views/admin/ClientPostView"; | import { PostViewProps } from "@/views/admin/ClientPostView"; | ||||||
| import { aifa } from "@/util/Utils"; | import { aifa } from "@/util/Utils"; | ||||||
| import { StateHook } from "@/util/state/stateUtils"; | import { StateHook } from "@/util/state/stateUtils"; | ||||||
|  | |||||||
| @ -6,7 +6,7 @@ import PostTable, { | |||||||
| import { | import { | ||||||
| 	GetPostsAttributes, | 	GetPostsAttributes, | ||||||
| 	PostServerActions, | 	PostServerActions, | ||||||
| } from "@/app/lib/actions/entityManagement/postActions"; | } from "@/app/lib/actions/entityManagement/post/postActions"; | ||||||
| import { EditorState } from "@/components/client/admin/PostEditor"; | import { EditorState } from "@/components/client/admin/PostEditor"; | ||||||
| import { Project } from "@/models"; | import { Project } from "@/models"; | ||||||
| import { Dispatch, ReactNode, SetStateAction, useState } from "react"; | import { Dispatch, ReactNode, SetStateAction, useState } from "react"; | ||||||
|  | |||||||
| @ -9,8 +9,8 @@ import { | |||||||
|   updatePost, |   updatePost, | ||||||
|   GetPostsAttributes, |   GetPostsAttributes, | ||||||
|   PostServerActions, |   PostServerActions, | ||||||
| } from "@/app/lib/actions/entityManagement/postActions"; | } from "@/app/lib/actions/entityManagement/post/postActions"; | ||||||
| import { getProjects } from "@/app/lib/actions/entityManagement/projectActions"; | import { getProjects } from "@/app/lib/actions/entityManagement/post/projectActions"; | ||||||
| import { Bucket, Project, Post, dbSync, Attachment } from "@/models"; | import { Bucket, Project, Post, dbSync, Attachment } from "@/models"; | ||||||
| import { handleActionResult } from "../../app/lib/actions/clientActionHandler"; | import { handleActionResult } from "../../app/lib/actions/clientActionHandler"; | ||||||
| import { ClientPostView } from "./ClientPostView"; | import { ClientPostView } from "./ClientPostView"; | ||||||
|  | |||||||
| @ -9,8 +9,8 @@ import { | |||||||
| 	deletePost, | 	deletePost, | ||||||
| 	getPostsWithBucketsAndProject, | 	getPostsWithBucketsAndProject, | ||||||
| 	updatePost, | 	updatePost, | ||||||
| } from "@/app/lib/actions/entityManagement/postActions"; | } from "@/app/lib/actions/entityManagement/post/postActions"; | ||||||
| import { getProjects } from "@/app/lib/actions/entityManagement/projectActions"; | import { getProjects } from "@/app/lib/actions/entityManagement/post/projectActions"; | ||||||
| import { Bucket, Project, Post, dbSync, Attachment } from "@/models"; | import { Bucket, Project, Post, dbSync, Attachment } from "@/models"; | ||||||
| import { tryCreateAttachment } from "@/app/api/attachment/route"; | import { tryCreateAttachment } from "@/app/api/attachment/route"; | ||||||
| import { Attributes } from "@sequelize/core"; | import { Attributes } from "@sequelize/core"; | ||||||
|  | |||||||
		Loading…
	
	
			
			x
			
			
		
	
		Reference in New Issue
	
	Block a user