diff options
author | Azul <azul@riseup.net> | 2020-06-18 11:55:53 +0300 |
---|---|---|
committer | Azul <azul@riseup.net> | 2020-08-11 16:44:33 +0300 |
commit | 611b799b81773cb53ce467eb0f8baa2b2dfb3778 (patch) | |
tree | 5d5eedebc8e4c0fb6738378ff0e36ebc9aebe698 /src | |
parent | a188b74d3c11a0f10b16253d90a578787b30139c (diff) |
links with complete urls
This way they also work if the viewer was opened from other apps
than the file app.
Also move the `relPath` param into the fragment.
It is only used to remember the relative path
for generating the short markdown form from the link.
Signed-off-by: Azul <azul@riseup.net>
Diffstat (limited to 'src')
-rw-r--r-- | src/helpers/links.js | 6 | ||||
-rw-r--r-- | src/tests/helpers/links.spec.js | 12 |
2 files changed, 11 insertions, 7 deletions
diff --git a/src/helpers/links.js b/src/helpers/links.js index 9da27351f..8120e1cdd 100644 --- a/src/helpers/links.js +++ b/src/helpers/links.js @@ -20,6 +20,8 @@ * */ +import { generateUrl } from '@nextcloud/router' + const absolutePath = function(base, rel) { if (!rel) { return base @@ -59,7 +61,7 @@ const domHref = function(node) { const currentDir = OC.Util.History.parseUrlQuery().dir || basedir(OCA.Viewer.state.file) const dir = absolutePath(currentDir, basedir(relPath)) - return `?dir=${dir}&openfile=${id}&relPath=${relPath}` + return generateUrl(`/apps/files/?dir=${dir}&openfile=${id}#relPath=${relPath}`) } } @@ -68,7 +70,7 @@ const parseHref = function(dom) { if (!ref) { return ref } - const match = ref.match(/^\?dir=([^&]*)&openfile=([^&]*)&relPath=([^&]*)/) + const match = ref.match(/\?dir=([^&]*)&openfile=([^&]*)#relPath=([^&]*)/) if (match) { const [, , id, path] = match return `${path}?fileId=${id}` diff --git a/src/tests/helpers/links.spec.js b/src/tests/helpers/links.spec.js index ece8dd715..a72072fd9 100644 --- a/src/tests/helpers/links.spec.js +++ b/src/tests/helpers/links.spec.js @@ -8,6 +8,8 @@ global.OC = { }), }, }, + config: {modRewriteWorking: true}, + webroot: '' } describe('Preparing href attributes for the DOM', () => { @@ -32,22 +34,22 @@ describe('Preparing href attributes for the DOM', () => { test('relative link with fileid', () => { expect(domHref({attrs: {href: 'otherfile?fileId=123'}})) - .toBe('?dir=/Wiki&openfile=123&relPath=otherfile') + .toBe('/apps/files/?dir=/Wiki&openfile=123#relPath=otherfile') }) test('relative path with ../', () => { expect(domHref({attrs: {href: '../other/otherfile?fileId=123'}})) - .toBe('?dir=/other&openfile=123&relPath=../other/otherfile') + .toBe('/apps/files/?dir=/other&openfile=123#relPath=../other/otherfile') }) test('absolute path', () => { expect(domHref({attrs: {href: '/other/otherfile?fileId=123'}})) - .toBe('?dir=/other&openfile=123&relPath=/other/otherfile') + .toBe('/apps/files/?dir=/other&openfile=123#relPath=/other/otherfile') }) test('absolute path', () => { expect(domHref({attrs: {href: '/otherfile?fileId=123'}})) - .toBe('?dir=/&openfile=123&relPath=/otherfile') + .toBe('/apps/files/?dir=/&openfile=123#relPath=/otherfile') }) }) @@ -69,7 +71,7 @@ describe('Extracting short urls from the DOM', () => { }) test('relative link with fileid', () => { - expect(parseHref(domStub('?dir=/other&openfile=123&relPath=../other/otherfile'))) + expect(parseHref(domStub('?dir=/other&openfile=123#relPath=../other/otherfile'))) .toBe('../other/otherfile?fileId=123') }) |