Created
March 11, 2020 06:29
-
-
Save nhuanhoangduc/df25be6d8b50e680f7611792c304919c 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
/* -*- javascript -*- | |
* | |
* Confidential and Proprietary | |
* NOT FOR RELEASE | |
* (c) 2017-present RevTera, Inc. | |
* All Rights Reserved | |
*/ | |
import path from 'path'; | |
import Model from './Model'; | |
import Source from './Source'; | |
import { fromTimeVal } from '../utils/time'; | |
function chunk (arr, len) { | |
var chunks = [], | |
i = 0, | |
n = arr.length; | |
while (i < n) { | |
chunks.push(arr.slice(i, i += len)); | |
} | |
return chunks; | |
} | |
/** | |
* FileNode stores strucutured fields of a FileNode record returned from the backend. | |
* @param {Object} [values] - Initial model attributes | |
* @class | |
*/ | |
class MultiCatalogFileNode extends Model { | |
constructor(values) { | |
const files = chunk(values.slice(3), 4) | |
const moreInformation = files.reduce((memo, file) => { | |
memo.catalogs.push(file[1]) | |
memo.nid = file[2] | |
memo.path = file[3] | |
return memo | |
}, { catalogs: [], nid: null, path: null, }) | |
super(Array.isArray(values) && (values.length == 21) ? { | |
index: parseInt(values[1], 10), | |
hash: parseInt(values[2], 10) ? values[2] : null, | |
...moreInformation | |
} : values); | |
} | |
/** @member {string} */ | |
get name() { | |
return this.path.split('/').slice(-1)[0]; | |
} | |
/** @member {string} */ | |
get extension() { | |
return this.path.split('/').slice(-1)[0].split('.').slice(-1)[0].toLowerCase(); | |
} | |
/** @member {string} */ | |
get isRegularFile() { | |
return this.type === 3; | |
} | |
/** @member {string} */ | |
get isDirectory() { | |
return this.type === 4; | |
} | |
/** @member {Source} */ | |
get source() { | |
return new Source({ path: path.join(this.root, this.path) }); | |
} | |
} | |
export default MultiCatalogFileNode; |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment