Skip to content
Closed
Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
51 commits
Select commit Hold shift + click to select a range
c2a2976
Refactor sync root management to use drive instance for unregistering…
ArceDanielShok Feb 11, 2025
53167e6
Update unregisterSyncRoot to use providerId instead of syncRootPath
ArceDanielShok Feb 12, 2025
976468b
Refactor registerSyncRoot to use providerId from instance and update …
ArceDanielShok Feb 12, 2025
850e4c3
Remove connections map from VirtualDrive and simplify disconnectSyncR…
ArceDanielShok Feb 12, 2025
693be0c
Add FilePlaceholderId type for improved type safety in TFetchDataCall…
ArceDanielShok Feb 12, 2025
326ad37
Remove syncRootPath parameter from connectSyncRoot method for cleaner…
ArceDanielShok Feb 13, 2025
5d68993
Refactor VirtualDrive to use logger for connection debug information …
ArceDanielShok Feb 13, 2025
2ff474e
Merge pull request #130 from internxt/chore/improve-sync-engine-and-v…
ArceDanielShok Feb 13, 2025
a95222d
Merge pull request #132 from internxt/master
dajimenezriv-internxt Feb 13, 2025
43e9c78
Delete 3758a9e6-de8b-4e1e-a4fe-53300d078e99
dajimenezriv-internxt Feb 13, 2025
bbc1c09
Add prettier
dajimenezriv-internxt Feb 13, 2025
cf10e3c
Remove prettier
dajimenezriv-internxt Feb 13, 2025
1ec350c
Update pull-request.yml
dajimenezriv-internxt Feb 13, 2025
4874fa2
Create .gitattributes
dajimenezriv-internxt Feb 13, 2025
04c2447
Update .gitattributes
dajimenezriv-internxt Feb 13, 2025
82ec823
Update .gitattributes
dajimenezriv-internxt Feb 13, 2025
b990df3
Update pull-request.yml
dajimenezriv-internxt Feb 13, 2025
0ee614d
Update pull-request.yml
dajimenezriv-internxt Feb 13, 2025
8813ddd
Remove IQueueManager
dajimenezriv-internxt Feb 13, 2025
61d0df6
Update virtual-drive.ts
dajimenezriv-internxt Feb 13, 2025
f951ed7
Merge pull request #133 from internxt/add-prettier
ArceDanielShok Feb 14, 2025
53fccf6
Check PR size
dajimenezriv-internxt Feb 25, 2025
406087b
Update pull-request.yml
dajimenezriv-internxt Feb 25, 2025
fb5df58
Split check PR size
dajimenezriv-internxt Feb 25, 2025
147428a
Update check-pr-size.yml
dajimenezriv-internxt Feb 25, 2025
26d998e
Update check-pr-size.yml
dajimenezriv-internxt Feb 25, 2025
374d011
Update check-pr-size.yml
dajimenezriv-internxt Feb 25, 2025
36379f0
Merge pull request #135 from internxt/check-pr-size
dajimenezriv-internxt Feb 25, 2025
7ec9f51
Add sonaclour
dajimenezriv-internxt Mar 17, 2025
f4e74d1
Update sonar-analysis.yml
dajimenezriv-internxt Mar 17, 2025
d63b27e
Update sonar-analysis.yml
dajimenezriv-internxt Mar 17, 2025
bf3a9ff
Split in build:addon
dajimenezriv-internxt Mar 17, 2025
df6aa51
Update sonar-analysis.yml
dajimenezriv-internxt Mar 17, 2025
0f89037
Update sonar-analysis.yml
dajimenezriv-internxt Mar 17, 2025
4b4c551
Update sonar-analysis.yml
dajimenezriv-internxt Mar 17, 2025
5fb01f9
Update sonar-analysis.yml
dajimenezriv-internxt Mar 17, 2025
c5d9b58
Update sonar-analysis.yml
dajimenezriv-internxt Mar 17, 2025
7792927
Update sonar-analysis.yml
dajimenezriv-internxt Mar 17, 2025
51c86ae
Update sonar-analysis.yml
dajimenezriv-internxt Mar 17, 2025
db579c4
Update sonar-analysis.yml
dajimenezriv-internxt Mar 17, 2025
ad227d9
Update sonar-analysis.yml
dajimenezriv-internxt Mar 17, 2025
a87d327
Update sonar-analysis.yml
dajimenezriv-internxt Mar 17, 2025
c55579f
Update sonar-analysis.yml
dajimenezriv-internxt Mar 17, 2025
bf8aa0c
Update sonar-analysis.yml
dajimenezriv-internxt Mar 17, 2025
0c5874d
Update sonar-analysis.yml
dajimenezriv-internxt Mar 17, 2025
56d92e2
Update sonar-analysis.yml
dajimenezriv-internxt Mar 17, 2025
9910cf4
Update sonar-analysis.yml
dajimenezriv-internxt Mar 17, 2025
508a2f4
Update sonar-analysis.yml
dajimenezriv-internxt Mar 17, 2025
0e2fc29
Update sonar-analysis.yml
dajimenezriv-internxt Mar 17, 2025
a919e25
Update sonar-analysis.yml
dajimenezriv-internxt Mar 17, 2025
bf176ee
Update sonar-analysis.yml
dajimenezriv-internxt Mar 17, 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
1 change: 1 addition & 0 deletions .gitattributes
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
* text=auto eol=crlf
46 changes: 46 additions & 0 deletions .github/workflows/check-pr-size.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,46 @@
name: Check PR size

