fix: restore share url parsing in importer
This commit is contained in:
@@ -836,6 +836,21 @@ function htmlPage(): string {
|
||||
return Number.isNaN(date.getTime()) ? null : date.toISOString();
|
||||
}
|
||||
|
||||
function resolveDavBaseUrl(shareUrlValue) {
|
||||
const url = new URL(shareUrlValue.trim());
|
||||
const publicShare = url.pathname.match(/\\/s\\/([^/?#]+)/);
|
||||
if (publicShare) {
|
||||
return url.origin + "/public.php/dav/files/" + publicShare[1] + "/";
|
||||
}
|
||||
|
||||
const davShare = url.pathname.match(/\\/public\\.php\\/dav\\/files\\/([^/?#]+)\\/?/);
|
||||
if (davShare) {
|
||||
return url.origin + "/public.php/dav/files/" + davShare[1] + "/";
|
||||
}
|
||||
|
||||
throw new Error("Please enter a public Nextcloud share link.");
|
||||
}
|
||||
|
||||
function clamp(value, min, max) {
|
||||
return Math.min(max, Math.max(min, value));
|
||||
}
|
||||
@@ -1502,9 +1517,10 @@ function htmlPage(): string {
|
||||
});
|
||||
}
|
||||
|
||||
async function loadShareListing(davUrl, signal) {
|
||||
async function loadShareListing(shareUrlValue, signal) {
|
||||
const davBaseUrl = resolveDavBaseUrl(shareUrlValue);
|
||||
const response = await fetch(
|
||||
"/api/nextcloud/list?share=" + encodeURIComponent(shareUrl.value.trim()),
|
||||
"/api/nextcloud/list?share=" + encodeURIComponent(shareUrlValue.trim()),
|
||||
{
|
||||
signal
|
||||
}
|
||||
@@ -1514,7 +1530,7 @@ function htmlPage(): string {
|
||||
throw new Error("Could not load the Nextcloud listing: " + response.status);
|
||||
}
|
||||
|
||||
return parseListing(await response.text(), davUrl);
|
||||
return parseListing(await response.text(), davBaseUrl);
|
||||
}
|
||||
|
||||
async function readRemotePhoto(entry, signal) {
|
||||
@@ -1558,8 +1574,7 @@ function htmlPage(): string {
|
||||
clearObjectUrls();
|
||||
clearGallery();
|
||||
updateStatus("Loading share...");
|
||||
const { davUrl } = parseShareInput(shareUrl.value);
|
||||
const listing = await loadShareListing(davUrl, controller.signal);
|
||||
const listing = await loadShareListing(shareUrl.value, controller.signal);
|
||||
|
||||
if (!listing.length) {
|
||||
throw new Error("No images were found in the share.");
|
||||
|
||||
Reference in New Issue
Block a user