The communications platform that puts data protection first.
You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.
 
 
 
 
 
Rocket.Chat/app/webdav/server/methods/getFileFromWebdav.js

35 lines
1.1 KiB

import { Meteor } from 'meteor/meteor';
import { createClient } from 'webdav';
import { settings } from '../../../settings';
import { WebdavAccounts } from '../../../models';
Meteor.methods({
async getFileFromWebdav(accountId, file) {
if (!Meteor.userId()) {
throw new Meteor.Error('error-invalid-user', 'Invalid User', { method: 'addNewWebdavAccount' });
}
if (!settings.get('Webdav_Integration_Enabled')) {
throw new Meteor.Error('error-not-allowed', 'WebDAV Integration Not Allowed', { method: 'addNewWebdavAccount' });
}
const account = WebdavAccounts.findOne({ _id: accountId, user_id: Meteor.userId() });
if (!account) {
throw new Meteor.Error('error-invalid-account', 'Invalid WebDAV Account', { method: 'addNewWebdavAccount' });
}
const client = createClient(
account.server_url,
{
username: account.username,
password: account.password,
}
);
try {
const fileContent = await client.getFileContents(file.filename);
const data = new Uint8Array(fileContent);
return { success: true, data };
} catch (error) {
return { success: false, data: error };
}
},
});