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)"
|
"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",
|
||||||
|
|
|
@ -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).
|
|
@ -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
|
||||||
|
@ -141,102 +147,104 @@ export default class Files {
|
||||||
let ogf = this.files[uploadId]
|
let ogf = this.files[uploadId]
|
||||||
|
|
||||||
this.files[uploadId] = {
|
this.files[uploadId] = {
|
||||||
filename:settings.name,
|
filename:settings.name,
|
||||||
messageids:[],
|
messageids:[],
|
||||||
mime:settings.mime,
|
mime:settings.mime,
|
||||||
sizeInBytes:0,
|
sizeInBytes:0,
|
||||||
|
|
||||||
owner:settings.owner,
|
owner:settings.owner,
|
||||||
visibility: settings.owner ? "private" : "public",
|
visibility: settings.owner ? "private" : "public",
|
||||||
reserved: true,
|
reserved: true,
|
||||||
|
|
||||||
chunkSize: this.config.maxDiscordFileSize
|
chunkSize: this.config.maxDiscordFileSize
|
||||||
}
|
}
|
||||||
|
|
||||||
// save
|
// save
|
||||||
|
|
||||||
|
if (settings.sizeInBytes >= (this.config.maxDiscordFileSize*this.config.maxDiscordFiles)) {
|
||||||
|
reject({status:400,message:"file too large"});
|
||||||
|
return
|
||||||
|
}
|
||||||
|
|
||||||
if (settings.owner) {
|
if (settings.owner) {
|
||||||
await files.index(settings.owner,uploadId)
|
await files.index(settings.owner,uploadId)
|
||||||
}
|
}
|
||||||
|
|
||||||
// get buffer
|
let msgIds: string[] = []
|
||||||
if (fBuffer.byteLength >= (this.config.maxDiscordFileSize*this.config.maxDiscordFiles)) {
|
let totalFileSize = 0
|
||||||
reject({status:400,message:"file too large"});
|
let chunkData: {size: number, data: Buffer[]} = {size: 0, data: []}
|
||||||
return
|
|
||||||
}
|
|
||||||
|
|
||||||
// generate buffers to upload
|
let uploadChunk = async (fBuffer: Buffer) => {
|
||||||
let toUpload = []
|
if (!this.uploadChannel) return
|
||||||
for (let i = 0; i < Math.ceil(fBuffer.byteLength/this.config.maxDiscordFileSize); i++) {
|
// generate buffers to upload
|
||||||
toUpload.push(
|
let toUpload = []
|
||||||
fBuffer.subarray(
|
for (let i = 0; i < Math.ceil(fBuffer.byteLength/this.config.maxDiscordFileSize); i++) {
|
||||||
i*this.config.maxDiscordFileSize,
|
toUpload.push(
|
||||||
Math.min(
|
fBuffer.subarray(
|
||||||
fBuffer.byteLength,
|
i*this.config.maxDiscordFileSize,
|
||||||
(i+1)*this.config.maxDiscordFileSize
|
Math.min(
|
||||||
|
fBuffer.byteLength,
|
||||||
|
(i+1)*this.config.maxDiscordFileSize
|
||||||
|
)
|
||||||
)
|
)
|
||||||
)
|
)
|
||||||
)
|
}
|
||||||
}
|
|
||||||
|
|
||||||
// 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++) {
|
|
||||||
|
|
||||||
|
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 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
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
// this code deletes the files from discord, btw
|
let finish = async () => {
|
||||||
// if need be, replace with job queue system
|
// this code deletes the files from discord, btw
|
||||||
|
// if need be, replace with job queue system
|
||||||
|
|
||||||
if (ogf&&this.uploadChannel) {
|
if (ogf&&this.uploadChannel) {
|
||||||
for (let x of ogf.messageids) {
|
for (let x of ogf.messageids) {
|
||||||
this.uploadChannel.messages.delete(x).catch(err => console.error(err))
|
this.uploadChannel.messages.delete(x).catch(err => console.error(err))
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
resolve(await this.writeFile(
|
||||||
|
uploadId,
|
||||||
|
{
|
||||||
|
filename: settings.name,
|
||||||
|
messageids: msgIds,
|
||||||
|
mime: settings.mime,
|
||||||
|
sizeInBytes: settings.sizeInBytes,
|
||||||
|
|
||||||
|
owner: settings.owner,
|
||||||
|
visibility: ogf ? ogf.visibility
|
||||||
|
: (
|
||||||
|
settings.owner
|
||||||
|
? Accounts.getFromId(settings.owner)?.defaultFileVisibility
|
||||||
|
: undefined
|
||||||
|
),
|
||||||
|
// so that json.stringify doesnt include tag:undefined
|
||||||
|
...((ogf||{}).tag ? {tag:ogf.tag} : {}),
|
||||||
|
|
||||||
|
chunkSize: this.config.maxDiscordFileSize
|
||||||
|
}
|
||||||
|
))
|
||||||
}
|
}
|
||||||
|
|
||||||
resolve(await this.writeFile(
|
|
||||||
uploadId,
|
|
||||||
{
|
|
||||||
filename:settings.name,
|
|
||||||
messageids:msgIds,
|
|
||||||
mime:settings.mime,
|
|
||||||
sizeInBytes:fBuffer.byteLength,
|
|
||||||
|
|
||||||
owner:settings.owner,
|
|
||||||
visibility: ogf ? ogf.visibility
|
|
||||||
: (
|
|
||||||
settings.owner
|
|
||||||
? Accounts.getFromId(settings.owner)?.defaultFileVisibility
|
|
||||||
: undefined
|
|
||||||
),
|
|
||||||
// so that json.stringify doesnt include tag:undefined
|
|
||||||
...((ogf||{}).tag ? {tag:ogf.tag} : {}),
|
|
||||||
|
|
||||||
chunkSize: this.config.maxDiscordFileSize
|
|
||||||
}
|
|
||||||
))
|
|
||||||
|
|
||||||
|
|
||||||
})
|
})
|
||||||
}
|
}
|
||||||
|
|
|
@ -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}
|
||||||
|
|
Loading…
Reference in a new issue