-}
-/* TODO: Continue to flesh this out */
-File.defaults = {
- name: '',
- data: '',
- mode: {},
- size: 0
- //lastModified: new Date()?
- //lastAccessed: new Date()?
-
-}
-
-
-/* Filesystem maintains the current session memory for the strapp instance. Files can be
- created and killed from the filesystem without leveraging localForage. Files that are
- in the filesystem can be stored to localForage while files that are in localForage can be loaded
- to the filesystem. When a Filesystem is first intialized, it attempts to get its strappID it populates itself from localForage and
- overwrites any files in its current memory. Files that have restore() as a property (which will be some method needed to
- make the file functions e.g. strappPeerConnections will restore() themselves lazily, i.e. when they are needed.*/
-
- /* TODO: Should it be possible to create/preserve/destroy a file to both localForage and fileSystem? (same time) */
- /* TODO: Should initFileSystem not overwrite files? */
-
-/* These are the default files on all file systems */
-let defaultFiles = [ "..", ".", "accounts", "ice", "log", "run" ]
-
-
-/* TODO: Protect data via closures? */
-const fs = {
- /* TODO: What if files are added to file system before init is is called? */
- initFileSystem(){
- this.db = localforage.createInstance({ name: "database" })
- /* Iterate through all files on localforage, adding them to FileSystem
- and calling their restore methods */
- this.db.iterate( (value, key, n) => {
- /* just btw, return !undefined to exit early */
- this.loadFile(key, true)
-
- }).catch( (err) => {
- console.log(`error: ${err} when iterating through localForage during initFileSystem`)
- })
- /* Add the hardcoded default files if they dont already exist */
- /* Restore these files --> need the private/public key*/
- initialFiles.map( (val, idx, array) => {
- if (this.fileExists(val)) {
- let file = this.getFile(val)
- let restoreProp = file['restore']
- if (restoreProp === undefined && typeof restoreFx === 'function') {
- //restore file
- }
- /* Else don't do anything, file exists in FS and doesnt need to be restored */
- }
- else {
- /* TODO: Remove checking for every file --> although its only for the default files which
- will probably be a low number. Still, unnecessary. Could make initialFiles a
- Map object with fileType in it and switch(val.fileType) */
- if (val === '..') {
- let file = new StrappPeerConnection()
- /* Connect with host */
- }
- else {
- /* Each default file is going to have specific permissions, */
- let filedata = new File()
- filedata.name = val
- filedata.mode =
- this.createFile(val,)
- }
- }
-
- })
-
- },
-
- fileExists(filename) {
- return this.files[filename] === undefined ? false : true
- },
-
- /* Create a file in the file system, if specified overwrites any file that is already there
- else does nothing */
- createFile(filename, filedata, overwrite = false){
- filedata.name = filename
- if (this.files[filename] === undefined) {
- this.files[filename] = filedata