Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
52 commits
Select commit Hold shift + click to select a range
21bd1ad
Create napi safe wrap
dajimenezriv-internxt Aug 15, 2025
819a1f1
Extract create folder placeholder
dajimenezriv-internxt Aug 16, 2025
cc1b678
Extract create file placeholder
dajimenezriv-internxt Aug 16, 2025
444a2d5
Extract get file identity
dajimenezriv-internxt Aug 19, 2025
b5eff5e
Update package.json
dajimenezriv-internxt Aug 19, 2025
fe31746
Extract connect sync root
dajimenezriv-internxt Aug 27, 2025
32c5ea9
Extract hydrate file
dajimenezriv-internxt Sep 8, 2025
75681d6
Hydrate file thread safe
dajimenezriv-internxt Sep 8, 2025
205f2be
Improve safe wrap
dajimenezriv-internxt Sep 8, 2025
9648c94
Remove delete file from c++
dajimenezriv-internxt Sep 8, 2025
46ee84c
Extract convert to placeholder
dajimenezriv-internxt Sep 10, 2025
313dfbf
Refactor register sync root
dajimenezriv-internxt Sep 15, 2025
ff28084
Extract code
dajimenezriv-internxt Sep 15, 2025
d1a7164
Improve
dajimenezriv-internxt Sep 15, 2025
70d004e
Simplify providerId
dajimenezriv-internxt Sep 15, 2025
69ce991
Commit
dajimenezriv-internxt Sep 15, 2025
1020526
Commit
dajimenezriv-internxt Sep 15, 2025
e94646e
Commit
dajimenezriv-internxt Sep 15, 2025
0601df9
Update get_registered_sync_roots.cpp
dajimenezriv-internxt Sep 15, 2025
73a1c9e
Update addon.node
dajimenezriv-internxt Sep 15, 2025
ae38d77
Commt
dajimenezriv-internxt Sep 15, 2025
f7b6a44
Commit
dajimenezriv-internxt Sep 16, 2025
41028a0
Simplify unregister
dajimenezriv-internxt Sep 16, 2025
38a0e29
Fix wrapper
dajimenezriv-internxt Sep 16, 2025
4832626
Remove context
dajimenezriv-internxt Sep 16, 2025
d947054
Improve napi
dajimenezriv-internxt Sep 16, 2025
9d096c0
Template napi_extract_args
dajimenezriv-internxt Sep 16, 2025
249d71c
Extract dehydrate file wrapper
dajimenezriv-internxt Sep 17, 2025
2d39fb1
Refactor dehydrate file
dajimenezriv-internxt Sep 17, 2025
0a6216f
Throw exceptions
dajimenezriv-internxt Sep 17, 2025
4577789
Commit
dajimenezriv-internxt Sep 17, 2025
bc748b0
Extract disconnect sync root
dajimenezriv-internxt Sep 17, 2025
e17ca28
Extract get placeholder state
dajimenezriv-internxt Sep 17, 2025
a5e3dc7
Remove sync state
dajimenezriv-internxt Sep 17, 2025
18b57ba
Extract update sync status
dajimenezriv-internxt Sep 17, 2025
8d97f38
Update publish-npm.yml
dajimenezriv-internxt Sep 18, 2025
0fe50fb
Merge branch 'master' into extract-disconnect-sync-root
dajimenezriv-internxt Sep 18, 2025
20b0533
Merge branch 'master' into extract-disconnect-sync-root
dajimenezriv-internxt Sep 18, 2025
d65af96
Merge branch 'extract-disconnect-sync-root' into extract-get-placehol…
dajimenezriv-internxt Sep 18, 2025
71f1c31
Merge branch 'extract-get-placeholder-state' into extract-update-sync…
dajimenezriv-internxt Sep 18, 2025
5729e8e
Update addon.node
dajimenezriv-internxt Sep 18, 2025
394f12d
Merge branch 'master' into extract-get-placeholder-state
dajimenezriv-internxt Sep 19, 2025
470f12e
Merge branch 'extract-get-placeholder-state' into extract-update-sync…
dajimenezriv-internxt Sep 19, 2025
5bd5c36
Clean
dajimenezriv-internxt Sep 19, 2025
9e35bf5
Refactor cancel fetch data
dajimenezriv-internxt Sep 19, 2025
fa70622
Update CancelFetchDataCallback.cpp
dajimenezriv-internxt Sep 19, 2025
0c2fd4d
Update addon.node
dajimenezriv-internxt Sep 19, 2025
5d9d904
Merge branch 'master' into refactor-cancel-fetch-data
dajimenezriv-internxt Sep 19, 2025
370eac2
Remove AddFolderToSearchIndexer
dajimenezriv-internxt Sep 24, 2025
aa5b393
Merge branch 'master' into refactor-cancel-fetch-data
dajimenezriv-internxt Sep 24, 2025
5bbd137
Update node
dajimenezriv-internxt Sep 24, 2025
04d62ec
Update publish-npm.yml
dajimenezriv-internxt Sep 25, 2025
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
10 changes: 8 additions & 2 deletions .github/workflows/publish-npm.yml
Original file line number Diff line number Diff line change
Expand Up @@ -19,17 +19,23 @@ jobs:
node-version: 20

