This commit is contained in:
Manav Rathi
2025-06-06 18:42:31 +05:30
parent ebf6c15655
commit ca748f731e
3 changed files with 19 additions and 24 deletions

View File

@@ -54,6 +54,7 @@ import type {
import { type CollectionUser } from "ente-media/collection";
import { PublicLinkCreated } from "ente-new/photos/components/share/PublicLinkCreated";
import { avatarTextColor } from "ente-new/photos/services/avatar";
import { deleteShareURL } from "ente-new/photos/services/collection";
import type { CollectionSummary } from "ente-new/photos/services/collection/ui";
import { usePhotosAppContext } from "ente-new/photos/types/context";
import { CustomError, parseSharingErrorCodes } from "ente-shared/error";
@@ -65,7 +66,6 @@ import React, { useContext, useEffect, useMemo, useRef, useState } from "react";
import { Trans } from "react-i18next";
import {
createShareableURL,
deleteShareableURL,
shareCollection,
unshareCollection,
updateShareableURL,
@@ -1222,16 +1222,16 @@ const ManagePublicShareOptions: React.FC<ManagePublicShareOptionsProps> = ({
galleryContext.setBlockingLoad(false);
}
};
const disablePublicSharing = async () => {
const handleRemovePublicLink = async () => {
try {
galleryContext.setBlockingLoad(true);
await deleteShareableURL(collection);
await deleteShareURL(collection.id);
setPublicShareProp(null);
galleryContext.syncWithRemote(false, true);
onClose();
} catch (e) {
const errorMessage = handleSharingErrors(e);
setSharableLinkError(errorMessage);
log.error("Failed to remove public link", e);
setSharableLinkError(t("generic_error"));
} finally {
galleryContext.setBlockingLoad(false);
}
@@ -1293,7 +1293,7 @@ const ManagePublicShareOptions: React.FC<ManagePublicShareOptionsProps> = ({
<RowButton
color="critical"
startIcon={<RemoveCircleOutlineIcon />}
onClick={disablePublicSharing}
onClick={handleRemovePublicLink}
label={t("remove_link")}
/>
</RowButtonGroup>

View File

@@ -571,24 +571,6 @@ export const createShareableURL = async (collection: Collection) => {
}
};
export const deleteShareableURL = async (collection: Collection) => {
try {
const token = getToken();
if (!token) {
return null;
}
await HTTPService.delete(
await apiURL(`/collections/share-url/${collection.id}`),
null,
null,
{ "X-Auth-Token": token },
);
} catch (e) {
log.error("deleteShareableURL failed ", e);
throw e;
}
};
export const updateShareableURL = async (
request: UpdatePublicURL,
): Promise<PublicURL> => {

View File

@@ -263,3 +263,16 @@ export const deleteFromTrash = async (fileIDs: number[]) => {
);
}
};
/**
* Delete the public link for the collection with given {@link collectionID}.
*
* Does not modify local state.
*/
export const deleteShareURL = async (collectionID: number) =>
ensureOk(
await fetch(await apiURL(`/collections/share-url/${collectionID}`), {
method: "DELETE",
headers: await authenticatedRequestHeaders(),
}),
);