mirror of
https://github.com/mollersuite/monofile.git
synced 2024-11-21 05:26:27 -08:00
i will not be finishing this
what the hell was i smoking
This commit is contained in:
parent
981c4bd801
commit
e1b9a14fbc
9
.vscode/tasks.json
vendored
9
.vscode/tasks.json
vendored
|
@ -10,6 +10,15 @@
|
|||
},
|
||||
"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",
|
||||
"command":"tsc\nsass src/style:out/style\nrollup -c\nnode ./out/server/index.js\ndel ./out/* -Recurse",
|
||||
|
|
|
@ -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).
|
||||
|
||||
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).
|
|
@ -25,7 +25,8 @@ export interface FileUploadSettings {
|
|||
name?: string,
|
||||
mime: string,
|
||||
uploadId?: string,
|
||||
owner?:string
|
||||
owner?:string,
|
||||
sizeInBytes: number
|
||||
}
|
||||
|
||||
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) => {
|
||||
|
||||
// guards
|
||||
|
||||
if (!this.uploadChannel) {
|
||||
reject({status:503,message:"server is not ready - please try again later"})
|
||||
return
|
||||
|
@ -155,16 +161,21 @@ export default class Files {
|
|||
|
||||
// save
|
||||
|
||||
if (settings.owner) {
|
||||
await files.index(settings.owner,uploadId)
|
||||
}
|
||||
|
||||
// get buffer
|
||||
if (fBuffer.byteLength >= (this.config.maxDiscordFileSize*this.config.maxDiscordFiles)) {
|
||||
if (settings.sizeInBytes >= (this.config.maxDiscordFileSize*this.config.maxDiscordFiles)) {
|
||||
reject({status:400,message:"file too large"});
|
||||
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
|
||||
let toUpload = []
|
||||
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
|
||||
let uploadTmplt:Discord.AttachmentBuilder[] = toUpload.map((e) => {
|
||||
return new Discord.AttachmentBuilder(e)
|
||||
.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({
|
||||
files:uploadGroups[i]
|
||||
files:uploadTmplt
|
||||
}).catch((e) => {console.error(e)})
|
||||
|
||||
if (ms) {
|
||||
msgIds.push(ms.id)
|
||||
return ms.id
|
||||
} else {
|
||||
if (!ogf) delete this.files[uploadId]
|
||||
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
|
||||
// if need be, replace with job queue system
|
||||
|
||||
|
@ -221,7 +227,7 @@ export default class Files {
|
|||
filename: settings.name,
|
||||
messageids: msgIds,
|
||||
mime: settings.mime,
|
||||
sizeInBytes:fBuffer.byteLength,
|
||||
sizeInBytes: settings.sizeInBytes,
|
||||
|
||||
owner: settings.owner,
|
||||
visibility: ogf ? ogf.visibility
|
||||
|
@ -236,6 +242,8 @@ export default class Files {
|
|||
chunkSize: this.config.maxDiscordFileSize
|
||||
}
|
||||
))
|
||||
}
|
||||
|
||||
|
||||
|
||||
})
|
||||
|
|
|
@ -165,7 +165,9 @@
|
|||
{:else}
|
||||
<div transition:padding_scaleY|local class="uploadingContainer">
|
||||
{#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 upload[1].uploadStatus.fileId}
|
||||
|
|
Loading…
Reference in a new issue