Git Product home page Git Product logo

Comments (11)

gpailler avatar gpailler commented on August 13, 2024

Well Mega API allows to create nodes with same name. We can change CreateFolder method to throw if we try to create a folder with a name that already exist but it's a shame to introduce this kind of limitation.
I think it's client side responsibility to get the folder node or create it if it doesn't exist.

Another solution is to add a method GetOrCreateFolder but if there is already 2 folders with the same name, the method is unable to choose and will throw.

What do you think?

from megaapiclient.

mrjohnr avatar mrjohnr commented on August 13, 2024

Hi! I think it is very ambiguous to have 2 or more folders/files with the same name GetOrCreateFolder will be fine for me but not for others
You can give me some steps to implement that:create folder if it not exists or else to select the folder

another question : do I need to distribute Newtonsoft.Json.dll ?

thanks!

from megaapiclient.

gpailler avatar gpailler commented on August 13, 2024

I don't know VB but something like that should work:

Dim myFolder As INode = client.nodes.[FirstOrDefault](Function(n) n.Type = NodeType.Folder And n.Name = "Upload")
If myFolder = Nothing then
    myFolder = client.CreateFolder("Upload", root)
End If

About Newtonsoft.Json.dll, you must distribute it with MegaApiClient

from megaapiclient.

mrjohnr avatar mrjohnr commented on August 13, 2024

good,it works with some little corrections:
Dim myFolder As INode = nodes.[FirstOrDefault](Function(n) n.Type = NodeType.Directory And n.Name = "upload") If myFolder Is Nothing Then myFolder = client.CreateFolder("upload", root) End If

thanks!

from megaapiclient.

gpailler avatar gpailler commented on August 13, 2024

Ok my skill in VB is not so good ;-)

from megaapiclient.

0x001R avatar 0x001R commented on August 13, 2024

Any solution for C# on this?

from megaapiclient.

gpailler avatar gpailler commented on August 13, 2024

To create a folder on root if it doesn't exist:

var nodes = client.GetNodes(); // Retrieve all folders and files
var root = nodes.Single(n => n.Type == NodeType.Root); // Retrieve root node

// Search a folder with "folder" name under root
var myFolder = client.GetNodes(root).FirstOrDefault(n => n.Type == NodeType.Folder && n.Name == "folder");

// Create the "folder" if not found
if (myFolder == null)
{
  myFolder = client.CreateFolder("folder", root);
}

from megaapiclient.

0x001R avatar 0x001R commented on August 13, 2024

Thank you very much!

from megaapiclient.

rigorvzla avatar rigorvzla commented on August 13, 2024

wow man is magnific , thanks

from megaapiclient.

samuel0l0y avatar samuel0l0y commented on August 13, 2024

I think you should make it a Boolean parameter to the CreateFolder() function.

from megaapiclient.

gpailler avatar gpailler commented on August 13, 2024

I prefer to avoid having this kind of flag because I don't want to have to download all the nodes for this check in the CreateFolder() method. MegaApiClient is "stateless" in the sense it doesn't keep a cache of the nodes and cannot make any assumption about the existing nodes structure.
I think it's the library consumer task to refresh/maintain the nodes cache and decide based on its content if a folder needs to be created or not.

from megaapiclient.

Related Issues (20)

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. 📊📈🎉

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google ❤️ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.