Created
August 30, 2018 19:50
-
-
Save embryologist/111e90584211ff33b3fb2ddb437ad880 to your computer and use it in GitHub Desktop.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
export class FileInfo implements IFileInfo { | |
constructor( | |
public exists: boolean, | |
public length: number, | |
public physicalPath: string, | |
public name: string, | |
public displayName: string, | |
public lastModified: Date, | |
public validUntil: Date, | |
public isDirectory: boolean, | |
public isProtected: boolean, | |
public allowedExtentions: Array<string>, | |
public isUploadRestricted: boolean, | |
) { | |
this.exists = exists; | |
this.length = length; | |
this.physicalPath = physicalPath; | |
this.name = name; | |
this.displayName = displayName; | |
this.lastModified = lastModified; | |
this.validUntil = validUntil; | |
this.isDirectory = isDirectory; | |
this.isProtected = isProtected; | |
this.allowedExtentions = allowedExtentions; | |
this.isUploadRestricted = isUploadRestricted; | |
} | |
getExtention(): string { | |
return /[.]/.exec(this.name) ? /[^.]+$/.exec(this.name)[0].toLowerCase() : undefined; | |
} | |
getType(): string { | |
const ext = this.name.replace(/^.*\./, ''); | |
switch (ext) { | |
case 'jpg': | |
case 'png': | |
case 'jpeg': | |
return 'image'; | |
case 'pdf': | |
return 'pdf'; | |
default: | |
return undefined; | |
} | |
} | |
getPhysicalPath(): string { | |
return this.physicalPath.substring(0, this.physicalPath.lastIndexOf('/')); | |
} | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment