i will not be finishing this

what the hell was i smoking
This commit is contained in:
May 2023-09-24 11:58:46 -07:00
parent 981c4bd801
commit e1b9a14fbc
4 changed files with 93 additions and 74 deletions

9
.vscode/tasks.json vendored
View file

@ -10,6 +10,15 @@
}, },
"label": "Build (Bot Server)" "label": "Build (Bot Server)"
}, },
{
"type": "shell",
"command":"sass src/style:out/style\nrollup -c",
"group": {
"kind": "build",
"isDefault": true
},
"label": "Build (Frontend Only)"
},
{ {
"type": "shell", "type": "shell",
"command":"tsc\nsass src/style:out/style\nrollup -c\nnode ./out/server/index.js\ndel ./out/* -Recurse", "command":"tsc\nsass src/style:out/style\nrollup -c\nnode ./out/server/index.js\ndel ./out/* -Recurse",

View file

@ -72,4 +72,4 @@ Although we believe monofile is not against Discord's developer terms of service
Code written by monofile's contributors is currently licensed under [Unlicense](https://github.com/nbitzz/monofile/blob/main/LICENSE). Code written by monofile's contributors is currently licensed under [Unlicense](https://github.com/nbitzz/monofile/blob/main/LICENSE).
Icons under `/assets/icons` were created by Microsoft, and as such are licensed under [different terms](https://github.com/nbitzz/monofile/blob/1.3.0/assets/icons/README.md) (MIT). Icons under `/assets/icons` were created by Microsoft, and as such are licensed under [different terms](https://github.com/nbitzz/monofile/blob/main/assets/icons/README.md) (MIT).

View file

@ -25,7 +25,8 @@ export interface FileUploadSettings {
name?: string, name?: string,
mime: string, mime: string,
uploadId?: string, uploadId?: string,
owner?:string owner?:string,
sizeInBytes: number
} }
export interface Configuration { export interface Configuration {
@ -92,8 +93,13 @@ export default class Files {
} }
uploadFile(settings:FileUploadSettings,fBuffer:Buffer):Promise<string|StatusCodeError> { uploadFileStream(_settings:FileUploadSettings,fStream:Readable):Promise<string|StatusCodeError> {
let settings = JSON.parse(JSON.stringify(_settings)) // copy
return new Promise<string>(async (resolve,reject) => { return new Promise<string>(async (resolve,reject) => {
// guards
if (!this.uploadChannel) { if (!this.uploadChannel) {
reject({status:503,message:"server is not ready - please try again later"}) reject({status:503,message:"server is not ready - please try again later"})
return return
@ -155,16 +161,21 @@ export default class Files {
// save // save
if (settings.owner) { if (settings.sizeInBytes >= (this.config.maxDiscordFileSize*this.config.maxDiscordFiles)) {
await files.index(settings.owner,uploadId)
}
// get buffer
if (fBuffer.byteLength >= (this.config.maxDiscordFileSize*this.config.maxDiscordFiles)) {
reject({status:400,message:"file too large"}); reject({status:400,message:"file too large"});
return return
} }
if (settings.owner) {
await files.index(settings.owner,uploadId)
}
let msgIds: string[] = []
let totalFileSize = 0
let chunkData: {size: number, data: Buffer[]} = {size: 0, data: []}
let uploadChunk = async (fBuffer: Buffer) => {
if (!this.uploadChannel) return
// generate buffers to upload // generate buffers to upload
let toUpload = [] let toUpload = []
for (let i = 0; i < Math.ceil(fBuffer.byteLength/this.config.maxDiscordFileSize); i++) { for (let i = 0; i < Math.ceil(fBuffer.byteLength/this.config.maxDiscordFileSize); i++) {
@ -179,33 +190,28 @@ export default class Files {
) )
} }
if (toUpload.length > this.config.maxDiscordFiles) return
// begin uploading // begin uploading
let uploadTmplt:Discord.AttachmentBuilder[] = toUpload.map((e) => { let uploadTmplt:Discord.AttachmentBuilder[] = toUpload.map((e) => {
return new Discord.AttachmentBuilder(e) return new Discord.AttachmentBuilder(e)
.setName(Math.random().toString().slice(2)) .setName(Math.random().toString().slice(2))
}) })
let uploadGroups = []
for (let i = 0; i < Math.ceil(uploadTmplt.length/10); i++) {
uploadGroups.push(uploadTmplt.slice(i*10,((i+1)*10)))
}
let msgIds = []
for (let i = 0; i < uploadGroups.length; i++) {
let ms = await this.uploadChannel.send({ let ms = await this.uploadChannel.send({
files:uploadGroups[i] files:uploadTmplt
}).catch((e) => {console.error(e)}) }).catch((e) => {console.error(e)})
if (ms) { if (ms) {
msgIds.push(ms.id) return ms.id
} else { } else {
if (!ogf) delete this.files[uploadId] if (!ogf) delete this.files[uploadId]
else this.files[uploadId] = ogf else this.files[uploadId] = ogf
reject({status:500,message:"please try again"}); return return
} }
} }
let finish = async () => {
// this code deletes the files from discord, btw // this code deletes the files from discord, btw
// if need be, replace with job queue system // if need be, replace with job queue system
@ -221,7 +227,7 @@ export default class Files {
filename: settings.name, filename: settings.name,
messageids: msgIds, messageids: msgIds,
mime: settings.mime, mime: settings.mime,
sizeInBytes:fBuffer.byteLength, sizeInBytes: settings.sizeInBytes,
owner: settings.owner, owner: settings.owner,
visibility: ogf ? ogf.visibility visibility: ogf ? ogf.visibility
@ -236,6 +242,8 @@ export default class Files {
chunkSize: this.config.maxDiscordFileSize chunkSize: this.config.maxDiscordFileSize
} }
)) ))
}
}) })

View file

@ -165,7 +165,9 @@
{:else} {:else}
<div transition:padding_scaleY|local class="uploadingContainer"> <div transition:padding_scaleY|local class="uploadingContainer">
{#if !upload[1].uploadStatus.fileId} {#if !upload[1].uploadStatus.fileId}
<p in:fade={{duration:300, delay:400, easingFunc:circOut}} out:padding_scaleY={{easingFunc:circIn,op:true}}>{upload[1].uploadStatus.error ?? "Uploading..."}</p> <div class="uploadStatus" in:fade={{duration:300, delay:400, easingFunc:circOut}} out:padding_scaleY={{easingFunc:circIn,op:true}}>
<p>{upload[1].uploadStatus.error ?? `${upload[1].uploadStatus.percentage}%`}</p>
</div>
{/if} {/if}
{#if upload[1].uploadStatus.fileId} {#if upload[1].uploadStatus.fileId}