Skip to content

Commit

Permalink
Ericbrehault/sc 9585/support xpath selector when uploading links (#47)
Browse files Browse the repository at this point in the history
* support xpath selector

* clean up useless try/catch
  • Loading branch information
ebrehault authored Apr 5, 2024
1 parent 9685d87 commit d921324
Show file tree
Hide file tree
Showing 16 changed files with 151 additions and 227 deletions.
8 changes: 4 additions & 4 deletions electron-app/package-lock.json

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

2 changes: 1 addition & 1 deletion electron-app/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -22,7 +22,7 @@
},
"license": "MIT",
"dependencies": {
"@nuclia/core": "^1.14.2",
"@nuclia/core": "^1.14.4",
"cheerio": "^1.0.0-rc.12",
"commander": "^11.1.0",
"compression": "^1.7.4",
Expand Down
2 changes: 1 addition & 1 deletion package.json
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
{
"name": "nuclia-sync-agent-app",
"version": "1.2.14",
"version": "1.2.15",
"description": "This is a Nuclia Sync Agent App",
"main": "build/index.js",
"scripts": {
Expand Down
4 changes: 4 additions & 0 deletions server/CHANGELOG.md
Original file line number Diff line number Diff line change
@@ -1,3 +1,7 @@
# 1.2.15 (2024-04-05)

- Support XPath selector in sitemap and RSS connectors

# 1.2.13 (2024-04-04)

- Report errors from the different connectors
Expand Down
8 changes: 4 additions & 4 deletions server/package-lock.json

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

2 changes: 1 addition & 1 deletion server/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -25,7 +25,7 @@
"start-server": "npm run compile && node build/start-file-system-server.js"
},
"dependencies": {
"@nuclia/core": "^1.14.2",
"@nuclia/core": "^1.14.4",
"cheerio": "^1.0.0-rc.12",
"commander": "^11.1.0",
"compression": "^1.7.4",
Expand Down
1 change: 1 addition & 0 deletions server/src/logic/connector/domain/connector.ts
Original file line number Diff line number Diff line change
Expand Up @@ -12,6 +12,7 @@ export interface Link {
uri: string;
extra_headers: { [key: string]: string };
cssSelector?: string;
xpathSelector?: string;
}

export interface ConnectorParameters {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -47,25 +47,17 @@ export class ConfluenceImpl implements IConnector {
items: [],
});
}
try {
return forkJoin((folders || []).map((folder) => this._getFiles('', false, folder.originalId))).pipe(
map((results) => {
const result: { items: SyncItem[] } = {
items: [],
};
results.forEach((res) => {
result.items = [...result.items, ...res.items];
});
return result;
}),
);
} catch (err) {
console.error(err);
return of({
items: [],
error: `Error fetching files: ${err}`,
});
}
return forkJoin((folders || []).map((folder) => this._getFiles('', false, folder.originalId))).pipe(
map((results) => {
const result: { items: SyncItem[] } = {
items: [],
};
results.forEach((res) => {
result.items = [...result.items, ...res.items];
});
return result;
}),
);
}

getLastModified(since: string, folders?: SyncItem[]): Observable<SearchResults> {
Expand All @@ -74,17 +66,9 @@ export class ConfluenceImpl implements IConnector {
items: [],
});
} else {
try {
return forkJoin((folders || []).map((folder) => this._getFiles('', false, folder.originalId, since))).pipe(
map((results) => ({ items: results.reduce((acc, result) => acc.concat(result.items), [] as SyncItem[]) })),
);
} catch (err) {
console.error(err);
return of({
items: [],
error: `Error fetching last modified files: ${err}`,
});
}
return forkJoin((folders || []).map((folder) => this._getFiles('', false, folder.originalId, since))).pipe(
map((results) => ({ items: results.reduce((acc, result) => acc.concat(result.items), [] as SyncItem[]) })),
);
}
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -46,24 +46,17 @@ export class DropboxImpl extends OAuthBaseConnector implements IConnector {
items: [],
});
}
try {
return forkJoin((folders || []).map((folder) => this._getFiles('', false, folder.originalId))).pipe(
map((results) => {
const items = results.reduce(
(acc, result) => acc.concat(result.items.filter((item) => item.modifiedGMT && item.modifiedGMT > since)),
[] as SyncItem[],
);
return {
items,
};
}),
);
} catch (err) {
return of({
items: [],
error: `Error fetching last modified files: ${err}`,
});
}
return forkJoin((folders || []).map((folder) => this._getFiles('', false, folder.originalId))).pipe(
map((results) => {
const items = results.reduce(
(acc, result) => acc.concat(result.items.filter((item) => item.modifiedGMT && item.modifiedGMT > since)),
[] as SyncItem[],
);
return {
items,
};
}),
);
}

