Skip to content

Commit

Permalink
Cover all other possible URLs
Browse files Browse the repository at this point in the history
  • Loading branch information
DmitrySharabin committed Nov 1, 2023
1 parent 9ef9ded commit 0c00b2b
Show file tree
Hide file tree
Showing 3 changed files with 43 additions and 5 deletions.
1 change: 1 addition & 0 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -22,6 +22,7 @@ Done!
- `https://disk.yandex.com/d/ahNF6_YRiAkeZA`—public (shared) file
- `https://disk.yandex.com/d/RJJgoQNFJlWO9Q/baz.json`—file in a public (shared) folder
- `https://disk.yandex.com/d/RJJgoQNFJlWO9Q/foo/bar/baz.json`—file in a subfolder of a public folder
- `https://disk.yandex.com/d/RJJgoQNFJlWO9Q/foo/bar`—file named `APP_ID.json` (where `APP_ID` is the name of your app) in a subfolder of a public folder

**Note:** URLs starting with `https://disk.yandex.ru` are also supported.

Expand Down
15 changes: 13 additions & 2 deletions mavo-yandex.js
Original file line number Diff line number Diff line change
Expand Up @@ -243,11 +243,22 @@ const _ = Mavo.Backend.register(
ret.filename = lastSegment;
path.splice(path.length - 1, 1);
}

if (!ret.filename) {
ret.filepath = path.join("/") || (isPublic? "" : defaults.filepath);
}
else {
ret.filename = !isPublic? defaults.filename : "";
ret.filepath = path.join("/") || "";
}

ret.filepath = path.join("/") || (!isPublic? defaults.filepath : "");
if (!ret.filename) {
if (ret.filepath) {
ret.filename = defaults.filename;
}
else {
ret.filename = isPublic? "" : defaults.filename;
}
}

if (isPublic) {
ret.publicKey = ret.rootPath;
Expand Down
32 changes: 29 additions & 3 deletions test.html
Original file line number Diff line number Diff line change
Expand Up @@ -40,6 +40,17 @@ <h1>parseURL</h1>
</td>
</tr>

<tr title="Default filename">
<td>https://disk.yandex.com/client/disk/foo/bar</td>
<td>{
path: "foo/bar/countries.json",
rootPath: "https://disk.yandex.com/client/disk",
filename: "countries.json",
filepath: "foo/bar"
}
</td>
</tr>

<tr title="Private file in the root">
<td>https://disk.yandex.com/client/disk/baz.json</td>
<td>{
Expand Down Expand Up @@ -68,7 +79,8 @@ <h1>parseURL</h1>
path: "",
rootPath: "https://disk.yandex.com/d/ahNF6_YRiAkeZA",
filename: "",
filepath: ""
filepath: "",
publicKey: "https://disk.yandex.com/d/ahNF6_YRiAkeZA"
}
</td>
</tr>
Expand All @@ -79,7 +91,8 @@ <h1>parseURL</h1>
path: "baz.json",
rootPath: "https://disk.yandex.com/d/RJJgoQNFJlWO9Q",
filename: "baz.json",
filepath: ""
filepath: "",
publicKey: "https://disk.yandex.com/d/RJJgoQNFJlWO9Q"
}
</td>
</tr>
Expand All @@ -90,7 +103,20 @@ <h1>parseURL</h1>
path: "foo/bar/baz.json",
rootPath: "https://disk.yandex.com/d/RJJgoQNFJlWO9Q",
filename: "baz.json",
filepath: "foo/bar"
filepath: "foo/bar",
publicKey: "https://disk.yandex.com/d/RJJgoQNFJlWO9Q"
}
</td>
</tr>

<tr title="File with the default name in a subfolder of a public folder">
<td>https://disk.yandex.com/d/RJJgoQNFJlWO9Q/foo/bar</td>
<td>{
path: "foo/bar/countries.json",
rootPath: "https://disk.yandex.com/d/RJJgoQNFJlWO9Q",
filename: "countries.json",
filepath: "foo/bar",
publicKey: "https://disk.yandex.com/d/RJJgoQNFJlWO9Q"
}
</td>
</tr>
Expand Down

0 comments on commit 0c00b2b

Please sign in to comment.