diff --git a/.github/workflows/check-pr-size.yml b/.github/workflows/check-pr-size.yml index c9291779..25d9a7e0 100644 --- a/.github/workflows/check-pr-size.yml +++ b/.github/workflows/check-pr-size.yml @@ -11,7 +11,7 @@ jobs: steps: - name: Checkout code - uses: actions/checkout@v3 + uses: actions/checkout@v4 with: fetch-depth: 0 diff --git a/.github/workflows/publish-npm.yml b/.github/workflows/publish-npm.yml index 810fcce4..ed8bddbe 100644 --- a/.github/workflows/publish-npm.yml +++ b/.github/workflows/publish-npm.yml @@ -7,6 +7,7 @@ on: jobs: publish_npm: runs-on: ubuntu-latest + timeout-minutes: 1 permissions: contents: read diff --git a/.github/workflows/stale-prs.yml b/.github/workflows/stale-prs.yml index 4c77c94c..25372656 100644 --- a/.github/workflows/stale-prs.yml +++ b/.github/workflows/stale-prs.yml @@ -12,6 +12,7 @@ permissions: jobs: stale_prs: runs-on: ubuntu-latest + timeout-minutes: 1 steps: - uses: actions/stale@v9 diff --git a/binding.gyp b/binding.gyp index f03368d2..60f1d9c4 100644 --- a/binding.gyp +++ b/binding.gyp @@ -34,7 +34,6 @@ "include/placeholders_interface", "include/sync_root_interface", "include/sync_root_interface/callbacks", - "include/types", "include/virtual_drive" ], "libraries": [ diff --git a/dist/addon.node b/dist/addon.node index 030c589c..5a6f75cc 100644 Binary files a/dist/addon.node and b/dist/addon.node differ diff --git a/include/sync_root_interface/Utilities.h b/include/sync_root_interface/Utilities.h index 3effcb19..b2498e6d 100644 --- a/include/sync_root_interface/Utilities.h +++ b/include/sync_root_interface/Utilities.h @@ -1,18 +1,11 @@ #pragma once #include -#include "ProcessTypes.h" class Utilities { public: static void AddFolderToSearchIndexer(_In_ LPCWSTR folder); static void ApplyTransferStateToFile(_In_ LPCWSTR fullPath, _In_ CF_CALLBACK_INFO &callbackInfo, UINT64 total, UINT64 completed); - static void ApplyCustomStateToPlaceholderFile(_In_ LPCWSTR path, _In_ LPCWSTR filename, _In_ winrt::StorageProviderItemProperty &prop); - static void ApplyCustomOverwriteStateToPlaceholderFile(_In_ LPCWSTR path, _In_ LPCWSTR filename, _In_ winrt::StorageProviderItemProperty &prop); - static std::wstring ProcessErrorNameToWString(_In_ ProcessErrorName error); - static std::wstring FileOperationErrorToWString(_In_ FileOperationError error); - static bool IsTemporaryFile(const std::wstring &fullPath); static std::wstring GetErrorMessageCloudFiles(HRESULT hr); - static void ClearTransferProperties(_In_ LPCWSTR fullPath); static winrt::com_array ConvertSidToStringSid(_In_ PSID sid) @@ -45,17 +38,6 @@ class Utilities return largeInteger; } - inline static CF_OPERATION_INFO ToOperationInfo( - _In_ CF_CALLBACK_INFO const *info, - _In_ CF_OPERATION_TYPE operationType) - { - return CF_OPERATION_INFO{ - sizeof(CF_OPERATION_INFO), - operationType, - info->ConnectionKey, - info->TransferKey}; - } - static DWORD convertSizeToDWORD(size_t &convertVar) { if (convertVar > UINT_MAX) diff --git a/include/types/ProcessTypes.h b/include/types/ProcessTypes.h deleted file mode 100644 index 5a6dba3e..00000000 --- a/include/types/ProcessTypes.h +++ /dev/null @@ -1,22 +0,0 @@ -#pragma once - -enum class ProcessErrorName -{ - NOT_EXISTS, - NO_PERMISSION, - NO_INTERNET, - NO_REMOTE_CONNECTION, - BAD_RESPONSE, - EMPTY_FILE, - FILE_TOO_BIG, - FILE_NON_EXTENSION, - UNKNOWN, -}; - -enum class FileOperationError -{ - UPLOAD_ERROR, - DOWNLOAD_ERROR, - DELETE_ERROR, - METADATA_READ_ERROR -}; \ No newline at end of file diff --git a/native-src/main.cpp b/native-src/main.cpp index 51b20597..2c1b58e9 100644 --- a/native-src/main.cpp +++ b/native-src/main.cpp @@ -3,7 +3,6 @@ napi_value init(napi_env env, napi_value exports) { - // CreatePlaceholderFileWrapper napi_property_descriptor desc = { "createPlaceholderFile", nullptr, @@ -21,7 +20,6 @@ napi_value init(napi_env env, napi_value exports) return nullptr; } - // UnregisterSyncRootWrapper napi_property_descriptor unregisterDesc = { "unregisterSyncRoot", nullptr, @@ -39,7 +37,6 @@ napi_value init(napi_env env, napi_value exports) return nullptr; } - // RegisterSyncRootWrapper napi_property_descriptor registerSyncRootDesc = { "registerSyncRoot", nullptr, @@ -57,7 +54,6 @@ napi_value init(napi_env env, napi_value exports) return nullptr; } - // GetRegisteredSyncRootsWrapper napi_property_descriptor getRegisteredSyncRootsRootDesc = { "getRegisteredSyncRoots", nullptr, @@ -75,7 +71,6 @@ napi_value init(napi_env env, napi_value exports) return nullptr; } - // ConnectSyncRootWrapper napi_property_descriptor connectSyncRootDesc = { "connectSyncRoot", nullptr, @@ -110,7 +105,6 @@ napi_value init(napi_env env, napi_value exports) return nullptr; } - // disconection napi_property_descriptor disconnectDesc = { "disconnectSyncRoot", nullptr, @@ -247,7 +241,6 @@ napi_value init(napi_env env, napi_value exports) return nullptr; } - // Define HydrateFile wrapper napi_property_descriptor hydrateFileDesc = { "hydrateFile", nullptr, @@ -265,7 +258,6 @@ napi_value init(napi_env env, napi_value exports) return nullptr; } - // Define DehydrateFile wrapper napi_property_descriptor dehydrateFileDesc = { "dehydrateFile", nullptr, diff --git a/native-src/sync_root_interface/Utilities.cpp b/native-src/sync_root_interface/Utilities.cpp index fc38fdab..b0c1a00c 100644 --- a/native-src/sync_root_interface/Utilities.cpp +++ b/native-src/sync_root_interface/Utilities.cpp @@ -3,57 +3,11 @@ #include #include #include "Utilities.h" -#include #include #define MSSEARCH_INDEX L"SystemIndex" DEFINE_PROPERTYKEY(PKEY_StorageProviderTransferProgress, 0xE77E90DF, 0x6271, 0x4F5B, 0x83, 0x4F, 0x2D, 0xD1, 0xF2, 0x45, 0xDD, 0xA4, 4); -void Utilities::ApplyCustomStateToPlaceholderFile(LPCWSTR path, LPCWSTR filename, winrt::StorageProviderItemProperty &prop) -{ - try - { - std::wstring fullPath(path); - fullPath.append(L"\\"); - fullPath.append(filename); - - // wprintf(L"Full path: %s\n", fullPath.c_str()); - winrt::IStorageItem item = winrt::StorageFile::GetFileFromPathAsync(fullPath).get(); - winrt::StorageProviderItemProperties::SetAsync(item, {prop}).get(); - } - catch (const winrt::hresult_error &error) - { - wprintf(L"Failed to set custom state. Error: %s (Code: %08x)\n", error.message().c_str(), error.code()); - } - catch (...) - { - wprintf(L"Failed to set custom state with unknown error %08x\n", static_cast(winrt::to_hresult())); - } -} - -void Utilities::ApplyCustomOverwriteStateToPlaceholderFile(LPCWSTR path, LPCWSTR filename, winrt::StorageProviderItemProperty &prop) -{ - try - { - std::wstring fullPath(path); - fullPath.append(L"\\"); - fullPath.append(filename); - - // wprintf(L"Full path: %s\n", fullPath.c_str()); - winrt::IStorageItem item = winrt::StorageFile::GetFileFromPathAsync(fullPath).get(); - winrt::StorageProviderItemProperties::SetAsync(item, {}).get(); - winrt::StorageProviderItemProperties::SetAsync(item, {prop}).get(); - } - catch (const winrt::hresult_error &error) - { - wprintf(L"Failed to set custom state. Error: %s (Code: %08x)\n", error.message().c_str(), error.code()); - } - catch (...) - { - wprintf(L"Failed to set custom state with unknown error %08x\n", static_cast(winrt::to_hresult())); - } -} - void Utilities::AddFolderToSearchIndexer(_In_ PCWSTR folder) { HRESULT hr = CoInitializeEx(NULL, COINIT_MULTITHREADED); @@ -88,26 +42,6 @@ void Utilities::AddFolderToSearchIndexer(_In_ PCWSTR folder) } } -void Utilities::ClearTransferProperties(PCWSTR fullPath) -{ - winrt::com_ptr item; - winrt::com_ptrstore; - - if (FAILED(SHCreateItemFromParsingName(fullPath, nullptr, - __uuidof(item), item.put_void()))) - return; - - if (FAILED(item->GetPropertyStore(GPS_READWRITE | GPS_VOLATILEPROPERTIESONLY, - __uuidof(store), store.put_void()))) - return; - - PROPVARIANT empty; PropVariantInit(&empty); - store->SetValue(PKEY_StorageProviderTransferProgress, empty); - store->SetValue(PKEY_SyncTransferStatus, empty); - store->Commit(); -} - - void Utilities::ApplyTransferStateToFile(_In_ PCWSTR fullPath, _In_ CF_CALLBACK_INFO &callbackInfo, UINT64 total, UINT64 completed) { Logger::getInstance().log("ApplyTransferStateToFile", LogLevel::INFO); @@ -211,78 +145,3 @@ std::wstring Utilities::GetErrorMessageCloudFiles(HRESULT hr) { LocalFree(errorMsg); return message; } - - -bool Utilities::IsTemporaryFile(const std::wstring &fullPath) -{ - size_t fileNameStart = fullPath.find_last_of(L'\\') + 1; - if (fullPath.size() >= fileNameStart + 2 && fullPath.compare(fileNameStart, 2, L"~$") == 0) - { - return true; - } - - std::array tempExtensions = { - L".tmp", - L".laccdb", - L".ldb", - L".bak", - L".sv$", - L".psdtmp", - L".~tmp" - }; - - for (const auto &ext : tempExtensions) - { - if (fullPath.size() >= ext.size() && - fullPath.compare(fullPath.size() - ext.size(), ext.size(), ext) == 0) - { - return true; - } - } - - return false; -} - -std::wstring Utilities::ProcessErrorNameToWString(ProcessErrorName error) -{ - switch (error) - { - case ProcessErrorName::NOT_EXISTS: - return L"NOT_EXISTS"; - case ProcessErrorName::NO_PERMISSION: - return L"NO_PERMISSION"; - case ProcessErrorName::NO_INTERNET: - return L"NO_INTERNET"; - case ProcessErrorName::NO_REMOTE_CONNECTION: - return L"NO_REMOTE_CONNECTION"; - case ProcessErrorName::BAD_RESPONSE: - return L"BAD_RESPONSE"; - case ProcessErrorName::EMPTY_FILE: - return L"EMPTY_FILE"; - case ProcessErrorName::FILE_TOO_BIG: - return L"FILE_TOO_BIG"; - case ProcessErrorName::UNKNOWN: - return L"UNKNOWN"; - case ProcessErrorName::FILE_NON_EXTENSION: - return L"FILE_NON_EXTENSION"; - default: - return L"UNKNOWN"; - } -} - -std::wstring Utilities::FileOperationErrorToWString(FileOperationError error) -{ - switch (error) - { - case FileOperationError::UPLOAD_ERROR: - return L"UPLOAD_ERROR"; - case FileOperationError::DOWNLOAD_ERROR: - return L"DOWNLOAD_ERROR"; - case FileOperationError::DELETE_ERROR: - return L"DELETE_ERROR"; - case FileOperationError::METADATA_READ_ERROR: - return L"METADATA_READ_ERROR"; - default: - return L"UNKNOWN"; - } -} \ No newline at end of file diff --git a/native-src/sync_root_interface/callbacks/FetchData/FetchData.cpp b/native-src/sync_root_interface/callbacks/FetchData/FetchData.cpp index 97fe2f72..1bff77f8 100644 --- a/native-src/sync_root_interface/callbacks/FetchData/FetchData.cpp +++ b/native-src/sync_root_interface/callbacks/FetchData/FetchData.cpp @@ -50,11 +50,6 @@ void load_data() printf("load_data called"); } -void setup_global_tsfn_fetch_data(napi_threadsafe_function tsfn) -{ - g_fetch_data_threadsafe_callback = tsfn; -} - napi_value create_response(napi_env env, bool finished, float progress) { napi_value result_object; @@ -276,34 +271,6 @@ static napi_value response_callback_fn_fetch_data(napi_env env, napi_callback_in return create_response(env, ctxPtr->loadFinished, progress); } -static napi_value create_error_response(napi_env env) -{ - Logger::getInstance().log("An error occurred during callback execution", LogLevel::ERROR); - return create_response(env, true, 0); -} - -static void handle_cancellation(TransferContext* ctxPtr) -{ - ctxPtr->loadFinished = true; - ctxPtr->lastReadOffset = 0; - { - std::lock_guard lock(ctxPtr->mtx); - ctxPtr->ready = true; - ctxPtr->cv.notify_one(); - } -} - -static void notify_completion(TransferContext* ctxPtr, float progress) -{ - std::lock_guard lock(ctxPtr->mtx); - if (ctxPtr->loadFinished) { - ctxPtr->ready = true; - ctxPtr->cv.notify_one(); - } -} - - - static void notify_fetch_data_call(napi_env env, napi_value js_callback, void *context, void *data) { Logger::getInstance().log("notify_fetch_data_call called context isolated", LogLevel::DEBUG); diff --git a/native-src/virtual_drive/Wrappers.cpp b/native-src/virtual_drive/Wrappers.cpp index 02c14488..01b0eed9 100644 --- a/native-src/virtual_drive/Wrappers.cpp +++ b/native-src/virtual_drive/Wrappers.cpp @@ -812,62 +812,7 @@ napi_value HydrateFileWrapper(napi_env env, napi_callback_info args) return promise; } -// napi_value HydrateFileWrapper(napi_env env, napi_callback_info args) { -// size_t argc = 1; -// napi_value argv[1]; -// napi_value thisArg; -// napi_get_cb_info(env, args, &argc, argv, &thisArg, nullptr); - -// if (argc < 1) { -// napi_throw_type_error(env, nullptr, "The file path is required for HydrateFile"); -// return nullptr; -// } - -// // Obtener el argumento de JavaScript y convertirlo a una cadena de C++ -// size_t pathLength; -// napi_get_value_string_utf16(env, argv[0], nullptr, 0, &pathLength); -// std::wstring fullPath(pathLength, L'\0'); -// napi_get_value_string_utf16(env, argv[0], reinterpret_cast(&fullPath[0]), pathLength + 1, nullptr); - -// // Crear una promesa -// napi_deferred deferred; -// napi_value promise; -// napi_create_promise(env, &deferred, &promise); - -// // Crear un handle scope para manejar la creación de objetos V8 -// napi_handle_scope handleScope; -// napi_open_handle_scope(env, &handleScope); - -// // Usar un bloque de manejo de V8 -// { -// v8::Isolate* isolate = v8::Isolate::GetCurrent(); -// v8::HandleScope scope(isolate); - -// try { -// Logger::getInstance().log("init... " + Logger::fromWStringToString(fullPath.c_str()), LogLevel::INFO); -// SyncRoot::HydrateFile(fullPath.c_str()); - -// napi_value result; -// napi_get_undefined(env, &result); -// napi_resolve_deferred(env, deferred, result); -// } catch (const std::exception& e) { -// napi_value error; -// napi_create_string_utf8(env, e.what(), NAPI_AUTO_LENGTH, &error); -// napi_reject_deferred(env, deferred, error); -// } catch (...) { -// napi_value error; -// napi_create_string_utf8(env, "Unknown error", NAPI_AUTO_LENGTH, &error); -// napi_reject_deferred(env, deferred, error); -// } -// } - -// // Cerrar el handle scope -// napi_close_handle_scope(env, handleScope); - -// return promise; -// } - -// Wrapper for DehydrateFile + napi_value DehydrateFileWrapper(napi_env env, napi_callback_info args) { size_t argc = 1; diff --git a/package.json b/package.json index 52976d4e..f9b1284a 100644 --- a/package.json +++ b/package.json @@ -1,23 +1,16 @@ { "name": "@internxt/node-win", - "version": "1.0.20", + "version": "1.0.21", + "author": "Internxt ", "description": "Drive desktop node addon", "main": "dist/index.js", "types": "dist/index.d.ts", - "author": "Internxt ", "license": "MIT", "gypfile": true, - "repository": { - "type": "git", - "url": "git+https://github.com/internxt/node-win.git" - }, "scripts": { "clean": "node-gyp clean", "build:gyp": "node-gyp configure build", "config:gyp": "python gyp.config.py", "build": "python gyp.config.py && node-gyp clean && node-gyp configure build" - }, - "engines": { - "node": ">=20.0.0" } }