I want to create a web interface for a folder structure on my server. Basically like dropbox or any other cloud storage but only with read functionality, no creation of new files or uploading.
I'm wondering what the best way would be to create a "virtual" representation of an existing folder structure on my server.
My idea was to recursively loop through the directory on the server and create a database entry for every file or folder. I'd create a hash of every file to uniquely identify them.
Like this:
'1382b6993e9f270cb1c29833be3f5750': {
type: 'folder',
name: 'root',
path: '/',
parentPath: null,
parentID: null,
children: ['147d0ef33fe657ce53a83de6a630473d']
},
'147d0ef33fe657ce53a83de6a630473d': {
type: 'folder',
name: 'pictures',
parentID: '1382b6993e9f270cb1c29833be3f5750',
parentPath: '/',
path: '/pictures',
children: ['8f7c5959dbb088c0aef8b145dbdf6e43']
},
'8f7c5959dbb088c0aef8b145dbdf6e43': {
type: 'file',
name: 'cat.jpg',
parentID: '147d0ef33fe657ce53a83de6a630473d',
parentPath: '/pictures',
path: '/pictures/cat.jpg'
},
To account for changes in the directory I'd periodically run a process to scan it and update the database accordingly.
It should be said that the directory is rather big with many subfolders and hundreds of files.
Since the whole folder structure is rather big I could see it being a problem to keep the whole tree in the react state, but I guess that could be fixed by always fetching the directory contents when navigating on the frontend.
Does this approach make sense or is there a better way?