diff --git a/binding.gyp b/binding.gyp index c280fd9c..8389e1aa 100644 --- a/binding.gyp +++ b/binding.gyp @@ -29,6 +29,7 @@ "native-src/virtual_drive/Wrappers.cpp", "native-src/virtual_drive/create_file_placeholder.cpp", "native-src/virtual_drive/create_folder_placeholder.cpp", + "native-src/virtual_drive/get_file_identity.cpp", "native-src/virtual_drive/register_sync_root.cpp" ], "include_dirs": [ diff --git a/dist/addon.node b/dist/addon.node index f758401f..2f7da47a 100644 Binary files a/dist/addon.node and b/dist/addon.node differ diff --git a/include/virtual_drive/get_file_identity.h b/include/virtual_drive/get_file_identity.h new file mode 100644 index 00000000..5ffc6608 --- /dev/null +++ b/include/virtual_drive/get_file_identity.h @@ -0,0 +1,5 @@ +#pragma once + +#include + +napi_value get_file_identity_impl(napi_env env, napi_callback_info args); diff --git a/native-src/virtual_drive/Wrappers.cpp b/native-src/virtual_drive/Wrappers.cpp index 6e4ea238..a643b716 100644 --- a/native-src/virtual_drive/Wrappers.cpp +++ b/native-src/virtual_drive/Wrappers.cpp @@ -11,6 +11,7 @@ #include "register_sync_root.h" #include "create_folder_placeholder.h" #include "create_file_placeholder.h" +#include "get_file_identity.h" #include "napi_safe_wrap.h" std::string WStringToUTF8(const std::wstring &wstr) @@ -271,31 +272,7 @@ napi_value DisconnectSyncRootWrapper(napi_env env, napi_callback_info args) napi_value GetFileIdentityWrapper(napi_env env, napi_callback_info args) { - size_t argc = 1; - napi_value argv[1]; - napi_get_cb_info(env, args, &argc, argv, nullptr, nullptr); - - if (argc < 1) - { - napi_throw_error(env, nullptr, "The path is required for GetFileIdentity"); - return nullptr; - } - - LPCWSTR fullPath; - size_t pathLength; - napi_get_value_string_utf16(env, argv[0], nullptr, 0, &pathLength); - fullPath = new WCHAR[pathLength + 1]; - napi_get_value_string_utf16(env, argv[0], reinterpret_cast(const_cast(fullPath)), pathLength + 1, nullptr); - - std::string fileIdentity = Placeholders::GetFileIdentity(fullPath); - fileIdentity.erase(std::remove(fileIdentity.begin(), fileIdentity.end(), '\0'), fileIdentity.end()); - fileIdentity.erase(std::remove(fileIdentity.begin(), fileIdentity.end(), ' '), fileIdentity.end()); - - napi_value jsFileIdentity; - napi_create_string_utf8(env, fileIdentity.c_str(), fileIdentity.length(), &jsFileIdentity); - - delete[] fullPath; - return jsFileIdentity; + return napi_safe_wrap(env, args, get_file_identity_impl); } napi_value DeleteFileSyncRootWrapper(napi_env env, napi_callback_info args) diff --git a/native-src/virtual_drive/get_file_identity.cpp b/native-src/virtual_drive/get_file_identity.cpp new file mode 100644 index 00000000..b86bdcd3 --- /dev/null +++ b/native-src/virtual_drive/get_file_identity.cpp @@ -0,0 +1,31 @@ +#include +#include "Placeholders.h" + +napi_value get_file_identity_impl(napi_env env, napi_callback_info args) +{ + size_t argc = 1; + napi_value argv[1]; + napi_get_cb_info(env, args, &argc, argv, nullptr, nullptr); + + if (argc < 1) + { + napi_throw_error(env, nullptr, "The path is required for GetFileIdentity"); + return nullptr; + } + + LPCWSTR fullPath; + size_t pathLength; + napi_get_value_string_utf16(env, argv[0], nullptr, 0, &pathLength); + fullPath = new WCHAR[pathLength + 1]; + napi_get_value_string_utf16(env, argv[0], reinterpret_cast(const_cast(fullPath)), pathLength + 1, nullptr); + + std::string fileIdentity = Placeholders::GetFileIdentity(fullPath); + fileIdentity.erase(std::remove(fileIdentity.begin(), fileIdentity.end(), '\0'), fileIdentity.end()); + fileIdentity.erase(std::remove(fileIdentity.begin(), fileIdentity.end(), ' '), fileIdentity.end()); + + napi_value jsFileIdentity; + napi_create_string_utf8(env, fileIdentity.c_str(), fileIdentity.length(), &jsFileIdentity); + + delete[] fullPath; + return jsFileIdentity; +} diff --git a/package.json b/package.json index e3b149f3..1fe63dbf 100644 --- a/package.json +++ b/package.json @@ -1,6 +1,6 @@ { "name": "@internxt/node-win", - "version": "1.0.22", + "version": "1.0.23", "author": "Internxt ", "description": "Drive desktop node addon", "main": "dist/index.js",