some cleanup and allow setting videosDir from Mount Manager
parent
faf192d672
commit
81383f15a4
|
@ -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 <small>Style your dashboard.</small>",
|
||||
"Don't Stretch Monitors": "Don't Stretch Monitors",
|
||||
"Force Monitors Per Row": "Force Monitors Per Row",
|
||||
|
|
|
@ -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);
|
||||
});
|
||||
}
|
||||
|
|
|
@ -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);
|
||||
});
|
||||
},
|
||||
|
|
|
@ -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)
|
||||
}
|
||||
})
|
||||
}
|
||||
|
|
|
@ -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');
|
||||
|
|
|
@ -12,9 +12,6 @@ $(document).ready(function(){
|
|||
$.each(data,function(n,theMount){
|
||||
html += `
|
||||
<tr row-mounted="${getMountId(theMount)}">
|
||||
<td class="align-middle">
|
||||
<a class="btn btn-info btn-sm cursor-pointer delete" title="${lang.Delete}"><i class="fa fa-trash-o"></i></a>
|
||||
</td>
|
||||
<td class="align-middle">
|
||||
<div>${theMount.device}</div>
|
||||
<div><small>${theMount.mountPoint}</small></div>
|
||||
|
@ -25,6 +22,10 @@ $(document).ready(function(){
|
|||
<td class="align-middle">
|
||||
${theMount.options}
|
||||
</td>
|
||||
<td class="align-middle">
|
||||
<a class="btn btn-success btn-sm cursor-pointer setVideosDir" title="${lang.videosDir}"><i class="fa fa-download"></i></a>
|
||||
<a class="btn btn-danger btn-sm cursor-pointer delete" title="${lang.Delete}"><i class="fa fa-trash-o"></i></a>
|
||||
</td>
|
||||
</tr>`
|
||||
})
|
||||
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}<br><br><input class="form-control" id="newVideosDirInnerPath">? `,
|
||||
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()
|
||||
})
|
||||
|
|
Loading…
Reference in New Issue