Skip to content

Commit

Permalink
fix: update lastModified timestamp on file version restore
Browse files Browse the repository at this point in the history
  • Loading branch information
Dwynr committed Nov 23, 2024
1 parent 99d3a3f commit e50db52
Show file tree
Hide file tree
Showing 7 changed files with 215 additions and 12 deletions.
68 changes: 65 additions & 3 deletions dist/browser/cloud/index.js

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

2 changes: 1 addition & 1 deletion dist/browser/cloud/index.js.map

Large diffs are not rendered by default.

65 changes: 62 additions & 3 deletions dist/node/cloud/index.js

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

2 changes: 1 addition & 1 deletion dist/node/cloud/index.js.map

Large diffs are not rendered by default.

14 changes: 14 additions & 0 deletions dist/types/cloud/index.d.ts
Original file line number Diff line number Diff line change
Expand Up @@ -225,6 +225,20 @@ export declare class Cloud {
name: string;
parent: string;
}): Promise<DirExistsResponse>;
/**
* Edit metadata of a file (currently uses the rename endpoint, might change later).
*
* @public
* @async
* @param {{ uuid: string; metadata: FileMetadata }} param0
* @param {string} param0.uuid
* @param {FileMetadata} param0.metadata
* @returns {Promise<void>}
*/
editFileMetadata({ uuid, metadata }: {
uuid: string;
metadata: FileMetadata;
}): Promise<void>;
/**
* Rename a file.
*
Expand Down
2 changes: 1 addition & 1 deletion package.json
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
{
"name": "@filen/sdk",
"version": "0.1.182",
"version": "0.1.183",
"description": "Filen SDK",
"main": "dist/node/index.js",
"browser": "dist/browser/index.js",
Expand Down
74 changes: 71 additions & 3 deletions src/cloud/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -847,6 +847,49 @@ export class Cloud {
return exists
}

/**
* Edit metadata of a file (currently uses the rename endpoint, might change later).
*
* @public
* @async
* @param {{ uuid: string; metadata: FileMetadata }} param0
* @param {string} param0.uuid
* @param {FileMetadata} param0.metadata
* @returns {Promise<void>}
*/
public async editFileMetadata({ uuid, metadata }: { uuid: string; metadata: FileMetadata }): Promise<void> {
const [nameHashed, metadataEncrypted, nameEncrypted] = await Promise.all([
this.sdk.getWorker().crypto.utils.hashFn({ input: metadata.name.toLowerCase() }),
this.sdk.getWorker().crypto.encrypt.metadata({
metadata: JSON.stringify(metadata)
}),
this.sdk.getWorker().crypto.encrypt.metadata({
metadata: metadata.name,
key: metadata.key
})
])

try {
await this.api.v3().file().rename({
uuid,
metadataEncrypted,
nameEncrypted,
nameHashed
})
} catch (e) {
if (e instanceof APIError) {
if (e.code === "file_not_found") {
return
}
}
}

await this.checkIfItemIsSharedForRename({
uuid,
itemMetadata: metadata
})
}

/**
* Rename a file.
*
Expand Down Expand Up @@ -1330,7 +1373,20 @@ export class Cloud {
* @returns {Promise<void>}
*/
public async restoreFileVersion({ uuid, currentUUID }: { uuid: string; currentUUID: string }): Promise<void> {
await this.api.v3().file().version().restore({ uuid, currentUUID })
const currentFile = await this.getFile({ uuid: currentUUID })

await this.api.v3().file().version().restore({
uuid,
currentUUID
})

await this.editFileMetadata({
uuid,
metadata: {
...currentFile.metadataDecrypted,
lastModified: Date.now()
}
})
}

/**
Expand Down Expand Up @@ -2467,14 +2523,26 @@ export class Cloud {

if (isSharingItem.sharing) {
for (const user of isSharingItem.users) {
promises.push(this.renameSharedItem({ uuid, receiverId: user.id, metadata: itemMetadata, publicKey: user.publicKey }))
promises.push(
this.renameSharedItem({
uuid,
receiverId: user.id,
metadata: itemMetadata,
publicKey: user.publicKey
})
)
}
}

if (isLinkingItem.link) {
for (const link of isLinkingItem.links) {
promises.push(
this.renamePubliclyLinkedItem({ uuid, linkUUID: link.linkUUID, metadata: itemMetadata, linkKeyEncrypted: link.linkKey })
this.renamePubliclyLinkedItem({
uuid,
linkUUID: link.linkUUID,
metadata: itemMetadata,
linkKeyEncrypted: link.linkKey
})
)
}
}
Expand Down

0 comments on commit e50db52

Please sign in to comment.