Skip to content

Commit

Permalink
Merge master into en
Browse files Browse the repository at this point in the history
  • Loading branch information
github-actions[bot] authored Jul 21, 2024
2 parents 8e32bb4 + 13111c7 commit 6e07aaa
Show file tree
Hide file tree
Showing 3 changed files with 127 additions and 86 deletions.
195 changes: 118 additions & 77 deletions package-lock.json

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

2 changes: 1 addition & 1 deletion package.json
Original file line number Diff line number Diff line change
Expand Up @@ -63,7 +63,7 @@
"docker-secret": "1.1.2",
"express": "4.19.2",
"express-urlrewrite": "1.2.0",
"formidable": "3.2.4",
"formidable": "3.5.1",
"gm": "1.23.1",
"got": "11.8.5",
"http-proxy-middleware": "0.20.0",
Expand Down
16 changes: 8 additions & 8 deletions uploader.js
Original file line number Diff line number Diff line change
Expand Up @@ -43,9 +43,10 @@ export function configure(startStamp) {

class FileInfo {
constructor(file, targetDir, nameLen, dirDepth) {
this.name = file.name;
this.name = file.originalFilename;
this.size = file.size;
this.mime = file.type;
this.mime = file.mimetype;
this.path = file.filepath;

this.createFileName(targetDir, nameLen, dirDepth);
}
Expand Down Expand Up @@ -193,7 +194,7 @@ export function configure(startStamp) {
}

const postHandler = (req, res) => {
const form = new formidable.IncomingForm();
const form = formidable({ uploadDir: incomeDir });
const isAvatar = req.url === '/uploadava';
const maxPostSize = isAvatar ? maxAvaPostSize : maxPhotoPostSize;
const targetDir = isAvatar ? targetDirAvatar : targetDirPhoto;
Expand All @@ -210,22 +211,21 @@ export function configure(startStamp) {
tooBigPostDestroy(req, isAvatar, 0, contentLength);
}

form.uploadDir = incomeDir;
form
.on('fileBegin', (name, file) => {
tmpFiles.push(file.path);
tmpFiles.push(file.filepath);

const fileInfo = new FileInfo(file, targetDir, isAvatar ? 10 : 18, isAvatar ? 2 : 3);

map[path.basename(file.path)] = fileInfo;
map[path.basename(file.filepath)] = fileInfo;
files.push(fileInfo);
})
.on('file', (name, file) => {
const fileInfo = map[path.basename(file.path)];
const fileInfo = map[path.basename(file.filepath)];

fileInfo.size = file.size;
fileInfo.path = path.join(incomeDir, fileInfo.file);
mv(file.path, fileInfo.path, { clobber: false }, err => {
mv(file.filepath, fileInfo.path, { clobber: false }, err => {
if (err) {
logger.error('MV error:', err);
}
Expand Down

0 comments on commit 6e07aaa

Please sign in to comment.