parent
cd73c8f82f
commit
808cc5d8d0
@ -24,9 +24,7 @@
|
|||||||
"node": ">=0.12"
|
"node": ">=0.12"
|
||||||
},
|
},
|
||||||
"dependencies": {
|
"dependencies": {
|
||||||
"lodash.filter": "^4.0.1",
|
"lodash": "^4.13.1"
|
||||||
"lodash.map": "^4.0.1",
|
|
||||||
"lodash.trim": "^4.0.1"
|
|
||||||
},
|
},
|
||||||
"devDependencies": {
|
"devDependencies": {
|
||||||
"babel-cli": "^6.3.17",
|
"babel-cli": "^6.3.17",
|
||||||
|
@ -1,6 +1,7 @@
|
|||||||
import filter from 'lodash.filter'
|
import filter from 'lodash/filter'
|
||||||
import map from 'lodash.map'
|
import map from 'lodash/map'
|
||||||
import trim from 'lodash.trim'
|
import trim from 'lodash/trim'
|
||||||
|
import trimStart from 'lodash/trimStart'
|
||||||
|
|
||||||
const sanitizePath = (...paths) => filter(map(paths, s => s && filter(map(s.split('/'), trim)).join('/'))).join('/')
|
const sanitizePath = (...paths) => filter(map(paths, s => s && filter(map(s.split('/'), trim)).join('/'))).join('/')
|
||||||
|
|
||||||
@ -8,7 +9,7 @@ export const parse = (remote) => {
|
|||||||
const [type, rest] = remote.url.split('://')
|
const [type, rest] = remote.url.split('://')
|
||||||
if (type === 'file') {
|
if (type === 'file') {
|
||||||
remote.type = 'local'
|
remote.type = 'local'
|
||||||
remote.path = `/${rest}` // FIXME the heading slash has been forgotten on client side first implementation
|
remote.path = `/${trimStart(rest, '/')}` // the leading slash has been forgotten on client side first implementation
|
||||||
} else if (type === 'nfs') {
|
} else if (type === 'nfs') {
|
||||||
remote.type = 'nfs'
|
remote.type = 'nfs'
|
||||||
const [host, share] = rest.split(':')
|
const [host, share] = rest.split(':')
|
||||||
@ -31,7 +32,8 @@ export const parse = (remote) => {
|
|||||||
}
|
}
|
||||||
|
|
||||||
export const format = ({type, host, path, username, password, domain}) => {
|
export const format = ({type, host, path, username, password, domain}) => {
|
||||||
let url = `${type === 'local' ? 'file' : type}://`
|
type === 'local' && (type = 'file')
|
||||||
|
let url = `${type}://`
|
||||||
if (type === 'nfs') {
|
if (type === 'nfs') {
|
||||||
url += `${host}:`
|
url += `${host}:`
|
||||||
}
|
}
|
||||||
@ -43,7 +45,7 @@ export const format = ({type, host, path, username, password, domain}) => {
|
|||||||
path = path.split('/')
|
path = path.split('/')
|
||||||
path = '\0' + path.join('\\') // FIXME saving with the windows fashion \ was a bad idea :,(
|
path = '\0' + path.join('\\') // FIXME saving with the windows fashion \ was a bad idea :,(
|
||||||
} else {
|
} else {
|
||||||
type === 'smb' && (path = `/${path}`) // FIXME file type should have a / too, but it has been forgotten on client side first implementation...
|
type === 'file' && (path = `/${path}`)
|
||||||
}
|
}
|
||||||
url += path
|
url += path
|
||||||
return url
|
return url
|
||||||
|
@ -8,28 +8,47 @@ import { parse, format } from './'
|
|||||||
|
|
||||||
// ===================================================================
|
// ===================================================================
|
||||||
|
|
||||||
const data = {
|
const FILE_FIXED = {
|
||||||
|
url: 'file:///var/lib/xoa/backup',
|
||||||
|
type: 'local',
|
||||||
|
path: '/var/lib/xoa/backup'
|
||||||
|
}
|
||||||
|
|
||||||
|
const SMB = {
|
||||||
|
url: 'smb://Administrator:password@toto\\\\192.168.100.225\\smb\0',
|
||||||
|
type: 'smb',
|
||||||
|
host: '192.168.100.225\\smb',
|
||||||
|
path: undefined,
|
||||||
|
domain: 'toto',
|
||||||
|
username: 'Administrator',
|
||||||
|
password: 'password'
|
||||||
|
}
|
||||||
|
|
||||||
|
const parseData = {
|
||||||
file: {
|
file: {
|
||||||
url: 'file://var/lib/xoa/backup',
|
url: 'file://var/lib/xoa/backup', // Remotes formatted before fixing #7 will not break when reparses
|
||||||
type: 'local',
|
type: 'local',
|
||||||
path: '/var/lib/xoa/backup'
|
path: '/var/lib/xoa/backup'
|
||||||
},
|
},
|
||||||
smb: {
|
fileFixed: FILE_FIXED,
|
||||||
url: 'smb://Administrator:password@toto\\\\192.168.100.225\\smb\0',
|
smb: SMB
|
||||||
type: 'smb',
|
}
|
||||||
host: '192.168.100.225\\smb',
|
|
||||||
path: undefined,
|
const formatData = {
|
||||||
domain: 'toto',
|
file: {
|
||||||
username: 'Administrator',
|
url: 'file:///var/lib/xoa/backup',
|
||||||
password: 'password'
|
type: 'local',
|
||||||
}
|
path: '/var/lib/xoa/backup'
|
||||||
|
},
|
||||||
|
fileFixed: FILE_FIXED,
|
||||||
|
smb: SMB
|
||||||
}
|
}
|
||||||
|
|
||||||
// -------------------------------------------------------------------
|
// -------------------------------------------------------------------
|
||||||
|
|
||||||
describe('format', () => {
|
describe('format', () => {
|
||||||
for (const name in data) {
|
for (const name in formatData) {
|
||||||
const datum = data[name]
|
const datum = formatData[name]
|
||||||
it(name, () => {
|
it(name, () => {
|
||||||
expect(format(datum)).to.equal(datum.url)
|
expect(format(datum)).to.equal(datum.url)
|
||||||
})
|
})
|
||||||
@ -37,8 +56,8 @@ describe('format', () => {
|
|||||||
})
|
})
|
||||||
|
|
||||||
describe('parse', () => {
|
describe('parse', () => {
|
||||||
for (const name in data) {
|
for (const name in parseData) {
|
||||||
const datum = data[name]
|
const datum = parseData[name]
|
||||||
it(name, () => {
|
it(name, () => {
|
||||||
expect(parse(datum)).to.eql(datum)
|
expect(parse(datum)).to.eql(datum)
|
||||||
})
|
})
|
||||||
|
Loading…
Reference in New Issue
Block a user