on:
pull_request:

jobs:
check_pr_size:
runs-on: ubuntu-latest

steps:
- name: Checkout code
uses: actions/checkout@v3
with:
fetch-depth: 0

- name: Calculate changed lines
id: diff_check
run: |
# Get the target branch commit (base) and the PR branch commit (head)
BASE_SHA="${{ github.event.pull_request.base.sha }}"
HEAD_SHA="${{ github.event.pull_request.head.sha }}"
echo "Base SHA: $BASE_SHA"
echo "Head SHA: $HEAD_SHA"

# Compute the merge base between the two branches
MERGE_BASE=$(git merge-base "$HEAD_SHA" "$BASE_SHA")
echo "Merge Base: $MERGE_BASE"

# Calculate added and deleted lines between the merge base and the head commit
TOTAL_CHANGED=$(git diff --numstat "$MERGE_BASE" "$HEAD_SHA" \
| grep -v "yarn.lock" \
| awk '{ added += $1; deleted += $2 } END { print added + deleted }')

# Default to 0 if nothing is output
TOTAL_CHANGED=${TOTAL_CHANGED:-0}
echo "Total changed lines: $TOTAL_CHANGED"

# Make the total available for later steps
echo "total=$TOTAL_CHANGED" >> "$GITHUB_OUTPUT"

- name: Fail if too many changes
if: ${{ steps.diff_check.outputs.total > 500 }}
run: |
echo "PR has ${{ steps.diff_check.outputs.total }} changed lines, which exceeds the 500-line limit."
echo "Please reduce the size of this PR."
exit 1
10 changes: 5 additions & 5 deletions .github/workflows/publish.yml
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@ on:
release:
types: [created]
workflow_dispatch:

jobs:
build-windows:
runs-on: windows-latest
Expand All @@ -12,7 +12,7 @@ jobs:
packages: write
steps:
- uses: actions/checkout@v2
- run: yarn build:gyp
- run: yarn build:gyp
- uses: actions/upload-artifact@v2
with:
name: windows-binaries
Expand All @@ -32,11 +32,11 @@ jobs:
path: build/Release
- uses: actions/setup-node@v2
with:
node-version: '16.x'
registry-url: 'https://npm.pkg.github.com'
node-version: "16.x"
registry-url: "https://npm.pkg.github.com"
- run: yarn
env:
NODE_AUTH_TOKEN: ${{ secrets.GITHUB_TOKEN }}
NODE_AUTH_TOKEN: ${{ secrets.GITHUB_TOKEN }}
- run: yarn publish
env:
NODE_AUTH_TOKEN: ${{ secrets.GITHUB_TOKEN }}
13 changes: 8 additions & 5 deletions .github/workflows/pull-request.yml
Original file line number Diff line number Diff line change
@@ -1,11 +1,11 @@
name: Some pull request checks
name: Pull request checks

on:
pull_request:

jobs:
type-check:
runs-on: ubuntu-latest
checks:
runs-on: windows-latest

steps:
- name: Checkout code
Expand All @@ -22,5 +22,8 @@ jobs:
- name: Run TypeScript compiler
run: yarn tsc

# - name: Run Vitest
# run: yarn vitest:once
- name: Run Prettier
run: yarn prettier . --check

- name: Run tests
run: yarn test:once
47 changes: 47 additions & 0 deletions .github/workflows/sonar-analysis.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,47 @@
name: SonarCloud code analysis

on:
pull_request:
types: [opened, synchronize, reopened]

jobs:
build:
runs-on: windows-latest

env:
BUILD_WRAPPER_OUT_DIR: build_wrapper_output_directory

steps:
- name: Checkout code
uses: actions/checkout@v4
with:
fetch-depth: 0

- name: Setup Node.js
uses: actions/setup-node@v3
with:
node-version: 18

