Skip to content

Commit

Permalink
Fix metadata for links (#52)
Browse files Browse the repository at this point in the history
  • Loading branch information
ebrehault authored Apr 16, 2024
1 parent e552a4a commit 76fe226
Show file tree
Hide file tree
Showing 4 changed files with 28 additions and 22 deletions.
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.19",
"version": "1.2.20",
"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.20 (2024-04-16)

- Fix metadata for links

# 1.2.19 (2024-04-15)

- Support syncing of the root folder for the different connectors.
Expand Down
38 changes: 21 additions & 17 deletions server/src/logic/sync/domain/nuclia-cloud.ts
Original file line number Diff line number Diff line change
Expand Up @@ -49,19 +49,7 @@ export class NucliaCloud {
const text = data.text;
const buffer = data.buffer;
const resourceData: Partial<ICreateResource> = { title: filename };
if (data.metadata.labels) {
resourceData.usermetadata = { classifications: data.metadata?.labels };
}
if (data.metadata.path) {
let path = data.metadata.path;
if (path && !path.startsWith('/')) {
path = `/${path}`;
}
resourceData.origin = { path };
}
if (data.metadata?.groups) {
resourceData.security = { access_groups: data.metadata.groups };
}
data = this.setMetadata(data, data.metadata);
if (buffer || text) {
return this.getKb().pipe(
switchMap((kb) =>
Expand Down Expand Up @@ -170,7 +158,7 @@ export class NucliaCloud {
linkExtraParams?: LinkExtraParams,
): Observable<void> {
const slug = sha256(originalId);
const payload: ICreateResource = {
let payload: ICreateResource = {
title: filename,
slug,
origin: { url: data.uri },
Expand All @@ -193,9 +181,8 @@ export class NucliaCloud {
};
payload.icon = 'application/stf-link';
}
if (metadata.labels) {
payload.usermetadata = { classifications: metadata.labels };
}
payload = this.setMetadata(payload, metadata);

return this.getKb().pipe(
switchMap((kb) =>
kb.createOrUpdateResource(payload).pipe(
Expand Down Expand Up @@ -229,4 +216,21 @@ export class NucliaCloud {
.filter((item) => item.key && item.value)
.reduce((acc, curr) => ({ ...acc, [curr.key]: curr.value }), {} as { [key: string]: string });
}

private setMetadata(resource: Partial<ICreateResource>, metadata: any): Partial<ICreateResource> {
if (metadata.labels) {
resource.usermetadata = { classifications: metadata?.labels };
}
if (metadata.path) {
let path = metadata.path;
if (path && !path.startsWith('/')) {
path = `/${path}`;
}
resource.origin = { ...(resource.origin || {}), path };
}
if (metadata?.groups) {
resource.security = { access_groups: metadata.groups };
}
return resource;
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -82,7 +82,7 @@ export class SyncSingleFile implements SyncSingleFileUseCase {
} else if (data.type === ContentType.text && data.text) {
return nucliaConnector.upload(item.originalId, item.title, {
text: data.text,
metadata: { labels: sync.labels, groups: data.extra?.groups },
metadata: { ...item.metadata, labels: sync.labels, groups: data.extra?.groups },
});
} else if (data.type === ContentType.link && data.link) {
const mimeType =
Expand All @@ -94,9 +94,7 @@ export class SyncSingleFile implements SyncSingleFileUseCase {
item.title,
data.link,
type,
{
labels: sync.labels,
},
{ ...item.metadata, labels: sync.labels, groups: data.extra?.groups },
{
headers: sync.connector.parameters.headers,
cookies: sync.connector.parameters.cookies,
Expand Down

0 comments on commit 76fe226

Please sign in to comment.