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 { where } from "@sequelize/core";
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
async function writeFilesToBucket(uuid: UUID, files:any[]) {
|
||||
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()};
|
||||
@ -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<UUID>
|
||||
async function addToPost(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()});
|
||||
// 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<UUID> {
|
||||
const bucket = await Bucket.findOne({where: {id: bucketid}});
|
||||
async function addToBucket(bucketid:number):Promise<Bucket> {
|
||||
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 });
|
||||
|
||||
|
||||
|
||||
@ -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;
|
||||
|
||||
@ -51,7 +51,7 @@ export class Post extends Model<InferAttributes<Post>, InferCreationAttributes<P
|
||||
|
||||
|
||||
@BelongsToMany(()=>Bucket,{through: {model:'PostBucket'}, throughAssociations: {
|
||||
fromSource: 'postPostBuckets',
|
||||
fromSource: 'postBucketBuckets',
|
||||
toSource: 'post',
|
||||
fromTarget: 'postBucketPosts',
|
||||
toTarget: 'PostBucket',
|
||||
|
||||
Loading…
x
Reference in New Issue
Block a user