mirror of
https://github.com/mollersuite/monofile.git
synced 2024-11-21 21:36:26 -08:00
dasdasdasdsd
This commit is contained in:
parent
79da014ec5
commit
9812ed454c
|
@ -1,4 +1,4 @@
|
||||||
import { Client } from "discord.js";
|
import Discord, { Client } from "discord.js";
|
||||||
|
|
||||||
export interface FileUploadSettings {
|
export interface FileUploadSettings {
|
||||||
name?: string,
|
name?: string,
|
||||||
|
@ -14,6 +14,8 @@ export interface Configuration {
|
||||||
requestTimeout: number
|
requestTimeout: number
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/* */
|
||||||
|
|
||||||
export default class Files {
|
export default class Files {
|
||||||
|
|
||||||
config: Configuration
|
config: Configuration
|
||||||
|
@ -44,8 +46,8 @@ export default class Files {
|
||||||
|
|
||||||
// generate buffers to upload
|
// generate buffers to upload
|
||||||
let toUpload = []
|
let toUpload = []
|
||||||
for (let i = 0; i < Math.ceil(fBuffer.byteLength/config.maxDiscordFileSize); i++) {
|
for (let i = 0; i < Math.ceil(fBuffer.byteLength/this.config.maxDiscordFileSize); i++) {
|
||||||
toUpload.push(fBuffer.subarray(i*config.maxDiscordFileSize,Math.min(fBuffer.byteLength,(i+1)*config.maxDiscordFileSize)))
|
toUpload.push(fBuffer.subarray(i*this.config.maxDiscordFileSize,Math.min(fBuffer.byteLength,(i+1)*config.maxDiscordFileSize)))
|
||||||
}
|
}
|
||||||
|
|
||||||
// begin uploading
|
// begin uploading
|
||||||
|
@ -73,9 +75,17 @@ export default class Files {
|
||||||
messageids:msgIds,
|
messageids:msgIds,
|
||||||
mime:settings.mime
|
mime:settings.mime
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/* similar save/load/etc system to your other projects, split */
|
||||||
|
/* you'll still need to do this later but whatever */
|
||||||
|
/* also might be a good idea to switch to fs/promises */
|
||||||
|
|
||||||
fs.writeFile(__dirname+"/../.data/files.json",JSON.stringify(files),(err) => {
|
fs.writeFile(__dirname+"/../.data/files.json",JSON.stringify(files),(err) => {
|
||||||
if (err) {reject({status:500,message:"please try again"}); delete files[uploadId];return}
|
if (err) {
|
||||||
|
reject({status:500,message:"please try again"});
|
||||||
|
delete files[uploadId];
|
||||||
|
return
|
||||||
|
}
|
||||||
resolve(uploadId)
|
resolve(uploadId)
|
||||||
})
|
})
|
||||||
})
|
})
|
||||||
|
|
Loading…
Reference in a new issue