getFilesFromFolders(folders: SyncItem[]): Observable<SearchResults> {
Expand All @@ -72,24 +65,17 @@ export class DropboxImpl extends OAuthBaseConnector implements IConnector {
items: [],
});
}
try {
return forkJoin((folders || []).map((folder) => this._getFiles('', false, folder.originalId))).pipe(
map((results) => {
const result: { items: SyncItem[] } = {
items: [],
};
results.forEach((res) => {
result.items = [...result.items, ...res.items];
});
return result;
}),
);
} catch (err) {
return of({
items: [],
error: `Error fetching files: ${err}`,
});
}
return forkJoin((folders || []).map((folder) => this._getFiles('', false, folder.originalId))).pipe(
map((results) => {
const result: { items: SyncItem[] } = {
items: [],
};
results.forEach((res) => {
result.items = [...result.items, ...res.items];
});
return result;
}),
);
}

getFolders(query?: string | undefined): Observable<SearchResults> {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -46,23 +46,17 @@ class FolderImpl implements IConnector {
items: [],
});
}
try {
return forkJoin((folders || []).map((folder) => this._getFiles(folder.originalId))).pipe(
map((results) => {
const result: { items: SyncItem[] } = {
items: [],
};
results.forEach((res) => {
result.items = [...result.items, ...res.items];
});
return result;
}),
);
} catch (err) {
return of({
items: [],
});
}
return forkJoin((folders || []).map((folder) => this._getFiles(folder.originalId))).pipe(
map((results) => {
const result: { items: SyncItem[] } = {
items: [],
};
results.forEach((res) => {
result.items = [...result.items, ...res.items];
});
return result;
}),
);
}

getLastModified(since: string, folders?: SyncItem[]): Observable<SearchResults> {
Expand All @@ -72,36 +66,29 @@ class FolderImpl implements IConnector {
});
}

try {
return forkJoin(
(folders || []).map((folder) =>
this._getFiles(folder.originalId).pipe(
switchMap((results) =>
from(this.getFilesModifiedSince(results.items, since)).pipe(
map((items) => ({ items, error: results.error })),
),
return forkJoin(
(folders || []).map((folder) =>
this._getFiles(folder.originalId).pipe(
switchMap((results) =>
from(this.getFilesModifiedSince(results.items, since)).pipe(
map((items) => ({ items, error: results.error })),
),
),
),
).pipe(
map((results) => {
const items = results.reduce((acc, result) => acc.concat(result.items), [] as SyncItem[]);
const errors = results
.map((result) => result.error)
.filter((error) => !!error)
.join('. ');
return {
items,
error: errors,
};
}),
);
} catch (err) {
return of({
items: [],
error: 'Error getting last modified files.',
});
}
),
).pipe(
map((results) => {
const items = results.reduce((acc, result) => acc.concat(result.items), [] as SyncItem[]);
const errors = results
.map((result) => result.error)
.filter((error) => !!error)
.join('. ');
return {
items,
error: errors,
};
}),
);
}

private _getFiles(path: string, query?: string): Observable<SearchResults> {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -47,24 +47,17 @@ export class GDriveImpl extends OAuthBaseConnector implements IConnector {
items: [],
});
}
try {
return forkJoin((folders || []).map((folder) => this._getFileItems('', folder.uuid))).pipe(
map((results) => {
const items = results.reduce(
(acc, result) => acc.concat(result.items.filter((item) => item.modifiedGMT && item.modifiedGMT > since)),
[] as SyncItem[],
);
return {
items,
};
}),
);
} catch (err) {
return of({
items: [],
error: `Error fetching last modified files: ${err}`,
});
}
return forkJoin((folders || []).map((folder) => this._getFileItems('', folder.uuid))).pipe(
map((results) => {
const items = results.reduce(
(acc, result) => acc.concat(result.items.filter((item) => item.modifiedGMT && item.modifiedGMT > since)),
[] as SyncItem[],
);
return {
items,
};
}),
);
}

getFilesFromFolders(folders: SyncItem[]): Observable<SearchResults> {
Expand All @@ -73,24 +66,17 @@ export class GDriveImpl extends OAuthBaseConnector implements IConnector {
items: [],
});
}
try {
return forkJoin((folders || []).map((folder) => this._getFileItems('', folder.uuid))).pipe(
map((results) => {
const result: { items: SyncItem[] } = {
items: [],
};
results.forEach((res) => {
result.items = [...result.items, ...res.items];
});
return result;
}),
);
} catch (err) {
return of({
items: [],
error: `Error fetching files: ${err}`,
});
}
return forkJoin((folders || []).map((folder) => this._getFileItems('', folder.uuid))).pipe(
map((results) => {
const result: { items: SyncItem[] } = {
items: [],
};
results.forEach((res) => {
result.items = [...result.items, ...res.items];
});
return result;
}),
);
}

getFolders(query?: string | undefined): Observable<SearchResults> {
Expand Down
Loading

0 comments on commit d921324

Please sign in to comment.