Skip to content

Commit

Permalink
fix: ipc, ignorer, feat: readme
Browse files Browse the repository at this point in the history
  • Loading branch information
Dwynr committed Jul 19, 2024
1 parent a863c0c commit 3552c86
Show file tree
Hide file tree
Showing 7 changed files with 388 additions and 233 deletions.
60 changes: 59 additions & 1 deletion README.md
Original file line number Diff line number Diff line change
@@ -1 +1,59 @@
work in progress, do not use it yet nor report issues/request features
<br/>
<p align="center">
<h3 align="center">Filen Sync</h3>

<p align="center">
A package to sync local and remote directories.
<br/>
<br/>
</p>
</p>

![Contributors](https://img.shields.io/github/contributors/FilenCloudDienste/filen-sync?color=dark-green) ![Forks](https://img.shields.io/github/forks/FilenCloudDienste/filen-sync?style=social) ![Stargazers](https://img.shields.io/github/stars/FilenCloudDienste/filen-sync?style=social) ![Issues](https://img.shields.io/github/issues/FilenCloudDienste/filen-sync) ![License](https://img.shields.io/github/license/FilenCloudDienste/filen-sync)

# Attention

The package is still a work in progress. DO NOT USE IT IN PRODUCTION YET. Class names, function names, types, definitions, constants etc. are subject to change until we release a fully tested and stable version.

### Installation

1. Install using NPM

```sh
npm install @filen/sync@latest
```

2. Initialize the server and query it using aws-sdk

```typescript
import Sync from "@filen/sync"

const sync = new Sync({
syncPairs: [
{
uuid: "UUIDV4", // Only used locally to identify the sync pair
localPath: pathModule.join(__dirname, "sync"), // Local absolute path
remotePath: "/sync", // Remote absolute path (UNIX style)
remoteParentUUID: "UUIDV4", // UUIDv4 of the remote parent directory
mode: "twoWay", // Sync mode
paused: false,
excludeDotFiles: true,
name: "Sync" // Only used locally to identify the sync pair
}
],
sdk: new FilenSDK(), // You can either directly pass a configured FilenSDK instance or instantiate a new SDK instance when passing `sdkConfig` (optional)
sdkConfig, // FilenSDK config object (omit when SDK instance is passed, needed when no SDK instance is passed)
dbPath: pathModule.join(__dirname, "db"), // Used to store sync state and other data
runOnce: false, // Run the sync once
onMessage(message) {
console.log(message.type)
}
})

// Start the sync
await server.initialize()
```

## License

Distributed under the AGPL-3.0 License. See [LICENSE](https://github.com/FilenCloudDienste/filen-sync/blob/main/LICENSE.md) for more information.
2 changes: 1 addition & 1 deletion package.json
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
{
"name": "@filen/sync",
"version": "0.1.5",
"version": "0.1.6",
"description": "Filen Sync",
"main": "dist/index.js",
"types": "dist/index.d.ts",
Expand Down
58 changes: 35 additions & 23 deletions src/ignorer.ts
Original file line number Diff line number Diff line change
Expand Up @@ -8,14 +8,42 @@ export const IGNORER_VERSION = 1
export class Ignorer {
private readonly sync: Sync
private instance = ignore()
private readonly name: string = "localIgnorer"
private readonly name: string = "ignorer"
private readonly cache: Record<string, boolean> = {}

public constructor(sync: Sync, name: string = "localIgnorer") {
public constructor(sync: Sync, name: string = "ignorer") {
this.sync = sync
this.name = name
}

public async fetch(): Promise<string> {
const filePath = pathModule.join(this.sync.dbPath, this.name, `v${IGNORER_VERSION}`, this.sync.syncPair.uuid, "filenIgnore")

await fs.ensureDir(pathModule.dirname(filePath))

const exists = await fs.exists(filePath)

if (!exists) {
return ""
}

const stats = await fs.stat(filePath)

if (stats.size === 0) {
return ""
}

const readContent = await fs.readFile(filePath, {
encoding: "utf-8"
})

if (readContent.length === 0) {
return ""
}

return readContent
}

public async initialize(passedContent?: string): Promise<void> {
let content: string = ""
const filePath = pathModule.join(this.sync.dbPath, this.name, `v${IGNORER_VERSION}`, this.sync.syncPair.uuid, "filenIgnore")
Expand All @@ -29,30 +57,14 @@ export class Ignorer {

content = passedContent
} else {
const exists = await fs.exists(filePath)

if (!exists) {
return
}

const stats = await fs.stat(filePath)

if (stats.size === 0) {
return
}

const readContent = await fs.readFile(filePath, {
encoding: "utf-8"
})
content = await this.fetch()
}

if (readContent.length === 0) {
return
}
this.instance = ignore()

content = readContent
if (content.length > 0) {
this.instance.add(content)
}

this.instance = ignore().add(content)
}

public async update(content?: string): Promise<void> {
Expand Down
Loading

0 comments on commit 3552c86

Please sign in to comment.