Skip to content

Commit

Permalink
feat: rename dir if exists on create
Browse files Browse the repository at this point in the history
  • Loading branch information
Dwynr committed Sep 13, 2024
1 parent 8afe943 commit 1377026
Show file tree
Hide file tree
Showing 7 changed files with 68 additions and 15 deletions.
18 changes: 15 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.

18 changes: 15 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.

12 changes: 9 additions & 3 deletions dist/types/cloud/index.d.ts
Original file line number Diff line number Diff line change
Expand Up @@ -345,20 +345,26 @@ export declare class Cloud {
}): Promise<void>;
/**
* Create a directory under parent.
* @date 2/15/2024 - 2:27:36 AM
*
* @public
* @async
* @param {{ uuid?: string; name: string; parent: string }} param0
* @param {{
* uuid?: string
* name: string
* parent: string
* renameIfExists?: boolean
* }} param0
* @param {string} param0.uuid
* @param {string} param0.name
* @param {string} param0.parent
* @param {boolean} [param0.renameIfExists=false]
* @returns {Promise<string>}
*/
createDirectory({ uuid, name, parent }: {
createDirectory({ uuid, name, parent, renameIfExists }: {
uuid?: string;
name: string;
parent: string;
renameIfExists?: boolean;
}): Promise<string>;
/**
* Change the color of a directory.
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.166",
"version": "0.1.167",
"description": "Filen SDK",
"main": "dist/node/index.js",
"browser": "dist/browser/index.js",
Expand Down
29 changes: 26 additions & 3 deletions src/cloud/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -1153,17 +1153,32 @@ export class Cloud {

/**
* Create a directory under parent.
* @date 2/15/2024 - 2:27:36 AM
*
* @public
* @async
* @param {{ uuid?: string; name: string; parent: string }} param0
* @param {{
* uuid?: string
* name: string
* parent: string
* renameIfExists?: boolean
* }} param0
* @param {string} param0.uuid
* @param {string} param0.name
* @param {string} param0.parent
* @param {boolean} [param0.renameIfExists=false]
* @returns {Promise<string>}
*/
public async createDirectory({ uuid, name, parent }: { uuid?: string; name: string; parent: string }): Promise<string> {
public async createDirectory({
uuid,
name,
parent,
renameIfExists = false
}: {
uuid?: string
name: string
parent: string
renameIfExists?: boolean
}): Promise<string> {
await this._semaphores.createDirectory.acquire()

try {
Expand All @@ -1172,6 +1187,14 @@ export class Cloud {

if (exists.exists) {
uuidToUse = exists.uuid

if (renameIfExists) {
await this.renameDirectory({
uuid: uuidToUse,
name,
overwriteIfExists: false
})
}
} else {
const [metadataEncrypted, nameHashed] = await Promise.all([
this.crypto.encrypt().metadata({ metadata: JSON.stringify({ name }) }),
Expand Down

0 comments on commit 1377026

Please sign in to comment.