bla
This commit is contained in:
parent
21e31d0ee4
commit
c3a8469371
BIN
public/genericHeaderImage.png
Normal file
BIN
public/genericHeaderImage.png
Normal file
Binary file not shown.
|
After Width: | Height: | Size: 1.5 MiB |
@ -8,10 +8,6 @@ import { UUID, randomUUID } from "crypto";
|
|||||||
import { mkdir, mkdirSync, writeFile } from "fs";
|
import { mkdir, mkdirSync, writeFile } from "fs";
|
||||||
import { where } from "@sequelize/core";
|
import { where } from "@sequelize/core";
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
async function writeFilesToBucket(uuid: UUID, files:any[]) {
|
async function writeFilesToBucket(uuid: UUID, files:any[]) {
|
||||||
const fileArray:{name:string, content:Promise<ReadableStreamReadResult<Uint8Array>>|ReadableStreamReadResult<Uint8Array>}[] = await Promise.all( files.map((file:File) => {
|
const fileArray:{name:string, content:Promise<ReadableStreamReadResult<Uint8Array>>|ReadableStreamReadResult<Uint8Array>}[] = await Promise.all( files.map((file:File) => {
|
||||||
return {'name':( ()=>file.name)(), 'content':file.stream().getReader().read()};
|
return {'name':( ()=>file.name)(), 'content':file.stream().getReader().read()};
|
||||||
@ -26,29 +22,25 @@ async function writeFilesToBucket(uuid: UUID, files:any[]) {
|
|||||||
|
|
||||||
mkdirSync(`./bucket/${uuid}/`)
|
mkdirSync(`./bucket/${uuid}/`)
|
||||||
for(let file in finalFileArray){
|
for(let file in finalFileArray){
|
||||||
|
|
||||||
writeFile(`./bucket/${uuid}/${finalFileArray[file].name}`,Buffer.from(finalFileArray[file].content.value as Uint8Array),(e)=>{console.log(e)})
|
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});
|
const attachment = await Attachment.create({bucket_id:uuid, filename:finalFileArray[file].name}, {include: Attachment.associations.bucket});
|
||||||
console.log(attachment);
|
console.log(attachment);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
async function addToPost(postid:number):Promise<UUID>
|
async function addToPost(postid:number):Promise<Bucket>
|
||||||
{
|
{
|
||||||
Post.sync();
|
Post.sync();
|
||||||
const post = await Post.findOne({where: {id:postid}});
|
const post = await Post.findOne({where: {id:postid}});
|
||||||
|
|
||||||
if (!post) throw new APIError({ status: 500, responseText: "invalid postid" });
|
if (!post) throw new APIError({ status: 500, responseText: "invalid postid" });
|
||||||
const bucket = await post.createBucket({id:randomUUID()});
|
const bucket = await post.createBucket({id:randomUUID()});
|
||||||
// const bucketPost = await Post.associations.postBuckets.create({bucketId: bucket.id, postId: postid})
|
return bucket;
|
||||||
|
|
||||||
// console.log(bucketPost);
|
|
||||||
return bucket.id;
|
|
||||||
}
|
}
|
||||||
async function addToBucket(bucketid:number):Promise<UUID> {
|
async function addToBucket(bucketid:number):Promise<Bucket> {
|
||||||
const bucket = await Bucket.findOne({where: {id: bucketid}});
|
const bucket = await Bucket.findOne({where: {id: bucketid}, include: {association: Bucket.associations.posts}});
|
||||||
if (!bucket) throw new APIError({ status: 500, responseText: "invalid bucketid" });
|
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);
|
const data = JSON.parse(requestData);
|
||||||
|
|
||||||
let uuid:UUID = (data.postid && !data.bucketid)? await addToPost(data.postid) : await addToBucket(data.bucketid)
|
let bucket:Bucket = (data.postid && !data.bucketid)? await addToPost(data.postid) : await addToBucket(data.bucketid)
|
||||||
writeFilesToBucket(uuid, files);
|
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({
|
return new Response(JSON.stringify({
|
||||||
'files': 'ya yeet',
|
bucket: bucket2
|
||||||
'uuid': uuid,
|
|
||||||
}), { status: 200 });
|
}), { status: 200 });
|
||||||
|
|
||||||
|
|
||||||
|
|||||||
@ -12,8 +12,9 @@
|
|||||||
min-width:fit-content;
|
min-width:fit-content;
|
||||||
min-height:256px;
|
min-height:256px;
|
||||||
/* flex-grow: 10; */
|
/* flex-grow: 10; */
|
||||||
background-image: url(/placeholder-square.png);
|
background-image: url(/genericHeaderImage.png);
|
||||||
background-size: contain;
|
opacity: 0.8;
|
||||||
|
background-size: cover;
|
||||||
background-repeat: no-repeat;
|
background-repeat: no-repeat;
|
||||||
background-position: center;
|
background-position: center;
|
||||||
background-color: #00000044;
|
background-color: #00000044;
|
||||||
|
|||||||
@ -51,7 +51,7 @@ export class Post extends Model<InferAttributes<Post>, InferCreationAttributes<P
|
|||||||
|
|
||||||
|
|
||||||
@BelongsToMany(()=>Bucket,{through: {model:'PostBucket'}, throughAssociations: {
|
@BelongsToMany(()=>Bucket,{through: {model:'PostBucket'}, throughAssociations: {
|
||||||
fromSource: 'postPostBuckets',
|
fromSource: 'postBucketBuckets',
|
||||||
toSource: 'post',
|
toSource: 'post',
|
||||||
fromTarget: 'postBucketPosts',
|
fromTarget: 'postBucketPosts',
|
||||||
toTarget: 'PostBucket',
|
toTarget: 'PostBucket',
|
||||||
|
|||||||
Loading…
x
Reference in New Issue
Block a user