Skip to content

Instantly share code, notes, and snippets.

@embryologist
Created August 30, 2018 19:50
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save embryologist/111e90584211ff33b3fb2ddb437ad880 to your computer and use it in GitHub Desktop.
Save embryologist/111e90584211ff33b3fb2ddb437ad880 to your computer and use it in GitHub Desktop.
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