- name: Install node-gyp
run: npm install -g node-gyp

- name: Install Build Wrapper
uses: SonarSource/sonarqube-scan-action/install-build-wrapper@v5

- name: Run Build Wrapper
run: build-wrapper-win-x86-64.exe --out-dir ${{ env.BUILD_WRAPPER_OUT_DIR }} node-gyp configure build

- run: ls ${{ env.BUILD_WRAPPER_OUT_DIR }}
- run: cat ${{ env.BUILD_WRAPPER_OUT_DIR }}/compile_commands.json
- run: cat ${{ env.BUILD_WRAPPER_OUT_DIR }}/build-wrapper.log
- run: cat ${{ env.BUILD_WRAPPER_OUT_DIR }}/build-wrapper-dump.json

- name: SonarQube Scan
uses: SonarSource/sonarqube-scan-action@v5
env:
SONAR_TOKEN: ${{ secrets.SONAR_TOKEN }}
with:
args: >
--define sonar.cfamily.compile-commands="${{ env.BUILD_WRAPPER_OUT_DIR }}/compile_commands.json"


1 change: 1 addition & 0 deletions .gitignore
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
/.env
/.vscode
/addon.node
/bin
/build
/dist
/examples/tmp
Expand Down
2 changes: 1 addition & 1 deletion examples/drive.ts
Original file line number Diff line number Diff line change
Expand Up @@ -3,5 +3,5 @@ import VirtualDrive from "@/virtual-drive";

import settings from "./settings";

export const drive = new VirtualDrive(settings.syncRootPath, settings.defaultLogPath);
export const drive = new VirtualDrive(settings.syncRootPath, settings.providerid, settings.defaultLogPath);
export const logger = createLogger(settings.defaultLogPath);
4 changes: 2 additions & 2 deletions examples/populate.ts
Original file line number Diff line number Diff line change
@@ -1,9 +1,9 @@
import VirtualDrive from "@/virtual-drive";

import { execSync } from "child_process";
import { join } from "path";
import { v4 } from "uuid";

import VirtualDrive from "@/virtual-drive";

import settings from "./settings";

const rootFileName1 = v4();
Expand Down
4 changes: 2 additions & 2 deletions examples/register.ts
Original file line number Diff line number Diff line change
Expand Up @@ -20,7 +20,7 @@ const handlers = { handleAdd, handleHydrate, handleDehydrate, handleChangeSize }
const notify = { onTaskSuccess: async () => undefined, onTaskProcessing: async () => undefined };
const queueManager = new QueueManager(handlers, notify, settings.queuePersistPath);

drive.registerSyncRoot(settings.driveName, settings.driveVersion, settings.providerid, callbacks, settings.iconPath);
drive.registerSyncRoot(settings.driveName, settings.driveVersion, callbacks, settings.iconPath);
drive.connectSyncRoot();

