Skip to content
This repository has been archived by the owner on Sep 9, 2024. It is now read-only.

Commit

Permalink
API_Design (#77)
Browse files Browse the repository at this point in the history
* API_Design

* Minor Fixes

* Modification and Fixes
  • Loading branch information
Vivek-Lahole authored May 10, 2024
1 parent 78a9e42 commit 53d025b
Show file tree
Hide file tree
Showing 9 changed files with 189 additions and 143 deletions.
6 changes: 4 additions & 2 deletions packages/apps/webconnector/src/services/oauth.ts
Original file line number Diff line number Diff line change
Expand Up @@ -29,13 +29,15 @@ class webConnectorOauth extends OauthService {
return {
name: AppNameDefinitions.WEBCONNECTOR,
logo: "/asana.svg",
description: "Web Connector",
description:
"🌐 WebConnector is an innovative app designed to streamline the process of data extraction from websites. Simply enter a URL and 🚀 quickly gather all relevant data from the webpage. This tool makes it easier to access and analyze online information efficiently",
oauth_url: ``,
slug: AppNameDefinitions.WEBCONNECTOR,
category: AppCategoryDefinitions.SOTWARE_DEVELOPMENT,
developer: "Ocular AI",
images: ["/asana.svg"],
overview: "Web Connector",
overview:
"WebConnector: Your Gateway to Efficient Web Data Extraction 🌍✨",
docs: "https://developer.atlassian.com/",
website: "https://www.atlassian.com/software/confluence",
};
Expand Down
107 changes: 49 additions & 58 deletions packages/apps/webconnector/src/services/webConnector.ts
Original file line number Diff line number Diff line change
Expand Up @@ -71,7 +71,7 @@ export default class webConnectorService extends TransactionBaseService {
const pageDocument: IndexableDocument = {
id: page.location,
organisationId: org.id,
title: page.text,
title: this.generateTitleFromParagraph(page.text),
source: AppNameDefinitions.WEBCONNECTOR,
sections: [
{
Expand All @@ -97,69 +97,32 @@ export default class webConnectorService extends TransactionBaseService {

await this.oauthService_.update(oauth.id, { last_sync: new Date() });

// const current_org = await this.organisationService.listInstalledApps();
// const installed_apps: any = current_org.installed_apps;
// const webConnector_index = installed_apps.findIndex(
// (app) => app.name === AppNameDefinitions.WEBCONNECTOR
// );

// if (webConnector_index !== -1) {
// const index = installed_apps[webConnector_index].links.findIndex(
// (link) => link.id === link_id
// );

// const updatedLink = {
// id: link_id,
// location: base_url,
// status: "success",
// };

// if (index !== -1) {
// installed_apps[webConnector_index].links[index] = {
// ...installed_apps[webConnector_index].links[index],
// ...updatedLink,
// };
// }

// await this.organisationService.update(org.id, {
// installed_apps,
// });
// }
const data = {
link: base_url,
link_id,
emit_event: false,
status: "success",
};
await this.organisationService.updateInstalledApp(
AppNameDefinitions.WEBCONNECTOR,
data
);

this.logger_.info(
`Finished oculation of Web Connector for ${org.id} organisation`
);
} catch (error) {
console.error("Error fetching web commector content:", error);

// const current_org = await this.organisationService.listInstalledApps();
// const installed_apps: any = current_org.installed_apps;
// const webConnector_index = installed_apps.findIndex(
// (app) => app.name === AppNameDefinitions.WEBCONNECTOR
// );

// if (webConnector_index !== -1) {
// const index = installed_apps[webConnector_index].links.findIndex(
// (link) => link.id === link_id
// );

// const updatedLink = {
// id: link_id,
// location: base_url,
// status: "failed",
// };

// if (index !== -1) {
// installed_apps[webConnector_index].links[index] = {
// ...installed_apps[webConnector_index].links[index],
// ...updatedLink,
// };
// }

// await this.organisationService.update(org.id, {
// installed_apps,
// });
// }
const data = {
link: base_url,
link_id,
emit_event: false,
status: "failed",
};
await this.organisationService.updateInstalledApp(
AppNameDefinitions.WEBCONNECTOR,
data
);
}
}

Expand Down Expand Up @@ -266,4 +229,32 @@ export default class webConnectorService extends TransactionBaseService {

return new Set(internalLinks);
}

generateTitleFromParagraph(paragraph: string) {
// Find the index of the first line break or full stop
const lineBreakIndex = paragraph.indexOf("\n");
const fullStopIndex = paragraph.indexOf(".");

// Determine the position of the title end (whichever comes first)
let titleEndIndex;
if (lineBreakIndex !== -1 && fullStopIndex !== -1) {
titleEndIndex = Math.min(lineBreakIndex, fullStopIndex);
} else if (lineBreakIndex !== -1) {
titleEndIndex = lineBreakIndex;
} else if (fullStopIndex !== -1) {
titleEndIndex = fullStopIndex;
} else {
// If no line break or full stop is found, use the entire paragraph as title
return paragraph.trim(); // Trim leading and trailing whitespace
}

// Extract the title from the beginning of the paragraph up to titleEndIndex
let title = paragraph.substring(0, titleEndIndex).trim();

if (title.length === 0) {
// Provide a default title or appropriate fallback
title = "Notion Page"; // Example default title
}
return title;
}
}
30 changes: 20 additions & 10 deletions packages/ocular-ui/components/marketplace/webConnector.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -79,19 +79,29 @@ export default function WebConnector({ links }: { links: Link[] }) {
try {
// const resp = await api.apps.saveWebConnectorLink();
// console.log('response', resp.data);
const response = await api.apps.saveWebConnectorLink({
const response = await api.apps.updateApp({
link: data as string,
name: 'webConnector' as string,
});
console.log('LINK RESPONSE', response.data);
const updatedLinkData: Link[] = [
...linkData,
{
location: data,
status: 'processing',
},
];
setLinkdata(updatedLinkData);
if (response.status === 200) {
const updatedLinkData: Link[] = [
...linkData,
{
location: data,
status: 'processing',
},
];
setLinkdata(updatedLinkData);
} else {
const updatedLinkData: Link[] = [
...linkData,
{
location: data,
status: 'failed',
},
];
setLinkdata(updatedLinkData);
}
} catch (error) {
console.error('Error fetching integrations:', error);
}
Expand Down
3 changes: 0 additions & 3 deletions packages/ocular-ui/pages/dashboard/marketplace/index.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -29,9 +29,6 @@ export const metadata: Metadata = {
},
};

interface Props {
integrations: Integration[];
}

interface IntegrationsByCategory {
[key: string]: Integration[];
Expand Down
4 changes: 2 additions & 2 deletions packages/ocular-ui/services/admin-api.ts
Original file line number Diff line number Diff line change
Expand Up @@ -23,8 +23,8 @@ export default {
const path = `/admin/apps/${id}`;
return ocularRequest('GET', path);
},
saveWebConnectorLink(data: any) {
const path = `/admin/apps/savelink`;
updateApp(data: any) {
const path = `/admin/apps/updateapp`;
return ocularRequest('POST', path, data);
},
},
Expand Down
2 changes: 1 addition & 1 deletion packages/ocular/src/api/routes/admin/apps/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -33,7 +33,7 @@ export default (app) => {
middlewares.wrap(require("./list-installed-apps").default)
);

route.post("/savelink", middlewares.wrap(require("./webConnector").default));
route.post("/updateapp", middlewares.wrap(require("./updateApp").default));
return app;
};

Expand Down
45 changes: 45 additions & 0 deletions packages/ocular/src/api/routes/admin/apps/updateApp.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,45 @@
import { IsNotEmpty, IsString, IsOptional, IsEnum } from "class-validator";
import { validator } from "@ocular/utils";
import { OAuthService, OrganisationService } from "../../../../services";
import { AppNameDefinitions } from "@ocular/types";
import { EventBusService } from "../../../../services";
const { v4: uuidv4 } = require("uuid");

export default async (req, res) => {
const validated = await validator(PostAppsReq, req.body);
const eventBus_: EventBusService = req.scope.resolve("eventBusService");
const loggedInUser = req.scope.resolve("loggedInUser");
const organisationService: OrganisationService = req.scope.resolve(
"organisationService"
);

const link_id = uuidv4();

const data = {
link: validated.link,
link_id,
status: "processing",
emit_event: true,
};

const installed_apps = await organisationService.updateInstalledApp(
validated.name,
data
);

if (installed_apps) {
res.status(200).json({ message: "Link saved successfully!" });
} else {
res.status(500).json({ error: "Internal Server Error" });
}
};

export class PostAppsReq {
@IsNotEmpty()
@IsEnum(AppNameDefinitions)
name: AppNameDefinitions;

@IsString()
@IsNotEmpty()
link: string;
}
64 changes: 0 additions & 64 deletions packages/ocular/src/api/routes/admin/apps/webConnector.ts

This file was deleted.

Loading

0 comments on commit 53d025b

Please sign in to comment.