Skip to content
Snippets Groups Projects
database_util.js 3.66 KiB
Newer Older
fcrisafulli-dev's avatar
fcrisafulli-dev committed


export const  dbCreateCollection = async (newCollectionName) => {
    console.log("dbCreateCollection");
    let result = await fetch(
      "http://127.0.0.1:5000/api/v1/create_collection",
      {
        method: "POST", // or 'PUT'
        headers: {
            "Content-Type": "application/json",
        },
        body: JSON.stringify(
            {
                "authenticate":{"username":"test_user","password":"12345"},
                "collection_info":{"collection_name": newCollectionName}
            }
        ),
      }
    )
    .then((response) => response.json())
    .then((response) => {
      if (response["status"] == "success") {
        console.log("dbCreateCollection Success")
        return response["collection_id"];
      }
    });


    return result
};

export const dbGetCollection = async (collection_id) => {
    console.log("dbGetCollection");
    let result = await fetch("http://127.0.0.1:5000//api/v1/get_collection?collection=" + collection_id,)
    .then((response) => response.json())
    .then((response) => {
        console.log(response)
        if (response["status"] == "success") {
            return response["collection"]
        }
    });
    return result;
};

fcrisafulli-dev's avatar
fcrisafulli-dev committed
export const dbGetItems = async (collection_id,item_type) => {
    console.log("dbGetItems");
    let result = await fetch(`http://127.0.0.1:5000//api/v1/get_items?collection=${collection_id}&type=${item_type}`)
    .then((response) => response.json())
    .then((response) => {
        console.log(response)
        if (response["status"] == "success") {
            return response["files"]
        }
    });
    return result;
};

fcrisafulli-dev's avatar
fcrisafulli-dev committed
export const dbGetCollections = async (user_id) => {
    let result = await fetch("http://127.0.0.1:5000//api/v1/get_collections?user=" + user_id,)
    .then((response) => response.json())
    .then((response) => {
        console.log("dbGetCollections",response);
        if (response["status"] == "success") {
            return response["collections"]
        } else {
            return []
        }
    });
    return result;
};

export const dbUpdateCollectionGlob = async (collection_id,glob) => {
    console.log("dbUpdateCollection",collection_id);
    let result = await fetch(
        "http://127.0.0.1:5000/api/v1/update_collection_glob",
        {
          method: "POST", // or 'PUT'
          headers: {
              "Content-Type": "application/json",
          },
          body: JSON.stringify(
                {
                    "authenticate":{"username":"test_user","password":"12345"},
                    "collection_info":{
                        "collection_id": collection_id, 
                        "glob":glob
                    }
              }
          ),
        }
      )
      .then((response) => response.json())
      .then((response) => {
        if (response["status"] == "success") {
          return response;
        }
      });
  
  
      return result
};

fcrisafulli-dev's avatar
fcrisafulli-dev committed
export const dbUpdateCollectionSummary = async (collection_id) => {
    console.log("dbUpdateCollectionSummary",collection_id);
    let result = await fetch(
        "http://127.0.0.1:5000/api/v1/summarize/t5",
        {
          method: "POST", // or 'PUT'
          headers: {
              "Content-Type": "application/json",
          },
          body: JSON.stringify(
                {
                    "collection_info":{
                        "collection_id": collection_id, 
                    }
              }
          ),
        }
      )
      .then((response) => response.json())
      .then((response) => {
        if (response["status"] == "success") {
          return response;
        }
      });
  
  
      return result
};

fcrisafulli-dev's avatar
fcrisafulli-dev committed
export default dbCreateCollection;