- name: Create .npmrc file
shell: bash
env:
GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }}
run: |
echo "@internxt:registry=https://npm.pkg.github.com/" > .npmrc
echo "//npm.pkg.github.com/:_authToken=${{ secrets.GITHUB_TOKEN }}" >> .npmrc
echo "//npm.pkg.github.com/:_authToken=$GITHUB_TOKEN >> .npmrc

- name: Publish package to github
run: npm publish --scope=@internxt --access public

- name: Create .npmrc file
shell: bash
env:
NPM_TOKEN: ${{ secrets.NPM_TOKEN }}
run: |
echo "registry=https://registry.npmjs.org/" > .npmrc
echo "//registry.npmjs.org/:_authToken=${{ secrets.NPM_TOKEN }}" >> .npmrc
echo "//registry.npmjs.org/:_authToken=$NPM_TOKEN" >> .npmrc

- name: Publish package to npm
run: npm publish --scope=@internxt --access public
1 change: 0 additions & 1 deletion binding.gyp
Original file line number Diff line number Diff line change
Expand Up @@ -21,7 +21,6 @@
"native-src/placeholders_interface/Planceholders.cpp",
"native-src/sync_root_interface/SyncRoot.cpp",
"native-src/sync_root_interface/Utilities.cpp",
"native-src/sync_root_interface/callbacks/Callbacks.cpp",
"native-src/sync_root_interface/callbacks/CancelFetchData/CancelFetchDataCallback.cpp",
"native-src/sync_root_interface/callbacks/FetchData/FetchData.cpp",
"native-src/sync_root_interface/callbacks/FetchData/FileCopierWithProgress.cpp",
Expand Down
Binary file modified dist/addon.node
Binary file not shown.
1 change: 0 additions & 1 deletion include/sync_root_interface/Utilities.h
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,6 @@
class Utilities
{
public:
static void AddFolderToSearchIndexer(_In_ LPCWSTR folder);
Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This is no longer necessary, the CfRegister already adds the InternxtDrive to the file explorer and indexes it when searching for files in the search bar of the file explorer.

static void ApplyTransferStateToFile(_In_ LPCWSTR fullPath, _In_ CF_CALLBACK_INFO &callbackInfo, UINT64 total, UINT64 completed);
static std::wstring GetErrorMessageCloudFiles(HRESULT hr);

Expand Down
2 changes: 0 additions & 2 deletions include/sync_root_interface/callbacks/Callbacks.h
Original file line number Diff line number Diff line change
Expand Up @@ -2,8 +2,6 @@

#include <CallbacksContext.h>

void register_threadsafe_callbacks(napi_env env, InputSyncCallbacks input);

// Fetch Data Callback
void register_threadsafe_fetch_data_callback(const std::string &resource_name, napi_env env, InputSyncCallbacks input);
void CALLBACK fetch_data_callback_wrapper(_In_ CONST CF_CALLBACK_INFO *callbackInfo, _In_ CONST CF_CALLBACK_PARAMETERS *callbackParameters);
Expand Down
7 changes: 2 additions & 5 deletions native-src/sync_root_interface/SyncRoot.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -6,9 +6,6 @@
#include <iostream>
#include <vector>

namespace fs = std::filesystem;
// variable to disconect
CF_CONNECTION_KEY gloablConnectionKey;
std::map<std::wstring, CF_CONNECTION_KEY> connectionMap;

void SyncRoot::HydrateFile(const wchar_t *filePath)
Expand Down Expand Up @@ -58,8 +55,8 @@ void SyncRoot::HydrateFile(const wchar_t *filePath)

HRESULT SyncRoot::ConnectSyncRoot(const wchar_t *syncRootPath, InputSyncCallbacks syncCallbacks, napi_env env, CF_CONNECTION_KEY *connectionKey)
{
Utilities::AddFolderToSearchIndexer(syncRootPath);
register_threadsafe_callbacks(env, syncCallbacks);
register_threadsafe_fetch_data_callback("FetchDataThreadSafe", env, syncCallbacks);
register_threadsafe_cancel_fetch_data_callback("CancelFetchDataThreadSafe", env, syncCallbacks);

CF_CALLBACK_REGISTRATION callbackTable[] = {
{CF_CALLBACK_TYPE_FETCH_DATA, fetch_data_callback_wrapper},
Expand Down
35 changes: 0 additions & 35 deletions native-src/sync_root_interface/Utilities.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -5,43 +5,8 @@
#include "Utilities.h"
#include <Logger.h>

#define MSSEARCH_INDEX L"SystemIndex"
DEFINE_PROPERTYKEY(PKEY_StorageProviderTransferProgress, 0xE77E90DF, 0x6271, 0x4F5B, 0x83, 0x4F, 0x2D, 0xD1, 0xF2, 0x45, 0xDD, 0xA4, 4);

void Utilities::AddFolderToSearchIndexer(_In_ PCWSTR folder)
Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This is no longer necessary, the CfRegister already adds the InternxtDrive to the file explorer and indexes it when searching for files in the search bar of the file explorer.

{
HRESULT hr = CoInitializeEx(NULL, COINIT_MULTITHREADED);
if (FAILED(hr))
{
wprintf(L"Failed to initialize COM library. Error code = %08x\n", hr);
return;
}

std::wstring url(L"file:///");
url.append(folder);

try
{
winrt::com_ptr<ISearchManager> searchManager;
winrt::check_hresult(CoCreateInstance(__uuidof(CSearchManager), NULL, CLSCTX_SERVER, __uuidof(&searchManager), searchManager.put_void()));

winrt::com_ptr<ISearchCatalogManager> searchCatalogManager;
winrt::check_hresult(searchManager->GetCatalog(MSSEARCH_INDEX, searchCatalogManager.put()));

winrt::com_ptr<ISearchCrawlScopeManager> searchCrawlScopeManager;
winrt::check_hresult(searchCatalogManager->GetCrawlScopeManager(searchCrawlScopeManager.put()));

winrt::check_hresult(searchCrawlScopeManager->AddDefaultScopeRule(url.data(), TRUE, FOLLOW_FLAGS::FF_INDEXCOMPLEXURLS));
winrt::check_hresult(searchCrawlScopeManager->SaveAll());

// wprintf(L"Succesfully called AddFolderToSearchIndexer on \"%s\"\n", url.data());
}
catch (...)
{
wprintf(L"Failed on call to AddFolderToSearchIndexer for \"%s\" with %08x\n", url.data(), static_cast<HRESULT>(winrt::to_hresult()));
}
}

void Utilities::ApplyTransferStateToFile(_In_ PCWSTR fullPath, _In_ CF_CALLBACK_INFO &callbackInfo, UINT64 total, UINT64 completed)
{
Logger::getInstance().log("ApplyTransferStateToFile", LogLevel::INFO);
Expand Down
8 changes: 0 additions & 8 deletions native-src/sync_root_interface/callbacks/Callbacks.cpp

This file was deleted.

Original file line number Diff line number Diff line change
Expand Up @@ -7,20 +7,25 @@
#include <mutex>
#include <filesystem>

napi_threadsafe_function g_cancel_delete_fetch_data_threadsafe_callback = nullptr;
napi_threadsafe_function g_cancel_fetch_data_threadsafe_callback = nullptr;

inline std::mutex mtx;
inline std::condition_variable cv;
inline bool ready = false;
Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

If this variables are global we can parallelize the cancel fetch data because all files would share the same variables.

struct CallbackContext {
std::mutex mtx;
std::condition_variable cv;
bool ready = false;
};

struct CancelFetchDataArgs
{
struct CancelFetchDataArgs {
std::wstring fileIdentityArg;
CallbackContext* context;

CancelFetchDataArgs(const std::wstring& fileId, CallbackContext* ctx)
: fileIdentityArg(fileId), context(ctx) {}
};

void setup_global_tsfn_cancel_fetch_data(napi_threadsafe_function tsfn)
{
g_cancel_delete_fetch_data_threadsafe_callback = tsfn;
g_cancel_fetch_data_threadsafe_callback = tsfn;
}

void notify_cancel_fetch_data_call(napi_env env, napi_value js_callback, void *context, void *data)
Expand All @@ -43,23 +48,27 @@ void notify_cancel_fetch_data_call(napi_env env, napi_value js_callback, void *c
{
fprintf(stderr, "Failed to call JS function.\n");
Logger::getInstance().log("Failed to call JS function in cancelFetchCallback.", LogLevel::ERROR);
return;
Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

We can't return since we need to change ready to true, otherwise we are not releasing the mutex lock.

}

cv.notify_one();
{
std::lock_guard<std::mutex> lock(args->context->mtx);
args->context->ready = true;
}

args->context->cv.notify_one();
delete args;
}

void register_threadsafe_cancel_fetch_data_callback(const std::string &resource_name, napi_env env, InputSyncCallbacks input)
{
std::u16string converted_resource_name = std::u16string(resource_name.begin(), resource_name.end());
std::u16string converted_resource_name(resource_name.begin(), resource_name.end());

napi_value resource_name_value;
napi_create_string_utf16(env, converted_resource_name.c_str(), NAPI_AUTO_LENGTH, &resource_name_value);

napi_threadsafe_function tsfn_cancel_fetch_data;
napi_value cancel_fetch_data_value;
napi_status status_ref = napi_get_reference_value(env, input.cancel_fetch_data_callback_ref, &cancel_fetch_data_value);
napi_get_reference_value(env, input.cancel_fetch_data_callback_ref, &cancel_fetch_data_value);

napi_status status = napi_create_threadsafe_function(
env,
Expand All @@ -76,47 +85,44 @@ void register_threadsafe_cancel_fetch_data_callback(const std::string &resource_

if (status != napi_ok)
{
fprintf(stderr, "Failed to create threadsafe function.\n");
napi_throw_error(env, nullptr, "Failed to create cancel fetch data threadsafe function");
Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

We want to throw an error in javascript if the connect function fails because we cannot register the cancel fetch data callback.

return;
}

setup_global_tsfn_cancel_fetch_data(tsfn_cancel_fetch_data);
}

void CALLBACK cancel_fetch_data_callback_wrapper(
_In_ CONST CF_CALLBACK_INFO *callbackInfo,
_In_ CONST CF_CALLBACK_PARAMETERS *callbackParameters)
{
printf("fetch_data_callback_wrapper\n");
printf("cancel_fetch_data_callback_wrapper called\n");

LPCVOID fileIdentity = callbackInfo->FileIdentity;
DWORD fileIdentityLength = callbackInfo->FileIdentityLength;

const wchar_t *wchar_ptr = static_cast<const wchar_t *>(fileIdentity);
std::wstring fileIdentityStr(wchar_ptr, fileIdentityLength / sizeof(wchar_t));

if (g_cancel_delete_fetch_data_threadsafe_callback == nullptr)
if (g_cancel_fetch_data_threadsafe_callback == nullptr)
{
wprintf(L"Callback fetch_data_callback_wrapper called but g_fetch_data_threadsafe_callback is null\n");
return;
}

CallbackContext context;
CancelFetchDataArgs *args = new CancelFetchDataArgs(fileIdentityStr, &context);

CancelFetchDataArgs *args = new CancelFetchDataArgs();
args->fileIdentityArg = fileIdentityStr;

napi_status status = napi_call_threadsafe_function(g_cancel_delete_fetch_data_threadsafe_callback, args, napi_tsfn_blocking);
napi_call_threadsafe_function(g_cancel_fetch_data_threadsafe_callback, args, napi_tsfn_blocking);

if (status != napi_ok)
{
wprintf(L"Callback called unsuccessfully.\n");
};
std::unique_lock<std::mutex> lock(context.mtx);
auto timeout = std::chrono::seconds(30);

{
Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Instead of locking the mutext without any condition, we lock it until context.ready becomes true. We also add a timeout of 30 seconds.

std::unique_lock<std::mutex> lock(mtx);
while (!ready)
{
cv.wait(lock);
if (context.cv.wait_for(lock, timeout, [&context] { return context.ready; })) {
wprintf(L"Cancel fetch completed\n");
} else {
wprintf(L"Cancel fetch timed out\n");
}
}

ready = false;
}
}
Loading