mirror of
https://github.com/Ylianst/MeshCentral.git
synced 2025-02-14 12:01:52 +00:00
fix-webdav-upload
This commit is contained in:
parent
b1d2d1aea9
commit
f297857d70
1 changed files with 25 additions and 27 deletions
52
db.js
52
db.js
|
@ -3064,39 +3064,37 @@ module.exports.CreateDB = function (parent, func) {
|
||||||
|
|
||||||
// Upload to the WebDAV folder
|
// Upload to the WebDAV folder
|
||||||
function performWebDavUpload(client, filepath) {
|
function performWebDavUpload(client, filepath) {
|
||||||
var fileStream = require('fs').createReadStream(filepath);
|
require('fs').stat(filepath, function(err,stat){
|
||||||
fileStream.on('close', function () { if (func) { func('WebDAV upload completed'); } })
|
var fileStream = require('fs').createReadStream(filepath);
|
||||||
fileStream.on('error', function (err) { if (func) { func('WebDAV (fileUpload) error: ' + err); } })
|
fileStream.on('close', function () { if (func) { func('WebDAV upload completed'); } })
|
||||||
fileStream.pipe(client.createWriteStream('/' + webdavfolderName + '/' + require('path').basename(filepath)));
|
fileStream.on('error', function (err) { if (func) { func('WebDAV (fileUpload) error: ' + err); } })
|
||||||
if (func) { func('Uploading using WebDAV...'); }
|
fileStream.pipe(client.createWriteStream('/' + webdavfolderName + '/' + require('path').basename(filepath), { headers: { "Content-Length": stat.size } }));
|
||||||
|
if (func) { func('Uploading using WebDAV...'); }
|
||||||
|
});
|
||||||
}
|
}
|
||||||
|
|
||||||
if (func) { func('Attempting WebDAV upload...'); }
|
if (func) { func('Attempting WebDAV upload...'); }
|
||||||
const { createClient } = require('webdav');
|
const { createClient } = require('webdav');
|
||||||
const client = createClient(parent.config.settings.autobackup.webdav.url, { username: parent.config.settings.autobackup.webdav.username, password: parent.config.settings.autobackup.webdav.password });
|
const client = createClient(parent.config.settings.autobackup.webdav.url, {
|
||||||
var directoryItems = client.getDirectoryContents('/');
|
username: parent.config.settings.autobackup.webdav.username,
|
||||||
directoryItems.then(
|
password: parent.config.settings.autobackup.webdav.password,
|
||||||
function (files) {
|
maxContentLength: Infinity,
|
||||||
var folderFound = false;
|
maxBodyLength: Infinity
|
||||||
for (var i in files) { if ((files[i].basename == webdavfolderName) && (files[i].type == 'directory')) { folderFound = true; } }
|
});
|
||||||
if (folderFound == false) {
|
client.exists(webdavfolderName).then(function(a){
|
||||||
client.createDirectory(webdavfolderName).then(function (a) {
|
if(a){
|
||||||
if (a.statusText == 'Created') {
|
performWebDavCleanup(client);
|
||||||
if (func) { func('WebDAV folder created'); }
|
performWebDavUpload(client, filename);
|
||||||
performWebDavUpload(client, filename);
|
}else{
|
||||||
} else {
|
client.createDirectory(webdavfolderName, {recursive: true}).then(function (a) {
|
||||||
if (func) { func('WebDAV (createDirectory) status: ' + a.statusText); }
|
if (func) { func('WebDAV folder created'); }
|
||||||
}
|
|
||||||
}).catch(function (err) {
|
|
||||||
if (func) { func('WebDAV (createDirectory) error: ' + err); }
|
|
||||||
});
|
|
||||||
} else {
|
|
||||||
performWebDavCleanup(client);
|
|
||||||
performWebDavUpload(client, filename);
|
performWebDavUpload(client, filename);
|
||||||
}
|
}).catch(function (err) {
|
||||||
|
if (func) { func('WebDAV (createDirectory) error: ' + err); }
|
||||||
|
});
|
||||||
}
|
}
|
||||||
).catch(function (err) {
|
}).catch(function (err) {
|
||||||
if (func) { func('WebDAV (getDirectoryContents) error: ' + err); }
|
if (func) { func('WebDAV (exists) error: ' + err); }
|
||||||
});
|
});
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
Loading…
Reference in a new issue