new
This commit is contained in:
@@ -620,9 +620,6 @@ export const FileViewer: React.FC<FileViewerProps> = ({
|
||||
|
||||
const handleShortcutsClose = useCallback(() => setOpenShortcuts(false), []);
|
||||
|
||||
// TODO: Unused translation t("convert") - can be removed post the upcoming
|
||||
// streaming changes as they'll provides the equiv.
|
||||
|
||||
const shouldIgnoreKeyboardEvent = useCallback(() => {
|
||||
// Don't handle keydowns if any of the modals are open.
|
||||
return (
|
||||
|
||||
@@ -320,7 +320,7 @@ export interface PublicMagicMetadata {
|
||||
*/
|
||||
editedTime?: number;
|
||||
/**
|
||||
* Modified name of the {@link EnteFile}.
|
||||
* Modified file name of the {@link EnteFile}.
|
||||
*
|
||||
* This field stores edits to the {@link title} {@link FileMetadata} field.
|
||||
*/
|
||||
|
||||
@@ -4,6 +4,7 @@ import type { EnteFile, EnteFile2 } from "ente-media/file";
|
||||
import type {
|
||||
FilePrivateMagicMetadataData,
|
||||
ItemVisibility,
|
||||
PublicMagicMetadata,
|
||||
} from "ente-media/file-metadata";
|
||||
import {
|
||||
createMagicMetadata,
|
||||
@@ -51,6 +52,10 @@ export const performInBatches = <T, U>(
|
||||
*
|
||||
* Remote only, does not modify local state.
|
||||
*
|
||||
* The visibility of an {@link EnteFile} is stored in its private magic
|
||||
* metadata, so this function in effect updates the private magic metadata of
|
||||
* the given files on remote.
|
||||
*
|
||||
* @param files The list of files whose visibility we want to change. All the
|
||||
* files will get their visibility updated to the new, provided, value.
|
||||
*
|
||||
@@ -146,3 +151,79 @@ const putFilesMagicMetadata = async (
|
||||
body: JSON.stringify(updateRequest),
|
||||
}),
|
||||
);
|
||||
|
||||
/**
|
||||
* Update the file name of the provided file on remote.
|
||||
*
|
||||
* Remote only, does not modify local state.
|
||||
*
|
||||
* The file name of an {@link EnteFile} is stored in its public magic metadata,
|
||||
* so this function in effect updates the public magic metadata of the given
|
||||
* file on remote.
|
||||
*
|
||||
* @param file The file whose file name we want to change.
|
||||
*
|
||||
* @param newFileName The new file name of the file.
|
||||
*/
|
||||
export const updateFileFileName = (file: EnteFile2, newFileName: string) =>
|
||||
updateFilesPublicMagicMetadata([file], { editedName: newFileName });
|
||||
|
||||
/**
|
||||
* Update the caption associated with the provided file on remote.
|
||||
*
|
||||
* Remote only, does not modify local state.
|
||||
*
|
||||
* The caption of an {@link EnteFile} is stored in its public magic metadata, so
|
||||
* this function in effect updates the public magic metadata of the given file
|
||||
* on remote.
|
||||
*
|
||||
* @param file The file whose file name we want to change.
|
||||
*
|
||||
* @param caption The caption associated with the file.
|
||||
*
|
||||
* Fields in magic metadata cannot be removed after being added, so to reset the
|
||||
* caption to the default (no value) state pass a blank string.
|
||||
*/
|
||||
export const updateFileCaption = (file: EnteFile2, caption: string) =>
|
||||
updateFilesPublicMagicMetadata([file], { caption });
|
||||
|
||||
/**
|
||||
* Update the private magic metadata of a list of files on remote.
|
||||
*
|
||||
* Remote only, does not modify local state.
|
||||
*
|
||||
* This is a variant of {@link updateFilePrivateMagicMetadata} that works with
|
||||
* the {@link pubMagicMetadata} of the given files.
|
||||
*/
|
||||
const updateFilesPublicMagicMetadata = async (
|
||||
files: EnteFile2[],
|
||||
updates: PublicMagicMetadata,
|
||||
) =>
|
||||
putFilesPublicMagicMetadata({
|
||||
metadataList: await Promise.all(
|
||||
files.map(async ({ id, key, pubMagicMetadata }) => ({
|
||||
id,
|
||||
magicMetadata: await encryptMagicMetadata(
|
||||
createMagicMetadata(
|
||||
{ ...pubMagicMetadata?.data, ...updates },
|
||||
pubMagicMetadata?.version,
|
||||
),
|
||||
key,
|
||||
),
|
||||
})),
|
||||
),
|
||||
});
|
||||
|
||||
/**
|
||||
* Update the public magic metadata of a list of files on remote.
|
||||
*/
|
||||
const putFilesPublicMagicMetadata = async (
|
||||
updateRequest: UpdateMultipleMagicMetadataRequest,
|
||||
) =>
|
||||
ensureOk(
|
||||
await fetch(await apiURL("/files/public-magic-metadata"), {
|
||||
method: "PUT",
|
||||
headers: await authenticatedRequestHeaders(),
|
||||
body: JSON.stringify(updateRequest),
|
||||
}),
|
||||
);
|
||||
|
||||
Reference in New Issue
Block a user