diff --git a/languages/en_CA.json b/languages/en_CA.json index 2c808244..88e3fe2f 100644 --- a/languages/en_CA.json +++ b/languages/en_CA.json @@ -554,6 +554,8 @@ "Operating Hours": "Operating Hours", "Autosave": "Autosave", "Save Directory": "Save Directory", + "New Videos Directory Set": "New Videos Directory Set", + "Set New Videos Directory": "Set New Videos Directory?", "CSS": "CSS Style your dashboard.", "Don't Stretch Monitors": "Don't Stretch Monitors", "Force Monitors Per Row": "Force Monitors Per Row", diff --git a/libs/mountManager.js b/libs/mountManager.js index 79fb01d1..236f04d1 100644 --- a/libs/mountManager.js +++ b/libs/mountManager.js @@ -1,6 +1,10 @@ +const path = require('path') module.exports = (s,config,lang,app,io) => { // for unix-based systems only if(s.isWin)return; + const { + modifyConfiguration, + } = require('./system/utils.js')(config) const { createMountPoint, mount, @@ -16,19 +20,7 @@ module.exports = (s,config,lang,app,io) => { */ app.get(config.webPaths.superApiPrefix+':auth/mountManager/list', function (req,res){ s.superAuth(req.params, async (resp) => { - const { - isRestricted, - isRestrictedApiKey, - apiKeyPermissions, - userPermissions, - } = s.checkPermission(user) - if( - isRestrictedApiKey && apiKeyPermissions.edit_mounts_disallowed - ){ - s.closeJsonResponse(res,{ ok: false, mounts: [] }); - return - } - const response = await remountAll(); + const response = await list(); s.closeJsonResponse(res, response); },res,req); }); @@ -38,18 +30,6 @@ module.exports = (s,config,lang,app,io) => { app.post(config.webPaths.superApiPrefix+':auth/mountManager/mount', function (req,res){ s.superAuth(req.params, async (resp) => { const { sourceTarget, localPath, mountType, options } = req.body; - const { - isRestricted, - isRestrictedApiKey, - apiKeyPermissions, - userPermissions, - } = s.checkPermission(user) - if( - isRestrictedApiKey && apiKeyPermissions.edit_mounts_disallowed - ){ - s.closeJsonResponse(res,{ ok: false }); - return - } try{ await createMountPoint(localPath) }catch(err){ @@ -70,18 +50,6 @@ module.exports = (s,config,lang,app,io) => { app.post(config.webPaths.superApiPrefix+':auth/mountManager/removeMount', function (req,res){ s.superAuth(req.params, async (resp) => { const { localPath } = req.body; - const { - isRestricted, - isRestrictedApiKey, - apiKeyPermissions, - userPermissions, - } = s.checkPermission(user) - if( - isRestrictedApiKey && apiKeyPermissions.edit_mounts_disallowed - ){ - s.closeJsonResponse(res,{ ok: false }); - return - } try{ await unmount(localPath) }catch(err){ @@ -91,4 +59,26 @@ module.exports = (s,config,lang,app,io) => { s.closeJsonResponse(res, response); },res,req); }); + /** + * API : Set Mount Point as Videos Directory (videosDir) + */ + app.post(config.webPaths.superApiPrefix+':auth/mountManager/setVideosDir', function (req,res){ + s.superAuth(req.params, async (resp) => { + const { localPath, pathInside } = req.body; + const response = { ok: false } + try{ + const { exists } = await checkDiskPathExists(localPath) + if(exists){ + const newVideosDirPath = pathInside ? path.join(localPath, pathInside) : localPath; + const configError = await modifyConfiguration({ + videosDir: newVideosDirPath, + }, true); + response.ok = true; + } + }catch(err){ + console.error(err) + } + s.closeJsonResponse(res, response); + },res,req); + }); } diff --git a/libs/system/utils.js b/libs/system/utils.js index b6178961..450e1a74 100644 --- a/libs/system/utils.js +++ b/libs/system/utils.js @@ -1,5 +1,8 @@ const fs = require('fs'); const spawn = require('child_process').spawn; +const { + mergeDeep, +} = require('../common.js') module.exports = (config) => { var currentlyUpdating = false return { @@ -33,13 +36,20 @@ module.exports = (config) => { }); }); }, - modifyConfiguration: (postBody) => { + modifyConfiguration: (postBody, useBase) => { return new Promise((resolve, reject) => { console.log(config) - const configPath = config.thisIsDocker ? "/config/conf.json" : s.location.config; - const configData = JSON.stringify(postBody,null,3); - + let configToPost = postBody; + if(useBase){ + try{ + const configBase = s.parseJSON(fs.readFileSync(configPath),{}); + configToPost = mergeDeep(configBase, postBody) + }catch(err){ + console.error('modifyConfiguration : Failed to use Config base!') + } + } + const configData = JSON.stringify(configToPost, null, 3); fs.writeFile(configPath, configData, resolve); }); }, diff --git a/libs/uploaders.js b/libs/uploaders.js index 6a09ab73..723da5c9 100644 --- a/libs/uploaders.js +++ b/libs/uploaders.js @@ -8,6 +8,8 @@ module.exports = function(s,config,lang,app,io){ backblazeB2: require('./uploaders/backblazeB2.js'), amazonS3: require('./uploaders/amazonS3.js'), webdav: require('./uploaders/webdav.js'), + //local storage + mnt: require('./uploaders/mount.js'), //oauth googleDrive: require('./uploaders/googleDrive.js'), //simple storage @@ -15,7 +17,9 @@ module.exports = function(s,config,lang,app,io){ } Object.keys(loadedLibraries).forEach((key) => { var loadedLib = loadedLibraries[key](s,config,lang,app,io) - loadedLib.isFormGroupGroup = true - s.definitions["Account Settings"].blocks["Uploaders"].info.push(loadedLib) + if(loadedLib.info){ + loadedLib.isFormGroupGroup = true + s.definitions["Account Settings"].blocks["Uploaders"].info.push(loadedLib) + } }) } diff --git a/libs/uploaders/mount.js b/libs/uploaders/mount.js index 65684ffb..0919e8d6 100644 --- a/libs/uploaders/mount.js +++ b/libs/uploaders/mount.js @@ -1,16 +1,7 @@ const fs = require('fs').promises; const { createReadStream } = require('fs'); -const path = require('path') +const path = require('path'); const { - createMountPoint, - mount, - update, - remove, - list, - remountAll, - remount, - unmount, - diskUsage, writeReadStream, checkDiskPathExists, } = require('node-fstab'); diff --git a/web/assets/js/super.mountManager.js b/web/assets/js/super.mountManager.js index 7ea5c4b8..5a192528 100644 --- a/web/assets/js/super.mountManager.js +++ b/web/assets/js/super.mountManager.js @@ -12,9 +12,6 @@ $(document).ready(function(){ $.each(data,function(n,theMount){ html += ` - - -
${theMount.device}
${theMount.mountPoint}
@@ -25,6 +22,10 @@ $(document).ready(function(){ ${theMount.options} + + + + ` }) downloadListElement.html(html) @@ -76,6 +77,16 @@ $(document).ready(function(){ }) }) } + function setVideosDir(localPath, pathInside) { + return new Promise((resolve,reject) => { + $.post(superApiPrefix + $user.sessionKey + '/mountManager/removeMount',{ + localPath, + pathInside + },function(data){ + resolve(data) + }) + }) + } newMountForm.submit(async function(e){ e.preventDefault(); const form = newMountForm.serializeObject(); @@ -108,5 +119,36 @@ $(document).ready(function(){ }) } }) + theTable.on('click','.setVideosDir', function(e){ + const el = $(this).parents('[row-mounted]') + const mountId = el.attr('row-mounted'); + const theMount = loadedMounts[mountId] + const localPath = theMount.mountPoint + $.confirm.create({ + title: lang['Set New Videos Directory'], + body: `${lang.restartRequired}

? `, + clickOptions: { + class: 'btn-success', + title: lang.Save, + }, + clickCallback: async function(){ + const pathInside = $('#newVideosDirInnerPath').val().trim(); + const response = await setVideosDir(localPath, pathInside); + if(response.ok){ + new PNotify({ + title: lang['New Videos Directory Set'], + text: lang.restartRequired, + type: 'success' + }) + }else{ + new PNotify({ + title: lang['Action Failed'], + text: lang['See System Logs'], + type: 'danger' + }) + } + } + }) + }) loadMounts() })