mirror of
https://github.com/mollersuite/monofile.git
synced 2024-11-25 07:06:25 -08:00
fg
This commit is contained in:
parent
eba3221d86
commit
96d0c1bf96
|
@ -4,7 +4,17 @@ import { readFile, writeFile } from "fs";
|
|||
import { Readable } from "node:stream"
|
||||
|
||||
export let id_check_regex = /[A-Za-z0-9_\-\.]+/
|
||||
export let alphanum = "abcdefghijklmnopqrstuvwxyzABCDEFGHIJKLMNOPQRSTUVWXYZ1234567890"
|
||||
|
||||
// bad solution but whatever
|
||||
|
||||
export function generateFileId() {
|
||||
let fid = ""
|
||||
for (let i = 0; i < 5; i++) {
|
||||
fid += alphanum[Math.floor(Math.random()*alphanum.length)]
|
||||
}
|
||||
return fid
|
||||
}
|
||||
|
||||
export interface FileUploadSettings {
|
||||
name?: string,
|
||||
|
@ -76,7 +86,7 @@ export default class Files {
|
|||
return
|
||||
}
|
||||
|
||||
let uploadId = (settings.uploadId || Math.random().toString().slice(2)).toString();
|
||||
let uploadId = (settings.uploadId || generateFileId()).toString();
|
||||
|
||||
if ((uploadId.match(id_check_regex) || [])[0] != uploadId || uploadId.length > 30) {
|
||||
reject({status:400,message:"invalid id"});return
|
||||
|
|
Loading…
Reference in a new issue