From 19030f7f722b24e1bd39af2514b8f69ddd100651 Mon Sep 17 00:00:00 2001 From: Romaric Mourgues Date: Tue, 18 Apr 2023 09:13:08 +0200 Subject: [PATCH] Fix globalResolve bad import --- Documentation/docs/.vitepress/config.js | 4 - .../backend/node/src/cli/cmds/applications.ts | 14 --- tdrive/backend/node/src/cli/cmds/migration.ts | 14 --- tdrive/backend/node/src/cli/cmds/workspace.ts | 14 --- .../node/src/cli/cmds/workspace_cmds/list.ts | 47 --------- .../node/src/cli/cmds/workspace_cmds/user.ts | 49 ---------- .../src/cli/utils/copy-messages/.gitignore | 2 - .../src/cli/utils/copy-messages/README.md | 4 - .../node/src/cli/utils/copy-messages/index.js | 98 ------------------- .../src/cli/utils/copy-messages/package.json | 9 -- .../src/cli/utils/repair-threads/README.md | 4 - .../src/cli/utils/repair-threads/index.js | 96 ------------------ .../src/cli/utils/repair-threads/package.json | 9 -- .../src/services/applications-api/index.ts | 4 +- 14 files changed, 3 insertions(+), 365 deletions(-) delete mode 100644 tdrive/backend/node/src/cli/cmds/applications.ts delete mode 100644 tdrive/backend/node/src/cli/cmds/migration.ts delete mode 100644 tdrive/backend/node/src/cli/cmds/workspace.ts delete mode 100644 tdrive/backend/node/src/cli/cmds/workspace_cmds/list.ts delete mode 100644 tdrive/backend/node/src/cli/cmds/workspace_cmds/user.ts delete mode 100644 tdrive/backend/node/src/cli/utils/copy-messages/.gitignore delete mode 100644 tdrive/backend/node/src/cli/utils/copy-messages/README.md delete mode 100644 tdrive/backend/node/src/cli/utils/copy-messages/index.js delete mode 100644 tdrive/backend/node/src/cli/utils/copy-messages/package.json delete mode 100644 tdrive/backend/node/src/cli/utils/repair-threads/README.md delete mode 100644 tdrive/backend/node/src/cli/utils/repair-threads/index.js delete mode 100644 tdrive/backend/node/src/cli/utils/repair-threads/package.json diff --git a/Documentation/docs/.vitepress/config.js b/Documentation/docs/.vitepress/config.js index 0e677dbf..08c85c65 100644 --- a/Documentation/docs/.vitepress/config.js +++ b/Documentation/docs/.vitepress/config.js @@ -45,10 +45,6 @@ export default { text: "Get started", link: "/internal-documentation/backend-services/intro/README.md", }, - { - text: "Applications", - link: "/internal-documentation/backend-services/applications/README.md", - }, { text: "Documents", link: "/internal-documentation/backend-services/documents/README.md", diff --git a/tdrive/backend/node/src/cli/cmds/applications.ts b/tdrive/backend/node/src/cli/cmds/applications.ts deleted file mode 100644 index b389590d..00000000 --- a/tdrive/backend/node/src/cli/cmds/applications.ts +++ /dev/null @@ -1,14 +0,0 @@ -import { CommandModule } from "yargs"; - -const command: CommandModule = { - describe: "Manage Tdrive Applications", - command: "applications ", - builder: yargs => - yargs.commandDir("applications_cmds", { - visit: commandModule => commandModule.default, - }), - // eslint-disable-next-line @typescript-eslint/no-empty-function - handler: () => {}, -}; - -export default command; diff --git a/tdrive/backend/node/src/cli/cmds/migration.ts b/tdrive/backend/node/src/cli/cmds/migration.ts deleted file mode 100644 index 99c0884c..00000000 --- a/tdrive/backend/node/src/cli/cmds/migration.ts +++ /dev/null @@ -1,14 +0,0 @@ -import { CommandModule } from "yargs"; - -const command: CommandModule = { - describe: "Migrate your php message to node", - command: "migration ", - builder: yargs => - yargs.commandDir("migration_cmds", { - visit: commandModule => commandModule.default, - }), - // eslint-disable-next-line @typescript-eslint/no-empty-function - handler: () => {}, -}; - -export default command; diff --git a/tdrive/backend/node/src/cli/cmds/workspace.ts b/tdrive/backend/node/src/cli/cmds/workspace.ts deleted file mode 100644 index 95686ec5..00000000 --- a/tdrive/backend/node/src/cli/cmds/workspace.ts +++ /dev/null @@ -1,14 +0,0 @@ -import { CommandModule } from "yargs"; - -const command: CommandModule = { - describe: "Manage Tdrive Workspaces", - command: "workspace ", - builder: yargs => - yargs.commandDir("workspace_cmds", { - visit: commandModule => commandModule.default, - }), - // eslint-disable-next-line @typescript-eslint/no-empty-function - handler: () => {}, -}; - -export default command; diff --git a/tdrive/backend/node/src/cli/cmds/workspace_cmds/list.ts b/tdrive/backend/node/src/cli/cmds/workspace_cmds/list.ts deleted file mode 100644 index d11e9e18..00000000 --- a/tdrive/backend/node/src/cli/cmds/workspace_cmds/list.ts +++ /dev/null @@ -1,47 +0,0 @@ -import yargs from "yargs"; -import ora from "ora"; -import Table from "cli-table"; -import tdrive from "../../../tdrive"; -import gr from "../../../services/global-resolver"; -/** - * Merge command parameters. Check the builder definition below for more details. - */ -type ListParams = { - size: string; -}; - -const services = [ - "platform-services", - "user", - "search", - "channels", - "notifications", - "database", - "webserver", - "message-queue", -]; - -const command: yargs.CommandModule = { - command: "list", - describe: "List Tdrive workspaces", - builder: { - size: { - default: "50", - type: "string", - description: "Number of workspaces to fetch", - }, - }, - handler: async argv => { - const table = new Table({ head: ["ID", "Name"], colWidths: [40, 50] }); - const spinner = ora({ text: "List Tdrive workspaces" }).start(); - const platform = await tdrive.run(services); - await gr.doInit(platform); - const workspaces = await gr.services.workspaces.list({ limitStr: argv.size }); - - spinner.stop(); - workspaces.getEntities().forEach(ws => table.push([ws.id, ws.name])); - console.log(table.toString()); - }, -}; - -export default command; diff --git a/tdrive/backend/node/src/cli/cmds/workspace_cmds/user.ts b/tdrive/backend/node/src/cli/cmds/workspace_cmds/user.ts deleted file mode 100644 index 3388e5ff..00000000 --- a/tdrive/backend/node/src/cli/cmds/workspace_cmds/user.ts +++ /dev/null @@ -1,49 +0,0 @@ -import yargs from "yargs"; -import ora from "ora"; -import Table from "cli-table"; -import tdrive from "../../../tdrive"; -import gr from "../../../services/global-resolver"; -/** - * Merge command parameters. Check the builder definition below for more details. - */ -type ListParams = { - id: string; -}; - -const services = [ - "platform-services", - "user", - "search", - "channels", - "notifications", - "database", - "webserver", - "message-queue", -]; - -const command: yargs.CommandModule = { - command: "user", - describe: "List workspace ers", - builder: { - id: { - default: "f339d54a-e833-11ea-92c3-0242ac120004", - type: "string", - description: "Workspace ID", - }, - }, - handler: async argv => { - const table = new Table({ head: ["user ID", "Date Added"], colWidths: [40, 40] }); - const spinner = ora({ text: "Retrieving workspace users" }).start(); - const platform = await tdrive.run(services); - await gr.doInit(platform); - const users = await gr.services.workspaces.getUsers({ workspaceId: argv.id }); - - spinner.stop(); - users - .getEntities() - .forEach(u => table.push([u.id, new Date(u.dateAdded).toLocaleDateString()])); - console.log(table.toString()); - }, -}; - -export default command; diff --git a/tdrive/backend/node/src/cli/utils/copy-messages/.gitignore b/tdrive/backend/node/src/cli/utils/copy-messages/.gitignore deleted file mode 100644 index 97008e5b..00000000 --- a/tdrive/backend/node/src/cli/utils/copy-messages/.gitignore +++ /dev/null @@ -1,2 +0,0 @@ -node_modules -yarn.lock \ No newline at end of file diff --git a/tdrive/backend/node/src/cli/utils/copy-messages/README.md b/tdrive/backend/node/src/cli/utils/copy-messages/README.md deleted file mode 100644 index 02fe7cc4..00000000 --- a/tdrive/backend/node/src/cli/utils/copy-messages/README.md +++ /dev/null @@ -1,4 +0,0 @@ -Edit the file to your needs - -yarn install -node index.js diff --git a/tdrive/backend/node/src/cli/utils/copy-messages/index.js b/tdrive/backend/node/src/cli/utils/copy-messages/index.js deleted file mode 100644 index e9edf081..00000000 --- a/tdrive/backend/node/src/cli/utils/copy-messages/index.js +++ /dev/null @@ -1,98 +0,0 @@ -/* eslint-disable */ -var cassandra = require("cassandra-driver"); - -var fromAuthProvider = new cassandra.auth.PlainTextAuthProvider("", ""); -var fromContactPoints = [""]; - -var toAuthProvider = new cassandra.auth.PlainTextAuthProvider("", ""); -var toContactPoints = [""]; - -// -- start process - -var fromClient = new cassandra.Client({ - localDataCenter: "datacenter1", - contactPoints: fromContactPoints, - authProvider: fromAuthProvider, - keyspace: "tdrive", -}); - -var toClient = new cassandra.Client({ - localDataCenter: "datacenter1", - contactPoints: toContactPoints, - authProvider: toAuthProvider, - keyspace: "tdrive", - queryOptions: { - consistency: cassandra.types.consistencies.quorum, - }, -}); - -// -- Get all tables and copy schema - -async function client(origin, query, parameters, options) { - return await new Promise((resolve, reject) => { - origin.execute(query, [], {}, function (err, result) { - if (err) { - reject({ err, result }); - } else { - resolve(result); - } - }); - }); -} - -// Get all threads and then copy all messages in each threads - -let copiedMessages = 0; -let copiedThreads = 0; - -(async () => { - await new Promise(r => { - fromClient.eachRow( - "SELECT id from tdrive.threads", - [], - { prepare: true, fetchSize: 50 }, - async function (n, row) { - const threadId = row["id"]; - - console.log("Threads / Messages :", copiedThreads, "/", copiedMessages); - - copiedThreads++; - - await new Promise(r2 => { - fromClient.eachRow( - "SELECT JSON * from tdrive.messages where thread_id = ? order by id desc", - [threadId], - { prepare: true, fetchSize: 1000 }, - async function (n, row) { - const message = row["[json]"]; - - copiedMessages++; - - await toClient.execute( - "INSERT INTO tdrive.messages JSON '" + message.replace(/'/g, "'$&") + "'", - [], - { prepare: true }, - ); - }, - async function (err, result) { - if (result && result.nextPage) { - await new Promise(r => setTimeout(r, 100)); - result.nextPage(); - } else { - r2(); - } - }, - ); - }); - }, - async function (err, result) { - if (result && result.nextPage) { - await new Promise(r => setTimeout(r, 2000)); - result.nextPage(); - } else { - r(); - } - }, - ); - }); -})(); diff --git a/tdrive/backend/node/src/cli/utils/copy-messages/package.json b/tdrive/backend/node/src/cli/utils/copy-messages/package.json deleted file mode 100644 index 6aa7d488..00000000 --- a/tdrive/backend/node/src/cli/utils/copy-messages/package.json +++ /dev/null @@ -1,9 +0,0 @@ -{ - "name": "copy-messages", - "version": "1.0.0", - "main": "index.js", - "license": "MIT", - "dependencies": { - "cassandra-driver": "^4.6.3" - } -} diff --git a/tdrive/backend/node/src/cli/utils/repair-threads/README.md b/tdrive/backend/node/src/cli/utils/repair-threads/README.md deleted file mode 100644 index 02fe7cc4..00000000 --- a/tdrive/backend/node/src/cli/utils/repair-threads/README.md +++ /dev/null @@ -1,4 +0,0 @@ -Edit the file to your needs - -yarn install -node index.js diff --git a/tdrive/backend/node/src/cli/utils/repair-threads/index.js b/tdrive/backend/node/src/cli/utils/repair-threads/index.js deleted file mode 100644 index 7eeb9a4d..00000000 --- a/tdrive/backend/node/src/cli/utils/repair-threads/index.js +++ /dev/null @@ -1,96 +0,0 @@ -/* eslint-disable */ -var cassandra = require("cassandra-driver"); - -var authProvider = new cassandra.auth.PlainTextAuthProvider("", ""); -var contactPoints = [""]; - -var client = new cassandra.Client({ - localDataCenter: "datacenter1", - contactPoints: contactPoints, - authProvider: authProvider, - keyspace: "tdrive", -}); - -var threadsTable = "threads"; -var messagesTable = "messages"; - -//Copy object to other table -(async () => { - const query = "SELECT * FROM " + threadsTable + " where answers>1000 allow filtering"; - const parameters = []; - const options = { prepare: true, fetchSize: 1000 }; - - let count = 0; - - let threads = {}; - - await new Promise(r => { - client.eachRow( - query, - parameters, - options, - function (n, row) { - threads[row.id] ||= { answers: 0, id: row.id }; - count++; - }, - function (err, result) { - if (result && result.nextPage) { - result.nextPage(); - } else { - r(); - } - }, - ); - }); - - console.log( - "Downloaded ", - Object.keys(threads).length, - " threads of ", - messagesTable, - ". Starting copy...", - ); - - for (var key of Object.keys(threads)) { - await new Promise(r => { - const query = "SELECT id FROM " + messagesTable + " where thread_id=" + key; - const parameters = []; - const options = { prepare: true, fetchSize: 1000 }; - client.eachRow( - query, - parameters, - options, - function (n, row) { - threads[key].answers++; - }, - function (err, result) { - if (result && result.nextPage) { - result.nextPage(); - } else { - r(); - } - }, - ); - r(); - }); - } - - var copyCount = 0; - for (var key of Object.keys(threads)) { - copyCount++; - if (copyCount % 100 == 0) { - console.log(copyCount, "of", Object.keys(threads)); - } - - const row = threads[key]; - - await new Promise(r => { - let query = "UPDATE " + threadsTable + " SET answers=? WHERE id=?"; - console.log(query, [row.answers, row.id + ""]); - //client.execute(query, [row.answers, row.id], () => { - // r(); - //}); - }); - } - console.log("Ended with ", Object.keys(threads), "threads"); -})(); diff --git a/tdrive/backend/node/src/cli/utils/repair-threads/package.json b/tdrive/backend/node/src/cli/utils/repair-threads/package.json deleted file mode 100644 index dd45de8a..00000000 --- a/tdrive/backend/node/src/cli/utils/repair-threads/package.json +++ /dev/null @@ -1,9 +0,0 @@ -{ - "name": "repair-threads", - "version": "1.0.0", - "main": "index.js", - "license": "MIT", - "dependencies": { - "cassandra-driver": "^4.6.3" - } -} diff --git a/tdrive/backend/node/src/services/applications-api/index.ts b/tdrive/backend/node/src/services/applications-api/index.ts index 995cb4b8..6cd04031 100644 --- a/tdrive/backend/node/src/services/applications-api/index.ts +++ b/tdrive/backend/node/src/services/applications-api/index.ts @@ -3,6 +3,8 @@ import WebServerAPI from "../../core/platform/services/webserver/provider"; import web from "./web/index"; import FastProxy from "fast-proxy"; import globalResolver from "../global-resolver"; +import config from "config"; +import Application from "../applications/entities/application"; @Prefix("/api") export default class ApplicationsApiService extends TdriveService { @@ -17,7 +19,7 @@ export default class ApplicationsApiService extends TdriveService { }); //Redirect requests from /plugins/* to the plugin server (if installed) - const apps = await globalResolver.services.applications.marketplaceApps.list(null); + const apps = config.get("applications.plugins") || []; for (const app of apps) { const domain = app.internal_domain; const prefix = app.external_prefix;