try {
Expand All @@ -29,5 +29,5 @@ try {
} catch (error) {
logger.error(error);
drive.disconnectSyncRoot();
VirtualDrive.unregisterSyncRoot(settings.syncRootPath);
drive.unregisterSyncRoot();
}
4 changes: 2 additions & 2 deletions examples/unregister.ts
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
import VirtualDrive from "@/virtual-drive";

import { drive } from "./drive";
import { deleteInfoItems } from "./info-items-manager";
import settings from "./settings";

VirtualDrive.unregisterSyncRoot(settings.syncRootPath);
drive.unregisterSyncRoot();
deleteInfoItems();
65 changes: 32 additions & 33 deletions examples/utils.ts
Original file line number Diff line number Diff line change
@@ -1,47 +1,46 @@
import fs from 'fs';
import path from 'path';
import fs from "fs";
import path from "path";

interface FileDetail {
path: string;
size: number;
baseDir: string;
path: string;
size: number;
baseDir: string;
}

function readFilesRecursively(dir: string, fileList: FileDetail[] = []): FileDetail[] {
fs.readdirSync(dir).forEach(file => {
const filePath = path.join(dir, file);
if (fs.statSync(filePath).isDirectory()) {
readFilesRecursively(filePath, fileList);
} else {
fileList.push({
path: filePath,
size: fs.statSync(filePath).size,
baseDir: dir
});
}
});
return fileList;
fs.readdirSync(dir).forEach((file) => {
const filePath = path.join(dir, file);
if (fs.statSync(filePath).isDirectory()) {
readFilesRecursively(filePath, fileList);
} else {
fileList.push({
path: filePath,
size: fs.statSync(filePath).size,
baseDir: dir,
});
}
});
return fileList;
}

function createFilesWithSize(sourceFolder: string, destFolder: string): void {
const files: FileDetail[] = readFilesRecursively(sourceFolder);
const files: FileDetail[] = readFilesRecursively(sourceFolder);

if (!fs.existsSync(destFolder)) {
fs.mkdirSync(destFolder, { recursive: true });
}

files.forEach(file => {
const relativePath = path.relative(file.baseDir, file.path);
const destFilePath = path.join(file.baseDir.replace(sourceFolder, destFolder), relativePath);//path.join(destFolder, relativePath);
const destFileDir = file.baseDir.replace(sourceFolder, destFolder);//path.dirname(destFilePath);
if (!fs.existsSync(destFolder)) {
fs.mkdirSync(destFolder, { recursive: true });
}

if (!fs.existsSync(destFileDir)){
fs.mkdirSync(destFileDir, { recursive: true });
}
files.forEach((file) => {
const relativePath = path.relative(file.baseDir, file.path);
const destFilePath = path.join(file.baseDir.replace(sourceFolder, destFolder), relativePath); //path.join(destFolder, relativePath);
const destFileDir = file.baseDir.replace(sourceFolder, destFolder); //path.dirname(destFilePath);

fs.writeFileSync(destFilePath, Buffer.alloc(file.size));
});
if (!fs.existsSync(destFileDir)) {
fs.mkdirSync(destFileDir, { recursive: true });
}

fs.writeFileSync(destFilePath, Buffer.alloc(file.size));
});
}

export { createFilesWithSize };
export { createFilesWithSize };
53 changes: 11 additions & 42 deletions examples/utils/generate-random-file-tree.ts
Original file line number Diff line number Diff line change
@@ -1,8 +1,9 @@
import VirtualDrive from '@/virtual-drive';
import { v4 as uuidv4 } from 'uuid';
import { v4 as uuidv4 } from "uuid";

import VirtualDrive from "@/virtual-drive";

interface GenerateOptions {
rootPath: string
rootPath: string;
depth: number;
filesPerFolder: number;
foldersPerLevel: number;
Expand All @@ -26,18 +27,7 @@ function randomNormal(mean: number, stdDev: number): number {
}

function getRandomExtension(): string {
const extensions = [
".txt",
".pdf",
".rar",
".jpg",
".docx",
".xlsx",
".mp4",
".mkv",
".json",
""
];
const extensions = [".txt", ".pdf", ".rar", ".jpg", ".docx", ".xlsx", ".mp4", ".mkv", ".json", ""];
const index = Math.floor(Math.random() * extensions.length);
return extensions[index];
}
Expand All @@ -47,17 +37,11 @@ async function createStructureRecursively(
currentPath: string,
level: number,
options: GenerateOptions,
result: Record<string, string>
result: Record<string, string>,
): Promise<void> {
if (level < 0) return;

const {
filesPerFolder,
foldersPerLevel,
meanSize,
stdDev,
timeOffset
} = options;
const { filesPerFolder, foldersPerLevel, meanSize, stdDev, timeOffset } = options;

for (let i = 0; i < filesPerFolder; i++) {
const fileName = `file_${generateRandomId()}${getRandomExtension()}`;
Expand All @@ -69,13 +53,7 @@ async function createStructureRecursively(
const createdAt = Date.now() - (timeOffset || 0);
const updatedAt = Date.now() - (timeOffset || 0) + 2000;

drive.createFileByPath(
fullPath,
fileId,
fileSize,
createdAt,
updatedAt
);
drive.createFileByPath(fullPath, fileId, fileSize, createdAt, updatedAt);

result[fileId] = fullPath;
}
Expand All @@ -88,22 +66,13 @@ async function createStructureRecursively(
const createdAt = Date.now() - (timeOffset || 0) - 10000; // Ejemplo
const updatedAt = Date.now() - (timeOffset || 0);

drive.createFolderByPath(
newFolderPath,
folderId,
1000,
createdAt,
updatedAt
);
drive.createFolderByPath(newFolderPath, folderId, 1000, createdAt, updatedAt);

await createStructureRecursively(drive, newFolderPath, level - 1, options, result);
}
}

async function generateRandomFilesAndFolders(
drive: VirtualDrive,
options: GenerateOptions
): Promise<Record<string, string>> {
async function generateRandomFilesAndFolders(drive: VirtualDrive, options: GenerateOptions): Promise<Record<string, string>> {
const { rootPath } = options;

const result: Record<string, string> = {};
Expand All @@ -114,4 +83,4 @@ async function generateRandomFilesAndFolders(
}

export { generateRandomFilesAndFolders };
export type { GenerateOptions }
export type { GenerateOptions };
Loading
Loading