Skip to content

Commit

Permalink
fix: remove tmpName from file objects, use uuid when generating file …
Browse files Browse the repository at this point in the history
…names
  • Loading branch information
teclone committed Oct 9, 2019
1 parent d503546 commit 8e37d7b
Show file tree
Hide file tree
Showing 4 changed files with 9,133 additions and 6 deletions.
3 changes: 2 additions & 1 deletion package.json
Expand Up @@ -75,6 +75,7 @@
"@forensic-js/node-utils": "1.0.0",
"@forensic-js/regex": "1.0.1",
"@forensic-js/utils": "2.0.0",
"mime-types": "2.1.24"
"mime-types": "2.1.24",
"uuid": "3.3.3"
}
}
2 changes: 0 additions & 2 deletions src/@types/index.d.ts
Expand Up @@ -135,15 +135,13 @@ export type MiddlewareInstance = [MiddlewareId, Url, Middleware[], null | Resolv

export interface FileEntry {
name: string;
tmpName: string;
path: string;
size: number;
type: string;
}

export interface FileEntryCollection {
name: string[];
tmpName: string[];
path: string[];
size: number[];
type: string[];
Expand Down
5 changes: 2 additions & 3 deletions src/modules/BodyParser.ts
Expand Up @@ -3,6 +3,7 @@ import * as fs from 'fs';
import { RServerConfig, Data, Files, MultipartHeaders, FileEntry, FileEntryCollection } from '../@types/index';
import { isArray, isNull, generateRandomText, isObject, makeArray } from '@forensic-js/utils';
import { CRLF, BLANK_LINE } from './Constants';
import uuidv1 from 'uuid/v1';

export default class {
private entryPath: string;
Expand Down Expand Up @@ -59,7 +60,6 @@ export default class {
size: [],
type: [],
name: [],
tmpName: [],
};

for (const [key, current] of Object.entries(value)) {
Expand All @@ -73,13 +73,12 @@ export default class {
* processes and stores file
*/
private processFile(headers: MultipartHeaders, content: string): FileEntry {
const tmpName = generateRandomText(16) + '.tmp';
const tmpName = uuidv1() + '.tmp';
const filePath = resolvePaths(this.entryPath, this.config.tempDir, tmpName);

fs.writeFileSync(filePath, content, headers.encoding);
return {
name: headers.fileName.replace(/\.\./g, ''),
tmpName,
path: filePath,
size: fs.statSync(filePath).size,
type: headers.type,
Expand Down

0 comments on commit 8e37d7b

Please sign in to comment.