This commit is contained in:
Manav Rathi
2025-06-13 12:19:12 +05:30
parent cf424e59f6
commit 3ee741abbb

View File

@@ -371,6 +371,49 @@ export const deleteFromTrash = async (fileIDs: number[]) => {
}
};
/**
* Rename a collection on remote.
*
* Remote only, does not modify local state.
*
* @param collection The collection to rename.
*
* @param newName The new name of the collection
*/
export const renameCollection = async (
collection: Collection2,
newName: string,
) => {
if (collection.magicMetadata?.data.subType == CollectionSubType.quicklink) {
// Convert quicklinks to a regular collection before giving them a name.
await updateCollectionPrivateMagicMetadata(collection, {
subType: CollectionSubType.default,
});
}
const { encryptedData: encryptedName, nonce: nameDecryptionNonce } =
await encryptBox(new TextEncoder().encode(newName), collection.key);
await postCollectionsRename({
collectionID: collection.id,
encryptedName,
nameDecryptionNonce,
});
};
interface RenameRequest {
collectionID: number;
encryptedName: string;
nameDecryptionNonce: string;
}
const postCollectionsRename = async (renameRequest: RenameRequest) =>
ensureOk(
await fetch(await apiURL("/collections/rename"), {
method: "POST",
headers: await authenticatedRequestHeaders(),
body: JSON.stringify(renameRequest),
}),
);
/**
* Update the private magic metadata contents of a collection on remote.
*