diff --git a/public/genericHeaderImage.png b/public/genericHeaderImage.png new file mode 100644 index 0000000..7b66cdd Binary files /dev/null and b/public/genericHeaderImage.png differ diff --git a/src/app/api/attachment/route.ts b/src/app/api/attachment/route.ts index 23bd198..1dc217e 100644 --- a/src/app/api/attachment/route.ts +++ b/src/app/api/attachment/route.ts @@ -8,10 +8,6 @@ import { UUID, randomUUID } from "crypto"; import { mkdir, mkdirSync, writeFile } from "fs"; import { where } from "@sequelize/core"; - - - - async function writeFilesToBucket(uuid: UUID, files:any[]) { const fileArray:{name:string, content:Promise>|ReadableStreamReadResult}[] = await Promise.all( files.map((file:File) => { return {'name':( ()=>file.name)(), 'content':file.stream().getReader().read()}; @@ -26,29 +22,25 @@ async function writeFilesToBucket(uuid: UUID, files:any[]) { mkdirSync(`./bucket/${uuid}/`) for(let file in finalFileArray){ - writeFile(`./bucket/${uuid}/${finalFileArray[file].name}`,Buffer.from(finalFileArray[file].content.value as Uint8Array),(e)=>{console.log(e)}) const attachment = await Attachment.create({bucket_id:uuid, filename:finalFileArray[file].name}, {include: Attachment.associations.bucket}); console.log(attachment); } } -async function addToPost(postid:number):Promise +async function addToPost(postid:number):Promise { 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()}); - // const bucketPost = await Post.associations.postBuckets.create({bucketId: bucket.id, postId: postid}) - - // console.log(bucketPost); - return bucket.id; + return bucket; } -async function addToBucket(bucketid:number):Promise { - const bucket = await Bucket.findOne({where: {id: bucketid}}); +async function addToBucket(bucketid:number):Promise { + const bucket = await Bucket.findOne({where: {id: bucketid}, include: {association: Bucket.associations.posts}}); if (!bucket) throw new APIError({ status: 500, responseText: "invalid bucketid" }); - return bucket.id; + return bucket; } @@ -98,13 +90,15 @@ async function tryCreateAttachment(request: Request) { const data = JSON.parse(requestData); - let uuid:UUID = (data.postid && !data.bucketid)? await addToPost(data.postid) : await addToBucket(data.bucketid) - writeFilesToBucket(uuid, files); + let bucket:Bucket = (data.postid && !data.bucketid)? await addToPost(data.postid) : await addToBucket(data.bucketid) + writeFilesToBucket(bucket.id, files); + + + const bucket2 = await Bucket.findOne({where: {id: bucket.id}, include: [Bucket.associations.posts, Bucket.associations.attachments]}) return new Response(JSON.stringify({ - 'files': 'ya yeet', - 'uuid': uuid, + bucket: bucket2 }), { status: 200 }); diff --git a/src/components/shared/news/article.module.css b/src/components/shared/news/article.module.css index b32d256..34c3c1f 100644 --- a/src/components/shared/news/article.module.css +++ b/src/components/shared/news/article.module.css @@ -12,8 +12,9 @@ min-width:fit-content; min-height:256px; /* flex-grow: 10; */ - background-image: url(/placeholder-square.png); - background-size: contain; + background-image: url(/genericHeaderImage.png); + opacity: 0.8; + background-size: cover; background-repeat: no-repeat; background-position: center; background-color: #00000044; diff --git a/src/model/Post.ts b/src/model/Post.ts index 9f38039..5de8481 100644 --- a/src/model/Post.ts +++ b/src/model/Post.ts @@ -51,7 +51,7 @@ export class Post extends Model, InferCreationAttributes

Bucket,{through: {model:'PostBucket'}, throughAssociations: { - fromSource: 'postPostBuckets', + fromSource: 'postBucketBuckets', toSource: 'post', fromTarget: 'postBucketPosts', toTarget: 'PostBucket',