Skip to content

Commit 4c5d22f

Browse files
committed
Use / instead of : for path separator (aka, filepath instead of rkey in parameters)
1 parent e4d08aa commit 4c5d22f

File tree

4 files changed

+287
-262
lines changed

4 files changed

+287
-262
lines changed

src/lib/atproto/rkey.ts

+25-1
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,10 @@
1+
import type { ParamValueOneOrMore } from "vue-router";
2+
13
export function filepathToRkey(filepath: string) {
24
if (filepath === '') throw new Error('File path is empty!');
35

6+
if (filepath.includes(':')) throw new Error('`:` character not allowed in file path!');
7+
48
filepath = filepath.replace(/\\/g, '/');
59

610
if (filepath.startsWith('./')) {
@@ -37,6 +41,26 @@ export function rkeyToFilepath(rkey: string) {
3741
return rkey
3842
.replace(/:/g, '/')
3943
.replace(/_([0-9a-z]{1,4})_/g, $$ => {
40-
return String.fromCharCode(parseInt($$.slice(1), 36));
44+
return String.fromCharCode(parseInt($$.slice(1, -1), 36));
4145
});
4246
}
47+
48+
export function filepathToPathParameter(filepath: string): ParamValueOneOrMore<true> {
49+
if (filepath === '') throw new Error('File path is empty!');
50+
51+
filepath = filepath.replace(/\\/g, '/');
52+
53+
if (filepath.startsWith('./')) {
54+
filepath = filepath.slice(2);
55+
}
56+
57+
if (filepath.startsWith('/')) {
58+
filepath = filepath.slice(1);
59+
}
60+
61+
if (filepath.includes('../') || filepath.includes('/..')) {
62+
throw new Error('Backwards directory navigation not supported in rkey');
63+
}
64+
65+
return filepath.split('/') as ParamValueOneOrMore<true>;
66+
}

0 commit comments

Comments
 (0)